blob: 855539b5842a92bee352aafa3e190e281e49d1d3 [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 Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020080#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100137# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000138#endif
139#define PV_MA OPT_BUF(BV_MA)
140#define PV_ML OPT_BUF(BV_ML)
141#define PV_MOD OPT_BUF(BV_MOD)
142#define PV_MPS OPT_BUF(BV_MPS)
143#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000144#ifdef FEAT_COMPL_FUNC
145# define PV_OFU OPT_BUF(BV_OFU)
146#endif
147#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
148#define PV_PI OPT_BUF(BV_PI)
149#ifdef FEAT_TEXTOBJ
150# define PV_QE OPT_BUF(BV_QE)
151#endif
152#define PV_RO OPT_BUF(BV_RO)
153#ifdef FEAT_SMARTINDENT
154# define PV_SI OPT_BUF(BV_SI)
155#endif
156#ifndef SHORT_FNAME
157# define PV_SN OPT_BUF(BV_SN)
158#endif
159#ifdef FEAT_SYN_HL
160# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000161# define PV_SYN OPT_BUF(BV_SYN)
162#endif
163#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164# define PV_SPC OPT_BUF(BV_SPC)
165# define PV_SPF OPT_BUF(BV_SPF)
166# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000167#endif
168#define PV_STS OPT_BUF(BV_STS)
169#ifdef FEAT_SEARCHPATH
170# define PV_SUA OPT_BUF(BV_SUA)
171#endif
172#define PV_SW OPT_BUF(BV_SW)
173#define PV_SWF OPT_BUF(BV_SWF)
174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
175#define PV_TS OPT_BUF(BV_TS)
176#define PV_TW OPT_BUF(BV_TW)
177#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200178#ifdef FEAT_PERSISTENT_UNDO
179# define PV_UDF OPT_BUF(BV_UDF)
180#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000181#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000182
183/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184 * Definition of the PV_ values for window-local options.
185 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187#define PV_LIST OPT_WIN(WV_LIST)
188#ifdef FEAT_ARABIC
189# define PV_ARAB OPT_WIN(WV_ARAB)
190#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200191#ifdef FEAT_LINEBREAK
192# define PV_BRI OPT_WIN(WV_BRI)
193# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
194#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000195#ifdef FEAT_DIFF
196# define PV_DIFF OPT_WIN(WV_DIFF)
197#endif
198#ifdef FEAT_FOLDING
199# define PV_FDC OPT_WIN(WV_FDC)
200# define PV_FEN OPT_WIN(WV_FEN)
201# define PV_FDI OPT_WIN(WV_FDI)
202# define PV_FDL OPT_WIN(WV_FDL)
203# define PV_FDM OPT_WIN(WV_FDM)
204# define PV_FML OPT_WIN(WV_FML)
205# define PV_FDN OPT_WIN(WV_FDN)
206# ifdef FEAT_EVAL
207# define PV_FDE OPT_WIN(WV_FDE)
208# define PV_FDT OPT_WIN(WV_FDT)
209# endif
210# define PV_FMR OPT_WIN(WV_FMR)
211#endif
212#ifdef FEAT_LINEBREAK
213# define PV_LBR OPT_WIN(WV_LBR)
214#endif
215#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200216#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000217#ifdef FEAT_LINEBREAK
218# define PV_NUW OPT_WIN(WV_NUW)
219#endif
220#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
221# define PV_PVW OPT_WIN(WV_PVW)
222#endif
223#ifdef FEAT_RIGHTLEFT
224# define PV_RL OPT_WIN(WV_RL)
225# define PV_RLC OPT_WIN(WV_RLC)
226#endif
227#ifdef FEAT_SCROLLBIND
228# define PV_SCBIND OPT_WIN(WV_SCBIND)
229#endif
230#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000231#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000232# define PV_SPELL OPT_WIN(WV_SPELL)
233#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000234#ifdef FEAT_SYN_HL
235# define PV_CUC OPT_WIN(WV_CUC)
236# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200237# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000238#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000239#ifdef FEAT_STL_OPT
240# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
241#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100242#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000243#ifdef FEAT_WINDOWS
244# define PV_WFH OPT_WIN(WV_WFH)
245#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000246#ifdef FEAT_VERTSPLIT
247# define PV_WFW OPT_WIN(WV_WFW)
248#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000249#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200250#ifdef FEAT_CURSORBIND
251# define PV_CRBIND OPT_WIN(WV_CRBIND)
252#endif
253#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200254# define PV_COCU OPT_WIN(WV_COCU)
255# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200256#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000257
258/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259typedef enum
260{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000261 PV_NONE = 0,
262 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000263} idopt_T;
264
265/*
266 * Options local to a window have a value local to a buffer and global to all
267 * buffers. Indicate this by setting "var" to VAR_WIN.
268 */
269#define VAR_WIN ((char_u *)-1)
270
271/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000272 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273 * Only to be used in option.c!
274 */
275static int p_ai;
276static int p_bin;
277#ifdef FEAT_MBYTE
278static int p_bomb;
279#endif
280#if defined(FEAT_QUICKFIX)
281static char_u *p_bh;
282static char_u *p_bt;
283#endif
284static int p_bl;
285static int p_ci;
286#ifdef FEAT_CINDENT
287static int p_cin;
288static char_u *p_cink;
289static char_u *p_cino;
290#endif
291#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
292static char_u *p_cinw;
293#endif
294#ifdef FEAT_COMMENTS
295static char_u *p_com;
296#endif
297#ifdef FEAT_FOLDING
298static char_u *p_cms;
299#endif
300#ifdef FEAT_INS_EXPAND
301static char_u *p_cpt;
302#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000303#ifdef FEAT_COMPL_FUNC
304static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000305static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307static int p_eol;
308static int p_et;
309#ifdef FEAT_MBYTE
310static char_u *p_fenc;
311#endif
312static char_u *p_ff;
313static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000314static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315#ifdef FEAT_AUTOCMD
316static char_u *p_ft;
317#endif
318static long p_iminsert;
319static long p_imsearch;
320#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
321static char_u *p_inex;
322#endif
323#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
324static char_u *p_inde;
325static char_u *p_indk;
326#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000327#if defined(FEAT_EVAL)
328static char_u *p_fex;
329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330static int p_inf;
331static char_u *p_isk;
332#ifdef FEAT_CRYPT
333static char_u *p_key;
334#endif
335#ifdef FEAT_LISP
336static int p_lisp;
337#endif
338static int p_ml;
339static int p_ma;
340static int p_mod;
341static char_u *p_mps;
342static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344#ifdef FEAT_TEXTOBJ
345static char_u *p_qe;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_ro;
348#ifdef FEAT_SMARTINDENT
349static int p_si;
350#endif
351#ifndef SHORT_FNAME
352static int p_sn;
353#endif
354static long p_sts;
355#if defined(FEAT_SEARCHPATH)
356static char_u *p_sua;
357#endif
358static long p_sw;
359static int p_swf;
360#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000361static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000363#endif
364#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000365static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000366static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000367static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368#endif
369static long p_ts;
370static long p_tw;
371static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200372#ifdef FEAT_PERSISTENT_UNDO
373static int p_udf;
374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375static long p_wm;
376#ifdef FEAT_KEYMAP
377static char_u *p_keymap;
378#endif
379
380/* Saved values for when 'bin' is set. */
381static int p_et_nobin;
382static int p_ml_nobin;
383static long p_tw_nobin;
384static long p_wm_nobin;
385
386/* Saved values for when 'paste' is set */
387static long p_tw_nopaste;
388static long p_wm_nopaste;
389static long p_sts_nopaste;
390static int p_ai_nopaste;
391
392struct vimoption
393{
394 char *fullname; /* full option name */
395 char *shortname; /* permissible abbreviation */
396 long_u flags; /* see below */
397 char_u *var; /* global option: pointer to variable;
398 * window-local option: VAR_WIN;
399 * buffer-local option: global value */
400 idopt_T indir; /* global option: PV_NONE;
401 * local option: indirect option index */
402 char_u *def_val[2]; /* default values for variable (vi and vim) */
403#ifdef FEAT_EVAL
404 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000405# define SCRIPTID_INIT , 0
406#else
407# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408#endif
409};
410
411#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
412#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
413
414/*
415 * Flags
416 */
417#define P_BOOL 0x01 /* the option is boolean */
418#define P_NUM 0x02 /* the option is numeric */
419#define P_STRING 0x04 /* the option is a string */
420#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000421 must use free_string_option() when
422 assigning new value. Not set if default is
423 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000424#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
425 never be used for local or hidden options! */
426#define P_NODEFAULT 0x40 /* don't set to default value */
427#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
428 use vim_free() when assigning new value */
429#define P_WAS_SET 0x100 /* option has been set/reset */
430#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
431#define P_VI_DEF 0x400 /* Use Vi default for Vim */
432#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
433
434 /* when option changed, what to display: */
435#define P_RSTAT 0x1000 /* redraw status lines */
436#define P_RWIN 0x2000 /* redraw current window */
437#define P_RBUF 0x4000 /* redraw current buffer */
438#define P_RALL 0x6000 /* redraw all windows */
439#define P_RCLR 0x7000 /* clear and redraw all */
440
441#define P_COMMA 0x8000 /* comma separated list */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200442#define P_NODUP 0x10000L /* don't allow duplicate strings */
443#define P_FLAGLIST 0x20000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444
Bram Moolenaar913077c2012-03-28 19:59:04 +0200445#define P_SECURE 0x40000L /* cannot change in modeline or secure mode */
446#define P_GETTEXT 0x80000L /* expand default value with _() */
447#define P_NOGLOB 0x100000L /* do not use local value for global vimrc */
448#define P_NFNAME 0x200000L /* only normal file name chars allowed */
449#define P_INSECURE 0x400000L /* option was set from a modeline */
450#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000451 side effects) */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200452#define P_NO_ML 0x1000000L /* not allowed in modeline */
453#define P_CURSWANT 0x2000000L /* update curswant required; not needed when
454 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000455
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000456#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
457
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000458/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
459 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000460#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000461# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000462#else
463# define ISP_LATIN1 (char_u *)"@,161-255"
464#endif
465
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000466/* The 16 bit MS-DOS version is low on space, make the string as short as
467 * possible when compiling with few features. */
468#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
469 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200470 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100471# 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 +0000472#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100473# 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 +0000474#endif
475
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476/*
477 * options[] is initialized here.
478 * The order of the options MUST be alphabetic for ":set all" and findoption().
479 * All option names MUST start with a lowercase letter (for findoption()).
480 * Exception: "t_" options are at the end.
481 * The options with a NULL variable are 'hidden': a set command for them is
482 * ignored and they are not printed.
483 */
484static struct vimoption
485#ifdef FEAT_GUI_W16
486 _far
487#endif
488 options[] =
489{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200490 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000491#ifdef FEAT_RIGHTLEFT
492 (char_u *)&p_aleph, PV_NONE,
493#else
494 (char_u *)NULL, PV_NONE,
495#endif
496 {
497#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
498 (char_u *)128L,
499#else
500 (char_u *)224L,
501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000502 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
504#if defined(FEAT_GUI) && defined(MACOS_X)
505 (char_u *)&p_antialias, PV_NONE,
506 {(char_u *)FALSE, (char_u *)FALSE}
507#else
508 (char_u *)NULL, PV_NONE,
509 {(char_u *)FALSE, (char_u *)FALSE}
510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000511 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200512 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000513#ifdef FEAT_ARABIC
514 (char_u *)VAR_WIN, PV_ARAB,
515#else
516 (char_u *)NULL, PV_NONE,
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
520#ifdef FEAT_ARABIC
521 (char_u *)&p_arshape, PV_NONE,
522#else
523 (char_u *)NULL, PV_NONE,
524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000525 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
527#ifdef FEAT_RIGHTLEFT
528 (char_u *)&p_ari, PV_NONE,
529#else
530 (char_u *)NULL, PV_NONE,
531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000532 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
534#ifdef FEAT_FKMAP
535 (char_u *)&p_altkeymap, PV_NONE,
536#else
537 (char_u *)NULL, PV_NONE,
538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000540 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
541#if defined(FEAT_MBYTE)
542 (char_u *)&p_ambw, PV_NONE,
543 {(char_u *)"single", (char_u *)0L}
544#else
545 (char_u *)NULL, PV_NONE,
546 {(char_u *)0L, (char_u *)0L}
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000549#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"autochdir", "acd", P_BOOL|P_VI_DEF,
551 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553#endif
554 {"autoindent", "ai", P_BOOL|P_VI_DEF,
555 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autoprint", "ap", P_BOOL|P_VI_DEF,
558 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000561 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autowrite", "aw", P_BOOL|P_VI_DEF,
564 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autowriteall","awa", P_BOOL|P_VI_DEF,
567 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
570 (char_u *)&p_bg, PV_NONE,
571 {
572#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
573 (char_u *)"dark",
574#else
575 (char_u *)"light",
576#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000577 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
579 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
582 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
585 (char_u *)&p_bkc, PV_NONE,
586#ifdef UNIX
587 {(char_u *)"yes", (char_u *)"auto"}
588#else
589 {(char_u *)"auto", (char_u *)"auto"}
590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
593 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000594 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000595 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 (char_u *)&p_bex, PV_NONE,
597 {
598#ifdef VMS
599 (char_u *)"_",
600#else
601 (char_u *)"~",
602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
605#ifdef FEAT_WILDIGN
606 (char_u *)&p_bsk, PV_NONE,
607 {(char_u *)"", (char_u *)0L}
608#else
609 (char_u *)NULL, PV_NONE,
610 {(char_u *)0L, (char_u *)0L}
611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613#ifdef FEAT_BEVAL
614 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
615 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
618 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000620# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000621 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000622 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000624# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625#endif
626 {"beautify", "bf", P_BOOL|P_VI_DEF,
627 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
630 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
633#ifdef MSDOS
634 (char_u *)&p_biosk, PV_NONE,
635#else
636 (char_u *)NULL, PV_NONE,
637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000638 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
640#ifdef FEAT_MBYTE
641 (char_u *)&p_bomb, PV_BOMB,
642#else
643 (char_u *)NULL, PV_NONE,
644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000645 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
647#ifdef FEAT_LINEBREAK
648 (char_u *)&p_breakat, PV_NONE,
649 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
650#else
651 (char_u *)NULL, PV_NONE,
652 {(char_u *)0L, (char_u *)0L}
653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000654 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200655 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
656#ifdef FEAT_LINEBREAK
657 (char_u *)VAR_WIN, PV_BRI,
658 {(char_u *)FALSE, (char_u *)0L}
659#else
660 (char_u *)NULL, PV_NONE,
661 {(char_u *)0L, (char_u *)0L}
662#endif
663 SCRIPTID_INIT},
664 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_COMMA|P_NODUP,
665#ifdef FEAT_LINEBREAK
666 (char_u *)VAR_WIN, PV_BRIOPT,
667 {(char_u *)"", (char_u *)NULL}
668#else
669 (char_u *)NULL, PV_NONE,
670 {(char_u *)"", (char_u *)NULL}
671#endif
672 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
674#ifdef FEAT_BROWSE
675 (char_u *)&p_bsdir, PV_NONE,
676 {(char_u *)"last", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
683#if defined(FEAT_QUICKFIX)
684 (char_u *)&p_bh, PV_BH,
685 {(char_u *)"", (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
692 (char_u *)&p_bl, PV_BL,
693 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000694 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
696#if defined(FEAT_QUICKFIX)
697 (char_u *)&p_bt, PV_BT,
698 {(char_u *)"", (char_u *)0L}
699#else
700 (char_u *)NULL, PV_NONE,
701 {(char_u *)0L, (char_u *)0L}
702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000703 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000705#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 (char_u *)&p_cmp, PV_NONE,
707 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000708#else
709 (char_u *)NULL, PV_NONE,
710 {(char_u *)0L, (char_u *)0L}
711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
714#ifdef FEAT_SEARCHPATH
715 (char_u *)&p_cdpath, PV_NONE,
716 {(char_u *)",,", (char_u *)0L}
717#else
718 (char_u *)NULL, PV_NONE,
719 {(char_u *)0L, (char_u *)0L}
720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 {"cedit", NULL, P_STRING,
723#ifdef FEAT_CMDWIN
724 (char_u *)&p_cedit, PV_NONE,
725 {(char_u *)"", (char_u *)CTRL_F_STR}
726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
732#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
733 (char_u *)&p_ccv, PV_NONE,
734 {(char_u *)"", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
741#ifdef FEAT_CINDENT
742 (char_u *)&p_cin, PV_CIN,
743#else
744 (char_u *)NULL, PV_NONE,
745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
748#ifdef FEAT_CINDENT
749 (char_u *)&p_cink, PV_CINK,
750 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
751#else
752 (char_u *)NULL, PV_NONE,
753 {(char_u *)0L, (char_u *)0L}
754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000755 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
757#ifdef FEAT_CINDENT
758 (char_u *)&p_cino, PV_CINO,
759#else
760 (char_u *)NULL, PV_NONE,
761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000762 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000763 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
764#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
765 (char_u *)&p_cinw, PV_CINW,
766 {(char_u *)"if,else,while,do,for,switch",
767 (char_u *)0L}
768#else
769 (char_u *)NULL, PV_NONE,
770 {(char_u *)0L, (char_u *)0L}
771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000772 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000773 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
774#ifdef FEAT_CLIPBOARD
775 (char_u *)&p_cb, PV_NONE,
776# ifdef FEAT_XCLIPBOARD
777 {(char_u *)"autoselect,exclude:cons\\|linux",
778 (char_u *)0L}
779# else
780 {(char_u *)"", (char_u *)0L}
781# endif
782#else
783 (char_u *)NULL, PV_NONE,
784 {(char_u *)"", (char_u *)0L}
785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
788 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
791#ifdef FEAT_CMDWIN
792 (char_u *)&p_cwh, PV_NONE,
793#else
794 (char_u *)NULL, PV_NONE,
795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000796 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200797 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
798#ifdef FEAT_SYN_HL
799 (char_u *)VAR_WIN, PV_CC,
800#else
801 (char_u *)NULL, PV_NONE,
802#endif
803 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
805 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000806 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200807 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808#ifdef FEAT_COMMENTS
809 (char_u *)&p_com, PV_COM,
810 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
811 (char_u *)0L}
812#else
813 (char_u *)NULL, PV_NONE,
814 {(char_u *)0L, (char_u *)0L}
815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000816 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200817 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818#ifdef FEAT_FOLDING
819 (char_u *)&p_cms, PV_CMS,
820 {(char_u *)"/*%s*/", (char_u *)0L}
821#else
822 (char_u *)NULL, PV_NONE,
823 {(char_u *)0L, (char_u *)0L}
824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000826 /* P_PRI_MKRC isn't needed here, optval_default()
827 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000828 {"compatible", "cp", P_BOOL|P_RALL,
829 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000830 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
832#ifdef FEAT_INS_EXPAND
833 (char_u *)&p_cpt, PV_CPT,
834 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
835#else
836 (char_u *)NULL, PV_NONE,
837 {(char_u *)0L, (char_u *)0L}
838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000839 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200840 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200841#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200842 (char_u *)VAR_WIN, PV_COCU,
843 {(char_u *)"", (char_u *)NULL}
844#else
845 (char_u *)NULL, PV_NONE,
846 {(char_u *)NULL, (char_u *)0L}
847#endif
848 SCRIPTID_INIT},
849 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
850#ifdef FEAT_CONCEAL
851 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200852#else
853 (char_u *)NULL, PV_NONE,
854#endif
855 {(char_u *)0L, (char_u *)0L}
856 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000857 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
858#ifdef FEAT_COMPL_FUNC
859 (char_u *)&p_cfu, PV_CFU,
860 {(char_u *)"", (char_u *)0L}
861#else
862 (char_u *)NULL, PV_NONE,
863 {(char_u *)0L, (char_u *)0L}
864#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000865 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000866 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
867#ifdef FEAT_INS_EXPAND
868 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000869 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000870#else
871 (char_u *)NULL, PV_NONE,
872 {(char_u *)0L, (char_u *)0L}
873#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000874 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000875 {"confirm", "cf", P_BOOL|P_VI_DEF,
876#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
877 (char_u *)&p_confirm, PV_NONE,
878#else
879 (char_u *)NULL, PV_NONE,
880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000881 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000882 {"conskey", "consk",P_BOOL|P_VI_DEF,
883#ifdef MSDOS
884 (char_u *)&p_consk, PV_NONE,
885#else
886 (char_u *)NULL, PV_NONE,
887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
890 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
893 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
895 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200896 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200897#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200898 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200899 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200900#else
901 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200902 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200903#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200904 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
906#ifdef FEAT_CSCOPE
907 (char_u *)&p_cspc, PV_NONE,
908#else
909 (char_u *)NULL, PV_NONE,
910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
913#ifdef FEAT_CSCOPE
914 (char_u *)&p_csprg, PV_NONE,
915 {(char_u *)"cscope", (char_u *)0L}
916#else
917 (char_u *)NULL, PV_NONE,
918 {(char_u *)0L, (char_u *)0L}
919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
922#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
923 (char_u *)&p_csqf, PV_NONE,
924 {(char_u *)"", (char_u *)0L}
925#else
926 (char_u *)NULL, PV_NONE,
927 {(char_u *)0L, (char_u *)0L}
928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000929 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200930 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
931#ifdef FEAT_CSCOPE
932 (char_u *)&p_csre, PV_NONE,
933#else
934 (char_u *)NULL, PV_NONE,
935#endif
936 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
938#ifdef FEAT_CSCOPE
939 (char_u *)&p_cst, PV_NONE,
940#else
941 (char_u *)NULL, PV_NONE,
942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000943 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
945#ifdef FEAT_CSCOPE
946 (char_u *)&p_csto, PV_NONE,
947#else
948 (char_u *)NULL, PV_NONE,
949#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000950 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000951 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
952#ifdef FEAT_CSCOPE
953 (char_u *)&p_csverbose, PV_NONE,
954#else
955 (char_u *)NULL, PV_NONE,
956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000957 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200958 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
959#ifdef FEAT_CURSORBIND
960 (char_u *)VAR_WIN, PV_CRBIND,
961#else
962 (char_u *)NULL, PV_NONE,
963#endif
964 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000965 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
966#ifdef FEAT_SYN_HL
967 (char_u *)VAR_WIN, PV_CUC,
968#else
969 (char_u *)NULL, PV_NONE,
970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000971 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000972 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
973#ifdef FEAT_SYN_HL
974 (char_u *)VAR_WIN, PV_CUL,
975#else
976 (char_u *)NULL, PV_NONE,
977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979 {"debug", NULL, P_STRING|P_VI_DEF,
980 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000981 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200982 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000984 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000985 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000986#else
987 (char_u *)NULL, PV_NONE,
988 {(char_u *)NULL, (char_u *)0L}
989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
992#ifdef FEAT_MBYTE
993 (char_u *)&p_deco, PV_NONE,
994#else
995 (char_u *)NULL, PV_NONE,
996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
999#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001000 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001#else
1002 (char_u *)NULL, PV_NONE,
1003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1006#ifdef FEAT_DIFF
1007 (char_u *)VAR_WIN, PV_DIFF,
1008#else
1009 (char_u *)NULL, PV_NONE,
1010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001011 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001012 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1014 (char_u *)&p_dex, PV_NONE,
1015 {(char_u *)"", (char_u *)0L}
1016#else
1017 (char_u *)NULL, PV_NONE,
1018 {(char_u *)0L, (char_u *)0L}
1019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001020 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
1022#ifdef FEAT_DIFF
1023 (char_u *)&p_dip, PV_NONE,
1024 {(char_u *)"filler", (char_u *)NULL}
1025#else
1026 (char_u *)NULL, PV_NONE,
1027 {(char_u *)"", (char_u *)NULL}
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1031#ifdef FEAT_DIGRAPHS
1032 (char_u *)&p_dg, PV_NONE,
1033#else
1034 (char_u *)NULL, PV_NONE,
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1038 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001039 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1041 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001042 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 {"eadirection", "ead", P_STRING|P_VI_DEF,
1044#ifdef FEAT_VERTSPLIT
1045 (char_u *)&p_ead, PV_NONE,
1046 {(char_u *)"both", (char_u *)0L}
1047#else
1048 (char_u *)NULL, PV_NONE,
1049 {(char_u *)NULL, (char_u *)0L}
1050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1053 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001055 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056#ifdef FEAT_MBYTE
1057 (char_u *)&p_enc, PV_NONE,
1058 {(char_u *)ENC_DFLT, (char_u *)0L}
1059#else
1060 (char_u *)NULL, PV_NONE,
1061 {(char_u *)0L, (char_u *)0L}
1062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1065 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1068 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001071 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1074 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001075 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1077#ifdef FEAT_QUICKFIX
1078 (char_u *)&p_ef, PV_NONE,
1079 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)NULL, (char_u *)0L}
1083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1086#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001087 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089#else
1090 (char_u *)NULL, PV_NONE,
1091 {(char_u *)NULL, (char_u *)0L}
1092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"esckeys", "ek", P_BOOL|P_VIM,
1095 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1098#ifdef FEAT_AUTOCMD
1099 (char_u *)&p_ei, PV_NONE,
1100#else
1101 (char_u *)NULL, PV_NONE,
1102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1105 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1108 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1111#ifdef FEAT_MBYTE
1112 (char_u *)&p_fenc, PV_FENC,
1113 {(char_u *)"", (char_u *)0L}
1114#else
1115 (char_u *)NULL, PV_NONE,
1116 {(char_u *)0L, (char_u *)0L}
1117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1120#ifdef FEAT_MBYTE
1121 (char_u *)&p_fencs, PV_NONE,
1122 {(char_u *)"ucs-bom", (char_u *)0L}
1123#else
1124 (char_u *)NULL, PV_NONE,
1125 {(char_u *)0L, (char_u *)0L}
1126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001128 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1132 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1134 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001135 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1136 (char_u *)&p_fic, PV_NONE,
1137 {
1138#ifdef CASE_INSENSITIVE_FILENAME
1139 (char_u *)TRUE,
1140#else
1141 (char_u *)FALSE,
1142#endif
1143 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001144 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145#ifdef FEAT_AUTOCMD
1146 (char_u *)&p_ft, PV_FT,
1147 {(char_u *)"", (char_u *)0L}
1148#else
1149 (char_u *)NULL, PV_NONE,
1150 {(char_u *)0L, (char_u *)0L}
1151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001152 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1154#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1155 (char_u *)&p_fcs, PV_NONE,
1156 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1157#else
1158 (char_u *)NULL, PV_NONE,
1159 {(char_u *)"", (char_u *)0L}
1160#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001161 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1163#ifdef FEAT_FKMAP
1164 (char_u *)&p_fkmap, PV_NONE,
1165#else
1166 (char_u *)NULL, PV_NONE,
1167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"flash", "fl", P_BOOL|P_VI_DEF,
1170 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172#ifdef FEAT_FOLDING
1173 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1174 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1177 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1180 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1183# ifdef FEAT_EVAL
1184 (char_u *)VAR_WIN, PV_FDE,
1185 {(char_u *)"0", (char_u *)NULL}
1186# else
1187 (char_u *)NULL, PV_NONE,
1188 {(char_u *)NULL, (char_u *)0L}
1189# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001190 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1192 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001193 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1195 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001196 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001197 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001199 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001200 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1201 P_RWIN|P_COMMA|P_NODUP,
1202 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 {(char_u *)"{{{,}}}", (char_u *)NULL}
1204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001205 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1206 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001207 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001208 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1209 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1212 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001214 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 (char_u *)&p_fdo, PV_NONE,
1216 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1219# ifdef FEAT_EVAL
1220 (char_u *)VAR_WIN, PV_FDT,
1221 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001222# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 (char_u *)NULL, PV_NONE,
1224 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001225# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001228 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001229#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001230 (char_u *)&p_fex, PV_FEX,
1231 {(char_u *)"", (char_u *)0L}
1232#else
1233 (char_u *)NULL, PV_NONE,
1234 {(char_u *)0L, (char_u *)0L}
1235#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1238 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001239 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1240 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001241 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1242 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001243 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1244 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1246 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001247 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001248 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1249#ifdef HAVE_FSYNC
1250 (char_u *)&p_fs, PV_NONE,
1251 {(char_u *)TRUE, (char_u *)0L}
1252#else
1253 (char_u *)NULL, PV_NONE,
1254 {(char_u *)FALSE, (char_u *)0L}
1255#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001257 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1258 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001259 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001260 {"graphic", "gr", P_BOOL|P_VI_DEF,
1261 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001262 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001263 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1264#ifdef FEAT_QUICKFIX
1265 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)NULL, (char_u *)0L}
1270#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001271 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001272 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1273#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001274 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001275 {
1276# ifdef WIN3264
1277 /* may be changed to "grep -n" in os_win32.c */
1278 (char_u *)"findstr /n",
1279# else
1280# ifdef UNIX
1281 /* Add an extra file name so that grep will always
1282 * insert a file name in the match line. */
1283 (char_u *)"grep -n $* /dev/null",
1284# else
1285# ifdef VMS
1286 (char_u *)"SEARCH/NUMBERS ",
1287# else
1288 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001289# endif
1290# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001292 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001293#else
1294 (char_u *)NULL, PV_NONE,
1295 {(char_u *)NULL, (char_u *)0L}
1296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001297 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1299#ifdef CURSOR_SHAPE
1300 (char_u *)&p_guicursor, PV_NONE,
1301 {
1302# ifdef FEAT_GUI
1303 (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",
1304# else /* MSDOS or Win32 console */
1305 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1306# endif
1307 (char_u *)0L}
1308#else
1309 (char_u *)NULL, PV_NONE,
1310 {(char_u *)NULL, (char_u *)0L}
1311#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1314#ifdef FEAT_GUI
1315 (char_u *)&p_guifont, PV_NONE,
1316 {(char_u *)"", (char_u *)0L}
1317#else
1318 (char_u *)NULL, PV_NONE,
1319 {(char_u *)NULL, (char_u *)0L}
1320#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001321 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001322 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1323#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1324 (char_u *)&p_guifontset, PV_NONE,
1325 {(char_u *)"", (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 Moolenaar071d4272004-06-13 20:20:40 +00001331 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1332#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1333 (char_u *)&p_guifontwide, 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 Moolenaar071d4272004-06-13 20:20:40 +00001340 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001341#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 (char_u *)&p_ghr, PV_NONE,
1343#else
1344 (char_u *)NULL, PV_NONE,
1345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001348#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 (char_u *)&p_go, PV_NONE,
1350# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001351 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001353 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354# endif
1355#else
1356 (char_u *)NULL, PV_NONE,
1357 {(char_u *)NULL, (char_u *)0L}
1358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 {"guipty", NULL, P_BOOL|P_VI_DEF,
1361#if defined(FEAT_GUI)
1362 (char_u *)&p_guipty, PV_NONE,
1363#else
1364 (char_u *)NULL, PV_NONE,
1365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001366 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001367 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001368#if defined(FEAT_GUI_TABLINE)
1369 (char_u *)&p_gtl, PV_NONE,
1370 {(char_u *)"", (char_u *)0L}
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001375 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001376 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001377#if defined(FEAT_GUI_TABLINE)
1378 (char_u *)&p_gtt, PV_NONE,
1379 {(char_u *)"", (char_u *)0L}
1380#else
1381 (char_u *)NULL, PV_NONE,
1382 {(char_u *)NULL, (char_u *)0L}
1383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001384 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1386 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001387 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001388 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1389 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001390 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1391 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392 {"helpheight", "hh", P_NUM|P_VI_DEF,
1393#ifdef FEAT_WINDOWS
1394 (char_u *)&p_hh, PV_NONE,
1395#else
1396 (char_u *)NULL, PV_NONE,
1397#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001398 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1400#ifdef FEAT_MULTI_LANG
1401 (char_u *)&p_hlg, PV_NONE,
1402 {(char_u *)"", (char_u *)0L}
1403#else
1404 (char_u *)NULL, PV_NONE,
1405 {(char_u *)0L, (char_u *)0L}
1406#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001407 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"hidden", "hid", P_BOOL|P_VI_DEF,
1409 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001410 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001411 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1412 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001413 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1414 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415 {"history", "hi", P_NUM|P_VIM,
1416 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001417 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1419#ifdef FEAT_RIGHTLEFT
1420 (char_u *)&p_hkmap, PV_NONE,
1421#else
1422 (char_u *)NULL, PV_NONE,
1423#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001424 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1426#ifdef FEAT_RIGHTLEFT
1427 (char_u *)&p_hkmapp, PV_NONE,
1428#else
1429 (char_u *)NULL, PV_NONE,
1430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1433 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"icon", NULL, P_BOOL|P_VI_DEF,
1436#ifdef FEAT_TITLE
1437 (char_u *)&p_icon, PV_NONE,
1438#else
1439 (char_u *)NULL, PV_NONE,
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"iconstring", NULL, P_STRING|P_VI_DEF,
1443#ifdef FEAT_TITLE
1444 (char_u *)&p_iconstring, PV_NONE,
1445#else
1446 (char_u *)NULL, PV_NONE,
1447#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001448 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1450 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001452 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1453# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1454 (char_u *)&p_imaf, PV_NONE,
1455 {(char_u *)"", (char_u *)NULL}
1456# else
1457 (char_u *)NULL, PV_NONE,
1458 {(char_u *)NULL, (char_u *)0L}
1459# endif
1460 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001462#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463 (char_u *)&p_imak, PV_NONE,
1464#else
1465 (char_u *)NULL, PV_NONE,
1466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001467 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1469#ifdef USE_IM_CONTROL
1470 (char_u *)&p_imcmdline, PV_NONE,
1471#else
1472 (char_u *)NULL, PV_NONE,
1473#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001474 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001475 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1476#ifdef USE_IM_CONTROL
1477 (char_u *)&p_imdisable, PV_NONE,
1478#else
1479 (char_u *)NULL, PV_NONE,
1480#endif
1481#ifdef __sgi
1482 {(char_u *)TRUE, (char_u *)0L}
1483#else
1484 {(char_u *)FALSE, (char_u *)0L}
1485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001486 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 {"iminsert", "imi", P_NUM|P_VI_DEF,
1488 (char_u *)&p_iminsert, PV_IMI,
1489#ifdef B_IMODE_IM
1490 {(char_u *)B_IMODE_IM, (char_u *)0L}
1491#else
1492 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001494 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"imsearch", "ims", P_NUM|P_VI_DEF,
1496 (char_u *)&p_imsearch, PV_IMS,
1497#ifdef B_IMODE_IM
1498 {(char_u *)B_IMODE_IM, (char_u *)0L}
1499#else
1500 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001503 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001504# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1505 (char_u *)&p_imsf, PV_NONE,
1506 {(char_u *)"", (char_u *)NULL}
1507# else
1508 (char_u *)NULL, PV_NONE,
1509 {(char_u *)NULL, (char_u *)0L}
1510# endif
1511 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1513#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001514 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1516#else
1517 (char_u *)NULL, PV_NONE,
1518 {(char_u *)0L, (char_u *)0L}
1519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001520 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1522#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1523 (char_u *)&p_inex, PV_INEX,
1524 {(char_u *)"", (char_u *)0L}
1525#else
1526 (char_u *)NULL, PV_NONE,
1527 {(char_u *)0L, (char_u *)0L}
1528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001529 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1531 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001532 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001533 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1534#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1535 (char_u *)&p_inde, PV_INDE,
1536 {(char_u *)"", (char_u *)0L}
1537#else
1538 (char_u *)NULL, PV_NONE,
1539 {(char_u *)0L, (char_u *)0L}
1540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001541 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1543#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1544 (char_u *)&p_indk, PV_INDK,
1545 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1546#else
1547 (char_u *)NULL, PV_NONE,
1548 {(char_u *)0L, (char_u *)0L}
1549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001550 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001551 {"infercase", "inf", P_BOOL|P_VI_DEF,
1552 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1555 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1558 (char_u *)&p_isf, PV_NONE,
1559 {
1560#ifdef BACKSLASH_IN_FILENAME
1561 /* Excluded are: & and ^ are special in cmd.exe
1562 * ( and ) are used in text separating fnames */
1563 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1564#else
1565# ifdef AMIGA
1566 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1567# else
1568# ifdef VMS
1569 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1570# else /* UNIX et al. */
1571# ifdef EBCDIC
1572 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1573# else
1574 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1575# endif
1576# endif
1577# endif
1578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1581 (char_u *)&p_isi, PV_NONE,
1582 {
1583#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1584 (char_u *)"@,48-57,_,128-167,224-235",
1585#else
1586# ifdef EBCDIC
1587 /* TODO: EBCDIC Check this! @ == isalpha()*/
1588 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1589 "112-120,128,140-142,156,158,172,"
1590 "174,186,191,203-207,219-225,235-239,"
1591 "251-254",
1592# else
1593 (char_u *)"@,48-57,_,192-255",
1594# endif
1595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001596 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001597 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1598 (char_u *)&p_isk, PV_ISK,
1599 {
1600#ifdef EBCDIC
1601 (char_u *)"@,240-249,_",
1602 /* TODO: EBCDIC Check this! @ == isalpha()*/
1603 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1604 "112-120,128,140-142,156,158,172,"
1605 "174,186,191,203-207,219-225,235-239,"
1606 "251-254",
1607#else
1608 (char_u *)"@,48-57,_",
1609# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1610 (char_u *)"@,48-57,_,128-167,224-235"
1611# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001612 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613# endif
1614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001615 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001616 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1617 (char_u *)&p_isp, PV_NONE,
1618 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001619#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1620 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001621 || defined(VMS)
1622 (char_u *)"@,~-255",
1623#else
1624# ifdef EBCDIC
1625 /* all chars above 63 are printable */
1626 (char_u *)"63-255",
1627# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001628 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629# endif
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1633 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1636#ifdef FEAT_CRYPT
1637 (char_u *)&p_key, PV_KEY,
1638 {(char_u *)"", (char_u *)0L}
1639#else
1640 (char_u *)NULL, PV_NONE,
1641 {(char_u *)0L, (char_u *)0L}
1642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001644 {"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 +00001645#ifdef FEAT_KEYMAP
1646 (char_u *)&p_keymap, PV_KMAP,
1647 {(char_u *)"", (char_u *)0L}
1648#else
1649 (char_u *)NULL, PV_NONE,
1650 {(char_u *)"", (char_u *)0L}
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001656 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001657 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658 {
1659#if defined(MSDOS) || defined(MSWIN)
1660 (char_u *)":help",
1661#else
1662#ifdef VMS
1663 (char_u *)"help",
1664#else
1665# if defined(OS2)
1666 (char_u *)"view /",
1667# else
1668# ifdef USEMAN_S
1669 (char_u *)"man -s",
1670# else
1671 (char_u *)"man",
1672# endif
1673# endif
1674#endif
1675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001676 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaared7547d2014-05-13 12:17:15 +02001677 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678#ifdef FEAT_LANGMAP
1679 (char_u *)&p_langmap, PV_NONE,
1680 {(char_u *)"", /* unmatched } */
1681#else
1682 (char_u *)NULL, PV_NONE,
1683 {(char_u *)NULL,
1684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001685 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001686 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1688 (char_u *)&p_lm, PV_NONE,
1689#else
1690 (char_u *)NULL, PV_NONE,
1691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1694#ifdef FEAT_WINDOWS
1695 (char_u *)&p_ls, PV_NONE,
1696#else
1697 (char_u *)NULL, PV_NONE,
1698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001699 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1701 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001702 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1704#ifdef FEAT_LINEBREAK
1705 (char_u *)VAR_WIN, PV_LBR,
1706#else
1707 (char_u *)NULL, PV_NONE,
1708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001709 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1711 (char_u *)&Rows, PV_NONE,
1712 {
1713#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1714 (char_u *)25L,
1715#else
1716 (char_u *)24L,
1717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001718 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1720#ifdef FEAT_GUI
1721 (char_u *)&p_linespace, PV_NONE,
1722#else
1723 (char_u *)NULL, PV_NONE,
1724#endif
1725#ifdef FEAT_GUI_W32
1726 {(char_u *)1L, (char_u *)0L}
1727#else
1728 {(char_u *)0L, (char_u *)0L}
1729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 {"lisp", NULL, P_BOOL|P_VI_DEF,
1732#ifdef FEAT_LISP
1733 (char_u *)&p_lisp, PV_LISP,
1734#else
1735 (char_u *)NULL, PV_NONE,
1736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001737 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1739#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001740 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1742#else
1743 (char_u *)NULL, PV_NONE,
1744 {(char_u *)"", (char_u *)0L}
1745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001746 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1748 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1751 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1754 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001755 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001756#ifdef FEAT_GUI_MAC
1757 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1758 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"magic", NULL, P_BOOL|P_VI_DEF,
1762 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001764 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765#ifdef FEAT_QUICKFIX
1766 (char_u *)&p_mef, PV_NONE,
1767 {(char_u *)"", (char_u *)0L}
1768#else
1769 (char_u *)NULL, PV_NONE,
1770 {(char_u *)NULL, (char_u *)0L}
1771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1774#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001775 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776# ifdef VMS
1777 {(char_u *)"MMS", (char_u *)0L}
1778# else
1779 {(char_u *)"make", (char_u *)0L}
1780# endif
1781#else
1782 (char_u *)NULL, PV_NONE,
1783 {(char_u *)NULL, (char_u *)0L}
1784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1787 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1789 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"matchtime", "mat", P_NUM|P_VI_DEF,
1791 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001793 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001794#ifdef FEAT_MBYTE
1795 (char_u *)&p_mco, PV_NONE,
1796#else
1797 (char_u *)NULL, PV_NONE,
1798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001799 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1801#ifdef FEAT_EVAL
1802 (char_u *)&p_mfd, PV_NONE,
1803#else
1804 (char_u *)NULL, PV_NONE,
1805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001806 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1808 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001809 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810 {"maxmem", "mm", P_NUM|P_VI_DEF,
1811 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001812 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1813 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001814 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1815 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1818 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1820 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"menuitems", "mis", P_NUM|P_VI_DEF,
1822#ifdef FEAT_MENU
1823 (char_u *)&p_mis, PV_NONE,
1824#else
1825 (char_u *)NULL, PV_NONE,
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"mesg", NULL, P_BOOL|P_VI_DEF,
1829 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001831 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001832#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001833 (char_u *)&p_msm, PV_NONE,
1834 {(char_u *)"460000,2000,500", (char_u *)0L}
1835#else
1836 (char_u *)NULL, PV_NONE,
1837 {(char_u *)0L, (char_u *)0L}
1838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001839 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001840 {"modeline", "ml", P_BOOL|P_VIM,
1841 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001842 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001843 {"modelines", "mls", P_NUM|P_VI_DEF,
1844 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1847 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1850 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"more", NULL, P_BOOL|P_VIM,
1853 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001854 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1856 (char_u *)&p_mouse, PV_NONE,
1857 {
1858#if defined(MSDOS) || defined(WIN3264)
1859 (char_u *)"a",
1860#else
1861 (char_u *)"",
1862#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1865#ifdef FEAT_GUI
1866 (char_u *)&p_mousef, PV_NONE,
1867#else
1868 (char_u *)NULL, PV_NONE,
1869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1872#ifdef FEAT_GUI
1873 (char_u *)&p_mh, PV_NONE,
1874#else
1875 (char_u *)NULL, PV_NONE,
1876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1879 (char_u *)&p_mousem, PV_NONE,
1880 {
1881#if defined(MSDOS) || defined(MSWIN)
1882 (char_u *)"popup",
1883#else
1884# if defined(MACOS)
1885 (char_u *)"popup_setpos",
1886# else
1887 (char_u *)"extend",
1888# endif
1889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001890 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1892#ifdef FEAT_MOUSESHAPE
1893 (char_u *)&p_mouseshape, PV_NONE,
1894 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1895#else
1896 (char_u *)NULL, PV_NONE,
1897 {(char_u *)NULL, (char_u *)0L}
1898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1901 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001903 {"mzquantum", "mzq", P_NUM,
1904#ifdef FEAT_MZSCHEME
1905 (char_u *)&p_mzq, PV_NONE,
1906#else
1907 (char_u *)NULL, PV_NONE,
1908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001909 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 {"novice", NULL, P_BOOL|P_VI_DEF,
1911 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1914 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)"octal,hex", (char_u *)0L}
1916 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1918 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001920 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1921#ifdef FEAT_LINEBREAK
1922 (char_u *)VAR_WIN, PV_NUW,
1923#else
1924 (char_u *)NULL, PV_NONE,
1925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001927 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001928#ifdef FEAT_COMPL_FUNC
1929 (char_u *)&p_ofu, PV_OFU,
1930 {(char_u *)"", (char_u *)0L}
1931#else
1932 (char_u *)NULL, PV_NONE,
1933 {(char_u *)0L, (char_u *)0L}
1934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {"open", NULL, P_BOOL|P_VI_DEF,
1937 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001939 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1940#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1941 (char_u *)&p_odev, PV_NONE,
1942#else
1943 (char_u *)NULL, PV_NONE,
1944#endif
1945 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001947 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1948 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"optimize", "opt", P_BOOL|P_VI_DEF,
1951 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001955 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"paragraphs", "para", P_STRING|P_VI_DEF,
1957 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001958 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001960 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1964 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001965 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1967#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1968 (char_u *)&p_pex, PV_NONE,
1969 {(char_u *)"", (char_u *)0L}
1970#else
1971 (char_u *)NULL, PV_NONE,
1972 {(char_u *)0L, (char_u *)0L}
1973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001975 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001979 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {
1981#if defined AMIGA || defined MSDOS || defined MSWIN
1982 (char_u *)".,,",
1983#else
1984# if defined(__EMX__)
1985 (char_u *)".,/emx/include,,",
1986# else /* Unix, probably */
1987 (char_u *)".,/usr/include,,",
1988# endif
1989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1992 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001994 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1996 (char_u *)&p_pvh, PV_NONE,
1997#else
1998 (char_u *)NULL, PV_NONE,
1999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2002#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2003 (char_u *)VAR_WIN, PV_PVW,
2004#else
2005 (char_u *)NULL, PV_NONE,
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002008 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009#ifdef FEAT_PRINTER
2010 (char_u *)&p_pdev, PV_NONE,
2011 {(char_u *)"", (char_u *)0L}
2012#else
2013 (char_u *)NULL, PV_NONE,
2014 {(char_u *)NULL, (char_u *)0L}
2015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 {"printencoding", "penc", P_STRING|P_VI_DEF,
2018#ifdef FEAT_POSTSCRIPT
2019 (char_u *)&p_penc, PV_NONE,
2020 {(char_u *)"", (char_u *)0L}
2021#else
2022 (char_u *)NULL, PV_NONE,
2023 {(char_u *)NULL, (char_u *)0L}
2024#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2027#ifdef FEAT_POSTSCRIPT
2028 (char_u *)&p_pexpr, PV_NONE,
2029 {(char_u *)"", (char_u *)0L}
2030#else
2031 (char_u *)NULL, PV_NONE,
2032 {(char_u *)NULL, (char_u *)0L}
2033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002034 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 {"printfont", "pfn", P_STRING|P_VI_DEF,
2036#ifdef FEAT_PRINTER
2037 (char_u *)&p_pfn, PV_NONE,
2038 {
2039# ifdef MSWIN
2040 (char_u *)"Courier_New:h10",
2041# else
2042 (char_u *)"courier",
2043# endif
2044 (char_u *)0L}
2045#else
2046 (char_u *)NULL, PV_NONE,
2047 {(char_u *)NULL, (char_u *)0L}
2048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002049 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2051#ifdef FEAT_PRINTER
2052 (char_u *)&p_header, PV_NONE,
2053 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2054#else
2055 (char_u *)NULL, PV_NONE,
2056 {(char_u *)NULL, (char_u *)0L}
2057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002058 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002059 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2060#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2061 (char_u *)&p_pmcs, PV_NONE,
2062 {(char_u *)"", (char_u *)0L}
2063#else
2064 (char_u *)NULL, PV_NONE,
2065 {(char_u *)NULL, (char_u *)0L}
2066#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002067 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002068 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2069#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2070 (char_u *)&p_pmfn, PV_NONE,
2071 {(char_u *)"", (char_u *)0L}
2072#else
2073 (char_u *)NULL, PV_NONE,
2074 {(char_u *)NULL, (char_u *)0L}
2075#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002076 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2078#ifdef FEAT_PRINTER
2079 (char_u *)&p_popt, PV_NONE,
2080 {(char_u *)"", (char_u *)0L}
2081#else
2082 (char_u *)NULL, PV_NONE,
2083 {(char_u *)NULL, (char_u *)0L}
2084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002087 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002089 {"pumheight", "ph", P_NUM|P_VI_DEF,
2090#ifdef FEAT_INS_EXPAND
2091 (char_u *)&p_ph, PV_NONE,
2092#else
2093 (char_u *)NULL, PV_NONE,
2094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002096 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2097#ifdef FEAT_TEXTOBJ
2098 (char_u *)&p_qe, PV_QE,
2099 {(char_u *)"\\", (char_u *)0L}
2100#else
2101 (char_u *)NULL, PV_NONE,
2102 {(char_u *)NULL, (char_u *)0L}
2103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2106 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"redraw", NULL, P_BOOL|P_VI_DEF,
2109 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002110 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002111 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2112#ifdef FEAT_RELTIME
2113 (char_u *)&p_rdt, PV_NONE,
2114#else
2115 (char_u *)NULL, PV_NONE,
2116#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002118 {"regexpengine", "re", P_NUM|P_VI_DEF,
2119 (char_u *)&p_re, PV_NONE,
2120 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002121 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2122 (char_u *)VAR_WIN, PV_RNU,
2123 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 {"remap", NULL, P_BOOL|P_VI_DEF,
2125 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002126 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002127 {"renderoptions", "rop", P_STRING|P_COMMA|P_RCLR|P_VI_DEF,
2128#ifdef FEAT_RENDER_OPTIONS
2129 (char_u *)&p_rop, PV_NONE,
2130 {(char_u *)"", (char_u *)0L}
2131#else
2132 (char_u *)NULL, PV_NONE,
2133 {(char_u *)NULL, (char_u *)0L}
2134#endif
2135 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 {"report", NULL, P_NUM|P_VI_DEF,
2137 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002138 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2140#ifdef WIN3264
2141 (char_u *)&p_rs, PV_NONE,
2142#else
2143 (char_u *)NULL, PV_NONE,
2144#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2147#ifdef FEAT_RIGHTLEFT
2148 (char_u *)&p_ri, PV_NONE,
2149#else
2150 (char_u *)NULL, PV_NONE,
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2154#ifdef FEAT_RIGHTLEFT
2155 (char_u *)VAR_WIN, PV_RL,
2156#else
2157 (char_u *)NULL, PV_NONE,
2158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002159 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2161#ifdef FEAT_RIGHTLEFT
2162 (char_u *)VAR_WIN, PV_RLC,
2163 {(char_u *)"search", (char_u *)NULL}
2164#else
2165 (char_u *)NULL, PV_NONE,
2166 {(char_u *)NULL, (char_u *)0L}
2167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002168 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2170#ifdef FEAT_CMDL_INFO
2171 (char_u *)&p_ru, PV_NONE,
2172#else
2173 (char_u *)NULL, PV_NONE,
2174#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002175 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2177#ifdef FEAT_STL_OPT
2178 (char_u *)&p_ruf, PV_NONE,
2179#else
2180 (char_u *)NULL, PV_NONE,
2181#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002182 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2184 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2186 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2188 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002189 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2191#ifdef FEAT_SCROLLBIND
2192 (char_u *)VAR_WIN, PV_SCBIND,
2193#else
2194 (char_u *)NULL, PV_NONE,
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2198 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002199 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2201 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002202 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2204#ifdef FEAT_SCROLLBIND
2205 (char_u *)&p_sbo, PV_NONE,
2206 {(char_u *)"ver,jump", (char_u *)0L}
2207#else
2208 (char_u *)NULL, PV_NONE,
2209 {(char_u *)0L, (char_u *)0L}
2210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002211 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212 {"sections", "sect", P_STRING|P_VI_DEF,
2213 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2215 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002216 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2217 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002218 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002219 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002220 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 {(char_u *)"inclusive", (char_u *)0L}
2222 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2227#ifdef FEAT_SESSION
2228 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002229 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230 (char_u *)0L}
2231#else
2232 (char_u *)NULL, PV_NONE,
2233 {(char_u *)0L, (char_u *)0L}
2234#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002235 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002236 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2237 (char_u *)&p_sh, PV_NONE,
2238 {
2239#ifdef VMS
2240 (char_u *)"-",
2241#else
2242# if defined(MSDOS)
2243 (char_u *)"command",
2244# else
2245# if defined(WIN16)
2246 (char_u *)"command.com",
2247# else
2248# if defined(WIN3264)
2249 (char_u *)"", /* set in set_init_1() */
2250# else
2251# if defined(OS2)
2252 (char_u *)"cmd.exe",
2253# else
2254# if defined(ARCHIE)
2255 (char_u *)"gos",
2256# else
2257 (char_u *)"sh",
2258# endif
2259# endif
2260# endif
2261# endif
2262# endif
2263#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002264 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2266 (char_u *)&p_shcf, PV_NONE,
2267 {
2268#if defined(MSDOS) || defined(MSWIN)
2269 (char_u *)"/c",
2270#else
2271# if defined(OS2)
2272 (char_u *)"/c",
2273# else
2274 (char_u *)"-c",
2275# endif
2276#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002277 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2279#ifdef FEAT_QUICKFIX
2280 (char_u *)&p_sp, PV_NONE,
2281 {
2282#if defined(UNIX) || defined(OS2)
2283# ifdef ARCHIE
2284 (char_u *)"2>",
2285# else
2286 (char_u *)"| tee",
2287# endif
2288#else
2289 (char_u *)">",
2290#endif
2291 (char_u *)0L}
2292#else
2293 (char_u *)NULL, PV_NONE,
2294 {(char_u *)0L, (char_u *)0L}
2295#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002296 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2298 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002299 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2301 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002302 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2304#ifdef BACKSLASH_IN_FILENAME
2305 (char_u *)&p_ssl, PV_NONE,
2306#else
2307 (char_u *)NULL, PV_NONE,
2308#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002310 {"shelltemp", "stmp", P_BOOL,
2311 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002312 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 {"shelltype", "st", P_NUM|P_VI_DEF,
2314#ifdef AMIGA
2315 (char_u *)&p_st, PV_NONE,
2316#else
2317 (char_u *)NULL, PV_NONE,
2318#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002319 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2321 (char_u *)&p_sxq, PV_NONE,
2322 {
2323#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2324 (char_u *)"\"",
2325#else
2326 (char_u *)"",
2327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002329 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2330 (char_u *)&p_sxe, PV_NONE,
2331 {
2332#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2333 (char_u *)"\"&|<>()@^",
2334#else
2335 (char_u *)"",
2336#endif
2337 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2339 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2342 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2345 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)"", (char_u *)"filnxtToO"}
2347 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 {"shortname", "sn", P_BOOL|P_VI_DEF,
2349#ifdef SHORT_FNAME
2350 (char_u *)NULL, PV_NONE,
2351#else
2352 (char_u *)&p_sn, PV_SN,
2353#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2356#ifdef FEAT_LINEBREAK
2357 (char_u *)&p_sbr, PV_NONE,
2358#else
2359 (char_u *)NULL, PV_NONE,
2360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"showcmd", "sc", P_BOOL|P_VIM,
2363#ifdef FEAT_CMDL_INFO
2364 (char_u *)&p_sc, PV_NONE,
2365#else
2366 (char_u *)NULL, PV_NONE,
2367#endif
2368 {(char_u *)FALSE,
2369#ifdef UNIX
2370 (char_u *)FALSE
2371#else
2372 (char_u *)TRUE
2373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2376 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2379 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"showmode", "smd", P_BOOL|P_VIM,
2382 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002383 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002384 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2385#ifdef FEAT_WINDOWS
2386 (char_u *)&p_stal, PV_NONE,
2387#else
2388 (char_u *)NULL, PV_NONE,
2389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2392 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2395 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2398 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2401 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2404#ifdef FEAT_SMARTINDENT
2405 (char_u *)&p_si, PV_SI,
2406#else
2407 (char_u *)NULL, PV_NONE,
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2411 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2414 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2417 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002419 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002420#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002421 (char_u *)VAR_WIN, PV_SPELL,
2422#else
2423 (char_u *)NULL, PV_NONE,
2424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002426 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002427#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002428 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002429 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002430#else
2431 (char_u *)NULL, PV_NONE,
2432 {(char_u *)0L, (char_u *)0L}
2433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002435 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002436#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002437 (char_u *)&p_spf, PV_SPF,
2438 {(char_u *)"", (char_u *)0L}
2439#else
2440 (char_u *)NULL, PV_NONE,
2441 {(char_u *)0L, (char_u *)0L}
2442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002443 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002444 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002445#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002446 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002447 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002448#else
2449 (char_u *)NULL, PV_NONE,
2450 {(char_u *)0L, (char_u *)0L}
2451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002453 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002454#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002455 (char_u *)&p_sps, PV_NONE,
2456 {(char_u *)"best", (char_u *)0L}
2457#else
2458 (char_u *)NULL, PV_NONE,
2459 {(char_u *)0L, (char_u *)0L}
2460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2463#ifdef FEAT_WINDOWS
2464 (char_u *)&p_sb, PV_NONE,
2465#else
2466 (char_u *)NULL, PV_NONE,
2467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"splitright", "spr", P_BOOL|P_VI_DEF,
2470#ifdef FEAT_VERTSPLIT
2471 (char_u *)&p_spr, PV_NONE,
2472#else
2473 (char_u *)NULL, PV_NONE,
2474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2477 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2480#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002481 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482#else
2483 (char_u *)NULL, PV_NONE,
2484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2487 (char_u *)&p_su, PV_NONE,
2488 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002491#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 (char_u *)&p_sua, PV_SUA,
2493 {(char_u *)"", (char_u *)0L}
2494#else
2495 (char_u *)NULL, PV_NONE,
2496 {(char_u *)0L, (char_u *)0L}
2497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2500 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"swapsync", "sws", P_STRING|P_VI_DEF,
2503 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2506 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002508 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2509#ifdef FEAT_SYN_HL
2510 (char_u *)&p_smc, PV_SMC,
2511 {(char_u *)3000L, (char_u *)0L}
2512#else
2513 (char_u *)NULL, PV_NONE,
2514 {(char_u *)0L, (char_u *)0L}
2515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002516 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002517 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518#ifdef FEAT_SYN_HL
2519 (char_u *)&p_syn, PV_SYN,
2520 {(char_u *)"", (char_u *)0L}
2521#else
2522 (char_u *)NULL, PV_NONE,
2523 {(char_u *)0L, (char_u *)0L}
2524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002526 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2527#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002528 (char_u *)&p_tal, PV_NONE,
2529#else
2530 (char_u *)NULL, PV_NONE,
2531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002533 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2534#ifdef FEAT_WINDOWS
2535 (char_u *)&p_tpm, PV_NONE,
2536#else
2537 (char_u *)NULL, PV_NONE,
2538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2541 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002542 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2544 (char_u *)&p_tbs, PV_NONE,
2545#ifdef VMS /* binary searching doesn't appear to work on VMS */
2546 {(char_u *)0L, (char_u *)0L}
2547#else
2548 {(char_u *)TRUE, (char_u *)0L}
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"taglength", "tl", P_NUM|P_VI_DEF,
2552 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"tagrelative", "tr", P_BOOL|P_VIM,
2555 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002558 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {
2560#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2561 (char_u *)"./tags,./TAGS,tags,TAGS",
2562#else
2563 (char_u *)"./tags,tags",
2564#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2567 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2570 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2573#ifdef FEAT_ARABIC
2574 (char_u *)&p_tbidi, PV_NONE,
2575#else
2576 (char_u *)NULL, PV_NONE,
2577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2580#ifdef FEAT_MBYTE
2581 (char_u *)&p_tenc, PV_NONE,
2582 {(char_u *)"", (char_u *)0L}
2583#else
2584 (char_u *)NULL, PV_NONE,
2585 {(char_u *)0L, (char_u *)0L}
2586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588 {"terse", NULL, P_BOOL|P_VI_DEF,
2589 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {"textauto", "ta", P_BOOL|P_VIM,
2592 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2594 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2596 (char_u *)&p_tx, PV_TX,
2597 {
2598#ifdef USE_CRNL
2599 (char_u *)TRUE,
2600#else
2601 (char_u *)FALSE,
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002604 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002606 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2608#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002609 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610#else
2611 (char_u *)NULL, PV_NONE,
2612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2615 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"timeout", "to", P_BOOL|P_VI_DEF,
2618 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2621 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"title", NULL, P_BOOL|P_VI_DEF,
2624#ifdef FEAT_TITLE
2625 (char_u *)&p_title, PV_NONE,
2626#else
2627 (char_u *)NULL, PV_NONE,
2628#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 {"titlelen", NULL, P_NUM|P_VI_DEF,
2631#ifdef FEAT_TITLE
2632 (char_u *)&p_titlelen, PV_NONE,
2633#else
2634 (char_u *)NULL, PV_NONE,
2635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002637 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638#ifdef FEAT_TITLE
2639 (char_u *)&p_titleold, PV_NONE,
2640 {(char_u *)N_("Thanks for flying Vim"),
2641 (char_u *)0L}
2642#else
2643 (char_u *)NULL, PV_NONE,
2644 {(char_u *)0L, (char_u *)0L}
2645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"titlestring", NULL, P_STRING|P_VI_DEF,
2648#ifdef FEAT_TITLE
2649 (char_u *)&p_titlestring, PV_NONE,
2650#else
2651 (char_u *)NULL, PV_NONE,
2652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2655 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2656 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)"icons,tooltips", (char_u *)0L}
2658 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002660#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2662 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664#endif
2665 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2666 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2669 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2672 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002673 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2675 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2678#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2679 (char_u *)&p_ttym, PV_NONE,
2680#else
2681 (char_u *)NULL, PV_NONE,
2682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2685 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002686 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2688 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002689 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002690 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2691#ifdef FEAT_PERSISTENT_UNDO
2692 (char_u *)&p_udir, PV_NONE,
2693 {(char_u *)".", (char_u *)0L}
2694#else
2695 (char_u *)NULL, PV_NONE,
2696 {(char_u *)0L, (char_u *)0L}
2697#endif
2698 SCRIPTID_INIT},
2699 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2700#ifdef FEAT_PERSISTENT_UNDO
2701 (char_u *)&p_udf, PV_UDF,
2702#else
2703 (char_u *)NULL, PV_NONE,
2704#endif
2705 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002707 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {
2709#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2710 (char_u *)1000L,
2711#else
2712 (char_u *)100L,
2713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002715 {"undoreload", "ur", P_NUM|P_VI_DEF,
2716 (char_u *)&p_ur, PV_NONE,
2717 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"updatecount", "uc", P_NUM|P_VI_DEF,
2719 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"updatetime", "ut", P_NUM|P_VI_DEF,
2722 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"verbose", "vbs", P_NUM|P_VI_DEF,
2725 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002727 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2728 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2731#ifdef FEAT_SESSION
2732 (char_u *)&p_vdir, PV_NONE,
2733 {(char_u *)DFLT_VDIR, (char_u *)0L}
2734#else
2735 (char_u *)NULL, PV_NONE,
2736 {(char_u *)0L, (char_u *)0L}
2737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2740#ifdef FEAT_SESSION
2741 (char_u *)&p_vop, PV_NONE,
2742 {(char_u *)"folds,options,cursor", (char_u *)0L}
2743#else
2744 (char_u *)NULL, PV_NONE,
2745 {(char_u *)0L, (char_u *)0L}
2746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2749#ifdef FEAT_VIMINFO
2750 (char_u *)&p_viminfo, PV_NONE,
2751#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002752 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753#else
2754# ifdef AMIGA
2755 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002756 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002758 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759# endif
2760#endif
2761#else
2762 (char_u *)NULL, PV_NONE,
2763 {(char_u *)0L, (char_u *)0L}
2764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002765 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002766 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767#ifdef FEAT_VIRTUALEDIT
2768 (char_u *)&p_ve, PV_NONE,
2769 {(char_u *)"", (char_u *)""}
2770#else
2771 (char_u *)NULL, PV_NONE,
2772 {(char_u *)0L, (char_u *)0L}
2773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002774 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2776 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"w300", NULL, P_NUM|P_VI_DEF,
2779 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002780 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 {"w1200", NULL, P_NUM|P_VI_DEF,
2782 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"w9600", NULL, P_NUM|P_VI_DEF,
2785 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"warn", NULL, P_BOOL|P_VI_DEF,
2788 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002789 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2791 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002792 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2794 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 {"wildchar", "wc", P_NUM|P_VIM,
2797 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2799 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002800 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2804#ifdef FEAT_WILDIGN
2805 (char_u *)&p_wig, PV_NONE,
2806#else
2807 (char_u *)NULL, PV_NONE,
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002810 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2811 (char_u *)&p_wic, PV_NONE,
2812 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2814#ifdef FEAT_WILDMENU
2815 (char_u *)&p_wmnu, PV_NONE,
2816#else
2817 (char_u *)NULL, PV_NONE,
2818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2821 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002823 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2824#ifdef FEAT_CMDL_COMPL
2825 (char_u *)&p_wop, PV_NONE,
2826 {(char_u *)"", (char_u *)0L}
2827#else
2828 (char_u *)NULL, PV_NONE,
2829 {(char_u *)NULL, (char_u *)0L}
2830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2833#ifdef FEAT_WAK
2834 (char_u *)&p_wak, PV_NONE,
2835 {(char_u *)"menu", (char_u *)0L}
2836#else
2837 (char_u *)NULL, PV_NONE,
2838 {(char_u *)NULL, (char_u *)0L}
2839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002842 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"winheight", "wh", P_NUM|P_VI_DEF,
2845#ifdef FEAT_WINDOWS
2846 (char_u *)&p_wh, PV_NONE,
2847#else
2848 (char_u *)NULL, PV_NONE,
2849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002852#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 (char_u *)VAR_WIN, PV_WFH,
2854#else
2855 (char_u *)NULL, PV_NONE,
2856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002858 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2859#ifdef FEAT_VERTSPLIT
2860 (char_u *)VAR_WIN, PV_WFW,
2861#else
2862 (char_u *)NULL, PV_NONE,
2863#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002864 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2866#ifdef FEAT_WINDOWS
2867 (char_u *)&p_wmh, PV_NONE,
2868#else
2869 (char_u *)NULL, PV_NONE,
2870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002871 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2873#ifdef FEAT_VERTSPLIT
2874 (char_u *)&p_wmw, PV_NONE,
2875#else
2876 (char_u *)NULL, PV_NONE,
2877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2880#ifdef FEAT_VERTSPLIT
2881 (char_u *)&p_wiw, PV_NONE,
2882#else
2883 (char_u *)NULL, PV_NONE,
2884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002885 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2887 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2890 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2893 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002894 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895 {"write", NULL, P_BOOL|P_VI_DEF,
2896 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"writeany", "wa", P_BOOL|P_VI_DEF,
2899 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2902 (char_u *)&p_wb, PV_NONE,
2903 {
2904#ifdef FEAT_WRITEBACKUP
2905 (char_u *)TRUE,
2906#else
2907 (char_u *)FALSE,
2908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002909 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 {"writedelay", "wd", P_NUM|P_VI_DEF,
2911 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002912 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913
2914/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002915#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918
2919 p_term("t_AB", T_CAB)
2920 p_term("t_AF", T_CAF)
2921 p_term("t_AL", T_CAL)
2922 p_term("t_al", T_AL)
2923 p_term("t_bc", T_BC)
2924 p_term("t_cd", T_CD)
2925 p_term("t_ce", T_CE)
2926 p_term("t_cl", T_CL)
2927 p_term("t_cm", T_CM)
2928 p_term("t_Co", T_CCO)
2929 p_term("t_CS", T_CCS)
2930 p_term("t_cs", T_CS)
2931#ifdef FEAT_VERTSPLIT
2932 p_term("t_CV", T_CSV)
2933#endif
2934 p_term("t_ut", T_UT)
2935 p_term("t_da", T_DA)
2936 p_term("t_db", T_DB)
2937 p_term("t_DL", T_CDL)
2938 p_term("t_dl", T_DL)
2939 p_term("t_fs", T_FS)
2940 p_term("t_IE", T_CIE)
2941 p_term("t_IS", T_CIS)
2942 p_term("t_ke", T_KE)
2943 p_term("t_ks", T_KS)
2944 p_term("t_le", T_LE)
2945 p_term("t_mb", T_MB)
2946 p_term("t_md", T_MD)
2947 p_term("t_me", T_ME)
2948 p_term("t_mr", T_MR)
2949 p_term("t_ms", T_MS)
2950 p_term("t_nd", T_ND)
2951 p_term("t_op", T_OP)
2952 p_term("t_RI", T_CRI)
2953 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002954 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 p_term("t_Sb", T_CSB)
2956 p_term("t_Sf", T_CSF)
2957 p_term("t_se", T_SE)
2958 p_term("t_so", T_SO)
2959 p_term("t_sr", T_SR)
2960 p_term("t_ts", T_TS)
2961 p_term("t_te", T_TE)
2962 p_term("t_ti", T_TI)
2963 p_term("t_ue", T_UE)
2964 p_term("t_us", T_US)
2965 p_term("t_vb", T_VB)
2966 p_term("t_ve", T_VE)
2967 p_term("t_vi", T_VI)
2968 p_term("t_vs", T_VS)
2969 p_term("t_WP", T_CWP)
2970 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002971 p_term("t_SI", T_CSI)
2972 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973 p_term("t_xs", T_XS)
2974 p_term("t_ZH", T_CZH)
2975 p_term("t_ZR", T_CZR)
2976
2977/* terminal key codes are not in here */
2978
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002979 /* end marker */
2980 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981};
2982
2983#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2984
2985#ifdef FEAT_MBYTE
2986static char *(p_ambw_values[]) = {"single", "double", NULL};
2987#endif
2988static char *(p_bg_values[]) = {"light", "dark", NULL};
2989static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2990static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002991#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02002992static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002993#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002994#ifdef FEAT_CMDL_COMPL
2995static char *(p_wop_values[]) = {"tagfile", NULL};
2996#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997#ifdef FEAT_WAK
2998static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2999#endif
3000static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3002static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004#ifdef FEAT_BROWSE
3005static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3006#endif
3007#ifdef FEAT_SCROLLBIND
3008static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3009#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003010static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011#ifdef FEAT_VERTSPLIT
3012static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3013#endif
3014#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003015# ifdef FEAT_AUTOCMD
3016static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3017# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003019# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3021#endif
3022static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3023#ifdef FEAT_FOLDING
3024static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003025# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003027# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 NULL};
3029static char *(p_fcl_values[]) = {"all", NULL};
3030#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003031#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003032static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003033#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034
3035static void set_option_default __ARGS((int, int opt_flags, int compatible));
3036static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003037static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003038static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039static char_u *illegal_char __ARGS((char_u *, int));
3040static int string_to_key __ARGS((char_u *arg));
3041#ifdef FEAT_CMDWIN
3042static char_u *check_cedit __ARGS((void));
3043#endif
3044#ifdef FEAT_TITLE
3045static void did_set_title __ARGS((int icon));
3046#endif
3047static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3048static void didset_options __ARGS((void));
3049static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003050#if defined(FEAT_EVAL) || defined(PROTO)
3051static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3052#else
3053# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3054#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003056static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057static 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));
3058static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003059#ifdef FEAT_SYN_HL
3060static int int_cmp __ARGS((const void *a, const void *b));
3061#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062#ifdef FEAT_CLIPBOARD
3063static char_u *check_clipboard_option __ARGS((void));
3064#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003065#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003066static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003067#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003068#ifdef FEAT_EVAL
3069static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3070#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003072static 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 +00003073static void check_redraw __ARGS((long_u flags));
3074static int findoption __ARGS((char_u *));
3075static int find_key_option __ARGS((char_u *));
3076static void showoptions __ARGS((int all, int opt_flags));
3077static int optval_default __ARGS((struct vimoption *, char_u *varp));
3078static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3079static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3080static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3081static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3082static int istermoption __ARGS((struct vimoption *));
3083static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3084static char_u *get_varp __ARGS((struct vimoption *));
3085static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003086static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3088#ifdef FEAT_LANGMAP
3089static void langmap_init __ARGS((void));
3090static void langmap_set __ARGS((void));
3091#endif
3092static void paste_option_changed __ARGS((void));
3093static void compatible_set __ARGS((void));
3094#ifdef FEAT_LINEBREAK
3095static void fill_breakat_flags __ARGS((void));
3096#endif
3097static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3098static int check_opt_strings __ARGS((char_u *val, char **values, int));
3099static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003100#ifdef FEAT_LINEBREAK
3101static int briopt_check __ARGS((win_T *wp));
3102#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103
3104/*
3105 * Initialize the options, first part.
3106 *
3107 * Called only once from main(), just after creating the first buffer.
3108 */
3109 void
3110set_init_1()
3111{
3112 char_u *p;
3113 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003114 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115
3116#ifdef FEAT_LANGMAP
3117 langmap_init();
3118#endif
3119
3120 /* Be Vi compatible by default */
3121 p_cp = TRUE;
3122
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003123 /* Use POSIX compatibility when $VIM_POSIX is set. */
3124 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003125 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003126 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003127 set_string_default("shm", (char_u *)"A");
3128 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003129
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 /*
3131 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003132 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003134 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3136# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003137 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003139 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003141 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142# endif
3143#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003144 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 set_string_default("sh", p);
3146
3147#ifdef FEAT_WILDIGN
3148 /*
3149 * Set the default for 'backupskip' to include environment variables for
3150 * temp files.
3151 */
3152 {
3153# ifdef UNIX
3154 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3155# else
3156 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3157# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003158 int len;
3159 garray_T ga;
3160 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161
3162 ga_init2(&ga, 1, 100);
3163 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3164 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003165 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166# ifdef UNIX
3167 if (*names[n] == NUL)
3168 p = (char_u *)"/tmp";
3169 else
3170# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003171 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 if (p != NULL && *p != NUL)
3173 {
3174 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003175 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 if (ga_grow(&ga, len) == OK)
3177 {
3178 if (ga.ga_len > 0)
3179 STRCAT(ga.ga_data, ",");
3180 STRCAT(ga.ga_data, p);
3181 add_pathsep(ga.ga_data);
3182 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 ga.ga_len += len;
3184 }
3185 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003186 if (mustfree)
3187 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188 }
3189 if (ga.ga_data != NULL)
3190 {
3191 set_string_default("bsk", ga.ga_data);
3192 vim_free(ga.ga_data);
3193 }
3194 }
3195#endif
3196
3197 /*
3198 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3199 */
3200 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003201 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003203#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3204 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3205#endif
3206 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003208 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003209 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210#else
3211# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003212 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003213 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003214# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003215 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216# endif
3217#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003219 opt_idx = findoption((char_u *)"maxmem");
3220 if (opt_idx >= 0)
3221 {
3222#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003223 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003224 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3225#endif
3226 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3227 }
3228 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003229 }
3230
3231#ifdef FEAT_GUI_W32
3232 /* force 'shortname' for Win32s */
3233 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003234 {
3235 opt_idx = findoption((char_u *)"shortname");
3236 if (opt_idx >= 0)
3237 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3238 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239#endif
3240
3241#ifdef FEAT_SEARCHPATH
3242 {
3243 char_u *cdpath;
3244 char_u *buf;
3245 int i;
3246 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003247 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248
3249 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003250 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251 if (cdpath != NULL)
3252 {
3253 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3254 if (buf != NULL)
3255 {
3256 buf[0] = ','; /* start with ",", current dir first */
3257 j = 1;
3258 for (i = 0; cdpath[i] != NUL; ++i)
3259 {
3260 if (vim_ispathlistsep(cdpath[i]))
3261 buf[j++] = ',';
3262 else
3263 {
3264 if (cdpath[i] == ' ' || cdpath[i] == ',')
3265 buf[j++] = '\\';
3266 buf[j++] = cdpath[i];
3267 }
3268 }
3269 buf[j] = NUL;
3270 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003271 if (opt_idx >= 0)
3272 {
3273 options[opt_idx].def_val[VI_DEFAULT] = buf;
3274 options[opt_idx].flags |= P_DEF_ALLOCED;
3275 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003276 else
3277 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003279 if (mustfree)
3280 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281 }
3282 }
3283#endif
3284
3285#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3286 /* Set print encoding on platforms that don't default to latin1 */
3287 set_string_default("penc",
3288# if defined(MSWIN) || defined(OS2)
3289 (char_u *)"cp1252"
3290# else
3291# ifdef VMS
3292 (char_u *)"dec-mcs"
3293# else
3294# ifdef EBCDIC
3295 (char_u *)"ebcdic-uk"
3296# else
3297# ifdef MAC
3298 (char_u *)"mac-roman"
3299# else /* HPUX */
3300 (char_u *)"hp-roman8"
3301# endif
3302# endif
3303# endif
3304# endif
3305 );
3306#endif
3307
3308#ifdef FEAT_POSTSCRIPT
3309 /* 'printexpr' must be allocated to be able to evaluate it. */
3310 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003311# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3312 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313# else
3314# ifdef VMS
3315 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3316
3317# else
3318 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3319# endif
3320# endif
3321 );
3322#endif
3323
3324 /*
3325 * Set all the options (except the terminal options) to their default
3326 * value. Also set the global value for local options.
3327 */
3328 set_options_default(0);
3329
3330#ifdef FEAT_GUI
3331 if (found_reverse_arg)
3332 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3333#endif
3334
3335 curbuf->b_p_initialized = TRUE;
3336 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003337 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338 check_buf_options(curbuf);
3339 check_win_options(curwin);
3340 check_options();
3341
3342 /* Must be before option_expand(), because that one needs vim_isIDc() */
3343 didset_options();
3344
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003345#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003346 /* Use the current chartab for the generic chartab. */
3347 init_spell_chartab();
3348#endif
3349
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350#ifdef FEAT_LINEBREAK
3351 /*
3352 * initialize the table for 'breakat'.
3353 */
3354 fill_breakat_flags();
3355#endif
3356
3357 /*
3358 * Expand environment variables and things like "~" for the defaults.
3359 * If option_expand() returns non-NULL the variable is expanded. This can
3360 * only happen for non-indirect options.
3361 * Also set the default to the expanded value, so ":set" does not list
3362 * them.
3363 * Don't set the P_ALLOCED flag, because we don't want to free the
3364 * default.
3365 */
3366 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3367 {
3368 if ((options[opt_idx].flags & P_GETTEXT)
3369 && options[opt_idx].var != NULL)
3370 p = (char_u *)_(*(char **)options[opt_idx].var);
3371 else
3372 p = option_expand(opt_idx, NULL);
3373 if (p != NULL && (p = vim_strsave(p)) != NULL)
3374 {
3375 *(char_u **)options[opt_idx].var = p;
3376 /* VIMEXP
3377 * Defaults for all expanded options are currently the same for Vi
3378 * and Vim. When this changes, add some code here! Also need to
3379 * split P_DEF_ALLOCED in two.
3380 */
3381 if (options[opt_idx].flags & P_DEF_ALLOCED)
3382 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3383 options[opt_idx].def_val[VI_DEFAULT] = p;
3384 options[opt_idx].flags |= P_DEF_ALLOCED;
3385 }
3386 }
3387
3388 /* Initialize the highlight_attr[] table. */
3389 highlight_changed();
3390
3391 save_file_ff(curbuf); /* Buffer is unchanged */
3392
3393 /* Parse default for 'wildmode' */
3394 check_opt_wim();
3395
3396#if defined(FEAT_ARABIC)
3397 /* Detect use of mlterm.
3398 * Mlterm is a terminal emulator akin to xterm that has some special
3399 * abilities (bidi namely).
3400 * NOTE: mlterm's author is being asked to 'set' a variable
3401 * instead of an environment variable due to inheritance.
3402 */
3403 if (mch_getenv((char_u *)"MLTERM") != NULL)
3404 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3405#endif
3406
3407#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3408 /* Parse default for 'fillchars'. */
3409 (void)set_chars_option(&p_fcs);
3410#endif
3411
3412#ifdef FEAT_CLIPBOARD
3413 /* Parse default for 'clipboard' */
3414 (void)check_clipboard_option();
3415#endif
3416
3417#ifdef FEAT_MBYTE
3418# if defined(WIN3264) && defined(FEAT_GETTEXT)
3419 /*
3420 * If $LANG isn't set, try to get a good value for it. This makes the
3421 * right language be used automatically. Don't do this for English.
3422 */
3423 if (mch_getenv((char_u *)"LANG") == NULL)
3424 {
3425 char buf[20];
3426
3427 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3428 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3429 * only the first two. */
3430 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3431 (LPTSTR)buf, 20);
3432 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3433 {
3434 /* There are a few exceptions (probably more) */
3435 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3436 STRCPY(buf, "zh_TW");
3437 else if (STRNICMP(buf, "chs", 3) == 0
3438 || STRNICMP(buf, "zhc", 3) == 0)
3439 STRCPY(buf, "zh_CN");
3440 else if (STRNICMP(buf, "jp", 2) == 0)
3441 STRCPY(buf, "ja");
3442 else
3443 buf[2] = NUL; /* truncate to two-letter code */
3444 vim_setenv("LANG", buf);
3445 }
3446 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003447# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003448# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003449 /* Moved to os_mac_conv.c to avoid dependency problems. */
3450 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003451# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452# endif
3453
3454 /* enc_locale() will try to find the encoding of the current locale. */
3455 p = enc_locale();
3456 if (p != NULL)
3457 {
3458 char_u *save_enc;
3459
3460 /* Try setting 'encoding' and check if the value is valid.
3461 * If not, go back to the default "latin1". */
3462 save_enc = p_enc;
3463 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003464 if (STRCMP(p_enc, "gb18030") == 0)
3465 {
3466 /* We don't support "gb18030", but "cp936" is a good substitute
3467 * for practical purposes, thus use that. It's not an alias to
3468 * still support conversion between gb18030 and utf-8. */
3469 p_enc = vim_strsave((char_u *)"cp936");
3470 vim_free(p);
3471 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472 if (mb_init() == NULL)
3473 {
3474 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003475 if (opt_idx >= 0)
3476 {
3477 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3478 options[opt_idx].flags |= P_DEF_ALLOCED;
3479 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003481#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3482 || defined(VMS)
3483 if (STRCMP(p_enc, "latin1") == 0
3484# ifdef FEAT_MBYTE
3485 || enc_utf8
3486# endif
3487 )
3488 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003489 /* Adjust the default for 'isprint' and 'iskeyword' to match
3490 * latin1. Also set the defaults for when 'nocompatible' is
3491 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003492 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003493 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003494 set_string_option_direct((char_u *)"isk", -1,
3495 ISK_LATIN1, OPT_FREE, SID_NONE);
3496 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003497 if (opt_idx >= 0)
3498 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003499 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003500 if (opt_idx >= 0)
3501 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003502 (void)init_chartab();
3503 }
3504#endif
3505
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506# if defined(WIN3264) && !defined(FEAT_GUI)
3507 /* Win32 console: When GetACP() returns a different value from
3508 * GetConsoleCP() set 'termencoding'. */
3509 if (GetACP() != GetConsoleCP())
3510 {
3511 char buf[50];
3512
3513 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3514 p_tenc = vim_strsave((char_u *)buf);
3515 if (p_tenc != NULL)
3516 {
3517 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003518 if (opt_idx >= 0)
3519 {
3520 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3521 options[opt_idx].flags |= P_DEF_ALLOCED;
3522 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003523 convert_setup(&input_conv, p_tenc, p_enc);
3524 convert_setup(&output_conv, p_enc, p_tenc);
3525 }
3526 else
3527 p_tenc = empty_option;
3528 }
3529# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003530# if defined(WIN3264) && defined(FEAT_MBYTE)
3531 /* $HOME may have characters in active code page. */
3532 init_homedir();
3533# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003534 }
3535 else
3536 {
3537 vim_free(p_enc);
3538 p_enc = save_enc;
3539 }
3540 }
3541#endif
3542
3543#ifdef FEAT_MULTI_LANG
3544 /* Set the default for 'helplang'. */
3545 set_helplang_default(get_mess_lang());
3546#endif
3547}
3548
3549/*
3550 * Set an option to its default value.
3551 * This does not take care of side effects!
3552 */
3553 static void
3554set_option_default(opt_idx, opt_flags, compatible)
3555 int opt_idx;
3556 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3557 int compatible; /* use Vi default value */
3558{
3559 char_u *varp; /* pointer to variable for current option */
3560 int dvi; /* index in def_val[] */
3561 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003562 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003563 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3564
3565 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3566 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003567 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003568 {
3569 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3570 if (flags & P_STRING)
3571 {
3572 /* Use set_string_option_direct() for local options to handle
3573 * freeing and allocating the value. */
3574 if (options[opt_idx].indir != PV_NONE)
3575 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003576 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003577 else
3578 {
3579 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3580 free_string_option(*(char_u **)(varp));
3581 *(char_u **)varp = options[opt_idx].def_val[dvi];
3582 options[opt_idx].flags &= ~P_ALLOCED;
3583 }
3584 }
3585 else if (flags & P_NUM)
3586 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003587 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588 win_comp_scroll(curwin);
3589 else
3590 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003591 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592 /* May also set global value for local option. */
3593 if (both)
3594 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3595 *(long *)varp;
3596 }
3597 }
3598 else /* P_BOOL */
3599 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003600 /* the cast to long is required for Manx C, long_i is needed for
3601 * MSVC */
3602 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003603#ifdef UNIX
3604 /* 'modeline' defaults to off for root */
3605 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3606 *(int *)varp = FALSE;
3607#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608 /* May also set global value for local option. */
3609 if (both)
3610 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3611 *(int *)varp;
3612 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003613
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003614 /* The default value is not insecure. */
3615 flagsp = insecure_flag(opt_idx, opt_flags);
3616 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003617 }
3618
3619#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003620 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003621#endif
3622}
3623
3624/*
3625 * Set all options (except terminal options) to their default value.
3626 */
3627 static void
3628set_options_default(opt_flags)
3629 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3630{
3631 int i;
3632#ifdef FEAT_WINDOWS
3633 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003634 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003635#endif
3636
3637 for (i = 0; !istermoption(&options[i]); i++)
3638 if (!(options[i].flags & P_NODEFAULT))
3639 set_option_default(i, opt_flags, p_cp);
3640
3641#ifdef FEAT_WINDOWS
3642 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003643 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003644 win_comp_scroll(wp);
3645#else
3646 win_comp_scroll(curwin);
3647#endif
3648}
3649
3650/*
3651 * Set the Vi-default value of a string option.
3652 * Used for 'sh', 'backupskip' and 'term'.
3653 */
3654 void
3655set_string_default(name, val)
3656 char *name;
3657 char_u *val;
3658{
3659 char_u *p;
3660 int opt_idx;
3661
3662 p = vim_strsave(val);
3663 if (p != NULL) /* we don't want a NULL */
3664 {
3665 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003666 if (opt_idx >= 0)
3667 {
3668 if (options[opt_idx].flags & P_DEF_ALLOCED)
3669 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3670 options[opt_idx].def_val[VI_DEFAULT] = p;
3671 options[opt_idx].flags |= P_DEF_ALLOCED;
3672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003673 }
3674}
3675
3676/*
3677 * Set the Vi-default value of a number option.
3678 * Used for 'lines' and 'columns'.
3679 */
3680 void
3681set_number_default(name, val)
3682 char *name;
3683 long val;
3684{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003685 int opt_idx;
3686
3687 opt_idx = findoption((char_u *)name);
3688 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003689 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003690}
3691
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003692#if defined(EXITFREE) || defined(PROTO)
3693/*
3694 * Free all options.
3695 */
3696 void
3697free_all_options()
3698{
3699 int i;
3700
3701 for (i = 0; !istermoption(&options[i]); i++)
3702 {
3703 if (options[i].indir == PV_NONE)
3704 {
3705 /* global option: free value and default value. */
3706 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3707 free_string_option(*(char_u **)options[i].var);
3708 if (options[i].flags & P_DEF_ALLOCED)
3709 free_string_option(options[i].def_val[VI_DEFAULT]);
3710 }
3711 else if (options[i].var != VAR_WIN
3712 && (options[i].flags & P_STRING))
3713 /* buffer-local option: free global value */
3714 free_string_option(*(char_u **)options[i].var);
3715 }
3716}
3717#endif
3718
3719
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720/*
3721 * Initialize the options, part two: After getting Rows and Columns and
3722 * setting 'term'.
3723 */
3724 void
3725set_init_2()
3726{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003727 int idx;
3728
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729 /*
3730 * 'scroll' defaults to half the window height. Note that this default is
3731 * wrong when the window height changes.
3732 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003733 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003734 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003735 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003736 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737 comp_col();
3738
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003739 /*
3740 * 'window' is only for backwards compatibility with Vi.
3741 * Default is Rows - 1.
3742 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003743 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003744 p_window = Rows - 1;
3745 set_number_default("window", Rows - 1);
3746
Bram Moolenaarf740b292006-02-16 22:11:02 +00003747 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003749 /*
3750 * If 'background' wasn't set by the user, try guessing the value,
3751 * depending on the terminal name. Only need to check for terminals
3752 * with a dark background, that can handle color.
3753 */
3754 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003755 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3756 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003757 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003758 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003759 /* don't mark it as set, when starting the GUI it may be
3760 * changed again */
3761 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 }
3763#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003764
3765#ifdef CURSOR_SHAPE
3766 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3767#endif
3768#ifdef FEAT_MOUSESHAPE
3769 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3770#endif
3771#ifdef FEAT_PRINTER
3772 (void)parse_printoptions(); /* parse 'printoptions' default value */
3773#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003774}
3775
3776/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003777 * Return "dark" or "light" depending on the kind of terminal.
3778 * This is just guessing! Recognized are:
3779 * "linux" Linux console
3780 * "screen.linux" Linux console with screen
3781 * "cygwin" Cygwin shell
3782 * "putty" Putty program
3783 * We also check the COLORFGBG environment variable, which is set by
3784 * rxvt and derivatives. This variable contains either two or three
3785 * values separated by semicolons; we want the last value in either
3786 * case. If this value is 0-6 or 8, our background is dark.
3787 */
3788 static char_u *
3789term_bg_default()
3790{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003791#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3792 /* DOS console nearly always black */
3793 return (char_u *)"dark";
3794#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003795 char_u *p;
3796
Bram Moolenaarf740b292006-02-16 22:11:02 +00003797 if (STRCMP(T_NAME, "linux") == 0
3798 || STRCMP(T_NAME, "screen.linux") == 0
3799 || STRCMP(T_NAME, "cygwin") == 0
3800 || STRCMP(T_NAME, "putty") == 0
3801 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3802 && (p = vim_strrchr(p, ';')) != NULL
3803 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3804 && p[2] == NUL))
3805 return (char_u *)"dark";
3806 return (char_u *)"light";
3807#endif
3808}
3809
3810/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811 * Initialize the options, part three: After reading the .vimrc
3812 */
3813 void
3814set_init_3()
3815{
3816#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3817/*
3818 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3819 * This is done after other initializations, where 'shell' might have been
3820 * set, but only if they have not been set before.
3821 */
3822 char_u *p;
3823 int idx_srr;
3824 int do_srr;
3825#ifdef FEAT_QUICKFIX
3826 int idx_sp;
3827 int do_sp;
3828#endif
3829
3830 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003831 if (idx_srr < 0)
3832 do_srr = FALSE;
3833 else
3834 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835#ifdef FEAT_QUICKFIX
3836 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003837 if (idx_sp < 0)
3838 do_sp = FALSE;
3839 else
3840 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003842 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843 if (p != NULL)
3844 {
3845 /*
3846 * Default for p_sp is "| tee", for p_srr is ">".
3847 * For known shells it is changed here to include stderr.
3848 */
3849 if ( fnamecmp(p, "csh") == 0
3850 || fnamecmp(p, "tcsh") == 0
3851# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3852 || fnamecmp(p, "csh.exe") == 0
3853 || fnamecmp(p, "tcsh.exe") == 0
3854# endif
3855 )
3856 {
3857#if defined(FEAT_QUICKFIX)
3858 if (do_sp)
3859 {
3860# ifdef WIN3264
3861 p_sp = (char_u *)">&";
3862# else
3863 p_sp = (char_u *)"|& tee";
3864# endif
3865 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3866 }
3867#endif
3868 if (do_srr)
3869 {
3870 p_srr = (char_u *)">&";
3871 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3872 }
3873 }
3874 else
3875# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3876 if ( fnamecmp(p, "sh") == 0
3877 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003878 || fnamecmp(p, "mksh") == 0
3879 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003881 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003882 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003883 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884# ifdef WIN3264
3885 || fnamecmp(p, "cmd") == 0
3886 || fnamecmp(p, "sh.exe") == 0
3887 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003888 || fnamecmp(p, "mksh.exe") == 0
3889 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003891 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892 || fnamecmp(p, "bash.exe") == 0
3893 || fnamecmp(p, "cmd.exe") == 0
3894# endif
3895 )
3896# endif
3897 {
3898#if defined(FEAT_QUICKFIX)
3899 if (do_sp)
3900 {
3901# ifdef WIN3264
3902 p_sp = (char_u *)">%s 2>&1";
3903# else
3904 p_sp = (char_u *)"2>&1| tee";
3905# endif
3906 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3907 }
3908#endif
3909 if (do_srr)
3910 {
3911 p_srr = (char_u *)">%s 2>&1";
3912 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3913 }
3914 }
3915 vim_free(p);
3916 }
3917#endif
3918
3919#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3920 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003921 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3922 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 * This is done after other initializations, where 'shell' might have been
3924 * set, but only if they have not been set before. Default for p_shcf is
3925 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3926 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3927 * command.com. And for Win32 we need to set p_sxq instead.
3928 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003929 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930 {
3931 int idx3;
3932
3933 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003934 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 {
3936 p_shcf = (char_u *)"-c";
3937 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3938 }
3939
3940# ifndef DJGPP
3941# ifdef WIN3264
3942 /* Somehow Win32 requires the quotes around the redirection too */
3943 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003944 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945 {
3946 p_sxq = (char_u *)"\"";
3947 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3948 }
3949# else
3950 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003951 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 {
3953 p_shq = (char_u *)"\"";
3954 options[idx3].def_val[VI_DEFAULT] = p_shq;
3955 }
3956# endif
3957# endif
3958 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003959 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3960 {
3961 int idx3;
3962
3963 /*
3964 * cmd.exe on Windows will strip the first and last double quote given
3965 * on the command line, e.g. most of the time things like:
3966 * cmd /c "my path/to/echo" "my args to echo"
3967 * become:
3968 * my path/to/echo" "my args to echo
3969 * when executed.
3970 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003971 * To avoid this, set shellxquote to surround the command in
3972 * parenthesis. This appears to make most commands work, without
3973 * breaking commands that worked previously, such as
3974 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003975 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003976 idx3 = findoption((char_u *)"sxq");
3977 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3978 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003979 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003980 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3981 }
3982
Bram Moolenaara64ba222012-02-12 23:23:31 +01003983 idx3 = findoption((char_u *)"shcf");
3984 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3985 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003986 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003987 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3988 }
3989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990#endif
3991
3992#ifdef FEAT_TITLE
3993 set_title_defaults();
3994#endif
3995}
3996
3997#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3998/*
3999 * When 'helplang' is still at its default value, set it to "lang".
4000 * Only the first two characters of "lang" are used.
4001 */
4002 void
4003set_helplang_default(lang)
4004 char_u *lang;
4005{
4006 int idx;
4007
4008 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4009 return;
4010 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004011 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012 {
4013 if (options[idx].flags & P_ALLOCED)
4014 free_string_option(p_hlg);
4015 p_hlg = vim_strsave(lang);
4016 if (p_hlg == NULL)
4017 p_hlg = empty_option;
4018 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004019 {
4020 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4021 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4022 {
4023 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4024 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4025 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004026 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004027 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028 options[idx].flags |= P_ALLOCED;
4029 }
4030}
4031#endif
4032
4033#ifdef FEAT_GUI
4034static char_u *gui_bg_default __ARGS((void));
4035
4036 static char_u *
4037gui_bg_default()
4038{
4039 if (gui_get_lightness(gui.back_pixel) < 127)
4040 return (char_u *)"dark";
4041 return (char_u *)"light";
4042}
4043
4044/*
4045 * Option initializations that can only be done after opening the GUI window.
4046 */
4047 void
4048init_gui_options()
4049{
4050 /* Set the 'background' option according to the lightness of the
4051 * background color, unless the user has set it already. */
4052 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4053 {
4054 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4055 highlight_changed();
4056 }
4057}
4058#endif
4059
4060#ifdef FEAT_TITLE
4061/*
4062 * 'title' and 'icon' only default to true if they have not been set or reset
4063 * in .vimrc and we can read the old value.
4064 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4065 * they can be reset. This reduces startup time when using X on a remote
4066 * machine.
4067 */
4068 void
4069set_title_defaults()
4070{
4071 int idx1;
4072 long val;
4073
4074 /*
4075 * If GUI is (going to be) used, we can always set the window title and
4076 * icon name. Saves a bit of time, because the X11 display server does
4077 * not need to be contacted.
4078 */
4079 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004080 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 {
4082#ifdef FEAT_GUI
4083 if (gui.starting || gui.in_use)
4084 val = TRUE;
4085 else
4086#endif
4087 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004088 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 p_title = val;
4090 }
4091 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004092 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 {
4094#ifdef FEAT_GUI
4095 if (gui.starting || gui.in_use)
4096 val = TRUE;
4097 else
4098#endif
4099 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004100 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 p_icon = val;
4102 }
4103}
4104#endif
4105
4106/*
4107 * Parse 'arg' for option settings.
4108 *
4109 * 'arg' may be IObuff, but only when no errors can be present and option
4110 * does not need to be expanded with option_expand().
4111 * "opt_flags":
4112 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004113 * OPT_GLOBAL for ":setglobal"
4114 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004116 * OPT_WINONLY to only set window-local options
4117 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 *
4119 * returns FAIL if an error is detected, OK otherwise
4120 */
4121 int
4122do_set(arg, opt_flags)
4123 char_u *arg; /* option string (may be written to!) */
4124 int opt_flags;
4125{
4126 int opt_idx;
4127 char_u *errmsg;
4128 char_u errbuf[80];
4129 char_u *startarg;
4130 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4131 int nextchar; /* next non-white char after option name */
4132 int afterchar; /* character just after option name */
4133 int len;
4134 int i;
4135 long value;
4136 int key;
4137 long_u flags; /* flags for current option */
4138 char_u *varp = NULL; /* pointer to variable for current option */
4139 int did_show = FALSE; /* already showed one value */
4140 int adding; /* "opt+=arg" */
4141 int prepending; /* "opt^=arg" */
4142 int removing; /* "opt-=arg" */
4143 int cp_val = 0;
4144 char_u key_name[2];
4145
4146 if (*arg == NUL)
4147 {
4148 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004149 did_show = TRUE;
4150 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 }
4152
4153 while (*arg != NUL) /* loop to process all options */
4154 {
4155 errmsg = NULL;
4156 startarg = arg; /* remember for error message */
4157
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004158 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4159 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 {
4161 /*
4162 * ":set all" show all options.
4163 * ":set all&" set all options to their default value.
4164 */
4165 arg += 3;
4166 if (*arg == '&')
4167 {
4168 ++arg;
4169 /* Only for :set command set global value of local options. */
4170 set_options_default(OPT_FREE | opt_flags);
4171 }
4172 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004173 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004175 did_show = TRUE;
4176 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004178 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 {
4180 showoptions(2, opt_flags);
4181 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004182 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 arg += 7;
4184 }
4185 else
4186 {
4187 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004188 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004189 {
4190 prefix = 0;
4191 arg += 2;
4192 }
4193 else if (STRNCMP(arg, "inv", 3) == 0)
4194 {
4195 prefix = 2;
4196 arg += 3;
4197 }
4198
4199 /* find end of name */
4200 key = 0;
4201 if (*arg == '<')
4202 {
4203 nextchar = 0;
4204 opt_idx = -1;
4205 /* look out for <t_>;> */
4206 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4207 len = 5;
4208 else
4209 {
4210 len = 1;
4211 while (arg[len] != NUL && arg[len] != '>')
4212 ++len;
4213 }
4214 if (arg[len] != '>')
4215 {
4216 errmsg = e_invarg;
4217 goto skip;
4218 }
4219 arg[len] = NUL; /* put NUL after name */
4220 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4221 opt_idx = findoption(arg + 1);
4222 arg[len++] = '>'; /* restore '>' */
4223 if (opt_idx == -1)
4224 key = find_key_option(arg + 1);
4225 }
4226 else
4227 {
4228 len = 0;
4229 /*
4230 * The two characters after "t_" may not be alphanumeric.
4231 */
4232 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4233 len = 4;
4234 else
4235 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4236 ++len;
4237 nextchar = arg[len];
4238 arg[len] = NUL; /* put NUL after name */
4239 opt_idx = findoption(arg);
4240 arg[len] = nextchar; /* restore nextchar */
4241 if (opt_idx == -1)
4242 key = find_key_option(arg);
4243 }
4244
4245 /* remember character after option name */
4246 afterchar = arg[len];
4247
4248 /* skip white space, allow ":set ai ?" */
4249 while (vim_iswhite(arg[len]))
4250 ++len;
4251
4252 adding = FALSE;
4253 prepending = FALSE;
4254 removing = FALSE;
4255 if (arg[len] != NUL && arg[len + 1] == '=')
4256 {
4257 if (arg[len] == '+')
4258 {
4259 adding = TRUE; /* "+=" */
4260 ++len;
4261 }
4262 else if (arg[len] == '^')
4263 {
4264 prepending = TRUE; /* "^=" */
4265 ++len;
4266 }
4267 else if (arg[len] == '-')
4268 {
4269 removing = TRUE; /* "-=" */
4270 ++len;
4271 }
4272 }
4273 nextchar = arg[len];
4274
4275 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4276 {
4277 errmsg = (char_u *)N_("E518: Unknown option");
4278 goto skip;
4279 }
4280
4281 if (opt_idx >= 0)
4282 {
4283 if (options[opt_idx].var == NULL) /* hidden option: skip */
4284 {
4285 /* Only give an error message when requesting the value of
4286 * a hidden option, ignore setting it. */
4287 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4288 && (!(options[opt_idx].flags & P_BOOL)
4289 || nextchar == '?'))
4290 errmsg = (char_u *)N_("E519: Option not supported");
4291 goto skip;
4292 }
4293
4294 flags = options[opt_idx].flags;
4295 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4296 }
4297 else
4298 {
4299 flags = P_STRING;
4300 if (key < 0)
4301 {
4302 key_name[0] = KEY2TERMCAP0(key);
4303 key_name[1] = KEY2TERMCAP1(key);
4304 }
4305 else
4306 {
4307 key_name[0] = KS_KEY;
4308 key_name[1] = (key & 0xff);
4309 }
4310 }
4311
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004312 /* Skip all options that are not window-local (used when showing
4313 * an already loaded buffer in a window). */
4314 if ((opt_flags & OPT_WINONLY)
4315 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4316 goto skip;
4317
Bram Moolenaara3227e22006-03-08 21:32:40 +00004318 /* Skip all options that are window-local (used for :vimgrep). */
4319 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4320 && options[opt_idx].var == VAR_WIN)
4321 goto skip;
4322
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004323 /* Disallow changing some options from modelines. */
4324 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004326 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004327 {
4328 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4329 goto skip;
4330 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004331#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004332 /* In diff mode some options are overruled. This avoids that
4333 * 'foldmethod' becomes "marker" instead of "diff" and that
4334 * "wrap" gets set. */
4335 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004336 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004337 && (options[opt_idx].indir == PV_FDM
4338 || options[opt_idx].indir == PV_WRAP))
4339 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004341 }
4342
4343#ifdef HAVE_SANDBOX
4344 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004345 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004346 {
4347 errmsg = (char_u *)_(e_sandbox);
4348 goto skip;
4349 }
4350#endif
4351
4352 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4353 {
4354 arg += len;
4355 cp_val = p_cp;
4356 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4357 {
4358 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4359 {
4360 cp_val = FALSE;
4361 arg += 3;
4362 }
4363 else /* "opt&vi": set to Vi default */
4364 {
4365 cp_val = TRUE;
4366 arg += 2;
4367 }
4368 }
4369 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4370 && arg[1] != NUL && !vim_iswhite(arg[1]))
4371 {
4372 errmsg = e_trailing;
4373 goto skip;
4374 }
4375 }
4376
4377 /*
4378 * allow '=' and ':' as MSDOS command.com allows only one
4379 * '=' character per "set" command line. grrr. (jw)
4380 */
4381 if (nextchar == '?'
4382 || (prefix == 1
4383 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4384 && !(flags & P_BOOL)))
4385 {
4386 /*
4387 * print value
4388 */
4389 if (did_show)
4390 msg_putchar('\n'); /* cursor below last one */
4391 else
4392 {
4393 gotocmdline(TRUE); /* cursor at status line */
4394 did_show = TRUE; /* remember that we did a line */
4395 }
4396 if (opt_idx >= 0)
4397 {
4398 showoneopt(&options[opt_idx], opt_flags);
4399#ifdef FEAT_EVAL
4400 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004401 {
4402 /* Mention where the option was last set. */
4403 if (varp == options[opt_idx].var)
4404 last_set_msg(options[opt_idx].scriptID);
4405 else if ((int)options[opt_idx].indir & PV_WIN)
4406 last_set_msg(curwin->w_p_scriptID[
4407 (int)options[opt_idx].indir & PV_MASK]);
4408 else if ((int)options[opt_idx].indir & PV_BUF)
4409 last_set_msg(curbuf->b_p_scriptID[
4410 (int)options[opt_idx].indir & PV_MASK]);
4411 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004412#endif
4413 }
4414 else
4415 {
4416 char_u *p;
4417
4418 p = find_termcode(key_name);
4419 if (p == NULL)
4420 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004421 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004422 goto skip;
4423 }
4424 else
4425 (void)show_one_termcode(key_name, p, TRUE);
4426 }
4427 if (nextchar != '?'
4428 && nextchar != NUL && !vim_iswhite(afterchar))
4429 errmsg = e_trailing;
4430 }
4431 else
4432 {
4433 if (flags & P_BOOL) /* boolean */
4434 {
4435 if (nextchar == '=' || nextchar == ':')
4436 {
4437 errmsg = e_invarg;
4438 goto skip;
4439 }
4440
4441 /*
4442 * ":set opt!": invert
4443 * ":set opt&": reset to default value
4444 * ":set opt<": reset to global value
4445 */
4446 if (nextchar == '!')
4447 value = *(int *)(varp) ^ 1;
4448 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004449 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004450 ((flags & P_VI_DEF) || cp_val)
4451 ? VI_DEFAULT : VIM_DEFAULT];
4452 else if (nextchar == '<')
4453 {
4454 /* For 'autoread' -1 means to use global value. */
4455 if ((int *)varp == &curbuf->b_p_ar
4456 && opt_flags == OPT_LOCAL)
4457 value = -1;
4458 else
4459 value = *(int *)get_varp_scope(&(options[opt_idx]),
4460 OPT_GLOBAL);
4461 }
4462 else
4463 {
4464 /*
4465 * ":set invopt": invert
4466 * ":set opt" or ":set noopt": set or reset
4467 */
4468 if (nextchar != NUL && !vim_iswhite(afterchar))
4469 {
4470 errmsg = e_trailing;
4471 goto skip;
4472 }
4473 if (prefix == 2) /* inv */
4474 value = *(int *)(varp) ^ 1;
4475 else
4476 value = prefix;
4477 }
4478
4479 errmsg = set_bool_option(opt_idx, varp, (int)value,
4480 opt_flags);
4481 }
4482 else /* numeric or string */
4483 {
4484 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4485 || prefix != 1)
4486 {
4487 errmsg = e_invarg;
4488 goto skip;
4489 }
4490
4491 if (flags & P_NUM) /* numeric */
4492 {
4493 /*
4494 * Different ways to set a number option:
4495 * & set to default value
4496 * < set to global value
4497 * <xx> accept special key codes for 'wildchar'
4498 * c accept any non-digit for 'wildchar'
4499 * [-]0-9 set number
4500 * other error
4501 */
4502 ++arg;
4503 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004504 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004505 ((flags & P_VI_DEF) || cp_val)
4506 ? VI_DEFAULT : VIM_DEFAULT];
4507 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004508 {
4509 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4510 * use the global value. */
4511 if ((long *)varp == &curbuf->b_p_ul
4512 && opt_flags == OPT_LOCAL)
4513 value = NO_LOCAL_UNDOLEVEL;
4514 else
4515 value = *(long *)get_varp_scope(
4516 &(options[opt_idx]), OPT_GLOBAL);
4517 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004518 else if (((long *)varp == &p_wc
4519 || (long *)varp == &p_wcm)
4520 && (*arg == '<'
4521 || *arg == '^'
4522 || ((!arg[1] || vim_iswhite(arg[1]))
4523 && !VIM_ISDIGIT(*arg))))
4524 {
4525 value = string_to_key(arg);
4526 if (value == 0 && (long *)varp != &p_wcm)
4527 {
4528 errmsg = e_invarg;
4529 goto skip;
4530 }
4531 }
4532 /* allow negative numbers (for 'undolevels') */
4533 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4534 {
4535 i = 0;
4536 if (*arg == '-')
4537 i = 1;
4538#ifdef HAVE_STRTOL
4539 value = strtol((char *)arg, NULL, 0);
4540 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4541 i += 2;
4542#else
4543 value = atol((char *)arg);
4544#endif
4545 while (VIM_ISDIGIT(arg[i]))
4546 ++i;
4547 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4548 {
4549 errmsg = e_invarg;
4550 goto skip;
4551 }
4552 }
4553 else
4554 {
4555 errmsg = (char_u *)N_("E521: Number required after =");
4556 goto skip;
4557 }
4558
4559 if (adding)
4560 value = *(long *)varp + value;
4561 if (prepending)
4562 value = *(long *)varp * value;
4563 if (removing)
4564 value = *(long *)varp - value;
4565 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004566 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004567 }
4568 else if (opt_idx >= 0) /* string */
4569 {
4570 char_u *save_arg = NULL;
4571 char_u *s = NULL;
4572 char_u *oldval; /* previous value if *varp */
4573 char_u *newval;
4574 char_u *origval;
4575 unsigned newlen;
4576 int comma;
4577 int bs;
4578 int new_value_alloced; /* new string option
4579 was allocated */
4580
4581 /* When using ":set opt=val" for a global option
4582 * with a local value the local value will be
4583 * reset, use the global value here. */
4584 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004585 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004586 varp = options[opt_idx].var;
4587
4588 /* The old value is kept until we are sure that the
4589 * new value is valid. */
4590 oldval = *(char_u **)varp;
4591 if (nextchar == '&') /* set to default val */
4592 {
4593 newval = options[opt_idx].def_val[
4594 ((flags & P_VI_DEF) || cp_val)
4595 ? VI_DEFAULT : VIM_DEFAULT];
4596 if ((char_u **)varp == &p_bg)
4597 {
4598 /* guess the value of 'background' */
4599#ifdef FEAT_GUI
4600 if (gui.in_use)
4601 newval = gui_bg_default();
4602 else
4603#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004604 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004605 }
4606
4607 /* expand environment variables and ~ (since the
4608 * default value was already expanded, only
4609 * required when an environment variable was set
4610 * later */
4611 if (newval == NULL)
4612 newval = empty_option;
4613 else
4614 {
4615 s = option_expand(opt_idx, newval);
4616 if (s == NULL)
4617 s = newval;
4618 newval = vim_strsave(s);
4619 }
4620 new_value_alloced = TRUE;
4621 }
4622 else if (nextchar == '<') /* set to global val */
4623 {
4624 newval = vim_strsave(*(char_u **)get_varp_scope(
4625 &(options[opt_idx]), OPT_GLOBAL));
4626 new_value_alloced = TRUE;
4627 }
4628 else
4629 {
4630 ++arg; /* jump to after the '=' or ':' */
4631
4632 /*
4633 * Set 'keywordprg' to ":help" if an empty
4634 * value was passed to :set by the user.
4635 * Misuse errbuf[] for the resulting string.
4636 */
4637 if (varp == (char_u *)&p_kp
4638 && (*arg == NUL || *arg == ' '))
4639 {
4640 STRCPY(errbuf, ":help");
4641 save_arg = arg;
4642 arg = errbuf;
4643 }
4644 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004645 * Convert 'backspace' number to string, for
4646 * adding, prepending and removing string.
4647 */
4648 else if (varp == (char_u *)&p_bs
4649 && VIM_ISDIGIT(**(char_u **)varp))
4650 {
4651 i = getdigits((char_u **)varp);
4652 switch (i)
4653 {
4654 case 0:
4655 *(char_u **)varp = empty_option;
4656 break;
4657 case 1:
4658 *(char_u **)varp = vim_strsave(
4659 (char_u *)"indent,eol");
4660 break;
4661 case 2:
4662 *(char_u **)varp = vim_strsave(
4663 (char_u *)"indent,eol,start");
4664 break;
4665 }
4666 vim_free(oldval);
4667 oldval = *(char_u **)varp;
4668 }
4669 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004670 * Convert 'whichwrap' number to string, for
4671 * backwards compatibility with Vim 3.0.
4672 * Misuse errbuf[] for the resulting string.
4673 */
4674 else if (varp == (char_u *)&p_ww
4675 && VIM_ISDIGIT(*arg))
4676 {
4677 *errbuf = NUL;
4678 i = getdigits(&arg);
4679 if (i & 1)
4680 STRCAT(errbuf, "b,");
4681 if (i & 2)
4682 STRCAT(errbuf, "s,");
4683 if (i & 4)
4684 STRCAT(errbuf, "h,l,");
4685 if (i & 8)
4686 STRCAT(errbuf, "<,>,");
4687 if (i & 16)
4688 STRCAT(errbuf, "[,],");
4689 if (*errbuf != NUL) /* remove trailing , */
4690 errbuf[STRLEN(errbuf) - 1] = NUL;
4691 save_arg = arg;
4692 arg = errbuf;
4693 }
4694 /*
4695 * Remove '>' before 'dir' and 'bdir', for
4696 * backwards compatibility with version 3.0
4697 */
4698 else if ( *arg == '>'
4699 && (varp == (char_u *)&p_dir
4700 || varp == (char_u *)&p_bdir))
4701 {
4702 ++arg;
4703 }
4704
4705 /* When setting the local value of a global
4706 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004707 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004708 && (opt_flags & OPT_LOCAL))
4709 origval = *(char_u **)get_varp(
4710 &options[opt_idx]);
4711 else
4712 origval = oldval;
4713
4714 /*
4715 * Copy the new string into allocated memory.
4716 * Can't use set_string_option_direct(), because
4717 * we need to remove the backslashes.
4718 */
4719 /* get a bit too much */
4720 newlen = (unsigned)STRLEN(arg) + 1;
4721 if (adding || prepending || removing)
4722 newlen += (unsigned)STRLEN(origval) + 1;
4723 newval = alloc(newlen);
4724 if (newval == NULL) /* out of mem, don't change */
4725 break;
4726 s = newval;
4727
4728 /*
4729 * Copy the string, skip over escaped chars.
4730 * For MS-DOS and WIN32 backslashes before normal
4731 * file name characters are not removed, and keep
4732 * backslash at start, for "\\machine\path", but
4733 * do remove it for "\\\\machine\\path".
4734 * The reverse is found in ExpandOldSetting().
4735 */
4736 while (*arg && !vim_iswhite(*arg))
4737 {
4738 if (*arg == '\\' && arg[1] != NUL
4739#ifdef BACKSLASH_IN_FILENAME
4740 && !((flags & P_EXPAND)
4741 && vim_isfilec(arg[1])
4742 && (arg[1] != '\\'
4743 || (s == newval
4744 && arg[2] != '\\')))
4745#endif
4746 )
4747 ++arg; /* remove backslash */
4748#ifdef FEAT_MBYTE
4749 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004750 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004751 {
4752 /* copy multibyte char */
4753 mch_memmove(s, arg, (size_t)i);
4754 arg += i;
4755 s += i;
4756 }
4757 else
4758#endif
4759 *s++ = *arg++;
4760 }
4761 *s = NUL;
4762
4763 /*
4764 * Expand environment variables and ~.
4765 * Don't do it when adding without inserting a
4766 * comma.
4767 */
4768 if (!(adding || prepending || removing)
4769 || (flags & P_COMMA))
4770 {
4771 s = option_expand(opt_idx, newval);
4772 if (s != NULL)
4773 {
4774 vim_free(newval);
4775 newlen = (unsigned)STRLEN(s) + 1;
4776 if (adding || prepending || removing)
4777 newlen += (unsigned)STRLEN(origval) + 1;
4778 newval = alloc(newlen);
4779 if (newval == NULL)
4780 break;
4781 STRCPY(newval, s);
4782 }
4783 }
4784
4785 /* locate newval[] in origval[] when removing it
4786 * and when adding to avoid duplicates */
4787 i = 0; /* init for GCC */
4788 if (removing || (flags & P_NODUP))
4789 {
4790 i = (int)STRLEN(newval);
4791 bs = 0;
4792 for (s = origval; *s; ++s)
4793 {
4794 if ((!(flags & P_COMMA)
4795 || s == origval
4796 || (s[-1] == ',' && !(bs & 1)))
4797 && STRNCMP(s, newval, i) == 0
4798 && (!(flags & P_COMMA)
4799 || s[i] == ','
4800 || s[i] == NUL))
4801 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004802 /* Count backslashes. Only a comma with an
4803 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004804 * recognized as a separator */
4805 if (s > origval && s[-1] == '\\')
4806 ++bs;
4807 else
4808 bs = 0;
4809 }
4810
4811 /* do not add if already there */
4812 if ((adding || prepending) && *s)
4813 {
4814 prepending = FALSE;
4815 adding = FALSE;
4816 STRCPY(newval, origval);
4817 }
4818 }
4819
4820 /* concatenate the two strings; add a ',' if
4821 * needed */
4822 if (adding || prepending)
4823 {
4824 comma = ((flags & P_COMMA) && *origval != NUL
4825 && *newval != NUL);
4826 if (adding)
4827 {
4828 i = (int)STRLEN(origval);
4829 mch_memmove(newval + i + comma, newval,
4830 STRLEN(newval) + 1);
4831 mch_memmove(newval, origval, (size_t)i);
4832 }
4833 else
4834 {
4835 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004836 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004837 }
4838 if (comma)
4839 newval[i] = ',';
4840 }
4841
4842 /* Remove newval[] from origval[]. (Note: "i" has
4843 * been set above and is used here). */
4844 if (removing)
4845 {
4846 STRCPY(newval, origval);
4847 if (*s)
4848 {
4849 /* may need to remove a comma */
4850 if (flags & P_COMMA)
4851 {
4852 if (s == origval)
4853 {
4854 /* include comma after string */
4855 if (s[i] == ',')
4856 ++i;
4857 }
4858 else
4859 {
4860 /* include comma before string */
4861 --s;
4862 ++i;
4863 }
4864 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004865 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004866 }
4867 }
4868
4869 if (flags & P_FLAGLIST)
4870 {
4871 /* Remove flags that appear twice. */
4872 for (s = newval; *s; ++s)
4873 if ((!(flags & P_COMMA) || *s != ',')
4874 && vim_strchr(s + 1, *s) != NULL)
4875 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004876 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004877 --s;
4878 }
4879 }
4880
4881 if (save_arg != NULL) /* number for 'whichwrap' */
4882 arg = save_arg;
4883 new_value_alloced = TRUE;
4884 }
4885
4886 /* Set the new value. */
4887 *(char_u **)(varp) = newval;
4888
4889 /* Handle side effects, and set the global value for
4890 * ":set" on local options. */
4891 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4892 new_value_alloced, oldval, errbuf, opt_flags);
4893
4894 /* If error detected, print the error message. */
4895 if (errmsg != NULL)
4896 goto skip;
4897 }
4898 else /* key code option */
4899 {
4900 char_u *p;
4901
4902 if (nextchar == '&')
4903 {
4904 if (add_termcap_entry(key_name, TRUE) == FAIL)
4905 errmsg = (char_u *)N_("E522: Not found in termcap");
4906 }
4907 else
4908 {
4909 ++arg; /* jump to after the '=' or ':' */
4910 for (p = arg; *p && !vim_iswhite(*p); ++p)
4911 if (*p == '\\' && p[1] != NUL)
4912 ++p;
4913 nextchar = *p;
4914 *p = NUL;
4915 add_termcode(key_name, arg, FALSE);
4916 *p = nextchar;
4917 }
4918 if (full_screen)
4919 ttest(FALSE);
4920 redraw_all_later(CLEAR);
4921 }
4922 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004923
Bram Moolenaar071d4272004-06-13 20:20:40 +00004924 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004925 did_set_option(opt_idx, opt_flags,
4926 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004927 }
4928
4929skip:
4930 /*
4931 * Advance to next argument.
4932 * - skip until a blank found, taking care of backslashes
4933 * - skip blanks
4934 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4935 */
4936 for (i = 0; i < 2 ; ++i)
4937 {
4938 while (*arg != NUL && !vim_iswhite(*arg))
4939 if (*arg++ == '\\' && *arg != NUL)
4940 ++arg;
4941 arg = skipwhite(arg);
4942 if (*arg != '=')
4943 break;
4944 }
4945 }
4946
4947 if (errmsg != NULL)
4948 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004949 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004950 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004951 if (i + (arg - startarg) < IOSIZE)
4952 {
4953 /* append the argument with the error */
4954 STRCAT(IObuff, ": ");
4955 mch_memmove(IObuff + i, startarg, (arg - startarg));
4956 IObuff[i + (arg - startarg)] = NUL;
4957 }
4958 /* make sure all characters are printable */
4959 trans_characters(IObuff, IOSIZE);
4960
4961 ++no_wait_return; /* wait_return done later */
4962 emsg(IObuff); /* show error highlighted */
4963 --no_wait_return;
4964
4965 return FAIL;
4966 }
4967
4968 arg = skipwhite(arg);
4969 }
4970
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004971theend:
4972 if (silent_mode && did_show)
4973 {
4974 /* After displaying option values in silent mode. */
4975 silent_mode = FALSE;
4976 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4977 msg_putchar('\n');
4978 cursor_on(); /* msg_start() switches it off */
4979 out_flush();
4980 silent_mode = TRUE;
4981 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4982 }
4983
Bram Moolenaar071d4272004-06-13 20:20:40 +00004984 return OK;
4985}
4986
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004987/*
4988 * Call this when an option has been given a new value through a user command.
4989 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4990 */
4991 static void
4992did_set_option(opt_idx, opt_flags, new_value)
4993 int opt_idx;
4994 int opt_flags; /* possibly with OPT_MODELINE */
4995 int new_value; /* value was replaced completely */
4996{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004997 long_u *p;
4998
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004999 options[opt_idx].flags |= P_WAS_SET;
5000
5001 /* When an option is set in the sandbox, from a modeline or in secure mode
5002 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005003 * flag. */
5004 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005005 if (secure
5006#ifdef HAVE_SANDBOX
5007 || sandbox != 0
5008#endif
5009 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005010 *p = *p | P_INSECURE;
5011 else if (new_value)
5012 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005013}
5014
Bram Moolenaar071d4272004-06-13 20:20:40 +00005015 static char_u *
5016illegal_char(errbuf, c)
5017 char_u *errbuf;
5018 int c;
5019{
5020 if (errbuf == NULL)
5021 return (char_u *)"";
5022 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005023 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005024 return errbuf;
5025}
5026
5027/*
5028 * Convert a key name or string into a key value.
5029 * Used for 'wildchar' and 'cedit' options.
5030 */
5031 static int
5032string_to_key(arg)
5033 char_u *arg;
5034{
5035 if (*arg == '<')
5036 return find_key_option(arg + 1);
5037 if (*arg == '^')
5038 return Ctrl_chr(arg[1]);
5039 return *arg;
5040}
5041
5042#ifdef FEAT_CMDWIN
5043/*
5044 * Check value of 'cedit' and set cedit_key.
5045 * Returns NULL if value is OK, error message otherwise.
5046 */
5047 static char_u *
5048check_cedit()
5049{
5050 int n;
5051
5052 if (*p_cedit == NUL)
5053 cedit_key = -1;
5054 else
5055 {
5056 n = string_to_key(p_cedit);
5057 if (vim_isprintc(n))
5058 return e_invarg;
5059 cedit_key = n;
5060 }
5061 return NULL;
5062}
5063#endif
5064
5065#ifdef FEAT_TITLE
5066/*
5067 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5068 * maketitle() to create and display it.
5069 * When switching the title or icon off, call mch_restore_title() to get
5070 * the old value back.
5071 */
5072 static void
5073did_set_title(icon)
5074 int icon; /* Did set icon instead of title */
5075{
5076 if (starting != NO_SCREEN
5077#ifdef FEAT_GUI
5078 && !gui.starting
5079#endif
5080 )
5081 {
5082 maketitle();
5083 if (icon)
5084 {
5085 if (!p_icon)
5086 mch_restore_title(2);
5087 }
5088 else
5089 {
5090 if (!p_title)
5091 mch_restore_title(1);
5092 }
5093 }
5094}
5095#endif
5096
5097/*
5098 * set_options_bin - called when 'bin' changes value.
5099 */
5100 void
5101set_options_bin(oldval, newval, opt_flags)
5102 int oldval;
5103 int newval;
5104 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5105{
5106 /*
5107 * The option values that are changed when 'bin' changes are
5108 * copied when 'bin is set and restored when 'bin' is reset.
5109 */
5110 if (newval)
5111 {
5112 if (!oldval) /* switched on */
5113 {
5114 if (!(opt_flags & OPT_GLOBAL))
5115 {
5116 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5117 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5118 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5119 curbuf->b_p_et_nobin = curbuf->b_p_et;
5120 }
5121 if (!(opt_flags & OPT_LOCAL))
5122 {
5123 p_tw_nobin = p_tw;
5124 p_wm_nobin = p_wm;
5125 p_ml_nobin = p_ml;
5126 p_et_nobin = p_et;
5127 }
5128 }
5129
5130 if (!(opt_flags & OPT_GLOBAL))
5131 {
5132 curbuf->b_p_tw = 0; /* no automatic line wrap */
5133 curbuf->b_p_wm = 0; /* no automatic line wrap */
5134 curbuf->b_p_ml = 0; /* no modelines */
5135 curbuf->b_p_et = 0; /* no expandtab */
5136 }
5137 if (!(opt_flags & OPT_LOCAL))
5138 {
5139 p_tw = 0;
5140 p_wm = 0;
5141 p_ml = FALSE;
5142 p_et = FALSE;
5143 p_bin = TRUE; /* needed when called for the "-b" argument */
5144 }
5145 }
5146 else if (oldval) /* switched off */
5147 {
5148 if (!(opt_flags & OPT_GLOBAL))
5149 {
5150 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5151 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5152 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5153 curbuf->b_p_et = curbuf->b_p_et_nobin;
5154 }
5155 if (!(opt_flags & OPT_LOCAL))
5156 {
5157 p_tw = p_tw_nobin;
5158 p_wm = p_wm_nobin;
5159 p_ml = p_ml_nobin;
5160 p_et = p_et_nobin;
5161 }
5162 }
5163}
5164
5165#ifdef FEAT_VIMINFO
5166/*
5167 * Find the parameter represented by the given character (eg ', :, ", or /),
5168 * and return its associated value in the 'viminfo' string.
5169 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005170 * If the parameter is not specified in the string or there is no following
5171 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005172 */
5173 int
5174get_viminfo_parameter(type)
5175 int type;
5176{
5177 char_u *p;
5178
5179 p = find_viminfo_parameter(type);
5180 if (p != NULL && VIM_ISDIGIT(*p))
5181 return atoi((char *)p);
5182 return -1;
5183}
5184
5185/*
5186 * Find the parameter represented by the given character (eg ''', ':', '"', or
5187 * '/') in the 'viminfo' option and return a pointer to the string after it.
5188 * Return NULL if the parameter is not specified in the string.
5189 */
5190 char_u *
5191find_viminfo_parameter(type)
5192 int type;
5193{
5194 char_u *p;
5195
5196 for (p = p_viminfo; *p; ++p)
5197 {
5198 if (*p == type)
5199 return p + 1;
5200 if (*p == 'n') /* 'n' is always the last one */
5201 break;
5202 p = vim_strchr(p, ','); /* skip until next ',' */
5203 if (p == NULL) /* hit the end without finding parameter */
5204 break;
5205 }
5206 return NULL;
5207}
5208#endif
5209
5210/*
5211 * Expand environment variables for some string options.
5212 * These string options cannot be indirect!
5213 * If "val" is NULL expand the current value of the option.
5214 * Return pointer to NameBuff, or NULL when not expanded.
5215 */
5216 static char_u *
5217option_expand(opt_idx, val)
5218 int opt_idx;
5219 char_u *val;
5220{
5221 /* if option doesn't need expansion nothing to do */
5222 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5223 return NULL;
5224
5225 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5226 * expand_env() would truncate the string. */
5227 if (val != NULL && STRLEN(val) > MAXPATHL)
5228 return NULL;
5229
5230 if (val == NULL)
5231 val = *(char_u **)options[opt_idx].var;
5232
5233 /*
5234 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5235 * Escape spaces when expanding 'tags', they are used to separate file
5236 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005237 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005238 */
5239 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005240 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005241#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005242 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5243#endif
5244 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005245 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5246 return NULL;
5247
5248 return NameBuff;
5249}
5250
5251/*
5252 * After setting various option values: recompute variables that depend on
5253 * option values.
5254 */
5255 static void
5256didset_options()
5257{
5258 /* initialize the table for 'iskeyword' et.al. */
5259 (void)init_chartab();
5260
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005261#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005262 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005263#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005264 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5265#ifdef FEAT_SESSION
5266 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5267 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5268#endif
5269#ifdef FEAT_FOLDING
5270 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5271#endif
5272 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5273#ifdef FEAT_VIRTUALEDIT
5274 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5275#endif
5276#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5277 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5278#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005279#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005280 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005281 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005282 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005283#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005284#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5285 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5286#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005287#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005288 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5289#endif
5290#ifdef FEAT_CMDWIN
5291 /* set cedit_key */
5292 (void)check_cedit();
5293#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005294#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005295 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005296#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005297}
5298
5299/*
5300 * Check for string options that are NULL (normally only termcap options).
5301 */
5302 void
5303check_options()
5304{
5305 int opt_idx;
5306
5307 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5308 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5309 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5310}
5311
5312/*
5313 * Check string options in a buffer for NULL value.
5314 */
5315 void
5316check_buf_options(buf)
5317 buf_T *buf;
5318{
5319#if defined(FEAT_QUICKFIX)
5320 check_string_option(&buf->b_p_bh);
5321 check_string_option(&buf->b_p_bt);
5322#endif
5323#ifdef FEAT_MBYTE
5324 check_string_option(&buf->b_p_fenc);
5325#endif
5326 check_string_option(&buf->b_p_ff);
5327#ifdef FEAT_FIND_ID
5328 check_string_option(&buf->b_p_def);
5329 check_string_option(&buf->b_p_inc);
5330# ifdef FEAT_EVAL
5331 check_string_option(&buf->b_p_inex);
5332# endif
5333#endif
5334#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5335 check_string_option(&buf->b_p_inde);
5336 check_string_option(&buf->b_p_indk);
5337#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005338#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5339 check_string_option(&buf->b_p_bexpr);
5340#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005341#if defined(FEAT_CRYPT)
5342 check_string_option(&buf->b_p_cm);
5343#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005344#if defined(FEAT_EVAL)
5345 check_string_option(&buf->b_p_fex);
5346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005347#ifdef FEAT_CRYPT
5348 check_string_option(&buf->b_p_key);
5349#endif
5350 check_string_option(&buf->b_p_kp);
5351 check_string_option(&buf->b_p_mps);
5352 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005353 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354 check_string_option(&buf->b_p_isk);
5355#ifdef FEAT_COMMENTS
5356 check_string_option(&buf->b_p_com);
5357#endif
5358#ifdef FEAT_FOLDING
5359 check_string_option(&buf->b_p_cms);
5360#endif
5361 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005362#ifdef FEAT_TEXTOBJ
5363 check_string_option(&buf->b_p_qe);
5364#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005365#ifdef FEAT_SYN_HL
5366 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005367#endif
5368#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005369 check_string_option(&buf->b_s.b_p_spc);
5370 check_string_option(&buf->b_s.b_p_spf);
5371 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372#endif
5373#ifdef FEAT_SEARCHPATH
5374 check_string_option(&buf->b_p_sua);
5375#endif
5376#ifdef FEAT_CINDENT
5377 check_string_option(&buf->b_p_cink);
5378 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005379 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005380#endif
5381#ifdef FEAT_AUTOCMD
5382 check_string_option(&buf->b_p_ft);
5383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005384#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5385 check_string_option(&buf->b_p_cinw);
5386#endif
5387#ifdef FEAT_INS_EXPAND
5388 check_string_option(&buf->b_p_cpt);
5389#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005390#ifdef FEAT_COMPL_FUNC
5391 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005392 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005393#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005394#ifdef FEAT_KEYMAP
5395 check_string_option(&buf->b_p_keymap);
5396#endif
5397#ifdef FEAT_QUICKFIX
5398 check_string_option(&buf->b_p_gp);
5399 check_string_option(&buf->b_p_mp);
5400 check_string_option(&buf->b_p_efm);
5401#endif
5402 check_string_option(&buf->b_p_ep);
5403 check_string_option(&buf->b_p_path);
5404 check_string_option(&buf->b_p_tags);
5405#ifdef FEAT_INS_EXPAND
5406 check_string_option(&buf->b_p_dict);
5407 check_string_option(&buf->b_p_tsr);
5408#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005409#ifdef FEAT_LISP
5410 check_string_option(&buf->b_p_lw);
5411#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005412}
5413
5414/*
5415 * Free the string allocated for an option.
5416 * Checks for the string being empty_option. This may happen if we're out of
5417 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5418 * check_options().
5419 * Does NOT check for P_ALLOCED flag!
5420 */
5421 void
5422free_string_option(p)
5423 char_u *p;
5424{
5425 if (p != empty_option)
5426 vim_free(p);
5427}
5428
5429 void
5430clear_string_option(pp)
5431 char_u **pp;
5432{
5433 if (*pp != empty_option)
5434 vim_free(*pp);
5435 *pp = empty_option;
5436}
5437
5438 static void
5439check_string_option(pp)
5440 char_u **pp;
5441{
5442 if (*pp == NULL)
5443 *pp = empty_option;
5444}
5445
5446/*
5447 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5448 */
5449 void
5450set_term_option_alloced(p)
5451 char_u **p;
5452{
5453 int opt_idx;
5454
5455 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5456 if (options[opt_idx].var == (char_u *)p)
5457 {
5458 options[opt_idx].flags |= P_ALLOCED;
5459 return;
5460 }
5461 return; /* cannot happen: didn't find it! */
5462}
5463
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005464#if defined(FEAT_EVAL) || defined(PROTO)
5465/*
5466 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5467 * Return FALSE when it wasn't.
5468 * Return -1 for an unknown option.
5469 */
5470 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005471was_set_insecurely(opt, opt_flags)
5472 char_u *opt;
5473 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005474{
5475 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005476 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005477
5478 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005479 {
5480 flagp = insecure_flag(idx, opt_flags);
5481 return (*flagp & P_INSECURE) != 0;
5482 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005483 EMSG2(_(e_intern2), "was_set_insecurely()");
5484 return -1;
5485}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005486
5487/*
5488 * Get a pointer to the flags used for the P_INSECURE flag of option
5489 * "opt_idx". For some local options a local flags field is used.
5490 */
5491 static long_u *
5492insecure_flag(opt_idx, opt_flags)
5493 int opt_idx;
5494 int opt_flags;
5495{
5496 if (opt_flags & OPT_LOCAL)
5497 switch ((int)options[opt_idx].indir)
5498 {
5499#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005500 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005501#endif
5502#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005503# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005504 case PV_FDE: return &curwin->w_p_fde_flags;
5505 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005506# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005507# ifdef FEAT_BEVAL
5508 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5509# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005510# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005511 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005512# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005513 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005514# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005515 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005516# endif
5517#endif
5518 }
5519
5520 /* Nothing special, return global flags field. */
5521 return &options[opt_idx].flags;
5522}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005523#endif
5524
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005525#ifdef FEAT_TITLE
5526static void redraw_titles __ARGS((void));
5527
5528/*
5529 * Redraw the window title and/or tab page text later.
5530 */
5531static void redraw_titles()
5532{
5533 need_maketitle = TRUE;
5534# ifdef FEAT_WINDOWS
5535 redraw_tabline = TRUE;
5536# endif
5537}
5538#endif
5539
Bram Moolenaar071d4272004-06-13 20:20:40 +00005540/*
5541 * Set a string option to a new value (without checking the effect).
5542 * The string is copied into allocated memory.
5543 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005544 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005545 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546 */
5547 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005548set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549 char_u *name;
5550 int opt_idx;
5551 char_u *val;
5552 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005553 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005554{
5555 char_u *s;
5556 char_u **varp;
5557 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005558 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559
Bram Moolenaar89d40322006-08-29 15:30:07 +00005560 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005561 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005562 idx = findoption(name);
5563 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005564 {
5565 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005567 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568 }
5569
Bram Moolenaar89d40322006-08-29 15:30:07 +00005570 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571 return;
5572
5573 s = vim_strsave(val);
5574 if (s != NULL)
5575 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005576 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005578 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005579 free_string_option(*varp);
5580 *varp = s;
5581
5582 /* For buffer/window local option may also set the global value. */
5583 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005584 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005585
Bram Moolenaar89d40322006-08-29 15:30:07 +00005586 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005587
5588 /* When setting both values of a global option with a local value,
5589 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005590 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591 {
5592 free_string_option(*varp);
5593 *varp = empty_option;
5594 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005595# ifdef FEAT_EVAL
5596 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005597 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005598 set_sid == 0 ? current_SID : set_sid);
5599# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005600 }
5601}
5602
5603/*
5604 * Set global value for string option when it's a local option.
5605 */
5606 static void
5607set_string_option_global(opt_idx, varp)
5608 int opt_idx; /* option index */
5609 char_u **varp; /* pointer to option variable */
5610{
5611 char_u **p, *s;
5612
5613 /* the global value is always allocated */
5614 if (options[opt_idx].var == VAR_WIN)
5615 p = (char_u **)GLOBAL_WO(varp);
5616 else
5617 p = (char_u **)options[opt_idx].var;
5618 if (options[opt_idx].indir != PV_NONE
5619 && p != varp
5620 && (s = vim_strsave(*varp)) != NULL)
5621 {
5622 free_string_option(*p);
5623 *p = s;
5624 }
5625}
5626
5627/*
5628 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005629 *
5630 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005631 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005632 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005633set_string_option(opt_idx, value, opt_flags)
5634 int opt_idx;
5635 char_u *value;
5636 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5637{
5638 char_u *s;
5639 char_u **varp;
5640 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005641 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005642
5643 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005644 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645
5646 s = vim_strsave(value);
5647 if (s != NULL)
5648 {
5649 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5650 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005651 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652 ? OPT_GLOBAL : OPT_LOCAL)
5653 : opt_flags);
5654 oldval = *varp;
5655 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005656 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5657 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005658 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005659 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005660 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661}
5662
5663/*
5664 * Handle string options that need some action to perform when changed.
5665 * Returns NULL for success, or an error message for an error.
5666 */
5667 static char_u *
5668did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5669 opt_flags)
5670 int opt_idx; /* index in options[] table */
5671 char_u **varp; /* pointer to the option variable */
5672 int new_value_alloced; /* new value was allocated */
5673 char_u *oldval; /* previous value of the option */
5674 char_u *errbuf; /* buffer for errors, or NULL */
5675 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5676{
5677 char_u *errmsg = NULL;
5678 char_u *s, *p;
5679 int did_chartab = FALSE;
5680 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005681 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005682#ifdef FEAT_GUI
5683 /* set when changing an option that only requires a redraw in the GUI */
5684 int redraw_gui_only = FALSE;
5685#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005686
5687 /* Get the global option to compare with, otherwise we would have to check
5688 * two values for all local options. */
5689 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5690
5691 /* Disallow changing some options from secure mode */
5692 if ((secure
5693#ifdef HAVE_SANDBOX
5694 || sandbox != 0
5695#endif
5696 ) && (options[opt_idx].flags & P_SECURE))
5697 {
5698 errmsg = e_secure;
5699 }
5700
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005701 /* Check for a "normal" file name in some options. Disallow a path
5702 * separator (slash and/or backslash), wildcards and characters that are
5703 * often illegal in a file name. */
5704 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005705 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005706 {
5707 errmsg = e_invarg;
5708 }
5709
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710 /* 'term' */
5711 else if (varp == &T_NAME)
5712 {
5713 if (T_NAME[0] == NUL)
5714 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5715#ifdef FEAT_GUI
5716 if (gui.in_use)
5717 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5718 else if (term_is_gui(T_NAME))
5719 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5720#endif
5721 else if (set_termname(T_NAME) == FAIL)
5722 errmsg = (char_u *)N_("E522: Not found in termcap");
5723 else
5724 /* Screen colors may have changed. */
5725 redraw_later_clear();
5726 }
5727
5728 /* 'backupcopy' */
5729 else if (varp == &p_bkc)
5730 {
5731 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5732 errmsg = e_invarg;
5733 if (((bkc_flags & BKC_AUTO) != 0)
5734 + ((bkc_flags & BKC_YES) != 0)
5735 + ((bkc_flags & BKC_NO) != 0) != 1)
5736 {
5737 /* Must have exactly one of "auto", "yes" and "no". */
5738 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5739 errmsg = e_invarg;
5740 }
5741 }
5742
5743 /* 'backupext' and 'patchmode' */
5744 else if (varp == &p_bex || varp == &p_pm)
5745 {
5746 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5747 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5748 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5749 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005750#ifdef FEAT_LINEBREAK
5751 /* 'breakindentopt' */
5752 else if (varp == &curwin->w_p_briopt)
5753 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005754 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005755 errmsg = e_invarg;
5756 }
5757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005758
5759 /*
5760 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5761 * If the new option is invalid, use old value. 'lisp' option: refill
5762 * chartab[] for '-' char
5763 */
5764 else if ( varp == &p_isi
5765 || varp == &(curbuf->b_p_isk)
5766 || varp == &p_isp
5767 || varp == &p_isf)
5768 {
5769 if (init_chartab() == FAIL)
5770 {
5771 did_chartab = TRUE; /* need to restore it below */
5772 errmsg = e_invarg; /* error in value */
5773 }
5774 }
5775
5776 /* 'helpfile' */
5777 else if (varp == &p_hf)
5778 {
5779 /* May compute new values for $VIM and $VIMRUNTIME */
5780 if (didset_vim)
5781 {
5782 vim_setenv((char_u *)"VIM", (char_u *)"");
5783 didset_vim = FALSE;
5784 }
5785 if (didset_vimruntime)
5786 {
5787 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5788 didset_vimruntime = FALSE;
5789 }
5790 }
5791
Bram Moolenaar1a384422010-07-14 19:53:30 +02005792#ifdef FEAT_SYN_HL
5793 /* 'colorcolumn' */
5794 else if (varp == &curwin->w_p_cc)
5795 errmsg = check_colorcolumn(curwin);
5796#endif
5797
Bram Moolenaar071d4272004-06-13 20:20:40 +00005798#ifdef FEAT_MULTI_LANG
5799 /* 'helplang' */
5800 else if (varp == &p_hlg)
5801 {
5802 /* Check for "", "ab", "ab,cd", etc. */
5803 for (s = p_hlg; *s != NUL; s += 3)
5804 {
5805 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5806 {
5807 errmsg = e_invarg;
5808 break;
5809 }
5810 if (s[2] == NUL)
5811 break;
5812 }
5813 }
5814#endif
5815
5816 /* 'highlight' */
5817 else if (varp == &p_hl)
5818 {
5819 if (highlight_changed() == FAIL)
5820 errmsg = e_invarg; /* invalid flags */
5821 }
5822
5823 /* 'nrformats' */
5824 else if (gvarp == &p_nf)
5825 {
5826 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5827 errmsg = e_invarg;
5828 }
5829
5830#ifdef FEAT_SESSION
5831 /* 'sessionoptions' */
5832 else if (varp == &p_ssop)
5833 {
5834 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5835 errmsg = e_invarg;
5836 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5837 {
5838 /* Don't allow both "sesdir" and "curdir". */
5839 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5840 errmsg = e_invarg;
5841 }
5842 }
5843 /* 'viewoptions' */
5844 else if (varp == &p_vop)
5845 {
5846 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5847 errmsg = e_invarg;
5848 }
5849#endif
5850
5851 /* 'scrollopt' */
5852#ifdef FEAT_SCROLLBIND
5853 else if (varp == &p_sbo)
5854 {
5855 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5856 errmsg = e_invarg;
5857 }
5858#endif
5859
5860 /* 'ambiwidth' */
5861#ifdef FEAT_MBYTE
5862 else if (varp == &p_ambw)
5863 {
5864 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5865 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005866 else if (set_chars_option(&p_lcs) != NULL)
5867 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5868# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5869 else if (set_chars_option(&p_fcs) != NULL)
5870 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5871# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872 }
5873#endif
5874
5875 /* 'background' */
5876 else if (varp == &p_bg)
5877 {
5878 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5879 {
5880#ifdef FEAT_EVAL
5881 int dark = (*p_bg == 'd');
5882#endif
5883
5884 init_highlight(FALSE, FALSE);
5885
5886#ifdef FEAT_EVAL
5887 if (dark != (*p_bg == 'd')
5888 && get_var_value((char_u *)"g:colors_name") != NULL)
5889 {
5890 /* The color scheme must have set 'background' back to another
5891 * value, that's not what we want here. Disable the color
5892 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005893 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894 free_string_option(p_bg);
5895 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5896 check_string_option(&p_bg);
5897 init_highlight(FALSE, FALSE);
5898 }
5899#endif
5900 }
5901 else
5902 errmsg = e_invarg;
5903 }
5904
5905 /* 'wildmode' */
5906 else if (varp == &p_wim)
5907 {
5908 if (check_opt_wim() == FAIL)
5909 errmsg = e_invarg;
5910 }
5911
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005912#ifdef FEAT_CMDL_COMPL
5913 /* 'wildoptions' */
5914 else if (varp == &p_wop)
5915 {
5916 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5917 errmsg = e_invarg;
5918 }
5919#endif
5920
Bram Moolenaar071d4272004-06-13 20:20:40 +00005921#ifdef FEAT_WAK
5922 /* 'winaltkeys' */
5923 else if (varp == &p_wak)
5924 {
5925 if (*p_wak == NUL
5926 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5927 errmsg = e_invarg;
5928# ifdef FEAT_MENU
5929# ifdef FEAT_GUI_MOTIF
5930 else if (gui.in_use)
5931 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5932# else
5933# ifdef FEAT_GUI_GTK
5934 else if (gui.in_use)
5935 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5936# endif
5937# endif
5938# endif
5939 }
5940#endif
5941
5942#ifdef FEAT_AUTOCMD
5943 /* 'eventignore' */
5944 else if (varp == &p_ei)
5945 {
5946 if (check_ei() == FAIL)
5947 errmsg = e_invarg;
5948 }
5949#endif
5950
5951#ifdef FEAT_MBYTE
5952 /* 'encoding' and 'fileencoding' */
5953 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5954 {
5955 if (gvarp == &p_fenc)
5956 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005957 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005958 errmsg = e_modifiable;
5959 else if (vim_strchr(*varp, ',') != NULL)
5960 /* No comma allowed in 'fileencoding'; catches confusing it
5961 * with 'fileencodings'. */
5962 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005964 {
5965# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005967 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005968# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005969 /* Add 'fileencoding' to the swap file. */
5970 ml_setflags(curbuf);
5971 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005972 }
5973 if (errmsg == NULL)
5974 {
5975 /* canonize the value, so that STRCMP() can be used on it */
5976 p = enc_canonize(*varp);
5977 if (p != NULL)
5978 {
5979 vim_free(*varp);
5980 *varp = p;
5981 }
5982 if (varp == &p_enc)
5983 {
5984 errmsg = mb_init();
5985# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005986 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005987# endif
5988 }
5989 }
5990
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005991# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005992 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5993 {
5994 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5995 if (STRCMP(p_tenc, "utf-8") != 0)
5996 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5997 }
5998# endif
5999
6000 if (errmsg == NULL)
6001 {
6002# ifdef FEAT_KEYMAP
6003 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6004 * (with another encoding). */
6005 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6006 (void)keymap_init();
6007# endif
6008
6009 /* When 'termencoding' is not empty and 'encoding' changes or when
6010 * 'termencoding' changes, need to setup for keyboard input and
6011 * display output conversion. */
6012 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6013 {
6014 convert_setup(&input_conv, p_tenc, p_enc);
6015 convert_setup(&output_conv, p_enc, p_tenc);
6016 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006017
6018# if defined(WIN3264) && defined(FEAT_MBYTE)
6019 /* $HOME may have characters in active code page. */
6020 if (varp == &p_enc)
6021 init_homedir();
6022# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006023 }
6024 }
6025#endif
6026
6027#if defined(FEAT_POSTSCRIPT)
6028 else if (varp == &p_penc)
6029 {
6030 /* Canonize printencoding if VIM standard one */
6031 p = enc_canonize(p_penc);
6032 if (p != NULL)
6033 {
6034 vim_free(p_penc);
6035 p_penc = p;
6036 }
6037 else
6038 {
6039 /* Ensure lower case and '-' for '_' */
6040 for (s = p_penc; *s != NUL; s++)
6041 {
6042 if (*s == '_')
6043 *s = '-';
6044 else
6045 *s = TOLOWER_ASC(*s);
6046 }
6047 }
6048 }
6049#endif
6050
Bram Moolenaar9372a112005-12-06 19:59:18 +00006051#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006052 else if (varp == &p_imak)
6053 {
6054 if (gui.in_use && !im_xim_isvalid_imactivate())
6055 errmsg = e_invarg;
6056 }
6057#endif
6058
6059#ifdef FEAT_KEYMAP
6060 else if (varp == &curbuf->b_p_keymap)
6061 {
6062 /* load or unload key mapping tables */
6063 errmsg = keymap_init();
6064
Bram Moolenaarfab06232009-03-04 03:13:35 +00006065 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006066 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006067 if (*curbuf->b_p_keymap != NUL)
6068 {
6069 /* Installed a new keymap, switch on using it. */
6070 curbuf->b_p_iminsert = B_IMODE_LMAP;
6071 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6072 curbuf->b_p_imsearch = B_IMODE_LMAP;
6073 }
6074 else
6075 {
6076 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6077 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6078 curbuf->b_p_iminsert = B_IMODE_NONE;
6079 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6080 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6081 }
6082 if ((opt_flags & OPT_LOCAL) == 0)
6083 {
6084 set_iminsert_global();
6085 set_imsearch_global();
6086 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006087# ifdef FEAT_WINDOWS
6088 status_redraw_curbuf();
6089# endif
6090 }
6091 }
6092#endif
6093
6094 /* 'fileformat' */
6095 else if (gvarp == &p_ff)
6096 {
6097 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6098 errmsg = e_modifiable;
6099 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6100 errmsg = e_invarg;
6101 else
6102 {
6103 /* may also change 'textmode' */
6104 if (get_fileformat(curbuf) == EOL_DOS)
6105 curbuf->b_p_tx = TRUE;
6106 else
6107 curbuf->b_p_tx = FALSE;
6108#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006109 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006110#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006111 /* update flag in swap file */
6112 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006113 /* Redraw needed when switching to/from "mac": a CR in the text
6114 * will be displayed differently. */
6115 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6116 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 }
6118 }
6119
6120 /* 'fileformats' */
6121 else if (varp == &p_ffs)
6122 {
6123 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6124 errmsg = e_invarg;
6125 else
6126 {
6127 /* also change 'textauto' */
6128 if (*p_ffs == NUL)
6129 p_ta = FALSE;
6130 else
6131 p_ta = TRUE;
6132 }
6133 }
6134
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006135#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136 /* 'cryptkey' */
6137 else if (gvarp == &p_key)
6138 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006139# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006140 /* Make sure the ":set" command doesn't show the new value in the
6141 * history. */
6142 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006143# endif
6144 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6145 /* Need to update the swapfile. */
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006146 ml_set_crypt_key(curbuf, oldval, crypt_get_method_nr(curbuf));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006147 }
6148
6149 else if (gvarp == &p_cm)
6150 {
6151 if (opt_flags & OPT_LOCAL)
6152 p = curbuf->b_p_cm;
6153 else
6154 p = p_cm;
6155 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6156 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006157 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006158 errmsg = e_invarg;
6159 else
6160 {
6161 /* When setting the global value to empty, make it "zip". */
6162 if (*p_cm == NUL)
6163 {
6164 if (new_value_alloced)
6165 free_string_option(p_cm);
6166 p_cm = vim_strsave((char_u *)"zip");
6167 new_value_alloced = TRUE;
6168 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006169 /* When using ":set cm=name" the local value is going to be empty.
6170 * Do that here, otherwise the crypt functions will still use the
6171 * local value. */
6172 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6173 {
6174 free_string_option(curbuf->b_p_cm);
6175 curbuf->b_p_cm = empty_option;
6176 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006177
6178 /* Need to update the swapfile when the effective method changed.
6179 * Set "s" to the effective old value, "p" to the effective new
6180 * method and compare. */
6181 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6182 s = p_cm; /* was previously using the global value */
6183 else
6184 s = oldval;
6185 if (*curbuf->b_p_cm == NUL)
6186 p = p_cm; /* is now using the global value */
6187 else
6188 p = curbuf->b_p_cm;
6189 if (STRCMP(s, p) != 0)
6190 ml_set_crypt_key(curbuf, curbuf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006191 crypt_method_nr_from_name(s));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006192
6193 /* If the global value changes need to update the swapfile for all
6194 * buffers using that value. */
6195 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6196 {
6197 buf_T *buf;
6198
6199 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6200 if (buf != curbuf && *buf->b_p_cm == NUL)
6201 ml_set_crypt_key(buf, buf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006202 crypt_method_nr_from_name(oldval));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006203 }
6204 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006205 }
6206#endif
6207
6208 /* 'matchpairs' */
6209 else if (gvarp == &p_mps)
6210 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006211#ifdef FEAT_MBYTE
6212 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006213 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006214 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006215 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006216 int x2 = -1;
6217 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006218
6219 if (*p != NUL)
6220 p += mb_ptr2len(p);
6221 if (*p != NUL)
6222 x2 = *p++;
6223 if (*p != NUL)
6224 {
6225 x3 = mb_ptr2char(p);
6226 p += mb_ptr2len(p);
6227 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006228 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006229 {
6230 errmsg = e_invarg;
6231 break;
6232 }
6233 if (*p == NUL)
6234 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006235 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006236 }
6237 else
6238#endif
6239 {
6240 /* Check for "x:y,x:y" */
6241 for (p = *varp; *p != NUL; p += 4)
6242 {
6243 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6244 {
6245 errmsg = e_invarg;
6246 break;
6247 }
6248 if (p[3] == NUL)
6249 break;
6250 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251 }
6252 }
6253
6254#ifdef FEAT_COMMENTS
6255 /* 'comments' */
6256 else if (gvarp == &p_com)
6257 {
6258 for (s = *varp; *s; )
6259 {
6260 while (*s && *s != ':')
6261 {
6262 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6263 && !VIM_ISDIGIT(*s) && *s != '-')
6264 {
6265 errmsg = illegal_char(errbuf, *s);
6266 break;
6267 }
6268 ++s;
6269 }
6270 if (*s++ == NUL)
6271 errmsg = (char_u *)N_("E524: Missing colon");
6272 else if (*s == ',' || *s == NUL)
6273 errmsg = (char_u *)N_("E525: Zero length string");
6274 if (errmsg != NULL)
6275 break;
6276 while (*s && *s != ',')
6277 {
6278 if (*s == '\\' && s[1] != NUL)
6279 ++s;
6280 ++s;
6281 }
6282 s = skip_to_option_part(s);
6283 }
6284 }
6285#endif
6286
6287 /* 'listchars' */
6288 else if (varp == &p_lcs)
6289 {
6290 errmsg = set_chars_option(varp);
6291 }
6292
6293#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6294 /* 'fillchars' */
6295 else if (varp == &p_fcs)
6296 {
6297 errmsg = set_chars_option(varp);
6298 }
6299#endif
6300
6301#ifdef FEAT_CMDWIN
6302 /* 'cedit' */
6303 else if (varp == &p_cedit)
6304 {
6305 errmsg = check_cedit();
6306 }
6307#endif
6308
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006309 /* 'verbosefile' */
6310 else if (varp == &p_vfile)
6311 {
6312 verbose_stop();
6313 if (*p_vfile != NUL && verbose_open() == FAIL)
6314 errmsg = e_invarg;
6315 }
6316
Bram Moolenaar071d4272004-06-13 20:20:40 +00006317#ifdef FEAT_VIMINFO
6318 /* 'viminfo' */
6319 else if (varp == &p_viminfo)
6320 {
6321 for (s = p_viminfo; *s;)
6322 {
6323 /* Check it's a valid character */
6324 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6325 {
6326 errmsg = illegal_char(errbuf, *s);
6327 break;
6328 }
6329 if (*s == 'n') /* name is always last one */
6330 {
6331 break;
6332 }
6333 else if (*s == 'r') /* skip until next ',' */
6334 {
6335 while (*++s && *s != ',')
6336 ;
6337 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006338 else if (*s == '%')
6339 {
6340 /* optional number */
6341 while (vim_isdigit(*++s))
6342 ;
6343 }
6344 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006345 ++s; /* no extra chars */
6346 else /* must have a number */
6347 {
6348 while (vim_isdigit(*++s))
6349 ;
6350
6351 if (!VIM_ISDIGIT(*(s - 1)))
6352 {
6353 if (errbuf != NULL)
6354 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006355 sprintf((char *)errbuf,
6356 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006357 transchar_byte(*(s - 1)));
6358 errmsg = errbuf;
6359 }
6360 else
6361 errmsg = (char_u *)"";
6362 break;
6363 }
6364 }
6365 if (*s == ',')
6366 ++s;
6367 else if (*s)
6368 {
6369 if (errbuf != NULL)
6370 errmsg = (char_u *)N_("E527: Missing comma");
6371 else
6372 errmsg = (char_u *)"";
6373 break;
6374 }
6375 }
6376 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6377 errmsg = (char_u *)N_("E528: Must specify a ' value");
6378 }
6379#endif /* FEAT_VIMINFO */
6380
6381 /* terminal options */
6382 else if (istermoption(&options[opt_idx]) && full_screen)
6383 {
6384 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6385 if (varp == &T_CCO)
6386 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006387 int colors = atoi((char *)T_CCO);
6388
6389 /* Only reinitialize colors if t_Co value has really changed to
6390 * avoid expensive reload of colorscheme if t_Co is set to the
6391 * same value multiple times. */
6392 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006393 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006394 t_colors = colors;
6395 if (t_colors <= 1)
6396 {
6397 if (new_value_alloced)
6398 vim_free(T_CCO);
6399 T_CCO = empty_option;
6400 }
6401 /* We now have a different color setup, initialize it again. */
6402 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006403 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006404 }
6405 ttest(FALSE);
6406 if (varp == &T_ME)
6407 {
6408 out_str(T_ME);
6409 redraw_later(CLEAR);
6410#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6411 /* Since t_me has been set, this probably means that the user
6412 * wants to use this as default colors. Need to reset default
6413 * background/foreground colors. */
6414 mch_set_normal_colors();
6415#endif
6416 }
6417 }
6418
6419#ifdef FEAT_LINEBREAK
6420 /* 'showbreak' */
6421 else if (varp == &p_sbr)
6422 {
6423 for (s = p_sbr; *s; )
6424 {
6425 if (ptr2cells(s) != 1)
6426 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006427 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006428 }
6429 }
6430#endif
6431
6432#ifdef FEAT_GUI
6433 /* 'guifont' */
6434 else if (varp == &p_guifont)
6435 {
6436 if (gui.in_use)
6437 {
6438 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006439# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006440 /*
6441 * Put up a font dialog and let the user select a new value.
6442 * If this is cancelled go back to the old value but don't
6443 * give an error message.
6444 */
6445 if (STRCMP(p, "*") == 0)
6446 {
6447 p = gui_mch_font_dialog(oldval);
6448
6449 if (new_value_alloced)
6450 free_string_option(p_guifont);
6451
6452 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6453 new_value_alloced = TRUE;
6454 }
6455# endif
6456 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6457 {
6458# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6459 if (STRCMP(p_guifont, "*") == 0)
6460 {
6461 /* Dialog was cancelled: Keep the old value without giving
6462 * an error message. */
6463 if (new_value_alloced)
6464 free_string_option(p_guifont);
6465 p_guifont = vim_strsave(oldval);
6466 new_value_alloced = TRUE;
6467 }
6468 else
6469# endif
6470 errmsg = (char_u *)N_("E596: Invalid font(s)");
6471 }
6472 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006473 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006474 }
6475# ifdef FEAT_XFONTSET
6476 else if (varp == &p_guifontset)
6477 {
6478 if (STRCMP(p_guifontset, "*") == 0)
6479 errmsg = (char_u *)N_("E597: can't select fontset");
6480 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6481 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006482 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483 }
6484# endif
6485# ifdef FEAT_MBYTE
6486 else if (varp == &p_guifontwide)
6487 {
6488 if (STRCMP(p_guifontwide, "*") == 0)
6489 errmsg = (char_u *)N_("E533: can't select wide font");
6490 else if (gui_get_wide_font() == FAIL)
6491 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006492 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006493 }
6494# endif
6495#endif
6496
6497#ifdef CURSOR_SHAPE
6498 /* 'guicursor' */
6499 else if (varp == &p_guicursor)
6500 errmsg = parse_shape_opt(SHAPE_CURSOR);
6501#endif
6502
6503#ifdef FEAT_MOUSESHAPE
6504 /* 'mouseshape' */
6505 else if (varp == &p_mouseshape)
6506 {
6507 errmsg = parse_shape_opt(SHAPE_MOUSE);
6508 update_mouseshape(-1);
6509 }
6510#endif
6511
6512#ifdef FEAT_PRINTER
6513 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006514 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006515# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006516 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006517 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006518# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006519#endif
6520
6521#ifdef FEAT_LANGMAP
6522 /* 'langmap' */
6523 else if (varp == &p_langmap)
6524 langmap_set();
6525#endif
6526
6527#ifdef FEAT_LINEBREAK
6528 /* 'breakat' */
6529 else if (varp == &p_breakat)
6530 fill_breakat_flags();
6531#endif
6532
6533#ifdef FEAT_TITLE
6534 /* 'titlestring' and 'iconstring' */
6535 else if (varp == &p_titlestring || varp == &p_iconstring)
6536 {
6537# ifdef FEAT_STL_OPT
6538 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6539
6540 /* NULL => statusline syntax */
6541 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6542 stl_syntax |= flagval;
6543 else
6544 stl_syntax &= ~flagval;
6545# endif
6546 did_set_title(varp == &p_iconstring);
6547
6548 }
6549#endif
6550
6551#ifdef FEAT_GUI
6552 /* 'guioptions' */
6553 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006554 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006556 redraw_gui_only = TRUE;
6557 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006558#endif
6559
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006560#if defined(FEAT_GUI_TABLINE)
6561 /* 'guitablabel' */
6562 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006563 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006564 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006565 redraw_gui_only = TRUE;
6566 }
6567 /* 'guitabtooltip' */
6568 else if (varp == &p_gtt)
6569 {
6570 redraw_gui_only = TRUE;
6571 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006572#endif
6573
Bram Moolenaar071d4272004-06-13 20:20:40 +00006574#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6575 /* 'ttymouse' */
6576 else if (varp == &p_ttym)
6577 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006578 /* Switch the mouse off before changing the escape sequences used for
6579 * that. */
6580 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6582 errmsg = e_invarg;
6583 else
6584 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006585 if (termcap_active)
6586 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006587 }
6588#endif
6589
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590 /* 'selection' */
6591 else if (varp == &p_sel)
6592 {
6593 if (*p_sel == NUL
6594 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6595 errmsg = e_invarg;
6596 }
6597
6598 /* 'selectmode' */
6599 else if (varp == &p_slm)
6600 {
6601 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6602 errmsg = e_invarg;
6603 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604
6605#ifdef FEAT_BROWSE
6606 /* 'browsedir' */
6607 else if (varp == &p_bsdir)
6608 {
6609 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6610 && !mch_isdir(p_bsdir))
6611 errmsg = e_invarg;
6612 }
6613#endif
6614
Bram Moolenaar071d4272004-06-13 20:20:40 +00006615 /* 'keymodel' */
6616 else if (varp == &p_km)
6617 {
6618 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6619 errmsg = e_invarg;
6620 else
6621 {
6622 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6623 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6624 }
6625 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006626
6627 /* 'mousemodel' */
6628 else if (varp == &p_mousem)
6629 {
6630 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6631 errmsg = e_invarg;
6632#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6633 else if (*p_mousem != *oldval)
6634 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6635 * to create or delete the popup menus. */
6636 gui_motif_update_mousemodel(root_menu);
6637#endif
6638 }
6639
6640 /* 'switchbuf' */
6641 else if (varp == &p_swb)
6642 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006643 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006644 errmsg = e_invarg;
6645 }
6646
6647 /* 'debug' */
6648 else if (varp == &p_debug)
6649 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006650 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006651 errmsg = e_invarg;
6652 }
6653
6654 /* 'display' */
6655 else if (varp == &p_dy)
6656 {
6657 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6658 errmsg = e_invarg;
6659 else
6660 (void)init_chartab();
6661
6662 }
6663
6664#ifdef FEAT_VERTSPLIT
6665 /* 'eadirection' */
6666 else if (varp == &p_ead)
6667 {
6668 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6669 errmsg = e_invarg;
6670 }
6671#endif
6672
6673#ifdef FEAT_CLIPBOARD
6674 /* 'clipboard' */
6675 else if (varp == &p_cb)
6676 errmsg = check_clipboard_option();
6677#endif
6678
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006679#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006680 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6681 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006682 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006683 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006684 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006685 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006686
Bram Moolenaar860cae12010-06-05 23:22:07 +02006687 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006688 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006689 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6690 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006691 ".add") != 0))
6692 errmsg = e_invarg;
6693 }
6694
6695 if (errmsg == NULL)
6696 {
6697 FOR_ALL_WINDOWS(wp)
6698 if (wp->w_buffer == curbuf && wp->w_p_spell)
6699 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006700 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006701# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006702 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006703# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006704 }
6705 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006706 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006707 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006708 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006709 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006710 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006711 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006712 /* 'spellsuggest' */
6713 else if (varp == &p_sps)
6714 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006715 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006716 errmsg = e_invarg;
6717 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006718 /* 'mkspellmem' */
6719 else if (varp == &p_msm)
6720 {
6721 if (spell_check_msm() != OK)
6722 errmsg = e_invarg;
6723 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006724#endif
6725
Bram Moolenaar071d4272004-06-13 20:20:40 +00006726#ifdef FEAT_QUICKFIX
6727 /* When 'bufhidden' is set, check for valid value. */
6728 else if (gvarp == &p_bh)
6729 {
6730 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6731 errmsg = e_invarg;
6732 }
6733
6734 /* When 'buftype' is set, check for valid value. */
6735 else if (gvarp == &p_bt)
6736 {
6737 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6738 errmsg = e_invarg;
6739 else
6740 {
6741# ifdef FEAT_WINDOWS
6742 if (curwin->w_status_height)
6743 {
6744 curwin->w_redr_status = TRUE;
6745 redraw_later(VALID);
6746 }
6747# endif
6748 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006749# ifdef FEAT_TITLE
6750 redraw_titles();
6751# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006752 }
6753 }
6754#endif
6755
6756#ifdef FEAT_STL_OPT
6757 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006758 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006759 {
6760 int wid;
6761
6762 if (varp == &p_ruf) /* reset ru_wid first */
6763 ru_wid = 0;
6764 s = *varp;
6765 if (varp == &p_ruf && *s == '%')
6766 {
6767 /* set ru_wid if 'ruf' starts with "%99(" */
6768 if (*++s == '-') /* ignore a '-' */
6769 s++;
6770 wid = getdigits(&s);
6771 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6772 ru_wid = wid;
6773 else
6774 errmsg = check_stl_option(p_ruf);
6775 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006776 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006777 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006778 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006779 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780 comp_col();
6781 }
6782#endif
6783
6784#ifdef FEAT_INS_EXPAND
6785 /* check if it is a valid value for 'complete' -- Acevedo */
6786 else if (gvarp == &p_cpt)
6787 {
6788 for (s = *varp; *s;)
6789 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006790 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006791 s++;
6792 if (!*s)
6793 break;
6794 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6795 {
6796 errmsg = illegal_char(errbuf, *s);
6797 break;
6798 }
6799 if (*++s != NUL && *s != ',' && *s != ' ')
6800 {
6801 if (s[-1] == 'k' || s[-1] == 's')
6802 {
6803 /* skip optional filename after 'k' and 's' */
6804 while (*s && *s != ',' && *s != ' ')
6805 {
6806 if (*s == '\\')
6807 ++s;
6808 ++s;
6809 }
6810 }
6811 else
6812 {
6813 if (errbuf != NULL)
6814 {
6815 sprintf((char *)errbuf,
6816 _("E535: Illegal character after <%c>"),
6817 *--s);
6818 errmsg = errbuf;
6819 }
6820 else
6821 errmsg = (char_u *)"";
6822 break;
6823 }
6824 }
6825 }
6826 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006827
6828 /* 'completeopt' */
6829 else if (varp == &p_cot)
6830 {
6831 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6832 errmsg = e_invarg;
6833 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006834#endif /* FEAT_INS_EXPAND */
6835
6836
6837#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6838 else if (varp == &p_toolbar)
6839 {
6840 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6841 &toolbar_flags, TRUE) != OK)
6842 errmsg = e_invarg;
6843 else
6844 {
6845 out_flush();
6846 gui_mch_show_toolbar((toolbar_flags &
6847 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6848 }
6849 }
6850#endif
6851
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006852#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006853 /* 'toolbariconsize': GTK+ 2 only */
6854 else if (varp == &p_tbis)
6855 {
6856 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6857 errmsg = e_invarg;
6858 else
6859 {
6860 out_flush();
6861 gui_mch_show_toolbar((toolbar_flags &
6862 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6863 }
6864 }
6865#endif
6866
6867 /* 'pastetoggle': translate key codes like in a mapping */
6868 else if (varp == &p_pt)
6869 {
6870 if (*p_pt)
6871 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006872 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873 if (p != NULL)
6874 {
6875 if (new_value_alloced)
6876 free_string_option(p_pt);
6877 p_pt = p;
6878 new_value_alloced = TRUE;
6879 }
6880 }
6881 }
6882
6883 /* 'backspace' */
6884 else if (varp == &p_bs)
6885 {
6886 if (VIM_ISDIGIT(*p_bs))
6887 {
6888 if (*p_bs >'2' || p_bs[1] != NUL)
6889 errmsg = e_invarg;
6890 }
6891 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6892 errmsg = e_invarg;
6893 }
6894
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006895#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006896 /* 'casemap' */
6897 else if (varp == &p_cmp)
6898 {
6899 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6900 errmsg = e_invarg;
6901 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006902#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903
6904#ifdef FEAT_DIFF
6905 /* 'diffopt' */
6906 else if (varp == &p_dip)
6907 {
6908 if (diffopt_changed() == FAIL)
6909 errmsg = e_invarg;
6910 }
6911#endif
6912
6913#ifdef FEAT_FOLDING
6914 /* 'foldmethod' */
6915 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6916 {
6917 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6918 || *curwin->w_p_fdm == NUL)
6919 errmsg = e_invarg;
6920 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006921 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006922 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006923 if (foldmethodIsDiff(curwin))
6924 newFoldLevel();
6925 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006926 }
6927# ifdef FEAT_EVAL
6928 /* 'foldexpr' */
6929 else if (varp == &curwin->w_p_fde)
6930 {
6931 if (foldmethodIsExpr(curwin))
6932 foldUpdateAll(curwin);
6933 }
6934# endif
6935 /* 'foldmarker' */
6936 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6937 {
6938 p = vim_strchr(*varp, ',');
6939 if (p == NULL)
6940 errmsg = (char_u *)N_("E536: comma required");
6941 else if (p == *varp || p[1] == NUL)
6942 errmsg = e_invarg;
6943 else if (foldmethodIsMarker(curwin))
6944 foldUpdateAll(curwin);
6945 }
6946 /* 'commentstring' */
6947 else if (gvarp == &p_cms)
6948 {
6949 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6950 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6951 }
6952 /* 'foldopen' */
6953 else if (varp == &p_fdo)
6954 {
6955 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6956 errmsg = e_invarg;
6957 }
6958 /* 'foldclose' */
6959 else if (varp == &p_fcl)
6960 {
6961 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6962 errmsg = e_invarg;
6963 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006964 /* 'foldignore' */
6965 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6966 {
6967 if (foldmethodIsIndent(curwin))
6968 foldUpdateAll(curwin);
6969 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006970#endif
6971
6972#ifdef FEAT_VIRTUALEDIT
6973 /* 'virtualedit' */
6974 else if (varp == &p_ve)
6975 {
6976 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6977 errmsg = e_invarg;
6978 else if (STRCMP(p_ve, oldval) != 0)
6979 {
6980 /* Recompute cursor position in case the new 've' setting
6981 * changes something. */
6982 validate_virtcol();
6983 coladvance(curwin->w_virtcol);
6984 }
6985 }
6986#endif
6987
6988#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6989 else if (varp == &p_csqf)
6990 {
6991 if (p_csqf != NULL)
6992 {
6993 p = p_csqf;
6994 while (*p != NUL)
6995 {
6996 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6997 || p[1] == NUL
6998 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6999 || (p[2] != NUL && p[2] != ','))
7000 {
7001 errmsg = e_invarg;
7002 break;
7003 }
7004 else if (p[2] == NUL)
7005 break;
7006 else
7007 p += 3;
7008 }
7009 }
7010 }
7011#endif
7012
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007013#ifdef FEAT_CINDENT
7014 /* 'cinoptions' */
7015 else if (gvarp == &p_cino)
7016 {
7017 /* TODO: recognize errors */
7018 parse_cino(curbuf);
7019 }
7020#endif
7021
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007022#if defined(FEAT_RENDER_OPTIONS)
7023 else if (varp == &p_rop && gui.in_use)
7024 {
7025 if (!gui_mch_set_rendering_options(p_rop))
7026 errmsg = e_invarg;
7027 }
7028#endif
7029
Bram Moolenaar071d4272004-06-13 20:20:40 +00007030 /* Options that are a list of flags. */
7031 else
7032 {
7033 p = NULL;
7034 if (varp == &p_ww)
7035 p = (char_u *)WW_ALL;
7036 if (varp == &p_shm)
7037 p = (char_u *)SHM_ALL;
7038 else if (varp == &(p_cpo))
7039 p = (char_u *)CPO_ALL;
7040 else if (varp == &(curbuf->b_p_fo))
7041 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007042#ifdef FEAT_CONCEAL
7043 else if (varp == &curwin->w_p_cocu)
7044 p = (char_u *)COCU_ALL;
7045#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007046 else if (varp == &p_mouse)
7047 {
7048#ifdef FEAT_MOUSE
7049 p = (char_u *)MOUSE_ALL;
7050#else
7051 if (*p_mouse != NUL)
7052 errmsg = (char_u *)N_("E538: No mouse support");
7053#endif
7054 }
7055#if defined(FEAT_GUI)
7056 else if (varp == &p_go)
7057 p = (char_u *)GO_ALL;
7058#endif
7059 if (p != NULL)
7060 {
7061 for (s = *varp; *s; ++s)
7062 if (vim_strchr(p, *s) == NULL)
7063 {
7064 errmsg = illegal_char(errbuf, *s);
7065 break;
7066 }
7067 }
7068 }
7069
7070 /*
7071 * If error detected, restore the previous value.
7072 */
7073 if (errmsg != NULL)
7074 {
7075 if (new_value_alloced)
7076 free_string_option(*varp);
7077 *varp = oldval;
7078 /*
7079 * When resetting some values, need to act on it.
7080 */
7081 if (did_chartab)
7082 (void)init_chartab();
7083 if (varp == &p_hl)
7084 (void)highlight_changed();
7085 }
7086 else
7087 {
7088#ifdef FEAT_EVAL
7089 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007090 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007091#endif
7092 /*
7093 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007094 * Use "free_oldval", because recursiveness may change the flags under
7095 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007097 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007098 free_string_option(oldval);
7099 if (new_value_alloced)
7100 options[opt_idx].flags |= P_ALLOCED;
7101 else
7102 options[opt_idx].flags &= ~P_ALLOCED;
7103
7104 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007105 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 {
7107 /* global option with local value set to use global value; free
7108 * the local value and make it empty */
7109 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7110 free_string_option(*(char_u **)p);
7111 *(char_u **)p = empty_option;
7112 }
7113
7114 /* May set global value for local option. */
7115 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7116 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007117
7118#ifdef FEAT_AUTOCMD
7119 /*
7120 * Trigger the autocommand only after setting the flags.
7121 */
7122# ifdef FEAT_SYN_HL
7123 /* When 'syntax' is set, load the syntax of that name */
7124 if (varp == &(curbuf->b_p_syn))
7125 {
7126 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7127 curbuf->b_fname, TRUE, curbuf);
7128 }
7129# endif
7130 else if (varp == &(curbuf->b_p_ft))
7131 {
7132 /* 'filetype' is set, trigger the FileType autocommand */
7133 did_filetype = TRUE;
7134 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7135 curbuf->b_fname, TRUE, curbuf);
7136 }
7137#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007138#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007139 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007140 {
7141 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007142 char_u *q = curwin->w_s->b_p_spl;
7143
7144 /* Skip the first name if it is "cjk". */
7145 if (STRNCMP(q, "cjk,", 4) == 0)
7146 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007147
7148 /*
7149 * Source the spell/LANG.vim in 'runtimepath'.
7150 * They could set 'spellcapcheck' depending on the language.
7151 * Use the first name in 'spelllang' up to '_region' or
7152 * '.encoding'.
7153 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007154 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007155 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7156 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007157 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007158 source_runtime(fname, TRUE);
7159 }
7160#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007161 }
7162
7163#ifdef FEAT_MOUSE
7164 if (varp == &p_mouse)
7165 {
7166# ifdef FEAT_MOUSE_TTY
7167 if (*p_mouse == NUL)
7168 mch_setmouse(FALSE); /* switch mouse off */
7169 else
7170# endif
7171 setmouse(); /* in case 'mouse' changed */
7172 }
7173#endif
7174
Bram Moolenaar913077c2012-03-28 19:59:04 +02007175 if (curwin->w_curswant != MAXCOL
7176 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7177 curwin->w_set_curswant = TRUE;
7178
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007179#ifdef FEAT_GUI
7180 /* check redraw when it's not a GUI option or the GUI is active. */
7181 if (!redraw_gui_only || gui.in_use)
7182#endif
7183 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007184
7185 return errmsg;
7186}
7187
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007188#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007189/*
7190 * Simple int comparison function for use with qsort()
7191 */
7192 static int
7193int_cmp(a, b)
7194 const void *a;
7195 const void *b;
7196{
7197 return *(const int *)a - *(const int *)b;
7198}
7199
7200/*
7201 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7202 * Returns error message, NULL if it's OK.
7203 */
7204 char_u *
7205check_colorcolumn(wp)
7206 win_T *wp;
7207{
7208 char_u *s;
7209 int col;
7210 int count = 0;
7211 int color_cols[256];
7212 int i;
7213 int j = 0;
7214
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007215 if (wp->w_buffer == NULL)
7216 return NULL; /* buffer was closed */
7217
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007218 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007219 {
7220 if (*s == '-' || *s == '+')
7221 {
7222 /* -N and +N: add to 'textwidth' */
7223 col = (*s == '-') ? -1 : 1;
7224 ++s;
7225 if (!VIM_ISDIGIT(*s))
7226 return e_invarg;
7227 col = col * getdigits(&s);
7228 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007229 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007230 col += wp->w_buffer->b_p_tw;
7231 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007232 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007233 }
7234 else if (VIM_ISDIGIT(*s))
7235 col = getdigits(&s);
7236 else
7237 return e_invarg;
7238 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007239skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007240 if (*s == NUL)
7241 break;
7242 if (*s != ',')
7243 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007244 if (*++s == NUL)
7245 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007246 }
7247
7248 vim_free(wp->w_p_cc_cols);
7249 if (count == 0)
7250 wp->w_p_cc_cols = NULL;
7251 else
7252 {
7253 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7254 if (wp->w_p_cc_cols != NULL)
7255 {
7256 /* sort the columns for faster usage on screen redraw inside
7257 * win_line() */
7258 qsort(color_cols, count, sizeof(int), int_cmp);
7259
7260 for (i = 0; i < count; ++i)
7261 /* skip duplicates */
7262 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7263 wp->w_p_cc_cols[j++] = color_cols[i];
7264 wp->w_p_cc_cols[j] = -1; /* end marker */
7265 }
7266 }
7267
7268 return NULL; /* no error */
7269}
7270#endif
7271
Bram Moolenaar071d4272004-06-13 20:20:40 +00007272/*
7273 * Handle setting 'listchars' or 'fillchars'.
7274 * Returns error message, NULL if it's OK.
7275 */
7276 static char_u *
7277set_chars_option(varp)
7278 char_u **varp;
7279{
7280 int round, i, len, entries;
7281 char_u *p, *s;
7282 int c1, c2 = 0;
7283 struct charstab
7284 {
7285 int *cp;
7286 char *name;
7287 };
7288#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7289 static struct charstab filltab[] =
7290 {
7291 {&fill_stl, "stl"},
7292 {&fill_stlnc, "stlnc"},
7293 {&fill_vert, "vert"},
7294 {&fill_fold, "fold"},
7295 {&fill_diff, "diff"},
7296 };
7297#endif
7298 static struct charstab lcstab[] =
7299 {
7300 {&lcs_eol, "eol"},
7301 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007302 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007303 {&lcs_prec, "precedes"},
7304 {&lcs_tab2, "tab"},
7305 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007306#ifdef FEAT_CONCEAL
7307 {&lcs_conceal, "conceal"},
7308#else
7309 {NULL, "conceal"},
7310#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 };
7312 struct charstab *tab;
7313
7314#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7315 if (varp == &p_lcs)
7316#endif
7317 {
7318 tab = lcstab;
7319 entries = sizeof(lcstab) / sizeof(struct charstab);
7320 }
7321#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7322 else
7323 {
7324 tab = filltab;
7325 entries = sizeof(filltab) / sizeof(struct charstab);
7326 }
7327#endif
7328
7329 /* first round: check for valid value, second round: assign values */
7330 for (round = 0; round <= 1; ++round)
7331 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007332 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007333 {
7334 /* After checking that the value is valid: set defaults: space for
7335 * 'fillchars', NUL for 'listchars' */
7336 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007337 if (tab[i].cp != NULL)
7338 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007339 if (varp == &p_lcs)
7340 lcs_tab1 = NUL;
7341#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7342 else
7343 fill_diff = '-';
7344#endif
7345 }
7346 p = *varp;
7347 while (*p)
7348 {
7349 for (i = 0; i < entries; ++i)
7350 {
7351 len = (int)STRLEN(tab[i].name);
7352 if (STRNCMP(p, tab[i].name, len) == 0
7353 && p[len] == ':'
7354 && p[len + 1] != NUL)
7355 {
7356 s = p + len + 1;
7357#ifdef FEAT_MBYTE
7358 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007359 if (mb_char2cells(c1) > 1)
7360 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007361#else
7362 c1 = *s++;
7363#endif
7364 if (tab[i].cp == &lcs_tab2)
7365 {
7366 if (*s == NUL)
7367 continue;
7368#ifdef FEAT_MBYTE
7369 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007370 if (mb_char2cells(c2) > 1)
7371 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007372#else
7373 c2 = *s++;
7374#endif
7375 }
7376 if (*s == ',' || *s == NUL)
7377 {
7378 if (round)
7379 {
7380 if (tab[i].cp == &lcs_tab2)
7381 {
7382 lcs_tab1 = c1;
7383 lcs_tab2 = c2;
7384 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007385 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007386 *(tab[i].cp) = c1;
7387
7388 }
7389 p = s;
7390 break;
7391 }
7392 }
7393 }
7394
7395 if (i == entries)
7396 return e_invarg;
7397 if (*p == ',')
7398 ++p;
7399 }
7400 }
7401
7402 return NULL; /* no error */
7403}
7404
7405#ifdef FEAT_STL_OPT
7406/*
7407 * Check validity of options with the 'statusline' format.
7408 * Return error message or NULL.
7409 */
7410 char_u *
7411check_stl_option(s)
7412 char_u *s;
7413{
7414 int itemcnt = 0;
7415 int groupdepth = 0;
7416 static char_u errbuf[80];
7417
7418 while (*s && itemcnt < STL_MAX_ITEM)
7419 {
7420 /* Check for valid keys after % sequences */
7421 while (*s && *s != '%')
7422 s++;
7423 if (!*s)
7424 break;
7425 s++;
7426 if (*s != '%' && *s != ')')
7427 ++itemcnt;
7428 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7429 {
7430 s++;
7431 continue;
7432 }
7433 if (*s == ')')
7434 {
7435 s++;
7436 if (--groupdepth < 0)
7437 break;
7438 continue;
7439 }
7440 if (*s == '-')
7441 s++;
7442 while (VIM_ISDIGIT(*s))
7443 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007444 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007445 continue;
7446 if (*s == '.')
7447 {
7448 s++;
7449 while (*s && VIM_ISDIGIT(*s))
7450 s++;
7451 }
7452 if (*s == '(')
7453 {
7454 groupdepth++;
7455 continue;
7456 }
7457 if (vim_strchr(STL_ALL, *s) == NULL)
7458 {
7459 return illegal_char(errbuf, *s);
7460 }
7461 if (*s == '{')
7462 {
7463 s++;
7464 while (*s != '}' && *s)
7465 s++;
7466 if (*s != '}')
7467 return (char_u *)N_("E540: Unclosed expression sequence");
7468 }
7469 }
7470 if (itemcnt >= STL_MAX_ITEM)
7471 return (char_u *)N_("E541: too many items");
7472 if (groupdepth != 0)
7473 return (char_u *)N_("E542: unbalanced groups");
7474 return NULL;
7475}
7476#endif
7477
7478#ifdef FEAT_CLIPBOARD
7479/*
7480 * Extract the items in the 'clipboard' option and set global values.
7481 */
7482 static char_u *
7483check_clipboard_option()
7484{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007485 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007486 int new_autoselect_star = FALSE;
7487 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007488 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007489 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007490 regprog_T *new_exclude_prog = NULL;
7491 char_u *errmsg = NULL;
7492 char_u *p;
7493
7494 for (p = p_cb; *p != NUL; )
7495 {
7496 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7497 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007498 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499 p += 7;
7500 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007501 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007502 && (p[11] == ',' || p[11] == NUL))
7503 {
7504 new_unnamed |= CLIP_UNNAMED_PLUS;
7505 p += 11;
7506 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007507 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007508 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007509 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007510 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007511 p += 10;
7512 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007513 else if (STRNCMP(p, "autoselectplus", 14) == 0
7514 && (p[14] == ',' || p[14] == NUL))
7515 {
7516 new_autoselect_plus = TRUE;
7517 p += 14;
7518 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007520 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521 {
7522 new_autoselectml = TRUE;
7523 p += 12;
7524 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007525 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7526 {
7527 new_html = TRUE;
7528 p += 4;
7529 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007530 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7531 {
7532 p += 8;
7533 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7534 if (new_exclude_prog == NULL)
7535 errmsg = e_invarg;
7536 break;
7537 }
7538 else
7539 {
7540 errmsg = e_invarg;
7541 break;
7542 }
7543 if (*p == ',')
7544 ++p;
7545 }
7546 if (errmsg == NULL)
7547 {
7548 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007549 clip_autoselect_star = new_autoselect_star;
7550 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007551 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007552 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007553 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007554 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007555#ifdef FEAT_GUI_GTK
7556 if (gui.in_use)
7557 {
7558 gui_gtk_set_selection_targets();
7559 gui_gtk_set_dnd_targets();
7560 }
7561#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007562 }
7563 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007564 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007565
7566 return errmsg;
7567}
7568#endif
7569
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007570#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007571/*
7572 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7573 * Return error message when failed, NULL when OK.
7574 */
7575 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007576compile_cap_prog(synblock)
7577 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007578{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007579 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007580 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007581
Bram Moolenaar860cae12010-06-05 23:22:07 +02007582 if (*synblock->b_p_spc == NUL)
7583 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007584 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007585 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007586 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007587 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007588 if (re != NULL)
7589 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007590 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007591 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007592 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007593 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007594 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007595 return e_invarg;
7596 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007597 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007598 }
7599
Bram Moolenaar473de612013-06-08 18:19:48 +02007600 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007601 return NULL;
7602}
7603#endif
7604
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007605#if defined(FEAT_EVAL) || defined(PROTO)
7606/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007607 * Set the scriptID for an option, taking care of setting the buffer- or
7608 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007609 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007610 static void
7611set_option_scriptID_idx(opt_idx, opt_flags, id)
7612 int opt_idx;
7613 int opt_flags;
7614 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007615{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007616 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7617 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007618
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007619 /* Remember where the option was set. For local options need to do that
7620 * in the buffer or window structure. */
7621 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007622 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007623 if (both || (opt_flags & OPT_LOCAL))
7624 {
7625 if (indir & PV_BUF)
7626 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7627 else if (indir & PV_WIN)
7628 curwin->w_p_scriptID[indir & PV_MASK] = id;
7629 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007630}
7631#endif
7632
Bram Moolenaar071d4272004-06-13 20:20:40 +00007633/*
7634 * Set the value of a boolean option, and take care of side effects.
7635 * Returns NULL for success, or an error message for an error.
7636 */
7637 static char_u *
7638set_bool_option(opt_idx, varp, value, opt_flags)
7639 int opt_idx; /* index in options[] table */
7640 char_u *varp; /* pointer to the option variable */
7641 int value; /* new value */
7642 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7643{
7644 int old_value = *(int *)varp;
7645
Bram Moolenaar071d4272004-06-13 20:20:40 +00007646 /* Disallow changing some options from secure mode */
7647 if ((secure
7648#ifdef HAVE_SANDBOX
7649 || sandbox != 0
7650#endif
7651 ) && (options[opt_idx].flags & P_SECURE))
7652 return e_secure;
7653
7654 *(int *)varp = value; /* set the new value */
7655#ifdef FEAT_EVAL
7656 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007657 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007658#endif
7659
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007660#ifdef FEAT_GUI
7661 need_mouse_correct = TRUE;
7662#endif
7663
Bram Moolenaar071d4272004-06-13 20:20:40 +00007664 /* May set global value for local option. */
7665 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7666 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7667
7668 /*
7669 * Handle side effects of changing a bool option.
7670 */
7671
7672 /* 'compatible' */
7673 if ((int *)varp == &p_cp)
7674 {
7675 compatible_set();
7676 }
7677
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007678#ifdef FEAT_PERSISTENT_UNDO
7679 /* 'undofile' */
7680 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7681 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007682 /* Only take action when the option was set. When reset we do not
7683 * delete the undo file, the option may be set again without making
7684 * any changes in between. */
7685 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007686 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007687 char_u hash[UNDO_HASH_SIZE];
7688 buf_T *save_curbuf = curbuf;
7689
7690 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007691 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007692 /* When 'undofile' is set globally: for every buffer, otherwise
7693 * only for the current buffer: Try to read in the undofile,
7694 * if one exists, the buffer wasn't changed and the buffer was
7695 * loaded */
7696 if ((curbuf == save_curbuf
7697 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7698 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7699 {
7700 u_compute_hash(hash);
7701 u_read_undo(NULL, hash, curbuf->b_fname);
7702 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007703 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007704 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007705 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007706 }
7707#endif
7708
Bram Moolenaar071d4272004-06-13 20:20:40 +00007709 else if ((int *)varp == &curbuf->b_p_ro)
7710 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007711 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7713 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007714
7715 /* when 'readonly' is set may give W10 again */
7716 if (curbuf->b_p_ro)
7717 curbuf->b_did_warn = FALSE;
7718
Bram Moolenaar071d4272004-06-13 20:20:40 +00007719#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007720 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007721#endif
7722 }
7723
Bram Moolenaar9c449722010-07-20 18:44:27 +02007724#ifdef FEAT_GUI
7725 else if ((int *)varp == &p_mh)
7726 {
7727 if (!p_mh)
7728 gui_mch_mousehide(FALSE);
7729 }
7730#endif
7731
Bram Moolenaara539df02010-08-01 14:35:05 +02007732#ifdef FEAT_TITLE
7733 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007734 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007735 {
7736 redraw_titles();
7737 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007738 /* when 'endofline' is changed, redraw the window title */
7739 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007740 {
7741 redraw_titles();
7742 }
7743# ifdef FEAT_MBYTE
7744 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007745 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007746 {
7747 redraw_titles();
7748 }
7749# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750#endif
7751
7752 /* when 'bin' is set also set some other options */
7753 else if ((int *)varp == &curbuf->b_p_bin)
7754 {
7755 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7756#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007757 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758#endif
7759 }
7760
7761#ifdef FEAT_AUTOCMD
7762 /* when 'buflisted' changes, trigger autocommands */
7763 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7764 {
7765 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7766 NULL, NULL, TRUE, curbuf);
7767 }
7768#endif
7769
7770 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7771 else if ((int *)varp == &curbuf->b_p_swf)
7772 {
7773 if (curbuf->b_p_swf && p_uc)
7774 ml_open_file(curbuf); /* create the swap file */
7775 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007776 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7777 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778 mf_close_file(curbuf, TRUE); /* remove the swap file */
7779 }
7780
7781 /* when 'terse' is set change 'shortmess' */
7782 else if ((int *)varp == &p_terse)
7783 {
7784 char_u *p;
7785
7786 p = vim_strchr(p_shm, SHM_SEARCH);
7787
7788 /* insert 's' in p_shm */
7789 if (p_terse && p == NULL)
7790 {
7791 STRCPY(IObuff, p_shm);
7792 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007793 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007794 }
7795 /* remove 's' from p_shm */
7796 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007797 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798 }
7799
7800 /* when 'paste' is set or reset also change other options */
7801 else if ((int *)varp == &p_paste)
7802 {
7803 paste_option_changed();
7804 }
7805
7806 /* when 'insertmode' is set from an autocommand need to do work here */
7807 else if ((int *)varp == &p_im)
7808 {
7809 if (p_im)
7810 {
7811 if ((State & INSERT) == 0)
7812 need_start_insertmode = TRUE;
7813 stop_insert_mode = FALSE;
7814 }
7815 else
7816 {
7817 need_start_insertmode = FALSE;
7818 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007819 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007820 clear_cmdline = TRUE; /* remove "(insert)" */
7821 restart_edit = 0;
7822 }
7823 }
7824
7825 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7826 else if ((int *)varp == &p_ic && p_hls)
7827 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007828 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007829 }
7830
7831#ifdef FEAT_SEARCH_EXTRA
7832 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7833 else if ((int *)varp == &p_hls)
7834 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007835 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007836 }
7837#endif
7838
7839#ifdef FEAT_SCROLLBIND
7840 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7841 * at the end of normal_cmd() */
7842 else if ((int *)varp == &curwin->w_p_scb)
7843 {
7844 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007845 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007846 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007847 curwin->w_scbind_pos = curwin->w_topline;
7848 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849 }
7850#endif
7851
7852#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7853 /* There can be only one window with 'previewwindow' set. */
7854 else if ((int *)varp == &curwin->w_p_pvw)
7855 {
7856 if (curwin->w_p_pvw)
7857 {
7858 win_T *win;
7859
7860 for (win = firstwin; win != NULL; win = win->w_next)
7861 if (win->w_p_pvw && win != curwin)
7862 {
7863 curwin->w_p_pvw = FALSE;
7864 return (char_u *)N_("E590: A preview window already exists");
7865 }
7866 }
7867 }
7868#endif
7869
7870 /* when 'textmode' is set or reset also change 'fileformat' */
7871 else if ((int *)varp == &curbuf->b_p_tx)
7872 {
7873 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7874 }
7875
7876 /* when 'textauto' is set or reset also change 'fileformats' */
7877 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007878 set_string_option_direct((char_u *)"ffs", -1,
7879 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007880 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007881
7882 /*
7883 * When 'lisp' option changes include/exclude '-' in
7884 * keyword characters.
7885 */
7886#ifdef FEAT_LISP
7887 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7888 {
7889 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7890 }
7891#endif
7892
7893#ifdef FEAT_TITLE
7894 /* when 'title' changed, may need to change the title; same for 'icon' */
7895 else if ((int *)varp == &p_title)
7896 {
7897 did_set_title(FALSE);
7898 }
7899
7900 else if ((int *)varp == &p_icon)
7901 {
7902 did_set_title(TRUE);
7903 }
7904#endif
7905
7906 else if ((int *)varp == &curbuf->b_changed)
7907 {
7908 if (!value)
7909 save_file_ff(curbuf); /* Buffer is unchanged */
7910#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007911 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007912#endif
7913#ifdef FEAT_AUTOCMD
7914 modified_was_set = value;
7915#endif
7916 }
7917
7918#ifdef BACKSLASH_IN_FILENAME
7919 else if ((int *)varp == &p_ssl)
7920 {
7921 if (p_ssl)
7922 {
7923 psepc = '/';
7924 psepcN = '\\';
7925 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926 }
7927 else
7928 {
7929 psepc = '\\';
7930 psepcN = '/';
7931 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007932 }
7933
7934 /* need to adjust the file name arguments and buffer names. */
7935 buflist_slash_adjust();
7936 alist_slash_adjust();
7937# ifdef FEAT_EVAL
7938 scriptnames_slash_adjust();
7939# endif
7940 }
7941#endif
7942
7943 /* If 'wrap' is set, set w_leftcol to zero. */
7944 else if ((int *)varp == &curwin->w_p_wrap)
7945 {
7946 if (curwin->w_p_wrap)
7947 curwin->w_leftcol = 0;
7948 }
7949
7950#ifdef FEAT_WINDOWS
7951 else if ((int *)varp == &p_ea)
7952 {
7953 if (p_ea && !old_value)
7954 win_equal(curwin, FALSE, 0);
7955 }
7956#endif
7957
7958 else if ((int *)varp == &p_wiv)
7959 {
7960 /*
7961 * When 'weirdinvert' changed, set/reset 't_xs'.
7962 * Then set 'weirdinvert' according to value of 't_xs'.
7963 */
7964 if (p_wiv && !old_value)
7965 T_XS = (char_u *)"y";
7966 else if (!p_wiv && old_value)
7967 T_XS = empty_option;
7968 p_wiv = (*T_XS != NUL);
7969 }
7970
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007971#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 else if ((int *)varp == &p_beval)
7973 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007974 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007975 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007976 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007977 gui_mch_disable_beval_area(balloonEval);
7978 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007979#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007981#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007982 else if ((int *)varp == &p_acd)
7983 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007984 /* Change directories when the 'acd' option is set now. */
7985 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007986 }
7987#endif
7988
7989#ifdef FEAT_DIFF
7990 /* 'diff' */
7991 else if ((int *)varp == &curwin->w_p_diff)
7992 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007993 /* May add or remove the buffer from the list of diff buffers. */
7994 diff_buf_adjust(curwin);
7995# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996 if (foldmethodIsDiff(curwin))
7997 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007998# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 }
8000#endif
8001
8002#ifdef USE_IM_CONTROL
8003 /* 'imdisable' */
8004 else if ((int *)varp == &p_imdisable)
8005 {
8006 /* Only de-activate it here, it will be enabled when changing mode. */
8007 if (p_imdisable)
8008 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008009 else if (State & INSERT)
8010 /* When the option is set from an autocommand, it may need to take
8011 * effect right away. */
8012 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013 }
8014#endif
8015
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008016#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008017 /* 'spell' */
8018 else if ((int *)varp == &curwin->w_p_spell)
8019 {
8020 if (curwin->w_p_spell)
8021 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008022 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008023 if (errmsg != NULL)
8024 EMSG(_(errmsg));
8025 }
8026 }
8027#endif
8028
Bram Moolenaar071d4272004-06-13 20:20:40 +00008029#ifdef FEAT_FKMAP
8030 else if ((int *)varp == &p_altkeymap)
8031 {
8032 if (old_value != p_altkeymap)
8033 {
8034 if (!p_altkeymap)
8035 {
8036 p_hkmap = p_fkmap;
8037 p_fkmap = 0;
8038 }
8039 else
8040 {
8041 p_fkmap = p_hkmap;
8042 p_hkmap = 0;
8043 }
8044 (void)init_chartab();
8045 }
8046 }
8047
8048 /*
8049 * In case some second language keymapping options have changed, check
8050 * and correct the setting in a consistent way.
8051 */
8052
8053 /*
8054 * If hkmap or fkmap are set, reset Arabic keymapping.
8055 */
8056 if ((p_hkmap || p_fkmap) && p_altkeymap)
8057 {
8058 p_altkeymap = p_fkmap;
8059# ifdef FEAT_ARABIC
8060 curwin->w_p_arab = FALSE;
8061# endif
8062 (void)init_chartab();
8063 }
8064
8065 /*
8066 * If hkmap set, reset Farsi keymapping.
8067 */
8068 if (p_hkmap && p_altkeymap)
8069 {
8070 p_altkeymap = 0;
8071 p_fkmap = 0;
8072# ifdef FEAT_ARABIC
8073 curwin->w_p_arab = FALSE;
8074# endif
8075 (void)init_chartab();
8076 }
8077
8078 /*
8079 * If fkmap set, reset Hebrew keymapping.
8080 */
8081 if (p_fkmap && !p_altkeymap)
8082 {
8083 p_altkeymap = 1;
8084 p_hkmap = 0;
8085# ifdef FEAT_ARABIC
8086 curwin->w_p_arab = FALSE;
8087# endif
8088 (void)init_chartab();
8089 }
8090#endif
8091
8092#ifdef FEAT_ARABIC
8093 if ((int *)varp == &curwin->w_p_arab)
8094 {
8095 if (curwin->w_p_arab)
8096 {
8097 /*
8098 * 'arabic' is set, handle various sub-settings.
8099 */
8100 if (!p_tbidi)
8101 {
8102 /* set rightleft mode */
8103 if (!curwin->w_p_rl)
8104 {
8105 curwin->w_p_rl = TRUE;
8106 changed_window_setting();
8107 }
8108
8109 /* Enable Arabic shaping (major part of what Arabic requires) */
8110 if (!p_arshape)
8111 {
8112 p_arshape = TRUE;
8113 redraw_later_clear();
8114 }
8115 }
8116
8117 /* Arabic requires a utf-8 encoding, inform the user if its not
8118 * set. */
8119 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008120 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008121 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8122
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008123 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008124 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8125#ifdef FEAT_EVAL
8126 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8127#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008128 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008129
8130# ifdef FEAT_MBYTE
8131 /* set 'delcombine' */
8132 p_deco = TRUE;
8133# endif
8134
8135# ifdef FEAT_KEYMAP
8136 /* Force-set the necessary keymap for arabic */
8137 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8138 OPT_LOCAL);
8139# endif
8140# ifdef FEAT_FKMAP
8141 p_altkeymap = 0;
8142 p_hkmap = 0;
8143 p_fkmap = 0;
8144 (void)init_chartab();
8145# endif
8146 }
8147 else
8148 {
8149 /*
8150 * 'arabic' is reset, handle various sub-settings.
8151 */
8152 if (!p_tbidi)
8153 {
8154 /* reset rightleft mode */
8155 if (curwin->w_p_rl)
8156 {
8157 curwin->w_p_rl = FALSE;
8158 changed_window_setting();
8159 }
8160
8161 /* 'arabicshape' isn't reset, it is a global option and
8162 * another window may still need it "on". */
8163 }
8164
8165 /* 'delcombine' isn't reset, it is a global option and another
8166 * window may still want it "on". */
8167
8168# ifdef FEAT_KEYMAP
8169 /* Revert to the default keymap */
8170 curbuf->b_p_iminsert = B_IMODE_NONE;
8171 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8172# endif
8173 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008174 }
8175
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008176#endif
8177
Bram Moolenaar071d4272004-06-13 20:20:40 +00008178 /*
8179 * End of handling side effects for bool options.
8180 */
8181
8182 options[opt_idx].flags |= P_WAS_SET;
8183
8184 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008185 if (curwin->w_curswant != MAXCOL
8186 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8187 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188 check_redraw(options[opt_idx].flags);
8189
8190 return NULL;
8191}
8192
8193/*
8194 * Set the value of a number option, and take care of side effects.
8195 * Returns NULL for success, or an error message for an error.
8196 */
8197 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008198set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008199 int opt_idx; /* index in options[] table */
8200 char_u *varp; /* pointer to the option variable */
8201 long value; /* new value */
8202 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008203 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008204 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8205 OPT_MODELINE */
8206{
8207 char_u *errmsg = NULL;
8208 long old_value = *(long *)varp;
8209 long old_Rows = Rows; /* remember old Rows */
8210 long old_Columns = Columns; /* remember old Columns */
8211 long *pp = (long *)varp;
8212
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008213 /* Disallow changing some options from secure mode. */
8214 if ((secure
8215#ifdef HAVE_SANDBOX
8216 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008217#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008218 ) && (options[opt_idx].flags & P_SECURE))
8219 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220
8221 *pp = value;
8222#ifdef FEAT_EVAL
8223 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008224 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008226#ifdef FEAT_GUI
8227 need_mouse_correct = TRUE;
8228#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008229
Bram Moolenaar14f24742012-08-08 18:01:05 +02008230 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008231 {
8232 errmsg = e_positive;
8233 curbuf->b_p_sw = curbuf->b_p_ts;
8234 }
8235
8236 /*
8237 * Number options that need some action when changed
8238 */
8239#ifdef FEAT_WINDOWS
8240 if (pp == &p_wh || pp == &p_hh)
8241 {
8242 if (p_wh < 1)
8243 {
8244 errmsg = e_positive;
8245 p_wh = 1;
8246 }
8247 if (p_wmh > p_wh)
8248 {
8249 errmsg = e_winheight;
8250 p_wh = p_wmh;
8251 }
8252 if (p_hh < 0)
8253 {
8254 errmsg = e_positive;
8255 p_hh = 0;
8256 }
8257
8258 /* Change window height NOW */
8259 if (lastwin != firstwin)
8260 {
8261 if (pp == &p_wh && curwin->w_height < p_wh)
8262 win_setheight((int)p_wh);
8263 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8264 win_setheight((int)p_hh);
8265 }
8266 }
8267
8268 /* 'winminheight' */
8269 else if (pp == &p_wmh)
8270 {
8271 if (p_wmh < 0)
8272 {
8273 errmsg = e_positive;
8274 p_wmh = 0;
8275 }
8276 if (p_wmh > p_wh)
8277 {
8278 errmsg = e_winheight;
8279 p_wmh = p_wh;
8280 }
8281 win_setminheight();
8282 }
8283
8284# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008285 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008286 {
8287 if (p_wiw < 1)
8288 {
8289 errmsg = e_positive;
8290 p_wiw = 1;
8291 }
8292 if (p_wmw > p_wiw)
8293 {
8294 errmsg = e_winwidth;
8295 p_wiw = p_wmw;
8296 }
8297
8298 /* Change window width NOW */
8299 if (lastwin != firstwin && curwin->w_width < p_wiw)
8300 win_setwidth((int)p_wiw);
8301 }
8302
8303 /* 'winminwidth' */
8304 else if (pp == &p_wmw)
8305 {
8306 if (p_wmw < 0)
8307 {
8308 errmsg = e_positive;
8309 p_wmw = 0;
8310 }
8311 if (p_wmw > p_wiw)
8312 {
8313 errmsg = e_winwidth;
8314 p_wmw = p_wiw;
8315 }
8316 win_setminheight();
8317 }
8318# endif
8319
8320#endif
8321
8322#ifdef FEAT_WINDOWS
8323 /* (re)set last window status line */
8324 else if (pp == &p_ls)
8325 {
8326 last_status(FALSE);
8327 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008328
8329 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008330 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008331 {
8332 shell_new_rows(); /* recompute window positions and heights */
8333 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008334#endif
8335
8336#ifdef FEAT_GUI
8337 else if (pp == &p_linespace)
8338 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008339 /* Recompute gui.char_height and resize the Vim window to keep the
8340 * same number of lines. */
8341 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008342 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 }
8344#endif
8345
8346#ifdef FEAT_FOLDING
8347 /* 'foldlevel' */
8348 else if (pp == &curwin->w_p_fdl)
8349 {
8350 if (curwin->w_p_fdl < 0)
8351 curwin->w_p_fdl = 0;
8352 newFoldLevel();
8353 }
8354
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008355 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008356 else if (pp == &curwin->w_p_fml)
8357 {
8358 foldUpdateAll(curwin);
8359 }
8360
8361 /* 'foldnestmax' */
8362 else if (pp == &curwin->w_p_fdn)
8363 {
8364 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8365 foldUpdateAll(curwin);
8366 }
8367
8368 /* 'foldcolumn' */
8369 else if (pp == &curwin->w_p_fdc)
8370 {
8371 if (curwin->w_p_fdc < 0)
8372 {
8373 errmsg = e_positive;
8374 curwin->w_p_fdc = 0;
8375 }
8376 else if (curwin->w_p_fdc > 12)
8377 {
8378 errmsg = e_invarg;
8379 curwin->w_p_fdc = 12;
8380 }
8381 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008382#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008384#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008385 /* 'shiftwidth' or 'tabstop' */
8386 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8387 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008388# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008389 if (foldmethodIsIndent(curwin))
8390 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008391# endif
8392# ifdef FEAT_CINDENT
8393 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8394 * parse 'cinoptions'. */
8395 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8396 parse_cino(curbuf);
8397# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008398 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008399#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008401#ifdef FEAT_MBYTE
8402 /* 'maxcombine' */
8403 else if (pp == &p_mco)
8404 {
8405 if (p_mco > MAX_MCO)
8406 p_mco = MAX_MCO;
8407 else if (p_mco < 0)
8408 p_mco = 0;
8409 screenclear(); /* will re-allocate the screen */
8410 }
8411#endif
8412
Bram Moolenaar071d4272004-06-13 20:20:40 +00008413 else if (pp == &curbuf->b_p_iminsert)
8414 {
8415 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8416 {
8417 errmsg = e_invarg;
8418 curbuf->b_p_iminsert = B_IMODE_NONE;
8419 }
8420 p_iminsert = curbuf->b_p_iminsert;
8421 if (termcap_active) /* don't do this in the alternate screen */
8422 showmode();
8423#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8424 /* Show/unshow value of 'keymap' in status lines. */
8425 status_redraw_curbuf();
8426#endif
8427 }
8428
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008429 else if (pp == &p_window)
8430 {
8431 if (p_window < 1)
8432 p_window = 1;
8433 else if (p_window >= Rows)
8434 p_window = Rows - 1;
8435 }
8436
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 else if (pp == &curbuf->b_p_imsearch)
8438 {
8439 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8440 {
8441 errmsg = e_invarg;
8442 curbuf->b_p_imsearch = B_IMODE_NONE;
8443 }
8444 p_imsearch = curbuf->b_p_imsearch;
8445 }
8446
8447#ifdef FEAT_TITLE
8448 /* if 'titlelen' has changed, redraw the title */
8449 else if (pp == &p_titlelen)
8450 {
8451 if (p_titlelen < 0)
8452 {
8453 errmsg = e_positive;
8454 p_titlelen = 85;
8455 }
8456 if (starting != NO_SCREEN && old_value != p_titlelen)
8457 need_maketitle = TRUE;
8458 }
8459#endif
8460
8461 /* if p_ch changed value, change the command line height */
8462 else if (pp == &p_ch)
8463 {
8464 if (p_ch < 1)
8465 {
8466 errmsg = e_positive;
8467 p_ch = 1;
8468 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008469 if (p_ch > Rows - min_rows() + 1)
8470 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471
8472 /* Only compute the new window layout when startup has been
8473 * completed. Otherwise the frame sizes may be wrong. */
8474 if (p_ch != old_value && full_screen
8475#ifdef FEAT_GUI
8476 && !gui.starting
8477#endif
8478 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008479 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008480 }
8481
8482 /* when 'updatecount' changes from zero to non-zero, open swap files */
8483 else if (pp == &p_uc)
8484 {
8485 if (p_uc < 0)
8486 {
8487 errmsg = e_positive;
8488 p_uc = 100;
8489 }
8490 if (p_uc && !old_value)
8491 ml_open_files();
8492 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008493#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008494 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008495 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008496 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008497 {
8498 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008499 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008500 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008501 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008502 {
8503 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008504 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008505 }
8506 }
8507#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008508#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008509 else if (pp == &p_mzq)
8510 mzvim_reset_timer();
8511#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008512
8513 /* sync undo before 'undolevels' changes */
8514 else if (pp == &p_ul)
8515 {
8516 /* use the old value, otherwise u_sync() may not work properly */
8517 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008518 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008519 p_ul = value;
8520 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008521 else if (pp == &curbuf->b_p_ul)
8522 {
8523 /* use the old value, otherwise u_sync() may not work properly */
8524 curbuf->b_p_ul = old_value;
8525 u_sync(TRUE);
8526 curbuf->b_p_ul = value;
8527 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008528
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008529#ifdef FEAT_LINEBREAK
8530 /* 'numberwidth' must be positive */
8531 else if (pp == &curwin->w_p_nuw)
8532 {
8533 if (curwin->w_p_nuw < 1)
8534 {
8535 errmsg = e_positive;
8536 curwin->w_p_nuw = 1;
8537 }
8538 if (curwin->w_p_nuw > 10)
8539 {
8540 errmsg = e_invarg;
8541 curwin->w_p_nuw = 10;
8542 }
8543 curwin->w_nrwidth_line_count = 0;
8544 }
8545#endif
8546
Bram Moolenaar1a384422010-07-14 19:53:30 +02008547 else if (pp == &curbuf->b_p_tw)
8548 {
8549 if (curbuf->b_p_tw < 0)
8550 {
8551 errmsg = e_positive;
8552 curbuf->b_p_tw = 0;
8553 }
8554#ifdef FEAT_SYN_HL
8555# ifdef FEAT_WINDOWS
8556 {
8557 win_T *wp;
8558 tabpage_T *tp;
8559
8560 FOR_ALL_TAB_WINDOWS(tp, wp)
8561 check_colorcolumn(wp);
8562 }
8563# else
8564 check_colorcolumn(curwin);
8565# endif
8566#endif
8567 }
8568
Bram Moolenaar071d4272004-06-13 20:20:40 +00008569 /*
8570 * Check the bounds for numeric options here
8571 */
8572 if (Rows < min_rows() && full_screen)
8573 {
8574 if (errbuf != NULL)
8575 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008576 vim_snprintf((char *)errbuf, errbuflen,
8577 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008578 errmsg = errbuf;
8579 }
8580 Rows = min_rows();
8581 }
8582 if (Columns < MIN_COLUMNS && full_screen)
8583 {
8584 if (errbuf != NULL)
8585 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008586 vim_snprintf((char *)errbuf, errbuflen,
8587 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588 errmsg = errbuf;
8589 }
8590 Columns = MIN_COLUMNS;
8591 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008592 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008593
8594#ifdef DJGPP
8595 /* avoid a crash by checking for a too large value of 'columns' */
8596 if (old_Columns != Columns && full_screen && term_console)
8597 mch_check_columns();
8598#endif
8599
8600 /*
8601 * If the screen (shell) height has been changed, assume it is the
8602 * physical screenheight.
8603 */
8604 if (old_Rows != Rows || old_Columns != Columns)
8605 {
8606 /* Changing the screen size is not allowed while updating the screen. */
8607 if (updating_screen)
8608 *pp = old_value;
8609 else if (full_screen
8610#ifdef FEAT_GUI
8611 && !gui.starting
8612#endif
8613 )
8614 set_shellsize((int)Columns, (int)Rows, TRUE);
8615 else
8616 {
8617 /* Postpone the resizing; check the size and cmdline position for
8618 * messages. */
8619 check_shellsize();
8620 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8621 cmdline_row = Rows - p_ch;
8622 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008623 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008624 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625 }
8626
Bram Moolenaar071d4272004-06-13 20:20:40 +00008627 if (curbuf->b_p_ts <= 0)
8628 {
8629 errmsg = e_positive;
8630 curbuf->b_p_ts = 8;
8631 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008632 if (p_tm < 0)
8633 {
8634 errmsg = e_positive;
8635 p_tm = 0;
8636 }
8637 if ((curwin->w_p_scr <= 0
8638 || (curwin->w_p_scr > curwin->w_height
8639 && curwin->w_height > 0))
8640 && full_screen)
8641 {
8642 if (pp == &(curwin->w_p_scr))
8643 {
8644 if (curwin->w_p_scr != 0)
8645 errmsg = e_scroll;
8646 win_comp_scroll(curwin);
8647 }
8648 /* If 'scroll' became invalid because of a side effect silently adjust
8649 * it. */
8650 else if (curwin->w_p_scr <= 0)
8651 curwin->w_p_scr = 1;
8652 else /* curwin->w_p_scr > curwin->w_height */
8653 curwin->w_p_scr = curwin->w_height;
8654 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008655 if (p_hi < 0)
8656 {
8657 errmsg = e_positive;
8658 p_hi = 0;
8659 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008660 else if (p_hi > 10000)
8661 {
8662 errmsg = e_invarg;
8663 p_hi = 10000;
8664 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008665 if (p_re < 0 || p_re > 2)
8666 {
8667 errmsg = e_invarg;
8668 p_re = 0;
8669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008670 if (p_report < 0)
8671 {
8672 errmsg = e_positive;
8673 p_report = 1;
8674 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008675 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676 {
8677 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8678 p_sj = Rows / 2;
8679 else
8680 {
8681 errmsg = e_scroll;
8682 p_sj = 1;
8683 }
8684 }
8685 if (p_so < 0 && full_screen)
8686 {
8687 errmsg = e_scroll;
8688 p_so = 0;
8689 }
8690 if (p_siso < 0 && full_screen)
8691 {
8692 errmsg = e_positive;
8693 p_siso = 0;
8694 }
8695#ifdef FEAT_CMDWIN
8696 if (p_cwh < 1)
8697 {
8698 errmsg = e_positive;
8699 p_cwh = 1;
8700 }
8701#endif
8702 if (p_ut < 0)
8703 {
8704 errmsg = e_positive;
8705 p_ut = 2000;
8706 }
8707 if (p_ss < 0)
8708 {
8709 errmsg = e_positive;
8710 p_ss = 0;
8711 }
8712
8713 /* May set global value for local option. */
8714 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8715 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8716
8717 options[opt_idx].flags |= P_WAS_SET;
8718
8719 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008720 if (curwin->w_curswant != MAXCOL
8721 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8722 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723 check_redraw(options[opt_idx].flags);
8724
8725 return errmsg;
8726}
8727
8728/*
8729 * Called after an option changed: check if something needs to be redrawn.
8730 */
8731 static void
8732check_redraw(flags)
8733 long_u flags;
8734{
8735 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008736 int doclear = (flags & P_RCLR) == P_RCLR;
8737 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008738
8739#ifdef FEAT_WINDOWS
8740 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8741 status_redraw_all();
8742#endif
8743
8744 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8745 changed_window_setting();
8746 if (flags & P_RBUF)
8747 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008748 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008749 redraw_all_later(CLEAR);
8750 else if (all)
8751 redraw_all_later(NOT_VALID);
8752}
8753
8754/*
8755 * Find index for option 'arg'.
8756 * Return -1 if not found.
8757 */
8758 static int
8759findoption(arg)
8760 char_u *arg;
8761{
8762 int opt_idx;
8763 char *s, *p;
8764 static short quick_tab[27] = {0, 0}; /* quick access table */
8765 int is_term_opt;
8766
8767 /*
8768 * For first call: Initialize the quick-access table.
8769 * It contains the index for the first option that starts with a certain
8770 * letter. There are 26 letters, plus the first "t_" option.
8771 */
8772 if (quick_tab[1] == 0)
8773 {
8774 p = options[0].fullname;
8775 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8776 {
8777 if (s[0] != p[0])
8778 {
8779 if (s[0] == 't' && s[1] == '_')
8780 quick_tab[26] = opt_idx;
8781 else
8782 quick_tab[CharOrdLow(s[0])] = opt_idx;
8783 }
8784 p = s;
8785 }
8786 }
8787
8788 /*
8789 * Check for name starting with an illegal character.
8790 */
8791#ifdef EBCDIC
8792 if (!islower(arg[0]))
8793#else
8794 if (arg[0] < 'a' || arg[0] > 'z')
8795#endif
8796 return -1;
8797
8798 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8799 if (is_term_opt)
8800 opt_idx = quick_tab[26];
8801 else
8802 opt_idx = quick_tab[CharOrdLow(arg[0])];
8803 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8804 {
8805 if (STRCMP(arg, s) == 0) /* match full name */
8806 break;
8807 }
8808 if (s == NULL && !is_term_opt)
8809 {
8810 opt_idx = quick_tab[CharOrdLow(arg[0])];
8811 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8812 {
8813 s = options[opt_idx].shortname;
8814 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8815 break;
8816 s = NULL;
8817 }
8818 }
8819 if (s == NULL)
8820 opt_idx = -1;
8821 return opt_idx;
8822}
8823
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008824#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008825/*
8826 * Get the value for an option.
8827 *
8828 * Returns:
8829 * Number or Toggle option: 1, *numval gets value.
8830 * String option: 0, *stringval gets allocated string.
8831 * Hidden Number or Toggle option: -1.
8832 * hidden String option: -2.
8833 * unknown option: -3.
8834 */
8835 int
8836get_option_value(name, numval, stringval, opt_flags)
8837 char_u *name;
8838 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008839 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008840 int opt_flags;
8841{
8842 int opt_idx;
8843 char_u *varp;
8844
8845 opt_idx = findoption(name);
8846 if (opt_idx < 0) /* unknown option */
8847 return -3;
8848
8849 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8850
8851 if (options[opt_idx].flags & P_STRING)
8852 {
8853 if (varp == NULL) /* hidden option */
8854 return -2;
8855 if (stringval != NULL)
8856 {
8857#ifdef FEAT_CRYPT
8858 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008859 if ((char_u **)varp == &curbuf->b_p_key
8860 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 *stringval = vim_strsave((char_u *)"*****");
8862 else
8863#endif
8864 *stringval = vim_strsave(*(char_u **)(varp));
8865 }
8866 return 0;
8867 }
8868
8869 if (varp == NULL) /* hidden option */
8870 return -1;
8871 if (options[opt_idx].flags & P_NUM)
8872 *numval = *(long *)varp;
8873 else
8874 {
8875 /* Special case: 'modified' is b_changed, but we also want to consider
8876 * it set when 'ff' or 'fenc' changed. */
8877 if ((int *)varp == &curbuf->b_changed)
8878 *numval = curbufIsChanged();
8879 else
8880 *numval = *(int *)varp;
8881 }
8882 return 1;
8883}
8884#endif
8885
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008886#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008887/*
8888 * Returns the option attributes and its value. Unlike the above function it
8889 * will return either global value or local value of the option depending on
8890 * what was requested, but it will never return global value if it was
8891 * requested to return local one and vice versa. Neither it will return
8892 * buffer-local value if it was requested to return window-local one.
8893 *
8894 * Pretends that option is absent if it is not present in the requested scope
8895 * (i.e. has no global, window-local or buffer-local value depending on
8896 * opt_type). Uses
8897 *
8898 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008899 * 0 hidden or unknown option, also option that does not have requested
8900 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008901 * see SOPT_* in vim.h for other flags
8902 *
8903 * Possible opt_type values: see SREQ_* in vim.h
8904 */
8905 int
8906get_option_value_strict(name, numval, stringval, opt_type, from)
8907 char_u *name;
8908 long *numval;
8909 char_u **stringval; /* NULL when only obtaining attributes */
8910 int opt_type;
8911 void *from;
8912{
8913 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008914 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008915 struct vimoption *p;
8916 int r = 0;
8917
8918 opt_idx = findoption(name);
8919 if (opt_idx < 0)
8920 return 0;
8921
8922 p = &(options[opt_idx]);
8923
8924 /* Hidden option */
8925 if (p->var == NULL)
8926 return 0;
8927
8928 if (p->flags & P_BOOL)
8929 r |= SOPT_BOOL;
8930 else if (p->flags & P_NUM)
8931 r |= SOPT_NUM;
8932 else if (p->flags & P_STRING)
8933 r |= SOPT_STRING;
8934
8935 if (p->indir == PV_NONE)
8936 {
8937 if (opt_type == SREQ_GLOBAL)
8938 r |= SOPT_GLOBAL;
8939 else
8940 return 0; /* Did not request global-only option */
8941 }
8942 else
8943 {
8944 if (p->indir & PV_BOTH)
8945 r |= SOPT_GLOBAL;
8946 else if (opt_type == SREQ_GLOBAL)
8947 return 0; /* Requested global option */
8948
8949 if (p->indir & PV_WIN)
8950 {
8951 if (opt_type == SREQ_BUF)
8952 return 0; /* Did not request window-local option */
8953 else
8954 r |= SOPT_WIN;
8955 }
8956 else if (p->indir & PV_BUF)
8957 {
8958 if (opt_type == SREQ_WIN)
8959 return 0; /* Did not request buffer-local option */
8960 else
8961 r |= SOPT_BUF;
8962 }
8963 }
8964
8965 if (stringval == NULL)
8966 return r;
8967
8968 if (opt_type == SREQ_GLOBAL)
8969 varp = p->var;
8970 else
8971 {
8972 if (opt_type == SREQ_BUF)
8973 {
8974 /* Special case: 'modified' is b_changed, but we also want to
8975 * consider it set when 'ff' or 'fenc' changed. */
8976 if (p->indir == PV_MOD)
8977 {
8978 *numval = bufIsChanged((buf_T *) from);
8979 varp = NULL;
8980 }
8981#ifdef FEAT_CRYPT
8982 else if (p->indir == PV_KEY)
8983 {
8984 /* never return the value of the crypt key */
8985 *stringval = NULL;
8986 varp = NULL;
8987 }
8988#endif
8989 else
8990 {
8991 aco_save_T aco;
8992 aucmd_prepbuf(&aco, (buf_T *) from);
8993 varp = get_varp(p);
8994 aucmd_restbuf(&aco);
8995 }
8996 }
8997 else if (opt_type == SREQ_WIN)
8998 {
8999 win_T *save_curwin;
9000 save_curwin = curwin;
9001 curwin = (win_T *) from;
9002 curbuf = curwin->w_buffer;
9003 varp = get_varp(p);
9004 curwin = save_curwin;
9005 curbuf = curwin->w_buffer;
9006 }
9007 if (varp == p->var)
9008 return (r | SOPT_UNSET);
9009 }
9010
9011 if (varp != NULL)
9012 {
9013 if (p->flags & P_STRING)
9014 *stringval = vim_strsave(*(char_u **)(varp));
9015 else if (p->flags & P_NUM)
9016 *numval = *(long *) varp;
9017 else
9018 *numval = *(int *)varp;
9019 }
9020
9021 return r;
9022}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009023
9024/*
9025 * Iterate over options. First argument is a pointer to a pointer to a structure
9026 * inside options[] array, second is option type like in the above function.
9027 *
9028 * If first argument points to NULL it is assumed that iteration just started
9029 * and caller needs the very first value.
9030 * If first argument points to the end marker function returns NULL and sets
9031 * first argument to NULL.
9032 *
9033 * Returns full option name for current option on each call.
9034 */
9035 char_u *
9036option_iter_next(option, opt_type)
9037 void **option;
9038 int opt_type;
9039{
9040 struct vimoption *ret = NULL;
9041 do
9042 {
9043 if (*option == NULL)
9044 *option = (void *) options;
9045 else if (((struct vimoption *) (*option))->fullname == NULL)
9046 {
9047 *option = NULL;
9048 return NULL;
9049 }
9050 else
9051 *option = (void *) (((struct vimoption *) (*option)) + 1);
9052
9053 ret = ((struct vimoption *) (*option));
9054
9055 /* Hidden option */
9056 if (ret->var == NULL)
9057 {
9058 ret = NULL;
9059 continue;
9060 }
9061
9062 switch (opt_type)
9063 {
9064 case SREQ_GLOBAL:
9065 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9066 ret = NULL;
9067 break;
9068 case SREQ_BUF:
9069 if (!(ret->indir & PV_BUF))
9070 ret = NULL;
9071 break;
9072 case SREQ_WIN:
9073 if (!(ret->indir & PV_WIN))
9074 ret = NULL;
9075 break;
9076 default:
9077 EMSG2(_(e_intern2), "option_iter_next()");
9078 return NULL;
9079 }
9080 }
9081 while (ret == NULL);
9082
9083 return (char_u *)ret->fullname;
9084}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009085#endif
9086
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087/*
9088 * Set the value of option "name".
9089 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009090 *
9091 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009093 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094set_option_value(name, number, string, opt_flags)
9095 char_u *name;
9096 long number;
9097 char_u *string;
9098 int opt_flags; /* OPT_LOCAL or 0 (both) */
9099{
9100 int opt_idx;
9101 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009102 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103
9104 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009105 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009106 EMSG2(_("E355: Unknown option: %s"), name);
9107 else
9108 {
9109 flags = options[opt_idx].flags;
9110#ifdef HAVE_SANDBOX
9111 /* Disallow changing some options in the sandbox */
9112 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009113 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009114 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009115 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009116 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009118 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009119 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009120 else
9121 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009122 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009123 if (varp != NULL) /* hidden option is not changed */
9124 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009125 if (number == 0 && string != NULL)
9126 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009127 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009128
9129 /* Either we are given a string or we are setting option
9130 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009131 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009132 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009133 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009134 {
9135 /* There's another character after zeros or the string
9136 * is empty. In both cases, we are trying to set a
9137 * num option using a string. */
9138 EMSG3(_("E521: Number required: &%s = '%s'"),
9139 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009140 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009141
9142 }
9143 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009144 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009145 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009146 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009147 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009148 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009149 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009150 }
9151 }
9152 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009153 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009154}
9155
9156/*
9157 * Get the terminal code for a terminal option.
9158 * Returns NULL when not found.
9159 */
9160 char_u *
9161get_term_code(tname)
9162 char_u *tname;
9163{
9164 int opt_idx;
9165 char_u *varp;
9166
9167 if (tname[0] != 't' || tname[1] != '_' ||
9168 tname[2] == NUL || tname[3] == NUL)
9169 return NULL;
9170 if ((opt_idx = findoption(tname)) >= 0)
9171 {
9172 varp = get_varp(&(options[opt_idx]));
9173 if (varp != NULL)
9174 varp = *(char_u **)(varp);
9175 return varp;
9176 }
9177 return find_termcode(tname + 2);
9178}
9179
9180 char_u *
9181get_highlight_default()
9182{
9183 int i;
9184
9185 i = findoption((char_u *)"hl");
9186 if (i >= 0)
9187 return options[i].def_val[VI_DEFAULT];
9188 return (char_u *)NULL;
9189}
9190
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009191#if defined(FEAT_MBYTE) || defined(PROTO)
9192 char_u *
9193get_encoding_default()
9194{
9195 int i;
9196
9197 i = findoption((char_u *)"enc");
9198 if (i >= 0)
9199 return options[i].def_val[VI_DEFAULT];
9200 return (char_u *)NULL;
9201}
9202#endif
9203
Bram Moolenaar071d4272004-06-13 20:20:40 +00009204/*
9205 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9206 */
9207 static int
9208find_key_option(arg)
9209 char_u *arg;
9210{
9211 int key;
9212 int modifiers;
9213
9214 /*
9215 * Don't use get_special_key_code() for t_xx, we don't want it to call
9216 * add_termcap_entry().
9217 */
9218 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9219 key = TERMCAP2KEY(arg[2], arg[3]);
9220 else
9221 {
9222 --arg; /* put arg at the '<' */
9223 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009224 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009225 if (modifiers) /* can't handle modifiers here */
9226 key = 0;
9227 }
9228 return key;
9229}
9230
9231/*
9232 * if 'all' == 0: show changed options
9233 * if 'all' == 1: show all normal options
9234 * if 'all' == 2: show all terminal options
9235 */
9236 static void
9237showoptions(all, opt_flags)
9238 int all;
9239 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9240{
9241 struct vimoption *p;
9242 int col;
9243 int isterm;
9244 char_u *varp;
9245 struct vimoption **items;
9246 int item_count;
9247 int run;
9248 int row, rows;
9249 int cols;
9250 int i;
9251 int len;
9252
9253#define INC 20
9254#define GAP 3
9255
9256 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9257 PARAM_COUNT));
9258 if (items == NULL)
9259 return;
9260
9261 /* Highlight title */
9262 if (all == 2)
9263 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9264 else if (opt_flags & OPT_GLOBAL)
9265 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9266 else if (opt_flags & OPT_LOCAL)
9267 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9268 else
9269 MSG_PUTS_TITLE(_("\n--- Options ---"));
9270
9271 /*
9272 * do the loop two times:
9273 * 1. display the short items
9274 * 2. display the long items (only strings and numbers)
9275 */
9276 for (run = 1; run <= 2 && !got_int; ++run)
9277 {
9278 /*
9279 * collect the items in items[]
9280 */
9281 item_count = 0;
9282 for (p = &options[0]; p->fullname != NULL; p++)
9283 {
9284 varp = NULL;
9285 isterm = istermoption(p);
9286 if (opt_flags != 0)
9287 {
9288 if (p->indir != PV_NONE && !isterm)
9289 varp = get_varp_scope(p, opt_flags);
9290 }
9291 else
9292 varp = get_varp(p);
9293 if (varp != NULL
9294 && ((all == 2 && isterm)
9295 || (all == 1 && !isterm)
9296 || (all == 0 && !optval_default(p, varp))))
9297 {
9298 if (p->flags & P_BOOL)
9299 len = 1; /* a toggle option fits always */
9300 else
9301 {
9302 option_value2string(p, opt_flags);
9303 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9304 }
9305 if ((len <= INC - GAP && run == 1) ||
9306 (len > INC - GAP && run == 2))
9307 items[item_count++] = p;
9308 }
9309 }
9310
9311 /*
9312 * display the items
9313 */
9314 if (run == 1)
9315 {
9316 cols = (Columns + GAP - 3) / INC;
9317 if (cols == 0)
9318 cols = 1;
9319 rows = (item_count + cols - 1) / cols;
9320 }
9321 else /* run == 2 */
9322 rows = item_count;
9323 for (row = 0; row < rows && !got_int; ++row)
9324 {
9325 msg_putchar('\n'); /* go to next line */
9326 if (got_int) /* 'q' typed in more */
9327 break;
9328 col = 0;
9329 for (i = row; i < item_count; i += rows)
9330 {
9331 msg_col = col; /* make columns */
9332 showoneopt(items[i], opt_flags);
9333 col += INC;
9334 }
9335 out_flush();
9336 ui_breakcheck();
9337 }
9338 }
9339 vim_free(items);
9340}
9341
9342/*
9343 * Return TRUE if option "p" has its default value.
9344 */
9345 static int
9346optval_default(p, varp)
9347 struct vimoption *p;
9348 char_u *varp;
9349{
9350 int dvi;
9351
9352 if (varp == NULL)
9353 return TRUE; /* hidden option is always at default */
9354 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9355 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009356 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009357 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009358 /* the cast to long is required for Manx C, long_i is
9359 * needed for MSVC */
9360 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361 /* P_STRING */
9362 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9363}
9364
9365/*
9366 * showoneopt: show the value of one option
9367 * must not be called with a hidden option!
9368 */
9369 static void
9370showoneopt(p, opt_flags)
9371 struct vimoption *p;
9372 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9373{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009374 char_u *varp;
9375 int save_silent = silent_mode;
9376
9377 silent_mode = FALSE;
9378 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009379
9380 varp = get_varp_scope(p, opt_flags);
9381
9382 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9383 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9384 ? !curbufIsChanged() : !*(int *)varp))
9385 MSG_PUTS("no");
9386 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9387 MSG_PUTS("--");
9388 else
9389 MSG_PUTS(" ");
9390 MSG_PUTS(p->fullname);
9391 if (!(p->flags & P_BOOL))
9392 {
9393 msg_putchar('=');
9394 /* put value string in NameBuff */
9395 option_value2string(p, opt_flags);
9396 msg_outtrans(NameBuff);
9397 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009398
9399 silent_mode = save_silent;
9400 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009401}
9402
9403/*
9404 * Write modified options as ":set" commands to a file.
9405 *
9406 * There are three values for "opt_flags":
9407 * OPT_GLOBAL: Write global option values and fresh values of
9408 * buffer-local options (used for start of a session
9409 * file).
9410 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9411 * curwin (used for a vimrc file).
9412 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9413 * and local values for window-local options of
9414 * curwin. Local values are also written when at the
9415 * default value, because a modeline or autocommand
9416 * may have set them when doing ":edit file" and the
9417 * user has set them back at the default or fresh
9418 * value.
9419 * When "local_only" is TRUE, don't write fresh
9420 * values, only local values (for ":mkview").
9421 * (fresh value = value used for a new buffer or window for a local option).
9422 *
9423 * Return FAIL on error, OK otherwise.
9424 */
9425 int
9426makeset(fd, opt_flags, local_only)
9427 FILE *fd;
9428 int opt_flags;
9429 int local_only;
9430{
9431 struct vimoption *p;
9432 char_u *varp; /* currently used value */
9433 char_u *varp_fresh; /* local value */
9434 char_u *varp_local = NULL; /* fresh value */
9435 char *cmd;
9436 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009437 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009438
9439 /*
9440 * The options that don't have a default (terminal name, columns, lines)
9441 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009442 * Do the loop over "options[]" twice: once for options with the
9443 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009444 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009445 for (pri = 1; pri >= 0; --pri)
9446 {
9447 for (p = &options[0]; !istermoption(p); p++)
9448 if (!(p->flags & P_NO_MKRC)
9449 && !istermoption(p)
9450 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009451 {
9452 /* skip global option when only doing locals */
9453 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9454 continue;
9455
9456 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9457 * file, they are always buffer-specific. */
9458 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9459 continue;
9460
9461 /* Global values are only written when not at the default value. */
9462 varp = get_varp_scope(p, opt_flags);
9463 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9464 continue;
9465
9466 round = 2;
9467 if (p->indir != PV_NONE)
9468 {
9469 if (p->var == VAR_WIN)
9470 {
9471 /* skip window-local option when only doing globals */
9472 if (!(opt_flags & OPT_LOCAL))
9473 continue;
9474 /* When fresh value of window-local option is not at the
9475 * default, need to write it too. */
9476 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9477 {
9478 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9479 if (!optval_default(p, varp_fresh))
9480 {
9481 round = 1;
9482 varp_local = varp;
9483 varp = varp_fresh;
9484 }
9485 }
9486 }
9487 }
9488
9489 /* Round 1: fresh value for window-local options.
9490 * Round 2: other values */
9491 for ( ; round <= 2; varp = varp_local, ++round)
9492 {
9493 if (round == 1 || (opt_flags & OPT_GLOBAL))
9494 cmd = "set";
9495 else
9496 cmd = "setlocal";
9497
9498 if (p->flags & P_BOOL)
9499 {
9500 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9501 return FAIL;
9502 }
9503 else if (p->flags & P_NUM)
9504 {
9505 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9506 return FAIL;
9507 }
9508 else /* P_STRING */
9509 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009510#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9511 int do_endif = FALSE;
9512
Bram Moolenaar071d4272004-06-13 20:20:40 +00009513 /* Don't set 'syntax' and 'filetype' again if the value is
9514 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009515 if (
9516# if defined(FEAT_SYN_HL)
9517 p->indir == PV_SYN
9518# if defined(FEAT_AUTOCMD)
9519 ||
9520# endif
9521# endif
9522# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009523 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009524# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009525 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009526 {
9527 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9528 *(char_u **)(varp)) < 0
9529 || put_eol(fd) < 0)
9530 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009531 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009532 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009534 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9535 (p->flags & P_EXPAND) != 0) == FAIL)
9536 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009537#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9538 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009539 {
9540 if (put_line(fd, "endif") == FAIL)
9541 return FAIL;
9542 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009543#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009544 }
9545 }
9546 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009547 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009548 return OK;
9549}
9550
9551#if defined(FEAT_FOLDING) || defined(PROTO)
9552/*
9553 * Generate set commands for the local fold options only. Used when
9554 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9555 */
9556 int
9557makefoldset(fd)
9558 FILE *fd;
9559{
9560 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9561# ifdef FEAT_EVAL
9562 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9563 == FAIL
9564# endif
9565 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9566 == FAIL
9567 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9568 == FAIL
9569 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9570 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9571 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9572 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9573 )
9574 return FAIL;
9575
9576 return OK;
9577}
9578#endif
9579
9580 static int
9581put_setstring(fd, cmd, name, valuep, expand)
9582 FILE *fd;
9583 char *cmd;
9584 char *name;
9585 char_u **valuep;
9586 int expand;
9587{
9588 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009589 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009590
9591 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9592 return FAIL;
9593 if (*valuep != NULL)
9594 {
9595 /* Output 'pastetoggle' as key names. For other
9596 * options some characters have to be escaped with
9597 * CTRL-V or backslash */
9598 if (valuep == &p_pt)
9599 {
9600 s = *valuep;
9601 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009602 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009603 return FAIL;
9604 }
9605 else if (expand)
9606 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009607 buf = alloc(MAXPATHL);
9608 if (buf == NULL)
9609 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009610 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9611 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009612 {
9613 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009614 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009615 }
9616 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009617 }
9618 else if (put_escstr(fd, *valuep, 2) == FAIL)
9619 return FAIL;
9620 }
9621 if (put_eol(fd) < 0)
9622 return FAIL;
9623 return OK;
9624}
9625
9626 static int
9627put_setnum(fd, cmd, name, valuep)
9628 FILE *fd;
9629 char *cmd;
9630 char *name;
9631 long *valuep;
9632{
9633 long wc;
9634
9635 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9636 return FAIL;
9637 if (wc_use_keyname((char_u *)valuep, &wc))
9638 {
9639 /* print 'wildchar' and 'wildcharm' as a key name */
9640 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9641 return FAIL;
9642 }
9643 else if (fprintf(fd, "%ld", *valuep) < 0)
9644 return FAIL;
9645 if (put_eol(fd) < 0)
9646 return FAIL;
9647 return OK;
9648}
9649
9650 static int
9651put_setbool(fd, cmd, name, value)
9652 FILE *fd;
9653 char *cmd;
9654 char *name;
9655 int value;
9656{
Bram Moolenaar893de922007-10-02 18:40:57 +00009657 if (value < 0) /* global/local option using global value */
9658 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009659 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9660 || put_eol(fd) < 0)
9661 return FAIL;
9662 return OK;
9663}
9664
9665/*
9666 * Clear all the terminal options.
9667 * If the option has been allocated, free the memory.
9668 * Terminal options are never hidden or indirect.
9669 */
9670 void
9671clear_termoptions()
9672{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009673 /*
9674 * Reset a few things before clearing the old options. This may cause
9675 * outputting a few things that the terminal doesn't understand, but the
9676 * screen will be cleared later, so this is OK.
9677 */
9678#ifdef FEAT_MOUSE_TTY
9679 mch_setmouse(FALSE); /* switch mouse off */
9680#endif
9681#ifdef FEAT_TITLE
9682 mch_restore_title(3); /* restore window titles */
9683#endif
9684#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9685 /* When starting the GUI close the display opened for the clipboard.
9686 * After restoring the title, because that will need the display. */
9687 if (gui.starting)
9688 clear_xterm_clip();
9689#endif
9690#ifdef WIN3264
9691 /*
9692 * Check if this is allowed now.
9693 */
9694 if (can_end_termcap_mode(FALSE) == TRUE)
9695#endif
9696 stoptermcap(); /* stop termcap mode */
9697
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009698 free_termoptions();
9699}
9700
9701 void
9702free_termoptions()
9703{
9704 struct vimoption *p;
9705
Bram Moolenaar071d4272004-06-13 20:20:40 +00009706 for (p = &options[0]; p->fullname != NULL; p++)
9707 if (istermoption(p))
9708 {
9709 if (p->flags & P_ALLOCED)
9710 free_string_option(*(char_u **)(p->var));
9711 if (p->flags & P_DEF_ALLOCED)
9712 free_string_option(p->def_val[VI_DEFAULT]);
9713 *(char_u **)(p->var) = empty_option;
9714 p->def_val[VI_DEFAULT] = empty_option;
9715 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9716 }
9717 clear_termcodes();
9718}
9719
9720/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009721 * Free the string for one term option, if it was allocated.
9722 * Set the string to empty_option and clear allocated flag.
9723 * "var" points to the option value.
9724 */
9725 void
9726free_one_termoption(var)
9727 char_u *var;
9728{
9729 struct vimoption *p;
9730
9731 for (p = &options[0]; p->fullname != NULL; p++)
9732 if (p->var == var)
9733 {
9734 if (p->flags & P_ALLOCED)
9735 free_string_option(*(char_u **)(p->var));
9736 *(char_u **)(p->var) = empty_option;
9737 p->flags &= ~P_ALLOCED;
9738 break;
9739 }
9740}
9741
9742/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009743 * Set the terminal option defaults to the current value.
9744 * Used after setting the terminal name.
9745 */
9746 void
9747set_term_defaults()
9748{
9749 struct vimoption *p;
9750
9751 for (p = &options[0]; p->fullname != NULL; p++)
9752 {
9753 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9754 {
9755 if (p->flags & P_DEF_ALLOCED)
9756 {
9757 free_string_option(p->def_val[VI_DEFAULT]);
9758 p->flags &= ~P_DEF_ALLOCED;
9759 }
9760 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9761 if (p->flags & P_ALLOCED)
9762 {
9763 p->flags |= P_DEF_ALLOCED;
9764 p->flags &= ~P_ALLOCED; /* don't free the value now */
9765 }
9766 }
9767 }
9768}
9769
9770/*
9771 * return TRUE if 'p' starts with 't_'
9772 */
9773 static int
9774istermoption(p)
9775 struct vimoption *p;
9776{
9777 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9778}
9779
9780/*
9781 * Compute columns for ruler and shown command. 'sc_col' is also used to
9782 * decide what the maximum length of a message on the status line can be.
9783 * If there is a status line for the last window, 'sc_col' is independent
9784 * of 'ru_col'.
9785 */
9786
9787#define COL_RULER 17 /* columns needed by standard ruler */
9788
9789 void
9790comp_col()
9791{
9792#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9793 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9794
9795 sc_col = 0;
9796 ru_col = 0;
9797 if (p_ru)
9798 {
9799#ifdef FEAT_STL_OPT
9800 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9801#else
9802 ru_col = COL_RULER + 1;
9803#endif
9804 /* no last status line, adjust sc_col */
9805 if (!last_has_status)
9806 sc_col = ru_col;
9807 }
9808 if (p_sc)
9809 {
9810 sc_col += SHOWCMD_COLS;
9811 if (!p_ru || last_has_status) /* no need for separating space */
9812 ++sc_col;
9813 }
9814 sc_col = Columns - sc_col;
9815 ru_col = Columns - ru_col;
9816 if (sc_col <= 0) /* screen too narrow, will become a mess */
9817 sc_col = 1;
9818 if (ru_col <= 0)
9819 ru_col = 1;
9820#else
9821 sc_col = Columns;
9822 ru_col = Columns;
9823#endif
9824}
9825
9826/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009827 * Unset local option value, similar to ":set opt<".
9828 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009829 void
9830unset_global_local_option(name, from)
9831 char_u *name;
9832 void *from;
9833{
9834 struct vimoption *p;
9835 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009836 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009837
9838 opt_idx = findoption(name);
9839 p = &(options[opt_idx]);
9840
9841 switch ((int)p->indir)
9842 {
9843 /* global option with local value: use local value if it's been set */
9844 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009845 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009846 break;
9847 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009848 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009849 break;
9850 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009851 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009852 break;
9853 case PV_AR:
9854 buf->b_p_ar = -1;
9855 break;
9856 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009857 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009858 break;
9859#ifdef FEAT_FIND_ID
9860 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009861 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009862 break;
9863 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009864 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009865 break;
9866#endif
9867#ifdef FEAT_INS_EXPAND
9868 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009869 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009870 break;
9871 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009872 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009873 break;
9874#endif
9875#ifdef FEAT_QUICKFIX
9876 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009877 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009878 break;
9879 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009880 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009881 break;
9882 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009883 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009884 break;
9885#endif
9886#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9887 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009888 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009889 break;
9890#endif
9891#if defined(FEAT_CRYPT)
9892 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009893 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009894 break;
9895#endif
9896#ifdef FEAT_STL_OPT
9897 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009898 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009899 break;
9900#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009901 case PV_UL:
9902 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9903 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009904#ifdef FEAT_LISP
9905 case PV_LW:
9906 clear_string_option(&buf->b_p_lw);
9907 break;
9908#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009909 }
9910}
9911
9912/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009913 * Get pointer to option variable, depending on local or global scope.
9914 */
9915 static char_u *
9916get_varp_scope(p, opt_flags)
9917 struct vimoption *p;
9918 int opt_flags;
9919{
9920 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9921 {
9922 if (p->var == VAR_WIN)
9923 return (char_u *)GLOBAL_WO(get_varp(p));
9924 return p->var;
9925 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009926 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009927 {
9928 switch ((int)p->indir)
9929 {
9930#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009931 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9932 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9933 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009934#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009935 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9936 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9937 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009938 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009939 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009941 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9942 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009943#endif
9944#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009945 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9946 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009947#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009948#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9949 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9950#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009951#if defined(FEAT_CRYPT)
9952 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9953#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009954#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009955 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009956#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009957 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009958#ifdef FEAT_LISP
9959 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9960#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961 }
9962 return NULL; /* "cannot happen" */
9963 }
9964 return get_varp(p);
9965}
9966
9967/*
9968 * Get pointer to option variable.
9969 */
9970 static char_u *
9971get_varp(p)
9972 struct vimoption *p;
9973{
9974 /* hidden option, always return NULL */
9975 if (p->var == NULL)
9976 return NULL;
9977
9978 switch ((int)p->indir)
9979 {
9980 case PV_NONE: return p->var;
9981
9982 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009983 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009985 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009986 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009987 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009988 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009989 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009990 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009991 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9993#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009994 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009995 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009996 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009997 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9998#endif
9999#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010000 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010001 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010002 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010003 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10004#endif
10005#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010006 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010007 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010008 case PV_GP: return *curbuf->b_p_gp != NUL
10009 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10010 case PV_MP: return *curbuf->b_p_mp != NUL
10011 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010012#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010013#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10014 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10015 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10016#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010017#if defined(FEAT_CRYPT)
10018 case PV_CM: return *curbuf->b_p_cm != NUL
10019 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10020#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010021#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010022 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010023 ? (char_u *)&(curwin->w_p_stl) : p->var;
10024#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010025 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10026 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010027#ifdef FEAT_LISP
10028 case PV_LW: return *curbuf->b_p_lw != NUL
10029 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031
10032#ifdef FEAT_ARABIC
10033 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10034#endif
10035 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010036#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010037 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10038#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010039#ifdef FEAT_SYN_HL
10040 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10041 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010042 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010043#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010044#ifdef FEAT_DIFF
10045 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10046#endif
10047#ifdef FEAT_FOLDING
10048 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10049 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10050 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10051 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10052 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10053 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10054 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10055# ifdef FEAT_EVAL
10056 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10057 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10058# endif
10059 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10060#endif
10061 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010062 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010063#ifdef FEAT_LINEBREAK
10064 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10065#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010066#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010067 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10068#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010069#ifdef FEAT_VERTSPLIT
10070 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010072#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10073 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10074#endif
10075#ifdef FEAT_RIGHTLEFT
10076 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10077 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10078#endif
10079 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10080 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10081#ifdef FEAT_LINEBREAK
10082 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010083 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10084 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010085#endif
10086#ifdef FEAT_SCROLLBIND
10087 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10088#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010089#ifdef FEAT_CURSORBIND
10090 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10091#endif
10092#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010093 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10094 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010096
10097 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10098 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10099#ifdef FEAT_MBYTE
10100 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10101#endif
10102#if defined(FEAT_QUICKFIX)
10103 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10104 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10105#endif
10106 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10107 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10108#ifdef FEAT_CINDENT
10109 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10110 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10111 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10112#endif
10113#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10114 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10115#endif
10116#ifdef FEAT_COMMENTS
10117 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10118#endif
10119#ifdef FEAT_FOLDING
10120 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10121#endif
10122#ifdef FEAT_INS_EXPAND
10123 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10124#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010125#ifdef FEAT_COMPL_FUNC
10126 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010127 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010128#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10130 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10131#ifdef FEAT_MBYTE
10132 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10133#endif
10134 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10135#ifdef FEAT_AUTOCMD
10136 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10137#endif
10138 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010139 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010140 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10141 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10142 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10143 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10144#ifdef FEAT_FIND_ID
10145# ifdef FEAT_EVAL
10146 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10147# endif
10148#endif
10149#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10150 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10151 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10152#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010153#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010154 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10155#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010156#ifdef FEAT_CRYPT
10157 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10158#endif
10159#ifdef FEAT_LISP
10160 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10161#endif
10162 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10163 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10164 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10165 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10166 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010167 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010168#ifdef FEAT_TEXTOBJ
10169 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10170#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10172#ifdef FEAT_SMARTINDENT
10173 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10174#endif
10175#ifndef SHORT_FNAME
10176 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10177#endif
10178 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10179#ifdef FEAT_SEARCHPATH
10180 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10181#endif
10182 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10183#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010184 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010185 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10186#endif
10187#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010188 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10189 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10190 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191#endif
10192 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10193 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10194 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10195 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010196#ifdef FEAT_PERSISTENT_UNDO
10197 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10198#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10200#ifdef FEAT_KEYMAP
10201 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10202#endif
10203 default: EMSG(_("E356: get_varp ERROR"));
10204 }
10205 /* always return a valid pointer to avoid a crash! */
10206 return (char_u *)&(curbuf->b_p_wm);
10207}
10208
10209/*
10210 * Get the value of 'equalprg', either the buffer-local one or the global one.
10211 */
10212 char_u *
10213get_equalprg()
10214{
10215 if (*curbuf->b_p_ep == NUL)
10216 return p_ep;
10217 return curbuf->b_p_ep;
10218}
10219
10220#if defined(FEAT_WINDOWS) || defined(PROTO)
10221/*
10222 * Copy options from one window to another.
10223 * Used when splitting a window.
10224 */
10225 void
10226win_copy_options(wp_from, wp_to)
10227 win_T *wp_from;
10228 win_T *wp_to;
10229{
10230 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10231 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10232# ifdef FEAT_RIGHTLEFT
10233# ifdef FEAT_FKMAP
10234 /* Is this right? */
10235 wp_to->w_farsi = wp_from->w_farsi;
10236# endif
10237# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010238#if defined(FEAT_LINEBREAK)
10239 briopt_check(wp_to);
10240#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241}
10242#endif
10243
10244/*
10245 * Copy the options from one winopt_T to another.
10246 * Doesn't free the old option values in "to", use clear_winopt() for that.
10247 * The 'scroll' option is not copied, because it depends on the window height.
10248 * The 'previewwindow' option is reset, there can be only one preview window.
10249 */
10250 void
10251copy_winopt(from, to)
10252 winopt_T *from;
10253 winopt_T *to;
10254{
10255#ifdef FEAT_ARABIC
10256 to->wo_arab = from->wo_arab;
10257#endif
10258 to->wo_list = from->wo_list;
10259 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010260 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010261#ifdef FEAT_LINEBREAK
10262 to->wo_nuw = from->wo_nuw;
10263#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264#ifdef FEAT_RIGHTLEFT
10265 to->wo_rl = from->wo_rl;
10266 to->wo_rlc = vim_strsave(from->wo_rlc);
10267#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010268#ifdef FEAT_STL_OPT
10269 to->wo_stl = vim_strsave(from->wo_stl);
10270#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010272#ifdef FEAT_DIFF
10273 to->wo_wrap_save = from->wo_wrap_save;
10274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010275#ifdef FEAT_LINEBREAK
10276 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010277 to->wo_bri = from->wo_bri;
10278 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279#endif
10280#ifdef FEAT_SCROLLBIND
10281 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010282 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010283#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010284#ifdef FEAT_CURSORBIND
10285 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010286 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010287#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010288#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010289 to->wo_spell = from->wo_spell;
10290#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010291#ifdef FEAT_SYN_HL
10292 to->wo_cuc = from->wo_cuc;
10293 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010294 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010295#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010296#ifdef FEAT_DIFF
10297 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010298 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010299#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010300#ifdef FEAT_CONCEAL
10301 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010302 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010303#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010304#ifdef FEAT_FOLDING
10305 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010306 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010308 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010309 to->wo_fdi = vim_strsave(from->wo_fdi);
10310 to->wo_fml = from->wo_fml;
10311 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010312 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010313 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010314 to->wo_fdm_save = from->wo_diff_saved
10315 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010316 to->wo_fdn = from->wo_fdn;
10317# ifdef FEAT_EVAL
10318 to->wo_fde = vim_strsave(from->wo_fde);
10319 to->wo_fdt = vim_strsave(from->wo_fdt);
10320# endif
10321 to->wo_fmr = vim_strsave(from->wo_fmr);
10322#endif
10323 check_winopt(to); /* don't want NULL pointers */
10324}
10325
10326/*
10327 * Check string options in a window for a NULL value.
10328 */
10329 void
10330check_win_options(win)
10331 win_T *win;
10332{
10333 check_winopt(&win->w_onebuf_opt);
10334 check_winopt(&win->w_allbuf_opt);
10335}
10336
10337/*
10338 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10339 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010340 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010342 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343{
10344#ifdef FEAT_FOLDING
10345 check_string_option(&wop->wo_fdi);
10346 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010347 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348# ifdef FEAT_EVAL
10349 check_string_option(&wop->wo_fde);
10350 check_string_option(&wop->wo_fdt);
10351# endif
10352 check_string_option(&wop->wo_fmr);
10353#endif
10354#ifdef FEAT_RIGHTLEFT
10355 check_string_option(&wop->wo_rlc);
10356#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010357#ifdef FEAT_STL_OPT
10358 check_string_option(&wop->wo_stl);
10359#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010360#ifdef FEAT_SYN_HL
10361 check_string_option(&wop->wo_cc);
10362#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010363#ifdef FEAT_CONCEAL
10364 check_string_option(&wop->wo_cocu);
10365#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010366#ifdef FEAT_LINEBREAK
10367 check_string_option(&wop->wo_briopt);
10368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010369}
10370
10371/*
10372 * Free the allocated memory inside a winopt_T.
10373 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010374 void
10375clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010376 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010377{
10378#ifdef FEAT_FOLDING
10379 clear_string_option(&wop->wo_fdi);
10380 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010381 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010382# ifdef FEAT_EVAL
10383 clear_string_option(&wop->wo_fde);
10384 clear_string_option(&wop->wo_fdt);
10385# endif
10386 clear_string_option(&wop->wo_fmr);
10387#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010388#ifdef FEAT_LINEBREAK
10389 clear_string_option(&wop->wo_briopt);
10390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010391#ifdef FEAT_RIGHTLEFT
10392 clear_string_option(&wop->wo_rlc);
10393#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010394#ifdef FEAT_STL_OPT
10395 clear_string_option(&wop->wo_stl);
10396#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010397#ifdef FEAT_SYN_HL
10398 clear_string_option(&wop->wo_cc);
10399#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010400#ifdef FEAT_CONCEAL
10401 clear_string_option(&wop->wo_cocu);
10402#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403}
10404
10405/*
10406 * Copy global option values to local options for one buffer.
10407 * Used when creating a new buffer and sometimes when entering a buffer.
10408 * flags:
10409 * BCO_ENTER We will enter the buf buffer.
10410 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10411 * appropriate.
10412 * BCO_NOHELP Don't copy the values to a help buffer.
10413 */
10414 void
10415buf_copy_options(buf, flags)
10416 buf_T *buf;
10417 int flags;
10418{
10419 int should_copy = TRUE;
10420 char_u *save_p_isk = NULL; /* init for GCC */
10421 int dont_do_help;
10422 int did_isk = FALSE;
10423
10424 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010425 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426 */
10427 if (buf == NULL || !buf_valid(buf))
10428 return;
10429
10430 /*
10431 * Skip this when the option defaults have not been set yet. Happens when
10432 * main() allocates the first buffer.
10433 */
10434 if (p_cpo != NULL)
10435 {
10436 /*
10437 * Always copy when entering and 'cpo' contains 'S'.
10438 * Don't copy when already initialized.
10439 * Don't copy when 'cpo' contains 's' and not entering.
10440 * 'S' BCO_ENTER initialized 's' should_copy
10441 * yes yes X X TRUE
10442 * yes no yes X FALSE
10443 * no X yes X FALSE
10444 * X no no yes FALSE
10445 * X no no no TRUE
10446 * no yes no X TRUE
10447 */
10448 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10449 && (buf->b_p_initialized
10450 || (!(flags & BCO_ENTER)
10451 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10452 should_copy = FALSE;
10453
10454 if (should_copy || (flags & BCO_ALWAYS))
10455 {
10456 /* Don't copy the options specific to a help buffer when
10457 * BCO_NOHELP is given or the options were initialized already
10458 * (jumping back to a help file with CTRL-T or CTRL-O) */
10459 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10460 || buf->b_p_initialized;
10461 if (dont_do_help) /* don't free b_p_isk */
10462 {
10463 save_p_isk = buf->b_p_isk;
10464 buf->b_p_isk = NULL;
10465 }
10466 /*
10467 * Always free the allocated strings.
10468 * If not already initialized, set 'readonly' and copy 'fileformat'.
10469 */
10470 if (!buf->b_p_initialized)
10471 {
10472 free_buf_options(buf, TRUE);
10473 buf->b_p_ro = FALSE; /* don't copy readonly */
10474 buf->b_p_tx = p_tx;
10475#ifdef FEAT_MBYTE
10476 buf->b_p_fenc = vim_strsave(p_fenc);
10477#endif
10478 buf->b_p_ff = vim_strsave(p_ff);
10479#if defined(FEAT_QUICKFIX)
10480 buf->b_p_bh = empty_option;
10481 buf->b_p_bt = empty_option;
10482#endif
10483 }
10484 else
10485 free_buf_options(buf, FALSE);
10486
10487 buf->b_p_ai = p_ai;
10488 buf->b_p_ai_nopaste = p_ai_nopaste;
10489 buf->b_p_sw = p_sw;
10490 buf->b_p_tw = p_tw;
10491 buf->b_p_tw_nopaste = p_tw_nopaste;
10492 buf->b_p_tw_nobin = p_tw_nobin;
10493 buf->b_p_wm = p_wm;
10494 buf->b_p_wm_nopaste = p_wm_nopaste;
10495 buf->b_p_wm_nobin = p_wm_nobin;
10496 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010497#ifdef FEAT_MBYTE
10498 buf->b_p_bomb = p_bomb;
10499#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500 buf->b_p_et = p_et;
10501 buf->b_p_et_nobin = p_et_nobin;
10502 buf->b_p_ml = p_ml;
10503 buf->b_p_ml_nobin = p_ml_nobin;
10504 buf->b_p_inf = p_inf;
10505 buf->b_p_swf = p_swf;
10506#ifdef FEAT_INS_EXPAND
10507 buf->b_p_cpt = vim_strsave(p_cpt);
10508#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010509#ifdef FEAT_COMPL_FUNC
10510 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010511 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010512#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010513 buf->b_p_sts = p_sts;
10514 buf->b_p_sts_nopaste = p_sts_nopaste;
10515#ifndef SHORT_FNAME
10516 buf->b_p_sn = p_sn;
10517#endif
10518#ifdef FEAT_COMMENTS
10519 buf->b_p_com = vim_strsave(p_com);
10520#endif
10521#ifdef FEAT_FOLDING
10522 buf->b_p_cms = vim_strsave(p_cms);
10523#endif
10524 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010525 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526 buf->b_p_nf = vim_strsave(p_nf);
10527 buf->b_p_mps = vim_strsave(p_mps);
10528#ifdef FEAT_SMARTINDENT
10529 buf->b_p_si = p_si;
10530#endif
10531 buf->b_p_ci = p_ci;
10532#ifdef FEAT_CINDENT
10533 buf->b_p_cin = p_cin;
10534 buf->b_p_cink = vim_strsave(p_cink);
10535 buf->b_p_cino = vim_strsave(p_cino);
10536#endif
10537#ifdef FEAT_AUTOCMD
10538 /* Don't copy 'filetype', it must be detected */
10539 buf->b_p_ft = empty_option;
10540#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541 buf->b_p_pi = p_pi;
10542#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10543 buf->b_p_cinw = vim_strsave(p_cinw);
10544#endif
10545#ifdef FEAT_LISP
10546 buf->b_p_lisp = p_lisp;
10547#endif
10548#ifdef FEAT_SYN_HL
10549 /* Don't copy 'syntax', it must be set */
10550 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010551 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010552#endif
10553#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010554 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010555 (void)compile_cap_prog(&buf->b_s);
10556 buf->b_s.b_p_spf = vim_strsave(p_spf);
10557 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010558#endif
10559#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10560 buf->b_p_inde = vim_strsave(p_inde);
10561 buf->b_p_indk = vim_strsave(p_indk);
10562#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010563#if defined(FEAT_EVAL)
10564 buf->b_p_fex = vim_strsave(p_fex);
10565#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566#ifdef FEAT_CRYPT
10567 buf->b_p_key = vim_strsave(p_key);
10568#endif
10569#ifdef FEAT_SEARCHPATH
10570 buf->b_p_sua = vim_strsave(p_sua);
10571#endif
10572#ifdef FEAT_KEYMAP
10573 buf->b_p_keymap = vim_strsave(p_keymap);
10574 buf->b_kmap_state |= KEYMAP_INIT;
10575#endif
10576 /* This isn't really an option, but copying the langmap and IME
10577 * state from the current buffer is better than resetting it. */
10578 buf->b_p_iminsert = p_iminsert;
10579 buf->b_p_imsearch = p_imsearch;
10580
10581 /* options that are normally global but also have a local value
10582 * are not copied, start using the global value */
10583 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010584 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585#ifdef FEAT_QUICKFIX
10586 buf->b_p_gp = empty_option;
10587 buf->b_p_mp = empty_option;
10588 buf->b_p_efm = empty_option;
10589#endif
10590 buf->b_p_ep = empty_option;
10591 buf->b_p_kp = empty_option;
10592 buf->b_p_path = empty_option;
10593 buf->b_p_tags = empty_option;
10594#ifdef FEAT_FIND_ID
10595 buf->b_p_def = empty_option;
10596 buf->b_p_inc = empty_option;
10597# ifdef FEAT_EVAL
10598 buf->b_p_inex = vim_strsave(p_inex);
10599# endif
10600#endif
10601#ifdef FEAT_INS_EXPAND
10602 buf->b_p_dict = empty_option;
10603 buf->b_p_tsr = empty_option;
10604#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010605#ifdef FEAT_TEXTOBJ
10606 buf->b_p_qe = vim_strsave(p_qe);
10607#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010608#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10609 buf->b_p_bexpr = empty_option;
10610#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010611#if defined(FEAT_CRYPT)
10612 buf->b_p_cm = empty_option;
10613#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010614#ifdef FEAT_PERSISTENT_UNDO
10615 buf->b_p_udf = p_udf;
10616#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010617#ifdef FEAT_LISP
10618 buf->b_p_lw = empty_option;
10619#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620
10621 /*
10622 * Don't copy the options set by ex_help(), use the saved values,
10623 * when going from a help buffer to a non-help buffer.
10624 * Don't touch these at all when BCO_NOHELP is used and going from
10625 * or to a help buffer.
10626 */
10627 if (dont_do_help)
10628 buf->b_p_isk = save_p_isk;
10629 else
10630 {
10631 buf->b_p_isk = vim_strsave(p_isk);
10632 did_isk = TRUE;
10633 buf->b_p_ts = p_ts;
10634 buf->b_help = FALSE;
10635#ifdef FEAT_QUICKFIX
10636 if (buf->b_p_bt[0] == 'h')
10637 clear_string_option(&buf->b_p_bt);
10638#endif
10639 buf->b_p_ma = p_ma;
10640 }
10641 }
10642
10643 /*
10644 * When the options should be copied (ignoring BCO_ALWAYS), set the
10645 * flag that indicates that the options have been initialized.
10646 */
10647 if (should_copy)
10648 buf->b_p_initialized = TRUE;
10649 }
10650
10651 check_buf_options(buf); /* make sure we don't have NULLs */
10652 if (did_isk)
10653 (void)buf_init_chartab(buf, FALSE);
10654}
10655
10656/*
10657 * Reset the 'modifiable' option and its default value.
10658 */
10659 void
10660reset_modifiable()
10661{
10662 int opt_idx;
10663
10664 curbuf->b_p_ma = FALSE;
10665 p_ma = FALSE;
10666 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010667 if (opt_idx >= 0)
10668 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010669}
10670
10671/*
10672 * Set the global value for 'iminsert' to the local value.
10673 */
10674 void
10675set_iminsert_global()
10676{
10677 p_iminsert = curbuf->b_p_iminsert;
10678}
10679
10680/*
10681 * Set the global value for 'imsearch' to the local value.
10682 */
10683 void
10684set_imsearch_global()
10685{
10686 p_imsearch = curbuf->b_p_imsearch;
10687}
10688
10689#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10690static int expand_option_idx = -1;
10691static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10692static int expand_option_flags = 0;
10693
10694 void
10695set_context_in_set_cmd(xp, arg, opt_flags)
10696 expand_T *xp;
10697 char_u *arg;
10698 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10699{
10700 int nextchar;
10701 long_u flags = 0; /* init for GCC */
10702 int opt_idx = 0; /* init for GCC */
10703 char_u *p;
10704 char_u *s;
10705 int is_term_option = FALSE;
10706 int key;
10707
10708 expand_option_flags = opt_flags;
10709
10710 xp->xp_context = EXPAND_SETTINGS;
10711 if (*arg == NUL)
10712 {
10713 xp->xp_pattern = arg;
10714 return;
10715 }
10716 p = arg + STRLEN(arg) - 1;
10717 if (*p == ' ' && *(p - 1) != '\\')
10718 {
10719 xp->xp_pattern = p + 1;
10720 return;
10721 }
10722 while (p > arg)
10723 {
10724 s = p;
10725 /* count number of backslashes before ' ' or ',' */
10726 if (*p == ' ' || *p == ',')
10727 {
10728 while (s > arg && *(s - 1) == '\\')
10729 --s;
10730 }
10731 /* break at a space with an even number of backslashes */
10732 if (*p == ' ' && ((p - s) & 1) == 0)
10733 {
10734 ++p;
10735 break;
10736 }
10737 --p;
10738 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010739 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010740 {
10741 xp->xp_context = EXPAND_BOOL_SETTINGS;
10742 p += 2;
10743 }
10744 if (STRNCMP(p, "inv", 3) == 0)
10745 {
10746 xp->xp_context = EXPAND_BOOL_SETTINGS;
10747 p += 3;
10748 }
10749 xp->xp_pattern = arg = p;
10750 if (*arg == '<')
10751 {
10752 while (*p != '>')
10753 if (*p++ == NUL) /* expand terminal option name */
10754 return;
10755 key = get_special_key_code(arg + 1);
10756 if (key == 0) /* unknown name */
10757 {
10758 xp->xp_context = EXPAND_NOTHING;
10759 return;
10760 }
10761 nextchar = *++p;
10762 is_term_option = TRUE;
10763 expand_option_name[2] = KEY2TERMCAP0(key);
10764 expand_option_name[3] = KEY2TERMCAP1(key);
10765 }
10766 else
10767 {
10768 if (p[0] == 't' && p[1] == '_')
10769 {
10770 p += 2;
10771 if (*p != NUL)
10772 ++p;
10773 if (*p == NUL)
10774 return; /* expand option name */
10775 nextchar = *++p;
10776 is_term_option = TRUE;
10777 expand_option_name[2] = p[-2];
10778 expand_option_name[3] = p[-1];
10779 }
10780 else
10781 {
10782 /* Allow * wildcard */
10783 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10784 p++;
10785 if (*p == NUL)
10786 return;
10787 nextchar = *p;
10788 *p = NUL;
10789 opt_idx = findoption(arg);
10790 *p = nextchar;
10791 if (opt_idx == -1 || options[opt_idx].var == NULL)
10792 {
10793 xp->xp_context = EXPAND_NOTHING;
10794 return;
10795 }
10796 flags = options[opt_idx].flags;
10797 if (flags & P_BOOL)
10798 {
10799 xp->xp_context = EXPAND_NOTHING;
10800 return;
10801 }
10802 }
10803 }
10804 /* handle "-=" and "+=" */
10805 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10806 {
10807 ++p;
10808 nextchar = '=';
10809 }
10810 if ((nextchar != '=' && nextchar != ':')
10811 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10812 {
10813 xp->xp_context = EXPAND_UNSUCCESSFUL;
10814 return;
10815 }
10816 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10817 {
10818 xp->xp_context = EXPAND_OLD_SETTING;
10819 if (is_term_option)
10820 expand_option_idx = -1;
10821 else
10822 expand_option_idx = opt_idx;
10823 xp->xp_pattern = p + 1;
10824 return;
10825 }
10826 xp->xp_context = EXPAND_NOTHING;
10827 if (is_term_option || (flags & P_NUM))
10828 return;
10829
10830 xp->xp_pattern = p + 1;
10831
10832 if (flags & P_EXPAND)
10833 {
10834 p = options[opt_idx].var;
10835 if (p == (char_u *)&p_bdir
10836 || p == (char_u *)&p_dir
10837 || p == (char_u *)&p_path
10838 || p == (char_u *)&p_rtp
10839#ifdef FEAT_SEARCHPATH
10840 || p == (char_u *)&p_cdpath
10841#endif
10842#ifdef FEAT_SESSION
10843 || p == (char_u *)&p_vdir
10844#endif
10845 )
10846 {
10847 xp->xp_context = EXPAND_DIRECTORIES;
10848 if (p == (char_u *)&p_path
10849#ifdef FEAT_SEARCHPATH
10850 || p == (char_u *)&p_cdpath
10851#endif
10852 )
10853 xp->xp_backslash = XP_BS_THREE;
10854 else
10855 xp->xp_backslash = XP_BS_ONE;
10856 }
10857 else
10858 {
10859 xp->xp_context = EXPAND_FILES;
10860 /* for 'tags' need three backslashes for a space */
10861 if (p == (char_u *)&p_tags)
10862 xp->xp_backslash = XP_BS_THREE;
10863 else
10864 xp->xp_backslash = XP_BS_ONE;
10865 }
10866 }
10867
10868 /* For an option that is a list of file names, find the start of the
10869 * last file name. */
10870 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10871 {
10872 /* count number of backslashes before ' ' or ',' */
10873 if (*p == ' ' || *p == ',')
10874 {
10875 s = p;
10876 while (s > xp->xp_pattern && *(s - 1) == '\\')
10877 --s;
10878 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10879 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10880 {
10881 xp->xp_pattern = p + 1;
10882 break;
10883 }
10884 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010885
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010886#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010887 /* for 'spellsuggest' start at "file:" */
10888 if (options[opt_idx].var == (char_u *)&p_sps
10889 && STRNCMP(p, "file:", 5) == 0)
10890 {
10891 xp->xp_pattern = p + 5;
10892 break;
10893 }
10894#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895 }
10896
10897 return;
10898}
10899
10900 int
10901ExpandSettings(xp, regmatch, num_file, file)
10902 expand_T *xp;
10903 regmatch_T *regmatch;
10904 int *num_file;
10905 char_u ***file;
10906{
10907 int num_normal = 0; /* Nr of matching non-term-code settings */
10908 int num_term = 0; /* Nr of matching terminal code settings */
10909 int opt_idx;
10910 int match;
10911 int count = 0;
10912 char_u *str;
10913 int loop;
10914 int is_term_opt;
10915 char_u name_buf[MAX_KEY_NAME_LEN];
10916 static char *(names[]) = {"all", "termcap"};
10917 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10918
10919 /* do this loop twice:
10920 * loop == 0: count the number of matching options
10921 * loop == 1: copy the matching options into allocated memory
10922 */
10923 for (loop = 0; loop <= 1; ++loop)
10924 {
10925 regmatch->rm_ic = ic;
10926 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10927 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010928 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10929 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010930 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10931 {
10932 if (loop == 0)
10933 num_normal++;
10934 else
10935 (*file)[count++] = vim_strsave((char_u *)names[match]);
10936 }
10937 }
10938 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10939 opt_idx++)
10940 {
10941 if (options[opt_idx].var == NULL)
10942 continue;
10943 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10944 && !(options[opt_idx].flags & P_BOOL))
10945 continue;
10946 is_term_opt = istermoption(&options[opt_idx]);
10947 if (is_term_opt && num_normal > 0)
10948 continue;
10949 match = FALSE;
10950 if (vim_regexec(regmatch, str, (colnr_T)0)
10951 || (options[opt_idx].shortname != NULL
10952 && vim_regexec(regmatch,
10953 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10954 match = TRUE;
10955 else if (is_term_opt)
10956 {
10957 name_buf[0] = '<';
10958 name_buf[1] = 't';
10959 name_buf[2] = '_';
10960 name_buf[3] = str[2];
10961 name_buf[4] = str[3];
10962 name_buf[5] = '>';
10963 name_buf[6] = NUL;
10964 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10965 {
10966 match = TRUE;
10967 str = name_buf;
10968 }
10969 }
10970 if (match)
10971 {
10972 if (loop == 0)
10973 {
10974 if (is_term_opt)
10975 num_term++;
10976 else
10977 num_normal++;
10978 }
10979 else
10980 (*file)[count++] = vim_strsave(str);
10981 }
10982 }
10983 /*
10984 * Check terminal key codes, these are not in the option table
10985 */
10986 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10987 {
10988 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10989 {
10990 if (!isprint(str[0]) || !isprint(str[1]))
10991 continue;
10992
10993 name_buf[0] = 't';
10994 name_buf[1] = '_';
10995 name_buf[2] = str[0];
10996 name_buf[3] = str[1];
10997 name_buf[4] = NUL;
10998
10999 match = FALSE;
11000 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11001 match = TRUE;
11002 else
11003 {
11004 name_buf[0] = '<';
11005 name_buf[1] = 't';
11006 name_buf[2] = '_';
11007 name_buf[3] = str[0];
11008 name_buf[4] = str[1];
11009 name_buf[5] = '>';
11010 name_buf[6] = NUL;
11011
11012 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11013 match = TRUE;
11014 }
11015 if (match)
11016 {
11017 if (loop == 0)
11018 num_term++;
11019 else
11020 (*file)[count++] = vim_strsave(name_buf);
11021 }
11022 }
11023
11024 /*
11025 * Check special key names.
11026 */
11027 regmatch->rm_ic = TRUE; /* ignore case here */
11028 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11029 {
11030 name_buf[0] = '<';
11031 STRCPY(name_buf + 1, str);
11032 STRCAT(name_buf, ">");
11033
11034 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11035 {
11036 if (loop == 0)
11037 num_term++;
11038 else
11039 (*file)[count++] = vim_strsave(name_buf);
11040 }
11041 }
11042 }
11043 if (loop == 0)
11044 {
11045 if (num_normal > 0)
11046 *num_file = num_normal;
11047 else if (num_term > 0)
11048 *num_file = num_term;
11049 else
11050 return OK;
11051 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11052 if (*file == NULL)
11053 {
11054 *file = (char_u **)"";
11055 return FAIL;
11056 }
11057 }
11058 }
11059 return OK;
11060}
11061
11062 int
11063ExpandOldSetting(num_file, file)
11064 int *num_file;
11065 char_u ***file;
11066{
11067 char_u *var = NULL; /* init for GCC */
11068 char_u *buf;
11069
11070 *num_file = 0;
11071 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11072 if (*file == NULL)
11073 return FAIL;
11074
11075 /*
11076 * For a terminal key code expand_option_idx is < 0.
11077 */
11078 if (expand_option_idx < 0)
11079 {
11080 var = find_termcode(expand_option_name + 2);
11081 if (var == NULL)
11082 expand_option_idx = findoption(expand_option_name);
11083 }
11084
11085 if (expand_option_idx >= 0)
11086 {
11087 /* put string of option value in NameBuff */
11088 option_value2string(&options[expand_option_idx], expand_option_flags);
11089 var = NameBuff;
11090 }
11091 else if (var == NULL)
11092 var = (char_u *)"";
11093
11094 /* A backslash is required before some characters. This is the reverse of
11095 * what happens in do_set(). */
11096 buf = vim_strsave_escaped(var, escape_chars);
11097
11098 if (buf == NULL)
11099 {
11100 vim_free(*file);
11101 *file = NULL;
11102 return FAIL;
11103 }
11104
11105#ifdef BACKSLASH_IN_FILENAME
11106 /* For MS-Windows et al. we don't double backslashes at the start and
11107 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011108 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109 if (var[0] == '\\' && var[1] == '\\'
11110 && expand_option_idx >= 0
11111 && (options[expand_option_idx].flags & P_EXPAND)
11112 && vim_isfilec(var[2])
11113 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011114 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011115#endif
11116
11117 *file[0] = buf;
11118 *num_file = 1;
11119 return OK;
11120}
11121#endif
11122
11123/*
11124 * Get the value for the numeric or string option *opp in a nice format into
11125 * NameBuff[]. Must not be called with a hidden option!
11126 */
11127 static void
11128option_value2string(opp, opt_flags)
11129 struct vimoption *opp;
11130 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11131{
11132 char_u *varp;
11133
11134 varp = get_varp_scope(opp, opt_flags);
11135
11136 if (opp->flags & P_NUM)
11137 {
11138 long wc = 0;
11139
11140 if (wc_use_keyname(varp, &wc))
11141 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11142 else if (wc != 0)
11143 STRCPY(NameBuff, transchar((int)wc));
11144 else
11145 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11146 }
11147 else /* P_STRING */
11148 {
11149 varp = *(char_u **)(varp);
11150 if (varp == NULL) /* just in case */
11151 NameBuff[0] = NUL;
11152#ifdef FEAT_CRYPT
11153 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011154 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155 STRCPY(NameBuff, "*****");
11156#endif
11157 else if (opp->flags & P_EXPAND)
11158 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11159 /* Translate 'pastetoggle' into special key names */
11160 else if ((char_u **)opp->var == &p_pt)
11161 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11162 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011163 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164 }
11165}
11166
11167/*
11168 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11169 * printed as a keyname.
11170 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11171 */
11172 static int
11173wc_use_keyname(varp, wcp)
11174 char_u *varp;
11175 long *wcp;
11176{
11177 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11178 {
11179 *wcp = *(long *)varp;
11180 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11181 return TRUE;
11182 }
11183 return FALSE;
11184}
11185
11186#ifdef FEAT_LANGMAP
11187/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011188 * Any character has an equivalent 'langmap' character. This is used for
11189 * keyboards that have a special language mode that sends characters above
11190 * 128 (although other characters can be translated too). The "to" field is a
11191 * Vim command character. This avoids having to switch the keyboard back to
11192 * ASCII mode when leaving Insert mode.
11193 *
11194 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11195 * commands.
11196 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11197 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11198 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011199 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011200# ifdef FEAT_MBYTE
11201/*
11202 * With multi-byte support use growarray for 'langmap' chars >= 256
11203 */
11204typedef struct
11205{
11206 int from;
11207 int to;
11208} langmap_entry_T;
11209
11210static garray_T langmap_mapga;
11211static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011212
11213/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011214 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11215 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011216 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011217 static void
11218langmap_set_entry(from, to)
11219 int from;
11220 int to;
11221{
11222 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011223 int a = 0;
11224 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011225
11226 /* Do a binary search for an existing entry. */
11227 while (a != b)
11228 {
11229 int i = (a + b) / 2;
11230 int d = entries[i].from - from;
11231
11232 if (d == 0)
11233 {
11234 entries[i].to = to;
11235 return;
11236 }
11237 if (d < 0)
11238 a = i + 1;
11239 else
11240 b = i;
11241 }
11242
11243 if (ga_grow(&langmap_mapga, 1) != OK)
11244 return; /* out of memory */
11245
11246 /* insert new entry at position "a" */
11247 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11248 mch_memmove(entries + 1, entries,
11249 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11250 ++langmap_mapga.ga_len;
11251 entries[0].from = from;
11252 entries[0].to = to;
11253}
11254
11255/*
11256 * Apply 'langmap' to multi-byte character "c" and return the result.
11257 */
11258 int
11259langmap_adjust_mb(c)
11260 int c;
11261{
11262 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11263 int a = 0;
11264 int b = langmap_mapga.ga_len;
11265
11266 while (a != b)
11267 {
11268 int i = (a + b) / 2;
11269 int d = entries[i].from - c;
11270
11271 if (d == 0)
11272 return entries[i].to; /* found matching entry */
11273 if (d < 0)
11274 a = i + 1;
11275 else
11276 b = i;
11277 }
11278 return c; /* no entry found, return "c" unmodified */
11279}
11280# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011281
11282 static void
11283langmap_init()
11284{
11285 int i;
11286
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011287 for (i = 0; i < 256; i++)
11288 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11289# ifdef FEAT_MBYTE
11290 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11291# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011292}
11293
11294/*
11295 * Called when langmap option is set; the language map can be
11296 * changed at any time!
11297 */
11298 static void
11299langmap_set()
11300{
11301 char_u *p;
11302 char_u *p2;
11303 int from, to;
11304
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011305#ifdef FEAT_MBYTE
11306 ga_clear(&langmap_mapga); /* clear the previous map first */
11307#endif
11308 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011309
11310 for (p = p_langmap; p[0] != NUL; )
11311 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011312 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11313 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011314 {
11315 if (p2[0] == '\\' && p2[1] != NUL)
11316 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011317 }
11318 if (p2[0] == ';')
11319 ++p2; /* abcd;ABCD form, p2 points to A */
11320 else
11321 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11322 while (p[0])
11323 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011324 if (p[0] == ',')
11325 {
11326 ++p;
11327 break;
11328 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011329 if (p[0] == '\\' && p[1] != NUL)
11330 ++p;
11331#ifdef FEAT_MBYTE
11332 from = (*mb_ptr2char)(p);
11333#else
11334 from = p[0];
11335#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011336 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011337 if (p2 == NULL)
11338 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011339 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011340 if (p[0] != ',')
11341 {
11342 if (p[0] == '\\')
11343 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011344#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011345 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011346#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011347 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011348#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011349 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350 }
11351 else
11352 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011353 if (p2[0] != ',')
11354 {
11355 if (p2[0] == '\\')
11356 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011357#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011358 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011359#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011360 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011361#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011362 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011363 }
11364 if (to == NUL)
11365 {
11366 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11367 transchar(from));
11368 return;
11369 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011370
11371#ifdef FEAT_MBYTE
11372 if (from >= 256)
11373 langmap_set_entry(from, to);
11374 else
11375#endif
11376 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011377
11378 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011379 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011380 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011381 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011382 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011383 if (*p == ';')
11384 {
11385 p = p2;
11386 if (p[0] != NUL)
11387 {
11388 if (p[0] != ',')
11389 {
11390 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11391 return;
11392 }
11393 ++p;
11394 }
11395 break;
11396 }
11397 }
11398 }
11399 }
11400}
11401#endif
11402
11403/*
11404 * Return TRUE if format option 'x' is in effect.
11405 * Take care of no formatting when 'paste' is set.
11406 */
11407 int
11408has_format_option(x)
11409 int x;
11410{
11411 if (p_paste)
11412 return FALSE;
11413 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11414}
11415
11416/*
11417 * Return TRUE if "x" is present in 'shortmess' option, or
11418 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11419 */
11420 int
11421shortmess(x)
11422 int x;
11423{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011424 return p_shm != NULL &&
11425 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011426 || (vim_strchr(p_shm, 'a') != NULL
11427 && vim_strchr((char_u *)SHM_A, x) != NULL));
11428}
11429
11430/*
11431 * paste_option_changed() - Called after p_paste was set or reset.
11432 */
11433 static void
11434paste_option_changed()
11435{
11436 static int old_p_paste = FALSE;
11437 static int save_sm = 0;
11438#ifdef FEAT_CMDL_INFO
11439 static int save_ru = 0;
11440#endif
11441#ifdef FEAT_RIGHTLEFT
11442 static int save_ri = 0;
11443 static int save_hkmap = 0;
11444#endif
11445 buf_T *buf;
11446
11447 if (p_paste)
11448 {
11449 /*
11450 * Paste switched from off to on.
11451 * Save the current values, so they can be restored later.
11452 */
11453 if (!old_p_paste)
11454 {
11455 /* save options for each buffer */
11456 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11457 {
11458 buf->b_p_tw_nopaste = buf->b_p_tw;
11459 buf->b_p_wm_nopaste = buf->b_p_wm;
11460 buf->b_p_sts_nopaste = buf->b_p_sts;
11461 buf->b_p_ai_nopaste = buf->b_p_ai;
11462 }
11463
11464 /* save global options */
11465 save_sm = p_sm;
11466#ifdef FEAT_CMDL_INFO
11467 save_ru = p_ru;
11468#endif
11469#ifdef FEAT_RIGHTLEFT
11470 save_ri = p_ri;
11471 save_hkmap = p_hkmap;
11472#endif
11473 /* save global values for local buffer options */
11474 p_tw_nopaste = p_tw;
11475 p_wm_nopaste = p_wm;
11476 p_sts_nopaste = p_sts;
11477 p_ai_nopaste = p_ai;
11478 }
11479
11480 /*
11481 * Always set the option values, also when 'paste' is set when it is
11482 * already on.
11483 */
11484 /* set options for each buffer */
11485 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11486 {
11487 buf->b_p_tw = 0; /* textwidth is 0 */
11488 buf->b_p_wm = 0; /* wrapmargin is 0 */
11489 buf->b_p_sts = 0; /* softtabstop is 0 */
11490 buf->b_p_ai = 0; /* no auto-indent */
11491 }
11492
11493 /* set global options */
11494 p_sm = 0; /* no showmatch */
11495#ifdef FEAT_CMDL_INFO
11496# ifdef FEAT_WINDOWS
11497 if (p_ru)
11498 status_redraw_all(); /* redraw to remove the ruler */
11499# endif
11500 p_ru = 0; /* no ruler */
11501#endif
11502#ifdef FEAT_RIGHTLEFT
11503 p_ri = 0; /* no reverse insert */
11504 p_hkmap = 0; /* no Hebrew keyboard */
11505#endif
11506 /* set global values for local buffer options */
11507 p_tw = 0;
11508 p_wm = 0;
11509 p_sts = 0;
11510 p_ai = 0;
11511 }
11512
11513 /*
11514 * Paste switched from on to off: Restore saved values.
11515 */
11516 else if (old_p_paste)
11517 {
11518 /* restore options for each buffer */
11519 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11520 {
11521 buf->b_p_tw = buf->b_p_tw_nopaste;
11522 buf->b_p_wm = buf->b_p_wm_nopaste;
11523 buf->b_p_sts = buf->b_p_sts_nopaste;
11524 buf->b_p_ai = buf->b_p_ai_nopaste;
11525 }
11526
11527 /* restore global options */
11528 p_sm = save_sm;
11529#ifdef FEAT_CMDL_INFO
11530# ifdef FEAT_WINDOWS
11531 if (p_ru != save_ru)
11532 status_redraw_all(); /* redraw to draw the ruler */
11533# endif
11534 p_ru = save_ru;
11535#endif
11536#ifdef FEAT_RIGHTLEFT
11537 p_ri = save_ri;
11538 p_hkmap = save_hkmap;
11539#endif
11540 /* set global values for local buffer options */
11541 p_tw = p_tw_nopaste;
11542 p_wm = p_wm_nopaste;
11543 p_sts = p_sts_nopaste;
11544 p_ai = p_ai_nopaste;
11545 }
11546
11547 old_p_paste = p_paste;
11548}
11549
11550/*
11551 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11552 *
11553 * Reset 'compatible' and set the values for options that didn't get set yet
11554 * to the Vim defaults.
11555 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011556 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011557 */
11558 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011559vimrc_found(fname, envname)
11560 char_u *fname;
11561 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011562{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011563 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011564 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011565 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011566
11567 if (!option_was_set((char_u *)"cp"))
11568 {
11569 p_cp = FALSE;
11570 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11571 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11572 set_option_default(opt_idx, OPT_FREE, FALSE);
11573 didset_options();
11574 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011575
11576 if (fname != NULL)
11577 {
11578 p = vim_getenv(envname, &dofree);
11579 if (p == NULL)
11580 {
11581 /* Set $MYVIMRC to the first vimrc file found. */
11582 p = FullName_save(fname, FALSE);
11583 if (p != NULL)
11584 {
11585 vim_setenv(envname, p);
11586 vim_free(p);
11587 }
11588 }
11589 else if (dofree)
11590 vim_free(p);
11591 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011592}
11593
11594/*
11595 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11596 */
11597 void
11598change_compatible(on)
11599 int on;
11600{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011601 int opt_idx;
11602
Bram Moolenaar071d4272004-06-13 20:20:40 +000011603 if (p_cp != on)
11604 {
11605 p_cp = on;
11606 compatible_set();
11607 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011608 opt_idx = findoption((char_u *)"cp");
11609 if (opt_idx >= 0)
11610 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011611}
11612
11613/*
11614 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011615 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616 */
11617 int
11618option_was_set(name)
11619 char_u *name;
11620{
11621 int idx;
11622
11623 idx = findoption(name);
11624 if (idx < 0) /* unknown option */
11625 return FALSE;
11626 if (options[idx].flags & P_WAS_SET)
11627 return TRUE;
11628 return FALSE;
11629}
11630
11631/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011632 * Reset the flag indicating option "name" was set.
11633 */
11634 void
11635reset_option_was_set(name)
11636 char_u *name;
11637{
11638 int idx = findoption(name);
11639
11640 if (idx >= 0)
11641 options[idx].flags &= ~P_WAS_SET;
11642}
11643
11644/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011645 * compatible_set() - Called when 'compatible' has been set or unset.
11646 *
11647 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11648 * flag) to a Vi compatible value.
11649 * When 'compatible' is unset: Set all options that have a different default
11650 * for Vim (without the P_VI_DEF flag) to that default.
11651 */
11652 static void
11653compatible_set()
11654{
11655 int opt_idx;
11656
11657 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11658 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11659 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11660 set_option_default(opt_idx, OPT_FREE, p_cp);
11661 didset_options();
11662}
11663
11664#ifdef FEAT_LINEBREAK
11665
11666# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11667 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011668 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011669# endif
11670
11671/*
11672 * fill_breakat_flags() -- called when 'breakat' changes value.
11673 */
11674 static void
11675fill_breakat_flags()
11676{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011677 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011678 int i;
11679
11680 for (i = 0; i < 256; i++)
11681 breakat_flags[i] = FALSE;
11682
11683 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011684 for (p = p_breakat; *p; p++)
11685 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011686}
11687
11688# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011689 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011690# endif
11691
11692#endif
11693
11694/*
11695 * Check an option that can be a range of string values.
11696 *
11697 * Return OK for correct value, FAIL otherwise.
11698 * Empty is always OK.
11699 */
11700 static int
11701check_opt_strings(val, values, list)
11702 char_u *val;
11703 char **values;
11704 int list; /* when TRUE: accept a list of values */
11705{
11706 return opt_strings_flags(val, values, NULL, list);
11707}
11708
11709/*
11710 * Handle an option that can be a range of string values.
11711 * Set a flag in "*flagp" for each string present.
11712 *
11713 * Return OK for correct value, FAIL otherwise.
11714 * Empty is always OK.
11715 */
11716 static int
11717opt_strings_flags(val, values, flagp, list)
11718 char_u *val; /* new value */
11719 char **values; /* array of valid string values */
11720 unsigned *flagp;
11721 int list; /* when TRUE: accept a list of values */
11722{
11723 int i;
11724 int len;
11725 unsigned new_flags = 0;
11726
11727 while (*val)
11728 {
11729 for (i = 0; ; ++i)
11730 {
11731 if (values[i] == NULL) /* val not found in values[] */
11732 return FAIL;
11733
11734 len = (int)STRLEN(values[i]);
11735 if (STRNCMP(values[i], val, len) == 0
11736 && ((list && val[len] == ',') || val[len] == NUL))
11737 {
11738 val += len + (val[len] == ',');
11739 new_flags |= (1 << i);
11740 break; /* check next item in val list */
11741 }
11742 }
11743 }
11744 if (flagp != NULL)
11745 *flagp = new_flags;
11746
11747 return OK;
11748}
11749
11750/*
11751 * Read the 'wildmode' option, fill wim_flags[].
11752 */
11753 static int
11754check_opt_wim()
11755{
11756 char_u new_wim_flags[4];
11757 char_u *p;
11758 int i;
11759 int idx = 0;
11760
11761 for (i = 0; i < 4; ++i)
11762 new_wim_flags[i] = 0;
11763
11764 for (p = p_wim; *p; ++p)
11765 {
11766 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11767 ;
11768 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11769 return FAIL;
11770 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11771 new_wim_flags[idx] |= WIM_LONGEST;
11772 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11773 new_wim_flags[idx] |= WIM_FULL;
11774 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11775 new_wim_flags[idx] |= WIM_LIST;
11776 else
11777 return FAIL;
11778 p += i;
11779 if (*p == NUL)
11780 break;
11781 if (*p == ',')
11782 {
11783 if (idx == 3)
11784 return FAIL;
11785 ++idx;
11786 }
11787 }
11788
11789 /* fill remaining entries with last flag */
11790 while (idx < 3)
11791 {
11792 new_wim_flags[idx + 1] = new_wim_flags[idx];
11793 ++idx;
11794 }
11795
11796 /* only when there are no errors, wim_flags[] is changed */
11797 for (i = 0; i < 4; ++i)
11798 wim_flags[i] = new_wim_flags[i];
11799 return OK;
11800}
11801
11802/*
11803 * Check if backspacing over something is allowed.
11804 */
11805 int
11806can_bs(what)
11807 int what; /* BS_INDENT, BS_EOL or BS_START */
11808{
11809 switch (*p_bs)
11810 {
11811 case '2': return TRUE;
11812 case '1': return (what != BS_START);
11813 case '0': return FALSE;
11814 }
11815 return vim_strchr(p_bs, what) != NULL;
11816}
11817
11818/*
11819 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11820 * the file must be considered changed when the value is different.
11821 */
11822 void
11823save_file_ff(buf)
11824 buf_T *buf;
11825{
11826 buf->b_start_ffc = *buf->b_p_ff;
11827 buf->b_start_eol = buf->b_p_eol;
11828#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011829 buf->b_start_bomb = buf->b_p_bomb;
11830
Bram Moolenaar071d4272004-06-13 20:20:40 +000011831 /* Only use free/alloc when necessary, they take time. */
11832 if (buf->b_start_fenc == NULL
11833 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11834 {
11835 vim_free(buf->b_start_fenc);
11836 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11837 }
11838#endif
11839}
11840
11841/*
11842 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11843 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011844 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11845 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011846 * When "ignore_empty" is true don't consider a new, empty buffer to be
11847 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011848 */
11849 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011850file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011851 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011852 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011853{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011854 /* In a buffer that was never loaded the options are not valid. */
11855 if (buf->b_flags & BF_NEVERLOADED)
11856 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011857 if (ignore_empty
11858 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011859 && buf->b_ml.ml_line_count == 1
11860 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11861 return FALSE;
11862 if (buf->b_start_ffc != *buf->b_p_ff)
11863 return TRUE;
11864 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11865 return TRUE;
11866#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011867 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11868 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011869 if (buf->b_start_fenc == NULL)
11870 return (*buf->b_p_fenc != NUL);
11871 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11872#else
11873 return FALSE;
11874#endif
11875}
11876
11877/*
11878 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11879 */
11880 int
11881check_ff_value(p)
11882 char_u *p;
11883{
11884 return check_opt_strings(p, p_ff_values, FALSE);
11885}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011886
11887/*
11888 * Return the effective shiftwidth value for current buffer, using the
11889 * 'tabstop' value when 'shiftwidth' is zero.
11890 */
11891 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011892get_sw_value(buf)
11893 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011894{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011895 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011896}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011897
11898/*
11899 * Return the effective softtabstop value for the current buffer, using the
11900 * 'tabstop' value when 'softtabstop' is negative.
11901 */
11902 long
11903get_sts_value()
11904{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011905 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011906}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011907
11908/*
11909 * Check matchpairs option for "*initc".
11910 * If there is a match set "*initc" to the matching character and "*findc" to
11911 * the opposite character. Set "*backwards" to the direction.
11912 * When "switchit" is TRUE swap the direction.
11913 */
11914 void
11915find_mps_values(initc, findc, backwards, switchit)
11916 int *initc;
11917 int *findc;
11918 int *backwards;
11919 int switchit;
11920{
11921 char_u *ptr;
11922
11923 ptr = curbuf->b_p_mps;
11924 while (*ptr != NUL)
11925 {
11926#ifdef FEAT_MBYTE
11927 if (has_mbyte)
11928 {
11929 char_u *prev;
11930
11931 if (mb_ptr2char(ptr) == *initc)
11932 {
11933 if (switchit)
11934 {
11935 *findc = *initc;
11936 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11937 *backwards = TRUE;
11938 }
11939 else
11940 {
11941 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11942 *backwards = FALSE;
11943 }
11944 return;
11945 }
11946 prev = ptr;
11947 ptr += mb_ptr2len(ptr) + 1;
11948 if (mb_ptr2char(ptr) == *initc)
11949 {
11950 if (switchit)
11951 {
11952 *findc = *initc;
11953 *initc = mb_ptr2char(prev);
11954 *backwards = FALSE;
11955 }
11956 else
11957 {
11958 *findc = mb_ptr2char(prev);
11959 *backwards = TRUE;
11960 }
11961 return;
11962 }
11963 ptr += mb_ptr2len(ptr);
11964 }
11965 else
11966#endif
11967 {
11968 if (*ptr == *initc)
11969 {
11970 if (switchit)
11971 {
11972 *backwards = TRUE;
11973 *findc = *initc;
11974 *initc = ptr[2];
11975 }
11976 else
11977 {
11978 *backwards = FALSE;
11979 *findc = ptr[2];
11980 }
11981 return;
11982 }
11983 ptr += 2;
11984 if (*ptr == *initc)
11985 {
11986 if (switchit)
11987 {
11988 *backwards = FALSE;
11989 *findc = *initc;
11990 *initc = ptr[-2];
11991 }
11992 else
11993 {
11994 *backwards = TRUE;
11995 *findc = ptr[-2];
11996 }
11997 return;
11998 }
11999 ++ptr;
12000 }
12001 if (*ptr == ',')
12002 ++ptr;
12003 }
12004}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012005
12006#if defined(FEAT_LINEBREAK) || defined(PROTO)
12007/*
12008 * This is called when 'breakindentopt' is changed and when a window is
12009 * initialized.
12010 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012011 static int
12012briopt_check(wp)
12013 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012014{
12015 char_u *p;
12016 int bri_shift = 0;
12017 long bri_min = 20;
12018 int bri_sbr = FALSE;
12019
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012020 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012021 while (*p != NUL)
12022 {
12023 if (STRNCMP(p, "shift:", 6) == 0
12024 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12025 {
12026 p += 6;
12027 bri_shift = getdigits(&p);
12028 }
12029 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12030 {
12031 p += 4;
12032 bri_min = getdigits(&p);
12033 }
12034 else if (STRNCMP(p, "sbr", 3) == 0)
12035 {
12036 p += 3;
12037 bri_sbr = TRUE;
12038 }
12039 if (*p != ',' && *p != NUL)
12040 return FAIL;
12041 if (*p == ',')
12042 ++p;
12043 }
12044
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012045 wp->w_p_brishift = bri_shift;
12046 wp->w_p_brimin = bri_min;
12047 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012048
12049 return OK;
12050}
12051#endif