blob: 2fc6bd0483b95bd7dacdee55f987363a173808d7 [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 */
390static long p_tw_nopaste;
391static long p_wm_nopaste;
392static long p_sts_nopaste;
393static int p_ai_nopaste;
394
395struct vimoption
396{
397 char *fullname; /* full option name */
398 char *shortname; /* permissible abbreviation */
399 long_u flags; /* see below */
400 char_u *var; /* global option: pointer to variable;
401 * window-local option: VAR_WIN;
402 * buffer-local option: global value */
403 idopt_T indir; /* global option: PV_NONE;
404 * local option: indirect option index */
405 char_u *def_val[2]; /* default values for variable (vi and vim) */
406#ifdef FEAT_EVAL
407 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000408# define SCRIPTID_INIT , 0
409#else
410# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411#endif
412};
413
414#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
415#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
416
417/*
418 * Flags
419 */
420#define P_BOOL 0x01 /* the option is boolean */
421#define P_NUM 0x02 /* the option is numeric */
422#define P_STRING 0x04 /* the option is a string */
423#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000424 must use free_string_option() when
425 assigning new value. Not set if default is
426 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000427#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
428 never be used for local or hidden options! */
429#define P_NODEFAULT 0x40 /* don't set to default value */
430#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
431 use vim_free() when assigning new value */
432#define P_WAS_SET 0x100 /* option has been set/reset */
433#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
434#define P_VI_DEF 0x400 /* Use Vi default for Vim */
435#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
436
437 /* when option changed, what to display: */
438#define P_RSTAT 0x1000 /* redraw status lines */
439#define P_RWIN 0x2000 /* redraw current window */
440#define P_RBUF 0x4000 /* redraw current buffer */
441#define P_RALL 0x6000 /* redraw all windows */
442#define P_RCLR 0x7000 /* clear and redraw all */
443
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200444#define P_COMMA 0x8000 /* comma separated list */
445#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
446 * commas */
447#define P_NODUP 0x20000L /* don't allow duplicate strings */
448#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200450#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
451#define P_GETTEXT 0x100000L /* expand default value with _() */
452#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
453#define P_NFNAME 0x400000L /* only normal file name chars allowed */
454#define P_INSECURE 0x800000L /* option was set from a modeline */
455#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000456 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200457#define P_NO_ML 0x2000000L /* not allowed in modeline */
458#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200459 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000460
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000461#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
462
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000463/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
464 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000465#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000466# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000467#else
468# define ISP_LATIN1 (char_u *)"@,161-255"
469#endif
470
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000471/* The 16 bit MS-DOS version is low on space, make the string as short as
472 * possible when compiling with few features. */
473#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
474 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200475 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100476# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,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 +0000477#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100478# 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 +0000479#endif
480
Bram Moolenaar071d4272004-06-13 20:20:40 +0000481/*
482 * options[] is initialized here.
483 * The order of the options MUST be alphabetic for ":set all" and findoption().
484 * All option names MUST start with a lowercase letter (for findoption()).
485 * Exception: "t_" options are at the end.
486 * The options with a NULL variable are 'hidden': a set command for them is
487 * ignored and they are not printed.
488 */
489static struct vimoption
490#ifdef FEAT_GUI_W16
491 _far
492#endif
493 options[] =
494{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200495 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496#ifdef FEAT_RIGHTLEFT
497 (char_u *)&p_aleph, PV_NONE,
498#else
499 (char_u *)NULL, PV_NONE,
500#endif
501 {
502#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
503 (char_u *)128L,
504#else
505 (char_u *)224L,
506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000507 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
509#if defined(FEAT_GUI) && defined(MACOS_X)
510 (char_u *)&p_antialias, PV_NONE,
511 {(char_u *)FALSE, (char_u *)FALSE}
512#else
513 (char_u *)NULL, PV_NONE,
514 {(char_u *)FALSE, (char_u *)FALSE}
515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000516 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200517 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518#ifdef FEAT_ARABIC
519 (char_u *)VAR_WIN, PV_ARAB,
520#else
521 (char_u *)NULL, PV_NONE,
522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
525#ifdef FEAT_ARABIC
526 (char_u *)&p_arshape, PV_NONE,
527#else
528 (char_u *)NULL, PV_NONE,
529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000530 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000531 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
532#ifdef FEAT_RIGHTLEFT
533 (char_u *)&p_ari, PV_NONE,
534#else
535 (char_u *)NULL, PV_NONE,
536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
539#ifdef FEAT_FKMAP
540 (char_u *)&p_altkeymap, PV_NONE,
541#else
542 (char_u *)NULL, PV_NONE,
543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
546#if defined(FEAT_MBYTE)
547 (char_u *)&p_ambw, PV_NONE,
548 {(char_u *)"single", (char_u *)0L}
549#else
550 (char_u *)NULL, PV_NONE,
551 {(char_u *)0L, (char_u *)0L}
552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000553 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000554#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555 {"autochdir", "acd", P_BOOL|P_VI_DEF,
556 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558#endif
559 {"autoindent", "ai", P_BOOL|P_VI_DEF,
560 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autoprint", "ap", P_BOOL|P_VI_DEF,
563 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000566 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autowrite", "aw", P_BOOL|P_VI_DEF,
569 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000570 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autowriteall","awa", P_BOOL|P_VI_DEF,
572 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
575 (char_u *)&p_bg, PV_NONE,
576 {
577#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
578 (char_u *)"dark",
579#else
580 (char_u *)"light",
581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200583 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
587 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200589 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200590 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591#ifdef UNIX
592 {(char_u *)"yes", (char_u *)"auto"}
593#else
594 {(char_u *)"auto", (char_u *)"auto"}
595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
598 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000601 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 (char_u *)&p_bex, PV_NONE,
603 {
604#ifdef VMS
605 (char_u *)"_",
606#else
607 (char_u *)"~",
608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000609 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200610 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611#ifdef FEAT_WILDIGN
612 (char_u *)&p_bsk, PV_NONE,
613 {(char_u *)"", (char_u *)0L}
614#else
615 (char_u *)NULL, PV_NONE,
616 {(char_u *)0L, (char_u *)0L}
617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000618 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#ifdef FEAT_BEVAL
620 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
621 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000622 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
624 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000625 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000626# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000627 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000628 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000629 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000630# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631#endif
632 {"beautify", "bf", P_BOOL|P_VI_DEF,
633 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000634 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200635 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
636 (char_u *)&p_bo, PV_NONE,
637 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
639 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000640 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000641 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
642#ifdef MSDOS
643 (char_u *)&p_biosk, PV_NONE,
644#else
645 (char_u *)NULL, PV_NONE,
646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000647 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000648 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
649#ifdef FEAT_MBYTE
650 (char_u *)&p_bomb, PV_BOMB,
651#else
652 (char_u *)NULL, PV_NONE,
653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000654 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000655 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
656#ifdef FEAT_LINEBREAK
657 (char_u *)&p_breakat, PV_NONE,
658 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
659#else
660 (char_u *)NULL, PV_NONE,
661 {(char_u *)0L, (char_u *)0L}
662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000663 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200664 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
665#ifdef FEAT_LINEBREAK
666 (char_u *)VAR_WIN, PV_BRI,
667 {(char_u *)FALSE, (char_u *)0L}
668#else
669 (char_u *)NULL, PV_NONE,
670 {(char_u *)0L, (char_u *)0L}
671#endif
672 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200673 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
674 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200675#ifdef FEAT_LINEBREAK
676 (char_u *)VAR_WIN, PV_BRIOPT,
677 {(char_u *)"", (char_u *)NULL}
678#else
679 (char_u *)NULL, PV_NONE,
680 {(char_u *)"", (char_u *)NULL}
681#endif
682 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
684#ifdef FEAT_BROWSE
685 (char_u *)&p_bsdir, PV_NONE,
686 {(char_u *)"last", (char_u *)0L}
687#else
688 (char_u *)NULL, PV_NONE,
689 {(char_u *)0L, (char_u *)0L}
690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000691 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
693#if defined(FEAT_QUICKFIX)
694 (char_u *)&p_bh, PV_BH,
695 {(char_u *)"", (char_u *)0L}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)0L, (char_u *)0L}
699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000700 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000701 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
702 (char_u *)&p_bl, PV_BL,
703 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
706#if defined(FEAT_QUICKFIX)
707 (char_u *)&p_bt, PV_BT,
708 {(char_u *)"", (char_u *)0L}
709#else
710 (char_u *)NULL, PV_NONE,
711 {(char_u *)0L, (char_u *)0L}
712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200714 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000715#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 (char_u *)&p_cmp, PV_NONE,
717 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000718#else
719 (char_u *)NULL, PV_NONE,
720 {(char_u *)0L, (char_u *)0L}
721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
724#ifdef FEAT_SEARCHPATH
725 (char_u *)&p_cdpath, PV_NONE,
726 {(char_u *)",,", (char_u *)0L}
727#else
728 (char_u *)NULL, PV_NONE,
729 {(char_u *)0L, (char_u *)0L}
730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000731 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 {"cedit", NULL, P_STRING,
733#ifdef FEAT_CMDWIN
734 (char_u *)&p_cedit, PV_NONE,
735 {(char_u *)"", (char_u *)CTRL_F_STR}
736#else
737 (char_u *)NULL, PV_NONE,
738 {(char_u *)0L, (char_u *)0L}
739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000740 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
742#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
743 (char_u *)&p_ccv, PV_NONE,
744 {(char_u *)"", (char_u *)0L}
745#else
746 (char_u *)NULL, PV_NONE,
747 {(char_u *)0L, (char_u *)0L}
748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000749 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
751#ifdef FEAT_CINDENT
752 (char_u *)&p_cin, PV_CIN,
753#else
754 (char_u *)NULL, PV_NONE,
755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000756 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200757 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758#ifdef FEAT_CINDENT
759 (char_u *)&p_cink, PV_CINK,
760 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
761#else
762 (char_u *)NULL, PV_NONE,
763 {(char_u *)0L, (char_u *)0L}
764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000765 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200766 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767#ifdef FEAT_CINDENT
768 (char_u *)&p_cino, PV_CINO,
769#else
770 (char_u *)NULL, PV_NONE,
771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000772 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200773 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
775 (char_u *)&p_cinw, PV_CINW,
776 {(char_u *)"if,else,while,do,for,switch",
777 (char_u *)0L}
778#else
779 (char_u *)NULL, PV_NONE,
780 {(char_u *)0L, (char_u *)0L}
781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000782 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200783 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#ifdef FEAT_CLIPBOARD
785 (char_u *)&p_cb, PV_NONE,
786# ifdef FEAT_XCLIPBOARD
787 {(char_u *)"autoselect,exclude:cons\\|linux",
788 (char_u *)0L}
789# else
790 {(char_u *)"", (char_u *)0L}
791# endif
792#else
793 (char_u *)NULL, PV_NONE,
794 {(char_u *)"", (char_u *)0L}
795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000796 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000797 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
798 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000799 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000800 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
801#ifdef FEAT_CMDWIN
802 (char_u *)&p_cwh, PV_NONE,
803#else
804 (char_u *)NULL, PV_NONE,
805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000806 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200807 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200808#ifdef FEAT_SYN_HL
809 (char_u *)VAR_WIN, PV_CC,
810#else
811 (char_u *)NULL, PV_NONE,
812#endif
813 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
815 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000816 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200817 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
818 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819#ifdef FEAT_COMMENTS
820 (char_u *)&p_com, PV_COM,
821 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
822 (char_u *)0L}
823#else
824 (char_u *)NULL, PV_NONE,
825 {(char_u *)0L, (char_u *)0L}
826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000827 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200828 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000829#ifdef FEAT_FOLDING
830 (char_u *)&p_cms, PV_CMS,
831 {(char_u *)"/*%s*/", (char_u *)0L}
832#else
833 (char_u *)NULL, PV_NONE,
834 {(char_u *)0L, (char_u *)0L}
835#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000836 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000837 /* P_PRI_MKRC isn't needed here, optval_default()
838 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839 {"compatible", "cp", P_BOOL|P_RALL,
840 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000841 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200842 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843#ifdef FEAT_INS_EXPAND
844 (char_u *)&p_cpt, PV_CPT,
845 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
846#else
847 (char_u *)NULL, PV_NONE,
848 {(char_u *)0L, (char_u *)0L}
849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000850 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200851 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200852#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200853 (char_u *)VAR_WIN, PV_COCU,
854 {(char_u *)"", (char_u *)NULL}
855#else
856 (char_u *)NULL, PV_NONE,
857 {(char_u *)NULL, (char_u *)0L}
858#endif
859 SCRIPTID_INIT},
860 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
861#ifdef FEAT_CONCEAL
862 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200863#else
864 (char_u *)NULL, PV_NONE,
865#endif
866 {(char_u *)0L, (char_u *)0L}
867 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000868 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
869#ifdef FEAT_COMPL_FUNC
870 (char_u *)&p_cfu, PV_CFU,
871 {(char_u *)"", (char_u *)0L}
872#else
873 (char_u *)NULL, PV_NONE,
874 {(char_u *)0L, (char_u *)0L}
875#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000876 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200877 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000878#ifdef FEAT_INS_EXPAND
879 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000880 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000881#else
882 (char_u *)NULL, PV_NONE,
883 {(char_u *)0L, (char_u *)0L}
884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"confirm", "cf", P_BOOL|P_VI_DEF,
887#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
888 (char_u *)&p_confirm, PV_NONE,
889#else
890 (char_u *)NULL, PV_NONE,
891#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000892 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893 {"conskey", "consk",P_BOOL|P_VI_DEF,
894#ifdef MSDOS
895 (char_u *)&p_consk, PV_NONE,
896#else
897 (char_u *)NULL, PV_NONE,
898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000899 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
901 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000902 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
904 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000905 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
906 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200907 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200908#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200909 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200910 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200911#else
912 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200913 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200914#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200915 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
917#ifdef FEAT_CSCOPE
918 (char_u *)&p_cspc, PV_NONE,
919#else
920 (char_u *)NULL, PV_NONE,
921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000922 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000923 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
924#ifdef FEAT_CSCOPE
925 (char_u *)&p_csprg, PV_NONE,
926 {(char_u *)"cscope", (char_u *)0L}
927#else
928 (char_u *)NULL, PV_NONE,
929 {(char_u *)0L, (char_u *)0L}
930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000931 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200932 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000933#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
934 (char_u *)&p_csqf, PV_NONE,
935 {(char_u *)"", (char_u *)0L}
936#else
937 (char_u *)NULL, PV_NONE,
938 {(char_u *)0L, (char_u *)0L}
939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000940 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200941 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
942#ifdef FEAT_CSCOPE
943 (char_u *)&p_csre, PV_NONE,
944#else
945 (char_u *)NULL, PV_NONE,
946#endif
947 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
949#ifdef FEAT_CSCOPE
950 (char_u *)&p_cst, PV_NONE,
951#else
952 (char_u *)NULL, PV_NONE,
953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
956#ifdef FEAT_CSCOPE
957 (char_u *)&p_csto, PV_NONE,
958#else
959 (char_u *)NULL, PV_NONE,
960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000961 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000962 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
963#ifdef FEAT_CSCOPE
964 (char_u *)&p_csverbose, PV_NONE,
965#else
966 (char_u *)NULL, PV_NONE,
967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000968 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200969 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
970#ifdef FEAT_CURSORBIND
971 (char_u *)VAR_WIN, PV_CRBIND,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000976 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
977#ifdef FEAT_SYN_HL
978 (char_u *)VAR_WIN, PV_CUC,
979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000983 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
984#ifdef FEAT_SYN_HL
985 (char_u *)VAR_WIN, PV_CUL,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000990 {"debug", NULL, P_STRING|P_VI_DEF,
991 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000992 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200993 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000995 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000996 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000997#else
998 (char_u *)NULL, PV_NONE,
999 {(char_u *)NULL, (char_u *)0L}
1000#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001001 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1003#ifdef FEAT_MBYTE
1004 (char_u *)&p_deco, PV_NONE,
1005#else
1006 (char_u *)NULL, PV_NONE,
1007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001008 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001009 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001011 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#else
1013 (char_u *)NULL, PV_NONE,
1014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001015 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1017#ifdef FEAT_DIFF
1018 (char_u *)VAR_WIN, PV_DIFF,
1019#else
1020 (char_u *)NULL, PV_NONE,
1021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001022 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001023 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1025 (char_u *)&p_dex, PV_NONE,
1026 {(char_u *)"", (char_u *)0L}
1027#else
1028 (char_u *)NULL, PV_NONE,
1029 {(char_u *)0L, (char_u *)0L}
1030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001031 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001032 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1033 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034#ifdef FEAT_DIFF
1035 (char_u *)&p_dip, PV_NONE,
1036 {(char_u *)"filler", (char_u *)NULL}
1037#else
1038 (char_u *)NULL, PV_NONE,
1039 {(char_u *)"", (char_u *)NULL}
1040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1043#ifdef FEAT_DIGRAPHS
1044 (char_u *)&p_dg, PV_NONE,
1045#else
1046 (char_u *)NULL, PV_NONE,
1047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001048 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001049 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1050 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001053 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001055 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 {"eadirection", "ead", P_STRING|P_VI_DEF,
1057#ifdef FEAT_VERTSPLIT
1058 (char_u *)&p_ead, PV_NONE,
1059 {(char_u *)"both", (char_u *)0L}
1060#else
1061 (char_u *)NULL, PV_NONE,
1062 {(char_u *)NULL, (char_u *)0L}
1063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1066 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001068 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069#ifdef FEAT_MBYTE
1070 (char_u *)&p_enc, PV_NONE,
1071 {(char_u *)ENC_DFLT, (char_u *)0L}
1072#else
1073 (char_u *)NULL, PV_NONE,
1074 {(char_u *)0L, (char_u *)0L}
1075#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001076 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1078 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001079 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1081 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001084 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1087 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1090#ifdef FEAT_QUICKFIX
1091 (char_u *)&p_ef, PV_NONE,
1092 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1093#else
1094 (char_u *)NULL, PV_NONE,
1095 {(char_u *)NULL, (char_u *)0L}
1096#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001097 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001098 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001100 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)NULL, (char_u *)0L}
1105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"esckeys", "ek", P_BOOL|P_VIM,
1108 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001110 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111#ifdef FEAT_AUTOCMD
1112 (char_u *)&p_ei, PV_NONE,
1113#else
1114 (char_u *)NULL, PV_NONE,
1115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001116 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1118 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1121 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001122 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001123 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1124 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125#ifdef FEAT_MBYTE
1126 (char_u *)&p_fenc, PV_FENC,
1127 {(char_u *)"", (char_u *)0L}
1128#else
1129 (char_u *)NULL, PV_NONE,
1130 {(char_u *)0L, (char_u *)0L}
1131#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001132 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001133 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134#ifdef FEAT_MBYTE
1135 (char_u *)&p_fencs, PV_NONE,
1136 {(char_u *)"ucs-bom", (char_u *)0L}
1137#else
1138 (char_u *)NULL, PV_NONE,
1139 {(char_u *)0L, (char_u *)0L}
1140#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001141 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001142 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1143 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001145 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001146 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001148 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1149 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001150 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1151 (char_u *)&p_fic, PV_NONE,
1152 {
1153#ifdef CASE_INSENSITIVE_FILENAME
1154 (char_u *)TRUE,
1155#else
1156 (char_u *)FALSE,
1157#endif
1158 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001159 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001160#ifdef FEAT_AUTOCMD
1161 (char_u *)&p_ft, PV_FT,
1162 {(char_u *)"", (char_u *)0L}
1163#else
1164 (char_u *)NULL, PV_NONE,
1165 {(char_u *)0L, (char_u *)0L}
1166#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001167 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001168 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1170 (char_u *)&p_fcs, PV_NONE,
1171 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1172#else
1173 (char_u *)NULL, PV_NONE,
1174 {(char_u *)"", (char_u *)0L}
1175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001176 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001177 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1178 (char_u *)&p_fixeol, PV_FIXEOL,
1179 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001180 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1181#ifdef FEAT_FKMAP
1182 (char_u *)&p_fkmap, PV_NONE,
1183#else
1184 (char_u *)NULL, PV_NONE,
1185#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001186 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187 {"flash", "fl", P_BOOL|P_VI_DEF,
1188 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001189 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001191 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001193 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1195 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001196 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001197 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1198 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001199 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001200 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1201# ifdef FEAT_EVAL
1202 (char_u *)VAR_WIN, PV_FDE,
1203 {(char_u *)"0", (char_u *)NULL}
1204# else
1205 (char_u *)NULL, PV_NONE,
1206 {(char_u *)NULL, (char_u *)0L}
1207# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001208 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1210 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001211 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1213 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001214 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001215 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001219 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001221 {(char_u *)"{{{,}}}", (char_u *)NULL}
1222 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1224 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001225 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001226 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1227 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001228 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1230 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001231 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001232 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 (char_u *)&p_fdo, PV_NONE,
1234 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001235 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1237# ifdef FEAT_EVAL
1238 (char_u *)VAR_WIN, PV_FDT,
1239 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001240# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 (char_u *)NULL, PV_NONE,
1242 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001243# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001244 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001246 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001247#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001248 (char_u *)&p_fex, PV_FEX,
1249 {(char_u *)"", (char_u *)0L}
1250#else
1251 (char_u *)NULL, PV_NONE,
1252 {(char_u *)0L, (char_u *)0L}
1253#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001254 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1256 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001257 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1258 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001259 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1260 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001261 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1262 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001263 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1264 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001265 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001266 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1267#ifdef HAVE_FSYNC
1268 (char_u *)&p_fs, PV_NONE,
1269 {(char_u *)TRUE, (char_u *)0L}
1270#else
1271 (char_u *)NULL, PV_NONE,
1272 {(char_u *)FALSE, (char_u *)0L}
1273#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001274 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001275 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1276 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001277 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001278 {"graphic", "gr", P_BOOL|P_VI_DEF,
1279 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001280 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001281 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282#ifdef FEAT_QUICKFIX
1283 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001284 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285#else
1286 (char_u *)NULL, PV_NONE,
1287 {(char_u *)NULL, (char_u *)0L}
1288#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001289 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001290 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1291#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001292 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001293 {
1294# ifdef WIN3264
1295 /* may be changed to "grep -n" in os_win32.c */
1296 (char_u *)"findstr /n",
1297# else
1298# ifdef UNIX
1299 /* Add an extra file name so that grep will always
1300 * insert a file name in the match line. */
1301 (char_u *)"grep -n $* /dev/null",
1302# else
1303# ifdef VMS
1304 (char_u *)"SEARCH/NUMBERS ",
1305# else
1306 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001307# endif
1308# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001310 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311#else
1312 (char_u *)NULL, PV_NONE,
1313 {(char_u *)NULL, (char_u *)0L}
1314#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001315 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001316 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317#ifdef CURSOR_SHAPE
1318 (char_u *)&p_guicursor, PV_NONE,
1319 {
1320# ifdef FEAT_GUI
1321 (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",
1322# else /* MSDOS or Win32 console */
1323 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1324# endif
1325 (char_u *)0L}
1326#else
1327 (char_u *)NULL, PV_NONE,
1328 {(char_u *)NULL, (char_u *)0L}
1329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001330 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001331 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332#ifdef FEAT_GUI
1333 (char_u *)&p_guifont, PV_NONE,
1334 {(char_u *)"", (char_u *)0L}
1335#else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)NULL, (char_u *)0L}
1338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001339 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001340 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1342 (char_u *)&p_guifontset, PV_NONE,
1343 {(char_u *)"", (char_u *)0L}
1344#else
1345 (char_u *)NULL, PV_NONE,
1346 {(char_u *)NULL, (char_u *)0L}
1347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001349 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1351 (char_u *)&p_guifontwide, PV_NONE,
1352 {(char_u *)"", (char_u *)0L}
1353#else
1354 (char_u *)NULL, PV_NONE,
1355 {(char_u *)NULL, (char_u *)0L}
1356#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001357 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001359#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 (char_u *)&p_ghr, PV_NONE,
1361#else
1362 (char_u *)NULL, PV_NONE,
1363#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001366#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367 (char_u *)&p_go, PV_NONE,
1368# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001369 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001371 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372# endif
1373#else
1374 (char_u *)NULL, PV_NONE,
1375 {(char_u *)NULL, (char_u *)0L}
1376#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001377 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378 {"guipty", NULL, P_BOOL|P_VI_DEF,
1379#if defined(FEAT_GUI)
1380 (char_u *)&p_guipty, PV_NONE,
1381#else
1382 (char_u *)NULL, PV_NONE,
1383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001384 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001385 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001386#if defined(FEAT_GUI_TABLINE)
1387 (char_u *)&p_gtl, PV_NONE,
1388 {(char_u *)"", (char_u *)0L}
1389#else
1390 (char_u *)NULL, PV_NONE,
1391 {(char_u *)NULL, (char_u *)0L}
1392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001393 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001394 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001395#if defined(FEAT_GUI_TABLINE)
1396 (char_u *)&p_gtt, PV_NONE,
1397 {(char_u *)"", (char_u *)0L}
1398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1404 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001406 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1407 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1409 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 {"helpheight", "hh", P_NUM|P_VI_DEF,
1411#ifdef FEAT_WINDOWS
1412 (char_u *)&p_hh, PV_NONE,
1413#else
1414 (char_u *)NULL, PV_NONE,
1415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001416 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001417 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418#ifdef FEAT_MULTI_LANG
1419 (char_u *)&p_hlg, PV_NONE,
1420 {(char_u *)"", (char_u *)0L}
1421#else
1422 (char_u *)NULL, PV_NONE,
1423 {(char_u *)0L, (char_u *)0L}
1424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001425 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 {"hidden", "hid", P_BOOL|P_VI_DEF,
1427 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001428 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001429 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1432 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"history", "hi", P_NUM|P_VIM,
1434 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001435 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1437#ifdef FEAT_RIGHTLEFT
1438 (char_u *)&p_hkmap, PV_NONE,
1439#else
1440 (char_u *)NULL, PV_NONE,
1441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001442 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001443 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1444#ifdef FEAT_RIGHTLEFT
1445 (char_u *)&p_hkmapp, PV_NONE,
1446#else
1447 (char_u *)NULL, PV_NONE,
1448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001449 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1451 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"icon", NULL, P_BOOL|P_VI_DEF,
1454#ifdef FEAT_TITLE
1455 (char_u *)&p_icon, PV_NONE,
1456#else
1457 (char_u *)NULL, PV_NONE,
1458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001459 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001460 {"iconstring", NULL, P_STRING|P_VI_DEF,
1461#ifdef FEAT_TITLE
1462 (char_u *)&p_iconstring, PV_NONE,
1463#else
1464 (char_u *)NULL, PV_NONE,
1465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001466 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1468 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001469 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001470 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1471# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1472 (char_u *)&p_imaf, PV_NONE,
1473 {(char_u *)"", (char_u *)NULL}
1474# else
1475 (char_u *)NULL, PV_NONE,
1476 {(char_u *)NULL, (char_u *)0L}
1477# endif
1478 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001480#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 (char_u *)&p_imak, PV_NONE,
1482#else
1483 (char_u *)NULL, PV_NONE,
1484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001485 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001486 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1487#ifdef USE_IM_CONTROL
1488 (char_u *)&p_imcmdline, PV_NONE,
1489#else
1490 (char_u *)NULL, PV_NONE,
1491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1494#ifdef USE_IM_CONTROL
1495 (char_u *)&p_imdisable, PV_NONE,
1496#else
1497 (char_u *)NULL, PV_NONE,
1498#endif
1499#ifdef __sgi
1500 {(char_u *)TRUE, (char_u *)0L}
1501#else
1502 {(char_u *)FALSE, (char_u *)0L}
1503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001504 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 {"iminsert", "imi", P_NUM|P_VI_DEF,
1506 (char_u *)&p_iminsert, PV_IMI,
1507#ifdef B_IMODE_IM
1508 {(char_u *)B_IMODE_IM, (char_u *)0L}
1509#else
1510 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001512 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 {"imsearch", "ims", P_NUM|P_VI_DEF,
1514 (char_u *)&p_imsearch, PV_IMS,
1515#ifdef B_IMODE_IM
1516 {(char_u *)B_IMODE_IM, (char_u *)0L}
1517#else
1518 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001520 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001521 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001522# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1523 (char_u *)&p_imsf, PV_NONE,
1524 {(char_u *)"", (char_u *)NULL}
1525# else
1526 (char_u *)NULL, PV_NONE,
1527 {(char_u *)NULL, (char_u *)0L}
1528# endif
1529 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1531#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001532 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001533 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1534#else
1535 (char_u *)NULL, PV_NONE,
1536 {(char_u *)0L, (char_u *)0L}
1537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001538 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001539 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1540#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1541 (char_u *)&p_inex, PV_INEX,
1542 {(char_u *)"", (char_u *)0L}
1543#else
1544 (char_u *)NULL, PV_NONE,
1545 {(char_u *)0L, (char_u *)0L}
1546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001547 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1549 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001550 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001551 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1552#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1553 (char_u *)&p_inde, PV_INDE,
1554 {(char_u *)"", (char_u *)0L}
1555#else
1556 (char_u *)NULL, PV_NONE,
1557 {(char_u *)0L, (char_u *)0L}
1558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001559 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001560 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1562 (char_u *)&p_indk, PV_INDK,
1563 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1564#else
1565 (char_u *)NULL, PV_NONE,
1566 {(char_u *)0L, (char_u *)0L}
1567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001568 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569 {"infercase", "inf", P_BOOL|P_VI_DEF,
1570 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1573 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001574 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001575 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1576 (char_u *)&p_isf, PV_NONE,
1577 {
1578#ifdef BACKSLASH_IN_FILENAME
1579 /* Excluded are: & and ^ are special in cmd.exe
1580 * ( and ) are used in text separating fnames */
1581 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1582#else
1583# ifdef AMIGA
1584 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1585# else
1586# ifdef VMS
1587 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1588# else /* UNIX et al. */
1589# ifdef EBCDIC
1590 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1591# else
1592 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1593# endif
1594# endif
1595# endif
1596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001597 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1599 (char_u *)&p_isi, PV_NONE,
1600 {
1601#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1602 (char_u *)"@,48-57,_,128-167,224-235",
1603#else
1604# ifdef EBCDIC
1605 /* TODO: EBCDIC Check this! @ == isalpha()*/
1606 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1607 "112-120,128,140-142,156,158,172,"
1608 "174,186,191,203-207,219-225,235-239,"
1609 "251-254",
1610# else
1611 (char_u *)"@,48-57,_,192-255",
1612# endif
1613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001614 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001615 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1616 (char_u *)&p_isk, PV_ISK,
1617 {
1618#ifdef EBCDIC
1619 (char_u *)"@,240-249,_",
1620 /* TODO: EBCDIC Check this! @ == isalpha()*/
1621 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1622 "112-120,128,140-142,156,158,172,"
1623 "174,186,191,203-207,219-225,235-239,"
1624 "251-254",
1625#else
1626 (char_u *)"@,48-57,_",
1627# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1628 (char_u *)"@,48-57,_,128-167,224-235"
1629# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001630 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631# endif
1632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001633 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001634 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1635 (char_u *)&p_isp, PV_NONE,
1636 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001637#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1638 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001639 || defined(VMS)
1640 (char_u *)"@,~-255",
1641#else
1642# ifdef EBCDIC
1643 /* all chars above 63 are printable */
1644 (char_u *)"63-255",
1645# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001646 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647# endif
1648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001649 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1651 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1654#ifdef FEAT_CRYPT
1655 (char_u *)&p_key, PV_KEY,
1656 {(char_u *)"", (char_u *)0L}
1657#else
1658 (char_u *)NULL, PV_NONE,
1659 {(char_u *)0L, (char_u *)0L}
1660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001662 {"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 +00001663#ifdef FEAT_KEYMAP
1664 (char_u *)&p_keymap, PV_KMAP,
1665 {(char_u *)"", (char_u *)0L}
1666#else
1667 (char_u *)NULL, PV_NONE,
1668 {(char_u *)"", (char_u *)0L}
1669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001670 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001671 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001673 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001675 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001676 {
1677#if defined(MSDOS) || defined(MSWIN)
1678 (char_u *)":help",
1679#else
1680#ifdef VMS
1681 (char_u *)"help",
1682#else
1683# if defined(OS2)
1684 (char_u *)"view /",
1685# else
1686# ifdef USEMAN_S
1687 (char_u *)"man -s",
1688# else
1689 (char_u *)"man",
1690# endif
1691# endif
1692#endif
1693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001694 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001695 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001696#ifdef FEAT_LANGMAP
1697 (char_u *)&p_langmap, PV_NONE,
1698 {(char_u *)"", /* unmatched } */
1699#else
1700 (char_u *)NULL, PV_NONE,
1701 {(char_u *)NULL,
1702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001703 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001704 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1706 (char_u *)&p_lm, PV_NONE,
1707#else
1708 (char_u *)NULL, PV_NONE,
1709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001711 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1712#ifdef FEAT_LANGMAP
1713 (char_u *)&p_lnr, PV_NONE,
1714#else
1715 (char_u *)NULL, PV_NONE,
1716#endif
1717 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1719#ifdef FEAT_WINDOWS
1720 (char_u *)&p_ls, PV_NONE,
1721#else
1722 (char_u *)NULL, PV_NONE,
1723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1726 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001727 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001728 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1729#ifdef FEAT_LINEBREAK
1730 (char_u *)VAR_WIN, PV_LBR,
1731#else
1732 (char_u *)NULL, PV_NONE,
1733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001734 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1736 (char_u *)&Rows, PV_NONE,
1737 {
1738#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1739 (char_u *)25L,
1740#else
1741 (char_u *)24L,
1742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1745#ifdef FEAT_GUI
1746 (char_u *)&p_linespace, PV_NONE,
1747#else
1748 (char_u *)NULL, PV_NONE,
1749#endif
1750#ifdef FEAT_GUI_W32
1751 {(char_u *)1L, (char_u *)0L}
1752#else
1753 {(char_u *)0L, (char_u *)0L}
1754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001755 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 {"lisp", NULL, P_BOOL|P_VI_DEF,
1757#ifdef FEAT_LISP
1758 (char_u *)&p_lisp, PV_LISP,
1759#else
1760 (char_u *)NULL, PV_NONE,
1761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001762 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001763 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001765 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1767#else
1768 (char_u *)NULL, PV_NONE,
1769 {(char_u *)"", (char_u *)0L}
1770#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1773 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001774 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001775 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1779 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001781#ifdef FEAT_GUI_MAC
1782 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1783 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001785#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"magic", NULL, P_BOOL|P_VI_DEF,
1787 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001789 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790#ifdef FEAT_QUICKFIX
1791 (char_u *)&p_mef, PV_NONE,
1792 {(char_u *)"", (char_u *)0L}
1793#else
1794 (char_u *)NULL, PV_NONE,
1795 {(char_u *)NULL, (char_u *)0L}
1796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001797 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001798 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1799#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001800 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001801# ifdef VMS
1802 {(char_u *)"MMS", (char_u *)0L}
1803# else
1804 {(char_u *)"make", (char_u *)0L}
1805# endif
1806#else
1807 (char_u *)NULL, PV_NONE,
1808 {(char_u *)NULL, (char_u *)0L}
1809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001811 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1814 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 {"matchtime", "mat", P_NUM|P_VI_DEF,
1816 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001818 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001819#ifdef FEAT_MBYTE
1820 (char_u *)&p_mco, PV_NONE,
1821#else
1822 (char_u *)NULL, PV_NONE,
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1826#ifdef FEAT_EVAL
1827 (char_u *)&p_mfd, PV_NONE,
1828#else
1829 (char_u *)NULL, PV_NONE,
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1833 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"maxmem", "mm", P_NUM|P_VI_DEF,
1836 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1838 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001839 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1840 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1843 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1845 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"menuitems", "mis", P_NUM|P_VI_DEF,
1847#ifdef FEAT_MENU
1848 (char_u *)&p_mis, PV_NONE,
1849#else
1850 (char_u *)NULL, PV_NONE,
1851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"mesg", NULL, P_BOOL|P_VI_DEF,
1854 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001856 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001857#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001858 (char_u *)&p_msm, PV_NONE,
1859 {(char_u *)"460000,2000,500", (char_u *)0L}
1860#else
1861 (char_u *)NULL, PV_NONE,
1862 {(char_u *)0L, (char_u *)0L}
1863#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001864 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 {"modeline", "ml", P_BOOL|P_VIM,
1866 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"modelines", "mls", P_NUM|P_VI_DEF,
1869 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1872 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001873 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1875 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"more", NULL, P_BOOL|P_VIM,
1878 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1881 (char_u *)&p_mouse, PV_NONE,
1882 {
1883#if defined(MSDOS) || defined(WIN3264)
1884 (char_u *)"a",
1885#else
1886 (char_u *)"",
1887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1890#ifdef FEAT_GUI
1891 (char_u *)&p_mousef, PV_NONE,
1892#else
1893 (char_u *)NULL, PV_NONE,
1894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1897#ifdef FEAT_GUI
1898 (char_u *)&p_mh, PV_NONE,
1899#else
1900 (char_u *)NULL, PV_NONE,
1901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1904 (char_u *)&p_mousem, PV_NONE,
1905 {
1906#if defined(MSDOS) || defined(MSWIN)
1907 (char_u *)"popup",
1908#else
1909# if defined(MACOS)
1910 (char_u *)"popup_setpos",
1911# else
1912 (char_u *)"extend",
1913# endif
1914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001916 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917#ifdef FEAT_MOUSESHAPE
1918 (char_u *)&p_mouseshape, PV_NONE,
1919 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1920#else
1921 (char_u *)NULL, PV_NONE,
1922 {(char_u *)NULL, (char_u *)0L}
1923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1926 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001928 {"mzquantum", "mzq", P_NUM,
1929#ifdef FEAT_MZSCHEME
1930 (char_u *)&p_mzq, PV_NONE,
1931#else
1932 (char_u *)NULL, PV_NONE,
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"novice", NULL, P_BOOL|P_VI_DEF,
1936 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001938 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)"octal,hex", (char_u *)0L}
1941 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1943 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001945 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1946#ifdef FEAT_LINEBREAK
1947 (char_u *)VAR_WIN, PV_NUW,
1948#else
1949 (char_u *)NULL, PV_NONE,
1950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001952 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001953#ifdef FEAT_COMPL_FUNC
1954 (char_u *)&p_ofu, PV_OFU,
1955 {(char_u *)"", (char_u *)0L}
1956#else
1957 (char_u *)NULL, PV_NONE,
1958 {(char_u *)0L, (char_u *)0L}
1959#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001960 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961 {"open", NULL, P_BOOL|P_VI_DEF,
1962 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001964 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1965#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1966 (char_u *)&p_odev, PV_NONE,
1967#else
1968 (char_u *)NULL, PV_NONE,
1969#endif
1970 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001971 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001972 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1973 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 {"optimize", "opt", P_BOOL|P_VI_DEF,
1976 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001980 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"paragraphs", "para", P_STRING|P_VI_DEF,
1982 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001983 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001985 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1989 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1992#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1993 (char_u *)&p_pex, PV_NONE,
1994 {(char_u *)"", (char_u *)0L}
1995#else
1996 (char_u *)NULL, PV_NONE,
1997 {(char_u *)0L, (char_u *)0L}
1998#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001999 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002000 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002002 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002004 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002005 {
2006#if defined AMIGA || defined MSDOS || defined MSWIN
2007 (char_u *)".,,",
2008#else
2009# if defined(__EMX__)
2010 (char_u *)".,/emx/include,,",
2011# else /* Unix, probably */
2012 (char_u *)".,/usr/include,,",
2013# endif
2014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2017 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002018 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002019 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2021 (char_u *)&p_pvh, PV_NONE,
2022#else
2023 (char_u *)NULL, PV_NONE,
2024#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2027#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2028 (char_u *)VAR_WIN, PV_PVW,
2029#else
2030 (char_u *)NULL, PV_NONE,
2031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002033 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034#ifdef FEAT_PRINTER
2035 (char_u *)&p_pdev, PV_NONE,
2036 {(char_u *)"", (char_u *)0L}
2037#else
2038 (char_u *)NULL, PV_NONE,
2039 {(char_u *)NULL, (char_u *)0L}
2040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"printencoding", "penc", P_STRING|P_VI_DEF,
2043#ifdef FEAT_POSTSCRIPT
2044 (char_u *)&p_penc, PV_NONE,
2045 {(char_u *)"", (char_u *)0L}
2046#else
2047 (char_u *)NULL, PV_NONE,
2048 {(char_u *)NULL, (char_u *)0L}
2049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2052#ifdef FEAT_POSTSCRIPT
2053 (char_u *)&p_pexpr, PV_NONE,
2054 {(char_u *)"", (char_u *)0L}
2055#else
2056 (char_u *)NULL, PV_NONE,
2057 {(char_u *)NULL, (char_u *)0L}
2058#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002059 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002060 {"printfont", "pfn", P_STRING|P_VI_DEF,
2061#ifdef FEAT_PRINTER
2062 (char_u *)&p_pfn, PV_NONE,
2063 {
2064# ifdef MSWIN
2065 (char_u *)"Courier_New:h10",
2066# else
2067 (char_u *)"courier",
2068# endif
2069 (char_u *)0L}
2070#else
2071 (char_u *)NULL, PV_NONE,
2072 {(char_u *)NULL, (char_u *)0L}
2073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002075 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2076#ifdef FEAT_PRINTER
2077 (char_u *)&p_header, PV_NONE,
2078 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2079#else
2080 (char_u *)NULL, PV_NONE,
2081 {(char_u *)NULL, (char_u *)0L}
2082#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002084 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2085#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2086 (char_u *)&p_pmcs, PV_NONE,
2087 {(char_u *)"", (char_u *)0L}
2088#else
2089 (char_u *)NULL, PV_NONE,
2090 {(char_u *)NULL, (char_u *)0L}
2091#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002092 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002093 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2094#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2095 (char_u *)&p_pmfn, PV_NONE,
2096 {(char_u *)"", (char_u *)0L}
2097#else
2098 (char_u *)NULL, PV_NONE,
2099 {(char_u *)NULL, (char_u *)0L}
2100#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002101 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002102 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103#ifdef FEAT_PRINTER
2104 (char_u *)&p_popt, PV_NONE,
2105 {(char_u *)"", (char_u *)0L}
2106#else
2107 (char_u *)NULL, PV_NONE,
2108 {(char_u *)NULL, (char_u *)0L}
2109#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002110 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002112 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002114 {"pumheight", "ph", P_NUM|P_VI_DEF,
2115#ifdef FEAT_INS_EXPAND
2116 (char_u *)&p_ph, PV_NONE,
2117#else
2118 (char_u *)NULL, PV_NONE,
2119#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002121 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2122#ifdef FEAT_TEXTOBJ
2123 (char_u *)&p_qe, PV_QE,
2124 {(char_u *)"\\", (char_u *)0L}
2125#else
2126 (char_u *)NULL, PV_NONE,
2127 {(char_u *)NULL, (char_u *)0L}
2128#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002129 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2131 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002132 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133 {"redraw", NULL, P_BOOL|P_VI_DEF,
2134 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002135 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002136 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2137#ifdef FEAT_RELTIME
2138 (char_u *)&p_rdt, PV_NONE,
2139#else
2140 (char_u *)NULL, PV_NONE,
2141#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002142 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002143 {"regexpengine", "re", P_NUM|P_VI_DEF,
2144 (char_u *)&p_re, PV_NONE,
2145 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002146 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2147 (char_u *)VAR_WIN, PV_RNU,
2148 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 {"remap", NULL, P_BOOL|P_VI_DEF,
2150 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002152 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002153#ifdef FEAT_RENDER_OPTIONS
2154 (char_u *)&p_rop, PV_NONE,
2155 {(char_u *)"", (char_u *)0L}
2156#else
2157 (char_u *)NULL, PV_NONE,
2158 {(char_u *)NULL, (char_u *)0L}
2159#endif
2160 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"report", NULL, P_NUM|P_VI_DEF,
2162 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002163 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002164 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2165#ifdef WIN3264
2166 (char_u *)&p_rs, PV_NONE,
2167#else
2168 (char_u *)NULL, PV_NONE,
2169#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002170 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2172#ifdef FEAT_RIGHTLEFT
2173 (char_u *)&p_ri, PV_NONE,
2174#else
2175 (char_u *)NULL, PV_NONE,
2176#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002177 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2179#ifdef FEAT_RIGHTLEFT
2180 (char_u *)VAR_WIN, PV_RL,
2181#else
2182 (char_u *)NULL, PV_NONE,
2183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002184 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2186#ifdef FEAT_RIGHTLEFT
2187 (char_u *)VAR_WIN, PV_RLC,
2188 {(char_u *)"search", (char_u *)NULL}
2189#else
2190 (char_u *)NULL, PV_NONE,
2191 {(char_u *)NULL, (char_u *)0L}
2192#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2195#ifdef FEAT_CMDL_INFO
2196 (char_u *)&p_ru, PV_NONE,
2197#else
2198 (char_u *)NULL, PV_NONE,
2199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002200 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002201 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2202#ifdef FEAT_STL_OPT
2203 (char_u *)&p_ruf, PV_NONE,
2204#else
2205 (char_u *)NULL, PV_NONE,
2206#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002208 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2209 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002210 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002211 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2212 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002213 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2214 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002215 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002216 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2217#ifdef FEAT_SCROLLBIND
2218 (char_u *)VAR_WIN, PV_SCBIND,
2219#else
2220 (char_u *)NULL, PV_NONE,
2221#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2224 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2227 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002229 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230#ifdef FEAT_SCROLLBIND
2231 (char_u *)&p_sbo, PV_NONE,
2232 {(char_u *)"ver,jump", (char_u *)0L}
2233#else
2234 (char_u *)NULL, PV_NONE,
2235 {(char_u *)0L, (char_u *)0L}
2236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 {"sections", "sect", P_STRING|P_VI_DEF,
2239 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002240 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2241 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2243 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002244 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002245 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002246 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002247 {(char_u *)"inclusive", (char_u *)0L}
2248 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002249 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002251 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002252 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002253#ifdef FEAT_SESSION
2254 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002255 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002256 (char_u *)0L}
2257#else
2258 (char_u *)NULL, PV_NONE,
2259 {(char_u *)0L, (char_u *)0L}
2260#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002261 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2263 (char_u *)&p_sh, PV_NONE,
2264 {
2265#ifdef VMS
2266 (char_u *)"-",
2267#else
2268# if defined(MSDOS)
2269 (char_u *)"command",
2270# else
2271# if defined(WIN16)
2272 (char_u *)"command.com",
2273# else
2274# if defined(WIN3264)
2275 (char_u *)"", /* set in set_init_1() */
2276# else
2277# if defined(OS2)
2278 (char_u *)"cmd.exe",
2279# else
2280# if defined(ARCHIE)
2281 (char_u *)"gos",
2282# else
2283 (char_u *)"sh",
2284# endif
2285# endif
2286# endif
2287# endif
2288# endif
2289#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2292 (char_u *)&p_shcf, PV_NONE,
2293 {
2294#if defined(MSDOS) || defined(MSWIN)
2295 (char_u *)"/c",
2296#else
2297# if defined(OS2)
2298 (char_u *)"/c",
2299# else
2300 (char_u *)"-c",
2301# endif
2302#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002303 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2305#ifdef FEAT_QUICKFIX
2306 (char_u *)&p_sp, PV_NONE,
2307 {
2308#if defined(UNIX) || defined(OS2)
2309# ifdef ARCHIE
2310 (char_u *)"2>",
2311# else
2312 (char_u *)"| tee",
2313# endif
2314#else
2315 (char_u *)">",
2316#endif
2317 (char_u *)0L}
2318#else
2319 (char_u *)NULL, PV_NONE,
2320 {(char_u *)0L, (char_u *)0L}
2321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002322 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2324 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002325 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2327 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2330#ifdef BACKSLASH_IN_FILENAME
2331 (char_u *)&p_ssl, PV_NONE,
2332#else
2333 (char_u *)NULL, PV_NONE,
2334#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002336 {"shelltemp", "stmp", P_BOOL,
2337 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002338 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 {"shelltype", "st", P_NUM|P_VI_DEF,
2340#ifdef AMIGA
2341 (char_u *)&p_st, PV_NONE,
2342#else
2343 (char_u *)NULL, PV_NONE,
2344#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002345 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2347 (char_u *)&p_sxq, PV_NONE,
2348 {
2349#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2350 (char_u *)"\"",
2351#else
2352 (char_u *)"",
2353#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002355 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2356 (char_u *)&p_sxe, PV_NONE,
2357 {
2358#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2359 (char_u *)"\"&|<>()@^",
2360#else
2361 (char_u *)"",
2362#endif
2363 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2365 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2368 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2371 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002372 {(char_u *)"", (char_u *)"filnxtToO"}
2373 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"shortname", "sn", P_BOOL|P_VI_DEF,
2375#ifdef SHORT_FNAME
2376 (char_u *)NULL, PV_NONE,
2377#else
2378 (char_u *)&p_sn, PV_SN,
2379#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2382#ifdef FEAT_LINEBREAK
2383 (char_u *)&p_sbr, PV_NONE,
2384#else
2385 (char_u *)NULL, PV_NONE,
2386#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"showcmd", "sc", P_BOOL|P_VIM,
2389#ifdef FEAT_CMDL_INFO
2390 (char_u *)&p_sc, PV_NONE,
2391#else
2392 (char_u *)NULL, PV_NONE,
2393#endif
2394 {(char_u *)FALSE,
2395#ifdef UNIX
2396 (char_u *)FALSE
2397#else
2398 (char_u *)TRUE
2399#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2402 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2405 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"showmode", "smd", P_BOOL|P_VIM,
2408 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002410 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2411#ifdef FEAT_WINDOWS
2412 (char_u *)&p_stal, PV_NONE,
2413#else
2414 (char_u *)NULL, PV_NONE,
2415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2418 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002419 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2421 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2424 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2427 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2430#ifdef FEAT_SMARTINDENT
2431 (char_u *)&p_si, PV_SI,
2432#else
2433 (char_u *)NULL, PV_NONE,
2434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2437 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2440 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2443 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002445 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002446#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002447 (char_u *)VAR_WIN, PV_SPELL,
2448#else
2449 (char_u *)NULL, PV_NONE,
2450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002452 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002453#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002454 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002455 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002456#else
2457 (char_u *)NULL, PV_NONE,
2458 {(char_u *)0L, (char_u *)0L}
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002461 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2462 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002463#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002464 (char_u *)&p_spf, PV_SPF,
2465 {(char_u *)"", (char_u *)0L}
2466#else
2467 (char_u *)NULL, PV_NONE,
2468 {(char_u *)0L, (char_u *)0L}
2469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002471 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2472 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002473#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002474 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002475 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002476#else
2477 (char_u *)NULL, PV_NONE,
2478 {(char_u *)0L, (char_u *)0L}
2479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002480 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002481 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002482#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002483 (char_u *)&p_sps, PV_NONE,
2484 {(char_u *)"best", (char_u *)0L}
2485#else
2486 (char_u *)NULL, PV_NONE,
2487 {(char_u *)0L, (char_u *)0L}
2488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2491#ifdef FEAT_WINDOWS
2492 (char_u *)&p_sb, PV_NONE,
2493#else
2494 (char_u *)NULL, PV_NONE,
2495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"splitright", "spr", P_BOOL|P_VI_DEF,
2498#ifdef FEAT_VERTSPLIT
2499 (char_u *)&p_spr, PV_NONE,
2500#else
2501 (char_u *)NULL, PV_NONE,
2502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2505 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002506 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2508#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002509 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510#else
2511 (char_u *)NULL, PV_NONE,
2512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002513 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002514 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 (char_u *)&p_su, PV_NONE,
2516 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002517 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002518 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002519#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 (char_u *)&p_sua, PV_SUA,
2521 {(char_u *)"", (char_u *)0L}
2522#else
2523 (char_u *)NULL, PV_NONE,
2524 {(char_u *)0L, (char_u *)0L}
2525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2528 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 {"swapsync", "sws", P_STRING|P_VI_DEF,
2531 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002533 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002535 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002536 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2537#ifdef FEAT_SYN_HL
2538 (char_u *)&p_smc, PV_SMC,
2539 {(char_u *)3000L, (char_u *)0L}
2540#else
2541 (char_u *)NULL, PV_NONE,
2542 {(char_u *)0L, (char_u *)0L}
2543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002545 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546#ifdef FEAT_SYN_HL
2547 (char_u *)&p_syn, PV_SYN,
2548 {(char_u *)"", (char_u *)0L}
2549#else
2550 (char_u *)NULL, PV_NONE,
2551 {(char_u *)0L, (char_u *)0L}
2552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002554 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2555#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002556 (char_u *)&p_tal, PV_NONE,
2557#else
2558 (char_u *)NULL, PV_NONE,
2559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002561 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2562#ifdef FEAT_WINDOWS
2563 (char_u *)&p_tpm, PV_NONE,
2564#else
2565 (char_u *)NULL, PV_NONE,
2566#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002567 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2569 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002570 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2572 (char_u *)&p_tbs, PV_NONE,
2573#ifdef VMS /* binary searching doesn't appear to work on VMS */
2574 {(char_u *)0L, (char_u *)0L}
2575#else
2576 {(char_u *)TRUE, (char_u *)0L}
2577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"taglength", "tl", P_NUM|P_VI_DEF,
2580 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"tagrelative", "tr", P_BOOL|P_VIM,
2583 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002585 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002586 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {
2588#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2589 (char_u *)"./tags,./TAGS,tags,TAGS",
2590#else
2591 (char_u *)"./tags,tags",
2592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2595 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2598 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002599 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2601#ifdef FEAT_ARABIC
2602 (char_u *)&p_tbidi, PV_NONE,
2603#else
2604 (char_u *)NULL, PV_NONE,
2605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002606 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2608#ifdef FEAT_MBYTE
2609 (char_u *)&p_tenc, PV_NONE,
2610 {(char_u *)"", (char_u *)0L}
2611#else
2612 (char_u *)NULL, PV_NONE,
2613 {(char_u *)0L, (char_u *)0L}
2614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002615 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 {"terse", NULL, P_BOOL|P_VI_DEF,
2617 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 {"textauto", "ta", P_BOOL|P_VIM,
2620 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2622 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2624 (char_u *)&p_tx, PV_TX,
2625 {
2626#ifdef USE_CRNL
2627 (char_u *)TRUE,
2628#else
2629 (char_u *)FALSE,
2630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002632 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002635 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002637 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638#else
2639 (char_u *)NULL, PV_NONE,
2640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002641 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2643 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"timeout", "to", P_BOOL|P_VI_DEF,
2646 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2649 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002650 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"title", NULL, P_BOOL|P_VI_DEF,
2652#ifdef FEAT_TITLE
2653 (char_u *)&p_title, PV_NONE,
2654#else
2655 (char_u *)NULL, PV_NONE,
2656#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 {"titlelen", NULL, P_NUM|P_VI_DEF,
2659#ifdef FEAT_TITLE
2660 (char_u *)&p_titlelen, PV_NONE,
2661#else
2662 (char_u *)NULL, PV_NONE,
2663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002665 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666#ifdef FEAT_TITLE
2667 (char_u *)&p_titleold, PV_NONE,
2668 {(char_u *)N_("Thanks for flying Vim"),
2669 (char_u *)0L}
2670#else
2671 (char_u *)NULL, PV_NONE,
2672 {(char_u *)0L, (char_u *)0L}
2673#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002674 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"titlestring", NULL, P_STRING|P_VI_DEF,
2676#ifdef FEAT_TITLE
2677 (char_u *)&p_titlestring, PV_NONE,
2678#else
2679 (char_u *)NULL, PV_NONE,
2680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002681 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002683 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002685 {(char_u *)"icons,tooltips", (char_u *)0L}
2686 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002688#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2690 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692#endif
2693 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2694 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002695 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2697 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2700 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2703 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2706#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2707 (char_u *)&p_ttym, PV_NONE,
2708#else
2709 (char_u *)NULL, PV_NONE,
2710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2713 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2716 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002718 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2719 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002720#ifdef FEAT_PERSISTENT_UNDO
2721 (char_u *)&p_udir, PV_NONE,
2722 {(char_u *)".", (char_u *)0L}
2723#else
2724 (char_u *)NULL, PV_NONE,
2725 {(char_u *)0L, (char_u *)0L}
2726#endif
2727 SCRIPTID_INIT},
2728 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2729#ifdef FEAT_PERSISTENT_UNDO
2730 (char_u *)&p_udf, PV_UDF,
2731#else
2732 (char_u *)NULL, PV_NONE,
2733#endif
2734 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002735 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002736 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002737 {
2738#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2739 (char_u *)1000L,
2740#else
2741 (char_u *)100L,
2742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002743 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002744 {"undoreload", "ur", P_NUM|P_VI_DEF,
2745 (char_u *)&p_ur, PV_NONE,
2746 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"updatecount", "uc", P_NUM|P_VI_DEF,
2748 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"updatetime", "ut", P_NUM|P_VI_DEF,
2751 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002752 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"verbose", "vbs", P_NUM|P_VI_DEF,
2754 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002756 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2757 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2760#ifdef FEAT_SESSION
2761 (char_u *)&p_vdir, PV_NONE,
2762 {(char_u *)DFLT_VDIR, (char_u *)0L}
2763#else
2764 (char_u *)NULL, PV_NONE,
2765 {(char_u *)0L, (char_u *)0L}
2766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002768 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769#ifdef FEAT_SESSION
2770 (char_u *)&p_vop, PV_NONE,
2771 {(char_u *)"folds,options,cursor", (char_u *)0L}
2772#else
2773 (char_u *)NULL, PV_NONE,
2774 {(char_u *)0L, (char_u *)0L}
2775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002776 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002777 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778#ifdef FEAT_VIMINFO
2779 (char_u *)&p_viminfo, PV_NONE,
2780#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002781 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782#else
2783# ifdef AMIGA
2784 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002785 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002787 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788# endif
2789#endif
2790#else
2791 (char_u *)NULL, PV_NONE,
2792 {(char_u *)0L, (char_u *)0L}
2793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002795 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2796 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797#ifdef FEAT_VIRTUALEDIT
2798 (char_u *)&p_ve, PV_NONE,
2799 {(char_u *)"", (char_u *)""}
2800#else
2801 (char_u *)NULL, PV_NONE,
2802 {(char_u *)0L, (char_u *)0L}
2803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2806 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"w300", NULL, P_NUM|P_VI_DEF,
2809 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"w1200", NULL, P_NUM|P_VI_DEF,
2812 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"w9600", NULL, P_NUM|P_VI_DEF,
2815 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"warn", NULL, P_BOOL|P_VI_DEF,
2818 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2821 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002823 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"wildchar", "wc", P_NUM|P_VIM,
2827 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2829 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002830 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002833 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834#ifdef FEAT_WILDIGN
2835 (char_u *)&p_wig, PV_NONE,
2836#else
2837 (char_u *)NULL, PV_NONE,
2838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002840 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2841 (char_u *)&p_wic, PV_NONE,
2842 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2844#ifdef FEAT_WILDMENU
2845 (char_u *)&p_wmnu, PV_NONE,
2846#else
2847 (char_u *)NULL, PV_NONE,
2848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002850 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002853 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2854#ifdef FEAT_CMDL_COMPL
2855 (char_u *)&p_wop, PV_NONE,
2856 {(char_u *)"", (char_u *)0L}
2857#else
2858 (char_u *)NULL, PV_NONE,
2859 {(char_u *)NULL, (char_u *)0L}
2860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002861 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2863#ifdef FEAT_WAK
2864 (char_u *)&p_wak, PV_NONE,
2865 {(char_u *)"menu", (char_u *)0L}
2866#else
2867 (char_u *)NULL, PV_NONE,
2868 {(char_u *)NULL, (char_u *)0L}
2869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002872 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {"winheight", "wh", P_NUM|P_VI_DEF,
2875#ifdef FEAT_WINDOWS
2876 (char_u *)&p_wh, PV_NONE,
2877#else
2878 (char_u *)NULL, PV_NONE,
2879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002880 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002882#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 (char_u *)VAR_WIN, PV_WFH,
2884#else
2885 (char_u *)NULL, PV_NONE,
2886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002887 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002888 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2889#ifdef FEAT_VERTSPLIT
2890 (char_u *)VAR_WIN, PV_WFW,
2891#else
2892 (char_u *)NULL, PV_NONE,
2893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002894 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2896#ifdef FEAT_WINDOWS
2897 (char_u *)&p_wmh, PV_NONE,
2898#else
2899 (char_u *)NULL, PV_NONE,
2900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002901 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2903#ifdef FEAT_VERTSPLIT
2904 (char_u *)&p_wmw, PV_NONE,
2905#else
2906 (char_u *)NULL, PV_NONE,
2907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002908 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2910#ifdef FEAT_VERTSPLIT
2911 (char_u *)&p_wiw, PV_NONE,
2912#else
2913 (char_u *)NULL, PV_NONE,
2914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002915 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2917 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002918 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2920 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2923 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"write", NULL, P_BOOL|P_VI_DEF,
2926 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002927 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"writeany", "wa", P_BOOL|P_VI_DEF,
2929 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002930 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2932 (char_u *)&p_wb, PV_NONE,
2933 {
2934#ifdef FEAT_WRITEBACKUP
2935 (char_u *)TRUE,
2936#else
2937 (char_u *)FALSE,
2938#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940 {"writedelay", "wd", P_NUM|P_VI_DEF,
2941 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002942 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943
2944/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002945#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002947 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948
2949 p_term("t_AB", T_CAB)
2950 p_term("t_AF", T_CAF)
2951 p_term("t_AL", T_CAL)
2952 p_term("t_al", T_AL)
2953 p_term("t_bc", T_BC)
2954 p_term("t_cd", T_CD)
2955 p_term("t_ce", T_CE)
2956 p_term("t_cl", T_CL)
2957 p_term("t_cm", T_CM)
2958 p_term("t_Co", T_CCO)
2959 p_term("t_CS", T_CCS)
2960 p_term("t_cs", T_CS)
2961#ifdef FEAT_VERTSPLIT
2962 p_term("t_CV", T_CSV)
2963#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 p_term("t_da", T_DA)
2965 p_term("t_db", T_DB)
2966 p_term("t_DL", T_CDL)
2967 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002968 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 p_term("t_fs", T_FS)
2970 p_term("t_IE", T_CIE)
2971 p_term("t_IS", T_CIS)
2972 p_term("t_ke", T_KE)
2973 p_term("t_ks", T_KS)
2974 p_term("t_le", T_LE)
2975 p_term("t_mb", T_MB)
2976 p_term("t_md", T_MD)
2977 p_term("t_me", T_ME)
2978 p_term("t_mr", T_MR)
2979 p_term("t_ms", T_MS)
2980 p_term("t_nd", T_ND)
2981 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002982 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 p_term("t_RI", T_CRI)
2984 p_term("t_RV", T_CRV)
2985 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002987 p_term("t_Sf", T_CSF)
2988 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02002990 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 p_term("t_te", T_TE)
2993 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02002994 p_term("t_ts", T_TS)
2995 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 p_term("t_ue", T_UE)
2997 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02002998 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 p_term("t_vb", T_VB)
3000 p_term("t_ve", T_VE)
3001 p_term("t_vi", T_VI)
3002 p_term("t_vs", T_VS)
3003 p_term("t_WP", T_CWP)
3004 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003005 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 p_term("t_xs", T_XS)
3007 p_term("t_ZH", T_CZH)
3008 p_term("t_ZR", T_CZR)
3009
3010/* terminal key codes are not in here */
3011
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003012 /* end marker */
3013 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014};
3015
3016#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3017
3018#ifdef FEAT_MBYTE
3019static char *(p_ambw_values[]) = {"single", "double", NULL};
3020#endif
3021static char *(p_bg_values[]) = {"light", "dark", NULL};
3022static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
3023static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003024#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003025static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003026#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003027#ifdef FEAT_CMDL_COMPL
3028static char *(p_wop_values[]) = {"tagfile", NULL};
3029#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030#ifdef FEAT_WAK
3031static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3032#endif
3033static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3035static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037#ifdef FEAT_BROWSE
3038static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3039#endif
3040#ifdef FEAT_SCROLLBIND
3041static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3042#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003043static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044#ifdef FEAT_VERTSPLIT
3045static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3046#endif
3047#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003048# ifdef FEAT_AUTOCMD
3049static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3050# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003052# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3054#endif
3055static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3056#ifdef FEAT_FOLDING
3057static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003058# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003060# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 NULL};
3062static char *(p_fcl_values[]) = {"all", NULL};
3063#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003064#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003065static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003066#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067
3068static void set_option_default __ARGS((int, int opt_flags, int compatible));
3069static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003070static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003071static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072static char_u *illegal_char __ARGS((char_u *, int));
3073static int string_to_key __ARGS((char_u *arg));
3074#ifdef FEAT_CMDWIN
3075static char_u *check_cedit __ARGS((void));
3076#endif
3077#ifdef FEAT_TITLE
3078static void did_set_title __ARGS((int icon));
3079#endif
3080static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3081static void didset_options __ARGS((void));
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003082static void didset_options2 __ARGS((void));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003084#if defined(FEAT_EVAL) || defined(PROTO)
3085static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3086#else
3087# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3088#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003090static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091static 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));
3092static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003093#ifdef FEAT_SYN_HL
3094static int int_cmp __ARGS((const void *a, const void *b));
3095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096#ifdef FEAT_CLIPBOARD
3097static char_u *check_clipboard_option __ARGS((void));
3098#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003099#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003100static char_u *did_set_spell_option __ARGS((int is_spellfile));
Bram Moolenaar860cae12010-06-05 23:22:07 +02003101static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003102#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003103#ifdef FEAT_EVAL
3104static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3105#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003107static 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 +00003108static void check_redraw __ARGS((long_u flags));
3109static int findoption __ARGS((char_u *));
3110static int find_key_option __ARGS((char_u *));
3111static void showoptions __ARGS((int all, int opt_flags));
3112static int optval_default __ARGS((struct vimoption *, char_u *varp));
3113static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3114static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3115static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3116static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3117static int istermoption __ARGS((struct vimoption *));
3118static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3119static char_u *get_varp __ARGS((struct vimoption *));
3120static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003121static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3123#ifdef FEAT_LANGMAP
3124static void langmap_init __ARGS((void));
3125static void langmap_set __ARGS((void));
3126#endif
3127static void paste_option_changed __ARGS((void));
3128static void compatible_set __ARGS((void));
3129#ifdef FEAT_LINEBREAK
3130static void fill_breakat_flags __ARGS((void));
3131#endif
3132static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3133static int check_opt_strings __ARGS((char_u *val, char **values, int));
3134static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003135#ifdef FEAT_LINEBREAK
3136static int briopt_check __ARGS((win_T *wp));
3137#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138
3139/*
3140 * Initialize the options, first part.
3141 *
3142 * Called only once from main(), just after creating the first buffer.
3143 */
3144 void
3145set_init_1()
3146{
3147 char_u *p;
3148 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003149 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150
3151#ifdef FEAT_LANGMAP
3152 langmap_init();
3153#endif
3154
3155 /* Be Vi compatible by default */
3156 p_cp = TRUE;
3157
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003158 /* Use POSIX compatibility when $VIM_POSIX is set. */
3159 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003160 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003161 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003162 set_string_default("shm", (char_u *)"A");
3163 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003164
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 /*
3166 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003167 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003169 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3171# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003172 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003174 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003176 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177# endif
3178#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003179 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 set_string_default("sh", p);
3181
3182#ifdef FEAT_WILDIGN
3183 /*
3184 * Set the default for 'backupskip' to include environment variables for
3185 * temp files.
3186 */
3187 {
3188# ifdef UNIX
3189 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3190# else
3191 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3192# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003193 int len;
3194 garray_T ga;
3195 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196
3197 ga_init2(&ga, 1, 100);
3198 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3199 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003200 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201# ifdef UNIX
3202 if (*names[n] == NUL)
3203 p = (char_u *)"/tmp";
3204 else
3205# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003206 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207 if (p != NULL && *p != NUL)
3208 {
3209 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003210 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211 if (ga_grow(&ga, len) == OK)
3212 {
3213 if (ga.ga_len > 0)
3214 STRCAT(ga.ga_data, ",");
3215 STRCAT(ga.ga_data, p);
3216 add_pathsep(ga.ga_data);
3217 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218 ga.ga_len += len;
3219 }
3220 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003221 if (mustfree)
3222 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 }
3224 if (ga.ga_data != NULL)
3225 {
3226 set_string_default("bsk", ga.ga_data);
3227 vim_free(ga.ga_data);
3228 }
3229 }
3230#endif
3231
3232 /*
3233 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3234 */
3235 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003236 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003238#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3239 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3240#endif
3241 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003243 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003244 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245#else
3246# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003247 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003248 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003250 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251# endif
3252#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003254 opt_idx = findoption((char_u *)"maxmem");
3255 if (opt_idx >= 0)
3256 {
3257#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003258 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3260#endif
3261 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3262 }
3263 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264 }
3265
3266#ifdef FEAT_GUI_W32
3267 /* force 'shortname' for Win32s */
3268 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003269 {
3270 opt_idx = findoption((char_u *)"shortname");
3271 if (opt_idx >= 0)
3272 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3273 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274#endif
3275
3276#ifdef FEAT_SEARCHPATH
3277 {
3278 char_u *cdpath;
3279 char_u *buf;
3280 int i;
3281 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003282 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283
3284 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003285 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286 if (cdpath != NULL)
3287 {
3288 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3289 if (buf != NULL)
3290 {
3291 buf[0] = ','; /* start with ",", current dir first */
3292 j = 1;
3293 for (i = 0; cdpath[i] != NUL; ++i)
3294 {
3295 if (vim_ispathlistsep(cdpath[i]))
3296 buf[j++] = ',';
3297 else
3298 {
3299 if (cdpath[i] == ' ' || cdpath[i] == ',')
3300 buf[j++] = '\\';
3301 buf[j++] = cdpath[i];
3302 }
3303 }
3304 buf[j] = NUL;
3305 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003306 if (opt_idx >= 0)
3307 {
3308 options[opt_idx].def_val[VI_DEFAULT] = buf;
3309 options[opt_idx].flags |= P_DEF_ALLOCED;
3310 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003311 else
3312 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003314 if (mustfree)
3315 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316 }
3317 }
3318#endif
3319
3320#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3321 /* Set print encoding on platforms that don't default to latin1 */
3322 set_string_default("penc",
3323# if defined(MSWIN) || defined(OS2)
3324 (char_u *)"cp1252"
3325# else
3326# ifdef VMS
3327 (char_u *)"dec-mcs"
3328# else
3329# ifdef EBCDIC
3330 (char_u *)"ebcdic-uk"
3331# else
3332# ifdef MAC
3333 (char_u *)"mac-roman"
3334# else /* HPUX */
3335 (char_u *)"hp-roman8"
3336# endif
3337# endif
3338# endif
3339# endif
3340 );
3341#endif
3342
3343#ifdef FEAT_POSTSCRIPT
3344 /* 'printexpr' must be allocated to be able to evaluate it. */
3345 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003346# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3347 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348# else
3349# ifdef VMS
3350 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3351
3352# else
3353 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3354# endif
3355# endif
3356 );
3357#endif
3358
3359 /*
3360 * Set all the options (except the terminal options) to their default
3361 * value. Also set the global value for local options.
3362 */
3363 set_options_default(0);
3364
3365#ifdef FEAT_GUI
3366 if (found_reverse_arg)
3367 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3368#endif
3369
3370 curbuf->b_p_initialized = TRUE;
3371 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003372 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373 check_buf_options(curbuf);
3374 check_win_options(curwin);
3375 check_options();
3376
3377 /* Must be before option_expand(), because that one needs vim_isIDc() */
3378 didset_options();
3379
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003380#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003381 /* Use the current chartab for the generic chartab. This is not in
3382 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003383 init_spell_chartab();
3384#endif
3385
Bram Moolenaar071d4272004-06-13 20:20:40 +00003386 /*
3387 * Expand environment variables and things like "~" for the defaults.
3388 * If option_expand() returns non-NULL the variable is expanded. This can
3389 * only happen for non-indirect options.
3390 * Also set the default to the expanded value, so ":set" does not list
3391 * them.
3392 * Don't set the P_ALLOCED flag, because we don't want to free the
3393 * default.
3394 */
3395 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3396 {
3397 if ((options[opt_idx].flags & P_GETTEXT)
3398 && options[opt_idx].var != NULL)
3399 p = (char_u *)_(*(char **)options[opt_idx].var);
3400 else
3401 p = option_expand(opt_idx, NULL);
3402 if (p != NULL && (p = vim_strsave(p)) != NULL)
3403 {
3404 *(char_u **)options[opt_idx].var = p;
3405 /* VIMEXP
3406 * Defaults for all expanded options are currently the same for Vi
3407 * and Vim. When this changes, add some code here! Also need to
3408 * split P_DEF_ALLOCED in two.
3409 */
3410 if (options[opt_idx].flags & P_DEF_ALLOCED)
3411 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3412 options[opt_idx].def_val[VI_DEFAULT] = p;
3413 options[opt_idx].flags |= P_DEF_ALLOCED;
3414 }
3415 }
3416
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417 save_file_ff(curbuf); /* Buffer is unchanged */
3418
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419#if defined(FEAT_ARABIC)
3420 /* Detect use of mlterm.
3421 * Mlterm is a terminal emulator akin to xterm that has some special
3422 * abilities (bidi namely).
3423 * NOTE: mlterm's author is being asked to 'set' a variable
3424 * instead of an environment variable due to inheritance.
3425 */
3426 if (mch_getenv((char_u *)"MLTERM") != NULL)
3427 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3428#endif
3429
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003430 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431
3432#ifdef FEAT_MBYTE
3433# if defined(WIN3264) && defined(FEAT_GETTEXT)
3434 /*
3435 * If $LANG isn't set, try to get a good value for it. This makes the
3436 * right language be used automatically. Don't do this for English.
3437 */
3438 if (mch_getenv((char_u *)"LANG") == NULL)
3439 {
3440 char buf[20];
3441
3442 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3443 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3444 * only the first two. */
3445 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3446 (LPTSTR)buf, 20);
3447 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3448 {
3449 /* There are a few exceptions (probably more) */
3450 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3451 STRCPY(buf, "zh_TW");
3452 else if (STRNICMP(buf, "chs", 3) == 0
3453 || STRNICMP(buf, "zhc", 3) == 0)
3454 STRCPY(buf, "zh_CN");
3455 else if (STRNICMP(buf, "jp", 2) == 0)
3456 STRCPY(buf, "ja");
3457 else
3458 buf[2] = NUL; /* truncate to two-letter code */
3459 vim_setenv("LANG", buf);
3460 }
3461 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003462# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003463# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003464 /* Moved to os_mac_conv.c to avoid dependency problems. */
3465 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003466# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467# endif
3468
3469 /* enc_locale() will try to find the encoding of the current locale. */
3470 p = enc_locale();
3471 if (p != NULL)
3472 {
3473 char_u *save_enc;
3474
3475 /* Try setting 'encoding' and check if the value is valid.
3476 * If not, go back to the default "latin1". */
3477 save_enc = p_enc;
3478 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003479 if (STRCMP(p_enc, "gb18030") == 0)
3480 {
3481 /* We don't support "gb18030", but "cp936" is a good substitute
3482 * for practical purposes, thus use that. It's not an alias to
3483 * still support conversion between gb18030 and utf-8. */
3484 p_enc = vim_strsave((char_u *)"cp936");
3485 vim_free(p);
3486 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487 if (mb_init() == NULL)
3488 {
3489 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003490 if (opt_idx >= 0)
3491 {
3492 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3493 options[opt_idx].flags |= P_DEF_ALLOCED;
3494 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003495
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003496#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3497 || defined(VMS)
3498 if (STRCMP(p_enc, "latin1") == 0
3499# ifdef FEAT_MBYTE
3500 || enc_utf8
3501# endif
3502 )
3503 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003504 /* Adjust the default for 'isprint' and 'iskeyword' to match
3505 * latin1. Also set the defaults for when 'nocompatible' is
3506 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003507 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003508 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003509 set_string_option_direct((char_u *)"isk", -1,
3510 ISK_LATIN1, OPT_FREE, SID_NONE);
3511 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003512 if (opt_idx >= 0)
3513 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003514 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003515 if (opt_idx >= 0)
3516 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003517 (void)init_chartab();
3518 }
3519#endif
3520
Bram Moolenaar071d4272004-06-13 20:20:40 +00003521# if defined(WIN3264) && !defined(FEAT_GUI)
3522 /* Win32 console: When GetACP() returns a different value from
3523 * GetConsoleCP() set 'termencoding'. */
3524 if (GetACP() != GetConsoleCP())
3525 {
3526 char buf[50];
3527
3528 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3529 p_tenc = vim_strsave((char_u *)buf);
3530 if (p_tenc != NULL)
3531 {
3532 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003533 if (opt_idx >= 0)
3534 {
3535 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3536 options[opt_idx].flags |= P_DEF_ALLOCED;
3537 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003538 convert_setup(&input_conv, p_tenc, p_enc);
3539 convert_setup(&output_conv, p_enc, p_tenc);
3540 }
3541 else
3542 p_tenc = empty_option;
3543 }
3544# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003545# if defined(WIN3264) && defined(FEAT_MBYTE)
3546 /* $HOME may have characters in active code page. */
3547 init_homedir();
3548# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003549 }
3550 else
3551 {
3552 vim_free(p_enc);
3553 p_enc = save_enc;
3554 }
3555 }
3556#endif
3557
3558#ifdef FEAT_MULTI_LANG
3559 /* Set the default for 'helplang'. */
3560 set_helplang_default(get_mess_lang());
3561#endif
3562}
3563
3564/*
3565 * Set an option to its default value.
3566 * This does not take care of side effects!
3567 */
3568 static void
3569set_option_default(opt_idx, opt_flags, compatible)
3570 int opt_idx;
3571 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3572 int compatible; /* use Vi default value */
3573{
3574 char_u *varp; /* pointer to variable for current option */
3575 int dvi; /* index in def_val[] */
3576 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003577 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003578 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3579
3580 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3581 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003582 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003583 {
3584 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3585 if (flags & P_STRING)
3586 {
3587 /* Use set_string_option_direct() for local options to handle
3588 * freeing and allocating the value. */
3589 if (options[opt_idx].indir != PV_NONE)
3590 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003591 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592 else
3593 {
3594 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3595 free_string_option(*(char_u **)(varp));
3596 *(char_u **)varp = options[opt_idx].def_val[dvi];
3597 options[opt_idx].flags &= ~P_ALLOCED;
3598 }
3599 }
3600 else if (flags & P_NUM)
3601 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003602 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603 win_comp_scroll(curwin);
3604 else
3605 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003606 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003607 /* May also set global value for local option. */
3608 if (both)
3609 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3610 *(long *)varp;
3611 }
3612 }
3613 else /* P_BOOL */
3614 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003615 /* the cast to long is required for Manx C, long_i is needed for
3616 * MSVC */
3617 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003618#ifdef UNIX
3619 /* 'modeline' defaults to off for root */
3620 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3621 *(int *)varp = FALSE;
3622#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623 /* May also set global value for local option. */
3624 if (both)
3625 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3626 *(int *)varp;
3627 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003628
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003629 /* The default value is not insecure. */
3630 flagsp = insecure_flag(opt_idx, opt_flags);
3631 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632 }
3633
3634#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003635 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636#endif
3637}
3638
3639/*
3640 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003641 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003642 */
3643 static void
3644set_options_default(opt_flags)
3645 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3646{
3647 int i;
3648#ifdef FEAT_WINDOWS
3649 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003650 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651#endif
3652
3653 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003654 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003655#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003656 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003657 || (TRUE
3658# if defined(FEAT_MBYTE)
3659 && options[i].var != (char_u *)&p_enc
3660# endif
3661# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003662 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003663 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003664# endif
3665 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003666#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003667 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003668 set_option_default(i, opt_flags, p_cp);
3669
3670#ifdef FEAT_WINDOWS
3671 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003672 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003673 win_comp_scroll(wp);
3674#else
3675 win_comp_scroll(curwin);
3676#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003677#ifdef FEAT_CINDENT
3678 parse_cino(curbuf);
3679#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680}
3681
3682/*
3683 * Set the Vi-default value of a string option.
3684 * Used for 'sh', 'backupskip' and 'term'.
3685 */
3686 void
3687set_string_default(name, val)
3688 char *name;
3689 char_u *val;
3690{
3691 char_u *p;
3692 int opt_idx;
3693
3694 p = vim_strsave(val);
3695 if (p != NULL) /* we don't want a NULL */
3696 {
3697 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003698 if (opt_idx >= 0)
3699 {
3700 if (options[opt_idx].flags & P_DEF_ALLOCED)
3701 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3702 options[opt_idx].def_val[VI_DEFAULT] = p;
3703 options[opt_idx].flags |= P_DEF_ALLOCED;
3704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705 }
3706}
3707
3708/*
3709 * Set the Vi-default value of a number option.
3710 * Used for 'lines' and 'columns'.
3711 */
3712 void
3713set_number_default(name, val)
3714 char *name;
3715 long val;
3716{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003717 int opt_idx;
3718
3719 opt_idx = findoption((char_u *)name);
3720 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003721 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722}
3723
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003724#if defined(EXITFREE) || defined(PROTO)
3725/*
3726 * Free all options.
3727 */
3728 void
3729free_all_options()
3730{
3731 int i;
3732
3733 for (i = 0; !istermoption(&options[i]); i++)
3734 {
3735 if (options[i].indir == PV_NONE)
3736 {
3737 /* global option: free value and default value. */
3738 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3739 free_string_option(*(char_u **)options[i].var);
3740 if (options[i].flags & P_DEF_ALLOCED)
3741 free_string_option(options[i].def_val[VI_DEFAULT]);
3742 }
3743 else if (options[i].var != VAR_WIN
3744 && (options[i].flags & P_STRING))
3745 /* buffer-local option: free global value */
3746 free_string_option(*(char_u **)options[i].var);
3747 }
3748}
3749#endif
3750
3751
Bram Moolenaar071d4272004-06-13 20:20:40 +00003752/*
3753 * Initialize the options, part two: After getting Rows and Columns and
3754 * setting 'term'.
3755 */
3756 void
3757set_init_2()
3758{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003759 int idx;
3760
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761 /*
3762 * 'scroll' defaults to half the window height. Note that this default is
3763 * wrong when the window height changes.
3764 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003765 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003766 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003767 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003768 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 comp_col();
3770
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003771 /*
3772 * 'window' is only for backwards compatibility with Vi.
3773 * Default is Rows - 1.
3774 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003775 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003776 p_window = Rows - 1;
3777 set_number_default("window", Rows - 1);
3778
Bram Moolenaarf740b292006-02-16 22:11:02 +00003779 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003781 /*
3782 * If 'background' wasn't set by the user, try guessing the value,
3783 * depending on the terminal name. Only need to check for terminals
3784 * with a dark background, that can handle color.
3785 */
3786 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003787 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3788 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003790 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003791 /* don't mark it as set, when starting the GUI it may be
3792 * changed again */
3793 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 }
3795#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003796
3797#ifdef CURSOR_SHAPE
3798 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3799#endif
3800#ifdef FEAT_MOUSESHAPE
3801 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3802#endif
3803#ifdef FEAT_PRINTER
3804 (void)parse_printoptions(); /* parse 'printoptions' default value */
3805#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806}
3807
3808/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003809 * Return "dark" or "light" depending on the kind of terminal.
3810 * This is just guessing! Recognized are:
3811 * "linux" Linux console
3812 * "screen.linux" Linux console with screen
3813 * "cygwin" Cygwin shell
3814 * "putty" Putty program
3815 * We also check the COLORFGBG environment variable, which is set by
3816 * rxvt and derivatives. This variable contains either two or three
3817 * values separated by semicolons; we want the last value in either
3818 * case. If this value is 0-6 or 8, our background is dark.
3819 */
3820 static char_u *
3821term_bg_default()
3822{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003823#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3824 /* DOS console nearly always black */
3825 return (char_u *)"dark";
3826#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003827 char_u *p;
3828
Bram Moolenaarf740b292006-02-16 22:11:02 +00003829 if (STRCMP(T_NAME, "linux") == 0
3830 || STRCMP(T_NAME, "screen.linux") == 0
3831 || STRCMP(T_NAME, "cygwin") == 0
3832 || STRCMP(T_NAME, "putty") == 0
3833 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3834 && (p = vim_strrchr(p, ';')) != NULL
3835 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3836 && p[2] == NUL))
3837 return (char_u *)"dark";
3838 return (char_u *)"light";
3839#endif
3840}
3841
3842/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843 * Initialize the options, part three: After reading the .vimrc
3844 */
3845 void
3846set_init_3()
3847{
3848#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3849/*
3850 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3851 * This is done after other initializations, where 'shell' might have been
3852 * set, but only if they have not been set before.
3853 */
3854 char_u *p;
3855 int idx_srr;
3856 int do_srr;
3857#ifdef FEAT_QUICKFIX
3858 int idx_sp;
3859 int do_sp;
3860#endif
3861
3862 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003863 if (idx_srr < 0)
3864 do_srr = FALSE;
3865 else
3866 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867#ifdef FEAT_QUICKFIX
3868 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003869 if (idx_sp < 0)
3870 do_sp = FALSE;
3871 else
3872 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003874 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 if (p != NULL)
3876 {
3877 /*
3878 * Default for p_sp is "| tee", for p_srr is ">".
3879 * For known shells it is changed here to include stderr.
3880 */
3881 if ( fnamecmp(p, "csh") == 0
3882 || fnamecmp(p, "tcsh") == 0
3883# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3884 || fnamecmp(p, "csh.exe") == 0
3885 || fnamecmp(p, "tcsh.exe") == 0
3886# endif
3887 )
3888 {
3889#if defined(FEAT_QUICKFIX)
3890 if (do_sp)
3891 {
3892# ifdef WIN3264
3893 p_sp = (char_u *)">&";
3894# else
3895 p_sp = (char_u *)"|& tee";
3896# endif
3897 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3898 }
3899#endif
3900 if (do_srr)
3901 {
3902 p_srr = (char_u *)">&";
3903 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3904 }
3905 }
3906 else
3907# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3908 if ( fnamecmp(p, "sh") == 0
3909 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003910 || fnamecmp(p, "mksh") == 0
3911 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003913 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003915 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916# ifdef WIN3264
3917 || fnamecmp(p, "cmd") == 0
3918 || fnamecmp(p, "sh.exe") == 0
3919 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003920 || fnamecmp(p, "mksh.exe") == 0
3921 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003923 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 || fnamecmp(p, "bash.exe") == 0
3925 || fnamecmp(p, "cmd.exe") == 0
3926# endif
3927 )
3928# endif
3929 {
3930#if defined(FEAT_QUICKFIX)
3931 if (do_sp)
3932 {
3933# ifdef WIN3264
3934 p_sp = (char_u *)">%s 2>&1";
3935# else
3936 p_sp = (char_u *)"2>&1| tee";
3937# endif
3938 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3939 }
3940#endif
3941 if (do_srr)
3942 {
3943 p_srr = (char_u *)">%s 2>&1";
3944 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3945 }
3946 }
3947 vim_free(p);
3948 }
3949#endif
3950
3951#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3952 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003953 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3954 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 * This is done after other initializations, where 'shell' might have been
3956 * set, but only if they have not been set before. Default for p_shcf is
3957 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3958 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3959 * command.com. And for Win32 we need to set p_sxq instead.
3960 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003961 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 {
3963 int idx3;
3964
3965 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003966 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003967 {
3968 p_shcf = (char_u *)"-c";
3969 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3970 }
3971
3972# ifndef DJGPP
3973# ifdef WIN3264
3974 /* Somehow Win32 requires the quotes around the redirection too */
3975 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003976 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 {
3978 p_sxq = (char_u *)"\"";
3979 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3980 }
3981# else
3982 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003983 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 {
3985 p_shq = (char_u *)"\"";
3986 options[idx3].def_val[VI_DEFAULT] = p_shq;
3987 }
3988# endif
3989# endif
3990 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003991 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3992 {
3993 int idx3;
3994
3995 /*
3996 * cmd.exe on Windows will strip the first and last double quote given
3997 * on the command line, e.g. most of the time things like:
3998 * cmd /c "my path/to/echo" "my args to echo"
3999 * become:
4000 * my path/to/echo" "my args to echo
4001 * when executed.
4002 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004003 * To avoid this, set shellxquote to surround the command in
4004 * parenthesis. This appears to make most commands work, without
4005 * breaking commands that worked previously, such as
4006 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004007 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004008 idx3 = findoption((char_u *)"sxq");
4009 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4010 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004011 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004012 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4013 }
4014
Bram Moolenaara64ba222012-02-12 23:23:31 +01004015 idx3 = findoption((char_u *)"shcf");
4016 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4017 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004018 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004019 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4020 }
4021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004022#endif
4023
4024#ifdef FEAT_TITLE
4025 set_title_defaults();
4026#endif
4027}
4028
4029#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4030/*
4031 * When 'helplang' is still at its default value, set it to "lang".
4032 * Only the first two characters of "lang" are used.
4033 */
4034 void
4035set_helplang_default(lang)
4036 char_u *lang;
4037{
4038 int idx;
4039
4040 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4041 return;
4042 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004043 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 {
4045 if (options[idx].flags & P_ALLOCED)
4046 free_string_option(p_hlg);
4047 p_hlg = vim_strsave(lang);
4048 if (p_hlg == NULL)
4049 p_hlg = empty_option;
4050 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004051 {
4052 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4053 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4054 {
4055 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4056 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4057 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004059 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060 options[idx].flags |= P_ALLOCED;
4061 }
4062}
4063#endif
4064
4065#ifdef FEAT_GUI
4066static char_u *gui_bg_default __ARGS((void));
4067
4068 static char_u *
4069gui_bg_default()
4070{
4071 if (gui_get_lightness(gui.back_pixel) < 127)
4072 return (char_u *)"dark";
4073 return (char_u *)"light";
4074}
4075
4076/*
4077 * Option initializations that can only be done after opening the GUI window.
4078 */
4079 void
4080init_gui_options()
4081{
4082 /* Set the 'background' option according to the lightness of the
4083 * background color, unless the user has set it already. */
4084 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4085 {
4086 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4087 highlight_changed();
4088 }
4089}
4090#endif
4091
4092#ifdef FEAT_TITLE
4093/*
4094 * 'title' and 'icon' only default to true if they have not been set or reset
4095 * in .vimrc and we can read the old value.
4096 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4097 * they can be reset. This reduces startup time when using X on a remote
4098 * machine.
4099 */
4100 void
4101set_title_defaults()
4102{
4103 int idx1;
4104 long val;
4105
4106 /*
4107 * If GUI is (going to be) used, we can always set the window title and
4108 * icon name. Saves a bit of time, because the X11 display server does
4109 * not need to be contacted.
4110 */
4111 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004112 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 {
4114#ifdef FEAT_GUI
4115 if (gui.starting || gui.in_use)
4116 val = TRUE;
4117 else
4118#endif
4119 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004120 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 p_title = val;
4122 }
4123 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004124 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 {
4126#ifdef FEAT_GUI
4127 if (gui.starting || gui.in_use)
4128 val = TRUE;
4129 else
4130#endif
4131 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004132 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 p_icon = val;
4134 }
4135}
4136#endif
4137
4138/*
4139 * Parse 'arg' for option settings.
4140 *
4141 * 'arg' may be IObuff, but only when no errors can be present and option
4142 * does not need to be expanded with option_expand().
4143 * "opt_flags":
4144 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004145 * OPT_GLOBAL for ":setglobal"
4146 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004148 * OPT_WINONLY to only set window-local options
4149 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 *
4151 * returns FAIL if an error is detected, OK otherwise
4152 */
4153 int
4154do_set(arg, opt_flags)
4155 char_u *arg; /* option string (may be written to!) */
4156 int opt_flags;
4157{
4158 int opt_idx;
4159 char_u *errmsg;
4160 char_u errbuf[80];
4161 char_u *startarg;
4162 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4163 int nextchar; /* next non-white char after option name */
4164 int afterchar; /* character just after option name */
4165 int len;
4166 int i;
4167 long value;
4168 int key;
4169 long_u flags; /* flags for current option */
4170 char_u *varp = NULL; /* pointer to variable for current option */
4171 int did_show = FALSE; /* already showed one value */
4172 int adding; /* "opt+=arg" */
4173 int prepending; /* "opt^=arg" */
4174 int removing; /* "opt-=arg" */
4175 int cp_val = 0;
4176 char_u key_name[2];
4177
4178 if (*arg == NUL)
4179 {
4180 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004181 did_show = TRUE;
4182 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 }
4184
4185 while (*arg != NUL) /* loop to process all options */
4186 {
4187 errmsg = NULL;
4188 startarg = arg; /* remember for error message */
4189
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004190 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4191 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004192 {
4193 /*
4194 * ":set all" show all options.
4195 * ":set all&" set all options to their default value.
4196 */
4197 arg += 3;
4198 if (*arg == '&')
4199 {
4200 ++arg;
4201 /* Only for :set command set global value of local options. */
4202 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004203 didset_options();
4204 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004205 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206 }
4207 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004208 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004209 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004210 did_show = TRUE;
4211 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004213 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004214 {
4215 showoptions(2, opt_flags);
4216 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004217 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004218 arg += 7;
4219 }
4220 else
4221 {
4222 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004223 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224 {
4225 prefix = 0;
4226 arg += 2;
4227 }
4228 else if (STRNCMP(arg, "inv", 3) == 0)
4229 {
4230 prefix = 2;
4231 arg += 3;
4232 }
4233
4234 /* find end of name */
4235 key = 0;
4236 if (*arg == '<')
4237 {
4238 nextchar = 0;
4239 opt_idx = -1;
4240 /* look out for <t_>;> */
4241 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4242 len = 5;
4243 else
4244 {
4245 len = 1;
4246 while (arg[len] != NUL && arg[len] != '>')
4247 ++len;
4248 }
4249 if (arg[len] != '>')
4250 {
4251 errmsg = e_invarg;
4252 goto skip;
4253 }
4254 arg[len] = NUL; /* put NUL after name */
4255 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4256 opt_idx = findoption(arg + 1);
4257 arg[len++] = '>'; /* restore '>' */
4258 if (opt_idx == -1)
4259 key = find_key_option(arg + 1);
4260 }
4261 else
4262 {
4263 len = 0;
4264 /*
4265 * The two characters after "t_" may not be alphanumeric.
4266 */
4267 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4268 len = 4;
4269 else
4270 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4271 ++len;
4272 nextchar = arg[len];
4273 arg[len] = NUL; /* put NUL after name */
4274 opt_idx = findoption(arg);
4275 arg[len] = nextchar; /* restore nextchar */
4276 if (opt_idx == -1)
4277 key = find_key_option(arg);
4278 }
4279
4280 /* remember character after option name */
4281 afterchar = arg[len];
4282
4283 /* skip white space, allow ":set ai ?" */
4284 while (vim_iswhite(arg[len]))
4285 ++len;
4286
4287 adding = FALSE;
4288 prepending = FALSE;
4289 removing = FALSE;
4290 if (arg[len] != NUL && arg[len + 1] == '=')
4291 {
4292 if (arg[len] == '+')
4293 {
4294 adding = TRUE; /* "+=" */
4295 ++len;
4296 }
4297 else if (arg[len] == '^')
4298 {
4299 prepending = TRUE; /* "^=" */
4300 ++len;
4301 }
4302 else if (arg[len] == '-')
4303 {
4304 removing = TRUE; /* "-=" */
4305 ++len;
4306 }
4307 }
4308 nextchar = arg[len];
4309
4310 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4311 {
4312 errmsg = (char_u *)N_("E518: Unknown option");
4313 goto skip;
4314 }
4315
4316 if (opt_idx >= 0)
4317 {
4318 if (options[opt_idx].var == NULL) /* hidden option: skip */
4319 {
4320 /* Only give an error message when requesting the value of
4321 * a hidden option, ignore setting it. */
4322 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4323 && (!(options[opt_idx].flags & P_BOOL)
4324 || nextchar == '?'))
4325 errmsg = (char_u *)N_("E519: Option not supported");
4326 goto skip;
4327 }
4328
4329 flags = options[opt_idx].flags;
4330 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4331 }
4332 else
4333 {
4334 flags = P_STRING;
4335 if (key < 0)
4336 {
4337 key_name[0] = KEY2TERMCAP0(key);
4338 key_name[1] = KEY2TERMCAP1(key);
4339 }
4340 else
4341 {
4342 key_name[0] = KS_KEY;
4343 key_name[1] = (key & 0xff);
4344 }
4345 }
4346
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004347 /* Skip all options that are not window-local (used when showing
4348 * an already loaded buffer in a window). */
4349 if ((opt_flags & OPT_WINONLY)
4350 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4351 goto skip;
4352
Bram Moolenaara3227e22006-03-08 21:32:40 +00004353 /* Skip all options that are window-local (used for :vimgrep). */
4354 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4355 && options[opt_idx].var == VAR_WIN)
4356 goto skip;
4357
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004358 /* Disallow changing some options from modelines. */
4359 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004360 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004361 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004362 {
4363 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4364 goto skip;
4365 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004366#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004367 /* In diff mode some options are overruled. This avoids that
4368 * 'foldmethod' becomes "marker" instead of "diff" and that
4369 * "wrap" gets set. */
4370 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004371 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004372 && (options[opt_idx].indir == PV_FDM
4373 || options[opt_idx].indir == PV_WRAP))
4374 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004376 }
4377
4378#ifdef HAVE_SANDBOX
4379 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004380 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004381 {
4382 errmsg = (char_u *)_(e_sandbox);
4383 goto skip;
4384 }
4385#endif
4386
4387 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4388 {
4389 arg += len;
4390 cp_val = p_cp;
4391 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4392 {
4393 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4394 {
4395 cp_val = FALSE;
4396 arg += 3;
4397 }
4398 else /* "opt&vi": set to Vi default */
4399 {
4400 cp_val = TRUE;
4401 arg += 2;
4402 }
4403 }
4404 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4405 && arg[1] != NUL && !vim_iswhite(arg[1]))
4406 {
4407 errmsg = e_trailing;
4408 goto skip;
4409 }
4410 }
4411
4412 /*
4413 * allow '=' and ':' as MSDOS command.com allows only one
4414 * '=' character per "set" command line. grrr. (jw)
4415 */
4416 if (nextchar == '?'
4417 || (prefix == 1
4418 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4419 && !(flags & P_BOOL)))
4420 {
4421 /*
4422 * print value
4423 */
4424 if (did_show)
4425 msg_putchar('\n'); /* cursor below last one */
4426 else
4427 {
4428 gotocmdline(TRUE); /* cursor at status line */
4429 did_show = TRUE; /* remember that we did a line */
4430 }
4431 if (opt_idx >= 0)
4432 {
4433 showoneopt(&options[opt_idx], opt_flags);
4434#ifdef FEAT_EVAL
4435 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004436 {
4437 /* Mention where the option was last set. */
4438 if (varp == options[opt_idx].var)
4439 last_set_msg(options[opt_idx].scriptID);
4440 else if ((int)options[opt_idx].indir & PV_WIN)
4441 last_set_msg(curwin->w_p_scriptID[
4442 (int)options[opt_idx].indir & PV_MASK]);
4443 else if ((int)options[opt_idx].indir & PV_BUF)
4444 last_set_msg(curbuf->b_p_scriptID[
4445 (int)options[opt_idx].indir & PV_MASK]);
4446 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004447#endif
4448 }
4449 else
4450 {
4451 char_u *p;
4452
4453 p = find_termcode(key_name);
4454 if (p == NULL)
4455 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004456 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004457 goto skip;
4458 }
4459 else
4460 (void)show_one_termcode(key_name, p, TRUE);
4461 }
4462 if (nextchar != '?'
4463 && nextchar != NUL && !vim_iswhite(afterchar))
4464 errmsg = e_trailing;
4465 }
4466 else
4467 {
4468 if (flags & P_BOOL) /* boolean */
4469 {
4470 if (nextchar == '=' || nextchar == ':')
4471 {
4472 errmsg = e_invarg;
4473 goto skip;
4474 }
4475
4476 /*
4477 * ":set opt!": invert
4478 * ":set opt&": reset to default value
4479 * ":set opt<": reset to global value
4480 */
4481 if (nextchar == '!')
4482 value = *(int *)(varp) ^ 1;
4483 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004484 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004485 ((flags & P_VI_DEF) || cp_val)
4486 ? VI_DEFAULT : VIM_DEFAULT];
4487 else if (nextchar == '<')
4488 {
4489 /* For 'autoread' -1 means to use global value. */
4490 if ((int *)varp == &curbuf->b_p_ar
4491 && opt_flags == OPT_LOCAL)
4492 value = -1;
4493 else
4494 value = *(int *)get_varp_scope(&(options[opt_idx]),
4495 OPT_GLOBAL);
4496 }
4497 else
4498 {
4499 /*
4500 * ":set invopt": invert
4501 * ":set opt" or ":set noopt": set or reset
4502 */
4503 if (nextchar != NUL && !vim_iswhite(afterchar))
4504 {
4505 errmsg = e_trailing;
4506 goto skip;
4507 }
4508 if (prefix == 2) /* inv */
4509 value = *(int *)(varp) ^ 1;
4510 else
4511 value = prefix;
4512 }
4513
4514 errmsg = set_bool_option(opt_idx, varp, (int)value,
4515 opt_flags);
4516 }
4517 else /* numeric or string */
4518 {
4519 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4520 || prefix != 1)
4521 {
4522 errmsg = e_invarg;
4523 goto skip;
4524 }
4525
4526 if (flags & P_NUM) /* numeric */
4527 {
4528 /*
4529 * Different ways to set a number option:
4530 * & set to default value
4531 * < set to global value
4532 * <xx> accept special key codes for 'wildchar'
4533 * c accept any non-digit for 'wildchar'
4534 * [-]0-9 set number
4535 * other error
4536 */
4537 ++arg;
4538 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004539 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004540 ((flags & P_VI_DEF) || cp_val)
4541 ? VI_DEFAULT : VIM_DEFAULT];
4542 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004543 {
4544 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4545 * use the global value. */
4546 if ((long *)varp == &curbuf->b_p_ul
4547 && opt_flags == OPT_LOCAL)
4548 value = NO_LOCAL_UNDOLEVEL;
4549 else
4550 value = *(long *)get_varp_scope(
4551 &(options[opt_idx]), OPT_GLOBAL);
4552 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004553 else if (((long *)varp == &p_wc
4554 || (long *)varp == &p_wcm)
4555 && (*arg == '<'
4556 || *arg == '^'
4557 || ((!arg[1] || vim_iswhite(arg[1]))
4558 && !VIM_ISDIGIT(*arg))))
4559 {
4560 value = string_to_key(arg);
4561 if (value == 0 && (long *)varp != &p_wcm)
4562 {
4563 errmsg = e_invarg;
4564 goto skip;
4565 }
4566 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004567 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4568 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004569 /* Allow negative (for 'undolevels'), octal and
4570 * hex numbers. */
Bram Moolenaar5d1bc782015-07-17 13:03:48 +02004571 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004572 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4573 {
4574 errmsg = e_invarg;
4575 goto skip;
4576 }
4577 }
4578 else
4579 {
4580 errmsg = (char_u *)N_("E521: Number required after =");
4581 goto skip;
4582 }
4583
4584 if (adding)
4585 value = *(long *)varp + value;
4586 if (prepending)
4587 value = *(long *)varp * value;
4588 if (removing)
4589 value = *(long *)varp - value;
4590 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004591 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004592 }
4593 else if (opt_idx >= 0) /* string */
4594 {
4595 char_u *save_arg = NULL;
4596 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004597 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004598 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004599 char_u *origval = NULL;
4600#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4601 char_u *saved_origval = NULL;
4602#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004603 unsigned newlen;
4604 int comma;
4605 int bs;
4606 int new_value_alloced; /* new string option
4607 was allocated */
4608
4609 /* When using ":set opt=val" for a global option
4610 * with a local value the local value will be
4611 * reset, use the global value here. */
4612 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004613 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004614 varp = options[opt_idx].var;
4615
4616 /* The old value is kept until we are sure that the
4617 * new value is valid. */
4618 oldval = *(char_u **)varp;
4619 if (nextchar == '&') /* set to default val */
4620 {
4621 newval = options[opt_idx].def_val[
4622 ((flags & P_VI_DEF) || cp_val)
4623 ? VI_DEFAULT : VIM_DEFAULT];
4624 if ((char_u **)varp == &p_bg)
4625 {
4626 /* guess the value of 'background' */
4627#ifdef FEAT_GUI
4628 if (gui.in_use)
4629 newval = gui_bg_default();
4630 else
4631#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004632 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004633 }
4634
4635 /* expand environment variables and ~ (since the
4636 * default value was already expanded, only
4637 * required when an environment variable was set
4638 * later */
4639 if (newval == NULL)
4640 newval = empty_option;
4641 else
4642 {
4643 s = option_expand(opt_idx, newval);
4644 if (s == NULL)
4645 s = newval;
4646 newval = vim_strsave(s);
4647 }
4648 new_value_alloced = TRUE;
4649 }
4650 else if (nextchar == '<') /* set to global val */
4651 {
4652 newval = vim_strsave(*(char_u **)get_varp_scope(
4653 &(options[opt_idx]), OPT_GLOBAL));
4654 new_value_alloced = TRUE;
4655 }
4656 else
4657 {
4658 ++arg; /* jump to after the '=' or ':' */
4659
4660 /*
4661 * Set 'keywordprg' to ":help" if an empty
4662 * value was passed to :set by the user.
4663 * Misuse errbuf[] for the resulting string.
4664 */
4665 if (varp == (char_u *)&p_kp
4666 && (*arg == NUL || *arg == ' '))
4667 {
4668 STRCPY(errbuf, ":help");
4669 save_arg = arg;
4670 arg = errbuf;
4671 }
4672 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004673 * Convert 'backspace' number to string, for
4674 * adding, prepending and removing string.
4675 */
4676 else if (varp == (char_u *)&p_bs
4677 && VIM_ISDIGIT(**(char_u **)varp))
4678 {
4679 i = getdigits((char_u **)varp);
4680 switch (i)
4681 {
4682 case 0:
4683 *(char_u **)varp = empty_option;
4684 break;
4685 case 1:
4686 *(char_u **)varp = vim_strsave(
4687 (char_u *)"indent,eol");
4688 break;
4689 case 2:
4690 *(char_u **)varp = vim_strsave(
4691 (char_u *)"indent,eol,start");
4692 break;
4693 }
4694 vim_free(oldval);
4695 oldval = *(char_u **)varp;
4696 }
4697 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004698 * Convert 'whichwrap' number to string, for
4699 * backwards compatibility with Vim 3.0.
4700 * Misuse errbuf[] for the resulting string.
4701 */
4702 else if (varp == (char_u *)&p_ww
4703 && VIM_ISDIGIT(*arg))
4704 {
4705 *errbuf = NUL;
4706 i = getdigits(&arg);
4707 if (i & 1)
4708 STRCAT(errbuf, "b,");
4709 if (i & 2)
4710 STRCAT(errbuf, "s,");
4711 if (i & 4)
4712 STRCAT(errbuf, "h,l,");
4713 if (i & 8)
4714 STRCAT(errbuf, "<,>,");
4715 if (i & 16)
4716 STRCAT(errbuf, "[,],");
4717 if (*errbuf != NUL) /* remove trailing , */
4718 errbuf[STRLEN(errbuf) - 1] = NUL;
4719 save_arg = arg;
4720 arg = errbuf;
4721 }
4722 /*
4723 * Remove '>' before 'dir' and 'bdir', for
4724 * backwards compatibility with version 3.0
4725 */
4726 else if ( *arg == '>'
4727 && (varp == (char_u *)&p_dir
4728 || varp == (char_u *)&p_bdir))
4729 {
4730 ++arg;
4731 }
4732
4733 /* When setting the local value of a global
4734 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004735 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004736 && (opt_flags & OPT_LOCAL))
4737 origval = *(char_u **)get_varp(
4738 &options[opt_idx]);
4739 else
4740 origval = oldval;
4741
4742 /*
4743 * Copy the new string into allocated memory.
4744 * Can't use set_string_option_direct(), because
4745 * we need to remove the backslashes.
4746 */
4747 /* get a bit too much */
4748 newlen = (unsigned)STRLEN(arg) + 1;
4749 if (adding || prepending || removing)
4750 newlen += (unsigned)STRLEN(origval) + 1;
4751 newval = alloc(newlen);
4752 if (newval == NULL) /* out of mem, don't change */
4753 break;
4754 s = newval;
4755
4756 /*
4757 * Copy the string, skip over escaped chars.
4758 * For MS-DOS and WIN32 backslashes before normal
4759 * file name characters are not removed, and keep
4760 * backslash at start, for "\\machine\path", but
4761 * do remove it for "\\\\machine\\path".
4762 * The reverse is found in ExpandOldSetting().
4763 */
4764 while (*arg && !vim_iswhite(*arg))
4765 {
4766 if (*arg == '\\' && arg[1] != NUL
4767#ifdef BACKSLASH_IN_FILENAME
4768 && !((flags & P_EXPAND)
4769 && vim_isfilec(arg[1])
4770 && (arg[1] != '\\'
4771 || (s == newval
4772 && arg[2] != '\\')))
4773#endif
4774 )
4775 ++arg; /* remove backslash */
4776#ifdef FEAT_MBYTE
4777 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004778 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004779 {
4780 /* copy multibyte char */
4781 mch_memmove(s, arg, (size_t)i);
4782 arg += i;
4783 s += i;
4784 }
4785 else
4786#endif
4787 *s++ = *arg++;
4788 }
4789 *s = NUL;
4790
4791 /*
4792 * Expand environment variables and ~.
4793 * Don't do it when adding without inserting a
4794 * comma.
4795 */
4796 if (!(adding || prepending || removing)
4797 || (flags & P_COMMA))
4798 {
4799 s = option_expand(opt_idx, newval);
4800 if (s != NULL)
4801 {
4802 vim_free(newval);
4803 newlen = (unsigned)STRLEN(s) + 1;
4804 if (adding || prepending || removing)
4805 newlen += (unsigned)STRLEN(origval) + 1;
4806 newval = alloc(newlen);
4807 if (newval == NULL)
4808 break;
4809 STRCPY(newval, s);
4810 }
4811 }
4812
4813 /* locate newval[] in origval[] when removing it
4814 * and when adding to avoid duplicates */
4815 i = 0; /* init for GCC */
4816 if (removing || (flags & P_NODUP))
4817 {
4818 i = (int)STRLEN(newval);
4819 bs = 0;
4820 for (s = origval; *s; ++s)
4821 {
4822 if ((!(flags & P_COMMA)
4823 || s == origval
4824 || (s[-1] == ',' && !(bs & 1)))
4825 && STRNCMP(s, newval, i) == 0
4826 && (!(flags & P_COMMA)
4827 || s[i] == ','
4828 || s[i] == NUL))
4829 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004830 /* Count backslashes. Only a comma with an
4831 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004832 * recognized as a separator */
4833 if (s > origval && s[-1] == '\\')
4834 ++bs;
4835 else
4836 bs = 0;
4837 }
4838
4839 /* do not add if already there */
4840 if ((adding || prepending) && *s)
4841 {
4842 prepending = FALSE;
4843 adding = FALSE;
4844 STRCPY(newval, origval);
4845 }
4846 }
4847
4848 /* concatenate the two strings; add a ',' if
4849 * needed */
4850 if (adding || prepending)
4851 {
4852 comma = ((flags & P_COMMA) && *origval != NUL
4853 && *newval != NUL);
4854 if (adding)
4855 {
4856 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004857 /* strip a trailing comma, would get 2 */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02004858 if (comma && (flags & P_ONECOMMA) && i > 1
4859 && origval[i - 1] == ','
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004860 && origval[i - 2] != '\\')
4861 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004862 mch_memmove(newval + i + comma, newval,
4863 STRLEN(newval) + 1);
4864 mch_memmove(newval, origval, (size_t)i);
4865 }
4866 else
4867 {
4868 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004869 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004870 }
4871 if (comma)
4872 newval[i] = ',';
4873 }
4874
4875 /* Remove newval[] from origval[]. (Note: "i" has
4876 * been set above and is used here). */
4877 if (removing)
4878 {
4879 STRCPY(newval, origval);
4880 if (*s)
4881 {
4882 /* may need to remove a comma */
4883 if (flags & P_COMMA)
4884 {
4885 if (s == origval)
4886 {
4887 /* include comma after string */
4888 if (s[i] == ',')
4889 ++i;
4890 }
4891 else
4892 {
4893 /* include comma before string */
4894 --s;
4895 ++i;
4896 }
4897 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004898 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004899 }
4900 }
4901
4902 if (flags & P_FLAGLIST)
4903 {
4904 /* Remove flags that appear twice. */
4905 for (s = newval; *s; ++s)
4906 if ((!(flags & P_COMMA) || *s != ',')
4907 && vim_strchr(s + 1, *s) != NULL)
4908 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004909 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004910 --s;
4911 }
4912 }
4913
4914 if (save_arg != NULL) /* number for 'whichwrap' */
4915 arg = save_arg;
4916 new_value_alloced = TRUE;
4917 }
4918
4919 /* Set the new value. */
4920 *(char_u **)(varp) = newval;
4921
Bram Moolenaar53744302015-07-17 17:38:22 +02004922#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004923 if (!starting
4924# ifdef FEAT_CRYPT
4925 && options[opt_idx].indir != PV_KEY
4926# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004927 && origval != NULL)
4928 /* origval may be freed by
4929 * did_set_string_option(), make a copy. */
4930 saved_origval = vim_strsave(origval);
4931#endif
4932
Bram Moolenaar071d4272004-06-13 20:20:40 +00004933 /* Handle side effects, and set the global value for
4934 * ":set" on local options. */
4935 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4936 new_value_alloced, oldval, errbuf, opt_flags);
4937
4938 /* If error detected, print the error message. */
4939 if (errmsg != NULL)
4940 goto skip;
Bram Moolenaar53744302015-07-17 17:38:22 +02004941#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4942 if (saved_origval != NULL)
4943 {
4944 char_u buf_type[7];
4945
4946 sprintf((char *)buf_type, "%s",
4947 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004948 set_vim_var_string(VV_OPTION_NEW,
4949 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004950 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4951 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4952 apply_autocmds(EVENT_OPTIONSET,
4953 (char_u *)options[opt_idx].fullname,
4954 NULL, FALSE, NULL);
4955 reset_v_option_vars();
4956 vim_free(saved_origval);
4957 }
4958#endif
4959
Bram Moolenaar071d4272004-06-13 20:20:40 +00004960 }
4961 else /* key code option */
4962 {
4963 char_u *p;
4964
4965 if (nextchar == '&')
4966 {
4967 if (add_termcap_entry(key_name, TRUE) == FAIL)
4968 errmsg = (char_u *)N_("E522: Not found in termcap");
4969 }
4970 else
4971 {
4972 ++arg; /* jump to after the '=' or ':' */
4973 for (p = arg; *p && !vim_iswhite(*p); ++p)
4974 if (*p == '\\' && p[1] != NUL)
4975 ++p;
4976 nextchar = *p;
4977 *p = NUL;
4978 add_termcode(key_name, arg, FALSE);
4979 *p = nextchar;
4980 }
4981 if (full_screen)
4982 ttest(FALSE);
4983 redraw_all_later(CLEAR);
4984 }
4985 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004986
Bram Moolenaar071d4272004-06-13 20:20:40 +00004987 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004988 did_set_option(opt_idx, opt_flags,
4989 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004990 }
4991
4992skip:
4993 /*
4994 * Advance to next argument.
4995 * - skip until a blank found, taking care of backslashes
4996 * - skip blanks
4997 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4998 */
4999 for (i = 0; i < 2 ; ++i)
5000 {
5001 while (*arg != NUL && !vim_iswhite(*arg))
5002 if (*arg++ == '\\' && *arg != NUL)
5003 ++arg;
5004 arg = skipwhite(arg);
5005 if (*arg != '=')
5006 break;
5007 }
5008 }
5009
5010 if (errmsg != NULL)
5011 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005012 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005013 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005014 if (i + (arg - startarg) < IOSIZE)
5015 {
5016 /* append the argument with the error */
5017 STRCAT(IObuff, ": ");
5018 mch_memmove(IObuff + i, startarg, (arg - startarg));
5019 IObuff[i + (arg - startarg)] = NUL;
5020 }
5021 /* make sure all characters are printable */
5022 trans_characters(IObuff, IOSIZE);
5023
5024 ++no_wait_return; /* wait_return done later */
5025 emsg(IObuff); /* show error highlighted */
5026 --no_wait_return;
5027
5028 return FAIL;
5029 }
5030
5031 arg = skipwhite(arg);
5032 }
5033
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005034theend:
5035 if (silent_mode && did_show)
5036 {
5037 /* After displaying option values in silent mode. */
5038 silent_mode = FALSE;
5039 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5040 msg_putchar('\n');
5041 cursor_on(); /* msg_start() switches it off */
5042 out_flush();
5043 silent_mode = TRUE;
5044 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5045 }
5046
Bram Moolenaar071d4272004-06-13 20:20:40 +00005047 return OK;
5048}
5049
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005050/*
5051 * Call this when an option has been given a new value through a user command.
5052 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5053 */
5054 static void
5055did_set_option(opt_idx, opt_flags, new_value)
5056 int opt_idx;
5057 int opt_flags; /* possibly with OPT_MODELINE */
5058 int new_value; /* value was replaced completely */
5059{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005060 long_u *p;
5061
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005062 options[opt_idx].flags |= P_WAS_SET;
5063
5064 /* When an option is set in the sandbox, from a modeline or in secure mode
5065 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005066 * flag. */
5067 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005068 if (secure
5069#ifdef HAVE_SANDBOX
5070 || sandbox != 0
5071#endif
5072 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005073 *p = *p | P_INSECURE;
5074 else if (new_value)
5075 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005076}
5077
Bram Moolenaar071d4272004-06-13 20:20:40 +00005078 static char_u *
5079illegal_char(errbuf, c)
5080 char_u *errbuf;
5081 int c;
5082{
5083 if (errbuf == NULL)
5084 return (char_u *)"";
5085 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005086 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005087 return errbuf;
5088}
5089
5090/*
5091 * Convert a key name or string into a key value.
5092 * Used for 'wildchar' and 'cedit' options.
5093 */
5094 static int
5095string_to_key(arg)
5096 char_u *arg;
5097{
5098 if (*arg == '<')
5099 return find_key_option(arg + 1);
5100 if (*arg == '^')
5101 return Ctrl_chr(arg[1]);
5102 return *arg;
5103}
5104
5105#ifdef FEAT_CMDWIN
5106/*
5107 * Check value of 'cedit' and set cedit_key.
5108 * Returns NULL if value is OK, error message otherwise.
5109 */
5110 static char_u *
5111check_cedit()
5112{
5113 int n;
5114
5115 if (*p_cedit == NUL)
5116 cedit_key = -1;
5117 else
5118 {
5119 n = string_to_key(p_cedit);
5120 if (vim_isprintc(n))
5121 return e_invarg;
5122 cedit_key = n;
5123 }
5124 return NULL;
5125}
5126#endif
5127
5128#ifdef FEAT_TITLE
5129/*
5130 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5131 * maketitle() to create and display it.
5132 * When switching the title or icon off, call mch_restore_title() to get
5133 * the old value back.
5134 */
5135 static void
5136did_set_title(icon)
5137 int icon; /* Did set icon instead of title */
5138{
5139 if (starting != NO_SCREEN
5140#ifdef FEAT_GUI
5141 && !gui.starting
5142#endif
5143 )
5144 {
5145 maketitle();
5146 if (icon)
5147 {
5148 if (!p_icon)
5149 mch_restore_title(2);
5150 }
5151 else
5152 {
5153 if (!p_title)
5154 mch_restore_title(1);
5155 }
5156 }
5157}
5158#endif
5159
5160/*
5161 * set_options_bin - called when 'bin' changes value.
5162 */
5163 void
5164set_options_bin(oldval, newval, opt_flags)
5165 int oldval;
5166 int newval;
5167 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5168{
5169 /*
5170 * The option values that are changed when 'bin' changes are
5171 * copied when 'bin is set and restored when 'bin' is reset.
5172 */
5173 if (newval)
5174 {
5175 if (!oldval) /* switched on */
5176 {
5177 if (!(opt_flags & OPT_GLOBAL))
5178 {
5179 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5180 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5181 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5182 curbuf->b_p_et_nobin = curbuf->b_p_et;
5183 }
5184 if (!(opt_flags & OPT_LOCAL))
5185 {
5186 p_tw_nobin = p_tw;
5187 p_wm_nobin = p_wm;
5188 p_ml_nobin = p_ml;
5189 p_et_nobin = p_et;
5190 }
5191 }
5192
5193 if (!(opt_flags & OPT_GLOBAL))
5194 {
5195 curbuf->b_p_tw = 0; /* no automatic line wrap */
5196 curbuf->b_p_wm = 0; /* no automatic line wrap */
5197 curbuf->b_p_ml = 0; /* no modelines */
5198 curbuf->b_p_et = 0; /* no expandtab */
5199 }
5200 if (!(opt_flags & OPT_LOCAL))
5201 {
5202 p_tw = 0;
5203 p_wm = 0;
5204 p_ml = FALSE;
5205 p_et = FALSE;
5206 p_bin = TRUE; /* needed when called for the "-b" argument */
5207 }
5208 }
5209 else if (oldval) /* switched off */
5210 {
5211 if (!(opt_flags & OPT_GLOBAL))
5212 {
5213 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5214 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5215 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5216 curbuf->b_p_et = curbuf->b_p_et_nobin;
5217 }
5218 if (!(opt_flags & OPT_LOCAL))
5219 {
5220 p_tw = p_tw_nobin;
5221 p_wm = p_wm_nobin;
5222 p_ml = p_ml_nobin;
5223 p_et = p_et_nobin;
5224 }
5225 }
5226}
5227
5228#ifdef FEAT_VIMINFO
5229/*
5230 * Find the parameter represented by the given character (eg ', :, ", or /),
5231 * and return its associated value in the 'viminfo' string.
5232 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005233 * If the parameter is not specified in the string or there is no following
5234 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005235 */
5236 int
5237get_viminfo_parameter(type)
5238 int type;
5239{
5240 char_u *p;
5241
5242 p = find_viminfo_parameter(type);
5243 if (p != NULL && VIM_ISDIGIT(*p))
5244 return atoi((char *)p);
5245 return -1;
5246}
5247
5248/*
5249 * Find the parameter represented by the given character (eg ''', ':', '"', or
5250 * '/') in the 'viminfo' option and return a pointer to the string after it.
5251 * Return NULL if the parameter is not specified in the string.
5252 */
5253 char_u *
5254find_viminfo_parameter(type)
5255 int type;
5256{
5257 char_u *p;
5258
5259 for (p = p_viminfo; *p; ++p)
5260 {
5261 if (*p == type)
5262 return p + 1;
5263 if (*p == 'n') /* 'n' is always the last one */
5264 break;
5265 p = vim_strchr(p, ','); /* skip until next ',' */
5266 if (p == NULL) /* hit the end without finding parameter */
5267 break;
5268 }
5269 return NULL;
5270}
5271#endif
5272
5273/*
5274 * Expand environment variables for some string options.
5275 * These string options cannot be indirect!
5276 * If "val" is NULL expand the current value of the option.
5277 * Return pointer to NameBuff, or NULL when not expanded.
5278 */
5279 static char_u *
5280option_expand(opt_idx, val)
5281 int opt_idx;
5282 char_u *val;
5283{
5284 /* if option doesn't need expansion nothing to do */
5285 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5286 return NULL;
5287
5288 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5289 * expand_env() would truncate the string. */
5290 if (val != NULL && STRLEN(val) > MAXPATHL)
5291 return NULL;
5292
5293 if (val == NULL)
5294 val = *(char_u **)options[opt_idx].var;
5295
5296 /*
5297 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5298 * Escape spaces when expanding 'tags', they are used to separate file
5299 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005300 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005301 */
5302 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005303 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005304#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005305 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5306#endif
5307 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5309 return NULL;
5310
5311 return NameBuff;
5312}
5313
5314/*
5315 * After setting various option values: recompute variables that depend on
5316 * option values.
5317 */
5318 static void
5319didset_options()
5320{
5321 /* initialize the table for 'iskeyword' et.al. */
5322 (void)init_chartab();
5323
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005324#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005326#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005328 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005329#ifdef FEAT_SESSION
5330 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5331 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5332#endif
5333#ifdef FEAT_FOLDING
5334 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5335#endif
5336 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5337#ifdef FEAT_VIRTUALEDIT
5338 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5339#endif
5340#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5341 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5342#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005343#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005344 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005345 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005346 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005347 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005348#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5350 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5351#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005352#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5354#endif
5355#ifdef FEAT_CMDWIN
5356 /* set cedit_key */
5357 (void)check_cedit();
5358#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005359#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005360 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005361#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005362#ifdef FEAT_LINEBREAK
5363 /* initialize the table for 'breakat'. */
5364 fill_breakat_flags();
5365#endif
5366
5367}
5368
5369/*
5370 * More side effects of setting options.
5371 */
5372 static void
5373didset_options2()
5374{
5375 /* Initialize the highlight_attr[] table. */
5376 (void)highlight_changed();
5377
5378 /* Parse default for 'wildmode' */
5379 check_opt_wim();
5380
5381 (void)set_chars_option(&p_lcs);
5382#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5383 /* Parse default for 'fillchars'. */
5384 (void)set_chars_option(&p_fcs);
5385#endif
5386
5387#ifdef FEAT_CLIPBOARD
5388 /* Parse default for 'clipboard' */
5389 (void)check_clipboard_option();
5390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005391}
5392
5393/*
5394 * Check for string options that are NULL (normally only termcap options).
5395 */
5396 void
5397check_options()
5398{
5399 int opt_idx;
5400
5401 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5402 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5403 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5404}
5405
5406/*
5407 * Check string options in a buffer for NULL value.
5408 */
5409 void
5410check_buf_options(buf)
5411 buf_T *buf;
5412{
5413#if defined(FEAT_QUICKFIX)
5414 check_string_option(&buf->b_p_bh);
5415 check_string_option(&buf->b_p_bt);
5416#endif
5417#ifdef FEAT_MBYTE
5418 check_string_option(&buf->b_p_fenc);
5419#endif
5420 check_string_option(&buf->b_p_ff);
5421#ifdef FEAT_FIND_ID
5422 check_string_option(&buf->b_p_def);
5423 check_string_option(&buf->b_p_inc);
5424# ifdef FEAT_EVAL
5425 check_string_option(&buf->b_p_inex);
5426# endif
5427#endif
5428#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5429 check_string_option(&buf->b_p_inde);
5430 check_string_option(&buf->b_p_indk);
5431#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005432#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5433 check_string_option(&buf->b_p_bexpr);
5434#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005435#if defined(FEAT_CRYPT)
5436 check_string_option(&buf->b_p_cm);
5437#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005438#if defined(FEAT_EVAL)
5439 check_string_option(&buf->b_p_fex);
5440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005441#ifdef FEAT_CRYPT
5442 check_string_option(&buf->b_p_key);
5443#endif
5444 check_string_option(&buf->b_p_kp);
5445 check_string_option(&buf->b_p_mps);
5446 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005447 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005448 check_string_option(&buf->b_p_isk);
5449#ifdef FEAT_COMMENTS
5450 check_string_option(&buf->b_p_com);
5451#endif
5452#ifdef FEAT_FOLDING
5453 check_string_option(&buf->b_p_cms);
5454#endif
5455 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005456#ifdef FEAT_TEXTOBJ
5457 check_string_option(&buf->b_p_qe);
5458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459#ifdef FEAT_SYN_HL
5460 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005461#endif
5462#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005463 check_string_option(&buf->b_s.b_p_spc);
5464 check_string_option(&buf->b_s.b_p_spf);
5465 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005466#endif
5467#ifdef FEAT_SEARCHPATH
5468 check_string_option(&buf->b_p_sua);
5469#endif
5470#ifdef FEAT_CINDENT
5471 check_string_option(&buf->b_p_cink);
5472 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005473 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005474#endif
5475#ifdef FEAT_AUTOCMD
5476 check_string_option(&buf->b_p_ft);
5477#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5479 check_string_option(&buf->b_p_cinw);
5480#endif
5481#ifdef FEAT_INS_EXPAND
5482 check_string_option(&buf->b_p_cpt);
5483#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005484#ifdef FEAT_COMPL_FUNC
5485 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005486 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005487#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005488#ifdef FEAT_KEYMAP
5489 check_string_option(&buf->b_p_keymap);
5490#endif
5491#ifdef FEAT_QUICKFIX
5492 check_string_option(&buf->b_p_gp);
5493 check_string_option(&buf->b_p_mp);
5494 check_string_option(&buf->b_p_efm);
5495#endif
5496 check_string_option(&buf->b_p_ep);
5497 check_string_option(&buf->b_p_path);
5498 check_string_option(&buf->b_p_tags);
5499#ifdef FEAT_INS_EXPAND
5500 check_string_option(&buf->b_p_dict);
5501 check_string_option(&buf->b_p_tsr);
5502#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005503#ifdef FEAT_LISP
5504 check_string_option(&buf->b_p_lw);
5505#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005506 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005507}
5508
5509/*
5510 * Free the string allocated for an option.
5511 * Checks for the string being empty_option. This may happen if we're out of
5512 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5513 * check_options().
5514 * Does NOT check for P_ALLOCED flag!
5515 */
5516 void
5517free_string_option(p)
5518 char_u *p;
5519{
5520 if (p != empty_option)
5521 vim_free(p);
5522}
5523
5524 void
5525clear_string_option(pp)
5526 char_u **pp;
5527{
5528 if (*pp != empty_option)
5529 vim_free(*pp);
5530 *pp = empty_option;
5531}
5532
5533 static void
5534check_string_option(pp)
5535 char_u **pp;
5536{
5537 if (*pp == NULL)
5538 *pp = empty_option;
5539}
5540
5541/*
5542 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5543 */
5544 void
5545set_term_option_alloced(p)
5546 char_u **p;
5547{
5548 int opt_idx;
5549
5550 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5551 if (options[opt_idx].var == (char_u *)p)
5552 {
5553 options[opt_idx].flags |= P_ALLOCED;
5554 return;
5555 }
5556 return; /* cannot happen: didn't find it! */
5557}
5558
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005559#if defined(FEAT_EVAL) || defined(PROTO)
5560/*
5561 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5562 * Return FALSE when it wasn't.
5563 * Return -1 for an unknown option.
5564 */
5565 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005566was_set_insecurely(opt, opt_flags)
5567 char_u *opt;
5568 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005569{
5570 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005571 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005572
5573 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005574 {
5575 flagp = insecure_flag(idx, opt_flags);
5576 return (*flagp & P_INSECURE) != 0;
5577 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005578 EMSG2(_(e_intern2), "was_set_insecurely()");
5579 return -1;
5580}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005581
5582/*
5583 * Get a pointer to the flags used for the P_INSECURE flag of option
5584 * "opt_idx". For some local options a local flags field is used.
5585 */
5586 static long_u *
5587insecure_flag(opt_idx, opt_flags)
5588 int opt_idx;
5589 int opt_flags;
5590{
5591 if (opt_flags & OPT_LOCAL)
5592 switch ((int)options[opt_idx].indir)
5593 {
5594#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005595 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005596#endif
5597#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005598# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005599 case PV_FDE: return &curwin->w_p_fde_flags;
5600 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005601# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005602# ifdef FEAT_BEVAL
5603 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5604# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005605# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005606 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005607# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005608 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005609# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005610 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005611# endif
5612#endif
5613 }
5614
5615 /* Nothing special, return global flags field. */
5616 return &options[opt_idx].flags;
5617}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005618#endif
5619
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005620#ifdef FEAT_TITLE
5621static void redraw_titles __ARGS((void));
5622
5623/*
5624 * Redraw the window title and/or tab page text later.
5625 */
5626static void redraw_titles()
5627{
5628 need_maketitle = TRUE;
5629# ifdef FEAT_WINDOWS
5630 redraw_tabline = TRUE;
5631# endif
5632}
5633#endif
5634
Bram Moolenaar071d4272004-06-13 20:20:40 +00005635/*
5636 * Set a string option to a new value (without checking the effect).
5637 * The string is copied into allocated memory.
5638 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005639 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005640 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005641 */
5642 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005643set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005644 char_u *name;
5645 int opt_idx;
5646 char_u *val;
5647 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005648 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649{
5650 char_u *s;
5651 char_u **varp;
5652 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005653 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005654
Bram Moolenaar89d40322006-08-29 15:30:07 +00005655 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005656 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005657 idx = findoption(name);
5658 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005659 {
5660 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005661 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005663 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664 }
5665
Bram Moolenaar89d40322006-08-29 15:30:07 +00005666 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667 return;
5668
5669 s = vim_strsave(val);
5670 if (s != NULL)
5671 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005672 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005674 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675 free_string_option(*varp);
5676 *varp = s;
5677
5678 /* For buffer/window local option may also set the global value. */
5679 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005680 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681
Bram Moolenaar89d40322006-08-29 15:30:07 +00005682 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683
5684 /* When setting both values of a global option with a local value,
5685 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005686 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005687 {
5688 free_string_option(*varp);
5689 *varp = empty_option;
5690 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005691# ifdef FEAT_EVAL
5692 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005693 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005694 set_sid == 0 ? current_SID : set_sid);
5695# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696 }
5697}
5698
5699/*
5700 * Set global value for string option when it's a local option.
5701 */
5702 static void
5703set_string_option_global(opt_idx, varp)
5704 int opt_idx; /* option index */
5705 char_u **varp; /* pointer to option variable */
5706{
5707 char_u **p, *s;
5708
5709 /* the global value is always allocated */
5710 if (options[opt_idx].var == VAR_WIN)
5711 p = (char_u **)GLOBAL_WO(varp);
5712 else
5713 p = (char_u **)options[opt_idx].var;
5714 if (options[opt_idx].indir != PV_NONE
5715 && p != varp
5716 && (s = vim_strsave(*varp)) != NULL)
5717 {
5718 free_string_option(*p);
5719 *p = s;
5720 }
5721}
5722
5723/*
5724 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005725 *
5726 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005728 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005729set_string_option(opt_idx, value, opt_flags)
5730 int opt_idx;
5731 char_u *value;
5732 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5733{
5734 char_u *s;
5735 char_u **varp;
5736 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005737#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5738 char_u *saved_oldval = NULL;
5739#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005740 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005741
5742 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005743 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005744
5745 s = vim_strsave(value);
5746 if (s != NULL)
5747 {
5748 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5749 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005750 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005751 ? OPT_GLOBAL : OPT_LOCAL)
5752 : opt_flags);
5753 oldval = *varp;
5754 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005755
5756#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005757 if (!starting
5758# ifdef FEAT_CRYPT
5759 && options[opt_idx].indir != PV_KEY
5760# endif
5761 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005762 saved_oldval = vim_strsave(oldval);
5763#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005764 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5765 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005766 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005767
5768 /* call autocomamnd after handling side effects */
5769#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5770 if (saved_oldval != NULL)
5771 {
5772 char_u buf_type[7];
5773 sprintf((char *)buf_type, "%s",
5774 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005775 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5776 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005777 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5778 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5779 reset_v_option_vars();
5780 vim_free(saved_oldval);
5781 }
5782#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005784 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785}
5786
5787/*
5788 * Handle string options that need some action to perform when changed.
5789 * Returns NULL for success, or an error message for an error.
5790 */
5791 static char_u *
5792did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5793 opt_flags)
5794 int opt_idx; /* index in options[] table */
5795 char_u **varp; /* pointer to the option variable */
5796 int new_value_alloced; /* new value was allocated */
5797 char_u *oldval; /* previous value of the option */
5798 char_u *errbuf; /* buffer for errors, or NULL */
5799 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5800{
5801 char_u *errmsg = NULL;
5802 char_u *s, *p;
5803 int did_chartab = FALSE;
5804 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005805 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005806#ifdef FEAT_GUI
5807 /* set when changing an option that only requires a redraw in the GUI */
5808 int redraw_gui_only = FALSE;
5809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005810
5811 /* Get the global option to compare with, otherwise we would have to check
5812 * two values for all local options. */
5813 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5814
5815 /* Disallow changing some options from secure mode */
5816 if ((secure
5817#ifdef HAVE_SANDBOX
5818 || sandbox != 0
5819#endif
5820 ) && (options[opt_idx].flags & P_SECURE))
5821 {
5822 errmsg = e_secure;
5823 }
5824
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005825 /* Check for a "normal" file name in some options. Disallow a path
5826 * separator (slash and/or backslash), wildcards and characters that are
5827 * often illegal in a file name. */
5828 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005829 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005830 {
5831 errmsg = e_invarg;
5832 }
5833
Bram Moolenaar071d4272004-06-13 20:20:40 +00005834 /* 'term' */
5835 else if (varp == &T_NAME)
5836 {
5837 if (T_NAME[0] == NUL)
5838 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5839#ifdef FEAT_GUI
5840 if (gui.in_use)
5841 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5842 else if (term_is_gui(T_NAME))
5843 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5844#endif
5845 else if (set_termname(T_NAME) == FAIL)
5846 errmsg = (char_u *)N_("E522: Not found in termcap");
5847 else
5848 /* Screen colors may have changed. */
5849 redraw_later_clear();
5850 }
5851
5852 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005853 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005854 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005855 char_u *bkc = p_bkc;
5856 unsigned int *flags = &bkc_flags;
5857
5858 if (opt_flags & OPT_LOCAL)
5859 {
5860 bkc = curbuf->b_p_bkc;
5861 flags = &curbuf->b_bkc_flags;
5862 }
5863
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005864 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5865 /* make the local value empty: use the global value */
5866 *flags = 0;
5867 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005868 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005869 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5870 errmsg = e_invarg;
5871 if ((((int)*flags & BKC_AUTO) != 0)
5872 + (((int)*flags & BKC_YES) != 0)
5873 + (((int)*flags & BKC_NO) != 0) != 1)
5874 {
5875 /* Must have exactly one of "auto", "yes" and "no". */
5876 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5877 errmsg = e_invarg;
5878 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879 }
5880 }
5881
5882 /* 'backupext' and 'patchmode' */
5883 else if (varp == &p_bex || varp == &p_pm)
5884 {
5885 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5886 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5887 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5888 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005889#ifdef FEAT_LINEBREAK
5890 /* 'breakindentopt' */
5891 else if (varp == &curwin->w_p_briopt)
5892 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005893 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005894 errmsg = e_invarg;
5895 }
5896#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897
5898 /*
5899 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5900 * If the new option is invalid, use old value. 'lisp' option: refill
5901 * chartab[] for '-' char
5902 */
5903 else if ( varp == &p_isi
5904 || varp == &(curbuf->b_p_isk)
5905 || varp == &p_isp
5906 || varp == &p_isf)
5907 {
5908 if (init_chartab() == FAIL)
5909 {
5910 did_chartab = TRUE; /* need to restore it below */
5911 errmsg = e_invarg; /* error in value */
5912 }
5913 }
5914
5915 /* 'helpfile' */
5916 else if (varp == &p_hf)
5917 {
5918 /* May compute new values for $VIM and $VIMRUNTIME */
5919 if (didset_vim)
5920 {
5921 vim_setenv((char_u *)"VIM", (char_u *)"");
5922 didset_vim = FALSE;
5923 }
5924 if (didset_vimruntime)
5925 {
5926 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5927 didset_vimruntime = FALSE;
5928 }
5929 }
5930
Bram Moolenaar1a384422010-07-14 19:53:30 +02005931#ifdef FEAT_SYN_HL
5932 /* 'colorcolumn' */
5933 else if (varp == &curwin->w_p_cc)
5934 errmsg = check_colorcolumn(curwin);
5935#endif
5936
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937#ifdef FEAT_MULTI_LANG
5938 /* 'helplang' */
5939 else if (varp == &p_hlg)
5940 {
5941 /* Check for "", "ab", "ab,cd", etc. */
5942 for (s = p_hlg; *s != NUL; s += 3)
5943 {
5944 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5945 {
5946 errmsg = e_invarg;
5947 break;
5948 }
5949 if (s[2] == NUL)
5950 break;
5951 }
5952 }
5953#endif
5954
5955 /* 'highlight' */
5956 else if (varp == &p_hl)
5957 {
5958 if (highlight_changed() == FAIL)
5959 errmsg = e_invarg; /* invalid flags */
5960 }
5961
5962 /* 'nrformats' */
5963 else if (gvarp == &p_nf)
5964 {
5965 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5966 errmsg = e_invarg;
5967 }
5968
5969#ifdef FEAT_SESSION
5970 /* 'sessionoptions' */
5971 else if (varp == &p_ssop)
5972 {
5973 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5974 errmsg = e_invarg;
5975 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5976 {
5977 /* Don't allow both "sesdir" and "curdir". */
5978 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5979 errmsg = e_invarg;
5980 }
5981 }
5982 /* 'viewoptions' */
5983 else if (varp == &p_vop)
5984 {
5985 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5986 errmsg = e_invarg;
5987 }
5988#endif
5989
5990 /* 'scrollopt' */
5991#ifdef FEAT_SCROLLBIND
5992 else if (varp == &p_sbo)
5993 {
5994 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5995 errmsg = e_invarg;
5996 }
5997#endif
5998
5999 /* 'ambiwidth' */
6000#ifdef FEAT_MBYTE
6001 else if (varp == &p_ambw)
6002 {
6003 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6004 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006005 else if (set_chars_option(&p_lcs) != NULL)
6006 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6007# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6008 else if (set_chars_option(&p_fcs) != NULL)
6009 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6010# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011 }
6012#endif
6013
6014 /* 'background' */
6015 else if (varp == &p_bg)
6016 {
6017 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6018 {
6019#ifdef FEAT_EVAL
6020 int dark = (*p_bg == 'd');
6021#endif
6022
6023 init_highlight(FALSE, FALSE);
6024
6025#ifdef FEAT_EVAL
6026 if (dark != (*p_bg == 'd')
6027 && get_var_value((char_u *)"g:colors_name") != NULL)
6028 {
6029 /* The color scheme must have set 'background' back to another
6030 * value, that's not what we want here. Disable the color
6031 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006032 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006033 free_string_option(p_bg);
6034 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6035 check_string_option(&p_bg);
6036 init_highlight(FALSE, FALSE);
6037 }
6038#endif
6039 }
6040 else
6041 errmsg = e_invarg;
6042 }
6043
6044 /* 'wildmode' */
6045 else if (varp == &p_wim)
6046 {
6047 if (check_opt_wim() == FAIL)
6048 errmsg = e_invarg;
6049 }
6050
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006051#ifdef FEAT_CMDL_COMPL
6052 /* 'wildoptions' */
6053 else if (varp == &p_wop)
6054 {
6055 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6056 errmsg = e_invarg;
6057 }
6058#endif
6059
Bram Moolenaar071d4272004-06-13 20:20:40 +00006060#ifdef FEAT_WAK
6061 /* 'winaltkeys' */
6062 else if (varp == &p_wak)
6063 {
6064 if (*p_wak == NUL
6065 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6066 errmsg = e_invarg;
6067# ifdef FEAT_MENU
6068# ifdef FEAT_GUI_MOTIF
6069 else if (gui.in_use)
6070 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6071# else
6072# ifdef FEAT_GUI_GTK
6073 else if (gui.in_use)
6074 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6075# endif
6076# endif
6077# endif
6078 }
6079#endif
6080
6081#ifdef FEAT_AUTOCMD
6082 /* 'eventignore' */
6083 else if (varp == &p_ei)
6084 {
6085 if (check_ei() == FAIL)
6086 errmsg = e_invarg;
6087 }
6088#endif
6089
6090#ifdef FEAT_MBYTE
6091 /* 'encoding' and 'fileencoding' */
6092 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6093 {
6094 if (gvarp == &p_fenc)
6095 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006096 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006097 errmsg = e_modifiable;
6098 else if (vim_strchr(*varp, ',') != NULL)
6099 /* No comma allowed in 'fileencoding'; catches confusing it
6100 * with 'fileencodings'. */
6101 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006102 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006103 {
6104# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006105 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006106 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006108 /* Add 'fileencoding' to the swap file. */
6109 ml_setflags(curbuf);
6110 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 }
6112 if (errmsg == NULL)
6113 {
6114 /* canonize the value, so that STRCMP() can be used on it */
6115 p = enc_canonize(*varp);
6116 if (p != NULL)
6117 {
6118 vim_free(*varp);
6119 *varp = p;
6120 }
6121 if (varp == &p_enc)
6122 {
6123 errmsg = mb_init();
6124# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006125 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006126# endif
6127 }
6128 }
6129
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006130# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006131 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6132 {
6133 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6134 if (STRCMP(p_tenc, "utf-8") != 0)
6135 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6136 }
6137# endif
6138
6139 if (errmsg == NULL)
6140 {
6141# ifdef FEAT_KEYMAP
6142 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6143 * (with another encoding). */
6144 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6145 (void)keymap_init();
6146# endif
6147
6148 /* When 'termencoding' is not empty and 'encoding' changes or when
6149 * 'termencoding' changes, need to setup for keyboard input and
6150 * display output conversion. */
6151 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6152 {
6153 convert_setup(&input_conv, p_tenc, p_enc);
6154 convert_setup(&output_conv, p_enc, p_tenc);
6155 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006156
6157# if defined(WIN3264) && defined(FEAT_MBYTE)
6158 /* $HOME may have characters in active code page. */
6159 if (varp == &p_enc)
6160 init_homedir();
6161# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006162 }
6163 }
6164#endif
6165
6166#if defined(FEAT_POSTSCRIPT)
6167 else if (varp == &p_penc)
6168 {
6169 /* Canonize printencoding if VIM standard one */
6170 p = enc_canonize(p_penc);
6171 if (p != NULL)
6172 {
6173 vim_free(p_penc);
6174 p_penc = p;
6175 }
6176 else
6177 {
6178 /* Ensure lower case and '-' for '_' */
6179 for (s = p_penc; *s != NUL; s++)
6180 {
6181 if (*s == '_')
6182 *s = '-';
6183 else
6184 *s = TOLOWER_ASC(*s);
6185 }
6186 }
6187 }
6188#endif
6189
Bram Moolenaar9372a112005-12-06 19:59:18 +00006190#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006191 else if (varp == &p_imak)
6192 {
6193 if (gui.in_use && !im_xim_isvalid_imactivate())
6194 errmsg = e_invarg;
6195 }
6196#endif
6197
6198#ifdef FEAT_KEYMAP
6199 else if (varp == &curbuf->b_p_keymap)
6200 {
6201 /* load or unload key mapping tables */
6202 errmsg = keymap_init();
6203
Bram Moolenaarfab06232009-03-04 03:13:35 +00006204 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006205 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006206 if (*curbuf->b_p_keymap != NUL)
6207 {
6208 /* Installed a new keymap, switch on using it. */
6209 curbuf->b_p_iminsert = B_IMODE_LMAP;
6210 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6211 curbuf->b_p_imsearch = B_IMODE_LMAP;
6212 }
6213 else
6214 {
6215 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6216 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6217 curbuf->b_p_iminsert = B_IMODE_NONE;
6218 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6219 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6220 }
6221 if ((opt_flags & OPT_LOCAL) == 0)
6222 {
6223 set_iminsert_global();
6224 set_imsearch_global();
6225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006226# ifdef FEAT_WINDOWS
6227 status_redraw_curbuf();
6228# endif
6229 }
6230 }
6231#endif
6232
6233 /* 'fileformat' */
6234 else if (gvarp == &p_ff)
6235 {
6236 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6237 errmsg = e_modifiable;
6238 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6239 errmsg = e_invarg;
6240 else
6241 {
6242 /* may also change 'textmode' */
6243 if (get_fileformat(curbuf) == EOL_DOS)
6244 curbuf->b_p_tx = TRUE;
6245 else
6246 curbuf->b_p_tx = FALSE;
6247#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006248 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006249#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006250 /* update flag in swap file */
6251 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006252 /* Redraw needed when switching to/from "mac": a CR in the text
6253 * will be displayed differently. */
6254 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6255 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006256 }
6257 }
6258
6259 /* 'fileformats' */
6260 else if (varp == &p_ffs)
6261 {
6262 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6263 errmsg = e_invarg;
6264 else
6265 {
6266 /* also change 'textauto' */
6267 if (*p_ffs == NUL)
6268 p_ta = FALSE;
6269 else
6270 p_ta = TRUE;
6271 }
6272 }
6273
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006274#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006275 /* 'cryptkey' */
6276 else if (gvarp == &p_key)
6277 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006278# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006279 /* Make sure the ":set" command doesn't show the new value in the
6280 * history. */
6281 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006282# endif
6283 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6284 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006285 ml_set_crypt_key(curbuf, oldval,
6286 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006287 }
6288
6289 else if (gvarp == &p_cm)
6290 {
6291 if (opt_flags & OPT_LOCAL)
6292 p = curbuf->b_p_cm;
6293 else
6294 p = p_cm;
6295 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6296 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006297 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006298 errmsg = e_invarg;
6299 else
6300 {
6301 /* When setting the global value to empty, make it "zip". */
6302 if (*p_cm == NUL)
6303 {
6304 if (new_value_alloced)
6305 free_string_option(p_cm);
6306 p_cm = vim_strsave((char_u *)"zip");
6307 new_value_alloced = TRUE;
6308 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006309 /* When using ":set cm=name" the local value is going to be empty.
6310 * Do that here, otherwise the crypt functions will still use the
6311 * local value. */
6312 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6313 {
6314 free_string_option(curbuf->b_p_cm);
6315 curbuf->b_p_cm = empty_option;
6316 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006317
6318 /* Need to update the swapfile when the effective method changed.
6319 * Set "s" to the effective old value, "p" to the effective new
6320 * method and compare. */
6321 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6322 s = p_cm; /* was previously using the global value */
6323 else
6324 s = oldval;
6325 if (*curbuf->b_p_cm == NUL)
6326 p = p_cm; /* is now using the global value */
6327 else
6328 p = curbuf->b_p_cm;
6329 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006330 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006331
6332 /* If the global value changes need to update the swapfile for all
6333 * buffers using that value. */
6334 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6335 {
6336 buf_T *buf;
6337
6338 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6339 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006340 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006341 }
6342 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343 }
6344#endif
6345
6346 /* 'matchpairs' */
6347 else if (gvarp == &p_mps)
6348 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006349#ifdef FEAT_MBYTE
6350 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006352 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006353 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006354 int x2 = -1;
6355 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006356
6357 if (*p != NUL)
6358 p += mb_ptr2len(p);
6359 if (*p != NUL)
6360 x2 = *p++;
6361 if (*p != NUL)
6362 {
6363 x3 = mb_ptr2char(p);
6364 p += mb_ptr2len(p);
6365 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006366 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006367 {
6368 errmsg = e_invarg;
6369 break;
6370 }
6371 if (*p == NUL)
6372 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006373 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006374 }
6375 else
6376#endif
6377 {
6378 /* Check for "x:y,x:y" */
6379 for (p = *varp; *p != NUL; p += 4)
6380 {
6381 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6382 {
6383 errmsg = e_invarg;
6384 break;
6385 }
6386 if (p[3] == NUL)
6387 break;
6388 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006389 }
6390 }
6391
6392#ifdef FEAT_COMMENTS
6393 /* 'comments' */
6394 else if (gvarp == &p_com)
6395 {
6396 for (s = *varp; *s; )
6397 {
6398 while (*s && *s != ':')
6399 {
6400 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6401 && !VIM_ISDIGIT(*s) && *s != '-')
6402 {
6403 errmsg = illegal_char(errbuf, *s);
6404 break;
6405 }
6406 ++s;
6407 }
6408 if (*s++ == NUL)
6409 errmsg = (char_u *)N_("E524: Missing colon");
6410 else if (*s == ',' || *s == NUL)
6411 errmsg = (char_u *)N_("E525: Zero length string");
6412 if (errmsg != NULL)
6413 break;
6414 while (*s && *s != ',')
6415 {
6416 if (*s == '\\' && s[1] != NUL)
6417 ++s;
6418 ++s;
6419 }
6420 s = skip_to_option_part(s);
6421 }
6422 }
6423#endif
6424
6425 /* 'listchars' */
6426 else if (varp == &p_lcs)
6427 {
6428 errmsg = set_chars_option(varp);
6429 }
6430
6431#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6432 /* 'fillchars' */
6433 else if (varp == &p_fcs)
6434 {
6435 errmsg = set_chars_option(varp);
6436 }
6437#endif
6438
6439#ifdef FEAT_CMDWIN
6440 /* 'cedit' */
6441 else if (varp == &p_cedit)
6442 {
6443 errmsg = check_cedit();
6444 }
6445#endif
6446
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006447 /* 'verbosefile' */
6448 else if (varp == &p_vfile)
6449 {
6450 verbose_stop();
6451 if (*p_vfile != NUL && verbose_open() == FAIL)
6452 errmsg = e_invarg;
6453 }
6454
Bram Moolenaar071d4272004-06-13 20:20:40 +00006455#ifdef FEAT_VIMINFO
6456 /* 'viminfo' */
6457 else if (varp == &p_viminfo)
6458 {
6459 for (s = p_viminfo; *s;)
6460 {
6461 /* Check it's a valid character */
6462 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6463 {
6464 errmsg = illegal_char(errbuf, *s);
6465 break;
6466 }
6467 if (*s == 'n') /* name is always last one */
6468 {
6469 break;
6470 }
6471 else if (*s == 'r') /* skip until next ',' */
6472 {
6473 while (*++s && *s != ',')
6474 ;
6475 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006476 else if (*s == '%')
6477 {
6478 /* optional number */
6479 while (vim_isdigit(*++s))
6480 ;
6481 }
6482 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483 ++s; /* no extra chars */
6484 else /* must have a number */
6485 {
6486 while (vim_isdigit(*++s))
6487 ;
6488
6489 if (!VIM_ISDIGIT(*(s - 1)))
6490 {
6491 if (errbuf != NULL)
6492 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006493 sprintf((char *)errbuf,
6494 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006495 transchar_byte(*(s - 1)));
6496 errmsg = errbuf;
6497 }
6498 else
6499 errmsg = (char_u *)"";
6500 break;
6501 }
6502 }
6503 if (*s == ',')
6504 ++s;
6505 else if (*s)
6506 {
6507 if (errbuf != NULL)
6508 errmsg = (char_u *)N_("E527: Missing comma");
6509 else
6510 errmsg = (char_u *)"";
6511 break;
6512 }
6513 }
6514 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6515 errmsg = (char_u *)N_("E528: Must specify a ' value");
6516 }
6517#endif /* FEAT_VIMINFO */
6518
6519 /* terminal options */
6520 else if (istermoption(&options[opt_idx]) && full_screen)
6521 {
6522 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6523 if (varp == &T_CCO)
6524 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006525 int colors = atoi((char *)T_CCO);
6526
6527 /* Only reinitialize colors if t_Co value has really changed to
6528 * avoid expensive reload of colorscheme if t_Co is set to the
6529 * same value multiple times. */
6530 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006531 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006532 t_colors = colors;
6533 if (t_colors <= 1)
6534 {
6535 if (new_value_alloced)
6536 vim_free(T_CCO);
6537 T_CCO = empty_option;
6538 }
6539 /* We now have a different color setup, initialize it again. */
6540 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006541 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006542 }
6543 ttest(FALSE);
6544 if (varp == &T_ME)
6545 {
6546 out_str(T_ME);
6547 redraw_later(CLEAR);
6548#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6549 /* Since t_me has been set, this probably means that the user
6550 * wants to use this as default colors. Need to reset default
6551 * background/foreground colors. */
6552 mch_set_normal_colors();
6553#endif
6554 }
6555 }
6556
6557#ifdef FEAT_LINEBREAK
6558 /* 'showbreak' */
6559 else if (varp == &p_sbr)
6560 {
6561 for (s = p_sbr; *s; )
6562 {
6563 if (ptr2cells(s) != 1)
6564 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006565 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566 }
6567 }
6568#endif
6569
6570#ifdef FEAT_GUI
6571 /* 'guifont' */
6572 else if (varp == &p_guifont)
6573 {
6574 if (gui.in_use)
6575 {
6576 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006577# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 /*
6579 * Put up a font dialog and let the user select a new value.
6580 * If this is cancelled go back to the old value but don't
6581 * give an error message.
6582 */
6583 if (STRCMP(p, "*") == 0)
6584 {
6585 p = gui_mch_font_dialog(oldval);
6586
6587 if (new_value_alloced)
6588 free_string_option(p_guifont);
6589
6590 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6591 new_value_alloced = TRUE;
6592 }
6593# endif
6594 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6595 {
6596# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6597 if (STRCMP(p_guifont, "*") == 0)
6598 {
6599 /* Dialog was cancelled: Keep the old value without giving
6600 * an error message. */
6601 if (new_value_alloced)
6602 free_string_option(p_guifont);
6603 p_guifont = vim_strsave(oldval);
6604 new_value_alloced = TRUE;
6605 }
6606 else
6607# endif
6608 errmsg = (char_u *)N_("E596: Invalid font(s)");
6609 }
6610 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006611 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006612 }
6613# ifdef FEAT_XFONTSET
6614 else if (varp == &p_guifontset)
6615 {
6616 if (STRCMP(p_guifontset, "*") == 0)
6617 errmsg = (char_u *)N_("E597: can't select fontset");
6618 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6619 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006620 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006621 }
6622# endif
6623# ifdef FEAT_MBYTE
6624 else if (varp == &p_guifontwide)
6625 {
6626 if (STRCMP(p_guifontwide, "*") == 0)
6627 errmsg = (char_u *)N_("E533: can't select wide font");
6628 else if (gui_get_wide_font() == FAIL)
6629 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006630 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631 }
6632# endif
6633#endif
6634
6635#ifdef CURSOR_SHAPE
6636 /* 'guicursor' */
6637 else if (varp == &p_guicursor)
6638 errmsg = parse_shape_opt(SHAPE_CURSOR);
6639#endif
6640
6641#ifdef FEAT_MOUSESHAPE
6642 /* 'mouseshape' */
6643 else if (varp == &p_mouseshape)
6644 {
6645 errmsg = parse_shape_opt(SHAPE_MOUSE);
6646 update_mouseshape(-1);
6647 }
6648#endif
6649
6650#ifdef FEAT_PRINTER
6651 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006652 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006653# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006654 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006655 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006656# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006657#endif
6658
6659#ifdef FEAT_LANGMAP
6660 /* 'langmap' */
6661 else if (varp == &p_langmap)
6662 langmap_set();
6663#endif
6664
6665#ifdef FEAT_LINEBREAK
6666 /* 'breakat' */
6667 else if (varp == &p_breakat)
6668 fill_breakat_flags();
6669#endif
6670
6671#ifdef FEAT_TITLE
6672 /* 'titlestring' and 'iconstring' */
6673 else if (varp == &p_titlestring || varp == &p_iconstring)
6674 {
6675# ifdef FEAT_STL_OPT
6676 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6677
6678 /* NULL => statusline syntax */
6679 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6680 stl_syntax |= flagval;
6681 else
6682 stl_syntax &= ~flagval;
6683# endif
6684 did_set_title(varp == &p_iconstring);
6685
6686 }
6687#endif
6688
6689#ifdef FEAT_GUI
6690 /* 'guioptions' */
6691 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006692 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006693 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006694 redraw_gui_only = TRUE;
6695 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006696#endif
6697
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006698#if defined(FEAT_GUI_TABLINE)
6699 /* 'guitablabel' */
6700 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006701 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006702 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006703 redraw_gui_only = TRUE;
6704 }
6705 /* 'guitabtooltip' */
6706 else if (varp == &p_gtt)
6707 {
6708 redraw_gui_only = TRUE;
6709 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006710#endif
6711
Bram Moolenaar071d4272004-06-13 20:20:40 +00006712#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6713 /* 'ttymouse' */
6714 else if (varp == &p_ttym)
6715 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006716 /* Switch the mouse off before changing the escape sequences used for
6717 * that. */
6718 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6720 errmsg = e_invarg;
6721 else
6722 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006723 if (termcap_active)
6724 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006725 }
6726#endif
6727
Bram Moolenaar071d4272004-06-13 20:20:40 +00006728 /* 'selection' */
6729 else if (varp == &p_sel)
6730 {
6731 if (*p_sel == NUL
6732 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6733 errmsg = e_invarg;
6734 }
6735
6736 /* 'selectmode' */
6737 else if (varp == &p_slm)
6738 {
6739 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6740 errmsg = e_invarg;
6741 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006742
6743#ifdef FEAT_BROWSE
6744 /* 'browsedir' */
6745 else if (varp == &p_bsdir)
6746 {
6747 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6748 && !mch_isdir(p_bsdir))
6749 errmsg = e_invarg;
6750 }
6751#endif
6752
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753 /* 'keymodel' */
6754 else if (varp == &p_km)
6755 {
6756 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6757 errmsg = e_invarg;
6758 else
6759 {
6760 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6761 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6762 }
6763 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006764
6765 /* 'mousemodel' */
6766 else if (varp == &p_mousem)
6767 {
6768 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6769 errmsg = e_invarg;
6770#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6771 else if (*p_mousem != *oldval)
6772 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6773 * to create or delete the popup menus. */
6774 gui_motif_update_mousemodel(root_menu);
6775#endif
6776 }
6777
6778 /* 'switchbuf' */
6779 else if (varp == &p_swb)
6780 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006781 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006782 errmsg = e_invarg;
6783 }
6784
6785 /* 'debug' */
6786 else if (varp == &p_debug)
6787 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006788 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006789 errmsg = e_invarg;
6790 }
6791
6792 /* 'display' */
6793 else if (varp == &p_dy)
6794 {
6795 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6796 errmsg = e_invarg;
6797 else
6798 (void)init_chartab();
6799
6800 }
6801
6802#ifdef FEAT_VERTSPLIT
6803 /* 'eadirection' */
6804 else if (varp == &p_ead)
6805 {
6806 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6807 errmsg = e_invarg;
6808 }
6809#endif
6810
6811#ifdef FEAT_CLIPBOARD
6812 /* 'clipboard' */
6813 else if (varp == &p_cb)
6814 errmsg = check_clipboard_option();
6815#endif
6816
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006817#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006818 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6819 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006820 else if (varp == &(curwin->w_s->b_p_spl)
6821 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006822 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006823 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006824 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006825 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006826 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006827 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006828 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006829 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006830 /* 'spellsuggest' */
6831 else if (varp == &p_sps)
6832 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006833 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006834 errmsg = e_invarg;
6835 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006836 /* 'mkspellmem' */
6837 else if (varp == &p_msm)
6838 {
6839 if (spell_check_msm() != OK)
6840 errmsg = e_invarg;
6841 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006842#endif
6843
Bram Moolenaar071d4272004-06-13 20:20:40 +00006844#ifdef FEAT_QUICKFIX
6845 /* When 'bufhidden' is set, check for valid value. */
6846 else if (gvarp == &p_bh)
6847 {
6848 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6849 errmsg = e_invarg;
6850 }
6851
6852 /* When 'buftype' is set, check for valid value. */
6853 else if (gvarp == &p_bt)
6854 {
6855 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6856 errmsg = e_invarg;
6857 else
6858 {
6859# ifdef FEAT_WINDOWS
6860 if (curwin->w_status_height)
6861 {
6862 curwin->w_redr_status = TRUE;
6863 redraw_later(VALID);
6864 }
6865# endif
6866 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006867# ifdef FEAT_TITLE
6868 redraw_titles();
6869# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006870 }
6871 }
6872#endif
6873
6874#ifdef FEAT_STL_OPT
6875 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006876 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006877 {
6878 int wid;
6879
6880 if (varp == &p_ruf) /* reset ru_wid first */
6881 ru_wid = 0;
6882 s = *varp;
6883 if (varp == &p_ruf && *s == '%')
6884 {
6885 /* set ru_wid if 'ruf' starts with "%99(" */
6886 if (*++s == '-') /* ignore a '-' */
6887 s++;
6888 wid = getdigits(&s);
6889 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6890 ru_wid = wid;
6891 else
6892 errmsg = check_stl_option(p_ruf);
6893 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006894 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006895 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006896 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006897 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898 comp_col();
6899 }
6900#endif
6901
6902#ifdef FEAT_INS_EXPAND
6903 /* check if it is a valid value for 'complete' -- Acevedo */
6904 else if (gvarp == &p_cpt)
6905 {
6906 for (s = *varp; *s;)
6907 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006908 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006909 s++;
6910 if (!*s)
6911 break;
6912 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6913 {
6914 errmsg = illegal_char(errbuf, *s);
6915 break;
6916 }
6917 if (*++s != NUL && *s != ',' && *s != ' ')
6918 {
6919 if (s[-1] == 'k' || s[-1] == 's')
6920 {
6921 /* skip optional filename after 'k' and 's' */
6922 while (*s && *s != ',' && *s != ' ')
6923 {
6924 if (*s == '\\')
6925 ++s;
6926 ++s;
6927 }
6928 }
6929 else
6930 {
6931 if (errbuf != NULL)
6932 {
6933 sprintf((char *)errbuf,
6934 _("E535: Illegal character after <%c>"),
6935 *--s);
6936 errmsg = errbuf;
6937 }
6938 else
6939 errmsg = (char_u *)"";
6940 break;
6941 }
6942 }
6943 }
6944 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006945
6946 /* 'completeopt' */
6947 else if (varp == &p_cot)
6948 {
6949 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6950 errmsg = e_invarg;
6951 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006952#endif /* FEAT_INS_EXPAND */
6953
6954
6955#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6956 else if (varp == &p_toolbar)
6957 {
6958 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6959 &toolbar_flags, TRUE) != OK)
6960 errmsg = e_invarg;
6961 else
6962 {
6963 out_flush();
6964 gui_mch_show_toolbar((toolbar_flags &
6965 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6966 }
6967 }
6968#endif
6969
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006970#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006971 /* 'toolbariconsize': GTK+ 2 only */
6972 else if (varp == &p_tbis)
6973 {
6974 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6975 errmsg = e_invarg;
6976 else
6977 {
6978 out_flush();
6979 gui_mch_show_toolbar((toolbar_flags &
6980 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6981 }
6982 }
6983#endif
6984
6985 /* 'pastetoggle': translate key codes like in a mapping */
6986 else if (varp == &p_pt)
6987 {
6988 if (*p_pt)
6989 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006990 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006991 if (p != NULL)
6992 {
6993 if (new_value_alloced)
6994 free_string_option(p_pt);
6995 p_pt = p;
6996 new_value_alloced = TRUE;
6997 }
6998 }
6999 }
7000
7001 /* 'backspace' */
7002 else if (varp == &p_bs)
7003 {
7004 if (VIM_ISDIGIT(*p_bs))
7005 {
7006 if (*p_bs >'2' || p_bs[1] != NUL)
7007 errmsg = e_invarg;
7008 }
7009 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7010 errmsg = e_invarg;
7011 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007012 else if (varp == &p_bo)
7013 {
7014 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7015 errmsg = e_invarg;
7016 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007018#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007019 /* 'casemap' */
7020 else if (varp == &p_cmp)
7021 {
7022 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7023 errmsg = e_invarg;
7024 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007026
7027#ifdef FEAT_DIFF
7028 /* 'diffopt' */
7029 else if (varp == &p_dip)
7030 {
7031 if (diffopt_changed() == FAIL)
7032 errmsg = e_invarg;
7033 }
7034#endif
7035
7036#ifdef FEAT_FOLDING
7037 /* 'foldmethod' */
7038 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7039 {
7040 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7041 || *curwin->w_p_fdm == NUL)
7042 errmsg = e_invarg;
7043 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007044 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007045 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007046 if (foldmethodIsDiff(curwin))
7047 newFoldLevel();
7048 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049 }
7050# ifdef FEAT_EVAL
7051 /* 'foldexpr' */
7052 else if (varp == &curwin->w_p_fde)
7053 {
7054 if (foldmethodIsExpr(curwin))
7055 foldUpdateAll(curwin);
7056 }
7057# endif
7058 /* 'foldmarker' */
7059 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7060 {
7061 p = vim_strchr(*varp, ',');
7062 if (p == NULL)
7063 errmsg = (char_u *)N_("E536: comma required");
7064 else if (p == *varp || p[1] == NUL)
7065 errmsg = e_invarg;
7066 else if (foldmethodIsMarker(curwin))
7067 foldUpdateAll(curwin);
7068 }
7069 /* 'commentstring' */
7070 else if (gvarp == &p_cms)
7071 {
7072 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7073 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7074 }
7075 /* 'foldopen' */
7076 else if (varp == &p_fdo)
7077 {
7078 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7079 errmsg = e_invarg;
7080 }
7081 /* 'foldclose' */
7082 else if (varp == &p_fcl)
7083 {
7084 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7085 errmsg = e_invarg;
7086 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007087 /* 'foldignore' */
7088 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7089 {
7090 if (foldmethodIsIndent(curwin))
7091 foldUpdateAll(curwin);
7092 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007093#endif
7094
7095#ifdef FEAT_VIRTUALEDIT
7096 /* 'virtualedit' */
7097 else if (varp == &p_ve)
7098 {
7099 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7100 errmsg = e_invarg;
7101 else if (STRCMP(p_ve, oldval) != 0)
7102 {
7103 /* Recompute cursor position in case the new 've' setting
7104 * changes something. */
7105 validate_virtcol();
7106 coladvance(curwin->w_virtcol);
7107 }
7108 }
7109#endif
7110
7111#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7112 else if (varp == &p_csqf)
7113 {
7114 if (p_csqf != NULL)
7115 {
7116 p = p_csqf;
7117 while (*p != NUL)
7118 {
7119 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7120 || p[1] == NUL
7121 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7122 || (p[2] != NUL && p[2] != ','))
7123 {
7124 errmsg = e_invarg;
7125 break;
7126 }
7127 else if (p[2] == NUL)
7128 break;
7129 else
7130 p += 3;
7131 }
7132 }
7133 }
7134#endif
7135
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007136#ifdef FEAT_CINDENT
7137 /* 'cinoptions' */
7138 else if (gvarp == &p_cino)
7139 {
7140 /* TODO: recognize errors */
7141 parse_cino(curbuf);
7142 }
7143#endif
7144
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007145#if defined(FEAT_RENDER_OPTIONS)
7146 else if (varp == &p_rop && gui.in_use)
7147 {
7148 if (!gui_mch_set_rendering_options(p_rop))
7149 errmsg = e_invarg;
7150 }
7151#endif
7152
Bram Moolenaar071d4272004-06-13 20:20:40 +00007153 /* Options that are a list of flags. */
7154 else
7155 {
7156 p = NULL;
7157 if (varp == &p_ww)
7158 p = (char_u *)WW_ALL;
7159 if (varp == &p_shm)
7160 p = (char_u *)SHM_ALL;
7161 else if (varp == &(p_cpo))
7162 p = (char_u *)CPO_ALL;
7163 else if (varp == &(curbuf->b_p_fo))
7164 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007165#ifdef FEAT_CONCEAL
7166 else if (varp == &curwin->w_p_cocu)
7167 p = (char_u *)COCU_ALL;
7168#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007169 else if (varp == &p_mouse)
7170 {
7171#ifdef FEAT_MOUSE
7172 p = (char_u *)MOUSE_ALL;
7173#else
7174 if (*p_mouse != NUL)
7175 errmsg = (char_u *)N_("E538: No mouse support");
7176#endif
7177 }
7178#if defined(FEAT_GUI)
7179 else if (varp == &p_go)
7180 p = (char_u *)GO_ALL;
7181#endif
7182 if (p != NULL)
7183 {
7184 for (s = *varp; *s; ++s)
7185 if (vim_strchr(p, *s) == NULL)
7186 {
7187 errmsg = illegal_char(errbuf, *s);
7188 break;
7189 }
7190 }
7191 }
7192
7193 /*
7194 * If error detected, restore the previous value.
7195 */
7196 if (errmsg != NULL)
7197 {
7198 if (new_value_alloced)
7199 free_string_option(*varp);
7200 *varp = oldval;
7201 /*
7202 * When resetting some values, need to act on it.
7203 */
7204 if (did_chartab)
7205 (void)init_chartab();
7206 if (varp == &p_hl)
7207 (void)highlight_changed();
7208 }
7209 else
7210 {
7211#ifdef FEAT_EVAL
7212 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007213 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007214#endif
7215 /*
7216 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007217 * Use "free_oldval", because recursiveness may change the flags under
7218 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007219 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007220 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007221 free_string_option(oldval);
7222 if (new_value_alloced)
7223 options[opt_idx].flags |= P_ALLOCED;
7224 else
7225 options[opt_idx].flags &= ~P_ALLOCED;
7226
7227 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007228 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007229 {
7230 /* global option with local value set to use global value; free
7231 * the local value and make it empty */
7232 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7233 free_string_option(*(char_u **)p);
7234 *(char_u **)p = empty_option;
7235 }
7236
7237 /* May set global value for local option. */
7238 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7239 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007240
7241#ifdef FEAT_AUTOCMD
7242 /*
7243 * Trigger the autocommand only after setting the flags.
7244 */
7245# ifdef FEAT_SYN_HL
7246 /* When 'syntax' is set, load the syntax of that name */
7247 if (varp == &(curbuf->b_p_syn))
7248 {
7249 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7250 curbuf->b_fname, TRUE, curbuf);
7251 }
7252# endif
7253 else if (varp == &(curbuf->b_p_ft))
7254 {
7255 /* 'filetype' is set, trigger the FileType autocommand */
7256 did_filetype = TRUE;
7257 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7258 curbuf->b_fname, TRUE, curbuf);
7259 }
7260#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007261#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007262 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007263 {
7264 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007265 char_u *q = curwin->w_s->b_p_spl;
7266
7267 /* Skip the first name if it is "cjk". */
7268 if (STRNCMP(q, "cjk,", 4) == 0)
7269 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007270
7271 /*
7272 * Source the spell/LANG.vim in 'runtimepath'.
7273 * They could set 'spellcapcheck' depending on the language.
7274 * Use the first name in 'spelllang' up to '_region' or
7275 * '.encoding'.
7276 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007277 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007278 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7279 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007280 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007281 source_runtime(fname, TRUE);
7282 }
7283#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007284 }
7285
7286#ifdef FEAT_MOUSE
7287 if (varp == &p_mouse)
7288 {
7289# ifdef FEAT_MOUSE_TTY
7290 if (*p_mouse == NUL)
7291 mch_setmouse(FALSE); /* switch mouse off */
7292 else
7293# endif
7294 setmouse(); /* in case 'mouse' changed */
7295 }
7296#endif
7297
Bram Moolenaar913077c2012-03-28 19:59:04 +02007298 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007299 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007300 curwin->w_set_curswant = TRUE;
7301
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007302#ifdef FEAT_GUI
7303 /* check redraw when it's not a GUI option or the GUI is active. */
7304 if (!redraw_gui_only || gui.in_use)
7305#endif
7306 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007307
7308 return errmsg;
7309}
7310
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007311#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007312/*
7313 * Simple int comparison function for use with qsort()
7314 */
7315 static int
7316int_cmp(a, b)
7317 const void *a;
7318 const void *b;
7319{
7320 return *(const int *)a - *(const int *)b;
7321}
7322
7323/*
7324 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7325 * Returns error message, NULL if it's OK.
7326 */
7327 char_u *
7328check_colorcolumn(wp)
7329 win_T *wp;
7330{
7331 char_u *s;
7332 int col;
7333 int count = 0;
7334 int color_cols[256];
7335 int i;
7336 int j = 0;
7337
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007338 if (wp->w_buffer == NULL)
7339 return NULL; /* buffer was closed */
7340
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007341 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007342 {
7343 if (*s == '-' || *s == '+')
7344 {
7345 /* -N and +N: add to 'textwidth' */
7346 col = (*s == '-') ? -1 : 1;
7347 ++s;
7348 if (!VIM_ISDIGIT(*s))
7349 return e_invarg;
7350 col = col * getdigits(&s);
7351 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007352 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007353 col += wp->w_buffer->b_p_tw;
7354 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007355 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007356 }
7357 else if (VIM_ISDIGIT(*s))
7358 col = getdigits(&s);
7359 else
7360 return e_invarg;
7361 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007362skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007363 if (*s == NUL)
7364 break;
7365 if (*s != ',')
7366 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007367 if (*++s == NUL)
7368 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007369 }
7370
7371 vim_free(wp->w_p_cc_cols);
7372 if (count == 0)
7373 wp->w_p_cc_cols = NULL;
7374 else
7375 {
7376 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7377 if (wp->w_p_cc_cols != NULL)
7378 {
7379 /* sort the columns for faster usage on screen redraw inside
7380 * win_line() */
7381 qsort(color_cols, count, sizeof(int), int_cmp);
7382
7383 for (i = 0; i < count; ++i)
7384 /* skip duplicates */
7385 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7386 wp->w_p_cc_cols[j++] = color_cols[i];
7387 wp->w_p_cc_cols[j] = -1; /* end marker */
7388 }
7389 }
7390
7391 return NULL; /* no error */
7392}
7393#endif
7394
Bram Moolenaar071d4272004-06-13 20:20:40 +00007395/*
7396 * Handle setting 'listchars' or 'fillchars'.
7397 * Returns error message, NULL if it's OK.
7398 */
7399 static char_u *
7400set_chars_option(varp)
7401 char_u **varp;
7402{
7403 int round, i, len, entries;
7404 char_u *p, *s;
7405 int c1, c2 = 0;
7406 struct charstab
7407 {
7408 int *cp;
7409 char *name;
7410 };
7411#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7412 static struct charstab filltab[] =
7413 {
7414 {&fill_stl, "stl"},
7415 {&fill_stlnc, "stlnc"},
7416 {&fill_vert, "vert"},
7417 {&fill_fold, "fold"},
7418 {&fill_diff, "diff"},
7419 };
7420#endif
7421 static struct charstab lcstab[] =
7422 {
7423 {&lcs_eol, "eol"},
7424 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007425 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007426 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007427 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007428 {&lcs_tab2, "tab"},
7429 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007430#ifdef FEAT_CONCEAL
7431 {&lcs_conceal, "conceal"},
7432#else
7433 {NULL, "conceal"},
7434#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007435 };
7436 struct charstab *tab;
7437
7438#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7439 if (varp == &p_lcs)
7440#endif
7441 {
7442 tab = lcstab;
7443 entries = sizeof(lcstab) / sizeof(struct charstab);
7444 }
7445#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7446 else
7447 {
7448 tab = filltab;
7449 entries = sizeof(filltab) / sizeof(struct charstab);
7450 }
7451#endif
7452
7453 /* first round: check for valid value, second round: assign values */
7454 for (round = 0; round <= 1; ++round)
7455 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007456 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007457 {
7458 /* After checking that the value is valid: set defaults: space for
7459 * 'fillchars', NUL for 'listchars' */
7460 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007461 if (tab[i].cp != NULL)
7462 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463 if (varp == &p_lcs)
7464 lcs_tab1 = NUL;
7465#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7466 else
7467 fill_diff = '-';
7468#endif
7469 }
7470 p = *varp;
7471 while (*p)
7472 {
7473 for (i = 0; i < entries; ++i)
7474 {
7475 len = (int)STRLEN(tab[i].name);
7476 if (STRNCMP(p, tab[i].name, len) == 0
7477 && p[len] == ':'
7478 && p[len + 1] != NUL)
7479 {
7480 s = p + len + 1;
7481#ifdef FEAT_MBYTE
7482 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007483 if (mb_char2cells(c1) > 1)
7484 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007485#else
7486 c1 = *s++;
7487#endif
7488 if (tab[i].cp == &lcs_tab2)
7489 {
7490 if (*s == NUL)
7491 continue;
7492#ifdef FEAT_MBYTE
7493 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007494 if (mb_char2cells(c2) > 1)
7495 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496#else
7497 c2 = *s++;
7498#endif
7499 }
7500 if (*s == ',' || *s == NUL)
7501 {
7502 if (round)
7503 {
7504 if (tab[i].cp == &lcs_tab2)
7505 {
7506 lcs_tab1 = c1;
7507 lcs_tab2 = c2;
7508 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007509 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510 *(tab[i].cp) = c1;
7511
7512 }
7513 p = s;
7514 break;
7515 }
7516 }
7517 }
7518
7519 if (i == entries)
7520 return e_invarg;
7521 if (*p == ',')
7522 ++p;
7523 }
7524 }
7525
7526 return NULL; /* no error */
7527}
7528
7529#ifdef FEAT_STL_OPT
7530/*
7531 * Check validity of options with the 'statusline' format.
7532 * Return error message or NULL.
7533 */
7534 char_u *
7535check_stl_option(s)
7536 char_u *s;
7537{
7538 int itemcnt = 0;
7539 int groupdepth = 0;
7540 static char_u errbuf[80];
7541
7542 while (*s && itemcnt < STL_MAX_ITEM)
7543 {
7544 /* Check for valid keys after % sequences */
7545 while (*s && *s != '%')
7546 s++;
7547 if (!*s)
7548 break;
7549 s++;
7550 if (*s != '%' && *s != ')')
7551 ++itemcnt;
7552 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7553 {
7554 s++;
7555 continue;
7556 }
7557 if (*s == ')')
7558 {
7559 s++;
7560 if (--groupdepth < 0)
7561 break;
7562 continue;
7563 }
7564 if (*s == '-')
7565 s++;
7566 while (VIM_ISDIGIT(*s))
7567 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007568 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007569 continue;
7570 if (*s == '.')
7571 {
7572 s++;
7573 while (*s && VIM_ISDIGIT(*s))
7574 s++;
7575 }
7576 if (*s == '(')
7577 {
7578 groupdepth++;
7579 continue;
7580 }
7581 if (vim_strchr(STL_ALL, *s) == NULL)
7582 {
7583 return illegal_char(errbuf, *s);
7584 }
7585 if (*s == '{')
7586 {
7587 s++;
7588 while (*s != '}' && *s)
7589 s++;
7590 if (*s != '}')
7591 return (char_u *)N_("E540: Unclosed expression sequence");
7592 }
7593 }
7594 if (itemcnt >= STL_MAX_ITEM)
7595 return (char_u *)N_("E541: too many items");
7596 if (groupdepth != 0)
7597 return (char_u *)N_("E542: unbalanced groups");
7598 return NULL;
7599}
7600#endif
7601
7602#ifdef FEAT_CLIPBOARD
7603/*
7604 * Extract the items in the 'clipboard' option and set global values.
7605 */
7606 static char_u *
7607check_clipboard_option()
7608{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007609 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007610 int new_autoselect_star = FALSE;
7611 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007612 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007613 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007614 regprog_T *new_exclude_prog = NULL;
7615 char_u *errmsg = NULL;
7616 char_u *p;
7617
7618 for (p = p_cb; *p != NUL; )
7619 {
7620 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7621 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007622 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007623 p += 7;
7624 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007625 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007626 && (p[11] == ',' || p[11] == NUL))
7627 {
7628 new_unnamed |= CLIP_UNNAMED_PLUS;
7629 p += 11;
7630 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007631 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007632 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007633 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007634 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007635 p += 10;
7636 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007637 else if (STRNCMP(p, "autoselectplus", 14) == 0
7638 && (p[14] == ',' || p[14] == NUL))
7639 {
7640 new_autoselect_plus = TRUE;
7641 p += 14;
7642 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007643 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007644 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007645 {
7646 new_autoselectml = TRUE;
7647 p += 12;
7648 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007649 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7650 {
7651 new_html = TRUE;
7652 p += 4;
7653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007654 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7655 {
7656 p += 8;
7657 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7658 if (new_exclude_prog == NULL)
7659 errmsg = e_invarg;
7660 break;
7661 }
7662 else
7663 {
7664 errmsg = e_invarg;
7665 break;
7666 }
7667 if (*p == ',')
7668 ++p;
7669 }
7670 if (errmsg == NULL)
7671 {
7672 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007673 clip_autoselect_star = new_autoselect_star;
7674 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007675 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007676 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007677 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007678 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007679#ifdef FEAT_GUI_GTK
7680 if (gui.in_use)
7681 {
7682 gui_gtk_set_selection_targets();
7683 gui_gtk_set_dnd_targets();
7684 }
7685#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007686 }
7687 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007688 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007689
7690 return errmsg;
7691}
7692#endif
7693
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007694#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007695 static char_u *
7696did_set_spell_option(is_spellfile)
7697 int is_spellfile;
7698{
7699 char_u *errmsg = NULL;
7700 win_T *wp;
7701 int l;
7702
7703 if (is_spellfile)
7704 {
7705 l = (int)STRLEN(curwin->w_s->b_p_spf);
7706 if (l > 0 && (l < 4
7707 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7708 errmsg = e_invarg;
7709 }
7710
7711 if (errmsg == NULL)
7712 {
7713 FOR_ALL_WINDOWS(wp)
7714 if (wp->w_buffer == curbuf && wp->w_p_spell)
7715 {
7716 errmsg = did_set_spelllang(wp);
7717# ifdef FEAT_WINDOWS
7718 break;
7719# endif
7720 }
7721 }
7722 return errmsg;
7723}
7724
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007725/*
7726 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7727 * Return error message when failed, NULL when OK.
7728 */
7729 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007730compile_cap_prog(synblock)
7731 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007732{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007733 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007734 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007735
Bram Moolenaar860cae12010-06-05 23:22:07 +02007736 if (*synblock->b_p_spc == NUL)
7737 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007738 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007739 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007740 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007741 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007742 if (re != NULL)
7743 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007744 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007745 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007746 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007747 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007748 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007749 return e_invarg;
7750 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007751 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007752 }
7753
Bram Moolenaar473de612013-06-08 18:19:48 +02007754 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007755 return NULL;
7756}
7757#endif
7758
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007759#if defined(FEAT_EVAL) || defined(PROTO)
7760/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007761 * Set the scriptID for an option, taking care of setting the buffer- or
7762 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007763 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007764 static void
7765set_option_scriptID_idx(opt_idx, opt_flags, id)
7766 int opt_idx;
7767 int opt_flags;
7768 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007769{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007770 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7771 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007772
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007773 /* Remember where the option was set. For local options need to do that
7774 * in the buffer or window structure. */
7775 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007776 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007777 if (both || (opt_flags & OPT_LOCAL))
7778 {
7779 if (indir & PV_BUF)
7780 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7781 else if (indir & PV_WIN)
7782 curwin->w_p_scriptID[indir & PV_MASK] = id;
7783 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007784}
7785#endif
7786
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787/*
7788 * Set the value of a boolean option, and take care of side effects.
7789 * Returns NULL for success, or an error message for an error.
7790 */
7791 static char_u *
7792set_bool_option(opt_idx, varp, value, opt_flags)
7793 int opt_idx; /* index in options[] table */
7794 char_u *varp; /* pointer to the option variable */
7795 int value; /* new value */
7796 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7797{
7798 int old_value = *(int *)varp;
7799
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800 /* Disallow changing some options from secure mode */
7801 if ((secure
7802#ifdef HAVE_SANDBOX
7803 || sandbox != 0
7804#endif
7805 ) && (options[opt_idx].flags & P_SECURE))
7806 return e_secure;
7807
7808 *(int *)varp = value; /* set the new value */
7809#ifdef FEAT_EVAL
7810 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007811 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007812#endif
7813
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007814#ifdef FEAT_GUI
7815 need_mouse_correct = TRUE;
7816#endif
7817
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818 /* May set global value for local option. */
7819 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7820 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7821
7822 /*
7823 * Handle side effects of changing a bool option.
7824 */
7825
7826 /* 'compatible' */
7827 if ((int *)varp == &p_cp)
7828 {
7829 compatible_set();
7830 }
7831
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007832#ifdef FEAT_PERSISTENT_UNDO
7833 /* 'undofile' */
7834 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7835 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007836 /* Only take action when the option was set. When reset we do not
7837 * delete the undo file, the option may be set again without making
7838 * any changes in between. */
7839 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007840 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007841 char_u hash[UNDO_HASH_SIZE];
7842 buf_T *save_curbuf = curbuf;
7843
7844 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007845 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007846 /* When 'undofile' is set globally: for every buffer, otherwise
7847 * only for the current buffer: Try to read in the undofile,
7848 * if one exists, the buffer wasn't changed and the buffer was
7849 * loaded */
7850 if ((curbuf == save_curbuf
7851 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7852 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7853 {
7854 u_compute_hash(hash);
7855 u_read_undo(NULL, hash, curbuf->b_fname);
7856 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007857 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007858 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007859 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007860 }
7861#endif
7862
Bram Moolenaar071d4272004-06-13 20:20:40 +00007863 else if ((int *)varp == &curbuf->b_p_ro)
7864 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007865 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007866 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7867 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007868
7869 /* when 'readonly' is set may give W10 again */
7870 if (curbuf->b_p_ro)
7871 curbuf->b_did_warn = FALSE;
7872
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007874 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007875#endif
7876 }
7877
Bram Moolenaar9c449722010-07-20 18:44:27 +02007878#ifdef FEAT_GUI
7879 else if ((int *)varp == &p_mh)
7880 {
7881 if (!p_mh)
7882 gui_mch_mousehide(FALSE);
7883 }
7884#endif
7885
Bram Moolenaara539df02010-08-01 14:35:05 +02007886#ifdef FEAT_TITLE
7887 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007888 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007889 {
7890 redraw_titles();
7891 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 /* when 'endofline' is changed, redraw the window title */
7893 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007894 {
7895 redraw_titles();
7896 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007897 /* when 'fixeol' is changed, redraw the window title */
7898 else if ((int *)varp == &curbuf->b_p_fixeol)
7899 {
7900 redraw_titles();
7901 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007902# ifdef FEAT_MBYTE
7903 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007904 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007905 {
7906 redraw_titles();
7907 }
7908# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909#endif
7910
7911 /* when 'bin' is set also set some other options */
7912 else if ((int *)varp == &curbuf->b_p_bin)
7913 {
7914 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7915#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007916 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917#endif
7918 }
7919
7920#ifdef FEAT_AUTOCMD
7921 /* when 'buflisted' changes, trigger autocommands */
7922 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7923 {
7924 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7925 NULL, NULL, TRUE, curbuf);
7926 }
7927#endif
7928
7929 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7930 else if ((int *)varp == &curbuf->b_p_swf)
7931 {
7932 if (curbuf->b_p_swf && p_uc)
7933 ml_open_file(curbuf); /* create the swap file */
7934 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007935 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7936 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007937 mf_close_file(curbuf, TRUE); /* remove the swap file */
7938 }
7939
7940 /* when 'terse' is set change 'shortmess' */
7941 else if ((int *)varp == &p_terse)
7942 {
7943 char_u *p;
7944
7945 p = vim_strchr(p_shm, SHM_SEARCH);
7946
7947 /* insert 's' in p_shm */
7948 if (p_terse && p == NULL)
7949 {
7950 STRCPY(IObuff, p_shm);
7951 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007952 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953 }
7954 /* remove 's' from p_shm */
7955 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007956 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957 }
7958
7959 /* when 'paste' is set or reset also change other options */
7960 else if ((int *)varp == &p_paste)
7961 {
7962 paste_option_changed();
7963 }
7964
7965 /* when 'insertmode' is set from an autocommand need to do work here */
7966 else if ((int *)varp == &p_im)
7967 {
7968 if (p_im)
7969 {
7970 if ((State & INSERT) == 0)
7971 need_start_insertmode = TRUE;
7972 stop_insert_mode = FALSE;
7973 }
7974 else
7975 {
7976 need_start_insertmode = FALSE;
7977 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007978 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007979 clear_cmdline = TRUE; /* remove "(insert)" */
7980 restart_edit = 0;
7981 }
7982 }
7983
7984 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7985 else if ((int *)varp == &p_ic && p_hls)
7986 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007987 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007988 }
7989
7990#ifdef FEAT_SEARCH_EXTRA
7991 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7992 else if ((int *)varp == &p_hls)
7993 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007994 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007995 }
7996#endif
7997
7998#ifdef FEAT_SCROLLBIND
7999 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8000 * at the end of normal_cmd() */
8001 else if ((int *)varp == &curwin->w_p_scb)
8002 {
8003 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008004 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008005 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008006 curwin->w_scbind_pos = curwin->w_topline;
8007 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008008 }
8009#endif
8010
8011#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8012 /* There can be only one window with 'previewwindow' set. */
8013 else if ((int *)varp == &curwin->w_p_pvw)
8014 {
8015 if (curwin->w_p_pvw)
8016 {
8017 win_T *win;
8018
8019 for (win = firstwin; win != NULL; win = win->w_next)
8020 if (win->w_p_pvw && win != curwin)
8021 {
8022 curwin->w_p_pvw = FALSE;
8023 return (char_u *)N_("E590: A preview window already exists");
8024 }
8025 }
8026 }
8027#endif
8028
8029 /* when 'textmode' is set or reset also change 'fileformat' */
8030 else if ((int *)varp == &curbuf->b_p_tx)
8031 {
8032 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8033 }
8034
8035 /* when 'textauto' is set or reset also change 'fileformats' */
8036 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 set_string_option_direct((char_u *)"ffs", -1,
8038 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008039 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008040
8041 /*
8042 * When 'lisp' option changes include/exclude '-' in
8043 * keyword characters.
8044 */
8045#ifdef FEAT_LISP
8046 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8047 {
8048 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8049 }
8050#endif
8051
8052#ifdef FEAT_TITLE
8053 /* when 'title' changed, may need to change the title; same for 'icon' */
8054 else if ((int *)varp == &p_title)
8055 {
8056 did_set_title(FALSE);
8057 }
8058
8059 else if ((int *)varp == &p_icon)
8060 {
8061 did_set_title(TRUE);
8062 }
8063#endif
8064
8065 else if ((int *)varp == &curbuf->b_changed)
8066 {
8067 if (!value)
8068 save_file_ff(curbuf); /* Buffer is unchanged */
8069#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008070 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008071#endif
8072#ifdef FEAT_AUTOCMD
8073 modified_was_set = value;
8074#endif
8075 }
8076
8077#ifdef BACKSLASH_IN_FILENAME
8078 else if ((int *)varp == &p_ssl)
8079 {
8080 if (p_ssl)
8081 {
8082 psepc = '/';
8083 psepcN = '\\';
8084 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085 }
8086 else
8087 {
8088 psepc = '\\';
8089 psepcN = '/';
8090 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 }
8092
8093 /* need to adjust the file name arguments and buffer names. */
8094 buflist_slash_adjust();
8095 alist_slash_adjust();
8096# ifdef FEAT_EVAL
8097 scriptnames_slash_adjust();
8098# endif
8099 }
8100#endif
8101
8102 /* If 'wrap' is set, set w_leftcol to zero. */
8103 else if ((int *)varp == &curwin->w_p_wrap)
8104 {
8105 if (curwin->w_p_wrap)
8106 curwin->w_leftcol = 0;
8107 }
8108
8109#ifdef FEAT_WINDOWS
8110 else if ((int *)varp == &p_ea)
8111 {
8112 if (p_ea && !old_value)
8113 win_equal(curwin, FALSE, 0);
8114 }
8115#endif
8116
8117 else if ((int *)varp == &p_wiv)
8118 {
8119 /*
8120 * When 'weirdinvert' changed, set/reset 't_xs'.
8121 * Then set 'weirdinvert' according to value of 't_xs'.
8122 */
8123 if (p_wiv && !old_value)
8124 T_XS = (char_u *)"y";
8125 else if (!p_wiv && old_value)
8126 T_XS = empty_option;
8127 p_wiv = (*T_XS != NUL);
8128 }
8129
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008130#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008131 else if ((int *)varp == &p_beval)
8132 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008133 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008134 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008135 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136 gui_mch_disable_beval_area(balloonEval);
8137 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008138#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008139
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008140#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008141 else if ((int *)varp == &p_acd)
8142 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008143 /* Change directories when the 'acd' option is set now. */
8144 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145 }
8146#endif
8147
8148#ifdef FEAT_DIFF
8149 /* 'diff' */
8150 else if ((int *)varp == &curwin->w_p_diff)
8151 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008152 /* May add or remove the buffer from the list of diff buffers. */
8153 diff_buf_adjust(curwin);
8154# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 if (foldmethodIsDiff(curwin))
8156 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008157# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 }
8159#endif
8160
8161#ifdef USE_IM_CONTROL
8162 /* 'imdisable' */
8163 else if ((int *)varp == &p_imdisable)
8164 {
8165 /* Only de-activate it here, it will be enabled when changing mode. */
8166 if (p_imdisable)
8167 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008168 else if (State & INSERT)
8169 /* When the option is set from an autocommand, it may need to take
8170 * effect right away. */
8171 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008172 }
8173#endif
8174
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008175#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008176 /* 'spell' */
8177 else if ((int *)varp == &curwin->w_p_spell)
8178 {
8179 if (curwin->w_p_spell)
8180 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008181 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008182 if (errmsg != NULL)
8183 EMSG(_(errmsg));
8184 }
8185 }
8186#endif
8187
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188#ifdef FEAT_FKMAP
8189 else if ((int *)varp == &p_altkeymap)
8190 {
8191 if (old_value != p_altkeymap)
8192 {
8193 if (!p_altkeymap)
8194 {
8195 p_hkmap = p_fkmap;
8196 p_fkmap = 0;
8197 }
8198 else
8199 {
8200 p_fkmap = p_hkmap;
8201 p_hkmap = 0;
8202 }
8203 (void)init_chartab();
8204 }
8205 }
8206
8207 /*
8208 * In case some second language keymapping options have changed, check
8209 * and correct the setting in a consistent way.
8210 */
8211
8212 /*
8213 * If hkmap or fkmap are set, reset Arabic keymapping.
8214 */
8215 if ((p_hkmap || p_fkmap) && p_altkeymap)
8216 {
8217 p_altkeymap = p_fkmap;
8218# ifdef FEAT_ARABIC
8219 curwin->w_p_arab = FALSE;
8220# endif
8221 (void)init_chartab();
8222 }
8223
8224 /*
8225 * If hkmap set, reset Farsi keymapping.
8226 */
8227 if (p_hkmap && p_altkeymap)
8228 {
8229 p_altkeymap = 0;
8230 p_fkmap = 0;
8231# ifdef FEAT_ARABIC
8232 curwin->w_p_arab = FALSE;
8233# endif
8234 (void)init_chartab();
8235 }
8236
8237 /*
8238 * If fkmap set, reset Hebrew keymapping.
8239 */
8240 if (p_fkmap && !p_altkeymap)
8241 {
8242 p_altkeymap = 1;
8243 p_hkmap = 0;
8244# ifdef FEAT_ARABIC
8245 curwin->w_p_arab = FALSE;
8246# endif
8247 (void)init_chartab();
8248 }
8249#endif
8250
8251#ifdef FEAT_ARABIC
8252 if ((int *)varp == &curwin->w_p_arab)
8253 {
8254 if (curwin->w_p_arab)
8255 {
8256 /*
8257 * 'arabic' is set, handle various sub-settings.
8258 */
8259 if (!p_tbidi)
8260 {
8261 /* set rightleft mode */
8262 if (!curwin->w_p_rl)
8263 {
8264 curwin->w_p_rl = TRUE;
8265 changed_window_setting();
8266 }
8267
8268 /* Enable Arabic shaping (major part of what Arabic requires) */
8269 if (!p_arshape)
8270 {
8271 p_arshape = TRUE;
8272 redraw_later_clear();
8273 }
8274 }
8275
8276 /* Arabic requires a utf-8 encoding, inform the user if its not
8277 * set. */
8278 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008279 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008280 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8281
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008282 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008283 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8284#ifdef FEAT_EVAL
8285 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8286#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008287 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008288
8289# ifdef FEAT_MBYTE
8290 /* set 'delcombine' */
8291 p_deco = TRUE;
8292# endif
8293
8294# ifdef FEAT_KEYMAP
8295 /* Force-set the necessary keymap for arabic */
8296 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8297 OPT_LOCAL);
8298# endif
8299# ifdef FEAT_FKMAP
8300 p_altkeymap = 0;
8301 p_hkmap = 0;
8302 p_fkmap = 0;
8303 (void)init_chartab();
8304# endif
8305 }
8306 else
8307 {
8308 /*
8309 * 'arabic' is reset, handle various sub-settings.
8310 */
8311 if (!p_tbidi)
8312 {
8313 /* reset rightleft mode */
8314 if (curwin->w_p_rl)
8315 {
8316 curwin->w_p_rl = FALSE;
8317 changed_window_setting();
8318 }
8319
8320 /* 'arabicshape' isn't reset, it is a global option and
8321 * another window may still need it "on". */
8322 }
8323
8324 /* 'delcombine' isn't reset, it is a global option and another
8325 * window may still want it "on". */
8326
8327# ifdef FEAT_KEYMAP
8328 /* Revert to the default keymap */
8329 curbuf->b_p_iminsert = B_IMODE_NONE;
8330 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8331# endif
8332 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008333 }
8334
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008335#endif
8336
Bram Moolenaar071d4272004-06-13 20:20:40 +00008337 /*
8338 * End of handling side effects for bool options.
8339 */
8340
Bram Moolenaar53744302015-07-17 17:38:22 +02008341 /* after handling side effects, call autocommand */
8342
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 options[opt_idx].flags |= P_WAS_SET;
8344
Bram Moolenaar53744302015-07-17 17:38:22 +02008345#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8346 if (!starting)
8347 {
8348 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008349 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8350 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8351 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008352 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8353 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8354 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8355 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8356 reset_v_option_vars();
8357 }
8358#endif
8359
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008361 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008362 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008363 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 check_redraw(options[opt_idx].flags);
8365
8366 return NULL;
8367}
8368
8369/*
8370 * Set the value of a number option, and take care of side effects.
8371 * Returns NULL for success, or an error message for an error.
8372 */
8373 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008374set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375 int opt_idx; /* index in options[] table */
8376 char_u *varp; /* pointer to the option variable */
8377 long value; /* new value */
8378 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008379 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8381 OPT_MODELINE */
8382{
8383 char_u *errmsg = NULL;
8384 long old_value = *(long *)varp;
8385 long old_Rows = Rows; /* remember old Rows */
8386 long old_Columns = Columns; /* remember old Columns */
8387 long *pp = (long *)varp;
8388
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008389 /* Disallow changing some options from secure mode. */
8390 if ((secure
8391#ifdef HAVE_SANDBOX
8392 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008393#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008394 ) && (options[opt_idx].flags & P_SECURE))
8395 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396
8397 *pp = value;
8398#ifdef FEAT_EVAL
8399 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008400 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008402#ifdef FEAT_GUI
8403 need_mouse_correct = TRUE;
8404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405
Bram Moolenaar14f24742012-08-08 18:01:05 +02008406 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 {
8408 errmsg = e_positive;
8409 curbuf->b_p_sw = curbuf->b_p_ts;
8410 }
8411
8412 /*
8413 * Number options that need some action when changed
8414 */
8415#ifdef FEAT_WINDOWS
8416 if (pp == &p_wh || pp == &p_hh)
8417 {
8418 if (p_wh < 1)
8419 {
8420 errmsg = e_positive;
8421 p_wh = 1;
8422 }
8423 if (p_wmh > p_wh)
8424 {
8425 errmsg = e_winheight;
8426 p_wh = p_wmh;
8427 }
8428 if (p_hh < 0)
8429 {
8430 errmsg = e_positive;
8431 p_hh = 0;
8432 }
8433
8434 /* Change window height NOW */
8435 if (lastwin != firstwin)
8436 {
8437 if (pp == &p_wh && curwin->w_height < p_wh)
8438 win_setheight((int)p_wh);
8439 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8440 win_setheight((int)p_hh);
8441 }
8442 }
8443
8444 /* 'winminheight' */
8445 else if (pp == &p_wmh)
8446 {
8447 if (p_wmh < 0)
8448 {
8449 errmsg = e_positive;
8450 p_wmh = 0;
8451 }
8452 if (p_wmh > p_wh)
8453 {
8454 errmsg = e_winheight;
8455 p_wmh = p_wh;
8456 }
8457 win_setminheight();
8458 }
8459
8460# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008461 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008462 {
8463 if (p_wiw < 1)
8464 {
8465 errmsg = e_positive;
8466 p_wiw = 1;
8467 }
8468 if (p_wmw > p_wiw)
8469 {
8470 errmsg = e_winwidth;
8471 p_wiw = p_wmw;
8472 }
8473
8474 /* Change window width NOW */
8475 if (lastwin != firstwin && curwin->w_width < p_wiw)
8476 win_setwidth((int)p_wiw);
8477 }
8478
8479 /* 'winminwidth' */
8480 else if (pp == &p_wmw)
8481 {
8482 if (p_wmw < 0)
8483 {
8484 errmsg = e_positive;
8485 p_wmw = 0;
8486 }
8487 if (p_wmw > p_wiw)
8488 {
8489 errmsg = e_winwidth;
8490 p_wmw = p_wiw;
8491 }
8492 win_setminheight();
8493 }
8494# endif
8495
8496#endif
8497
8498#ifdef FEAT_WINDOWS
8499 /* (re)set last window status line */
8500 else if (pp == &p_ls)
8501 {
8502 last_status(FALSE);
8503 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008504
8505 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008506 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008507 {
8508 shell_new_rows(); /* recompute window positions and heights */
8509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510#endif
8511
8512#ifdef FEAT_GUI
8513 else if (pp == &p_linespace)
8514 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008515 /* Recompute gui.char_height and resize the Vim window to keep the
8516 * same number of lines. */
8517 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008518 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008519 }
8520#endif
8521
8522#ifdef FEAT_FOLDING
8523 /* 'foldlevel' */
8524 else if (pp == &curwin->w_p_fdl)
8525 {
8526 if (curwin->w_p_fdl < 0)
8527 curwin->w_p_fdl = 0;
8528 newFoldLevel();
8529 }
8530
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008531 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532 else if (pp == &curwin->w_p_fml)
8533 {
8534 foldUpdateAll(curwin);
8535 }
8536
8537 /* 'foldnestmax' */
8538 else if (pp == &curwin->w_p_fdn)
8539 {
8540 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8541 foldUpdateAll(curwin);
8542 }
8543
8544 /* 'foldcolumn' */
8545 else if (pp == &curwin->w_p_fdc)
8546 {
8547 if (curwin->w_p_fdc < 0)
8548 {
8549 errmsg = e_positive;
8550 curwin->w_p_fdc = 0;
8551 }
8552 else if (curwin->w_p_fdc > 12)
8553 {
8554 errmsg = e_invarg;
8555 curwin->w_p_fdc = 12;
8556 }
8557 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008558#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008559
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008560#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561 /* 'shiftwidth' or 'tabstop' */
8562 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8563 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008564# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008565 if (foldmethodIsIndent(curwin))
8566 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008567# endif
8568# ifdef FEAT_CINDENT
8569 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8570 * parse 'cinoptions'. */
8571 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8572 parse_cino(curbuf);
8573# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008574 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008575#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008577#ifdef FEAT_MBYTE
8578 /* 'maxcombine' */
8579 else if (pp == &p_mco)
8580 {
8581 if (p_mco > MAX_MCO)
8582 p_mco = MAX_MCO;
8583 else if (p_mco < 0)
8584 p_mco = 0;
8585 screenclear(); /* will re-allocate the screen */
8586 }
8587#endif
8588
Bram Moolenaar071d4272004-06-13 20:20:40 +00008589 else if (pp == &curbuf->b_p_iminsert)
8590 {
8591 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8592 {
8593 errmsg = e_invarg;
8594 curbuf->b_p_iminsert = B_IMODE_NONE;
8595 }
8596 p_iminsert = curbuf->b_p_iminsert;
8597 if (termcap_active) /* don't do this in the alternate screen */
8598 showmode();
8599#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8600 /* Show/unshow value of 'keymap' in status lines. */
8601 status_redraw_curbuf();
8602#endif
8603 }
8604
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008605 else if (pp == &p_window)
8606 {
8607 if (p_window < 1)
8608 p_window = 1;
8609 else if (p_window >= Rows)
8610 p_window = Rows - 1;
8611 }
8612
Bram Moolenaar071d4272004-06-13 20:20:40 +00008613 else if (pp == &curbuf->b_p_imsearch)
8614 {
8615 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8616 {
8617 errmsg = e_invarg;
8618 curbuf->b_p_imsearch = B_IMODE_NONE;
8619 }
8620 p_imsearch = curbuf->b_p_imsearch;
8621 }
8622
8623#ifdef FEAT_TITLE
8624 /* if 'titlelen' has changed, redraw the title */
8625 else if (pp == &p_titlelen)
8626 {
8627 if (p_titlelen < 0)
8628 {
8629 errmsg = e_positive;
8630 p_titlelen = 85;
8631 }
8632 if (starting != NO_SCREEN && old_value != p_titlelen)
8633 need_maketitle = TRUE;
8634 }
8635#endif
8636
8637 /* if p_ch changed value, change the command line height */
8638 else if (pp == &p_ch)
8639 {
8640 if (p_ch < 1)
8641 {
8642 errmsg = e_positive;
8643 p_ch = 1;
8644 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008645 if (p_ch > Rows - min_rows() + 1)
8646 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008647
8648 /* Only compute the new window layout when startup has been
8649 * completed. Otherwise the frame sizes may be wrong. */
8650 if (p_ch != old_value && full_screen
8651#ifdef FEAT_GUI
8652 && !gui.starting
8653#endif
8654 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008655 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008656 }
8657
8658 /* when 'updatecount' changes from zero to non-zero, open swap files */
8659 else if (pp == &p_uc)
8660 {
8661 if (p_uc < 0)
8662 {
8663 errmsg = e_positive;
8664 p_uc = 100;
8665 }
8666 if (p_uc && !old_value)
8667 ml_open_files();
8668 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008669#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008670 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008671 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008672 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008673 {
8674 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008675 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008676 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008677 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008678 {
8679 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008680 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008681 }
8682 }
8683#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008684#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008685 else if (pp == &p_mzq)
8686 mzvim_reset_timer();
8687#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008688
8689 /* sync undo before 'undolevels' changes */
8690 else if (pp == &p_ul)
8691 {
8692 /* use the old value, otherwise u_sync() may not work properly */
8693 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008694 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008695 p_ul = value;
8696 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008697 else if (pp == &curbuf->b_p_ul)
8698 {
8699 /* use the old value, otherwise u_sync() may not work properly */
8700 curbuf->b_p_ul = old_value;
8701 u_sync(TRUE);
8702 curbuf->b_p_ul = value;
8703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008705#ifdef FEAT_LINEBREAK
8706 /* 'numberwidth' must be positive */
8707 else if (pp == &curwin->w_p_nuw)
8708 {
8709 if (curwin->w_p_nuw < 1)
8710 {
8711 errmsg = e_positive;
8712 curwin->w_p_nuw = 1;
8713 }
8714 if (curwin->w_p_nuw > 10)
8715 {
8716 errmsg = e_invarg;
8717 curwin->w_p_nuw = 10;
8718 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008719 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008720 }
8721#endif
8722
Bram Moolenaar1a384422010-07-14 19:53:30 +02008723 else if (pp == &curbuf->b_p_tw)
8724 {
8725 if (curbuf->b_p_tw < 0)
8726 {
8727 errmsg = e_positive;
8728 curbuf->b_p_tw = 0;
8729 }
8730#ifdef FEAT_SYN_HL
8731# ifdef FEAT_WINDOWS
8732 {
8733 win_T *wp;
8734 tabpage_T *tp;
8735
8736 FOR_ALL_TAB_WINDOWS(tp, wp)
8737 check_colorcolumn(wp);
8738 }
8739# else
8740 check_colorcolumn(curwin);
8741# endif
8742#endif
8743 }
8744
Bram Moolenaar071d4272004-06-13 20:20:40 +00008745 /*
8746 * Check the bounds for numeric options here
8747 */
8748 if (Rows < min_rows() && full_screen)
8749 {
8750 if (errbuf != NULL)
8751 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008752 vim_snprintf((char *)errbuf, errbuflen,
8753 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008754 errmsg = errbuf;
8755 }
8756 Rows = min_rows();
8757 }
8758 if (Columns < MIN_COLUMNS && full_screen)
8759 {
8760 if (errbuf != NULL)
8761 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008762 vim_snprintf((char *)errbuf, errbuflen,
8763 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008764 errmsg = errbuf;
8765 }
8766 Columns = MIN_COLUMNS;
8767 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008768 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008769
8770#ifdef DJGPP
8771 /* avoid a crash by checking for a too large value of 'columns' */
8772 if (old_Columns != Columns && full_screen && term_console)
8773 mch_check_columns();
8774#endif
8775
8776 /*
8777 * If the screen (shell) height has been changed, assume it is the
8778 * physical screenheight.
8779 */
8780 if (old_Rows != Rows || old_Columns != Columns)
8781 {
8782 /* Changing the screen size is not allowed while updating the screen. */
8783 if (updating_screen)
8784 *pp = old_value;
8785 else if (full_screen
8786#ifdef FEAT_GUI
8787 && !gui.starting
8788#endif
8789 )
8790 set_shellsize((int)Columns, (int)Rows, TRUE);
8791 else
8792 {
8793 /* Postpone the resizing; check the size and cmdline position for
8794 * messages. */
8795 check_shellsize();
8796 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8797 cmdline_row = Rows - p_ch;
8798 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008799 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008800 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008801 }
8802
Bram Moolenaar071d4272004-06-13 20:20:40 +00008803 if (curbuf->b_p_ts <= 0)
8804 {
8805 errmsg = e_positive;
8806 curbuf->b_p_ts = 8;
8807 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008808 if (p_tm < 0)
8809 {
8810 errmsg = e_positive;
8811 p_tm = 0;
8812 }
8813 if ((curwin->w_p_scr <= 0
8814 || (curwin->w_p_scr > curwin->w_height
8815 && curwin->w_height > 0))
8816 && full_screen)
8817 {
8818 if (pp == &(curwin->w_p_scr))
8819 {
8820 if (curwin->w_p_scr != 0)
8821 errmsg = e_scroll;
8822 win_comp_scroll(curwin);
8823 }
8824 /* If 'scroll' became invalid because of a side effect silently adjust
8825 * it. */
8826 else if (curwin->w_p_scr <= 0)
8827 curwin->w_p_scr = 1;
8828 else /* curwin->w_p_scr > curwin->w_height */
8829 curwin->w_p_scr = curwin->w_height;
8830 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008831 if (p_hi < 0)
8832 {
8833 errmsg = e_positive;
8834 p_hi = 0;
8835 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008836 else if (p_hi > 10000)
8837 {
8838 errmsg = e_invarg;
8839 p_hi = 10000;
8840 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008841 if (p_re < 0 || p_re > 2)
8842 {
8843 errmsg = e_invarg;
8844 p_re = 0;
8845 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008846 if (p_report < 0)
8847 {
8848 errmsg = e_positive;
8849 p_report = 1;
8850 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008851 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852 {
8853 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8854 p_sj = Rows / 2;
8855 else
8856 {
8857 errmsg = e_scroll;
8858 p_sj = 1;
8859 }
8860 }
8861 if (p_so < 0 && full_screen)
8862 {
8863 errmsg = e_scroll;
8864 p_so = 0;
8865 }
8866 if (p_siso < 0 && full_screen)
8867 {
8868 errmsg = e_positive;
8869 p_siso = 0;
8870 }
8871#ifdef FEAT_CMDWIN
8872 if (p_cwh < 1)
8873 {
8874 errmsg = e_positive;
8875 p_cwh = 1;
8876 }
8877#endif
8878 if (p_ut < 0)
8879 {
8880 errmsg = e_positive;
8881 p_ut = 2000;
8882 }
8883 if (p_ss < 0)
8884 {
8885 errmsg = e_positive;
8886 p_ss = 0;
8887 }
8888
8889 /* May set global value for local option. */
8890 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8891 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8892
8893 options[opt_idx].flags |= P_WAS_SET;
8894
Bram Moolenaar53744302015-07-17 17:38:22 +02008895#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8896 if (!starting && errmsg == NULL)
8897 {
8898 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008899 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8900 vim_snprintf((char *)buf_new, 10, "%ld", value);
8901 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008902 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8903 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8904 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8905 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8906 reset_v_option_vars();
8907 }
8908#endif
8909
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008911 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008912 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008913 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008914 check_redraw(options[opt_idx].flags);
8915
8916 return errmsg;
8917}
8918
8919/*
8920 * Called after an option changed: check if something needs to be redrawn.
8921 */
8922 static void
8923check_redraw(flags)
8924 long_u flags;
8925{
8926 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008927 int doclear = (flags & P_RCLR) == P_RCLR;
8928 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929
8930#ifdef FEAT_WINDOWS
8931 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8932 status_redraw_all();
8933#endif
8934
8935 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8936 changed_window_setting();
8937 if (flags & P_RBUF)
8938 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008939 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940 redraw_all_later(CLEAR);
8941 else if (all)
8942 redraw_all_later(NOT_VALID);
8943}
8944
8945/*
8946 * Find index for option 'arg'.
8947 * Return -1 if not found.
8948 */
8949 static int
8950findoption(arg)
8951 char_u *arg;
8952{
8953 int opt_idx;
8954 char *s, *p;
8955 static short quick_tab[27] = {0, 0}; /* quick access table */
8956 int is_term_opt;
8957
8958 /*
8959 * For first call: Initialize the quick-access table.
8960 * It contains the index for the first option that starts with a certain
8961 * letter. There are 26 letters, plus the first "t_" option.
8962 */
8963 if (quick_tab[1] == 0)
8964 {
8965 p = options[0].fullname;
8966 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8967 {
8968 if (s[0] != p[0])
8969 {
8970 if (s[0] == 't' && s[1] == '_')
8971 quick_tab[26] = opt_idx;
8972 else
8973 quick_tab[CharOrdLow(s[0])] = opt_idx;
8974 }
8975 p = s;
8976 }
8977 }
8978
8979 /*
8980 * Check for name starting with an illegal character.
8981 */
8982#ifdef EBCDIC
8983 if (!islower(arg[0]))
8984#else
8985 if (arg[0] < 'a' || arg[0] > 'z')
8986#endif
8987 return -1;
8988
8989 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8990 if (is_term_opt)
8991 opt_idx = quick_tab[26];
8992 else
8993 opt_idx = quick_tab[CharOrdLow(arg[0])];
8994 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8995 {
8996 if (STRCMP(arg, s) == 0) /* match full name */
8997 break;
8998 }
8999 if (s == NULL && !is_term_opt)
9000 {
9001 opt_idx = quick_tab[CharOrdLow(arg[0])];
9002 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9003 {
9004 s = options[opt_idx].shortname;
9005 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9006 break;
9007 s = NULL;
9008 }
9009 }
9010 if (s == NULL)
9011 opt_idx = -1;
9012 return opt_idx;
9013}
9014
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009015#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016/*
9017 * Get the value for an option.
9018 *
9019 * Returns:
9020 * Number or Toggle option: 1, *numval gets value.
9021 * String option: 0, *stringval gets allocated string.
9022 * Hidden Number or Toggle option: -1.
9023 * hidden String option: -2.
9024 * unknown option: -3.
9025 */
9026 int
9027get_option_value(name, numval, stringval, opt_flags)
9028 char_u *name;
9029 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02009030 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009031 int opt_flags;
9032{
9033 int opt_idx;
9034 char_u *varp;
9035
9036 opt_idx = findoption(name);
9037 if (opt_idx < 0) /* unknown option */
9038 return -3;
9039
9040 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9041
9042 if (options[opt_idx].flags & P_STRING)
9043 {
9044 if (varp == NULL) /* hidden option */
9045 return -2;
9046 if (stringval != NULL)
9047 {
9048#ifdef FEAT_CRYPT
9049 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009050 if ((char_u **)varp == &curbuf->b_p_key
9051 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009052 *stringval = vim_strsave((char_u *)"*****");
9053 else
9054#endif
9055 *stringval = vim_strsave(*(char_u **)(varp));
9056 }
9057 return 0;
9058 }
9059
9060 if (varp == NULL) /* hidden option */
9061 return -1;
9062 if (options[opt_idx].flags & P_NUM)
9063 *numval = *(long *)varp;
9064 else
9065 {
9066 /* Special case: 'modified' is b_changed, but we also want to consider
9067 * it set when 'ff' or 'fenc' changed. */
9068 if ((int *)varp == &curbuf->b_changed)
9069 *numval = curbufIsChanged();
9070 else
9071 *numval = *(int *)varp;
9072 }
9073 return 1;
9074}
9075#endif
9076
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009077#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009078/*
9079 * Returns the option attributes and its value. Unlike the above function it
9080 * will return either global value or local value of the option depending on
9081 * what was requested, but it will never return global value if it was
9082 * requested to return local one and vice versa. Neither it will return
9083 * buffer-local value if it was requested to return window-local one.
9084 *
9085 * Pretends that option is absent if it is not present in the requested scope
9086 * (i.e. has no global, window-local or buffer-local value depending on
9087 * opt_type). Uses
9088 *
9089 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009090 * 0 hidden or unknown option, also option that does not have requested
9091 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009092 * see SOPT_* in vim.h for other flags
9093 *
9094 * Possible opt_type values: see SREQ_* in vim.h
9095 */
9096 int
9097get_option_value_strict(name, numval, stringval, opt_type, from)
9098 char_u *name;
9099 long *numval;
9100 char_u **stringval; /* NULL when only obtaining attributes */
9101 int opt_type;
9102 void *from;
9103{
9104 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009105 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009106 struct vimoption *p;
9107 int r = 0;
9108
9109 opt_idx = findoption(name);
9110 if (opt_idx < 0)
9111 return 0;
9112
9113 p = &(options[opt_idx]);
9114
9115 /* Hidden option */
9116 if (p->var == NULL)
9117 return 0;
9118
9119 if (p->flags & P_BOOL)
9120 r |= SOPT_BOOL;
9121 else if (p->flags & P_NUM)
9122 r |= SOPT_NUM;
9123 else if (p->flags & P_STRING)
9124 r |= SOPT_STRING;
9125
9126 if (p->indir == PV_NONE)
9127 {
9128 if (opt_type == SREQ_GLOBAL)
9129 r |= SOPT_GLOBAL;
9130 else
9131 return 0; /* Did not request global-only option */
9132 }
9133 else
9134 {
9135 if (p->indir & PV_BOTH)
9136 r |= SOPT_GLOBAL;
9137 else if (opt_type == SREQ_GLOBAL)
9138 return 0; /* Requested global option */
9139
9140 if (p->indir & PV_WIN)
9141 {
9142 if (opt_type == SREQ_BUF)
9143 return 0; /* Did not request window-local option */
9144 else
9145 r |= SOPT_WIN;
9146 }
9147 else if (p->indir & PV_BUF)
9148 {
9149 if (opt_type == SREQ_WIN)
9150 return 0; /* Did not request buffer-local option */
9151 else
9152 r |= SOPT_BUF;
9153 }
9154 }
9155
9156 if (stringval == NULL)
9157 return r;
9158
9159 if (opt_type == SREQ_GLOBAL)
9160 varp = p->var;
9161 else
9162 {
9163 if (opt_type == SREQ_BUF)
9164 {
9165 /* Special case: 'modified' is b_changed, but we also want to
9166 * consider it set when 'ff' or 'fenc' changed. */
9167 if (p->indir == PV_MOD)
9168 {
9169 *numval = bufIsChanged((buf_T *) from);
9170 varp = NULL;
9171 }
9172#ifdef FEAT_CRYPT
9173 else if (p->indir == PV_KEY)
9174 {
9175 /* never return the value of the crypt key */
9176 *stringval = NULL;
9177 varp = NULL;
9178 }
9179#endif
9180 else
9181 {
9182 aco_save_T aco;
9183 aucmd_prepbuf(&aco, (buf_T *) from);
9184 varp = get_varp(p);
9185 aucmd_restbuf(&aco);
9186 }
9187 }
9188 else if (opt_type == SREQ_WIN)
9189 {
9190 win_T *save_curwin;
9191 save_curwin = curwin;
9192 curwin = (win_T *) from;
9193 curbuf = curwin->w_buffer;
9194 varp = get_varp(p);
9195 curwin = save_curwin;
9196 curbuf = curwin->w_buffer;
9197 }
9198 if (varp == p->var)
9199 return (r | SOPT_UNSET);
9200 }
9201
9202 if (varp != NULL)
9203 {
9204 if (p->flags & P_STRING)
9205 *stringval = vim_strsave(*(char_u **)(varp));
9206 else if (p->flags & P_NUM)
9207 *numval = *(long *) varp;
9208 else
9209 *numval = *(int *)varp;
9210 }
9211
9212 return r;
9213}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009214
9215/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009216 * Iterate over options. First argument is a pointer to a pointer to a
9217 * structure inside options[] array, second is option type like in the above
9218 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009219 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009220 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009221 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009222 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009223 * first argument to NULL.
9224 *
9225 * Returns full option name for current option on each call.
9226 */
9227 char_u *
9228option_iter_next(option, opt_type)
9229 void **option;
9230 int opt_type;
9231{
9232 struct vimoption *ret = NULL;
9233 do
9234 {
9235 if (*option == NULL)
9236 *option = (void *) options;
9237 else if (((struct vimoption *) (*option))->fullname == NULL)
9238 {
9239 *option = NULL;
9240 return NULL;
9241 }
9242 else
9243 *option = (void *) (((struct vimoption *) (*option)) + 1);
9244
9245 ret = ((struct vimoption *) (*option));
9246
9247 /* Hidden option */
9248 if (ret->var == NULL)
9249 {
9250 ret = NULL;
9251 continue;
9252 }
9253
9254 switch (opt_type)
9255 {
9256 case SREQ_GLOBAL:
9257 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9258 ret = NULL;
9259 break;
9260 case SREQ_BUF:
9261 if (!(ret->indir & PV_BUF))
9262 ret = NULL;
9263 break;
9264 case SREQ_WIN:
9265 if (!(ret->indir & PV_WIN))
9266 ret = NULL;
9267 break;
9268 default:
9269 EMSG2(_(e_intern2), "option_iter_next()");
9270 return NULL;
9271 }
9272 }
9273 while (ret == NULL);
9274
9275 return (char_u *)ret->fullname;
9276}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009277#endif
9278
Bram Moolenaar071d4272004-06-13 20:20:40 +00009279/*
9280 * Set the value of option "name".
9281 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009282 *
9283 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009284 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009285 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009286set_option_value(name, number, string, opt_flags)
9287 char_u *name;
9288 long number;
9289 char_u *string;
9290 int opt_flags; /* OPT_LOCAL or 0 (both) */
9291{
9292 int opt_idx;
9293 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009294 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295
9296 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009297 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009298 EMSG2(_("E355: Unknown option: %s"), name);
9299 else
9300 {
9301 flags = options[opt_idx].flags;
9302#ifdef HAVE_SANDBOX
9303 /* Disallow changing some options in the sandbox */
9304 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009305 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009307 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009308 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009309#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009310 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009311 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009312 else
9313 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009314 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009315 if (varp != NULL) /* hidden option is not changed */
9316 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009317 if (number == 0 && string != NULL)
9318 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009319 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009320
9321 /* Either we are given a string or we are setting option
9322 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009323 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009324 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009325 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009326 {
9327 /* There's another character after zeros or the string
9328 * is empty. In both cases, we are trying to set a
9329 * num option using a string. */
9330 EMSG3(_("E521: Number required: &%s = '%s'"),
9331 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009332 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009333
9334 }
9335 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009337 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009338 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009339 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009340 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009341 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009342 }
9343 }
9344 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009345 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009346}
9347
9348/*
9349 * Get the terminal code for a terminal option.
9350 * Returns NULL when not found.
9351 */
9352 char_u *
9353get_term_code(tname)
9354 char_u *tname;
9355{
9356 int opt_idx;
9357 char_u *varp;
9358
9359 if (tname[0] != 't' || tname[1] != '_' ||
9360 tname[2] == NUL || tname[3] == NUL)
9361 return NULL;
9362 if ((opt_idx = findoption(tname)) >= 0)
9363 {
9364 varp = get_varp(&(options[opt_idx]));
9365 if (varp != NULL)
9366 varp = *(char_u **)(varp);
9367 return varp;
9368 }
9369 return find_termcode(tname + 2);
9370}
9371
9372 char_u *
9373get_highlight_default()
9374{
9375 int i;
9376
9377 i = findoption((char_u *)"hl");
9378 if (i >= 0)
9379 return options[i].def_val[VI_DEFAULT];
9380 return (char_u *)NULL;
9381}
9382
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009383#if defined(FEAT_MBYTE) || defined(PROTO)
9384 char_u *
9385get_encoding_default()
9386{
9387 int i;
9388
9389 i = findoption((char_u *)"enc");
9390 if (i >= 0)
9391 return options[i].def_val[VI_DEFAULT];
9392 return (char_u *)NULL;
9393}
9394#endif
9395
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396/*
9397 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9398 */
9399 static int
9400find_key_option(arg)
9401 char_u *arg;
9402{
9403 int key;
9404 int modifiers;
9405
9406 /*
9407 * Don't use get_special_key_code() for t_xx, we don't want it to call
9408 * add_termcap_entry().
9409 */
9410 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9411 key = TERMCAP2KEY(arg[2], arg[3]);
9412 else
9413 {
9414 --arg; /* put arg at the '<' */
9415 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009416 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009417 if (modifiers) /* can't handle modifiers here */
9418 key = 0;
9419 }
9420 return key;
9421}
9422
9423/*
9424 * if 'all' == 0: show changed options
9425 * if 'all' == 1: show all normal options
9426 * if 'all' == 2: show all terminal options
9427 */
9428 static void
9429showoptions(all, opt_flags)
9430 int all;
9431 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9432{
9433 struct vimoption *p;
9434 int col;
9435 int isterm;
9436 char_u *varp;
9437 struct vimoption **items;
9438 int item_count;
9439 int run;
9440 int row, rows;
9441 int cols;
9442 int i;
9443 int len;
9444
9445#define INC 20
9446#define GAP 3
9447
9448 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9449 PARAM_COUNT));
9450 if (items == NULL)
9451 return;
9452
9453 /* Highlight title */
9454 if (all == 2)
9455 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9456 else if (opt_flags & OPT_GLOBAL)
9457 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9458 else if (opt_flags & OPT_LOCAL)
9459 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9460 else
9461 MSG_PUTS_TITLE(_("\n--- Options ---"));
9462
9463 /*
9464 * do the loop two times:
9465 * 1. display the short items
9466 * 2. display the long items (only strings and numbers)
9467 */
9468 for (run = 1; run <= 2 && !got_int; ++run)
9469 {
9470 /*
9471 * collect the items in items[]
9472 */
9473 item_count = 0;
9474 for (p = &options[0]; p->fullname != NULL; p++)
9475 {
9476 varp = NULL;
9477 isterm = istermoption(p);
9478 if (opt_flags != 0)
9479 {
9480 if (p->indir != PV_NONE && !isterm)
9481 varp = get_varp_scope(p, opt_flags);
9482 }
9483 else
9484 varp = get_varp(p);
9485 if (varp != NULL
9486 && ((all == 2 && isterm)
9487 || (all == 1 && !isterm)
9488 || (all == 0 && !optval_default(p, varp))))
9489 {
9490 if (p->flags & P_BOOL)
9491 len = 1; /* a toggle option fits always */
9492 else
9493 {
9494 option_value2string(p, opt_flags);
9495 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9496 }
9497 if ((len <= INC - GAP && run == 1) ||
9498 (len > INC - GAP && run == 2))
9499 items[item_count++] = p;
9500 }
9501 }
9502
9503 /*
9504 * display the items
9505 */
9506 if (run == 1)
9507 {
9508 cols = (Columns + GAP - 3) / INC;
9509 if (cols == 0)
9510 cols = 1;
9511 rows = (item_count + cols - 1) / cols;
9512 }
9513 else /* run == 2 */
9514 rows = item_count;
9515 for (row = 0; row < rows && !got_int; ++row)
9516 {
9517 msg_putchar('\n'); /* go to next line */
9518 if (got_int) /* 'q' typed in more */
9519 break;
9520 col = 0;
9521 for (i = row; i < item_count; i += rows)
9522 {
9523 msg_col = col; /* make columns */
9524 showoneopt(items[i], opt_flags);
9525 col += INC;
9526 }
9527 out_flush();
9528 ui_breakcheck();
9529 }
9530 }
9531 vim_free(items);
9532}
9533
9534/*
9535 * Return TRUE if option "p" has its default value.
9536 */
9537 static int
9538optval_default(p, varp)
9539 struct vimoption *p;
9540 char_u *varp;
9541{
9542 int dvi;
9543
9544 if (varp == NULL)
9545 return TRUE; /* hidden option is always at default */
9546 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9547 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009548 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009549 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009550 /* the cast to long is required for Manx C, long_i is
9551 * needed for MSVC */
9552 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009553 /* P_STRING */
9554 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9555}
9556
9557/*
9558 * showoneopt: show the value of one option
9559 * must not be called with a hidden option!
9560 */
9561 static void
9562showoneopt(p, opt_flags)
9563 struct vimoption *p;
9564 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9565{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009566 char_u *varp;
9567 int save_silent = silent_mode;
9568
9569 silent_mode = FALSE;
9570 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009571
9572 varp = get_varp_scope(p, opt_flags);
9573
9574 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9575 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9576 ? !curbufIsChanged() : !*(int *)varp))
9577 MSG_PUTS("no");
9578 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9579 MSG_PUTS("--");
9580 else
9581 MSG_PUTS(" ");
9582 MSG_PUTS(p->fullname);
9583 if (!(p->flags & P_BOOL))
9584 {
9585 msg_putchar('=');
9586 /* put value string in NameBuff */
9587 option_value2string(p, opt_flags);
9588 msg_outtrans(NameBuff);
9589 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009590
9591 silent_mode = save_silent;
9592 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009593}
9594
9595/*
9596 * Write modified options as ":set" commands to a file.
9597 *
9598 * There are three values for "opt_flags":
9599 * OPT_GLOBAL: Write global option values and fresh values of
9600 * buffer-local options (used for start of a session
9601 * file).
9602 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9603 * curwin (used for a vimrc file).
9604 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9605 * and local values for window-local options of
9606 * curwin. Local values are also written when at the
9607 * default value, because a modeline or autocommand
9608 * may have set them when doing ":edit file" and the
9609 * user has set them back at the default or fresh
9610 * value.
9611 * When "local_only" is TRUE, don't write fresh
9612 * values, only local values (for ":mkview").
9613 * (fresh value = value used for a new buffer or window for a local option).
9614 *
9615 * Return FAIL on error, OK otherwise.
9616 */
9617 int
9618makeset(fd, opt_flags, local_only)
9619 FILE *fd;
9620 int opt_flags;
9621 int local_only;
9622{
9623 struct vimoption *p;
9624 char_u *varp; /* currently used value */
9625 char_u *varp_fresh; /* local value */
9626 char_u *varp_local = NULL; /* fresh value */
9627 char *cmd;
9628 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009629 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009630
9631 /*
9632 * The options that don't have a default (terminal name, columns, lines)
9633 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009634 * Do the loop over "options[]" twice: once for options with the
9635 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009636 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009637 for (pri = 1; pri >= 0; --pri)
9638 {
9639 for (p = &options[0]; !istermoption(p); p++)
9640 if (!(p->flags & P_NO_MKRC)
9641 && !istermoption(p)
9642 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009643 {
9644 /* skip global option when only doing locals */
9645 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9646 continue;
9647
9648 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9649 * file, they are always buffer-specific. */
9650 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9651 continue;
9652
9653 /* Global values are only written when not at the default value. */
9654 varp = get_varp_scope(p, opt_flags);
9655 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9656 continue;
9657
9658 round = 2;
9659 if (p->indir != PV_NONE)
9660 {
9661 if (p->var == VAR_WIN)
9662 {
9663 /* skip window-local option when only doing globals */
9664 if (!(opt_flags & OPT_LOCAL))
9665 continue;
9666 /* When fresh value of window-local option is not at the
9667 * default, need to write it too. */
9668 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9669 {
9670 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9671 if (!optval_default(p, varp_fresh))
9672 {
9673 round = 1;
9674 varp_local = varp;
9675 varp = varp_fresh;
9676 }
9677 }
9678 }
9679 }
9680
9681 /* Round 1: fresh value for window-local options.
9682 * Round 2: other values */
9683 for ( ; round <= 2; varp = varp_local, ++round)
9684 {
9685 if (round == 1 || (opt_flags & OPT_GLOBAL))
9686 cmd = "set";
9687 else
9688 cmd = "setlocal";
9689
9690 if (p->flags & P_BOOL)
9691 {
9692 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9693 return FAIL;
9694 }
9695 else if (p->flags & P_NUM)
9696 {
9697 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9698 return FAIL;
9699 }
9700 else /* P_STRING */
9701 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009702#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9703 int do_endif = FALSE;
9704
Bram Moolenaar071d4272004-06-13 20:20:40 +00009705 /* Don't set 'syntax' and 'filetype' again if the value is
9706 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009707 if (
9708# if defined(FEAT_SYN_HL)
9709 p->indir == PV_SYN
9710# if defined(FEAT_AUTOCMD)
9711 ||
9712# endif
9713# endif
9714# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009715 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009716# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009717 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009718 {
9719 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9720 *(char_u **)(varp)) < 0
9721 || put_eol(fd) < 0)
9722 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009723 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009724 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009725#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009726 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9727 (p->flags & P_EXPAND) != 0) == FAIL)
9728 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009729#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9730 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731 {
9732 if (put_line(fd, "endif") == FAIL)
9733 return FAIL;
9734 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009735#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009736 }
9737 }
9738 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009739 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740 return OK;
9741}
9742
9743#if defined(FEAT_FOLDING) || defined(PROTO)
9744/*
9745 * Generate set commands for the local fold options only. Used when
9746 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9747 */
9748 int
9749makefoldset(fd)
9750 FILE *fd;
9751{
9752 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9753# ifdef FEAT_EVAL
9754 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9755 == FAIL
9756# endif
9757 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9758 == FAIL
9759 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9760 == FAIL
9761 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9762 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9763 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9764 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9765 )
9766 return FAIL;
9767
9768 return OK;
9769}
9770#endif
9771
9772 static int
9773put_setstring(fd, cmd, name, valuep, expand)
9774 FILE *fd;
9775 char *cmd;
9776 char *name;
9777 char_u **valuep;
9778 int expand;
9779{
9780 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009781 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009782
9783 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9784 return FAIL;
9785 if (*valuep != NULL)
9786 {
9787 /* Output 'pastetoggle' as key names. For other
9788 * options some characters have to be escaped with
9789 * CTRL-V or backslash */
9790 if (valuep == &p_pt)
9791 {
9792 s = *valuep;
9793 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009794 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795 return FAIL;
9796 }
9797 else if (expand)
9798 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009799 buf = alloc(MAXPATHL);
9800 if (buf == NULL)
9801 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009802 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9803 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009804 {
9805 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009806 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009807 }
9808 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009809 }
9810 else if (put_escstr(fd, *valuep, 2) == FAIL)
9811 return FAIL;
9812 }
9813 if (put_eol(fd) < 0)
9814 return FAIL;
9815 return OK;
9816}
9817
9818 static int
9819put_setnum(fd, cmd, name, valuep)
9820 FILE *fd;
9821 char *cmd;
9822 char *name;
9823 long *valuep;
9824{
9825 long wc;
9826
9827 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9828 return FAIL;
9829 if (wc_use_keyname((char_u *)valuep, &wc))
9830 {
9831 /* print 'wildchar' and 'wildcharm' as a key name */
9832 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9833 return FAIL;
9834 }
9835 else if (fprintf(fd, "%ld", *valuep) < 0)
9836 return FAIL;
9837 if (put_eol(fd) < 0)
9838 return FAIL;
9839 return OK;
9840}
9841
9842 static int
9843put_setbool(fd, cmd, name, value)
9844 FILE *fd;
9845 char *cmd;
9846 char *name;
9847 int value;
9848{
Bram Moolenaar893de922007-10-02 18:40:57 +00009849 if (value < 0) /* global/local option using global value */
9850 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009851 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9852 || put_eol(fd) < 0)
9853 return FAIL;
9854 return OK;
9855}
9856
9857/*
9858 * Clear all the terminal options.
9859 * If the option has been allocated, free the memory.
9860 * Terminal options are never hidden or indirect.
9861 */
9862 void
9863clear_termoptions()
9864{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865 /*
9866 * Reset a few things before clearing the old options. This may cause
9867 * outputting a few things that the terminal doesn't understand, but the
9868 * screen will be cleared later, so this is OK.
9869 */
9870#ifdef FEAT_MOUSE_TTY
9871 mch_setmouse(FALSE); /* switch mouse off */
9872#endif
9873#ifdef FEAT_TITLE
9874 mch_restore_title(3); /* restore window titles */
9875#endif
9876#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9877 /* When starting the GUI close the display opened for the clipboard.
9878 * After restoring the title, because that will need the display. */
9879 if (gui.starting)
9880 clear_xterm_clip();
9881#endif
9882#ifdef WIN3264
9883 /*
9884 * Check if this is allowed now.
9885 */
9886 if (can_end_termcap_mode(FALSE) == TRUE)
9887#endif
9888 stoptermcap(); /* stop termcap mode */
9889
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009890 free_termoptions();
9891}
9892
9893 void
9894free_termoptions()
9895{
9896 struct vimoption *p;
9897
Bram Moolenaar071d4272004-06-13 20:20:40 +00009898 for (p = &options[0]; p->fullname != NULL; p++)
9899 if (istermoption(p))
9900 {
9901 if (p->flags & P_ALLOCED)
9902 free_string_option(*(char_u **)(p->var));
9903 if (p->flags & P_DEF_ALLOCED)
9904 free_string_option(p->def_val[VI_DEFAULT]);
9905 *(char_u **)(p->var) = empty_option;
9906 p->def_val[VI_DEFAULT] = empty_option;
9907 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9908 }
9909 clear_termcodes();
9910}
9911
9912/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009913 * Free the string for one term option, if it was allocated.
9914 * Set the string to empty_option and clear allocated flag.
9915 * "var" points to the option value.
9916 */
9917 void
9918free_one_termoption(var)
9919 char_u *var;
9920{
9921 struct vimoption *p;
9922
9923 for (p = &options[0]; p->fullname != NULL; p++)
9924 if (p->var == var)
9925 {
9926 if (p->flags & P_ALLOCED)
9927 free_string_option(*(char_u **)(p->var));
9928 *(char_u **)(p->var) = empty_option;
9929 p->flags &= ~P_ALLOCED;
9930 break;
9931 }
9932}
9933
9934/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009935 * Set the terminal option defaults to the current value.
9936 * Used after setting the terminal name.
9937 */
9938 void
9939set_term_defaults()
9940{
9941 struct vimoption *p;
9942
9943 for (p = &options[0]; p->fullname != NULL; p++)
9944 {
9945 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9946 {
9947 if (p->flags & P_DEF_ALLOCED)
9948 {
9949 free_string_option(p->def_val[VI_DEFAULT]);
9950 p->flags &= ~P_DEF_ALLOCED;
9951 }
9952 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9953 if (p->flags & P_ALLOCED)
9954 {
9955 p->flags |= P_DEF_ALLOCED;
9956 p->flags &= ~P_ALLOCED; /* don't free the value now */
9957 }
9958 }
9959 }
9960}
9961
9962/*
9963 * return TRUE if 'p' starts with 't_'
9964 */
9965 static int
9966istermoption(p)
9967 struct vimoption *p;
9968{
9969 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9970}
9971
9972/*
9973 * Compute columns for ruler and shown command. 'sc_col' is also used to
9974 * decide what the maximum length of a message on the status line can be.
9975 * If there is a status line for the last window, 'sc_col' is independent
9976 * of 'ru_col'.
9977 */
9978
9979#define COL_RULER 17 /* columns needed by standard ruler */
9980
9981 void
9982comp_col()
9983{
9984#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9985 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9986
9987 sc_col = 0;
9988 ru_col = 0;
9989 if (p_ru)
9990 {
9991#ifdef FEAT_STL_OPT
9992 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9993#else
9994 ru_col = COL_RULER + 1;
9995#endif
9996 /* no last status line, adjust sc_col */
9997 if (!last_has_status)
9998 sc_col = ru_col;
9999 }
10000 if (p_sc)
10001 {
10002 sc_col += SHOWCMD_COLS;
10003 if (!p_ru || last_has_status) /* no need for separating space */
10004 ++sc_col;
10005 }
10006 sc_col = Columns - sc_col;
10007 ru_col = Columns - ru_col;
10008 if (sc_col <= 0) /* screen too narrow, will become a mess */
10009 sc_col = 1;
10010 if (ru_col <= 0)
10011 ru_col = 1;
10012#else
10013 sc_col = Columns;
10014 ru_col = Columns;
10015#endif
10016}
10017
10018/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010019 * Unset local option value, similar to ":set opt<".
10020 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010021 void
10022unset_global_local_option(name, from)
10023 char_u *name;
10024 void *from;
10025{
10026 struct vimoption *p;
10027 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010028 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010029
10030 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010031 if (opt_idx < 0)
10032 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010033 p = &(options[opt_idx]);
10034
10035 switch ((int)p->indir)
10036 {
10037 /* global option with local value: use local value if it's been set */
10038 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010039 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010040 break;
10041 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010042 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010043 break;
10044 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010045 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010046 break;
10047 case PV_AR:
10048 buf->b_p_ar = -1;
10049 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010050 case PV_BKC:
10051 clear_string_option(&buf->b_p_bkc);
10052 buf->b_bkc_flags = 0;
10053 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010054 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010055 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010056 break;
10057#ifdef FEAT_FIND_ID
10058 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010059 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010060 break;
10061 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010062 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010063 break;
10064#endif
10065#ifdef FEAT_INS_EXPAND
10066 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010067 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010068 break;
10069 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010070 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010071 break;
10072#endif
10073#ifdef FEAT_QUICKFIX
10074 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010075 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010076 break;
10077 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010078 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010079 break;
10080 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010081 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010082 break;
10083#endif
10084#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10085 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010086 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010087 break;
10088#endif
10089#if defined(FEAT_CRYPT)
10090 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010091 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010092 break;
10093#endif
10094#ifdef FEAT_STL_OPT
10095 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010096 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010097 break;
10098#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010099 case PV_UL:
10100 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10101 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010102#ifdef FEAT_LISP
10103 case PV_LW:
10104 clear_string_option(&buf->b_p_lw);
10105 break;
10106#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010107 }
10108}
10109
10110/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010111 * Get pointer to option variable, depending on local or global scope.
10112 */
10113 static char_u *
10114get_varp_scope(p, opt_flags)
10115 struct vimoption *p;
10116 int opt_flags;
10117{
10118 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10119 {
10120 if (p->var == VAR_WIN)
10121 return (char_u *)GLOBAL_WO(get_varp(p));
10122 return p->var;
10123 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010124 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125 {
10126 switch ((int)p->indir)
10127 {
10128#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010129 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10130 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10131 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010132#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010133 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10134 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10135 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010136 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010137 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010138#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010139 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10140 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141#endif
10142#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010143 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10144 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010146#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10147 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10148#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010149#if defined(FEAT_CRYPT)
10150 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10151#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010152#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010153 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010154#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010155 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010156#ifdef FEAT_LISP
10157 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10158#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010159 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160 }
10161 return NULL; /* "cannot happen" */
10162 }
10163 return get_varp(p);
10164}
10165
10166/*
10167 * Get pointer to option variable.
10168 */
10169 static char_u *
10170get_varp(p)
10171 struct vimoption *p;
10172{
10173 /* hidden option, always return NULL */
10174 if (p->var == NULL)
10175 return NULL;
10176
10177 switch ((int)p->indir)
10178 {
10179 case PV_NONE: return p->var;
10180
10181 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010182 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010183 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010184 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010186 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010187 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010188 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010190 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010192 case PV_BKC: return *curbuf->b_p_bkc != NUL
10193 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010195 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010197 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10199#endif
10200#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010201 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010203 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10205#endif
10206#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010207 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010208 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010209 case PV_GP: return *curbuf->b_p_gp != NUL
10210 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10211 case PV_MP: return *curbuf->b_p_mp != NUL
10212 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010213#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010214#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10215 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10216 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10217#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010218#if defined(FEAT_CRYPT)
10219 case PV_CM: return *curbuf->b_p_cm != NUL
10220 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10221#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010222#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010223 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010224 ? (char_u *)&(curwin->w_p_stl) : p->var;
10225#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010226 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10227 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010228#ifdef FEAT_LISP
10229 case PV_LW: return *curbuf->b_p_lw != NUL
10230 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10231#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232
10233#ifdef FEAT_ARABIC
10234 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10235#endif
10236 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010237#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010238 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10239#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010240#ifdef FEAT_SYN_HL
10241 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10242 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010243 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010244#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010245#ifdef FEAT_DIFF
10246 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10247#endif
10248#ifdef FEAT_FOLDING
10249 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10250 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10251 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10252 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10253 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10254 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10255 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10256# ifdef FEAT_EVAL
10257 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10258 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10259# endif
10260 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10261#endif
10262 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010263 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010264#ifdef FEAT_LINEBREAK
10265 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10266#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010267#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10269#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010270#ifdef FEAT_VERTSPLIT
10271 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10272#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10274 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10275#endif
10276#ifdef FEAT_RIGHTLEFT
10277 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10278 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10279#endif
10280 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10281 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10282#ifdef FEAT_LINEBREAK
10283 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010284 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10285 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010286#endif
10287#ifdef FEAT_SCROLLBIND
10288 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10289#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010290#ifdef FEAT_CURSORBIND
10291 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10292#endif
10293#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010294 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10295 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010296#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297
10298 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10299 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10300#ifdef FEAT_MBYTE
10301 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10302#endif
10303#if defined(FEAT_QUICKFIX)
10304 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10305 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10306#endif
10307 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10308 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10309#ifdef FEAT_CINDENT
10310 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10311 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10312 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10313#endif
10314#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10315 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10316#endif
10317#ifdef FEAT_COMMENTS
10318 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10319#endif
10320#ifdef FEAT_FOLDING
10321 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10322#endif
10323#ifdef FEAT_INS_EXPAND
10324 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10325#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010326#ifdef FEAT_COMPL_FUNC
10327 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010328 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010331 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010332 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10333#ifdef FEAT_MBYTE
10334 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10335#endif
10336 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10337#ifdef FEAT_AUTOCMD
10338 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10339#endif
10340 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010341 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10343 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10344 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10345 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10346#ifdef FEAT_FIND_ID
10347# ifdef FEAT_EVAL
10348 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10349# endif
10350#endif
10351#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10352 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10353 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10354#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010355#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010356 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358#ifdef FEAT_CRYPT
10359 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10360#endif
10361#ifdef FEAT_LISP
10362 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10363#endif
10364 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10365 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10366 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10367 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10368 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010369 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010370#ifdef FEAT_TEXTOBJ
10371 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010373 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10374#ifdef FEAT_SMARTINDENT
10375 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10376#endif
10377#ifndef SHORT_FNAME
10378 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10379#endif
10380 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10381#ifdef FEAT_SEARCHPATH
10382 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10383#endif
10384 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10385#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010386 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010387 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10388#endif
10389#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010390 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10391 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10392 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010393#endif
10394 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10395 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10396 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10397 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010398#ifdef FEAT_PERSISTENT_UNDO
10399 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10402#ifdef FEAT_KEYMAP
10403 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10404#endif
10405 default: EMSG(_("E356: get_varp ERROR"));
10406 }
10407 /* always return a valid pointer to avoid a crash! */
10408 return (char_u *)&(curbuf->b_p_wm);
10409}
10410
10411/*
10412 * Get the value of 'equalprg', either the buffer-local one or the global one.
10413 */
10414 char_u *
10415get_equalprg()
10416{
10417 if (*curbuf->b_p_ep == NUL)
10418 return p_ep;
10419 return curbuf->b_p_ep;
10420}
10421
10422#if defined(FEAT_WINDOWS) || defined(PROTO)
10423/*
10424 * Copy options from one window to another.
10425 * Used when splitting a window.
10426 */
10427 void
10428win_copy_options(wp_from, wp_to)
10429 win_T *wp_from;
10430 win_T *wp_to;
10431{
10432 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10433 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10434# ifdef FEAT_RIGHTLEFT
10435# ifdef FEAT_FKMAP
10436 /* Is this right? */
10437 wp_to->w_farsi = wp_from->w_farsi;
10438# endif
10439# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010440#if defined(FEAT_LINEBREAK)
10441 briopt_check(wp_to);
10442#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010443}
10444#endif
10445
10446/*
10447 * Copy the options from one winopt_T to another.
10448 * Doesn't free the old option values in "to", use clear_winopt() for that.
10449 * The 'scroll' option is not copied, because it depends on the window height.
10450 * The 'previewwindow' option is reset, there can be only one preview window.
10451 */
10452 void
10453copy_winopt(from, to)
10454 winopt_T *from;
10455 winopt_T *to;
10456{
10457#ifdef FEAT_ARABIC
10458 to->wo_arab = from->wo_arab;
10459#endif
10460 to->wo_list = from->wo_list;
10461 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010462 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010463#ifdef FEAT_LINEBREAK
10464 to->wo_nuw = from->wo_nuw;
10465#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010466#ifdef FEAT_RIGHTLEFT
10467 to->wo_rl = from->wo_rl;
10468 to->wo_rlc = vim_strsave(from->wo_rlc);
10469#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010470#ifdef FEAT_STL_OPT
10471 to->wo_stl = vim_strsave(from->wo_stl);
10472#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010473 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010474#ifdef FEAT_DIFF
10475 to->wo_wrap_save = from->wo_wrap_save;
10476#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010477#ifdef FEAT_LINEBREAK
10478 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010479 to->wo_bri = from->wo_bri;
10480 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010481#endif
10482#ifdef FEAT_SCROLLBIND
10483 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010484 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010485#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010486#ifdef FEAT_CURSORBIND
10487 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010488 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010489#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010490#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010491 to->wo_spell = from->wo_spell;
10492#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010493#ifdef FEAT_SYN_HL
10494 to->wo_cuc = from->wo_cuc;
10495 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010496 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010497#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010498#ifdef FEAT_DIFF
10499 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010500 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010502#ifdef FEAT_CONCEAL
10503 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010504 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010506#ifdef FEAT_FOLDING
10507 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010508 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010509 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010510 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511 to->wo_fdi = vim_strsave(from->wo_fdi);
10512 to->wo_fml = from->wo_fml;
10513 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010514 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010516 to->wo_fdm_save = from->wo_diff_saved
10517 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010518 to->wo_fdn = from->wo_fdn;
10519# ifdef FEAT_EVAL
10520 to->wo_fde = vim_strsave(from->wo_fde);
10521 to->wo_fdt = vim_strsave(from->wo_fdt);
10522# endif
10523 to->wo_fmr = vim_strsave(from->wo_fmr);
10524#endif
10525 check_winopt(to); /* don't want NULL pointers */
10526}
10527
10528/*
10529 * Check string options in a window for a NULL value.
10530 */
10531 void
10532check_win_options(win)
10533 win_T *win;
10534{
10535 check_winopt(&win->w_onebuf_opt);
10536 check_winopt(&win->w_allbuf_opt);
10537}
10538
10539/*
10540 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10541 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010542 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010544 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010545{
10546#ifdef FEAT_FOLDING
10547 check_string_option(&wop->wo_fdi);
10548 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010549 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010550# ifdef FEAT_EVAL
10551 check_string_option(&wop->wo_fde);
10552 check_string_option(&wop->wo_fdt);
10553# endif
10554 check_string_option(&wop->wo_fmr);
10555#endif
10556#ifdef FEAT_RIGHTLEFT
10557 check_string_option(&wop->wo_rlc);
10558#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010559#ifdef FEAT_STL_OPT
10560 check_string_option(&wop->wo_stl);
10561#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010562#ifdef FEAT_SYN_HL
10563 check_string_option(&wop->wo_cc);
10564#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010565#ifdef FEAT_CONCEAL
10566 check_string_option(&wop->wo_cocu);
10567#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010568#ifdef FEAT_LINEBREAK
10569 check_string_option(&wop->wo_briopt);
10570#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571}
10572
10573/*
10574 * Free the allocated memory inside a winopt_T.
10575 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576 void
10577clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010578 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579{
10580#ifdef FEAT_FOLDING
10581 clear_string_option(&wop->wo_fdi);
10582 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010583 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584# ifdef FEAT_EVAL
10585 clear_string_option(&wop->wo_fde);
10586 clear_string_option(&wop->wo_fdt);
10587# endif
10588 clear_string_option(&wop->wo_fmr);
10589#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010590#ifdef FEAT_LINEBREAK
10591 clear_string_option(&wop->wo_briopt);
10592#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593#ifdef FEAT_RIGHTLEFT
10594 clear_string_option(&wop->wo_rlc);
10595#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010596#ifdef FEAT_STL_OPT
10597 clear_string_option(&wop->wo_stl);
10598#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010599#ifdef FEAT_SYN_HL
10600 clear_string_option(&wop->wo_cc);
10601#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010602#ifdef FEAT_CONCEAL
10603 clear_string_option(&wop->wo_cocu);
10604#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010605}
10606
10607/*
10608 * Copy global option values to local options for one buffer.
10609 * Used when creating a new buffer and sometimes when entering a buffer.
10610 * flags:
10611 * BCO_ENTER We will enter the buf buffer.
10612 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10613 * appropriate.
10614 * BCO_NOHELP Don't copy the values to a help buffer.
10615 */
10616 void
10617buf_copy_options(buf, flags)
10618 buf_T *buf;
10619 int flags;
10620{
10621 int should_copy = TRUE;
10622 char_u *save_p_isk = NULL; /* init for GCC */
10623 int dont_do_help;
10624 int did_isk = FALSE;
10625
10626 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010627 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628 */
10629 if (buf == NULL || !buf_valid(buf))
10630 return;
10631
10632 /*
10633 * Skip this when the option defaults have not been set yet. Happens when
10634 * main() allocates the first buffer.
10635 */
10636 if (p_cpo != NULL)
10637 {
10638 /*
10639 * Always copy when entering and 'cpo' contains 'S'.
10640 * Don't copy when already initialized.
10641 * Don't copy when 'cpo' contains 's' and not entering.
10642 * 'S' BCO_ENTER initialized 's' should_copy
10643 * yes yes X X TRUE
10644 * yes no yes X FALSE
10645 * no X yes X FALSE
10646 * X no no yes FALSE
10647 * X no no no TRUE
10648 * no yes no X TRUE
10649 */
10650 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10651 && (buf->b_p_initialized
10652 || (!(flags & BCO_ENTER)
10653 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10654 should_copy = FALSE;
10655
10656 if (should_copy || (flags & BCO_ALWAYS))
10657 {
10658 /* Don't copy the options specific to a help buffer when
10659 * BCO_NOHELP is given or the options were initialized already
10660 * (jumping back to a help file with CTRL-T or CTRL-O) */
10661 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10662 || buf->b_p_initialized;
10663 if (dont_do_help) /* don't free b_p_isk */
10664 {
10665 save_p_isk = buf->b_p_isk;
10666 buf->b_p_isk = NULL;
10667 }
10668 /*
10669 * Always free the allocated strings.
10670 * If not already initialized, set 'readonly' and copy 'fileformat'.
10671 */
10672 if (!buf->b_p_initialized)
10673 {
10674 free_buf_options(buf, TRUE);
10675 buf->b_p_ro = FALSE; /* don't copy readonly */
10676 buf->b_p_tx = p_tx;
10677#ifdef FEAT_MBYTE
10678 buf->b_p_fenc = vim_strsave(p_fenc);
10679#endif
10680 buf->b_p_ff = vim_strsave(p_ff);
10681#if defined(FEAT_QUICKFIX)
10682 buf->b_p_bh = empty_option;
10683 buf->b_p_bt = empty_option;
10684#endif
10685 }
10686 else
10687 free_buf_options(buf, FALSE);
10688
10689 buf->b_p_ai = p_ai;
10690 buf->b_p_ai_nopaste = p_ai_nopaste;
10691 buf->b_p_sw = p_sw;
10692 buf->b_p_tw = p_tw;
10693 buf->b_p_tw_nopaste = p_tw_nopaste;
10694 buf->b_p_tw_nobin = p_tw_nobin;
10695 buf->b_p_wm = p_wm;
10696 buf->b_p_wm_nopaste = p_wm_nopaste;
10697 buf->b_p_wm_nobin = p_wm_nobin;
10698 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010699#ifdef FEAT_MBYTE
10700 buf->b_p_bomb = p_bomb;
10701#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010702 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010703 buf->b_p_et = p_et;
10704 buf->b_p_et_nobin = p_et_nobin;
10705 buf->b_p_ml = p_ml;
10706 buf->b_p_ml_nobin = p_ml_nobin;
10707 buf->b_p_inf = p_inf;
10708 buf->b_p_swf = p_swf;
10709#ifdef FEAT_INS_EXPAND
10710 buf->b_p_cpt = vim_strsave(p_cpt);
10711#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010712#ifdef FEAT_COMPL_FUNC
10713 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010714 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716 buf->b_p_sts = p_sts;
10717 buf->b_p_sts_nopaste = p_sts_nopaste;
10718#ifndef SHORT_FNAME
10719 buf->b_p_sn = p_sn;
10720#endif
10721#ifdef FEAT_COMMENTS
10722 buf->b_p_com = vim_strsave(p_com);
10723#endif
10724#ifdef FEAT_FOLDING
10725 buf->b_p_cms = vim_strsave(p_cms);
10726#endif
10727 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010728 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729 buf->b_p_nf = vim_strsave(p_nf);
10730 buf->b_p_mps = vim_strsave(p_mps);
10731#ifdef FEAT_SMARTINDENT
10732 buf->b_p_si = p_si;
10733#endif
10734 buf->b_p_ci = p_ci;
10735#ifdef FEAT_CINDENT
10736 buf->b_p_cin = p_cin;
10737 buf->b_p_cink = vim_strsave(p_cink);
10738 buf->b_p_cino = vim_strsave(p_cino);
10739#endif
10740#ifdef FEAT_AUTOCMD
10741 /* Don't copy 'filetype', it must be detected */
10742 buf->b_p_ft = empty_option;
10743#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010744 buf->b_p_pi = p_pi;
10745#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10746 buf->b_p_cinw = vim_strsave(p_cinw);
10747#endif
10748#ifdef FEAT_LISP
10749 buf->b_p_lisp = p_lisp;
10750#endif
10751#ifdef FEAT_SYN_HL
10752 /* Don't copy 'syntax', it must be set */
10753 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010754 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010755#endif
10756#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010757 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010758 (void)compile_cap_prog(&buf->b_s);
10759 buf->b_s.b_p_spf = vim_strsave(p_spf);
10760 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761#endif
10762#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10763 buf->b_p_inde = vim_strsave(p_inde);
10764 buf->b_p_indk = vim_strsave(p_indk);
10765#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010766#if defined(FEAT_EVAL)
10767 buf->b_p_fex = vim_strsave(p_fex);
10768#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010769#ifdef FEAT_CRYPT
10770 buf->b_p_key = vim_strsave(p_key);
10771#endif
10772#ifdef FEAT_SEARCHPATH
10773 buf->b_p_sua = vim_strsave(p_sua);
10774#endif
10775#ifdef FEAT_KEYMAP
10776 buf->b_p_keymap = vim_strsave(p_keymap);
10777 buf->b_kmap_state |= KEYMAP_INIT;
10778#endif
10779 /* This isn't really an option, but copying the langmap and IME
10780 * state from the current buffer is better than resetting it. */
10781 buf->b_p_iminsert = p_iminsert;
10782 buf->b_p_imsearch = p_imsearch;
10783
10784 /* options that are normally global but also have a local value
10785 * are not copied, start using the global value */
10786 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010787 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010788 buf->b_p_bkc = empty_option;
10789 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010790#ifdef FEAT_QUICKFIX
10791 buf->b_p_gp = empty_option;
10792 buf->b_p_mp = empty_option;
10793 buf->b_p_efm = empty_option;
10794#endif
10795 buf->b_p_ep = empty_option;
10796 buf->b_p_kp = empty_option;
10797 buf->b_p_path = empty_option;
10798 buf->b_p_tags = empty_option;
10799#ifdef FEAT_FIND_ID
10800 buf->b_p_def = empty_option;
10801 buf->b_p_inc = empty_option;
10802# ifdef FEAT_EVAL
10803 buf->b_p_inex = vim_strsave(p_inex);
10804# endif
10805#endif
10806#ifdef FEAT_INS_EXPAND
10807 buf->b_p_dict = empty_option;
10808 buf->b_p_tsr = empty_option;
10809#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010810#ifdef FEAT_TEXTOBJ
10811 buf->b_p_qe = vim_strsave(p_qe);
10812#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010813#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10814 buf->b_p_bexpr = empty_option;
10815#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010816#if defined(FEAT_CRYPT)
10817 buf->b_p_cm = empty_option;
10818#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010819#ifdef FEAT_PERSISTENT_UNDO
10820 buf->b_p_udf = p_udf;
10821#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010822#ifdef FEAT_LISP
10823 buf->b_p_lw = empty_option;
10824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825
10826 /*
10827 * Don't copy the options set by ex_help(), use the saved values,
10828 * when going from a help buffer to a non-help buffer.
10829 * Don't touch these at all when BCO_NOHELP is used and going from
10830 * or to a help buffer.
10831 */
10832 if (dont_do_help)
10833 buf->b_p_isk = save_p_isk;
10834 else
10835 {
10836 buf->b_p_isk = vim_strsave(p_isk);
10837 did_isk = TRUE;
10838 buf->b_p_ts = p_ts;
10839 buf->b_help = FALSE;
10840#ifdef FEAT_QUICKFIX
10841 if (buf->b_p_bt[0] == 'h')
10842 clear_string_option(&buf->b_p_bt);
10843#endif
10844 buf->b_p_ma = p_ma;
10845 }
10846 }
10847
10848 /*
10849 * When the options should be copied (ignoring BCO_ALWAYS), set the
10850 * flag that indicates that the options have been initialized.
10851 */
10852 if (should_copy)
10853 buf->b_p_initialized = TRUE;
10854 }
10855
10856 check_buf_options(buf); /* make sure we don't have NULLs */
10857 if (did_isk)
10858 (void)buf_init_chartab(buf, FALSE);
10859}
10860
10861/*
10862 * Reset the 'modifiable' option and its default value.
10863 */
10864 void
10865reset_modifiable()
10866{
10867 int opt_idx;
10868
10869 curbuf->b_p_ma = FALSE;
10870 p_ma = FALSE;
10871 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010872 if (opt_idx >= 0)
10873 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874}
10875
10876/*
10877 * Set the global value for 'iminsert' to the local value.
10878 */
10879 void
10880set_iminsert_global()
10881{
10882 p_iminsert = curbuf->b_p_iminsert;
10883}
10884
10885/*
10886 * Set the global value for 'imsearch' to the local value.
10887 */
10888 void
10889set_imsearch_global()
10890{
10891 p_imsearch = curbuf->b_p_imsearch;
10892}
10893
10894#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10895static int expand_option_idx = -1;
10896static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10897static int expand_option_flags = 0;
10898
10899 void
10900set_context_in_set_cmd(xp, arg, opt_flags)
10901 expand_T *xp;
10902 char_u *arg;
10903 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10904{
10905 int nextchar;
10906 long_u flags = 0; /* init for GCC */
10907 int opt_idx = 0; /* init for GCC */
10908 char_u *p;
10909 char_u *s;
10910 int is_term_option = FALSE;
10911 int key;
10912
10913 expand_option_flags = opt_flags;
10914
10915 xp->xp_context = EXPAND_SETTINGS;
10916 if (*arg == NUL)
10917 {
10918 xp->xp_pattern = arg;
10919 return;
10920 }
10921 p = arg + STRLEN(arg) - 1;
10922 if (*p == ' ' && *(p - 1) != '\\')
10923 {
10924 xp->xp_pattern = p + 1;
10925 return;
10926 }
10927 while (p > arg)
10928 {
10929 s = p;
10930 /* count number of backslashes before ' ' or ',' */
10931 if (*p == ' ' || *p == ',')
10932 {
10933 while (s > arg && *(s - 1) == '\\')
10934 --s;
10935 }
10936 /* break at a space with an even number of backslashes */
10937 if (*p == ' ' && ((p - s) & 1) == 0)
10938 {
10939 ++p;
10940 break;
10941 }
10942 --p;
10943 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010944 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945 {
10946 xp->xp_context = EXPAND_BOOL_SETTINGS;
10947 p += 2;
10948 }
10949 if (STRNCMP(p, "inv", 3) == 0)
10950 {
10951 xp->xp_context = EXPAND_BOOL_SETTINGS;
10952 p += 3;
10953 }
10954 xp->xp_pattern = arg = p;
10955 if (*arg == '<')
10956 {
10957 while (*p != '>')
10958 if (*p++ == NUL) /* expand terminal option name */
10959 return;
10960 key = get_special_key_code(arg + 1);
10961 if (key == 0) /* unknown name */
10962 {
10963 xp->xp_context = EXPAND_NOTHING;
10964 return;
10965 }
10966 nextchar = *++p;
10967 is_term_option = TRUE;
10968 expand_option_name[2] = KEY2TERMCAP0(key);
10969 expand_option_name[3] = KEY2TERMCAP1(key);
10970 }
10971 else
10972 {
10973 if (p[0] == 't' && p[1] == '_')
10974 {
10975 p += 2;
10976 if (*p != NUL)
10977 ++p;
10978 if (*p == NUL)
10979 return; /* expand option name */
10980 nextchar = *++p;
10981 is_term_option = TRUE;
10982 expand_option_name[2] = p[-2];
10983 expand_option_name[3] = p[-1];
10984 }
10985 else
10986 {
10987 /* Allow * wildcard */
10988 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10989 p++;
10990 if (*p == NUL)
10991 return;
10992 nextchar = *p;
10993 *p = NUL;
10994 opt_idx = findoption(arg);
10995 *p = nextchar;
10996 if (opt_idx == -1 || options[opt_idx].var == NULL)
10997 {
10998 xp->xp_context = EXPAND_NOTHING;
10999 return;
11000 }
11001 flags = options[opt_idx].flags;
11002 if (flags & P_BOOL)
11003 {
11004 xp->xp_context = EXPAND_NOTHING;
11005 return;
11006 }
11007 }
11008 }
11009 /* handle "-=" and "+=" */
11010 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11011 {
11012 ++p;
11013 nextchar = '=';
11014 }
11015 if ((nextchar != '=' && nextchar != ':')
11016 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11017 {
11018 xp->xp_context = EXPAND_UNSUCCESSFUL;
11019 return;
11020 }
11021 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11022 {
11023 xp->xp_context = EXPAND_OLD_SETTING;
11024 if (is_term_option)
11025 expand_option_idx = -1;
11026 else
11027 expand_option_idx = opt_idx;
11028 xp->xp_pattern = p + 1;
11029 return;
11030 }
11031 xp->xp_context = EXPAND_NOTHING;
11032 if (is_term_option || (flags & P_NUM))
11033 return;
11034
11035 xp->xp_pattern = p + 1;
11036
11037 if (flags & P_EXPAND)
11038 {
11039 p = options[opt_idx].var;
11040 if (p == (char_u *)&p_bdir
11041 || p == (char_u *)&p_dir
11042 || p == (char_u *)&p_path
11043 || p == (char_u *)&p_rtp
11044#ifdef FEAT_SEARCHPATH
11045 || p == (char_u *)&p_cdpath
11046#endif
11047#ifdef FEAT_SESSION
11048 || p == (char_u *)&p_vdir
11049#endif
11050 )
11051 {
11052 xp->xp_context = EXPAND_DIRECTORIES;
11053 if (p == (char_u *)&p_path
11054#ifdef FEAT_SEARCHPATH
11055 || p == (char_u *)&p_cdpath
11056#endif
11057 )
11058 xp->xp_backslash = XP_BS_THREE;
11059 else
11060 xp->xp_backslash = XP_BS_ONE;
11061 }
11062 else
11063 {
11064 xp->xp_context = EXPAND_FILES;
11065 /* for 'tags' need three backslashes for a space */
11066 if (p == (char_u *)&p_tags)
11067 xp->xp_backslash = XP_BS_THREE;
11068 else
11069 xp->xp_backslash = XP_BS_ONE;
11070 }
11071 }
11072
11073 /* For an option that is a list of file names, find the start of the
11074 * last file name. */
11075 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11076 {
11077 /* count number of backslashes before ' ' or ',' */
11078 if (*p == ' ' || *p == ',')
11079 {
11080 s = p;
11081 while (s > xp->xp_pattern && *(s - 1) == '\\')
11082 --s;
11083 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11084 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11085 {
11086 xp->xp_pattern = p + 1;
11087 break;
11088 }
11089 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011090
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011091#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011092 /* for 'spellsuggest' start at "file:" */
11093 if (options[opt_idx].var == (char_u *)&p_sps
11094 && STRNCMP(p, "file:", 5) == 0)
11095 {
11096 xp->xp_pattern = p + 5;
11097 break;
11098 }
11099#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011100 }
11101
11102 return;
11103}
11104
11105 int
11106ExpandSettings(xp, regmatch, num_file, file)
11107 expand_T *xp;
11108 regmatch_T *regmatch;
11109 int *num_file;
11110 char_u ***file;
11111{
11112 int num_normal = 0; /* Nr of matching non-term-code settings */
11113 int num_term = 0; /* Nr of matching terminal code settings */
11114 int opt_idx;
11115 int match;
11116 int count = 0;
11117 char_u *str;
11118 int loop;
11119 int is_term_opt;
11120 char_u name_buf[MAX_KEY_NAME_LEN];
11121 static char *(names[]) = {"all", "termcap"};
11122 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11123
11124 /* do this loop twice:
11125 * loop == 0: count the number of matching options
11126 * loop == 1: copy the matching options into allocated memory
11127 */
11128 for (loop = 0; loop <= 1; ++loop)
11129 {
11130 regmatch->rm_ic = ic;
11131 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11132 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011133 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11134 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011135 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11136 {
11137 if (loop == 0)
11138 num_normal++;
11139 else
11140 (*file)[count++] = vim_strsave((char_u *)names[match]);
11141 }
11142 }
11143 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11144 opt_idx++)
11145 {
11146 if (options[opt_idx].var == NULL)
11147 continue;
11148 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11149 && !(options[opt_idx].flags & P_BOOL))
11150 continue;
11151 is_term_opt = istermoption(&options[opt_idx]);
11152 if (is_term_opt && num_normal > 0)
11153 continue;
11154 match = FALSE;
11155 if (vim_regexec(regmatch, str, (colnr_T)0)
11156 || (options[opt_idx].shortname != NULL
11157 && vim_regexec(regmatch,
11158 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11159 match = TRUE;
11160 else if (is_term_opt)
11161 {
11162 name_buf[0] = '<';
11163 name_buf[1] = 't';
11164 name_buf[2] = '_';
11165 name_buf[3] = str[2];
11166 name_buf[4] = str[3];
11167 name_buf[5] = '>';
11168 name_buf[6] = NUL;
11169 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11170 {
11171 match = TRUE;
11172 str = name_buf;
11173 }
11174 }
11175 if (match)
11176 {
11177 if (loop == 0)
11178 {
11179 if (is_term_opt)
11180 num_term++;
11181 else
11182 num_normal++;
11183 }
11184 else
11185 (*file)[count++] = vim_strsave(str);
11186 }
11187 }
11188 /*
11189 * Check terminal key codes, these are not in the option table
11190 */
11191 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11192 {
11193 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11194 {
11195 if (!isprint(str[0]) || !isprint(str[1]))
11196 continue;
11197
11198 name_buf[0] = 't';
11199 name_buf[1] = '_';
11200 name_buf[2] = str[0];
11201 name_buf[3] = str[1];
11202 name_buf[4] = NUL;
11203
11204 match = FALSE;
11205 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11206 match = TRUE;
11207 else
11208 {
11209 name_buf[0] = '<';
11210 name_buf[1] = 't';
11211 name_buf[2] = '_';
11212 name_buf[3] = str[0];
11213 name_buf[4] = str[1];
11214 name_buf[5] = '>';
11215 name_buf[6] = NUL;
11216
11217 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11218 match = TRUE;
11219 }
11220 if (match)
11221 {
11222 if (loop == 0)
11223 num_term++;
11224 else
11225 (*file)[count++] = vim_strsave(name_buf);
11226 }
11227 }
11228
11229 /*
11230 * Check special key names.
11231 */
11232 regmatch->rm_ic = TRUE; /* ignore case here */
11233 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11234 {
11235 name_buf[0] = '<';
11236 STRCPY(name_buf + 1, str);
11237 STRCAT(name_buf, ">");
11238
11239 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11240 {
11241 if (loop == 0)
11242 num_term++;
11243 else
11244 (*file)[count++] = vim_strsave(name_buf);
11245 }
11246 }
11247 }
11248 if (loop == 0)
11249 {
11250 if (num_normal > 0)
11251 *num_file = num_normal;
11252 else if (num_term > 0)
11253 *num_file = num_term;
11254 else
11255 return OK;
11256 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11257 if (*file == NULL)
11258 {
11259 *file = (char_u **)"";
11260 return FAIL;
11261 }
11262 }
11263 }
11264 return OK;
11265}
11266
11267 int
11268ExpandOldSetting(num_file, file)
11269 int *num_file;
11270 char_u ***file;
11271{
11272 char_u *var = NULL; /* init for GCC */
11273 char_u *buf;
11274
11275 *num_file = 0;
11276 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11277 if (*file == NULL)
11278 return FAIL;
11279
11280 /*
11281 * For a terminal key code expand_option_idx is < 0.
11282 */
11283 if (expand_option_idx < 0)
11284 {
11285 var = find_termcode(expand_option_name + 2);
11286 if (var == NULL)
11287 expand_option_idx = findoption(expand_option_name);
11288 }
11289
11290 if (expand_option_idx >= 0)
11291 {
11292 /* put string of option value in NameBuff */
11293 option_value2string(&options[expand_option_idx], expand_option_flags);
11294 var = NameBuff;
11295 }
11296 else if (var == NULL)
11297 var = (char_u *)"";
11298
11299 /* A backslash is required before some characters. This is the reverse of
11300 * what happens in do_set(). */
11301 buf = vim_strsave_escaped(var, escape_chars);
11302
11303 if (buf == NULL)
11304 {
11305 vim_free(*file);
11306 *file = NULL;
11307 return FAIL;
11308 }
11309
11310#ifdef BACKSLASH_IN_FILENAME
11311 /* For MS-Windows et al. we don't double backslashes at the start and
11312 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011313 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011314 if (var[0] == '\\' && var[1] == '\\'
11315 && expand_option_idx >= 0
11316 && (options[expand_option_idx].flags & P_EXPAND)
11317 && vim_isfilec(var[2])
11318 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011319 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011320#endif
11321
11322 *file[0] = buf;
11323 *num_file = 1;
11324 return OK;
11325}
11326#endif
11327
11328/*
11329 * Get the value for the numeric or string option *opp in a nice format into
11330 * NameBuff[]. Must not be called with a hidden option!
11331 */
11332 static void
11333option_value2string(opp, opt_flags)
11334 struct vimoption *opp;
11335 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11336{
11337 char_u *varp;
11338
11339 varp = get_varp_scope(opp, opt_flags);
11340
11341 if (opp->flags & P_NUM)
11342 {
11343 long wc = 0;
11344
11345 if (wc_use_keyname(varp, &wc))
11346 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11347 else if (wc != 0)
11348 STRCPY(NameBuff, transchar((int)wc));
11349 else
11350 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11351 }
11352 else /* P_STRING */
11353 {
11354 varp = *(char_u **)(varp);
11355 if (varp == NULL) /* just in case */
11356 NameBuff[0] = NUL;
11357#ifdef FEAT_CRYPT
11358 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011359 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011360 STRCPY(NameBuff, "*****");
11361#endif
11362 else if (opp->flags & P_EXPAND)
11363 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11364 /* Translate 'pastetoggle' into special key names */
11365 else if ((char_u **)opp->var == &p_pt)
11366 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11367 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011368 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011369 }
11370}
11371
11372/*
11373 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11374 * printed as a keyname.
11375 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11376 */
11377 static int
11378wc_use_keyname(varp, wcp)
11379 char_u *varp;
11380 long *wcp;
11381{
11382 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11383 {
11384 *wcp = *(long *)varp;
11385 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11386 return TRUE;
11387 }
11388 return FALSE;
11389}
11390
Bram Moolenaar01615492015-02-03 13:00:38 +010011391#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011392/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011393 * Any character has an equivalent 'langmap' character. This is used for
11394 * keyboards that have a special language mode that sends characters above
11395 * 128 (although other characters can be translated too). The "to" field is a
11396 * Vim command character. This avoids having to switch the keyboard back to
11397 * ASCII mode when leaving Insert mode.
11398 *
11399 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11400 * commands.
11401 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11402 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11403 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011404 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011405# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011406/*
11407 * With multi-byte support use growarray for 'langmap' chars >= 256
11408 */
11409typedef struct
11410{
11411 int from;
11412 int to;
11413} langmap_entry_T;
11414
11415static garray_T langmap_mapga;
11416static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011417
11418/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011419 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11420 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011421 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011422 static void
11423langmap_set_entry(from, to)
11424 int from;
11425 int to;
11426{
11427 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011428 int a = 0;
11429 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011430
11431 /* Do a binary search for an existing entry. */
11432 while (a != b)
11433 {
11434 int i = (a + b) / 2;
11435 int d = entries[i].from - from;
11436
11437 if (d == 0)
11438 {
11439 entries[i].to = to;
11440 return;
11441 }
11442 if (d < 0)
11443 a = i + 1;
11444 else
11445 b = i;
11446 }
11447
11448 if (ga_grow(&langmap_mapga, 1) != OK)
11449 return; /* out of memory */
11450
11451 /* insert new entry at position "a" */
11452 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11453 mch_memmove(entries + 1, entries,
11454 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11455 ++langmap_mapga.ga_len;
11456 entries[0].from = from;
11457 entries[0].to = to;
11458}
11459
11460/*
11461 * Apply 'langmap' to multi-byte character "c" and return the result.
11462 */
11463 int
11464langmap_adjust_mb(c)
11465 int c;
11466{
11467 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11468 int a = 0;
11469 int b = langmap_mapga.ga_len;
11470
11471 while (a != b)
11472 {
11473 int i = (a + b) / 2;
11474 int d = entries[i].from - c;
11475
11476 if (d == 0)
11477 return entries[i].to; /* found matching entry */
11478 if (d < 0)
11479 a = i + 1;
11480 else
11481 b = i;
11482 }
11483 return c; /* no entry found, return "c" unmodified */
11484}
11485# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011486
11487 static void
11488langmap_init()
11489{
11490 int i;
11491
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011492 for (i = 0; i < 256; i++)
11493 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11494# ifdef FEAT_MBYTE
11495 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11496# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011497}
11498
11499/*
11500 * Called when langmap option is set; the language map can be
11501 * changed at any time!
11502 */
11503 static void
11504langmap_set()
11505{
11506 char_u *p;
11507 char_u *p2;
11508 int from, to;
11509
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011510#ifdef FEAT_MBYTE
11511 ga_clear(&langmap_mapga); /* clear the previous map first */
11512#endif
11513 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011514
11515 for (p = p_langmap; p[0] != NUL; )
11516 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011517 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11518 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011519 {
11520 if (p2[0] == '\\' && p2[1] != NUL)
11521 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011522 }
11523 if (p2[0] == ';')
11524 ++p2; /* abcd;ABCD form, p2 points to A */
11525 else
11526 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11527 while (p[0])
11528 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011529 if (p[0] == ',')
11530 {
11531 ++p;
11532 break;
11533 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534 if (p[0] == '\\' && p[1] != NUL)
11535 ++p;
11536#ifdef FEAT_MBYTE
11537 from = (*mb_ptr2char)(p);
11538#else
11539 from = p[0];
11540#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011541 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011542 if (p2 == NULL)
11543 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011544 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011545 if (p[0] != ',')
11546 {
11547 if (p[0] == '\\')
11548 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011549#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011550 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011551#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011552 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011553#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011554 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555 }
11556 else
11557 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011558 if (p2[0] != ',')
11559 {
11560 if (p2[0] == '\\')
11561 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011562#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011563 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011564#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011565 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011566#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011567 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011568 }
11569 if (to == NUL)
11570 {
11571 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11572 transchar(from));
11573 return;
11574 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011575
11576#ifdef FEAT_MBYTE
11577 if (from >= 256)
11578 langmap_set_entry(from, to);
11579 else
11580#endif
11581 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011582
11583 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011584 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011585 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011586 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011587 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011588 if (*p == ';')
11589 {
11590 p = p2;
11591 if (p[0] != NUL)
11592 {
11593 if (p[0] != ',')
11594 {
11595 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11596 return;
11597 }
11598 ++p;
11599 }
11600 break;
11601 }
11602 }
11603 }
11604 }
11605}
11606#endif
11607
11608/*
11609 * Return TRUE if format option 'x' is in effect.
11610 * Take care of no formatting when 'paste' is set.
11611 */
11612 int
11613has_format_option(x)
11614 int x;
11615{
11616 if (p_paste)
11617 return FALSE;
11618 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11619}
11620
11621/*
11622 * Return TRUE if "x" is present in 'shortmess' option, or
11623 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11624 */
11625 int
11626shortmess(x)
11627 int x;
11628{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011629 return p_shm != NULL &&
11630 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011631 || (vim_strchr(p_shm, 'a') != NULL
11632 && vim_strchr((char_u *)SHM_A, x) != NULL));
11633}
11634
11635/*
11636 * paste_option_changed() - Called after p_paste was set or reset.
11637 */
11638 static void
11639paste_option_changed()
11640{
11641 static int old_p_paste = FALSE;
11642 static int save_sm = 0;
11643#ifdef FEAT_CMDL_INFO
11644 static int save_ru = 0;
11645#endif
11646#ifdef FEAT_RIGHTLEFT
11647 static int save_ri = 0;
11648 static int save_hkmap = 0;
11649#endif
11650 buf_T *buf;
11651
11652 if (p_paste)
11653 {
11654 /*
11655 * Paste switched from off to on.
11656 * Save the current values, so they can be restored later.
11657 */
11658 if (!old_p_paste)
11659 {
11660 /* save options for each buffer */
11661 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11662 {
11663 buf->b_p_tw_nopaste = buf->b_p_tw;
11664 buf->b_p_wm_nopaste = buf->b_p_wm;
11665 buf->b_p_sts_nopaste = buf->b_p_sts;
11666 buf->b_p_ai_nopaste = buf->b_p_ai;
11667 }
11668
11669 /* save global options */
11670 save_sm = p_sm;
11671#ifdef FEAT_CMDL_INFO
11672 save_ru = p_ru;
11673#endif
11674#ifdef FEAT_RIGHTLEFT
11675 save_ri = p_ri;
11676 save_hkmap = p_hkmap;
11677#endif
11678 /* save global values for local buffer options */
11679 p_tw_nopaste = p_tw;
11680 p_wm_nopaste = p_wm;
11681 p_sts_nopaste = p_sts;
11682 p_ai_nopaste = p_ai;
11683 }
11684
11685 /*
11686 * Always set the option values, also when 'paste' is set when it is
11687 * already on.
11688 */
11689 /* set options for each buffer */
11690 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11691 {
11692 buf->b_p_tw = 0; /* textwidth is 0 */
11693 buf->b_p_wm = 0; /* wrapmargin is 0 */
11694 buf->b_p_sts = 0; /* softtabstop is 0 */
11695 buf->b_p_ai = 0; /* no auto-indent */
11696 }
11697
11698 /* set global options */
11699 p_sm = 0; /* no showmatch */
11700#ifdef FEAT_CMDL_INFO
11701# ifdef FEAT_WINDOWS
11702 if (p_ru)
11703 status_redraw_all(); /* redraw to remove the ruler */
11704# endif
11705 p_ru = 0; /* no ruler */
11706#endif
11707#ifdef FEAT_RIGHTLEFT
11708 p_ri = 0; /* no reverse insert */
11709 p_hkmap = 0; /* no Hebrew keyboard */
11710#endif
11711 /* set global values for local buffer options */
11712 p_tw = 0;
11713 p_wm = 0;
11714 p_sts = 0;
11715 p_ai = 0;
11716 }
11717
11718 /*
11719 * Paste switched from on to off: Restore saved values.
11720 */
11721 else if (old_p_paste)
11722 {
11723 /* restore options for each buffer */
11724 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11725 {
11726 buf->b_p_tw = buf->b_p_tw_nopaste;
11727 buf->b_p_wm = buf->b_p_wm_nopaste;
11728 buf->b_p_sts = buf->b_p_sts_nopaste;
11729 buf->b_p_ai = buf->b_p_ai_nopaste;
11730 }
11731
11732 /* restore global options */
11733 p_sm = save_sm;
11734#ifdef FEAT_CMDL_INFO
11735# ifdef FEAT_WINDOWS
11736 if (p_ru != save_ru)
11737 status_redraw_all(); /* redraw to draw the ruler */
11738# endif
11739 p_ru = save_ru;
11740#endif
11741#ifdef FEAT_RIGHTLEFT
11742 p_ri = save_ri;
11743 p_hkmap = save_hkmap;
11744#endif
11745 /* set global values for local buffer options */
11746 p_tw = p_tw_nopaste;
11747 p_wm = p_wm_nopaste;
11748 p_sts = p_sts_nopaste;
11749 p_ai = p_ai_nopaste;
11750 }
11751
11752 old_p_paste = p_paste;
11753}
11754
11755/*
11756 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11757 *
11758 * Reset 'compatible' and set the values for options that didn't get set yet
11759 * to the Vim defaults.
11760 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011761 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011762 */
11763 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011764vimrc_found(fname, envname)
11765 char_u *fname;
11766 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011768 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011769 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011770 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771
11772 if (!option_was_set((char_u *)"cp"))
11773 {
11774 p_cp = FALSE;
11775 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11776 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11777 set_option_default(opt_idx, OPT_FREE, FALSE);
11778 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011779 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011780 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011781
11782 if (fname != NULL)
11783 {
11784 p = vim_getenv(envname, &dofree);
11785 if (p == NULL)
11786 {
11787 /* Set $MYVIMRC to the first vimrc file found. */
11788 p = FullName_save(fname, FALSE);
11789 if (p != NULL)
11790 {
11791 vim_setenv(envname, p);
11792 vim_free(p);
11793 }
11794 }
11795 else if (dofree)
11796 vim_free(p);
11797 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011798}
11799
11800/*
11801 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11802 */
11803 void
11804change_compatible(on)
11805 int on;
11806{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011807 int opt_idx;
11808
Bram Moolenaar071d4272004-06-13 20:20:40 +000011809 if (p_cp != on)
11810 {
11811 p_cp = on;
11812 compatible_set();
11813 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011814 opt_idx = findoption((char_u *)"cp");
11815 if (opt_idx >= 0)
11816 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011817}
11818
11819/*
11820 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011821 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011822 */
11823 int
11824option_was_set(name)
11825 char_u *name;
11826{
11827 int idx;
11828
11829 idx = findoption(name);
11830 if (idx < 0) /* unknown option */
11831 return FALSE;
11832 if (options[idx].flags & P_WAS_SET)
11833 return TRUE;
11834 return FALSE;
11835}
11836
11837/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011838 * Reset the flag indicating option "name" was set.
11839 */
11840 void
11841reset_option_was_set(name)
11842 char_u *name;
11843{
11844 int idx = findoption(name);
11845
11846 if (idx >= 0)
11847 options[idx].flags &= ~P_WAS_SET;
11848}
11849
11850/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011851 * compatible_set() - Called when 'compatible' has been set or unset.
11852 *
11853 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11854 * flag) to a Vi compatible value.
11855 * When 'compatible' is unset: Set all options that have a different default
11856 * for Vim (without the P_VI_DEF flag) to that default.
11857 */
11858 static void
11859compatible_set()
11860{
11861 int opt_idx;
11862
11863 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11864 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11865 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11866 set_option_default(opt_idx, OPT_FREE, p_cp);
11867 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011868 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011869}
11870
11871#ifdef FEAT_LINEBREAK
11872
11873# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11874 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011875 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011876# endif
11877
11878/*
11879 * fill_breakat_flags() -- called when 'breakat' changes value.
11880 */
11881 static void
11882fill_breakat_flags()
11883{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011884 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011885 int i;
11886
11887 for (i = 0; i < 256; i++)
11888 breakat_flags[i] = FALSE;
11889
11890 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011891 for (p = p_breakat; *p; p++)
11892 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893}
11894
11895# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011896 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011897# endif
11898
11899#endif
11900
11901/*
11902 * Check an option that can be a range of string values.
11903 *
11904 * Return OK for correct value, FAIL otherwise.
11905 * Empty is always OK.
11906 */
11907 static int
11908check_opt_strings(val, values, list)
11909 char_u *val;
11910 char **values;
11911 int list; /* when TRUE: accept a list of values */
11912{
11913 return opt_strings_flags(val, values, NULL, list);
11914}
11915
11916/*
11917 * Handle an option that can be a range of string values.
11918 * Set a flag in "*flagp" for each string present.
11919 *
11920 * Return OK for correct value, FAIL otherwise.
11921 * Empty is always OK.
11922 */
11923 static int
11924opt_strings_flags(val, values, flagp, list)
11925 char_u *val; /* new value */
11926 char **values; /* array of valid string values */
11927 unsigned *flagp;
11928 int list; /* when TRUE: accept a list of values */
11929{
11930 int i;
11931 int len;
11932 unsigned new_flags = 0;
11933
11934 while (*val)
11935 {
11936 for (i = 0; ; ++i)
11937 {
11938 if (values[i] == NULL) /* val not found in values[] */
11939 return FAIL;
11940
11941 len = (int)STRLEN(values[i]);
11942 if (STRNCMP(values[i], val, len) == 0
11943 && ((list && val[len] == ',') || val[len] == NUL))
11944 {
11945 val += len + (val[len] == ',');
11946 new_flags |= (1 << i);
11947 break; /* check next item in val list */
11948 }
11949 }
11950 }
11951 if (flagp != NULL)
11952 *flagp = new_flags;
11953
11954 return OK;
11955}
11956
11957/*
11958 * Read the 'wildmode' option, fill wim_flags[].
11959 */
11960 static int
11961check_opt_wim()
11962{
11963 char_u new_wim_flags[4];
11964 char_u *p;
11965 int i;
11966 int idx = 0;
11967
11968 for (i = 0; i < 4; ++i)
11969 new_wim_flags[i] = 0;
11970
11971 for (p = p_wim; *p; ++p)
11972 {
11973 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11974 ;
11975 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11976 return FAIL;
11977 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11978 new_wim_flags[idx] |= WIM_LONGEST;
11979 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11980 new_wim_flags[idx] |= WIM_FULL;
11981 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11982 new_wim_flags[idx] |= WIM_LIST;
11983 else
11984 return FAIL;
11985 p += i;
11986 if (*p == NUL)
11987 break;
11988 if (*p == ',')
11989 {
11990 if (idx == 3)
11991 return FAIL;
11992 ++idx;
11993 }
11994 }
11995
11996 /* fill remaining entries with last flag */
11997 while (idx < 3)
11998 {
11999 new_wim_flags[idx + 1] = new_wim_flags[idx];
12000 ++idx;
12001 }
12002
12003 /* only when there are no errors, wim_flags[] is changed */
12004 for (i = 0; i < 4; ++i)
12005 wim_flags[i] = new_wim_flags[i];
12006 return OK;
12007}
12008
12009/*
12010 * Check if backspacing over something is allowed.
12011 */
12012 int
12013can_bs(what)
12014 int what; /* BS_INDENT, BS_EOL or BS_START */
12015{
12016 switch (*p_bs)
12017 {
12018 case '2': return TRUE;
12019 case '1': return (what != BS_START);
12020 case '0': return FALSE;
12021 }
12022 return vim_strchr(p_bs, what) != NULL;
12023}
12024
12025/*
12026 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12027 * the file must be considered changed when the value is different.
12028 */
12029 void
12030save_file_ff(buf)
12031 buf_T *buf;
12032{
12033 buf->b_start_ffc = *buf->b_p_ff;
12034 buf->b_start_eol = buf->b_p_eol;
12035#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012036 buf->b_start_bomb = buf->b_p_bomb;
12037
Bram Moolenaar071d4272004-06-13 20:20:40 +000012038 /* Only use free/alloc when necessary, they take time. */
12039 if (buf->b_start_fenc == NULL
12040 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12041 {
12042 vim_free(buf->b_start_fenc);
12043 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12044 }
12045#endif
12046}
12047
12048/*
12049 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12050 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012051 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12052 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012053 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012054 * When "ignore_empty" is true don't consider a new, empty buffer to be
12055 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056 */
12057 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012058file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012059 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012060 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012061{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012062 /* In a buffer that was never loaded the options are not valid. */
12063 if (buf->b_flags & BF_NEVERLOADED)
12064 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012065 if (ignore_empty
12066 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012067 && buf->b_ml.ml_line_count == 1
12068 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12069 return FALSE;
12070 if (buf->b_start_ffc != *buf->b_p_ff)
12071 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012072 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012073 return TRUE;
12074#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012075 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12076 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012077 if (buf->b_start_fenc == NULL)
12078 return (*buf->b_p_fenc != NUL);
12079 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12080#else
12081 return FALSE;
12082#endif
12083}
12084
12085/*
12086 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12087 */
12088 int
12089check_ff_value(p)
12090 char_u *p;
12091{
12092 return check_opt_strings(p, p_ff_values, FALSE);
12093}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012094
12095/*
12096 * Return the effective shiftwidth value for current buffer, using the
12097 * 'tabstop' value when 'shiftwidth' is zero.
12098 */
12099 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012100get_sw_value(buf)
12101 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012102{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012103 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012104}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012105
12106/*
12107 * Return the effective softtabstop value for the current buffer, using the
12108 * 'tabstop' value when 'softtabstop' is negative.
12109 */
12110 long
12111get_sts_value()
12112{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012113 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012114}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012115
12116/*
12117 * Check matchpairs option for "*initc".
12118 * If there is a match set "*initc" to the matching character and "*findc" to
12119 * the opposite character. Set "*backwards" to the direction.
12120 * When "switchit" is TRUE swap the direction.
12121 */
12122 void
12123find_mps_values(initc, findc, backwards, switchit)
12124 int *initc;
12125 int *findc;
12126 int *backwards;
12127 int switchit;
12128{
12129 char_u *ptr;
12130
12131 ptr = curbuf->b_p_mps;
12132 while (*ptr != NUL)
12133 {
12134#ifdef FEAT_MBYTE
12135 if (has_mbyte)
12136 {
12137 char_u *prev;
12138
12139 if (mb_ptr2char(ptr) == *initc)
12140 {
12141 if (switchit)
12142 {
12143 *findc = *initc;
12144 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12145 *backwards = TRUE;
12146 }
12147 else
12148 {
12149 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12150 *backwards = FALSE;
12151 }
12152 return;
12153 }
12154 prev = ptr;
12155 ptr += mb_ptr2len(ptr) + 1;
12156 if (mb_ptr2char(ptr) == *initc)
12157 {
12158 if (switchit)
12159 {
12160 *findc = *initc;
12161 *initc = mb_ptr2char(prev);
12162 *backwards = FALSE;
12163 }
12164 else
12165 {
12166 *findc = mb_ptr2char(prev);
12167 *backwards = TRUE;
12168 }
12169 return;
12170 }
12171 ptr += mb_ptr2len(ptr);
12172 }
12173 else
12174#endif
12175 {
12176 if (*ptr == *initc)
12177 {
12178 if (switchit)
12179 {
12180 *backwards = TRUE;
12181 *findc = *initc;
12182 *initc = ptr[2];
12183 }
12184 else
12185 {
12186 *backwards = FALSE;
12187 *findc = ptr[2];
12188 }
12189 return;
12190 }
12191 ptr += 2;
12192 if (*ptr == *initc)
12193 {
12194 if (switchit)
12195 {
12196 *backwards = FALSE;
12197 *findc = *initc;
12198 *initc = ptr[-2];
12199 }
12200 else
12201 {
12202 *backwards = TRUE;
12203 *findc = ptr[-2];
12204 }
12205 return;
12206 }
12207 ++ptr;
12208 }
12209 if (*ptr == ',')
12210 ++ptr;
12211 }
12212}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012213
12214#if defined(FEAT_LINEBREAK) || defined(PROTO)
12215/*
12216 * This is called when 'breakindentopt' is changed and when a window is
12217 * initialized.
12218 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012219 static int
12220briopt_check(wp)
12221 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012222{
12223 char_u *p;
12224 int bri_shift = 0;
12225 long bri_min = 20;
12226 int bri_sbr = FALSE;
12227
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012228 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012229 while (*p != NUL)
12230 {
12231 if (STRNCMP(p, "shift:", 6) == 0
12232 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12233 {
12234 p += 6;
12235 bri_shift = getdigits(&p);
12236 }
12237 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12238 {
12239 p += 4;
12240 bri_min = getdigits(&p);
12241 }
12242 else if (STRNCMP(p, "sbr", 3) == 0)
12243 {
12244 p += 3;
12245 bri_sbr = TRUE;
12246 }
12247 if (*p != ',' && *p != NUL)
12248 return FAIL;
12249 if (*p == ',')
12250 ++p;
12251 }
12252
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012253 wp->w_p_brishift = bri_shift;
12254 wp->w_p_brimin = bri_min;
12255 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012256
12257 return OK;
12258}
12259#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012260
12261/*
12262 * Get the local or global value of 'backupcopy'.
12263 */
12264 unsigned int
12265get_bkc_value(buf)
12266 buf_T *buf;
12267{
12268 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12269}