blob: 2007dee7dbfa32cf79f93d4c654e64319ef4052f [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
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003648#ifdef FEAT_CINDENT
3649 parse_cino(curbuf);
3650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651}
3652
3653/*
3654 * Set the Vi-default value of a string option.
3655 * Used for 'sh', 'backupskip' and 'term'.
3656 */
3657 void
3658set_string_default(name, val)
3659 char *name;
3660 char_u *val;
3661{
3662 char_u *p;
3663 int opt_idx;
3664
3665 p = vim_strsave(val);
3666 if (p != NULL) /* we don't want a NULL */
3667 {
3668 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003669 if (opt_idx >= 0)
3670 {
3671 if (options[opt_idx].flags & P_DEF_ALLOCED)
3672 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3673 options[opt_idx].def_val[VI_DEFAULT] = p;
3674 options[opt_idx].flags |= P_DEF_ALLOCED;
3675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676 }
3677}
3678
3679/*
3680 * Set the Vi-default value of a number option.
3681 * Used for 'lines' and 'columns'.
3682 */
3683 void
3684set_number_default(name, val)
3685 char *name;
3686 long val;
3687{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003688 int opt_idx;
3689
3690 opt_idx = findoption((char_u *)name);
3691 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003692 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003693}
3694
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003695#if defined(EXITFREE) || defined(PROTO)
3696/*
3697 * Free all options.
3698 */
3699 void
3700free_all_options()
3701{
3702 int i;
3703
3704 for (i = 0; !istermoption(&options[i]); i++)
3705 {
3706 if (options[i].indir == PV_NONE)
3707 {
3708 /* global option: free value and default value. */
3709 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3710 free_string_option(*(char_u **)options[i].var);
3711 if (options[i].flags & P_DEF_ALLOCED)
3712 free_string_option(options[i].def_val[VI_DEFAULT]);
3713 }
3714 else if (options[i].var != VAR_WIN
3715 && (options[i].flags & P_STRING))
3716 /* buffer-local option: free global value */
3717 free_string_option(*(char_u **)options[i].var);
3718 }
3719}
3720#endif
3721
3722
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723/*
3724 * Initialize the options, part two: After getting Rows and Columns and
3725 * setting 'term'.
3726 */
3727 void
3728set_init_2()
3729{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003730 int idx;
3731
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732 /*
3733 * 'scroll' defaults to half the window height. Note that this default is
3734 * wrong when the window height changes.
3735 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003736 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003737 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003738 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003739 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740 comp_col();
3741
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003742 /*
3743 * 'window' is only for backwards compatibility with Vi.
3744 * Default is Rows - 1.
3745 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003746 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003747 p_window = Rows - 1;
3748 set_number_default("window", Rows - 1);
3749
Bram Moolenaarf740b292006-02-16 22:11:02 +00003750 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003751#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003752 /*
3753 * If 'background' wasn't set by the user, try guessing the value,
3754 * depending on the terminal name. Only need to check for terminals
3755 * with a dark background, that can handle color.
3756 */
3757 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003758 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3759 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003760 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003761 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003762 /* don't mark it as set, when starting the GUI it may be
3763 * changed again */
3764 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003765 }
3766#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003767
3768#ifdef CURSOR_SHAPE
3769 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3770#endif
3771#ifdef FEAT_MOUSESHAPE
3772 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3773#endif
3774#ifdef FEAT_PRINTER
3775 (void)parse_printoptions(); /* parse 'printoptions' default value */
3776#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777}
3778
3779/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003780 * Return "dark" or "light" depending on the kind of terminal.
3781 * This is just guessing! Recognized are:
3782 * "linux" Linux console
3783 * "screen.linux" Linux console with screen
3784 * "cygwin" Cygwin shell
3785 * "putty" Putty program
3786 * We also check the COLORFGBG environment variable, which is set by
3787 * rxvt and derivatives. This variable contains either two or three
3788 * values separated by semicolons; we want the last value in either
3789 * case. If this value is 0-6 or 8, our background is dark.
3790 */
3791 static char_u *
3792term_bg_default()
3793{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003794#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3795 /* DOS console nearly always black */
3796 return (char_u *)"dark";
3797#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003798 char_u *p;
3799
Bram Moolenaarf740b292006-02-16 22:11:02 +00003800 if (STRCMP(T_NAME, "linux") == 0
3801 || STRCMP(T_NAME, "screen.linux") == 0
3802 || STRCMP(T_NAME, "cygwin") == 0
3803 || STRCMP(T_NAME, "putty") == 0
3804 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3805 && (p = vim_strrchr(p, ';')) != NULL
3806 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3807 && p[2] == NUL))
3808 return (char_u *)"dark";
3809 return (char_u *)"light";
3810#endif
3811}
3812
3813/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003814 * Initialize the options, part three: After reading the .vimrc
3815 */
3816 void
3817set_init_3()
3818{
3819#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3820/*
3821 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3822 * This is done after other initializations, where 'shell' might have been
3823 * set, but only if they have not been set before.
3824 */
3825 char_u *p;
3826 int idx_srr;
3827 int do_srr;
3828#ifdef FEAT_QUICKFIX
3829 int idx_sp;
3830 int do_sp;
3831#endif
3832
3833 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003834 if (idx_srr < 0)
3835 do_srr = FALSE;
3836 else
3837 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838#ifdef FEAT_QUICKFIX
3839 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003840 if (idx_sp < 0)
3841 do_sp = FALSE;
3842 else
3843 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003844#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003845 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846 if (p != NULL)
3847 {
3848 /*
3849 * Default for p_sp is "| tee", for p_srr is ">".
3850 * For known shells it is changed here to include stderr.
3851 */
3852 if ( fnamecmp(p, "csh") == 0
3853 || fnamecmp(p, "tcsh") == 0
3854# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3855 || fnamecmp(p, "csh.exe") == 0
3856 || fnamecmp(p, "tcsh.exe") == 0
3857# endif
3858 )
3859 {
3860#if defined(FEAT_QUICKFIX)
3861 if (do_sp)
3862 {
3863# ifdef WIN3264
3864 p_sp = (char_u *)">&";
3865# else
3866 p_sp = (char_u *)"|& tee";
3867# endif
3868 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3869 }
3870#endif
3871 if (do_srr)
3872 {
3873 p_srr = (char_u *)">&";
3874 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3875 }
3876 }
3877 else
3878# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3879 if ( fnamecmp(p, "sh") == 0
3880 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003881 || fnamecmp(p, "mksh") == 0
3882 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003884 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003886 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887# ifdef WIN3264
3888 || fnamecmp(p, "cmd") == 0
3889 || fnamecmp(p, "sh.exe") == 0
3890 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003891 || fnamecmp(p, "mksh.exe") == 0
3892 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003894 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 || fnamecmp(p, "bash.exe") == 0
3896 || fnamecmp(p, "cmd.exe") == 0
3897# endif
3898 )
3899# endif
3900 {
3901#if defined(FEAT_QUICKFIX)
3902 if (do_sp)
3903 {
3904# ifdef WIN3264
3905 p_sp = (char_u *)">%s 2>&1";
3906# else
3907 p_sp = (char_u *)"2>&1| tee";
3908# endif
3909 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3910 }
3911#endif
3912 if (do_srr)
3913 {
3914 p_srr = (char_u *)">%s 2>&1";
3915 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3916 }
3917 }
3918 vim_free(p);
3919 }
3920#endif
3921
3922#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3923 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003924 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3925 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926 * This is done after other initializations, where 'shell' might have been
3927 * set, but only if they have not been set before. Default for p_shcf is
3928 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3929 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3930 * command.com. And for Win32 we need to set p_sxq instead.
3931 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003932 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 {
3934 int idx3;
3935
3936 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003937 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 {
3939 p_shcf = (char_u *)"-c";
3940 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3941 }
3942
3943# ifndef DJGPP
3944# ifdef WIN3264
3945 /* Somehow Win32 requires the quotes around the redirection too */
3946 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003947 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 {
3949 p_sxq = (char_u *)"\"";
3950 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3951 }
3952# else
3953 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003954 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 {
3956 p_shq = (char_u *)"\"";
3957 options[idx3].def_val[VI_DEFAULT] = p_shq;
3958 }
3959# endif
3960# endif
3961 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003962 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3963 {
3964 int idx3;
3965
3966 /*
3967 * cmd.exe on Windows will strip the first and last double quote given
3968 * on the command line, e.g. most of the time things like:
3969 * cmd /c "my path/to/echo" "my args to echo"
3970 * become:
3971 * my path/to/echo" "my args to echo
3972 * when executed.
3973 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003974 * To avoid this, set shellxquote to surround the command in
3975 * parenthesis. This appears to make most commands work, without
3976 * breaking commands that worked previously, such as
3977 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003978 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003979 idx3 = findoption((char_u *)"sxq");
3980 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3981 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003982 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003983 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3984 }
3985
Bram Moolenaara64ba222012-02-12 23:23:31 +01003986 idx3 = findoption((char_u *)"shcf");
3987 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3988 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003989 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003990 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3991 }
3992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993#endif
3994
3995#ifdef FEAT_TITLE
3996 set_title_defaults();
3997#endif
3998}
3999
4000#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4001/*
4002 * When 'helplang' is still at its default value, set it to "lang".
4003 * Only the first two characters of "lang" are used.
4004 */
4005 void
4006set_helplang_default(lang)
4007 char_u *lang;
4008{
4009 int idx;
4010
4011 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4012 return;
4013 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004014 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015 {
4016 if (options[idx].flags & P_ALLOCED)
4017 free_string_option(p_hlg);
4018 p_hlg = vim_strsave(lang);
4019 if (p_hlg == NULL)
4020 p_hlg = empty_option;
4021 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004022 {
4023 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4024 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4025 {
4026 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4027 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4028 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004029 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004030 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004031 options[idx].flags |= P_ALLOCED;
4032 }
4033}
4034#endif
4035
4036#ifdef FEAT_GUI
4037static char_u *gui_bg_default __ARGS((void));
4038
4039 static char_u *
4040gui_bg_default()
4041{
4042 if (gui_get_lightness(gui.back_pixel) < 127)
4043 return (char_u *)"dark";
4044 return (char_u *)"light";
4045}
4046
4047/*
4048 * Option initializations that can only be done after opening the GUI window.
4049 */
4050 void
4051init_gui_options()
4052{
4053 /* Set the 'background' option according to the lightness of the
4054 * background color, unless the user has set it already. */
4055 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4056 {
4057 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4058 highlight_changed();
4059 }
4060}
4061#endif
4062
4063#ifdef FEAT_TITLE
4064/*
4065 * 'title' and 'icon' only default to true if they have not been set or reset
4066 * in .vimrc and we can read the old value.
4067 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4068 * they can be reset. This reduces startup time when using X on a remote
4069 * machine.
4070 */
4071 void
4072set_title_defaults()
4073{
4074 int idx1;
4075 long val;
4076
4077 /*
4078 * If GUI is (going to be) used, we can always set the window title and
4079 * icon name. Saves a bit of time, because the X11 display server does
4080 * not need to be contacted.
4081 */
4082 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004083 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 {
4085#ifdef FEAT_GUI
4086 if (gui.starting || gui.in_use)
4087 val = TRUE;
4088 else
4089#endif
4090 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004091 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 p_title = val;
4093 }
4094 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004095 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 {
4097#ifdef FEAT_GUI
4098 if (gui.starting || gui.in_use)
4099 val = TRUE;
4100 else
4101#endif
4102 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004103 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 p_icon = val;
4105 }
4106}
4107#endif
4108
4109/*
4110 * Parse 'arg' for option settings.
4111 *
4112 * 'arg' may be IObuff, but only when no errors can be present and option
4113 * does not need to be expanded with option_expand().
4114 * "opt_flags":
4115 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004116 * OPT_GLOBAL for ":setglobal"
4117 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004119 * OPT_WINONLY to only set window-local options
4120 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 *
4122 * returns FAIL if an error is detected, OK otherwise
4123 */
4124 int
4125do_set(arg, opt_flags)
4126 char_u *arg; /* option string (may be written to!) */
4127 int opt_flags;
4128{
4129 int opt_idx;
4130 char_u *errmsg;
4131 char_u errbuf[80];
4132 char_u *startarg;
4133 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4134 int nextchar; /* next non-white char after option name */
4135 int afterchar; /* character just after option name */
4136 int len;
4137 int i;
4138 long value;
4139 int key;
4140 long_u flags; /* flags for current option */
4141 char_u *varp = NULL; /* pointer to variable for current option */
4142 int did_show = FALSE; /* already showed one value */
4143 int adding; /* "opt+=arg" */
4144 int prepending; /* "opt^=arg" */
4145 int removing; /* "opt-=arg" */
4146 int cp_val = 0;
4147 char_u key_name[2];
4148
4149 if (*arg == NUL)
4150 {
4151 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004152 did_show = TRUE;
4153 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 }
4155
4156 while (*arg != NUL) /* loop to process all options */
4157 {
4158 errmsg = NULL;
4159 startarg = arg; /* remember for error message */
4160
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004161 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4162 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 {
4164 /*
4165 * ":set all" show all options.
4166 * ":set all&" set all options to their default value.
4167 */
4168 arg += 3;
4169 if (*arg == '&')
4170 {
4171 ++arg;
4172 /* Only for :set command set global value of local options. */
4173 set_options_default(OPT_FREE | opt_flags);
4174 }
4175 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004176 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004178 did_show = TRUE;
4179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004181 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182 {
4183 showoptions(2, opt_flags);
4184 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004185 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186 arg += 7;
4187 }
4188 else
4189 {
4190 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004191 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004192 {
4193 prefix = 0;
4194 arg += 2;
4195 }
4196 else if (STRNCMP(arg, "inv", 3) == 0)
4197 {
4198 prefix = 2;
4199 arg += 3;
4200 }
4201
4202 /* find end of name */
4203 key = 0;
4204 if (*arg == '<')
4205 {
4206 nextchar = 0;
4207 opt_idx = -1;
4208 /* look out for <t_>;> */
4209 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4210 len = 5;
4211 else
4212 {
4213 len = 1;
4214 while (arg[len] != NUL && arg[len] != '>')
4215 ++len;
4216 }
4217 if (arg[len] != '>')
4218 {
4219 errmsg = e_invarg;
4220 goto skip;
4221 }
4222 arg[len] = NUL; /* put NUL after name */
4223 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4224 opt_idx = findoption(arg + 1);
4225 arg[len++] = '>'; /* restore '>' */
4226 if (opt_idx == -1)
4227 key = find_key_option(arg + 1);
4228 }
4229 else
4230 {
4231 len = 0;
4232 /*
4233 * The two characters after "t_" may not be alphanumeric.
4234 */
4235 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4236 len = 4;
4237 else
4238 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4239 ++len;
4240 nextchar = arg[len];
4241 arg[len] = NUL; /* put NUL after name */
4242 opt_idx = findoption(arg);
4243 arg[len] = nextchar; /* restore nextchar */
4244 if (opt_idx == -1)
4245 key = find_key_option(arg);
4246 }
4247
4248 /* remember character after option name */
4249 afterchar = arg[len];
4250
4251 /* skip white space, allow ":set ai ?" */
4252 while (vim_iswhite(arg[len]))
4253 ++len;
4254
4255 adding = FALSE;
4256 prepending = FALSE;
4257 removing = FALSE;
4258 if (arg[len] != NUL && arg[len + 1] == '=')
4259 {
4260 if (arg[len] == '+')
4261 {
4262 adding = TRUE; /* "+=" */
4263 ++len;
4264 }
4265 else if (arg[len] == '^')
4266 {
4267 prepending = TRUE; /* "^=" */
4268 ++len;
4269 }
4270 else if (arg[len] == '-')
4271 {
4272 removing = TRUE; /* "-=" */
4273 ++len;
4274 }
4275 }
4276 nextchar = arg[len];
4277
4278 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4279 {
4280 errmsg = (char_u *)N_("E518: Unknown option");
4281 goto skip;
4282 }
4283
4284 if (opt_idx >= 0)
4285 {
4286 if (options[opt_idx].var == NULL) /* hidden option: skip */
4287 {
4288 /* Only give an error message when requesting the value of
4289 * a hidden option, ignore setting it. */
4290 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4291 && (!(options[opt_idx].flags & P_BOOL)
4292 || nextchar == '?'))
4293 errmsg = (char_u *)N_("E519: Option not supported");
4294 goto skip;
4295 }
4296
4297 flags = options[opt_idx].flags;
4298 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4299 }
4300 else
4301 {
4302 flags = P_STRING;
4303 if (key < 0)
4304 {
4305 key_name[0] = KEY2TERMCAP0(key);
4306 key_name[1] = KEY2TERMCAP1(key);
4307 }
4308 else
4309 {
4310 key_name[0] = KS_KEY;
4311 key_name[1] = (key & 0xff);
4312 }
4313 }
4314
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004315 /* Skip all options that are not window-local (used when showing
4316 * an already loaded buffer in a window). */
4317 if ((opt_flags & OPT_WINONLY)
4318 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4319 goto skip;
4320
Bram Moolenaara3227e22006-03-08 21:32:40 +00004321 /* Skip all options that are window-local (used for :vimgrep). */
4322 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4323 && options[opt_idx].var == VAR_WIN)
4324 goto skip;
4325
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004326 /* Disallow changing some options from modelines. */
4327 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004328 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004329 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004330 {
4331 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4332 goto skip;
4333 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004334#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004335 /* In diff mode some options are overruled. This avoids that
4336 * 'foldmethod' becomes "marker" instead of "diff" and that
4337 * "wrap" gets set. */
4338 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004339 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004340 && (options[opt_idx].indir == PV_FDM
4341 || options[opt_idx].indir == PV_WRAP))
4342 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004344 }
4345
4346#ifdef HAVE_SANDBOX
4347 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004348 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 {
4350 errmsg = (char_u *)_(e_sandbox);
4351 goto skip;
4352 }
4353#endif
4354
4355 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4356 {
4357 arg += len;
4358 cp_val = p_cp;
4359 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4360 {
4361 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4362 {
4363 cp_val = FALSE;
4364 arg += 3;
4365 }
4366 else /* "opt&vi": set to Vi default */
4367 {
4368 cp_val = TRUE;
4369 arg += 2;
4370 }
4371 }
4372 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4373 && arg[1] != NUL && !vim_iswhite(arg[1]))
4374 {
4375 errmsg = e_trailing;
4376 goto skip;
4377 }
4378 }
4379
4380 /*
4381 * allow '=' and ':' as MSDOS command.com allows only one
4382 * '=' character per "set" command line. grrr. (jw)
4383 */
4384 if (nextchar == '?'
4385 || (prefix == 1
4386 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4387 && !(flags & P_BOOL)))
4388 {
4389 /*
4390 * print value
4391 */
4392 if (did_show)
4393 msg_putchar('\n'); /* cursor below last one */
4394 else
4395 {
4396 gotocmdline(TRUE); /* cursor at status line */
4397 did_show = TRUE; /* remember that we did a line */
4398 }
4399 if (opt_idx >= 0)
4400 {
4401 showoneopt(&options[opt_idx], opt_flags);
4402#ifdef FEAT_EVAL
4403 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004404 {
4405 /* Mention where the option was last set. */
4406 if (varp == options[opt_idx].var)
4407 last_set_msg(options[opt_idx].scriptID);
4408 else if ((int)options[opt_idx].indir & PV_WIN)
4409 last_set_msg(curwin->w_p_scriptID[
4410 (int)options[opt_idx].indir & PV_MASK]);
4411 else if ((int)options[opt_idx].indir & PV_BUF)
4412 last_set_msg(curbuf->b_p_scriptID[
4413 (int)options[opt_idx].indir & PV_MASK]);
4414 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004415#endif
4416 }
4417 else
4418 {
4419 char_u *p;
4420
4421 p = find_termcode(key_name);
4422 if (p == NULL)
4423 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004424 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425 goto skip;
4426 }
4427 else
4428 (void)show_one_termcode(key_name, p, TRUE);
4429 }
4430 if (nextchar != '?'
4431 && nextchar != NUL && !vim_iswhite(afterchar))
4432 errmsg = e_trailing;
4433 }
4434 else
4435 {
4436 if (flags & P_BOOL) /* boolean */
4437 {
4438 if (nextchar == '=' || nextchar == ':')
4439 {
4440 errmsg = e_invarg;
4441 goto skip;
4442 }
4443
4444 /*
4445 * ":set opt!": invert
4446 * ":set opt&": reset to default value
4447 * ":set opt<": reset to global value
4448 */
4449 if (nextchar == '!')
4450 value = *(int *)(varp) ^ 1;
4451 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004452 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004453 ((flags & P_VI_DEF) || cp_val)
4454 ? VI_DEFAULT : VIM_DEFAULT];
4455 else if (nextchar == '<')
4456 {
4457 /* For 'autoread' -1 means to use global value. */
4458 if ((int *)varp == &curbuf->b_p_ar
4459 && opt_flags == OPT_LOCAL)
4460 value = -1;
4461 else
4462 value = *(int *)get_varp_scope(&(options[opt_idx]),
4463 OPT_GLOBAL);
4464 }
4465 else
4466 {
4467 /*
4468 * ":set invopt": invert
4469 * ":set opt" or ":set noopt": set or reset
4470 */
4471 if (nextchar != NUL && !vim_iswhite(afterchar))
4472 {
4473 errmsg = e_trailing;
4474 goto skip;
4475 }
4476 if (prefix == 2) /* inv */
4477 value = *(int *)(varp) ^ 1;
4478 else
4479 value = prefix;
4480 }
4481
4482 errmsg = set_bool_option(opt_idx, varp, (int)value,
4483 opt_flags);
4484 }
4485 else /* numeric or string */
4486 {
4487 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4488 || prefix != 1)
4489 {
4490 errmsg = e_invarg;
4491 goto skip;
4492 }
4493
4494 if (flags & P_NUM) /* numeric */
4495 {
4496 /*
4497 * Different ways to set a number option:
4498 * & set to default value
4499 * < set to global value
4500 * <xx> accept special key codes for 'wildchar'
4501 * c accept any non-digit for 'wildchar'
4502 * [-]0-9 set number
4503 * other error
4504 */
4505 ++arg;
4506 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004507 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004508 ((flags & P_VI_DEF) || cp_val)
4509 ? VI_DEFAULT : VIM_DEFAULT];
4510 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004511 {
4512 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4513 * use the global value. */
4514 if ((long *)varp == &curbuf->b_p_ul
4515 && opt_flags == OPT_LOCAL)
4516 value = NO_LOCAL_UNDOLEVEL;
4517 else
4518 value = *(long *)get_varp_scope(
4519 &(options[opt_idx]), OPT_GLOBAL);
4520 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004521 else if (((long *)varp == &p_wc
4522 || (long *)varp == &p_wcm)
4523 && (*arg == '<'
4524 || *arg == '^'
4525 || ((!arg[1] || vim_iswhite(arg[1]))
4526 && !VIM_ISDIGIT(*arg))))
4527 {
4528 value = string_to_key(arg);
4529 if (value == 0 && (long *)varp != &p_wcm)
4530 {
4531 errmsg = e_invarg;
4532 goto skip;
4533 }
4534 }
4535 /* allow negative numbers (for 'undolevels') */
4536 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4537 {
4538 i = 0;
4539 if (*arg == '-')
4540 i = 1;
4541#ifdef HAVE_STRTOL
4542 value = strtol((char *)arg, NULL, 0);
4543 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4544 i += 2;
4545#else
4546 value = atol((char *)arg);
4547#endif
4548 while (VIM_ISDIGIT(arg[i]))
4549 ++i;
4550 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4551 {
4552 errmsg = e_invarg;
4553 goto skip;
4554 }
4555 }
4556 else
4557 {
4558 errmsg = (char_u *)N_("E521: Number required after =");
4559 goto skip;
4560 }
4561
4562 if (adding)
4563 value = *(long *)varp + value;
4564 if (prepending)
4565 value = *(long *)varp * value;
4566 if (removing)
4567 value = *(long *)varp - value;
4568 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004569 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004570 }
4571 else if (opt_idx >= 0) /* string */
4572 {
4573 char_u *save_arg = NULL;
4574 char_u *s = NULL;
4575 char_u *oldval; /* previous value if *varp */
4576 char_u *newval;
4577 char_u *origval;
4578 unsigned newlen;
4579 int comma;
4580 int bs;
4581 int new_value_alloced; /* new string option
4582 was allocated */
4583
4584 /* When using ":set opt=val" for a global option
4585 * with a local value the local value will be
4586 * reset, use the global value here. */
4587 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004588 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004589 varp = options[opt_idx].var;
4590
4591 /* The old value is kept until we are sure that the
4592 * new value is valid. */
4593 oldval = *(char_u **)varp;
4594 if (nextchar == '&') /* set to default val */
4595 {
4596 newval = options[opt_idx].def_val[
4597 ((flags & P_VI_DEF) || cp_val)
4598 ? VI_DEFAULT : VIM_DEFAULT];
4599 if ((char_u **)varp == &p_bg)
4600 {
4601 /* guess the value of 'background' */
4602#ifdef FEAT_GUI
4603 if (gui.in_use)
4604 newval = gui_bg_default();
4605 else
4606#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004607 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004608 }
4609
4610 /* expand environment variables and ~ (since the
4611 * default value was already expanded, only
4612 * required when an environment variable was set
4613 * later */
4614 if (newval == NULL)
4615 newval = empty_option;
4616 else
4617 {
4618 s = option_expand(opt_idx, newval);
4619 if (s == NULL)
4620 s = newval;
4621 newval = vim_strsave(s);
4622 }
4623 new_value_alloced = TRUE;
4624 }
4625 else if (nextchar == '<') /* set to global val */
4626 {
4627 newval = vim_strsave(*(char_u **)get_varp_scope(
4628 &(options[opt_idx]), OPT_GLOBAL));
4629 new_value_alloced = TRUE;
4630 }
4631 else
4632 {
4633 ++arg; /* jump to after the '=' or ':' */
4634
4635 /*
4636 * Set 'keywordprg' to ":help" if an empty
4637 * value was passed to :set by the user.
4638 * Misuse errbuf[] for the resulting string.
4639 */
4640 if (varp == (char_u *)&p_kp
4641 && (*arg == NUL || *arg == ' '))
4642 {
4643 STRCPY(errbuf, ":help");
4644 save_arg = arg;
4645 arg = errbuf;
4646 }
4647 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004648 * Convert 'backspace' number to string, for
4649 * adding, prepending and removing string.
4650 */
4651 else if (varp == (char_u *)&p_bs
4652 && VIM_ISDIGIT(**(char_u **)varp))
4653 {
4654 i = getdigits((char_u **)varp);
4655 switch (i)
4656 {
4657 case 0:
4658 *(char_u **)varp = empty_option;
4659 break;
4660 case 1:
4661 *(char_u **)varp = vim_strsave(
4662 (char_u *)"indent,eol");
4663 break;
4664 case 2:
4665 *(char_u **)varp = vim_strsave(
4666 (char_u *)"indent,eol,start");
4667 break;
4668 }
4669 vim_free(oldval);
4670 oldval = *(char_u **)varp;
4671 }
4672 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004673 * Convert 'whichwrap' number to string, for
4674 * backwards compatibility with Vim 3.0.
4675 * Misuse errbuf[] for the resulting string.
4676 */
4677 else if (varp == (char_u *)&p_ww
4678 && VIM_ISDIGIT(*arg))
4679 {
4680 *errbuf = NUL;
4681 i = getdigits(&arg);
4682 if (i & 1)
4683 STRCAT(errbuf, "b,");
4684 if (i & 2)
4685 STRCAT(errbuf, "s,");
4686 if (i & 4)
4687 STRCAT(errbuf, "h,l,");
4688 if (i & 8)
4689 STRCAT(errbuf, "<,>,");
4690 if (i & 16)
4691 STRCAT(errbuf, "[,],");
4692 if (*errbuf != NUL) /* remove trailing , */
4693 errbuf[STRLEN(errbuf) - 1] = NUL;
4694 save_arg = arg;
4695 arg = errbuf;
4696 }
4697 /*
4698 * Remove '>' before 'dir' and 'bdir', for
4699 * backwards compatibility with version 3.0
4700 */
4701 else if ( *arg == '>'
4702 && (varp == (char_u *)&p_dir
4703 || varp == (char_u *)&p_bdir))
4704 {
4705 ++arg;
4706 }
4707
4708 /* When setting the local value of a global
4709 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004710 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004711 && (opt_flags & OPT_LOCAL))
4712 origval = *(char_u **)get_varp(
4713 &options[opt_idx]);
4714 else
4715 origval = oldval;
4716
4717 /*
4718 * Copy the new string into allocated memory.
4719 * Can't use set_string_option_direct(), because
4720 * we need to remove the backslashes.
4721 */
4722 /* get a bit too much */
4723 newlen = (unsigned)STRLEN(arg) + 1;
4724 if (adding || prepending || removing)
4725 newlen += (unsigned)STRLEN(origval) + 1;
4726 newval = alloc(newlen);
4727 if (newval == NULL) /* out of mem, don't change */
4728 break;
4729 s = newval;
4730
4731 /*
4732 * Copy the string, skip over escaped chars.
4733 * For MS-DOS and WIN32 backslashes before normal
4734 * file name characters are not removed, and keep
4735 * backslash at start, for "\\machine\path", but
4736 * do remove it for "\\\\machine\\path".
4737 * The reverse is found in ExpandOldSetting().
4738 */
4739 while (*arg && !vim_iswhite(*arg))
4740 {
4741 if (*arg == '\\' && arg[1] != NUL
4742#ifdef BACKSLASH_IN_FILENAME
4743 && !((flags & P_EXPAND)
4744 && vim_isfilec(arg[1])
4745 && (arg[1] != '\\'
4746 || (s == newval
4747 && arg[2] != '\\')))
4748#endif
4749 )
4750 ++arg; /* remove backslash */
4751#ifdef FEAT_MBYTE
4752 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004753 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004754 {
4755 /* copy multibyte char */
4756 mch_memmove(s, arg, (size_t)i);
4757 arg += i;
4758 s += i;
4759 }
4760 else
4761#endif
4762 *s++ = *arg++;
4763 }
4764 *s = NUL;
4765
4766 /*
4767 * Expand environment variables and ~.
4768 * Don't do it when adding without inserting a
4769 * comma.
4770 */
4771 if (!(adding || prepending || removing)
4772 || (flags & P_COMMA))
4773 {
4774 s = option_expand(opt_idx, newval);
4775 if (s != NULL)
4776 {
4777 vim_free(newval);
4778 newlen = (unsigned)STRLEN(s) + 1;
4779 if (adding || prepending || removing)
4780 newlen += (unsigned)STRLEN(origval) + 1;
4781 newval = alloc(newlen);
4782 if (newval == NULL)
4783 break;
4784 STRCPY(newval, s);
4785 }
4786 }
4787
4788 /* locate newval[] in origval[] when removing it
4789 * and when adding to avoid duplicates */
4790 i = 0; /* init for GCC */
4791 if (removing || (flags & P_NODUP))
4792 {
4793 i = (int)STRLEN(newval);
4794 bs = 0;
4795 for (s = origval; *s; ++s)
4796 {
4797 if ((!(flags & P_COMMA)
4798 || s == origval
4799 || (s[-1] == ',' && !(bs & 1)))
4800 && STRNCMP(s, newval, i) == 0
4801 && (!(flags & P_COMMA)
4802 || s[i] == ','
4803 || s[i] == NUL))
4804 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004805 /* Count backslashes. Only a comma with an
4806 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004807 * recognized as a separator */
4808 if (s > origval && s[-1] == '\\')
4809 ++bs;
4810 else
4811 bs = 0;
4812 }
4813
4814 /* do not add if already there */
4815 if ((adding || prepending) && *s)
4816 {
4817 prepending = FALSE;
4818 adding = FALSE;
4819 STRCPY(newval, origval);
4820 }
4821 }
4822
4823 /* concatenate the two strings; add a ',' if
4824 * needed */
4825 if (adding || prepending)
4826 {
4827 comma = ((flags & P_COMMA) && *origval != NUL
4828 && *newval != NUL);
4829 if (adding)
4830 {
4831 i = (int)STRLEN(origval);
4832 mch_memmove(newval + i + comma, newval,
4833 STRLEN(newval) + 1);
4834 mch_memmove(newval, origval, (size_t)i);
4835 }
4836 else
4837 {
4838 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004839 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004840 }
4841 if (comma)
4842 newval[i] = ',';
4843 }
4844
4845 /* Remove newval[] from origval[]. (Note: "i" has
4846 * been set above and is used here). */
4847 if (removing)
4848 {
4849 STRCPY(newval, origval);
4850 if (*s)
4851 {
4852 /* may need to remove a comma */
4853 if (flags & P_COMMA)
4854 {
4855 if (s == origval)
4856 {
4857 /* include comma after string */
4858 if (s[i] == ',')
4859 ++i;
4860 }
4861 else
4862 {
4863 /* include comma before string */
4864 --s;
4865 ++i;
4866 }
4867 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004868 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004869 }
4870 }
4871
4872 if (flags & P_FLAGLIST)
4873 {
4874 /* Remove flags that appear twice. */
4875 for (s = newval; *s; ++s)
4876 if ((!(flags & P_COMMA) || *s != ',')
4877 && vim_strchr(s + 1, *s) != NULL)
4878 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004879 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004880 --s;
4881 }
4882 }
4883
4884 if (save_arg != NULL) /* number for 'whichwrap' */
4885 arg = save_arg;
4886 new_value_alloced = TRUE;
4887 }
4888
4889 /* Set the new value. */
4890 *(char_u **)(varp) = newval;
4891
4892 /* Handle side effects, and set the global value for
4893 * ":set" on local options. */
4894 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4895 new_value_alloced, oldval, errbuf, opt_flags);
4896
4897 /* If error detected, print the error message. */
4898 if (errmsg != NULL)
4899 goto skip;
4900 }
4901 else /* key code option */
4902 {
4903 char_u *p;
4904
4905 if (nextchar == '&')
4906 {
4907 if (add_termcap_entry(key_name, TRUE) == FAIL)
4908 errmsg = (char_u *)N_("E522: Not found in termcap");
4909 }
4910 else
4911 {
4912 ++arg; /* jump to after the '=' or ':' */
4913 for (p = arg; *p && !vim_iswhite(*p); ++p)
4914 if (*p == '\\' && p[1] != NUL)
4915 ++p;
4916 nextchar = *p;
4917 *p = NUL;
4918 add_termcode(key_name, arg, FALSE);
4919 *p = nextchar;
4920 }
4921 if (full_screen)
4922 ttest(FALSE);
4923 redraw_all_later(CLEAR);
4924 }
4925 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004926
Bram Moolenaar071d4272004-06-13 20:20:40 +00004927 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004928 did_set_option(opt_idx, opt_flags,
4929 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004930 }
4931
4932skip:
4933 /*
4934 * Advance to next argument.
4935 * - skip until a blank found, taking care of backslashes
4936 * - skip blanks
4937 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4938 */
4939 for (i = 0; i < 2 ; ++i)
4940 {
4941 while (*arg != NUL && !vim_iswhite(*arg))
4942 if (*arg++ == '\\' && *arg != NUL)
4943 ++arg;
4944 arg = skipwhite(arg);
4945 if (*arg != '=')
4946 break;
4947 }
4948 }
4949
4950 if (errmsg != NULL)
4951 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004952 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004953 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004954 if (i + (arg - startarg) < IOSIZE)
4955 {
4956 /* append the argument with the error */
4957 STRCAT(IObuff, ": ");
4958 mch_memmove(IObuff + i, startarg, (arg - startarg));
4959 IObuff[i + (arg - startarg)] = NUL;
4960 }
4961 /* make sure all characters are printable */
4962 trans_characters(IObuff, IOSIZE);
4963
4964 ++no_wait_return; /* wait_return done later */
4965 emsg(IObuff); /* show error highlighted */
4966 --no_wait_return;
4967
4968 return FAIL;
4969 }
4970
4971 arg = skipwhite(arg);
4972 }
4973
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004974theend:
4975 if (silent_mode && did_show)
4976 {
4977 /* After displaying option values in silent mode. */
4978 silent_mode = FALSE;
4979 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4980 msg_putchar('\n');
4981 cursor_on(); /* msg_start() switches it off */
4982 out_flush();
4983 silent_mode = TRUE;
4984 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4985 }
4986
Bram Moolenaar071d4272004-06-13 20:20:40 +00004987 return OK;
4988}
4989
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004990/*
4991 * Call this when an option has been given a new value through a user command.
4992 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4993 */
4994 static void
4995did_set_option(opt_idx, opt_flags, new_value)
4996 int opt_idx;
4997 int opt_flags; /* possibly with OPT_MODELINE */
4998 int new_value; /* value was replaced completely */
4999{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005000 long_u *p;
5001
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005002 options[opt_idx].flags |= P_WAS_SET;
5003
5004 /* When an option is set in the sandbox, from a modeline or in secure mode
5005 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005006 * flag. */
5007 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005008 if (secure
5009#ifdef HAVE_SANDBOX
5010 || sandbox != 0
5011#endif
5012 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005013 *p = *p | P_INSECURE;
5014 else if (new_value)
5015 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005016}
5017
Bram Moolenaar071d4272004-06-13 20:20:40 +00005018 static char_u *
5019illegal_char(errbuf, c)
5020 char_u *errbuf;
5021 int c;
5022{
5023 if (errbuf == NULL)
5024 return (char_u *)"";
5025 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005026 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005027 return errbuf;
5028}
5029
5030/*
5031 * Convert a key name or string into a key value.
5032 * Used for 'wildchar' and 'cedit' options.
5033 */
5034 static int
5035string_to_key(arg)
5036 char_u *arg;
5037{
5038 if (*arg == '<')
5039 return find_key_option(arg + 1);
5040 if (*arg == '^')
5041 return Ctrl_chr(arg[1]);
5042 return *arg;
5043}
5044
5045#ifdef FEAT_CMDWIN
5046/*
5047 * Check value of 'cedit' and set cedit_key.
5048 * Returns NULL if value is OK, error message otherwise.
5049 */
5050 static char_u *
5051check_cedit()
5052{
5053 int n;
5054
5055 if (*p_cedit == NUL)
5056 cedit_key = -1;
5057 else
5058 {
5059 n = string_to_key(p_cedit);
5060 if (vim_isprintc(n))
5061 return e_invarg;
5062 cedit_key = n;
5063 }
5064 return NULL;
5065}
5066#endif
5067
5068#ifdef FEAT_TITLE
5069/*
5070 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5071 * maketitle() to create and display it.
5072 * When switching the title or icon off, call mch_restore_title() to get
5073 * the old value back.
5074 */
5075 static void
5076did_set_title(icon)
5077 int icon; /* Did set icon instead of title */
5078{
5079 if (starting != NO_SCREEN
5080#ifdef FEAT_GUI
5081 && !gui.starting
5082#endif
5083 )
5084 {
5085 maketitle();
5086 if (icon)
5087 {
5088 if (!p_icon)
5089 mch_restore_title(2);
5090 }
5091 else
5092 {
5093 if (!p_title)
5094 mch_restore_title(1);
5095 }
5096 }
5097}
5098#endif
5099
5100/*
5101 * set_options_bin - called when 'bin' changes value.
5102 */
5103 void
5104set_options_bin(oldval, newval, opt_flags)
5105 int oldval;
5106 int newval;
5107 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5108{
5109 /*
5110 * The option values that are changed when 'bin' changes are
5111 * copied when 'bin is set and restored when 'bin' is reset.
5112 */
5113 if (newval)
5114 {
5115 if (!oldval) /* switched on */
5116 {
5117 if (!(opt_flags & OPT_GLOBAL))
5118 {
5119 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5120 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5121 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5122 curbuf->b_p_et_nobin = curbuf->b_p_et;
5123 }
5124 if (!(opt_flags & OPT_LOCAL))
5125 {
5126 p_tw_nobin = p_tw;
5127 p_wm_nobin = p_wm;
5128 p_ml_nobin = p_ml;
5129 p_et_nobin = p_et;
5130 }
5131 }
5132
5133 if (!(opt_flags & OPT_GLOBAL))
5134 {
5135 curbuf->b_p_tw = 0; /* no automatic line wrap */
5136 curbuf->b_p_wm = 0; /* no automatic line wrap */
5137 curbuf->b_p_ml = 0; /* no modelines */
5138 curbuf->b_p_et = 0; /* no expandtab */
5139 }
5140 if (!(opt_flags & OPT_LOCAL))
5141 {
5142 p_tw = 0;
5143 p_wm = 0;
5144 p_ml = FALSE;
5145 p_et = FALSE;
5146 p_bin = TRUE; /* needed when called for the "-b" argument */
5147 }
5148 }
5149 else if (oldval) /* switched off */
5150 {
5151 if (!(opt_flags & OPT_GLOBAL))
5152 {
5153 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5154 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5155 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5156 curbuf->b_p_et = curbuf->b_p_et_nobin;
5157 }
5158 if (!(opt_flags & OPT_LOCAL))
5159 {
5160 p_tw = p_tw_nobin;
5161 p_wm = p_wm_nobin;
5162 p_ml = p_ml_nobin;
5163 p_et = p_et_nobin;
5164 }
5165 }
5166}
5167
5168#ifdef FEAT_VIMINFO
5169/*
5170 * Find the parameter represented by the given character (eg ', :, ", or /),
5171 * and return its associated value in the 'viminfo' string.
5172 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005173 * If the parameter is not specified in the string or there is no following
5174 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005175 */
5176 int
5177get_viminfo_parameter(type)
5178 int type;
5179{
5180 char_u *p;
5181
5182 p = find_viminfo_parameter(type);
5183 if (p != NULL && VIM_ISDIGIT(*p))
5184 return atoi((char *)p);
5185 return -1;
5186}
5187
5188/*
5189 * Find the parameter represented by the given character (eg ''', ':', '"', or
5190 * '/') in the 'viminfo' option and return a pointer to the string after it.
5191 * Return NULL if the parameter is not specified in the string.
5192 */
5193 char_u *
5194find_viminfo_parameter(type)
5195 int type;
5196{
5197 char_u *p;
5198
5199 for (p = p_viminfo; *p; ++p)
5200 {
5201 if (*p == type)
5202 return p + 1;
5203 if (*p == 'n') /* 'n' is always the last one */
5204 break;
5205 p = vim_strchr(p, ','); /* skip until next ',' */
5206 if (p == NULL) /* hit the end without finding parameter */
5207 break;
5208 }
5209 return NULL;
5210}
5211#endif
5212
5213/*
5214 * Expand environment variables for some string options.
5215 * These string options cannot be indirect!
5216 * If "val" is NULL expand the current value of the option.
5217 * Return pointer to NameBuff, or NULL when not expanded.
5218 */
5219 static char_u *
5220option_expand(opt_idx, val)
5221 int opt_idx;
5222 char_u *val;
5223{
5224 /* if option doesn't need expansion nothing to do */
5225 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5226 return NULL;
5227
5228 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5229 * expand_env() would truncate the string. */
5230 if (val != NULL && STRLEN(val) > MAXPATHL)
5231 return NULL;
5232
5233 if (val == NULL)
5234 val = *(char_u **)options[opt_idx].var;
5235
5236 /*
5237 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5238 * Escape spaces when expanding 'tags', they are used to separate file
5239 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005240 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005241 */
5242 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005243 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005244#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005245 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5246#endif
5247 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005248 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5249 return NULL;
5250
5251 return NameBuff;
5252}
5253
5254/*
5255 * After setting various option values: recompute variables that depend on
5256 * option values.
5257 */
5258 static void
5259didset_options()
5260{
5261 /* initialize the table for 'iskeyword' et.al. */
5262 (void)init_chartab();
5263
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005264#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005265 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005266#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005267 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5268#ifdef FEAT_SESSION
5269 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5270 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5271#endif
5272#ifdef FEAT_FOLDING
5273 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5274#endif
5275 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5276#ifdef FEAT_VIRTUALEDIT
5277 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5278#endif
5279#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5280 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5281#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005282#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005283 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005284 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005285 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005286#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005287#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5288 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5289#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005290#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005291 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5292#endif
5293#ifdef FEAT_CMDWIN
5294 /* set cedit_key */
5295 (void)check_cedit();
5296#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005297#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005298 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005299#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005300}
5301
5302/*
5303 * Check for string options that are NULL (normally only termcap options).
5304 */
5305 void
5306check_options()
5307{
5308 int opt_idx;
5309
5310 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5311 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5312 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5313}
5314
5315/*
5316 * Check string options in a buffer for NULL value.
5317 */
5318 void
5319check_buf_options(buf)
5320 buf_T *buf;
5321{
5322#if defined(FEAT_QUICKFIX)
5323 check_string_option(&buf->b_p_bh);
5324 check_string_option(&buf->b_p_bt);
5325#endif
5326#ifdef FEAT_MBYTE
5327 check_string_option(&buf->b_p_fenc);
5328#endif
5329 check_string_option(&buf->b_p_ff);
5330#ifdef FEAT_FIND_ID
5331 check_string_option(&buf->b_p_def);
5332 check_string_option(&buf->b_p_inc);
5333# ifdef FEAT_EVAL
5334 check_string_option(&buf->b_p_inex);
5335# endif
5336#endif
5337#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5338 check_string_option(&buf->b_p_inde);
5339 check_string_option(&buf->b_p_indk);
5340#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005341#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5342 check_string_option(&buf->b_p_bexpr);
5343#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005344#if defined(FEAT_CRYPT)
5345 check_string_option(&buf->b_p_cm);
5346#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005347#if defined(FEAT_EVAL)
5348 check_string_option(&buf->b_p_fex);
5349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005350#ifdef FEAT_CRYPT
5351 check_string_option(&buf->b_p_key);
5352#endif
5353 check_string_option(&buf->b_p_kp);
5354 check_string_option(&buf->b_p_mps);
5355 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005356 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357 check_string_option(&buf->b_p_isk);
5358#ifdef FEAT_COMMENTS
5359 check_string_option(&buf->b_p_com);
5360#endif
5361#ifdef FEAT_FOLDING
5362 check_string_option(&buf->b_p_cms);
5363#endif
5364 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005365#ifdef FEAT_TEXTOBJ
5366 check_string_option(&buf->b_p_qe);
5367#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005368#ifdef FEAT_SYN_HL
5369 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005370#endif
5371#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005372 check_string_option(&buf->b_s.b_p_spc);
5373 check_string_option(&buf->b_s.b_p_spf);
5374 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375#endif
5376#ifdef FEAT_SEARCHPATH
5377 check_string_option(&buf->b_p_sua);
5378#endif
5379#ifdef FEAT_CINDENT
5380 check_string_option(&buf->b_p_cink);
5381 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005382 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005383#endif
5384#ifdef FEAT_AUTOCMD
5385 check_string_option(&buf->b_p_ft);
5386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5388 check_string_option(&buf->b_p_cinw);
5389#endif
5390#ifdef FEAT_INS_EXPAND
5391 check_string_option(&buf->b_p_cpt);
5392#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005393#ifdef FEAT_COMPL_FUNC
5394 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005395 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005397#ifdef FEAT_KEYMAP
5398 check_string_option(&buf->b_p_keymap);
5399#endif
5400#ifdef FEAT_QUICKFIX
5401 check_string_option(&buf->b_p_gp);
5402 check_string_option(&buf->b_p_mp);
5403 check_string_option(&buf->b_p_efm);
5404#endif
5405 check_string_option(&buf->b_p_ep);
5406 check_string_option(&buf->b_p_path);
5407 check_string_option(&buf->b_p_tags);
5408#ifdef FEAT_INS_EXPAND
5409 check_string_option(&buf->b_p_dict);
5410 check_string_option(&buf->b_p_tsr);
5411#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005412#ifdef FEAT_LISP
5413 check_string_option(&buf->b_p_lw);
5414#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005415}
5416
5417/*
5418 * Free the string allocated for an option.
5419 * Checks for the string being empty_option. This may happen if we're out of
5420 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5421 * check_options().
5422 * Does NOT check for P_ALLOCED flag!
5423 */
5424 void
5425free_string_option(p)
5426 char_u *p;
5427{
5428 if (p != empty_option)
5429 vim_free(p);
5430}
5431
5432 void
5433clear_string_option(pp)
5434 char_u **pp;
5435{
5436 if (*pp != empty_option)
5437 vim_free(*pp);
5438 *pp = empty_option;
5439}
5440
5441 static void
5442check_string_option(pp)
5443 char_u **pp;
5444{
5445 if (*pp == NULL)
5446 *pp = empty_option;
5447}
5448
5449/*
5450 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5451 */
5452 void
5453set_term_option_alloced(p)
5454 char_u **p;
5455{
5456 int opt_idx;
5457
5458 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5459 if (options[opt_idx].var == (char_u *)p)
5460 {
5461 options[opt_idx].flags |= P_ALLOCED;
5462 return;
5463 }
5464 return; /* cannot happen: didn't find it! */
5465}
5466
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005467#if defined(FEAT_EVAL) || defined(PROTO)
5468/*
5469 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5470 * Return FALSE when it wasn't.
5471 * Return -1 for an unknown option.
5472 */
5473 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005474was_set_insecurely(opt, opt_flags)
5475 char_u *opt;
5476 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005477{
5478 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005479 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005480
5481 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005482 {
5483 flagp = insecure_flag(idx, opt_flags);
5484 return (*flagp & P_INSECURE) != 0;
5485 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005486 EMSG2(_(e_intern2), "was_set_insecurely()");
5487 return -1;
5488}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005489
5490/*
5491 * Get a pointer to the flags used for the P_INSECURE flag of option
5492 * "opt_idx". For some local options a local flags field is used.
5493 */
5494 static long_u *
5495insecure_flag(opt_idx, opt_flags)
5496 int opt_idx;
5497 int opt_flags;
5498{
5499 if (opt_flags & OPT_LOCAL)
5500 switch ((int)options[opt_idx].indir)
5501 {
5502#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005503 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005504#endif
5505#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005506# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005507 case PV_FDE: return &curwin->w_p_fde_flags;
5508 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005509# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005510# ifdef FEAT_BEVAL
5511 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5512# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005513# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005514 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005515# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005516 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005517# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005518 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005519# endif
5520#endif
5521 }
5522
5523 /* Nothing special, return global flags field. */
5524 return &options[opt_idx].flags;
5525}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005526#endif
5527
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005528#ifdef FEAT_TITLE
5529static void redraw_titles __ARGS((void));
5530
5531/*
5532 * Redraw the window title and/or tab page text later.
5533 */
5534static void redraw_titles()
5535{
5536 need_maketitle = TRUE;
5537# ifdef FEAT_WINDOWS
5538 redraw_tabline = TRUE;
5539# endif
5540}
5541#endif
5542
Bram Moolenaar071d4272004-06-13 20:20:40 +00005543/*
5544 * Set a string option to a new value (without checking the effect).
5545 * The string is copied into allocated memory.
5546 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005547 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005548 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549 */
5550 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005551set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005552 char_u *name;
5553 int opt_idx;
5554 char_u *val;
5555 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005556 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005557{
5558 char_u *s;
5559 char_u **varp;
5560 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005561 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005562
Bram Moolenaar89d40322006-08-29 15:30:07 +00005563 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005565 idx = findoption(name);
5566 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005567 {
5568 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005569 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005570 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571 }
5572
Bram Moolenaar89d40322006-08-29 15:30:07 +00005573 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005574 return;
5575
5576 s = vim_strsave(val);
5577 if (s != NULL)
5578 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005579 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005580 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005581 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582 free_string_option(*varp);
5583 *varp = s;
5584
5585 /* For buffer/window local option may also set the global value. */
5586 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005587 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588
Bram Moolenaar89d40322006-08-29 15:30:07 +00005589 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590
5591 /* When setting both values of a global option with a local value,
5592 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005593 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005594 {
5595 free_string_option(*varp);
5596 *varp = empty_option;
5597 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005598# ifdef FEAT_EVAL
5599 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005600 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005601 set_sid == 0 ? current_SID : set_sid);
5602# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005603 }
5604}
5605
5606/*
5607 * Set global value for string option when it's a local option.
5608 */
5609 static void
5610set_string_option_global(opt_idx, varp)
5611 int opt_idx; /* option index */
5612 char_u **varp; /* pointer to option variable */
5613{
5614 char_u **p, *s;
5615
5616 /* the global value is always allocated */
5617 if (options[opt_idx].var == VAR_WIN)
5618 p = (char_u **)GLOBAL_WO(varp);
5619 else
5620 p = (char_u **)options[opt_idx].var;
5621 if (options[opt_idx].indir != PV_NONE
5622 && p != varp
5623 && (s = vim_strsave(*varp)) != NULL)
5624 {
5625 free_string_option(*p);
5626 *p = s;
5627 }
5628}
5629
5630/*
5631 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005632 *
5633 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005634 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005635 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636set_string_option(opt_idx, value, opt_flags)
5637 int opt_idx;
5638 char_u *value;
5639 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5640{
5641 char_u *s;
5642 char_u **varp;
5643 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005644 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645
5646 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005647 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005648
5649 s = vim_strsave(value);
5650 if (s != NULL)
5651 {
5652 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5653 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005654 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005655 ? OPT_GLOBAL : OPT_LOCAL)
5656 : opt_flags);
5657 oldval = *varp;
5658 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005659 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5660 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005661 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005663 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664}
5665
5666/*
5667 * Handle string options that need some action to perform when changed.
5668 * Returns NULL for success, or an error message for an error.
5669 */
5670 static char_u *
5671did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5672 opt_flags)
5673 int opt_idx; /* index in options[] table */
5674 char_u **varp; /* pointer to the option variable */
5675 int new_value_alloced; /* new value was allocated */
5676 char_u *oldval; /* previous value of the option */
5677 char_u *errbuf; /* buffer for errors, or NULL */
5678 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5679{
5680 char_u *errmsg = NULL;
5681 char_u *s, *p;
5682 int did_chartab = FALSE;
5683 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005684 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005685#ifdef FEAT_GUI
5686 /* set when changing an option that only requires a redraw in the GUI */
5687 int redraw_gui_only = FALSE;
5688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689
5690 /* Get the global option to compare with, otherwise we would have to check
5691 * two values for all local options. */
5692 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5693
5694 /* Disallow changing some options from secure mode */
5695 if ((secure
5696#ifdef HAVE_SANDBOX
5697 || sandbox != 0
5698#endif
5699 ) && (options[opt_idx].flags & P_SECURE))
5700 {
5701 errmsg = e_secure;
5702 }
5703
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005704 /* Check for a "normal" file name in some options. Disallow a path
5705 * separator (slash and/or backslash), wildcards and characters that are
5706 * often illegal in a file name. */
5707 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005708 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005709 {
5710 errmsg = e_invarg;
5711 }
5712
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713 /* 'term' */
5714 else if (varp == &T_NAME)
5715 {
5716 if (T_NAME[0] == NUL)
5717 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5718#ifdef FEAT_GUI
5719 if (gui.in_use)
5720 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5721 else if (term_is_gui(T_NAME))
5722 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5723#endif
5724 else if (set_termname(T_NAME) == FAIL)
5725 errmsg = (char_u *)N_("E522: Not found in termcap");
5726 else
5727 /* Screen colors may have changed. */
5728 redraw_later_clear();
5729 }
5730
5731 /* 'backupcopy' */
5732 else if (varp == &p_bkc)
5733 {
5734 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5735 errmsg = e_invarg;
5736 if (((bkc_flags & BKC_AUTO) != 0)
5737 + ((bkc_flags & BKC_YES) != 0)
5738 + ((bkc_flags & BKC_NO) != 0) != 1)
5739 {
5740 /* Must have exactly one of "auto", "yes" and "no". */
5741 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5742 errmsg = e_invarg;
5743 }
5744 }
5745
5746 /* 'backupext' and 'patchmode' */
5747 else if (varp == &p_bex || varp == &p_pm)
5748 {
5749 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5750 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5751 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5752 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005753#ifdef FEAT_LINEBREAK
5754 /* 'breakindentopt' */
5755 else if (varp == &curwin->w_p_briopt)
5756 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005757 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005758 errmsg = e_invarg;
5759 }
5760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005761
5762 /*
5763 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5764 * If the new option is invalid, use old value. 'lisp' option: refill
5765 * chartab[] for '-' char
5766 */
5767 else if ( varp == &p_isi
5768 || varp == &(curbuf->b_p_isk)
5769 || varp == &p_isp
5770 || varp == &p_isf)
5771 {
5772 if (init_chartab() == FAIL)
5773 {
5774 did_chartab = TRUE; /* need to restore it below */
5775 errmsg = e_invarg; /* error in value */
5776 }
5777 }
5778
5779 /* 'helpfile' */
5780 else if (varp == &p_hf)
5781 {
5782 /* May compute new values for $VIM and $VIMRUNTIME */
5783 if (didset_vim)
5784 {
5785 vim_setenv((char_u *)"VIM", (char_u *)"");
5786 didset_vim = FALSE;
5787 }
5788 if (didset_vimruntime)
5789 {
5790 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5791 didset_vimruntime = FALSE;
5792 }
5793 }
5794
Bram Moolenaar1a384422010-07-14 19:53:30 +02005795#ifdef FEAT_SYN_HL
5796 /* 'colorcolumn' */
5797 else if (varp == &curwin->w_p_cc)
5798 errmsg = check_colorcolumn(curwin);
5799#endif
5800
Bram Moolenaar071d4272004-06-13 20:20:40 +00005801#ifdef FEAT_MULTI_LANG
5802 /* 'helplang' */
5803 else if (varp == &p_hlg)
5804 {
5805 /* Check for "", "ab", "ab,cd", etc. */
5806 for (s = p_hlg; *s != NUL; s += 3)
5807 {
5808 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5809 {
5810 errmsg = e_invarg;
5811 break;
5812 }
5813 if (s[2] == NUL)
5814 break;
5815 }
5816 }
5817#endif
5818
5819 /* 'highlight' */
5820 else if (varp == &p_hl)
5821 {
5822 if (highlight_changed() == FAIL)
5823 errmsg = e_invarg; /* invalid flags */
5824 }
5825
5826 /* 'nrformats' */
5827 else if (gvarp == &p_nf)
5828 {
5829 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5830 errmsg = e_invarg;
5831 }
5832
5833#ifdef FEAT_SESSION
5834 /* 'sessionoptions' */
5835 else if (varp == &p_ssop)
5836 {
5837 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5838 errmsg = e_invarg;
5839 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5840 {
5841 /* Don't allow both "sesdir" and "curdir". */
5842 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5843 errmsg = e_invarg;
5844 }
5845 }
5846 /* 'viewoptions' */
5847 else if (varp == &p_vop)
5848 {
5849 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5850 errmsg = e_invarg;
5851 }
5852#endif
5853
5854 /* 'scrollopt' */
5855#ifdef FEAT_SCROLLBIND
5856 else if (varp == &p_sbo)
5857 {
5858 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5859 errmsg = e_invarg;
5860 }
5861#endif
5862
5863 /* 'ambiwidth' */
5864#ifdef FEAT_MBYTE
5865 else if (varp == &p_ambw)
5866 {
5867 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5868 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005869 else if (set_chars_option(&p_lcs) != NULL)
5870 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5871# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5872 else if (set_chars_option(&p_fcs) != NULL)
5873 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5874# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875 }
5876#endif
5877
5878 /* 'background' */
5879 else if (varp == &p_bg)
5880 {
5881 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5882 {
5883#ifdef FEAT_EVAL
5884 int dark = (*p_bg == 'd');
5885#endif
5886
5887 init_highlight(FALSE, FALSE);
5888
5889#ifdef FEAT_EVAL
5890 if (dark != (*p_bg == 'd')
5891 && get_var_value((char_u *)"g:colors_name") != NULL)
5892 {
5893 /* The color scheme must have set 'background' back to another
5894 * value, that's not what we want here. Disable the color
5895 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005896 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005897 free_string_option(p_bg);
5898 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5899 check_string_option(&p_bg);
5900 init_highlight(FALSE, FALSE);
5901 }
5902#endif
5903 }
5904 else
5905 errmsg = e_invarg;
5906 }
5907
5908 /* 'wildmode' */
5909 else if (varp == &p_wim)
5910 {
5911 if (check_opt_wim() == FAIL)
5912 errmsg = e_invarg;
5913 }
5914
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005915#ifdef FEAT_CMDL_COMPL
5916 /* 'wildoptions' */
5917 else if (varp == &p_wop)
5918 {
5919 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5920 errmsg = e_invarg;
5921 }
5922#endif
5923
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924#ifdef FEAT_WAK
5925 /* 'winaltkeys' */
5926 else if (varp == &p_wak)
5927 {
5928 if (*p_wak == NUL
5929 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5930 errmsg = e_invarg;
5931# ifdef FEAT_MENU
5932# ifdef FEAT_GUI_MOTIF
5933 else if (gui.in_use)
5934 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5935# else
5936# ifdef FEAT_GUI_GTK
5937 else if (gui.in_use)
5938 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5939# endif
5940# endif
5941# endif
5942 }
5943#endif
5944
5945#ifdef FEAT_AUTOCMD
5946 /* 'eventignore' */
5947 else if (varp == &p_ei)
5948 {
5949 if (check_ei() == FAIL)
5950 errmsg = e_invarg;
5951 }
5952#endif
5953
5954#ifdef FEAT_MBYTE
5955 /* 'encoding' and 'fileencoding' */
5956 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5957 {
5958 if (gvarp == &p_fenc)
5959 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005960 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005961 errmsg = e_modifiable;
5962 else if (vim_strchr(*varp, ',') != NULL)
5963 /* No comma allowed in 'fileencoding'; catches confusing it
5964 * with 'fileencodings'. */
5965 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005967 {
5968# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005970 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005971# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005972 /* Add 'fileencoding' to the swap file. */
5973 ml_setflags(curbuf);
5974 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975 }
5976 if (errmsg == NULL)
5977 {
5978 /* canonize the value, so that STRCMP() can be used on it */
5979 p = enc_canonize(*varp);
5980 if (p != NULL)
5981 {
5982 vim_free(*varp);
5983 *varp = p;
5984 }
5985 if (varp == &p_enc)
5986 {
5987 errmsg = mb_init();
5988# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005989 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990# endif
5991 }
5992 }
5993
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005994# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005995 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5996 {
5997 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5998 if (STRCMP(p_tenc, "utf-8") != 0)
5999 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6000 }
6001# endif
6002
6003 if (errmsg == NULL)
6004 {
6005# ifdef FEAT_KEYMAP
6006 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6007 * (with another encoding). */
6008 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6009 (void)keymap_init();
6010# endif
6011
6012 /* When 'termencoding' is not empty and 'encoding' changes or when
6013 * 'termencoding' changes, need to setup for keyboard input and
6014 * display output conversion. */
6015 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6016 {
6017 convert_setup(&input_conv, p_tenc, p_enc);
6018 convert_setup(&output_conv, p_enc, p_tenc);
6019 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006020
6021# if defined(WIN3264) && defined(FEAT_MBYTE)
6022 /* $HOME may have characters in active code page. */
6023 if (varp == &p_enc)
6024 init_homedir();
6025# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006026 }
6027 }
6028#endif
6029
6030#if defined(FEAT_POSTSCRIPT)
6031 else if (varp == &p_penc)
6032 {
6033 /* Canonize printencoding if VIM standard one */
6034 p = enc_canonize(p_penc);
6035 if (p != NULL)
6036 {
6037 vim_free(p_penc);
6038 p_penc = p;
6039 }
6040 else
6041 {
6042 /* Ensure lower case and '-' for '_' */
6043 for (s = p_penc; *s != NUL; s++)
6044 {
6045 if (*s == '_')
6046 *s = '-';
6047 else
6048 *s = TOLOWER_ASC(*s);
6049 }
6050 }
6051 }
6052#endif
6053
Bram Moolenaar9372a112005-12-06 19:59:18 +00006054#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006055 else if (varp == &p_imak)
6056 {
6057 if (gui.in_use && !im_xim_isvalid_imactivate())
6058 errmsg = e_invarg;
6059 }
6060#endif
6061
6062#ifdef FEAT_KEYMAP
6063 else if (varp == &curbuf->b_p_keymap)
6064 {
6065 /* load or unload key mapping tables */
6066 errmsg = keymap_init();
6067
Bram Moolenaarfab06232009-03-04 03:13:35 +00006068 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006069 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006070 if (*curbuf->b_p_keymap != NUL)
6071 {
6072 /* Installed a new keymap, switch on using it. */
6073 curbuf->b_p_iminsert = B_IMODE_LMAP;
6074 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6075 curbuf->b_p_imsearch = B_IMODE_LMAP;
6076 }
6077 else
6078 {
6079 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6080 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6081 curbuf->b_p_iminsert = B_IMODE_NONE;
6082 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6083 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6084 }
6085 if ((opt_flags & OPT_LOCAL) == 0)
6086 {
6087 set_iminsert_global();
6088 set_imsearch_global();
6089 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006090# ifdef FEAT_WINDOWS
6091 status_redraw_curbuf();
6092# endif
6093 }
6094 }
6095#endif
6096
6097 /* 'fileformat' */
6098 else if (gvarp == &p_ff)
6099 {
6100 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6101 errmsg = e_modifiable;
6102 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6103 errmsg = e_invarg;
6104 else
6105 {
6106 /* may also change 'textmode' */
6107 if (get_fileformat(curbuf) == EOL_DOS)
6108 curbuf->b_p_tx = TRUE;
6109 else
6110 curbuf->b_p_tx = FALSE;
6111#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006112 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006114 /* update flag in swap file */
6115 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006116 /* Redraw needed when switching to/from "mac": a CR in the text
6117 * will be displayed differently. */
6118 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6119 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006120 }
6121 }
6122
6123 /* 'fileformats' */
6124 else if (varp == &p_ffs)
6125 {
6126 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6127 errmsg = e_invarg;
6128 else
6129 {
6130 /* also change 'textauto' */
6131 if (*p_ffs == NUL)
6132 p_ta = FALSE;
6133 else
6134 p_ta = TRUE;
6135 }
6136 }
6137
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006138#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139 /* 'cryptkey' */
6140 else if (gvarp == &p_key)
6141 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006142# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006143 /* Make sure the ":set" command doesn't show the new value in the
6144 * history. */
6145 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006146# endif
6147 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6148 /* Need to update the swapfile. */
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006149 ml_set_crypt_key(curbuf, oldval, crypt_get_method_nr(curbuf));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006150 }
6151
6152 else if (gvarp == &p_cm)
6153 {
6154 if (opt_flags & OPT_LOCAL)
6155 p = curbuf->b_p_cm;
6156 else
6157 p = p_cm;
6158 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6159 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006160 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006161 errmsg = e_invarg;
6162 else
6163 {
6164 /* When setting the global value to empty, make it "zip". */
6165 if (*p_cm == NUL)
6166 {
6167 if (new_value_alloced)
6168 free_string_option(p_cm);
6169 p_cm = vim_strsave((char_u *)"zip");
6170 new_value_alloced = TRUE;
6171 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006172 /* When using ":set cm=name" the local value is going to be empty.
6173 * Do that here, otherwise the crypt functions will still use the
6174 * local value. */
6175 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6176 {
6177 free_string_option(curbuf->b_p_cm);
6178 curbuf->b_p_cm = empty_option;
6179 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006180
6181 /* Need to update the swapfile when the effective method changed.
6182 * Set "s" to the effective old value, "p" to the effective new
6183 * method and compare. */
6184 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6185 s = p_cm; /* was previously using the global value */
6186 else
6187 s = oldval;
6188 if (*curbuf->b_p_cm == NUL)
6189 p = p_cm; /* is now using the global value */
6190 else
6191 p = curbuf->b_p_cm;
6192 if (STRCMP(s, p) != 0)
6193 ml_set_crypt_key(curbuf, curbuf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006194 crypt_method_nr_from_name(s));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006195
6196 /* If the global value changes need to update the swapfile for all
6197 * buffers using that value. */
6198 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6199 {
6200 buf_T *buf;
6201
6202 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6203 if (buf != curbuf && *buf->b_p_cm == NUL)
6204 ml_set_crypt_key(buf, buf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006205 crypt_method_nr_from_name(oldval));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006206 }
6207 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006208 }
6209#endif
6210
6211 /* 'matchpairs' */
6212 else if (gvarp == &p_mps)
6213 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006214#ifdef FEAT_MBYTE
6215 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006216 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006217 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006218 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006219 int x2 = -1;
6220 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006221
6222 if (*p != NUL)
6223 p += mb_ptr2len(p);
6224 if (*p != NUL)
6225 x2 = *p++;
6226 if (*p != NUL)
6227 {
6228 x3 = mb_ptr2char(p);
6229 p += mb_ptr2len(p);
6230 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006231 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006232 {
6233 errmsg = e_invarg;
6234 break;
6235 }
6236 if (*p == NUL)
6237 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006238 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006239 }
6240 else
6241#endif
6242 {
6243 /* Check for "x:y,x:y" */
6244 for (p = *varp; *p != NUL; p += 4)
6245 {
6246 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6247 {
6248 errmsg = e_invarg;
6249 break;
6250 }
6251 if (p[3] == NUL)
6252 break;
6253 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006254 }
6255 }
6256
6257#ifdef FEAT_COMMENTS
6258 /* 'comments' */
6259 else if (gvarp == &p_com)
6260 {
6261 for (s = *varp; *s; )
6262 {
6263 while (*s && *s != ':')
6264 {
6265 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6266 && !VIM_ISDIGIT(*s) && *s != '-')
6267 {
6268 errmsg = illegal_char(errbuf, *s);
6269 break;
6270 }
6271 ++s;
6272 }
6273 if (*s++ == NUL)
6274 errmsg = (char_u *)N_("E524: Missing colon");
6275 else if (*s == ',' || *s == NUL)
6276 errmsg = (char_u *)N_("E525: Zero length string");
6277 if (errmsg != NULL)
6278 break;
6279 while (*s && *s != ',')
6280 {
6281 if (*s == '\\' && s[1] != NUL)
6282 ++s;
6283 ++s;
6284 }
6285 s = skip_to_option_part(s);
6286 }
6287 }
6288#endif
6289
6290 /* 'listchars' */
6291 else if (varp == &p_lcs)
6292 {
6293 errmsg = set_chars_option(varp);
6294 }
6295
6296#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6297 /* 'fillchars' */
6298 else if (varp == &p_fcs)
6299 {
6300 errmsg = set_chars_option(varp);
6301 }
6302#endif
6303
6304#ifdef FEAT_CMDWIN
6305 /* 'cedit' */
6306 else if (varp == &p_cedit)
6307 {
6308 errmsg = check_cedit();
6309 }
6310#endif
6311
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006312 /* 'verbosefile' */
6313 else if (varp == &p_vfile)
6314 {
6315 verbose_stop();
6316 if (*p_vfile != NUL && verbose_open() == FAIL)
6317 errmsg = e_invarg;
6318 }
6319
Bram Moolenaar071d4272004-06-13 20:20:40 +00006320#ifdef FEAT_VIMINFO
6321 /* 'viminfo' */
6322 else if (varp == &p_viminfo)
6323 {
6324 for (s = p_viminfo; *s;)
6325 {
6326 /* Check it's a valid character */
6327 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6328 {
6329 errmsg = illegal_char(errbuf, *s);
6330 break;
6331 }
6332 if (*s == 'n') /* name is always last one */
6333 {
6334 break;
6335 }
6336 else if (*s == 'r') /* skip until next ',' */
6337 {
6338 while (*++s && *s != ',')
6339 ;
6340 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006341 else if (*s == '%')
6342 {
6343 /* optional number */
6344 while (vim_isdigit(*++s))
6345 ;
6346 }
6347 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348 ++s; /* no extra chars */
6349 else /* must have a number */
6350 {
6351 while (vim_isdigit(*++s))
6352 ;
6353
6354 if (!VIM_ISDIGIT(*(s - 1)))
6355 {
6356 if (errbuf != NULL)
6357 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006358 sprintf((char *)errbuf,
6359 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006360 transchar_byte(*(s - 1)));
6361 errmsg = errbuf;
6362 }
6363 else
6364 errmsg = (char_u *)"";
6365 break;
6366 }
6367 }
6368 if (*s == ',')
6369 ++s;
6370 else if (*s)
6371 {
6372 if (errbuf != NULL)
6373 errmsg = (char_u *)N_("E527: Missing comma");
6374 else
6375 errmsg = (char_u *)"";
6376 break;
6377 }
6378 }
6379 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6380 errmsg = (char_u *)N_("E528: Must specify a ' value");
6381 }
6382#endif /* FEAT_VIMINFO */
6383
6384 /* terminal options */
6385 else if (istermoption(&options[opt_idx]) && full_screen)
6386 {
6387 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6388 if (varp == &T_CCO)
6389 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006390 int colors = atoi((char *)T_CCO);
6391
6392 /* Only reinitialize colors if t_Co value has really changed to
6393 * avoid expensive reload of colorscheme if t_Co is set to the
6394 * same value multiple times. */
6395 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006397 t_colors = colors;
6398 if (t_colors <= 1)
6399 {
6400 if (new_value_alloced)
6401 vim_free(T_CCO);
6402 T_CCO = empty_option;
6403 }
6404 /* We now have a different color setup, initialize it again. */
6405 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006406 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006407 }
6408 ttest(FALSE);
6409 if (varp == &T_ME)
6410 {
6411 out_str(T_ME);
6412 redraw_later(CLEAR);
6413#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6414 /* Since t_me has been set, this probably means that the user
6415 * wants to use this as default colors. Need to reset default
6416 * background/foreground colors. */
6417 mch_set_normal_colors();
6418#endif
6419 }
6420 }
6421
6422#ifdef FEAT_LINEBREAK
6423 /* 'showbreak' */
6424 else if (varp == &p_sbr)
6425 {
6426 for (s = p_sbr; *s; )
6427 {
6428 if (ptr2cells(s) != 1)
6429 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006430 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006431 }
6432 }
6433#endif
6434
6435#ifdef FEAT_GUI
6436 /* 'guifont' */
6437 else if (varp == &p_guifont)
6438 {
6439 if (gui.in_use)
6440 {
6441 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006442# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006443 /*
6444 * Put up a font dialog and let the user select a new value.
6445 * If this is cancelled go back to the old value but don't
6446 * give an error message.
6447 */
6448 if (STRCMP(p, "*") == 0)
6449 {
6450 p = gui_mch_font_dialog(oldval);
6451
6452 if (new_value_alloced)
6453 free_string_option(p_guifont);
6454
6455 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6456 new_value_alloced = TRUE;
6457 }
6458# endif
6459 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6460 {
6461# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6462 if (STRCMP(p_guifont, "*") == 0)
6463 {
6464 /* Dialog was cancelled: Keep the old value without giving
6465 * an error message. */
6466 if (new_value_alloced)
6467 free_string_option(p_guifont);
6468 p_guifont = vim_strsave(oldval);
6469 new_value_alloced = TRUE;
6470 }
6471 else
6472# endif
6473 errmsg = (char_u *)N_("E596: Invalid font(s)");
6474 }
6475 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006476 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006477 }
6478# ifdef FEAT_XFONTSET
6479 else if (varp == &p_guifontset)
6480 {
6481 if (STRCMP(p_guifontset, "*") == 0)
6482 errmsg = (char_u *)N_("E597: can't select fontset");
6483 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6484 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006485 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006486 }
6487# endif
6488# ifdef FEAT_MBYTE
6489 else if (varp == &p_guifontwide)
6490 {
6491 if (STRCMP(p_guifontwide, "*") == 0)
6492 errmsg = (char_u *)N_("E533: can't select wide font");
6493 else if (gui_get_wide_font() == FAIL)
6494 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006495 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006496 }
6497# endif
6498#endif
6499
6500#ifdef CURSOR_SHAPE
6501 /* 'guicursor' */
6502 else if (varp == &p_guicursor)
6503 errmsg = parse_shape_opt(SHAPE_CURSOR);
6504#endif
6505
6506#ifdef FEAT_MOUSESHAPE
6507 /* 'mouseshape' */
6508 else if (varp == &p_mouseshape)
6509 {
6510 errmsg = parse_shape_opt(SHAPE_MOUSE);
6511 update_mouseshape(-1);
6512 }
6513#endif
6514
6515#ifdef FEAT_PRINTER
6516 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006517 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006518# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006519 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006520 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006521# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522#endif
6523
6524#ifdef FEAT_LANGMAP
6525 /* 'langmap' */
6526 else if (varp == &p_langmap)
6527 langmap_set();
6528#endif
6529
6530#ifdef FEAT_LINEBREAK
6531 /* 'breakat' */
6532 else if (varp == &p_breakat)
6533 fill_breakat_flags();
6534#endif
6535
6536#ifdef FEAT_TITLE
6537 /* 'titlestring' and 'iconstring' */
6538 else if (varp == &p_titlestring || varp == &p_iconstring)
6539 {
6540# ifdef FEAT_STL_OPT
6541 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6542
6543 /* NULL => statusline syntax */
6544 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6545 stl_syntax |= flagval;
6546 else
6547 stl_syntax &= ~flagval;
6548# endif
6549 did_set_title(varp == &p_iconstring);
6550
6551 }
6552#endif
6553
6554#ifdef FEAT_GUI
6555 /* 'guioptions' */
6556 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006557 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006558 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006559 redraw_gui_only = TRUE;
6560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006561#endif
6562
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006563#if defined(FEAT_GUI_TABLINE)
6564 /* 'guitablabel' */
6565 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006566 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006567 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006568 redraw_gui_only = TRUE;
6569 }
6570 /* 'guitabtooltip' */
6571 else if (varp == &p_gtt)
6572 {
6573 redraw_gui_only = TRUE;
6574 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006575#endif
6576
Bram Moolenaar071d4272004-06-13 20:20:40 +00006577#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6578 /* 'ttymouse' */
6579 else if (varp == &p_ttym)
6580 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006581 /* Switch the mouse off before changing the escape sequences used for
6582 * that. */
6583 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006584 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6585 errmsg = e_invarg;
6586 else
6587 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006588 if (termcap_active)
6589 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590 }
6591#endif
6592
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593 /* 'selection' */
6594 else if (varp == &p_sel)
6595 {
6596 if (*p_sel == NUL
6597 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6598 errmsg = e_invarg;
6599 }
6600
6601 /* 'selectmode' */
6602 else if (varp == &p_slm)
6603 {
6604 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6605 errmsg = e_invarg;
6606 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006607
6608#ifdef FEAT_BROWSE
6609 /* 'browsedir' */
6610 else if (varp == &p_bsdir)
6611 {
6612 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6613 && !mch_isdir(p_bsdir))
6614 errmsg = e_invarg;
6615 }
6616#endif
6617
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 /* 'keymodel' */
6619 else if (varp == &p_km)
6620 {
6621 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6622 errmsg = e_invarg;
6623 else
6624 {
6625 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6626 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6627 }
6628 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006629
6630 /* 'mousemodel' */
6631 else if (varp == &p_mousem)
6632 {
6633 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6634 errmsg = e_invarg;
6635#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6636 else if (*p_mousem != *oldval)
6637 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6638 * to create or delete the popup menus. */
6639 gui_motif_update_mousemodel(root_menu);
6640#endif
6641 }
6642
6643 /* 'switchbuf' */
6644 else if (varp == &p_swb)
6645 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006646 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006647 errmsg = e_invarg;
6648 }
6649
6650 /* 'debug' */
6651 else if (varp == &p_debug)
6652 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006653 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 errmsg = e_invarg;
6655 }
6656
6657 /* 'display' */
6658 else if (varp == &p_dy)
6659 {
6660 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6661 errmsg = e_invarg;
6662 else
6663 (void)init_chartab();
6664
6665 }
6666
6667#ifdef FEAT_VERTSPLIT
6668 /* 'eadirection' */
6669 else if (varp == &p_ead)
6670 {
6671 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6672 errmsg = e_invarg;
6673 }
6674#endif
6675
6676#ifdef FEAT_CLIPBOARD
6677 /* 'clipboard' */
6678 else if (varp == &p_cb)
6679 errmsg = check_clipboard_option();
6680#endif
6681
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006682#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006683 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6684 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006685 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006686 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006687 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006688 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006689
Bram Moolenaar860cae12010-06-05 23:22:07 +02006690 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006691 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006692 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6693 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006694 ".add") != 0))
6695 errmsg = e_invarg;
6696 }
6697
6698 if (errmsg == NULL)
6699 {
6700 FOR_ALL_WINDOWS(wp)
6701 if (wp->w_buffer == curbuf && wp->w_p_spell)
6702 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006703 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006704# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006705 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006706# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006707 }
6708 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006709 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006710 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006711 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006712 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006713 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006714 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006715 /* 'spellsuggest' */
6716 else if (varp == &p_sps)
6717 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006718 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006719 errmsg = e_invarg;
6720 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006721 /* 'mkspellmem' */
6722 else if (varp == &p_msm)
6723 {
6724 if (spell_check_msm() != OK)
6725 errmsg = e_invarg;
6726 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006727#endif
6728
Bram Moolenaar071d4272004-06-13 20:20:40 +00006729#ifdef FEAT_QUICKFIX
6730 /* When 'bufhidden' is set, check for valid value. */
6731 else if (gvarp == &p_bh)
6732 {
6733 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6734 errmsg = e_invarg;
6735 }
6736
6737 /* When 'buftype' is set, check for valid value. */
6738 else if (gvarp == &p_bt)
6739 {
6740 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6741 errmsg = e_invarg;
6742 else
6743 {
6744# ifdef FEAT_WINDOWS
6745 if (curwin->w_status_height)
6746 {
6747 curwin->w_redr_status = TRUE;
6748 redraw_later(VALID);
6749 }
6750# endif
6751 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006752# ifdef FEAT_TITLE
6753 redraw_titles();
6754# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006755 }
6756 }
6757#endif
6758
6759#ifdef FEAT_STL_OPT
6760 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006761 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006762 {
6763 int wid;
6764
6765 if (varp == &p_ruf) /* reset ru_wid first */
6766 ru_wid = 0;
6767 s = *varp;
6768 if (varp == &p_ruf && *s == '%')
6769 {
6770 /* set ru_wid if 'ruf' starts with "%99(" */
6771 if (*++s == '-') /* ignore a '-' */
6772 s++;
6773 wid = getdigits(&s);
6774 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6775 ru_wid = wid;
6776 else
6777 errmsg = check_stl_option(p_ruf);
6778 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006779 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006780 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006781 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006782 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 comp_col();
6784 }
6785#endif
6786
6787#ifdef FEAT_INS_EXPAND
6788 /* check if it is a valid value for 'complete' -- Acevedo */
6789 else if (gvarp == &p_cpt)
6790 {
6791 for (s = *varp; *s;)
6792 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006793 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006794 s++;
6795 if (!*s)
6796 break;
6797 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6798 {
6799 errmsg = illegal_char(errbuf, *s);
6800 break;
6801 }
6802 if (*++s != NUL && *s != ',' && *s != ' ')
6803 {
6804 if (s[-1] == 'k' || s[-1] == 's')
6805 {
6806 /* skip optional filename after 'k' and 's' */
6807 while (*s && *s != ',' && *s != ' ')
6808 {
6809 if (*s == '\\')
6810 ++s;
6811 ++s;
6812 }
6813 }
6814 else
6815 {
6816 if (errbuf != NULL)
6817 {
6818 sprintf((char *)errbuf,
6819 _("E535: Illegal character after <%c>"),
6820 *--s);
6821 errmsg = errbuf;
6822 }
6823 else
6824 errmsg = (char_u *)"";
6825 break;
6826 }
6827 }
6828 }
6829 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006830
6831 /* 'completeopt' */
6832 else if (varp == &p_cot)
6833 {
6834 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6835 errmsg = e_invarg;
6836 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006837#endif /* FEAT_INS_EXPAND */
6838
6839
6840#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6841 else if (varp == &p_toolbar)
6842 {
6843 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6844 &toolbar_flags, TRUE) != OK)
6845 errmsg = e_invarg;
6846 else
6847 {
6848 out_flush();
6849 gui_mch_show_toolbar((toolbar_flags &
6850 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6851 }
6852 }
6853#endif
6854
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006855#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006856 /* 'toolbariconsize': GTK+ 2 only */
6857 else if (varp == &p_tbis)
6858 {
6859 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6860 errmsg = e_invarg;
6861 else
6862 {
6863 out_flush();
6864 gui_mch_show_toolbar((toolbar_flags &
6865 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6866 }
6867 }
6868#endif
6869
6870 /* 'pastetoggle': translate key codes like in a mapping */
6871 else if (varp == &p_pt)
6872 {
6873 if (*p_pt)
6874 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006875 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006876 if (p != NULL)
6877 {
6878 if (new_value_alloced)
6879 free_string_option(p_pt);
6880 p_pt = p;
6881 new_value_alloced = TRUE;
6882 }
6883 }
6884 }
6885
6886 /* 'backspace' */
6887 else if (varp == &p_bs)
6888 {
6889 if (VIM_ISDIGIT(*p_bs))
6890 {
6891 if (*p_bs >'2' || p_bs[1] != NUL)
6892 errmsg = e_invarg;
6893 }
6894 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6895 errmsg = e_invarg;
6896 }
6897
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006898#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 /* 'casemap' */
6900 else if (varp == &p_cmp)
6901 {
6902 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6903 errmsg = e_invarg;
6904 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006905#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906
6907#ifdef FEAT_DIFF
6908 /* 'diffopt' */
6909 else if (varp == &p_dip)
6910 {
6911 if (diffopt_changed() == FAIL)
6912 errmsg = e_invarg;
6913 }
6914#endif
6915
6916#ifdef FEAT_FOLDING
6917 /* 'foldmethod' */
6918 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6919 {
6920 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6921 || *curwin->w_p_fdm == NUL)
6922 errmsg = e_invarg;
6923 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006924 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006926 if (foldmethodIsDiff(curwin))
6927 newFoldLevel();
6928 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006929 }
6930# ifdef FEAT_EVAL
6931 /* 'foldexpr' */
6932 else if (varp == &curwin->w_p_fde)
6933 {
6934 if (foldmethodIsExpr(curwin))
6935 foldUpdateAll(curwin);
6936 }
6937# endif
6938 /* 'foldmarker' */
6939 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6940 {
6941 p = vim_strchr(*varp, ',');
6942 if (p == NULL)
6943 errmsg = (char_u *)N_("E536: comma required");
6944 else if (p == *varp || p[1] == NUL)
6945 errmsg = e_invarg;
6946 else if (foldmethodIsMarker(curwin))
6947 foldUpdateAll(curwin);
6948 }
6949 /* 'commentstring' */
6950 else if (gvarp == &p_cms)
6951 {
6952 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6953 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6954 }
6955 /* 'foldopen' */
6956 else if (varp == &p_fdo)
6957 {
6958 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6959 errmsg = e_invarg;
6960 }
6961 /* 'foldclose' */
6962 else if (varp == &p_fcl)
6963 {
6964 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6965 errmsg = e_invarg;
6966 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006967 /* 'foldignore' */
6968 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6969 {
6970 if (foldmethodIsIndent(curwin))
6971 foldUpdateAll(curwin);
6972 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973#endif
6974
6975#ifdef FEAT_VIRTUALEDIT
6976 /* 'virtualedit' */
6977 else if (varp == &p_ve)
6978 {
6979 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6980 errmsg = e_invarg;
6981 else if (STRCMP(p_ve, oldval) != 0)
6982 {
6983 /* Recompute cursor position in case the new 've' setting
6984 * changes something. */
6985 validate_virtcol();
6986 coladvance(curwin->w_virtcol);
6987 }
6988 }
6989#endif
6990
6991#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6992 else if (varp == &p_csqf)
6993 {
6994 if (p_csqf != NULL)
6995 {
6996 p = p_csqf;
6997 while (*p != NUL)
6998 {
6999 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7000 || p[1] == NUL
7001 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7002 || (p[2] != NUL && p[2] != ','))
7003 {
7004 errmsg = e_invarg;
7005 break;
7006 }
7007 else if (p[2] == NUL)
7008 break;
7009 else
7010 p += 3;
7011 }
7012 }
7013 }
7014#endif
7015
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007016#ifdef FEAT_CINDENT
7017 /* 'cinoptions' */
7018 else if (gvarp == &p_cino)
7019 {
7020 /* TODO: recognize errors */
7021 parse_cino(curbuf);
7022 }
7023#endif
7024
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007025#if defined(FEAT_RENDER_OPTIONS)
7026 else if (varp == &p_rop && gui.in_use)
7027 {
7028 if (!gui_mch_set_rendering_options(p_rop))
7029 errmsg = e_invarg;
7030 }
7031#endif
7032
Bram Moolenaar071d4272004-06-13 20:20:40 +00007033 /* Options that are a list of flags. */
7034 else
7035 {
7036 p = NULL;
7037 if (varp == &p_ww)
7038 p = (char_u *)WW_ALL;
7039 if (varp == &p_shm)
7040 p = (char_u *)SHM_ALL;
7041 else if (varp == &(p_cpo))
7042 p = (char_u *)CPO_ALL;
7043 else if (varp == &(curbuf->b_p_fo))
7044 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007045#ifdef FEAT_CONCEAL
7046 else if (varp == &curwin->w_p_cocu)
7047 p = (char_u *)COCU_ALL;
7048#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049 else if (varp == &p_mouse)
7050 {
7051#ifdef FEAT_MOUSE
7052 p = (char_u *)MOUSE_ALL;
7053#else
7054 if (*p_mouse != NUL)
7055 errmsg = (char_u *)N_("E538: No mouse support");
7056#endif
7057 }
7058#if defined(FEAT_GUI)
7059 else if (varp == &p_go)
7060 p = (char_u *)GO_ALL;
7061#endif
7062 if (p != NULL)
7063 {
7064 for (s = *varp; *s; ++s)
7065 if (vim_strchr(p, *s) == NULL)
7066 {
7067 errmsg = illegal_char(errbuf, *s);
7068 break;
7069 }
7070 }
7071 }
7072
7073 /*
7074 * If error detected, restore the previous value.
7075 */
7076 if (errmsg != NULL)
7077 {
7078 if (new_value_alloced)
7079 free_string_option(*varp);
7080 *varp = oldval;
7081 /*
7082 * When resetting some values, need to act on it.
7083 */
7084 if (did_chartab)
7085 (void)init_chartab();
7086 if (varp == &p_hl)
7087 (void)highlight_changed();
7088 }
7089 else
7090 {
7091#ifdef FEAT_EVAL
7092 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007093 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007094#endif
7095 /*
7096 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007097 * Use "free_oldval", because recursiveness may change the flags under
7098 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007099 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007100 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007101 free_string_option(oldval);
7102 if (new_value_alloced)
7103 options[opt_idx].flags |= P_ALLOCED;
7104 else
7105 options[opt_idx].flags &= ~P_ALLOCED;
7106
7107 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007108 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007109 {
7110 /* global option with local value set to use global value; free
7111 * the local value and make it empty */
7112 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7113 free_string_option(*(char_u **)p);
7114 *(char_u **)p = empty_option;
7115 }
7116
7117 /* May set global value for local option. */
7118 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7119 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007120
7121#ifdef FEAT_AUTOCMD
7122 /*
7123 * Trigger the autocommand only after setting the flags.
7124 */
7125# ifdef FEAT_SYN_HL
7126 /* When 'syntax' is set, load the syntax of that name */
7127 if (varp == &(curbuf->b_p_syn))
7128 {
7129 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7130 curbuf->b_fname, TRUE, curbuf);
7131 }
7132# endif
7133 else if (varp == &(curbuf->b_p_ft))
7134 {
7135 /* 'filetype' is set, trigger the FileType autocommand */
7136 did_filetype = TRUE;
7137 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7138 curbuf->b_fname, TRUE, curbuf);
7139 }
7140#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007141#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007142 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007143 {
7144 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007145 char_u *q = curwin->w_s->b_p_spl;
7146
7147 /* Skip the first name if it is "cjk". */
7148 if (STRNCMP(q, "cjk,", 4) == 0)
7149 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007150
7151 /*
7152 * Source the spell/LANG.vim in 'runtimepath'.
7153 * They could set 'spellcapcheck' depending on the language.
7154 * Use the first name in 'spelllang' up to '_region' or
7155 * '.encoding'.
7156 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007157 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007158 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7159 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007160 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007161 source_runtime(fname, TRUE);
7162 }
7163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007164 }
7165
7166#ifdef FEAT_MOUSE
7167 if (varp == &p_mouse)
7168 {
7169# ifdef FEAT_MOUSE_TTY
7170 if (*p_mouse == NUL)
7171 mch_setmouse(FALSE); /* switch mouse off */
7172 else
7173# endif
7174 setmouse(); /* in case 'mouse' changed */
7175 }
7176#endif
7177
Bram Moolenaar913077c2012-03-28 19:59:04 +02007178 if (curwin->w_curswant != MAXCOL
7179 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7180 curwin->w_set_curswant = TRUE;
7181
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007182#ifdef FEAT_GUI
7183 /* check redraw when it's not a GUI option or the GUI is active. */
7184 if (!redraw_gui_only || gui.in_use)
7185#endif
7186 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007187
7188 return errmsg;
7189}
7190
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007191#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007192/*
7193 * Simple int comparison function for use with qsort()
7194 */
7195 static int
7196int_cmp(a, b)
7197 const void *a;
7198 const void *b;
7199{
7200 return *(const int *)a - *(const int *)b;
7201}
7202
7203/*
7204 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7205 * Returns error message, NULL if it's OK.
7206 */
7207 char_u *
7208check_colorcolumn(wp)
7209 win_T *wp;
7210{
7211 char_u *s;
7212 int col;
7213 int count = 0;
7214 int color_cols[256];
7215 int i;
7216 int j = 0;
7217
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007218 if (wp->w_buffer == NULL)
7219 return NULL; /* buffer was closed */
7220
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007221 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007222 {
7223 if (*s == '-' || *s == '+')
7224 {
7225 /* -N and +N: add to 'textwidth' */
7226 col = (*s == '-') ? -1 : 1;
7227 ++s;
7228 if (!VIM_ISDIGIT(*s))
7229 return e_invarg;
7230 col = col * getdigits(&s);
7231 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007232 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007233 col += wp->w_buffer->b_p_tw;
7234 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007235 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007236 }
7237 else if (VIM_ISDIGIT(*s))
7238 col = getdigits(&s);
7239 else
7240 return e_invarg;
7241 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007242skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007243 if (*s == NUL)
7244 break;
7245 if (*s != ',')
7246 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007247 if (*++s == NUL)
7248 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007249 }
7250
7251 vim_free(wp->w_p_cc_cols);
7252 if (count == 0)
7253 wp->w_p_cc_cols = NULL;
7254 else
7255 {
7256 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7257 if (wp->w_p_cc_cols != NULL)
7258 {
7259 /* sort the columns for faster usage on screen redraw inside
7260 * win_line() */
7261 qsort(color_cols, count, sizeof(int), int_cmp);
7262
7263 for (i = 0; i < count; ++i)
7264 /* skip duplicates */
7265 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7266 wp->w_p_cc_cols[j++] = color_cols[i];
7267 wp->w_p_cc_cols[j] = -1; /* end marker */
7268 }
7269 }
7270
7271 return NULL; /* no error */
7272}
7273#endif
7274
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275/*
7276 * Handle setting 'listchars' or 'fillchars'.
7277 * Returns error message, NULL if it's OK.
7278 */
7279 static char_u *
7280set_chars_option(varp)
7281 char_u **varp;
7282{
7283 int round, i, len, entries;
7284 char_u *p, *s;
7285 int c1, c2 = 0;
7286 struct charstab
7287 {
7288 int *cp;
7289 char *name;
7290 };
7291#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7292 static struct charstab filltab[] =
7293 {
7294 {&fill_stl, "stl"},
7295 {&fill_stlnc, "stlnc"},
7296 {&fill_vert, "vert"},
7297 {&fill_fold, "fold"},
7298 {&fill_diff, "diff"},
7299 };
7300#endif
7301 static struct charstab lcstab[] =
7302 {
7303 {&lcs_eol, "eol"},
7304 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007305 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007306 {&lcs_prec, "precedes"},
7307 {&lcs_tab2, "tab"},
7308 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007309#ifdef FEAT_CONCEAL
7310 {&lcs_conceal, "conceal"},
7311#else
7312 {NULL, "conceal"},
7313#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007314 };
7315 struct charstab *tab;
7316
7317#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7318 if (varp == &p_lcs)
7319#endif
7320 {
7321 tab = lcstab;
7322 entries = sizeof(lcstab) / sizeof(struct charstab);
7323 }
7324#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7325 else
7326 {
7327 tab = filltab;
7328 entries = sizeof(filltab) / sizeof(struct charstab);
7329 }
7330#endif
7331
7332 /* first round: check for valid value, second round: assign values */
7333 for (round = 0; round <= 1; ++round)
7334 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007335 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336 {
7337 /* After checking that the value is valid: set defaults: space for
7338 * 'fillchars', NUL for 'listchars' */
7339 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007340 if (tab[i].cp != NULL)
7341 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007342 if (varp == &p_lcs)
7343 lcs_tab1 = NUL;
7344#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7345 else
7346 fill_diff = '-';
7347#endif
7348 }
7349 p = *varp;
7350 while (*p)
7351 {
7352 for (i = 0; i < entries; ++i)
7353 {
7354 len = (int)STRLEN(tab[i].name);
7355 if (STRNCMP(p, tab[i].name, len) == 0
7356 && p[len] == ':'
7357 && p[len + 1] != NUL)
7358 {
7359 s = p + len + 1;
7360#ifdef FEAT_MBYTE
7361 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007362 if (mb_char2cells(c1) > 1)
7363 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007364#else
7365 c1 = *s++;
7366#endif
7367 if (tab[i].cp == &lcs_tab2)
7368 {
7369 if (*s == NUL)
7370 continue;
7371#ifdef FEAT_MBYTE
7372 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007373 if (mb_char2cells(c2) > 1)
7374 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007375#else
7376 c2 = *s++;
7377#endif
7378 }
7379 if (*s == ',' || *s == NUL)
7380 {
7381 if (round)
7382 {
7383 if (tab[i].cp == &lcs_tab2)
7384 {
7385 lcs_tab1 = c1;
7386 lcs_tab2 = c2;
7387 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007388 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007389 *(tab[i].cp) = c1;
7390
7391 }
7392 p = s;
7393 break;
7394 }
7395 }
7396 }
7397
7398 if (i == entries)
7399 return e_invarg;
7400 if (*p == ',')
7401 ++p;
7402 }
7403 }
7404
7405 return NULL; /* no error */
7406}
7407
7408#ifdef FEAT_STL_OPT
7409/*
7410 * Check validity of options with the 'statusline' format.
7411 * Return error message or NULL.
7412 */
7413 char_u *
7414check_stl_option(s)
7415 char_u *s;
7416{
7417 int itemcnt = 0;
7418 int groupdepth = 0;
7419 static char_u errbuf[80];
7420
7421 while (*s && itemcnt < STL_MAX_ITEM)
7422 {
7423 /* Check for valid keys after % sequences */
7424 while (*s && *s != '%')
7425 s++;
7426 if (!*s)
7427 break;
7428 s++;
7429 if (*s != '%' && *s != ')')
7430 ++itemcnt;
7431 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7432 {
7433 s++;
7434 continue;
7435 }
7436 if (*s == ')')
7437 {
7438 s++;
7439 if (--groupdepth < 0)
7440 break;
7441 continue;
7442 }
7443 if (*s == '-')
7444 s++;
7445 while (VIM_ISDIGIT(*s))
7446 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007447 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007448 continue;
7449 if (*s == '.')
7450 {
7451 s++;
7452 while (*s && VIM_ISDIGIT(*s))
7453 s++;
7454 }
7455 if (*s == '(')
7456 {
7457 groupdepth++;
7458 continue;
7459 }
7460 if (vim_strchr(STL_ALL, *s) == NULL)
7461 {
7462 return illegal_char(errbuf, *s);
7463 }
7464 if (*s == '{')
7465 {
7466 s++;
7467 while (*s != '}' && *s)
7468 s++;
7469 if (*s != '}')
7470 return (char_u *)N_("E540: Unclosed expression sequence");
7471 }
7472 }
7473 if (itemcnt >= STL_MAX_ITEM)
7474 return (char_u *)N_("E541: too many items");
7475 if (groupdepth != 0)
7476 return (char_u *)N_("E542: unbalanced groups");
7477 return NULL;
7478}
7479#endif
7480
7481#ifdef FEAT_CLIPBOARD
7482/*
7483 * Extract the items in the 'clipboard' option and set global values.
7484 */
7485 static char_u *
7486check_clipboard_option()
7487{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007488 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007489 int new_autoselect_star = FALSE;
7490 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007492 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007493 regprog_T *new_exclude_prog = NULL;
7494 char_u *errmsg = NULL;
7495 char_u *p;
7496
7497 for (p = p_cb; *p != NUL; )
7498 {
7499 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7500 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007501 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007502 p += 7;
7503 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007504 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007505 && (p[11] == ',' || p[11] == NUL))
7506 {
7507 new_unnamed |= CLIP_UNNAMED_PLUS;
7508 p += 11;
7509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007511 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007512 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007513 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514 p += 10;
7515 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007516 else if (STRNCMP(p, "autoselectplus", 14) == 0
7517 && (p[14] == ',' || p[14] == NUL))
7518 {
7519 new_autoselect_plus = TRUE;
7520 p += 14;
7521 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007522 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007523 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007524 {
7525 new_autoselectml = TRUE;
7526 p += 12;
7527 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007528 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7529 {
7530 new_html = TRUE;
7531 p += 4;
7532 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007533 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7534 {
7535 p += 8;
7536 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7537 if (new_exclude_prog == NULL)
7538 errmsg = e_invarg;
7539 break;
7540 }
7541 else
7542 {
7543 errmsg = e_invarg;
7544 break;
7545 }
7546 if (*p == ',')
7547 ++p;
7548 }
7549 if (errmsg == NULL)
7550 {
7551 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007552 clip_autoselect_star = new_autoselect_star;
7553 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007554 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007555 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007556 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007557 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007558#ifdef FEAT_GUI_GTK
7559 if (gui.in_use)
7560 {
7561 gui_gtk_set_selection_targets();
7562 gui_gtk_set_dnd_targets();
7563 }
7564#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007565 }
7566 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007567 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007568
7569 return errmsg;
7570}
7571#endif
7572
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007573#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007574/*
7575 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7576 * Return error message when failed, NULL when OK.
7577 */
7578 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007579compile_cap_prog(synblock)
7580 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007581{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007582 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007583 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007584
Bram Moolenaar860cae12010-06-05 23:22:07 +02007585 if (*synblock->b_p_spc == NUL)
7586 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007587 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007588 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007589 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007590 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007591 if (re != NULL)
7592 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007593 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007594 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007595 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007596 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007597 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007598 return e_invarg;
7599 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007600 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007601 }
7602
Bram Moolenaar473de612013-06-08 18:19:48 +02007603 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007604 return NULL;
7605}
7606#endif
7607
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007608#if defined(FEAT_EVAL) || defined(PROTO)
7609/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007610 * Set the scriptID for an option, taking care of setting the buffer- or
7611 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007612 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007613 static void
7614set_option_scriptID_idx(opt_idx, opt_flags, id)
7615 int opt_idx;
7616 int opt_flags;
7617 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007618{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007619 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7620 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007621
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007622 /* Remember where the option was set. For local options need to do that
7623 * in the buffer or window structure. */
7624 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007625 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007626 if (both || (opt_flags & OPT_LOCAL))
7627 {
7628 if (indir & PV_BUF)
7629 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7630 else if (indir & PV_WIN)
7631 curwin->w_p_scriptID[indir & PV_MASK] = id;
7632 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007633}
7634#endif
7635
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636/*
7637 * Set the value of a boolean option, and take care of side effects.
7638 * Returns NULL for success, or an error message for an error.
7639 */
7640 static char_u *
7641set_bool_option(opt_idx, varp, value, opt_flags)
7642 int opt_idx; /* index in options[] table */
7643 char_u *varp; /* pointer to the option variable */
7644 int value; /* new value */
7645 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7646{
7647 int old_value = *(int *)varp;
7648
Bram Moolenaar071d4272004-06-13 20:20:40 +00007649 /* Disallow changing some options from secure mode */
7650 if ((secure
7651#ifdef HAVE_SANDBOX
7652 || sandbox != 0
7653#endif
7654 ) && (options[opt_idx].flags & P_SECURE))
7655 return e_secure;
7656
7657 *(int *)varp = value; /* set the new value */
7658#ifdef FEAT_EVAL
7659 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007660 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661#endif
7662
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007663#ifdef FEAT_GUI
7664 need_mouse_correct = TRUE;
7665#endif
7666
Bram Moolenaar071d4272004-06-13 20:20:40 +00007667 /* May set global value for local option. */
7668 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7669 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7670
7671 /*
7672 * Handle side effects of changing a bool option.
7673 */
7674
7675 /* 'compatible' */
7676 if ((int *)varp == &p_cp)
7677 {
7678 compatible_set();
7679 }
7680
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007681#ifdef FEAT_PERSISTENT_UNDO
7682 /* 'undofile' */
7683 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7684 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007685 /* Only take action when the option was set. When reset we do not
7686 * delete the undo file, the option may be set again without making
7687 * any changes in between. */
7688 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007689 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007690 char_u hash[UNDO_HASH_SIZE];
7691 buf_T *save_curbuf = curbuf;
7692
7693 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007694 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007695 /* When 'undofile' is set globally: for every buffer, otherwise
7696 * only for the current buffer: Try to read in the undofile,
7697 * if one exists, the buffer wasn't changed and the buffer was
7698 * loaded */
7699 if ((curbuf == save_curbuf
7700 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7701 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7702 {
7703 u_compute_hash(hash);
7704 u_read_undo(NULL, hash, curbuf->b_fname);
7705 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007706 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007707 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007708 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007709 }
7710#endif
7711
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712 else if ((int *)varp == &curbuf->b_p_ro)
7713 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007714 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007715 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7716 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007717
7718 /* when 'readonly' is set may give W10 again */
7719 if (curbuf->b_p_ro)
7720 curbuf->b_did_warn = FALSE;
7721
Bram Moolenaar071d4272004-06-13 20:20:40 +00007722#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007723 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007724#endif
7725 }
7726
Bram Moolenaar9c449722010-07-20 18:44:27 +02007727#ifdef FEAT_GUI
7728 else if ((int *)varp == &p_mh)
7729 {
7730 if (!p_mh)
7731 gui_mch_mousehide(FALSE);
7732 }
7733#endif
7734
Bram Moolenaara539df02010-08-01 14:35:05 +02007735#ifdef FEAT_TITLE
7736 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007737 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007738 {
7739 redraw_titles();
7740 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007741 /* when 'endofline' is changed, redraw the window title */
7742 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007743 {
7744 redraw_titles();
7745 }
7746# ifdef FEAT_MBYTE
7747 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007748 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007749 {
7750 redraw_titles();
7751 }
7752# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007753#endif
7754
7755 /* when 'bin' is set also set some other options */
7756 else if ((int *)varp == &curbuf->b_p_bin)
7757 {
7758 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7759#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007760 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761#endif
7762 }
7763
7764#ifdef FEAT_AUTOCMD
7765 /* when 'buflisted' changes, trigger autocommands */
7766 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7767 {
7768 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7769 NULL, NULL, TRUE, curbuf);
7770 }
7771#endif
7772
7773 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7774 else if ((int *)varp == &curbuf->b_p_swf)
7775 {
7776 if (curbuf->b_p_swf && p_uc)
7777 ml_open_file(curbuf); /* create the swap file */
7778 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007779 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7780 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781 mf_close_file(curbuf, TRUE); /* remove the swap file */
7782 }
7783
7784 /* when 'terse' is set change 'shortmess' */
7785 else if ((int *)varp == &p_terse)
7786 {
7787 char_u *p;
7788
7789 p = vim_strchr(p_shm, SHM_SEARCH);
7790
7791 /* insert 's' in p_shm */
7792 if (p_terse && p == NULL)
7793 {
7794 STRCPY(IObuff, p_shm);
7795 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007796 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007797 }
7798 /* remove 's' from p_shm */
7799 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007800 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801 }
7802
7803 /* when 'paste' is set or reset also change other options */
7804 else if ((int *)varp == &p_paste)
7805 {
7806 paste_option_changed();
7807 }
7808
7809 /* when 'insertmode' is set from an autocommand need to do work here */
7810 else if ((int *)varp == &p_im)
7811 {
7812 if (p_im)
7813 {
7814 if ((State & INSERT) == 0)
7815 need_start_insertmode = TRUE;
7816 stop_insert_mode = FALSE;
7817 }
7818 else
7819 {
7820 need_start_insertmode = FALSE;
7821 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007822 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007823 clear_cmdline = TRUE; /* remove "(insert)" */
7824 restart_edit = 0;
7825 }
7826 }
7827
7828 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7829 else if ((int *)varp == &p_ic && p_hls)
7830 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007831 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007832 }
7833
7834#ifdef FEAT_SEARCH_EXTRA
7835 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7836 else if ((int *)varp == &p_hls)
7837 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007838 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007839 }
7840#endif
7841
7842#ifdef FEAT_SCROLLBIND
7843 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7844 * at the end of normal_cmd() */
7845 else if ((int *)varp == &curwin->w_p_scb)
7846 {
7847 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007848 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007850 curwin->w_scbind_pos = curwin->w_topline;
7851 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007852 }
7853#endif
7854
7855#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7856 /* There can be only one window with 'previewwindow' set. */
7857 else if ((int *)varp == &curwin->w_p_pvw)
7858 {
7859 if (curwin->w_p_pvw)
7860 {
7861 win_T *win;
7862
7863 for (win = firstwin; win != NULL; win = win->w_next)
7864 if (win->w_p_pvw && win != curwin)
7865 {
7866 curwin->w_p_pvw = FALSE;
7867 return (char_u *)N_("E590: A preview window already exists");
7868 }
7869 }
7870 }
7871#endif
7872
7873 /* when 'textmode' is set or reset also change 'fileformat' */
7874 else if ((int *)varp == &curbuf->b_p_tx)
7875 {
7876 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7877 }
7878
7879 /* when 'textauto' is set or reset also change 'fileformats' */
7880 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007881 set_string_option_direct((char_u *)"ffs", -1,
7882 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007883 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007884
7885 /*
7886 * When 'lisp' option changes include/exclude '-' in
7887 * keyword characters.
7888 */
7889#ifdef FEAT_LISP
7890 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7891 {
7892 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7893 }
7894#endif
7895
7896#ifdef FEAT_TITLE
7897 /* when 'title' changed, may need to change the title; same for 'icon' */
7898 else if ((int *)varp == &p_title)
7899 {
7900 did_set_title(FALSE);
7901 }
7902
7903 else if ((int *)varp == &p_icon)
7904 {
7905 did_set_title(TRUE);
7906 }
7907#endif
7908
7909 else if ((int *)varp == &curbuf->b_changed)
7910 {
7911 if (!value)
7912 save_file_ff(curbuf); /* Buffer is unchanged */
7913#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007914 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915#endif
7916#ifdef FEAT_AUTOCMD
7917 modified_was_set = value;
7918#endif
7919 }
7920
7921#ifdef BACKSLASH_IN_FILENAME
7922 else if ((int *)varp == &p_ssl)
7923 {
7924 if (p_ssl)
7925 {
7926 psepc = '/';
7927 psepcN = '\\';
7928 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007929 }
7930 else
7931 {
7932 psepc = '\\';
7933 psepcN = '/';
7934 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935 }
7936
7937 /* need to adjust the file name arguments and buffer names. */
7938 buflist_slash_adjust();
7939 alist_slash_adjust();
7940# ifdef FEAT_EVAL
7941 scriptnames_slash_adjust();
7942# endif
7943 }
7944#endif
7945
7946 /* If 'wrap' is set, set w_leftcol to zero. */
7947 else if ((int *)varp == &curwin->w_p_wrap)
7948 {
7949 if (curwin->w_p_wrap)
7950 curwin->w_leftcol = 0;
7951 }
7952
7953#ifdef FEAT_WINDOWS
7954 else if ((int *)varp == &p_ea)
7955 {
7956 if (p_ea && !old_value)
7957 win_equal(curwin, FALSE, 0);
7958 }
7959#endif
7960
7961 else if ((int *)varp == &p_wiv)
7962 {
7963 /*
7964 * When 'weirdinvert' changed, set/reset 't_xs'.
7965 * Then set 'weirdinvert' according to value of 't_xs'.
7966 */
7967 if (p_wiv && !old_value)
7968 T_XS = (char_u *)"y";
7969 else if (!p_wiv && old_value)
7970 T_XS = empty_option;
7971 p_wiv = (*T_XS != NUL);
7972 }
7973
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007974#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007975 else if ((int *)varp == &p_beval)
7976 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007977 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007979 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980 gui_mch_disable_beval_area(balloonEval);
7981 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007982#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007984#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 else if ((int *)varp == &p_acd)
7986 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007987 /* Change directories when the 'acd' option is set now. */
7988 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007989 }
7990#endif
7991
7992#ifdef FEAT_DIFF
7993 /* 'diff' */
7994 else if ((int *)varp == &curwin->w_p_diff)
7995 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007996 /* May add or remove the buffer from the list of diff buffers. */
7997 diff_buf_adjust(curwin);
7998# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 if (foldmethodIsDiff(curwin))
8000 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008001# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 }
8003#endif
8004
8005#ifdef USE_IM_CONTROL
8006 /* 'imdisable' */
8007 else if ((int *)varp == &p_imdisable)
8008 {
8009 /* Only de-activate it here, it will be enabled when changing mode. */
8010 if (p_imdisable)
8011 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008012 else if (State & INSERT)
8013 /* When the option is set from an autocommand, it may need to take
8014 * effect right away. */
8015 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 }
8017#endif
8018
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008019#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008020 /* 'spell' */
8021 else if ((int *)varp == &curwin->w_p_spell)
8022 {
8023 if (curwin->w_p_spell)
8024 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008025 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008026 if (errmsg != NULL)
8027 EMSG(_(errmsg));
8028 }
8029 }
8030#endif
8031
Bram Moolenaar071d4272004-06-13 20:20:40 +00008032#ifdef FEAT_FKMAP
8033 else if ((int *)varp == &p_altkeymap)
8034 {
8035 if (old_value != p_altkeymap)
8036 {
8037 if (!p_altkeymap)
8038 {
8039 p_hkmap = p_fkmap;
8040 p_fkmap = 0;
8041 }
8042 else
8043 {
8044 p_fkmap = p_hkmap;
8045 p_hkmap = 0;
8046 }
8047 (void)init_chartab();
8048 }
8049 }
8050
8051 /*
8052 * In case some second language keymapping options have changed, check
8053 * and correct the setting in a consistent way.
8054 */
8055
8056 /*
8057 * If hkmap or fkmap are set, reset Arabic keymapping.
8058 */
8059 if ((p_hkmap || p_fkmap) && p_altkeymap)
8060 {
8061 p_altkeymap = p_fkmap;
8062# ifdef FEAT_ARABIC
8063 curwin->w_p_arab = FALSE;
8064# endif
8065 (void)init_chartab();
8066 }
8067
8068 /*
8069 * If hkmap set, reset Farsi keymapping.
8070 */
8071 if (p_hkmap && p_altkeymap)
8072 {
8073 p_altkeymap = 0;
8074 p_fkmap = 0;
8075# ifdef FEAT_ARABIC
8076 curwin->w_p_arab = FALSE;
8077# endif
8078 (void)init_chartab();
8079 }
8080
8081 /*
8082 * If fkmap set, reset Hebrew keymapping.
8083 */
8084 if (p_fkmap && !p_altkeymap)
8085 {
8086 p_altkeymap = 1;
8087 p_hkmap = 0;
8088# ifdef FEAT_ARABIC
8089 curwin->w_p_arab = FALSE;
8090# endif
8091 (void)init_chartab();
8092 }
8093#endif
8094
8095#ifdef FEAT_ARABIC
8096 if ((int *)varp == &curwin->w_p_arab)
8097 {
8098 if (curwin->w_p_arab)
8099 {
8100 /*
8101 * 'arabic' is set, handle various sub-settings.
8102 */
8103 if (!p_tbidi)
8104 {
8105 /* set rightleft mode */
8106 if (!curwin->w_p_rl)
8107 {
8108 curwin->w_p_rl = TRUE;
8109 changed_window_setting();
8110 }
8111
8112 /* Enable Arabic shaping (major part of what Arabic requires) */
8113 if (!p_arshape)
8114 {
8115 p_arshape = TRUE;
8116 redraw_later_clear();
8117 }
8118 }
8119
8120 /* Arabic requires a utf-8 encoding, inform the user if its not
8121 * set. */
8122 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008123 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008124 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8125
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008126 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008127 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8128#ifdef FEAT_EVAL
8129 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8130#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132
8133# ifdef FEAT_MBYTE
8134 /* set 'delcombine' */
8135 p_deco = TRUE;
8136# endif
8137
8138# ifdef FEAT_KEYMAP
8139 /* Force-set the necessary keymap for arabic */
8140 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8141 OPT_LOCAL);
8142# endif
8143# ifdef FEAT_FKMAP
8144 p_altkeymap = 0;
8145 p_hkmap = 0;
8146 p_fkmap = 0;
8147 (void)init_chartab();
8148# endif
8149 }
8150 else
8151 {
8152 /*
8153 * 'arabic' is reset, handle various sub-settings.
8154 */
8155 if (!p_tbidi)
8156 {
8157 /* reset rightleft mode */
8158 if (curwin->w_p_rl)
8159 {
8160 curwin->w_p_rl = FALSE;
8161 changed_window_setting();
8162 }
8163
8164 /* 'arabicshape' isn't reset, it is a global option and
8165 * another window may still need it "on". */
8166 }
8167
8168 /* 'delcombine' isn't reset, it is a global option and another
8169 * window may still want it "on". */
8170
8171# ifdef FEAT_KEYMAP
8172 /* Revert to the default keymap */
8173 curbuf->b_p_iminsert = B_IMODE_NONE;
8174 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8175# endif
8176 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008177 }
8178
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008179#endif
8180
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181 /*
8182 * End of handling side effects for bool options.
8183 */
8184
8185 options[opt_idx].flags |= P_WAS_SET;
8186
8187 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008188 if (curwin->w_curswant != MAXCOL
8189 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8190 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008191 check_redraw(options[opt_idx].flags);
8192
8193 return NULL;
8194}
8195
8196/*
8197 * Set the value of a number option, and take care of side effects.
8198 * Returns NULL for success, or an error message for an error.
8199 */
8200 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008201set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 int opt_idx; /* index in options[] table */
8203 char_u *varp; /* pointer to the option variable */
8204 long value; /* new value */
8205 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008206 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008207 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8208 OPT_MODELINE */
8209{
8210 char_u *errmsg = NULL;
8211 long old_value = *(long *)varp;
8212 long old_Rows = Rows; /* remember old Rows */
8213 long old_Columns = Columns; /* remember old Columns */
8214 long *pp = (long *)varp;
8215
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008216 /* Disallow changing some options from secure mode. */
8217 if ((secure
8218#ifdef HAVE_SANDBOX
8219 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008221 ) && (options[opt_idx].flags & P_SECURE))
8222 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008223
8224 *pp = value;
8225#ifdef FEAT_EVAL
8226 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008227 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008228#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008229#ifdef FEAT_GUI
8230 need_mouse_correct = TRUE;
8231#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008232
Bram Moolenaar14f24742012-08-08 18:01:05 +02008233 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008234 {
8235 errmsg = e_positive;
8236 curbuf->b_p_sw = curbuf->b_p_ts;
8237 }
8238
8239 /*
8240 * Number options that need some action when changed
8241 */
8242#ifdef FEAT_WINDOWS
8243 if (pp == &p_wh || pp == &p_hh)
8244 {
8245 if (p_wh < 1)
8246 {
8247 errmsg = e_positive;
8248 p_wh = 1;
8249 }
8250 if (p_wmh > p_wh)
8251 {
8252 errmsg = e_winheight;
8253 p_wh = p_wmh;
8254 }
8255 if (p_hh < 0)
8256 {
8257 errmsg = e_positive;
8258 p_hh = 0;
8259 }
8260
8261 /* Change window height NOW */
8262 if (lastwin != firstwin)
8263 {
8264 if (pp == &p_wh && curwin->w_height < p_wh)
8265 win_setheight((int)p_wh);
8266 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8267 win_setheight((int)p_hh);
8268 }
8269 }
8270
8271 /* 'winminheight' */
8272 else if (pp == &p_wmh)
8273 {
8274 if (p_wmh < 0)
8275 {
8276 errmsg = e_positive;
8277 p_wmh = 0;
8278 }
8279 if (p_wmh > p_wh)
8280 {
8281 errmsg = e_winheight;
8282 p_wmh = p_wh;
8283 }
8284 win_setminheight();
8285 }
8286
8287# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008288 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289 {
8290 if (p_wiw < 1)
8291 {
8292 errmsg = e_positive;
8293 p_wiw = 1;
8294 }
8295 if (p_wmw > p_wiw)
8296 {
8297 errmsg = e_winwidth;
8298 p_wiw = p_wmw;
8299 }
8300
8301 /* Change window width NOW */
8302 if (lastwin != firstwin && curwin->w_width < p_wiw)
8303 win_setwidth((int)p_wiw);
8304 }
8305
8306 /* 'winminwidth' */
8307 else if (pp == &p_wmw)
8308 {
8309 if (p_wmw < 0)
8310 {
8311 errmsg = e_positive;
8312 p_wmw = 0;
8313 }
8314 if (p_wmw > p_wiw)
8315 {
8316 errmsg = e_winwidth;
8317 p_wmw = p_wiw;
8318 }
8319 win_setminheight();
8320 }
8321# endif
8322
8323#endif
8324
8325#ifdef FEAT_WINDOWS
8326 /* (re)set last window status line */
8327 else if (pp == &p_ls)
8328 {
8329 last_status(FALSE);
8330 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008331
8332 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008333 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008334 {
8335 shell_new_rows(); /* recompute window positions and heights */
8336 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008337#endif
8338
8339#ifdef FEAT_GUI
8340 else if (pp == &p_linespace)
8341 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008342 /* Recompute gui.char_height and resize the Vim window to keep the
8343 * same number of lines. */
8344 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008345 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008346 }
8347#endif
8348
8349#ifdef FEAT_FOLDING
8350 /* 'foldlevel' */
8351 else if (pp == &curwin->w_p_fdl)
8352 {
8353 if (curwin->w_p_fdl < 0)
8354 curwin->w_p_fdl = 0;
8355 newFoldLevel();
8356 }
8357
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008358 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359 else if (pp == &curwin->w_p_fml)
8360 {
8361 foldUpdateAll(curwin);
8362 }
8363
8364 /* 'foldnestmax' */
8365 else if (pp == &curwin->w_p_fdn)
8366 {
8367 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8368 foldUpdateAll(curwin);
8369 }
8370
8371 /* 'foldcolumn' */
8372 else if (pp == &curwin->w_p_fdc)
8373 {
8374 if (curwin->w_p_fdc < 0)
8375 {
8376 errmsg = e_positive;
8377 curwin->w_p_fdc = 0;
8378 }
8379 else if (curwin->w_p_fdc > 12)
8380 {
8381 errmsg = e_invarg;
8382 curwin->w_p_fdc = 12;
8383 }
8384 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008385#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008387#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008388 /* 'shiftwidth' or 'tabstop' */
8389 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8390 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008391# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008392 if (foldmethodIsIndent(curwin))
8393 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008394# endif
8395# ifdef FEAT_CINDENT
8396 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8397 * parse 'cinoptions'. */
8398 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8399 parse_cino(curbuf);
8400# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008402#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008404#ifdef FEAT_MBYTE
8405 /* 'maxcombine' */
8406 else if (pp == &p_mco)
8407 {
8408 if (p_mco > MAX_MCO)
8409 p_mco = MAX_MCO;
8410 else if (p_mco < 0)
8411 p_mco = 0;
8412 screenclear(); /* will re-allocate the screen */
8413 }
8414#endif
8415
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 else if (pp == &curbuf->b_p_iminsert)
8417 {
8418 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8419 {
8420 errmsg = e_invarg;
8421 curbuf->b_p_iminsert = B_IMODE_NONE;
8422 }
8423 p_iminsert = curbuf->b_p_iminsert;
8424 if (termcap_active) /* don't do this in the alternate screen */
8425 showmode();
8426#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8427 /* Show/unshow value of 'keymap' in status lines. */
8428 status_redraw_curbuf();
8429#endif
8430 }
8431
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008432 else if (pp == &p_window)
8433 {
8434 if (p_window < 1)
8435 p_window = 1;
8436 else if (p_window >= Rows)
8437 p_window = Rows - 1;
8438 }
8439
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 else if (pp == &curbuf->b_p_imsearch)
8441 {
8442 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8443 {
8444 errmsg = e_invarg;
8445 curbuf->b_p_imsearch = B_IMODE_NONE;
8446 }
8447 p_imsearch = curbuf->b_p_imsearch;
8448 }
8449
8450#ifdef FEAT_TITLE
8451 /* if 'titlelen' has changed, redraw the title */
8452 else if (pp == &p_titlelen)
8453 {
8454 if (p_titlelen < 0)
8455 {
8456 errmsg = e_positive;
8457 p_titlelen = 85;
8458 }
8459 if (starting != NO_SCREEN && old_value != p_titlelen)
8460 need_maketitle = TRUE;
8461 }
8462#endif
8463
8464 /* if p_ch changed value, change the command line height */
8465 else if (pp == &p_ch)
8466 {
8467 if (p_ch < 1)
8468 {
8469 errmsg = e_positive;
8470 p_ch = 1;
8471 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008472 if (p_ch > Rows - min_rows() + 1)
8473 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474
8475 /* Only compute the new window layout when startup has been
8476 * completed. Otherwise the frame sizes may be wrong. */
8477 if (p_ch != old_value && full_screen
8478#ifdef FEAT_GUI
8479 && !gui.starting
8480#endif
8481 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008482 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483 }
8484
8485 /* when 'updatecount' changes from zero to non-zero, open swap files */
8486 else if (pp == &p_uc)
8487 {
8488 if (p_uc < 0)
8489 {
8490 errmsg = e_positive;
8491 p_uc = 100;
8492 }
8493 if (p_uc && !old_value)
8494 ml_open_files();
8495 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008496#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008497 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008498 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008499 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008500 {
8501 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008502 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008503 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008504 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008505 {
8506 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008507 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008508 }
8509 }
8510#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008511#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008512 else if (pp == &p_mzq)
8513 mzvim_reset_timer();
8514#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008515
8516 /* sync undo before 'undolevels' changes */
8517 else if (pp == &p_ul)
8518 {
8519 /* use the old value, otherwise u_sync() may not work properly */
8520 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008521 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008522 p_ul = value;
8523 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008524 else if (pp == &curbuf->b_p_ul)
8525 {
8526 /* use the old value, otherwise u_sync() may not work properly */
8527 curbuf->b_p_ul = old_value;
8528 u_sync(TRUE);
8529 curbuf->b_p_ul = value;
8530 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008531
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008532#ifdef FEAT_LINEBREAK
8533 /* 'numberwidth' must be positive */
8534 else if (pp == &curwin->w_p_nuw)
8535 {
8536 if (curwin->w_p_nuw < 1)
8537 {
8538 errmsg = e_positive;
8539 curwin->w_p_nuw = 1;
8540 }
8541 if (curwin->w_p_nuw > 10)
8542 {
8543 errmsg = e_invarg;
8544 curwin->w_p_nuw = 10;
8545 }
8546 curwin->w_nrwidth_line_count = 0;
8547 }
8548#endif
8549
Bram Moolenaar1a384422010-07-14 19:53:30 +02008550 else if (pp == &curbuf->b_p_tw)
8551 {
8552 if (curbuf->b_p_tw < 0)
8553 {
8554 errmsg = e_positive;
8555 curbuf->b_p_tw = 0;
8556 }
8557#ifdef FEAT_SYN_HL
8558# ifdef FEAT_WINDOWS
8559 {
8560 win_T *wp;
8561 tabpage_T *tp;
8562
8563 FOR_ALL_TAB_WINDOWS(tp, wp)
8564 check_colorcolumn(wp);
8565 }
8566# else
8567 check_colorcolumn(curwin);
8568# endif
8569#endif
8570 }
8571
Bram Moolenaar071d4272004-06-13 20:20:40 +00008572 /*
8573 * Check the bounds for numeric options here
8574 */
8575 if (Rows < min_rows() && full_screen)
8576 {
8577 if (errbuf != NULL)
8578 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008579 vim_snprintf((char *)errbuf, errbuflen,
8580 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008581 errmsg = errbuf;
8582 }
8583 Rows = min_rows();
8584 }
8585 if (Columns < MIN_COLUMNS && full_screen)
8586 {
8587 if (errbuf != NULL)
8588 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008589 vim_snprintf((char *)errbuf, errbuflen,
8590 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 errmsg = errbuf;
8592 }
8593 Columns = MIN_COLUMNS;
8594 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008595 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008596
8597#ifdef DJGPP
8598 /* avoid a crash by checking for a too large value of 'columns' */
8599 if (old_Columns != Columns && full_screen && term_console)
8600 mch_check_columns();
8601#endif
8602
8603 /*
8604 * If the screen (shell) height has been changed, assume it is the
8605 * physical screenheight.
8606 */
8607 if (old_Rows != Rows || old_Columns != Columns)
8608 {
8609 /* Changing the screen size is not allowed while updating the screen. */
8610 if (updating_screen)
8611 *pp = old_value;
8612 else if (full_screen
8613#ifdef FEAT_GUI
8614 && !gui.starting
8615#endif
8616 )
8617 set_shellsize((int)Columns, (int)Rows, TRUE);
8618 else
8619 {
8620 /* Postpone the resizing; check the size and cmdline position for
8621 * messages. */
8622 check_shellsize();
8623 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8624 cmdline_row = Rows - p_ch;
8625 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008626 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008627 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 }
8629
Bram Moolenaar071d4272004-06-13 20:20:40 +00008630 if (curbuf->b_p_ts <= 0)
8631 {
8632 errmsg = e_positive;
8633 curbuf->b_p_ts = 8;
8634 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635 if (p_tm < 0)
8636 {
8637 errmsg = e_positive;
8638 p_tm = 0;
8639 }
8640 if ((curwin->w_p_scr <= 0
8641 || (curwin->w_p_scr > curwin->w_height
8642 && curwin->w_height > 0))
8643 && full_screen)
8644 {
8645 if (pp == &(curwin->w_p_scr))
8646 {
8647 if (curwin->w_p_scr != 0)
8648 errmsg = e_scroll;
8649 win_comp_scroll(curwin);
8650 }
8651 /* If 'scroll' became invalid because of a side effect silently adjust
8652 * it. */
8653 else if (curwin->w_p_scr <= 0)
8654 curwin->w_p_scr = 1;
8655 else /* curwin->w_p_scr > curwin->w_height */
8656 curwin->w_p_scr = curwin->w_height;
8657 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008658 if (p_hi < 0)
8659 {
8660 errmsg = e_positive;
8661 p_hi = 0;
8662 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008663 else if (p_hi > 10000)
8664 {
8665 errmsg = e_invarg;
8666 p_hi = 10000;
8667 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008668 if (p_re < 0 || p_re > 2)
8669 {
8670 errmsg = e_invarg;
8671 p_re = 0;
8672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673 if (p_report < 0)
8674 {
8675 errmsg = e_positive;
8676 p_report = 1;
8677 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008678 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008679 {
8680 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8681 p_sj = Rows / 2;
8682 else
8683 {
8684 errmsg = e_scroll;
8685 p_sj = 1;
8686 }
8687 }
8688 if (p_so < 0 && full_screen)
8689 {
8690 errmsg = e_scroll;
8691 p_so = 0;
8692 }
8693 if (p_siso < 0 && full_screen)
8694 {
8695 errmsg = e_positive;
8696 p_siso = 0;
8697 }
8698#ifdef FEAT_CMDWIN
8699 if (p_cwh < 1)
8700 {
8701 errmsg = e_positive;
8702 p_cwh = 1;
8703 }
8704#endif
8705 if (p_ut < 0)
8706 {
8707 errmsg = e_positive;
8708 p_ut = 2000;
8709 }
8710 if (p_ss < 0)
8711 {
8712 errmsg = e_positive;
8713 p_ss = 0;
8714 }
8715
8716 /* May set global value for local option. */
8717 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8718 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8719
8720 options[opt_idx].flags |= P_WAS_SET;
8721
8722 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008723 if (curwin->w_curswant != MAXCOL
8724 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8725 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726 check_redraw(options[opt_idx].flags);
8727
8728 return errmsg;
8729}
8730
8731/*
8732 * Called after an option changed: check if something needs to be redrawn.
8733 */
8734 static void
8735check_redraw(flags)
8736 long_u flags;
8737{
8738 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008739 int doclear = (flags & P_RCLR) == P_RCLR;
8740 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008741
8742#ifdef FEAT_WINDOWS
8743 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8744 status_redraw_all();
8745#endif
8746
8747 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8748 changed_window_setting();
8749 if (flags & P_RBUF)
8750 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008751 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752 redraw_all_later(CLEAR);
8753 else if (all)
8754 redraw_all_later(NOT_VALID);
8755}
8756
8757/*
8758 * Find index for option 'arg'.
8759 * Return -1 if not found.
8760 */
8761 static int
8762findoption(arg)
8763 char_u *arg;
8764{
8765 int opt_idx;
8766 char *s, *p;
8767 static short quick_tab[27] = {0, 0}; /* quick access table */
8768 int is_term_opt;
8769
8770 /*
8771 * For first call: Initialize the quick-access table.
8772 * It contains the index for the first option that starts with a certain
8773 * letter. There are 26 letters, plus the first "t_" option.
8774 */
8775 if (quick_tab[1] == 0)
8776 {
8777 p = options[0].fullname;
8778 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8779 {
8780 if (s[0] != p[0])
8781 {
8782 if (s[0] == 't' && s[1] == '_')
8783 quick_tab[26] = opt_idx;
8784 else
8785 quick_tab[CharOrdLow(s[0])] = opt_idx;
8786 }
8787 p = s;
8788 }
8789 }
8790
8791 /*
8792 * Check for name starting with an illegal character.
8793 */
8794#ifdef EBCDIC
8795 if (!islower(arg[0]))
8796#else
8797 if (arg[0] < 'a' || arg[0] > 'z')
8798#endif
8799 return -1;
8800
8801 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8802 if (is_term_opt)
8803 opt_idx = quick_tab[26];
8804 else
8805 opt_idx = quick_tab[CharOrdLow(arg[0])];
8806 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8807 {
8808 if (STRCMP(arg, s) == 0) /* match full name */
8809 break;
8810 }
8811 if (s == NULL && !is_term_opt)
8812 {
8813 opt_idx = quick_tab[CharOrdLow(arg[0])];
8814 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8815 {
8816 s = options[opt_idx].shortname;
8817 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8818 break;
8819 s = NULL;
8820 }
8821 }
8822 if (s == NULL)
8823 opt_idx = -1;
8824 return opt_idx;
8825}
8826
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008827#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828/*
8829 * Get the value for an option.
8830 *
8831 * Returns:
8832 * Number or Toggle option: 1, *numval gets value.
8833 * String option: 0, *stringval gets allocated string.
8834 * Hidden Number or Toggle option: -1.
8835 * hidden String option: -2.
8836 * unknown option: -3.
8837 */
8838 int
8839get_option_value(name, numval, stringval, opt_flags)
8840 char_u *name;
8841 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008842 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008843 int opt_flags;
8844{
8845 int opt_idx;
8846 char_u *varp;
8847
8848 opt_idx = findoption(name);
8849 if (opt_idx < 0) /* unknown option */
8850 return -3;
8851
8852 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8853
8854 if (options[opt_idx].flags & P_STRING)
8855 {
8856 if (varp == NULL) /* hidden option */
8857 return -2;
8858 if (stringval != NULL)
8859 {
8860#ifdef FEAT_CRYPT
8861 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008862 if ((char_u **)varp == &curbuf->b_p_key
8863 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008864 *stringval = vim_strsave((char_u *)"*****");
8865 else
8866#endif
8867 *stringval = vim_strsave(*(char_u **)(varp));
8868 }
8869 return 0;
8870 }
8871
8872 if (varp == NULL) /* hidden option */
8873 return -1;
8874 if (options[opt_idx].flags & P_NUM)
8875 *numval = *(long *)varp;
8876 else
8877 {
8878 /* Special case: 'modified' is b_changed, but we also want to consider
8879 * it set when 'ff' or 'fenc' changed. */
8880 if ((int *)varp == &curbuf->b_changed)
8881 *numval = curbufIsChanged();
8882 else
8883 *numval = *(int *)varp;
8884 }
8885 return 1;
8886}
8887#endif
8888
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008889#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008890/*
8891 * Returns the option attributes and its value. Unlike the above function it
8892 * will return either global value or local value of the option depending on
8893 * what was requested, but it will never return global value if it was
8894 * requested to return local one and vice versa. Neither it will return
8895 * buffer-local value if it was requested to return window-local one.
8896 *
8897 * Pretends that option is absent if it is not present in the requested scope
8898 * (i.e. has no global, window-local or buffer-local value depending on
8899 * opt_type). Uses
8900 *
8901 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008902 * 0 hidden or unknown option, also option that does not have requested
8903 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008904 * see SOPT_* in vim.h for other flags
8905 *
8906 * Possible opt_type values: see SREQ_* in vim.h
8907 */
8908 int
8909get_option_value_strict(name, numval, stringval, opt_type, from)
8910 char_u *name;
8911 long *numval;
8912 char_u **stringval; /* NULL when only obtaining attributes */
8913 int opt_type;
8914 void *from;
8915{
8916 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008917 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008918 struct vimoption *p;
8919 int r = 0;
8920
8921 opt_idx = findoption(name);
8922 if (opt_idx < 0)
8923 return 0;
8924
8925 p = &(options[opt_idx]);
8926
8927 /* Hidden option */
8928 if (p->var == NULL)
8929 return 0;
8930
8931 if (p->flags & P_BOOL)
8932 r |= SOPT_BOOL;
8933 else if (p->flags & P_NUM)
8934 r |= SOPT_NUM;
8935 else if (p->flags & P_STRING)
8936 r |= SOPT_STRING;
8937
8938 if (p->indir == PV_NONE)
8939 {
8940 if (opt_type == SREQ_GLOBAL)
8941 r |= SOPT_GLOBAL;
8942 else
8943 return 0; /* Did not request global-only option */
8944 }
8945 else
8946 {
8947 if (p->indir & PV_BOTH)
8948 r |= SOPT_GLOBAL;
8949 else if (opt_type == SREQ_GLOBAL)
8950 return 0; /* Requested global option */
8951
8952 if (p->indir & PV_WIN)
8953 {
8954 if (opt_type == SREQ_BUF)
8955 return 0; /* Did not request window-local option */
8956 else
8957 r |= SOPT_WIN;
8958 }
8959 else if (p->indir & PV_BUF)
8960 {
8961 if (opt_type == SREQ_WIN)
8962 return 0; /* Did not request buffer-local option */
8963 else
8964 r |= SOPT_BUF;
8965 }
8966 }
8967
8968 if (stringval == NULL)
8969 return r;
8970
8971 if (opt_type == SREQ_GLOBAL)
8972 varp = p->var;
8973 else
8974 {
8975 if (opt_type == SREQ_BUF)
8976 {
8977 /* Special case: 'modified' is b_changed, but we also want to
8978 * consider it set when 'ff' or 'fenc' changed. */
8979 if (p->indir == PV_MOD)
8980 {
8981 *numval = bufIsChanged((buf_T *) from);
8982 varp = NULL;
8983 }
8984#ifdef FEAT_CRYPT
8985 else if (p->indir == PV_KEY)
8986 {
8987 /* never return the value of the crypt key */
8988 *stringval = NULL;
8989 varp = NULL;
8990 }
8991#endif
8992 else
8993 {
8994 aco_save_T aco;
8995 aucmd_prepbuf(&aco, (buf_T *) from);
8996 varp = get_varp(p);
8997 aucmd_restbuf(&aco);
8998 }
8999 }
9000 else if (opt_type == SREQ_WIN)
9001 {
9002 win_T *save_curwin;
9003 save_curwin = curwin;
9004 curwin = (win_T *) from;
9005 curbuf = curwin->w_buffer;
9006 varp = get_varp(p);
9007 curwin = save_curwin;
9008 curbuf = curwin->w_buffer;
9009 }
9010 if (varp == p->var)
9011 return (r | SOPT_UNSET);
9012 }
9013
9014 if (varp != NULL)
9015 {
9016 if (p->flags & P_STRING)
9017 *stringval = vim_strsave(*(char_u **)(varp));
9018 else if (p->flags & P_NUM)
9019 *numval = *(long *) varp;
9020 else
9021 *numval = *(int *)varp;
9022 }
9023
9024 return r;
9025}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009026
9027/*
9028 * Iterate over options. First argument is a pointer to a pointer to a structure
9029 * inside options[] array, second is option type like in the above function.
9030 *
9031 * If first argument points to NULL it is assumed that iteration just started
9032 * and caller needs the very first value.
9033 * If first argument points to the end marker function returns NULL and sets
9034 * first argument to NULL.
9035 *
9036 * Returns full option name for current option on each call.
9037 */
9038 char_u *
9039option_iter_next(option, opt_type)
9040 void **option;
9041 int opt_type;
9042{
9043 struct vimoption *ret = NULL;
9044 do
9045 {
9046 if (*option == NULL)
9047 *option = (void *) options;
9048 else if (((struct vimoption *) (*option))->fullname == NULL)
9049 {
9050 *option = NULL;
9051 return NULL;
9052 }
9053 else
9054 *option = (void *) (((struct vimoption *) (*option)) + 1);
9055
9056 ret = ((struct vimoption *) (*option));
9057
9058 /* Hidden option */
9059 if (ret->var == NULL)
9060 {
9061 ret = NULL;
9062 continue;
9063 }
9064
9065 switch (opt_type)
9066 {
9067 case SREQ_GLOBAL:
9068 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9069 ret = NULL;
9070 break;
9071 case SREQ_BUF:
9072 if (!(ret->indir & PV_BUF))
9073 ret = NULL;
9074 break;
9075 case SREQ_WIN:
9076 if (!(ret->indir & PV_WIN))
9077 ret = NULL;
9078 break;
9079 default:
9080 EMSG2(_(e_intern2), "option_iter_next()");
9081 return NULL;
9082 }
9083 }
9084 while (ret == NULL);
9085
9086 return (char_u *)ret->fullname;
9087}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009088#endif
9089
Bram Moolenaar071d4272004-06-13 20:20:40 +00009090/*
9091 * Set the value of option "name".
9092 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009093 *
9094 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009095 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009096 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009097set_option_value(name, number, string, opt_flags)
9098 char_u *name;
9099 long number;
9100 char_u *string;
9101 int opt_flags; /* OPT_LOCAL or 0 (both) */
9102{
9103 int opt_idx;
9104 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009105 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009106
9107 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009108 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009109 EMSG2(_("E355: Unknown option: %s"), name);
9110 else
9111 {
9112 flags = options[opt_idx].flags;
9113#ifdef HAVE_SANDBOX
9114 /* Disallow changing some options in the sandbox */
9115 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009116 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009118 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009119 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009120#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009121 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009122 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009123 else
9124 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009125 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009126 if (varp != NULL) /* hidden option is not changed */
9127 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009128 if (number == 0 && string != NULL)
9129 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009130 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009131
9132 /* Either we are given a string or we are setting option
9133 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009134 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009135 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009136 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009137 {
9138 /* There's another character after zeros or the string
9139 * is empty. In both cases, we are trying to set a
9140 * num option using a string. */
9141 EMSG3(_("E521: Number required: &%s = '%s'"),
9142 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009143 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009144
9145 }
9146 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009147 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009148 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009149 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009150 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009151 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009152 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009153 }
9154 }
9155 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009156 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009157}
9158
9159/*
9160 * Get the terminal code for a terminal option.
9161 * Returns NULL when not found.
9162 */
9163 char_u *
9164get_term_code(tname)
9165 char_u *tname;
9166{
9167 int opt_idx;
9168 char_u *varp;
9169
9170 if (tname[0] != 't' || tname[1] != '_' ||
9171 tname[2] == NUL || tname[3] == NUL)
9172 return NULL;
9173 if ((opt_idx = findoption(tname)) >= 0)
9174 {
9175 varp = get_varp(&(options[opt_idx]));
9176 if (varp != NULL)
9177 varp = *(char_u **)(varp);
9178 return varp;
9179 }
9180 return find_termcode(tname + 2);
9181}
9182
9183 char_u *
9184get_highlight_default()
9185{
9186 int i;
9187
9188 i = findoption((char_u *)"hl");
9189 if (i >= 0)
9190 return options[i].def_val[VI_DEFAULT];
9191 return (char_u *)NULL;
9192}
9193
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009194#if defined(FEAT_MBYTE) || defined(PROTO)
9195 char_u *
9196get_encoding_default()
9197{
9198 int i;
9199
9200 i = findoption((char_u *)"enc");
9201 if (i >= 0)
9202 return options[i].def_val[VI_DEFAULT];
9203 return (char_u *)NULL;
9204}
9205#endif
9206
Bram Moolenaar071d4272004-06-13 20:20:40 +00009207/*
9208 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9209 */
9210 static int
9211find_key_option(arg)
9212 char_u *arg;
9213{
9214 int key;
9215 int modifiers;
9216
9217 /*
9218 * Don't use get_special_key_code() for t_xx, we don't want it to call
9219 * add_termcap_entry().
9220 */
9221 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9222 key = TERMCAP2KEY(arg[2], arg[3]);
9223 else
9224 {
9225 --arg; /* put arg at the '<' */
9226 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009227 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009228 if (modifiers) /* can't handle modifiers here */
9229 key = 0;
9230 }
9231 return key;
9232}
9233
9234/*
9235 * if 'all' == 0: show changed options
9236 * if 'all' == 1: show all normal options
9237 * if 'all' == 2: show all terminal options
9238 */
9239 static void
9240showoptions(all, opt_flags)
9241 int all;
9242 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9243{
9244 struct vimoption *p;
9245 int col;
9246 int isterm;
9247 char_u *varp;
9248 struct vimoption **items;
9249 int item_count;
9250 int run;
9251 int row, rows;
9252 int cols;
9253 int i;
9254 int len;
9255
9256#define INC 20
9257#define GAP 3
9258
9259 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9260 PARAM_COUNT));
9261 if (items == NULL)
9262 return;
9263
9264 /* Highlight title */
9265 if (all == 2)
9266 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9267 else if (opt_flags & OPT_GLOBAL)
9268 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9269 else if (opt_flags & OPT_LOCAL)
9270 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9271 else
9272 MSG_PUTS_TITLE(_("\n--- Options ---"));
9273
9274 /*
9275 * do the loop two times:
9276 * 1. display the short items
9277 * 2. display the long items (only strings and numbers)
9278 */
9279 for (run = 1; run <= 2 && !got_int; ++run)
9280 {
9281 /*
9282 * collect the items in items[]
9283 */
9284 item_count = 0;
9285 for (p = &options[0]; p->fullname != NULL; p++)
9286 {
9287 varp = NULL;
9288 isterm = istermoption(p);
9289 if (opt_flags != 0)
9290 {
9291 if (p->indir != PV_NONE && !isterm)
9292 varp = get_varp_scope(p, opt_flags);
9293 }
9294 else
9295 varp = get_varp(p);
9296 if (varp != NULL
9297 && ((all == 2 && isterm)
9298 || (all == 1 && !isterm)
9299 || (all == 0 && !optval_default(p, varp))))
9300 {
9301 if (p->flags & P_BOOL)
9302 len = 1; /* a toggle option fits always */
9303 else
9304 {
9305 option_value2string(p, opt_flags);
9306 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9307 }
9308 if ((len <= INC - GAP && run == 1) ||
9309 (len > INC - GAP && run == 2))
9310 items[item_count++] = p;
9311 }
9312 }
9313
9314 /*
9315 * display the items
9316 */
9317 if (run == 1)
9318 {
9319 cols = (Columns + GAP - 3) / INC;
9320 if (cols == 0)
9321 cols = 1;
9322 rows = (item_count + cols - 1) / cols;
9323 }
9324 else /* run == 2 */
9325 rows = item_count;
9326 for (row = 0; row < rows && !got_int; ++row)
9327 {
9328 msg_putchar('\n'); /* go to next line */
9329 if (got_int) /* 'q' typed in more */
9330 break;
9331 col = 0;
9332 for (i = row; i < item_count; i += rows)
9333 {
9334 msg_col = col; /* make columns */
9335 showoneopt(items[i], opt_flags);
9336 col += INC;
9337 }
9338 out_flush();
9339 ui_breakcheck();
9340 }
9341 }
9342 vim_free(items);
9343}
9344
9345/*
9346 * Return TRUE if option "p" has its default value.
9347 */
9348 static int
9349optval_default(p, varp)
9350 struct vimoption *p;
9351 char_u *varp;
9352{
9353 int dvi;
9354
9355 if (varp == NULL)
9356 return TRUE; /* hidden option is always at default */
9357 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9358 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009359 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009360 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009361 /* the cast to long is required for Manx C, long_i is
9362 * needed for MSVC */
9363 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364 /* P_STRING */
9365 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9366}
9367
9368/*
9369 * showoneopt: show the value of one option
9370 * must not be called with a hidden option!
9371 */
9372 static void
9373showoneopt(p, opt_flags)
9374 struct vimoption *p;
9375 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9376{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009377 char_u *varp;
9378 int save_silent = silent_mode;
9379
9380 silent_mode = FALSE;
9381 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009382
9383 varp = get_varp_scope(p, opt_flags);
9384
9385 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9386 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9387 ? !curbufIsChanged() : !*(int *)varp))
9388 MSG_PUTS("no");
9389 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9390 MSG_PUTS("--");
9391 else
9392 MSG_PUTS(" ");
9393 MSG_PUTS(p->fullname);
9394 if (!(p->flags & P_BOOL))
9395 {
9396 msg_putchar('=');
9397 /* put value string in NameBuff */
9398 option_value2string(p, opt_flags);
9399 msg_outtrans(NameBuff);
9400 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009401
9402 silent_mode = save_silent;
9403 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009404}
9405
9406/*
9407 * Write modified options as ":set" commands to a file.
9408 *
9409 * There are three values for "opt_flags":
9410 * OPT_GLOBAL: Write global option values and fresh values of
9411 * buffer-local options (used for start of a session
9412 * file).
9413 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9414 * curwin (used for a vimrc file).
9415 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9416 * and local values for window-local options of
9417 * curwin. Local values are also written when at the
9418 * default value, because a modeline or autocommand
9419 * may have set them when doing ":edit file" and the
9420 * user has set them back at the default or fresh
9421 * value.
9422 * When "local_only" is TRUE, don't write fresh
9423 * values, only local values (for ":mkview").
9424 * (fresh value = value used for a new buffer or window for a local option).
9425 *
9426 * Return FAIL on error, OK otherwise.
9427 */
9428 int
9429makeset(fd, opt_flags, local_only)
9430 FILE *fd;
9431 int opt_flags;
9432 int local_only;
9433{
9434 struct vimoption *p;
9435 char_u *varp; /* currently used value */
9436 char_u *varp_fresh; /* local value */
9437 char_u *varp_local = NULL; /* fresh value */
9438 char *cmd;
9439 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009440 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009441
9442 /*
9443 * The options that don't have a default (terminal name, columns, lines)
9444 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009445 * Do the loop over "options[]" twice: once for options with the
9446 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009447 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009448 for (pri = 1; pri >= 0; --pri)
9449 {
9450 for (p = &options[0]; !istermoption(p); p++)
9451 if (!(p->flags & P_NO_MKRC)
9452 && !istermoption(p)
9453 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009454 {
9455 /* skip global option when only doing locals */
9456 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9457 continue;
9458
9459 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9460 * file, they are always buffer-specific. */
9461 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9462 continue;
9463
9464 /* Global values are only written when not at the default value. */
9465 varp = get_varp_scope(p, opt_flags);
9466 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9467 continue;
9468
9469 round = 2;
9470 if (p->indir != PV_NONE)
9471 {
9472 if (p->var == VAR_WIN)
9473 {
9474 /* skip window-local option when only doing globals */
9475 if (!(opt_flags & OPT_LOCAL))
9476 continue;
9477 /* When fresh value of window-local option is not at the
9478 * default, need to write it too. */
9479 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9480 {
9481 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9482 if (!optval_default(p, varp_fresh))
9483 {
9484 round = 1;
9485 varp_local = varp;
9486 varp = varp_fresh;
9487 }
9488 }
9489 }
9490 }
9491
9492 /* Round 1: fresh value for window-local options.
9493 * Round 2: other values */
9494 for ( ; round <= 2; varp = varp_local, ++round)
9495 {
9496 if (round == 1 || (opt_flags & OPT_GLOBAL))
9497 cmd = "set";
9498 else
9499 cmd = "setlocal";
9500
9501 if (p->flags & P_BOOL)
9502 {
9503 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9504 return FAIL;
9505 }
9506 else if (p->flags & P_NUM)
9507 {
9508 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9509 return FAIL;
9510 }
9511 else /* P_STRING */
9512 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009513#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9514 int do_endif = FALSE;
9515
Bram Moolenaar071d4272004-06-13 20:20:40 +00009516 /* Don't set 'syntax' and 'filetype' again if the value is
9517 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009518 if (
9519# if defined(FEAT_SYN_HL)
9520 p->indir == PV_SYN
9521# if defined(FEAT_AUTOCMD)
9522 ||
9523# endif
9524# endif
9525# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009526 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009527# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009528 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009529 {
9530 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9531 *(char_u **)(varp)) < 0
9532 || put_eol(fd) < 0)
9533 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009534 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009535 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009536#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9538 (p->flags & P_EXPAND) != 0) == FAIL)
9539 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009540#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9541 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009542 {
9543 if (put_line(fd, "endif") == FAIL)
9544 return FAIL;
9545 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009546#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 }
9548 }
9549 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009550 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009551 return OK;
9552}
9553
9554#if defined(FEAT_FOLDING) || defined(PROTO)
9555/*
9556 * Generate set commands for the local fold options only. Used when
9557 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9558 */
9559 int
9560makefoldset(fd)
9561 FILE *fd;
9562{
9563 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9564# ifdef FEAT_EVAL
9565 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9566 == FAIL
9567# endif
9568 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9569 == FAIL
9570 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9571 == FAIL
9572 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9573 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9574 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9575 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9576 )
9577 return FAIL;
9578
9579 return OK;
9580}
9581#endif
9582
9583 static int
9584put_setstring(fd, cmd, name, valuep, expand)
9585 FILE *fd;
9586 char *cmd;
9587 char *name;
9588 char_u **valuep;
9589 int expand;
9590{
9591 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009592 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009593
9594 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9595 return FAIL;
9596 if (*valuep != NULL)
9597 {
9598 /* Output 'pastetoggle' as key names. For other
9599 * options some characters have to be escaped with
9600 * CTRL-V or backslash */
9601 if (valuep == &p_pt)
9602 {
9603 s = *valuep;
9604 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009605 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009606 return FAIL;
9607 }
9608 else if (expand)
9609 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009610 buf = alloc(MAXPATHL);
9611 if (buf == NULL)
9612 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009613 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9614 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009615 {
9616 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009617 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009618 }
9619 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009620 }
9621 else if (put_escstr(fd, *valuep, 2) == FAIL)
9622 return FAIL;
9623 }
9624 if (put_eol(fd) < 0)
9625 return FAIL;
9626 return OK;
9627}
9628
9629 static int
9630put_setnum(fd, cmd, name, valuep)
9631 FILE *fd;
9632 char *cmd;
9633 char *name;
9634 long *valuep;
9635{
9636 long wc;
9637
9638 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9639 return FAIL;
9640 if (wc_use_keyname((char_u *)valuep, &wc))
9641 {
9642 /* print 'wildchar' and 'wildcharm' as a key name */
9643 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9644 return FAIL;
9645 }
9646 else if (fprintf(fd, "%ld", *valuep) < 0)
9647 return FAIL;
9648 if (put_eol(fd) < 0)
9649 return FAIL;
9650 return OK;
9651}
9652
9653 static int
9654put_setbool(fd, cmd, name, value)
9655 FILE *fd;
9656 char *cmd;
9657 char *name;
9658 int value;
9659{
Bram Moolenaar893de922007-10-02 18:40:57 +00009660 if (value < 0) /* global/local option using global value */
9661 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009662 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9663 || put_eol(fd) < 0)
9664 return FAIL;
9665 return OK;
9666}
9667
9668/*
9669 * Clear all the terminal options.
9670 * If the option has been allocated, free the memory.
9671 * Terminal options are never hidden or indirect.
9672 */
9673 void
9674clear_termoptions()
9675{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009676 /*
9677 * Reset a few things before clearing the old options. This may cause
9678 * outputting a few things that the terminal doesn't understand, but the
9679 * screen will be cleared later, so this is OK.
9680 */
9681#ifdef FEAT_MOUSE_TTY
9682 mch_setmouse(FALSE); /* switch mouse off */
9683#endif
9684#ifdef FEAT_TITLE
9685 mch_restore_title(3); /* restore window titles */
9686#endif
9687#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9688 /* When starting the GUI close the display opened for the clipboard.
9689 * After restoring the title, because that will need the display. */
9690 if (gui.starting)
9691 clear_xterm_clip();
9692#endif
9693#ifdef WIN3264
9694 /*
9695 * Check if this is allowed now.
9696 */
9697 if (can_end_termcap_mode(FALSE) == TRUE)
9698#endif
9699 stoptermcap(); /* stop termcap mode */
9700
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009701 free_termoptions();
9702}
9703
9704 void
9705free_termoptions()
9706{
9707 struct vimoption *p;
9708
Bram Moolenaar071d4272004-06-13 20:20:40 +00009709 for (p = &options[0]; p->fullname != NULL; p++)
9710 if (istermoption(p))
9711 {
9712 if (p->flags & P_ALLOCED)
9713 free_string_option(*(char_u **)(p->var));
9714 if (p->flags & P_DEF_ALLOCED)
9715 free_string_option(p->def_val[VI_DEFAULT]);
9716 *(char_u **)(p->var) = empty_option;
9717 p->def_val[VI_DEFAULT] = empty_option;
9718 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9719 }
9720 clear_termcodes();
9721}
9722
9723/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009724 * Free the string for one term option, if it was allocated.
9725 * Set the string to empty_option and clear allocated flag.
9726 * "var" points to the option value.
9727 */
9728 void
9729free_one_termoption(var)
9730 char_u *var;
9731{
9732 struct vimoption *p;
9733
9734 for (p = &options[0]; p->fullname != NULL; p++)
9735 if (p->var == var)
9736 {
9737 if (p->flags & P_ALLOCED)
9738 free_string_option(*(char_u **)(p->var));
9739 *(char_u **)(p->var) = empty_option;
9740 p->flags &= ~P_ALLOCED;
9741 break;
9742 }
9743}
9744
9745/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009746 * Set the terminal option defaults to the current value.
9747 * Used after setting the terminal name.
9748 */
9749 void
9750set_term_defaults()
9751{
9752 struct vimoption *p;
9753
9754 for (p = &options[0]; p->fullname != NULL; p++)
9755 {
9756 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9757 {
9758 if (p->flags & P_DEF_ALLOCED)
9759 {
9760 free_string_option(p->def_val[VI_DEFAULT]);
9761 p->flags &= ~P_DEF_ALLOCED;
9762 }
9763 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9764 if (p->flags & P_ALLOCED)
9765 {
9766 p->flags |= P_DEF_ALLOCED;
9767 p->flags &= ~P_ALLOCED; /* don't free the value now */
9768 }
9769 }
9770 }
9771}
9772
9773/*
9774 * return TRUE if 'p' starts with 't_'
9775 */
9776 static int
9777istermoption(p)
9778 struct vimoption *p;
9779{
9780 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9781}
9782
9783/*
9784 * Compute columns for ruler and shown command. 'sc_col' is also used to
9785 * decide what the maximum length of a message on the status line can be.
9786 * If there is a status line for the last window, 'sc_col' is independent
9787 * of 'ru_col'.
9788 */
9789
9790#define COL_RULER 17 /* columns needed by standard ruler */
9791
9792 void
9793comp_col()
9794{
9795#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9796 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9797
9798 sc_col = 0;
9799 ru_col = 0;
9800 if (p_ru)
9801 {
9802#ifdef FEAT_STL_OPT
9803 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9804#else
9805 ru_col = COL_RULER + 1;
9806#endif
9807 /* no last status line, adjust sc_col */
9808 if (!last_has_status)
9809 sc_col = ru_col;
9810 }
9811 if (p_sc)
9812 {
9813 sc_col += SHOWCMD_COLS;
9814 if (!p_ru || last_has_status) /* no need for separating space */
9815 ++sc_col;
9816 }
9817 sc_col = Columns - sc_col;
9818 ru_col = Columns - ru_col;
9819 if (sc_col <= 0) /* screen too narrow, will become a mess */
9820 sc_col = 1;
9821 if (ru_col <= 0)
9822 ru_col = 1;
9823#else
9824 sc_col = Columns;
9825 ru_col = Columns;
9826#endif
9827}
9828
9829/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009830 * Unset local option value, similar to ":set opt<".
9831 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009832 void
9833unset_global_local_option(name, from)
9834 char_u *name;
9835 void *from;
9836{
9837 struct vimoption *p;
9838 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009839 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009840
9841 opt_idx = findoption(name);
9842 p = &(options[opt_idx]);
9843
9844 switch ((int)p->indir)
9845 {
9846 /* global option with local value: use local value if it's been set */
9847 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009848 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009849 break;
9850 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009851 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009852 break;
9853 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009854 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009855 break;
9856 case PV_AR:
9857 buf->b_p_ar = -1;
9858 break;
9859 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009860 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009861 break;
9862#ifdef FEAT_FIND_ID
9863 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009864 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009865 break;
9866 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009867 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009868 break;
9869#endif
9870#ifdef FEAT_INS_EXPAND
9871 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009872 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009873 break;
9874 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009875 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009876 break;
9877#endif
9878#ifdef FEAT_QUICKFIX
9879 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009880 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009881 break;
9882 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009883 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009884 break;
9885 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009886 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009887 break;
9888#endif
9889#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9890 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009891 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009892 break;
9893#endif
9894#if defined(FEAT_CRYPT)
9895 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009896 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009897 break;
9898#endif
9899#ifdef FEAT_STL_OPT
9900 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009901 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009902 break;
9903#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009904 case PV_UL:
9905 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9906 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009907#ifdef FEAT_LISP
9908 case PV_LW:
9909 clear_string_option(&buf->b_p_lw);
9910 break;
9911#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009912 }
9913}
9914
9915/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009916 * Get pointer to option variable, depending on local or global scope.
9917 */
9918 static char_u *
9919get_varp_scope(p, opt_flags)
9920 struct vimoption *p;
9921 int opt_flags;
9922{
9923 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9924 {
9925 if (p->var == VAR_WIN)
9926 return (char_u *)GLOBAL_WO(get_varp(p));
9927 return p->var;
9928 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009929 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009930 {
9931 switch ((int)p->indir)
9932 {
9933#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009934 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9935 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9936 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009937#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009938 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9939 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9940 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009941 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009942 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009943#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009944 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9945 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009946#endif
9947#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009948 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9949 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009951#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9952 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9953#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009954#if defined(FEAT_CRYPT)
9955 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9956#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009957#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009958 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009959#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009960 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009961#ifdef FEAT_LISP
9962 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9963#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009964 }
9965 return NULL; /* "cannot happen" */
9966 }
9967 return get_varp(p);
9968}
9969
9970/*
9971 * Get pointer to option variable.
9972 */
9973 static char_u *
9974get_varp(p)
9975 struct vimoption *p;
9976{
9977 /* hidden option, always return NULL */
9978 if (p->var == NULL)
9979 return NULL;
9980
9981 switch ((int)p->indir)
9982 {
9983 case PV_NONE: return p->var;
9984
9985 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009986 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009987 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009988 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009990 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009991 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009992 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009994 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009995 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9996#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009997 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009998 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009999 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010000 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10001#endif
10002#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010003 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010004 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010005 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10007#endif
10008#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010009 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010010 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010011 case PV_GP: return *curbuf->b_p_gp != NUL
10012 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10013 case PV_MP: return *curbuf->b_p_mp != NUL
10014 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010015#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010016#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10017 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10018 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10019#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010020#if defined(FEAT_CRYPT)
10021 case PV_CM: return *curbuf->b_p_cm != NUL
10022 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10023#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010024#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010025 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010026 ? (char_u *)&(curwin->w_p_stl) : p->var;
10027#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010028 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10029 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010030#ifdef FEAT_LISP
10031 case PV_LW: return *curbuf->b_p_lw != NUL
10032 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10033#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034
10035#ifdef FEAT_ARABIC
10036 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10037#endif
10038 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010039#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010040 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10041#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010042#ifdef FEAT_SYN_HL
10043 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10044 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010045 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010046#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010047#ifdef FEAT_DIFF
10048 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10049#endif
10050#ifdef FEAT_FOLDING
10051 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10052 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10053 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10054 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10055 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10056 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10057 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10058# ifdef FEAT_EVAL
10059 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10060 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10061# endif
10062 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10063#endif
10064 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010065 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010066#ifdef FEAT_LINEBREAK
10067 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10068#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010069#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10071#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010072#ifdef FEAT_VERTSPLIT
10073 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10074#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010075#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10076 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10077#endif
10078#ifdef FEAT_RIGHTLEFT
10079 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10080 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10081#endif
10082 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10083 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10084#ifdef FEAT_LINEBREAK
10085 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010086 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10087 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010088#endif
10089#ifdef FEAT_SCROLLBIND
10090 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10091#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010092#ifdef FEAT_CURSORBIND
10093 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10094#endif
10095#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010096 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10097 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010098#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010099
10100 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10101 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10102#ifdef FEAT_MBYTE
10103 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10104#endif
10105#if defined(FEAT_QUICKFIX)
10106 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10107 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10108#endif
10109 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10110 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10111#ifdef FEAT_CINDENT
10112 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10113 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10114 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10115#endif
10116#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10117 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10118#endif
10119#ifdef FEAT_COMMENTS
10120 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10121#endif
10122#ifdef FEAT_FOLDING
10123 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10124#endif
10125#ifdef FEAT_INS_EXPAND
10126 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10127#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010128#ifdef FEAT_COMPL_FUNC
10129 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010130 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010132 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10133 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10134#ifdef FEAT_MBYTE
10135 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10136#endif
10137 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10138#ifdef FEAT_AUTOCMD
10139 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10140#endif
10141 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010142 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010143 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10144 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10145 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10146 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10147#ifdef FEAT_FIND_ID
10148# ifdef FEAT_EVAL
10149 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10150# endif
10151#endif
10152#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10153 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10154 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10155#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010156#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010157 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10158#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159#ifdef FEAT_CRYPT
10160 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10161#endif
10162#ifdef FEAT_LISP
10163 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10164#endif
10165 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10166 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10167 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10168 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10169 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010170 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010171#ifdef FEAT_TEXTOBJ
10172 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10173#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10175#ifdef FEAT_SMARTINDENT
10176 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10177#endif
10178#ifndef SHORT_FNAME
10179 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10180#endif
10181 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10182#ifdef FEAT_SEARCHPATH
10183 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10184#endif
10185 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10186#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010187 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010188 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10189#endif
10190#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010191 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10192 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10193 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194#endif
10195 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10196 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10197 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10198 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010199#ifdef FEAT_PERSISTENT_UNDO
10200 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10201#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10203#ifdef FEAT_KEYMAP
10204 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10205#endif
10206 default: EMSG(_("E356: get_varp ERROR"));
10207 }
10208 /* always return a valid pointer to avoid a crash! */
10209 return (char_u *)&(curbuf->b_p_wm);
10210}
10211
10212/*
10213 * Get the value of 'equalprg', either the buffer-local one or the global one.
10214 */
10215 char_u *
10216get_equalprg()
10217{
10218 if (*curbuf->b_p_ep == NUL)
10219 return p_ep;
10220 return curbuf->b_p_ep;
10221}
10222
10223#if defined(FEAT_WINDOWS) || defined(PROTO)
10224/*
10225 * Copy options from one window to another.
10226 * Used when splitting a window.
10227 */
10228 void
10229win_copy_options(wp_from, wp_to)
10230 win_T *wp_from;
10231 win_T *wp_to;
10232{
10233 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10234 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10235# ifdef FEAT_RIGHTLEFT
10236# ifdef FEAT_FKMAP
10237 /* Is this right? */
10238 wp_to->w_farsi = wp_from->w_farsi;
10239# endif
10240# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010241#if defined(FEAT_LINEBREAK)
10242 briopt_check(wp_to);
10243#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010244}
10245#endif
10246
10247/*
10248 * Copy the options from one winopt_T to another.
10249 * Doesn't free the old option values in "to", use clear_winopt() for that.
10250 * The 'scroll' option is not copied, because it depends on the window height.
10251 * The 'previewwindow' option is reset, there can be only one preview window.
10252 */
10253 void
10254copy_winopt(from, to)
10255 winopt_T *from;
10256 winopt_T *to;
10257{
10258#ifdef FEAT_ARABIC
10259 to->wo_arab = from->wo_arab;
10260#endif
10261 to->wo_list = from->wo_list;
10262 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010263 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010264#ifdef FEAT_LINEBREAK
10265 to->wo_nuw = from->wo_nuw;
10266#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010267#ifdef FEAT_RIGHTLEFT
10268 to->wo_rl = from->wo_rl;
10269 to->wo_rlc = vim_strsave(from->wo_rlc);
10270#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010271#ifdef FEAT_STL_OPT
10272 to->wo_stl = vim_strsave(from->wo_stl);
10273#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010275#ifdef FEAT_DIFF
10276 to->wo_wrap_save = from->wo_wrap_save;
10277#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010278#ifdef FEAT_LINEBREAK
10279 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010280 to->wo_bri = from->wo_bri;
10281 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010282#endif
10283#ifdef FEAT_SCROLLBIND
10284 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010285 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010286#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010287#ifdef FEAT_CURSORBIND
10288 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010289 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010290#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010291#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010292 to->wo_spell = from->wo_spell;
10293#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010294#ifdef FEAT_SYN_HL
10295 to->wo_cuc = from->wo_cuc;
10296 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010297 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010298#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010299#ifdef FEAT_DIFF
10300 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010301 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010303#ifdef FEAT_CONCEAL
10304 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010305 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307#ifdef FEAT_FOLDING
10308 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010309 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010310 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010311 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312 to->wo_fdi = vim_strsave(from->wo_fdi);
10313 to->wo_fml = from->wo_fml;
10314 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010315 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010316 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010317 to->wo_fdm_save = from->wo_diff_saved
10318 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319 to->wo_fdn = from->wo_fdn;
10320# ifdef FEAT_EVAL
10321 to->wo_fde = vim_strsave(from->wo_fde);
10322 to->wo_fdt = vim_strsave(from->wo_fdt);
10323# endif
10324 to->wo_fmr = vim_strsave(from->wo_fmr);
10325#endif
10326 check_winopt(to); /* don't want NULL pointers */
10327}
10328
10329/*
10330 * Check string options in a window for a NULL value.
10331 */
10332 void
10333check_win_options(win)
10334 win_T *win;
10335{
10336 check_winopt(&win->w_onebuf_opt);
10337 check_winopt(&win->w_allbuf_opt);
10338}
10339
10340/*
10341 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10342 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010343 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010345 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346{
10347#ifdef FEAT_FOLDING
10348 check_string_option(&wop->wo_fdi);
10349 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010350 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351# ifdef FEAT_EVAL
10352 check_string_option(&wop->wo_fde);
10353 check_string_option(&wop->wo_fdt);
10354# endif
10355 check_string_option(&wop->wo_fmr);
10356#endif
10357#ifdef FEAT_RIGHTLEFT
10358 check_string_option(&wop->wo_rlc);
10359#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010360#ifdef FEAT_STL_OPT
10361 check_string_option(&wop->wo_stl);
10362#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010363#ifdef FEAT_SYN_HL
10364 check_string_option(&wop->wo_cc);
10365#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010366#ifdef FEAT_CONCEAL
10367 check_string_option(&wop->wo_cocu);
10368#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010369#ifdef FEAT_LINEBREAK
10370 check_string_option(&wop->wo_briopt);
10371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010372}
10373
10374/*
10375 * Free the allocated memory inside a winopt_T.
10376 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010377 void
10378clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010379 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010380{
10381#ifdef FEAT_FOLDING
10382 clear_string_option(&wop->wo_fdi);
10383 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010384 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010385# ifdef FEAT_EVAL
10386 clear_string_option(&wop->wo_fde);
10387 clear_string_option(&wop->wo_fdt);
10388# endif
10389 clear_string_option(&wop->wo_fmr);
10390#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010391#ifdef FEAT_LINEBREAK
10392 clear_string_option(&wop->wo_briopt);
10393#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010394#ifdef FEAT_RIGHTLEFT
10395 clear_string_option(&wop->wo_rlc);
10396#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010397#ifdef FEAT_STL_OPT
10398 clear_string_option(&wop->wo_stl);
10399#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010400#ifdef FEAT_SYN_HL
10401 clear_string_option(&wop->wo_cc);
10402#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010403#ifdef FEAT_CONCEAL
10404 clear_string_option(&wop->wo_cocu);
10405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406}
10407
10408/*
10409 * Copy global option values to local options for one buffer.
10410 * Used when creating a new buffer and sometimes when entering a buffer.
10411 * flags:
10412 * BCO_ENTER We will enter the buf buffer.
10413 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10414 * appropriate.
10415 * BCO_NOHELP Don't copy the values to a help buffer.
10416 */
10417 void
10418buf_copy_options(buf, flags)
10419 buf_T *buf;
10420 int flags;
10421{
10422 int should_copy = TRUE;
10423 char_u *save_p_isk = NULL; /* init for GCC */
10424 int dont_do_help;
10425 int did_isk = FALSE;
10426
10427 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010428 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429 */
10430 if (buf == NULL || !buf_valid(buf))
10431 return;
10432
10433 /*
10434 * Skip this when the option defaults have not been set yet. Happens when
10435 * main() allocates the first buffer.
10436 */
10437 if (p_cpo != NULL)
10438 {
10439 /*
10440 * Always copy when entering and 'cpo' contains 'S'.
10441 * Don't copy when already initialized.
10442 * Don't copy when 'cpo' contains 's' and not entering.
10443 * 'S' BCO_ENTER initialized 's' should_copy
10444 * yes yes X X TRUE
10445 * yes no yes X FALSE
10446 * no X yes X FALSE
10447 * X no no yes FALSE
10448 * X no no no TRUE
10449 * no yes no X TRUE
10450 */
10451 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10452 && (buf->b_p_initialized
10453 || (!(flags & BCO_ENTER)
10454 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10455 should_copy = FALSE;
10456
10457 if (should_copy || (flags & BCO_ALWAYS))
10458 {
10459 /* Don't copy the options specific to a help buffer when
10460 * BCO_NOHELP is given or the options were initialized already
10461 * (jumping back to a help file with CTRL-T or CTRL-O) */
10462 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10463 || buf->b_p_initialized;
10464 if (dont_do_help) /* don't free b_p_isk */
10465 {
10466 save_p_isk = buf->b_p_isk;
10467 buf->b_p_isk = NULL;
10468 }
10469 /*
10470 * Always free the allocated strings.
10471 * If not already initialized, set 'readonly' and copy 'fileformat'.
10472 */
10473 if (!buf->b_p_initialized)
10474 {
10475 free_buf_options(buf, TRUE);
10476 buf->b_p_ro = FALSE; /* don't copy readonly */
10477 buf->b_p_tx = p_tx;
10478#ifdef FEAT_MBYTE
10479 buf->b_p_fenc = vim_strsave(p_fenc);
10480#endif
10481 buf->b_p_ff = vim_strsave(p_ff);
10482#if defined(FEAT_QUICKFIX)
10483 buf->b_p_bh = empty_option;
10484 buf->b_p_bt = empty_option;
10485#endif
10486 }
10487 else
10488 free_buf_options(buf, FALSE);
10489
10490 buf->b_p_ai = p_ai;
10491 buf->b_p_ai_nopaste = p_ai_nopaste;
10492 buf->b_p_sw = p_sw;
10493 buf->b_p_tw = p_tw;
10494 buf->b_p_tw_nopaste = p_tw_nopaste;
10495 buf->b_p_tw_nobin = p_tw_nobin;
10496 buf->b_p_wm = p_wm;
10497 buf->b_p_wm_nopaste = p_wm_nopaste;
10498 buf->b_p_wm_nobin = p_wm_nobin;
10499 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010500#ifdef FEAT_MBYTE
10501 buf->b_p_bomb = p_bomb;
10502#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010503 buf->b_p_et = p_et;
10504 buf->b_p_et_nobin = p_et_nobin;
10505 buf->b_p_ml = p_ml;
10506 buf->b_p_ml_nobin = p_ml_nobin;
10507 buf->b_p_inf = p_inf;
10508 buf->b_p_swf = p_swf;
10509#ifdef FEAT_INS_EXPAND
10510 buf->b_p_cpt = vim_strsave(p_cpt);
10511#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010512#ifdef FEAT_COMPL_FUNC
10513 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010514 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010515#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516 buf->b_p_sts = p_sts;
10517 buf->b_p_sts_nopaste = p_sts_nopaste;
10518#ifndef SHORT_FNAME
10519 buf->b_p_sn = p_sn;
10520#endif
10521#ifdef FEAT_COMMENTS
10522 buf->b_p_com = vim_strsave(p_com);
10523#endif
10524#ifdef FEAT_FOLDING
10525 buf->b_p_cms = vim_strsave(p_cms);
10526#endif
10527 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010528 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529 buf->b_p_nf = vim_strsave(p_nf);
10530 buf->b_p_mps = vim_strsave(p_mps);
10531#ifdef FEAT_SMARTINDENT
10532 buf->b_p_si = p_si;
10533#endif
10534 buf->b_p_ci = p_ci;
10535#ifdef FEAT_CINDENT
10536 buf->b_p_cin = p_cin;
10537 buf->b_p_cink = vim_strsave(p_cink);
10538 buf->b_p_cino = vim_strsave(p_cino);
10539#endif
10540#ifdef FEAT_AUTOCMD
10541 /* Don't copy 'filetype', it must be detected */
10542 buf->b_p_ft = empty_option;
10543#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544 buf->b_p_pi = p_pi;
10545#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10546 buf->b_p_cinw = vim_strsave(p_cinw);
10547#endif
10548#ifdef FEAT_LISP
10549 buf->b_p_lisp = p_lisp;
10550#endif
10551#ifdef FEAT_SYN_HL
10552 /* Don't copy 'syntax', it must be set */
10553 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010554 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010555#endif
10556#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010557 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010558 (void)compile_cap_prog(&buf->b_s);
10559 buf->b_s.b_p_spf = vim_strsave(p_spf);
10560 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561#endif
10562#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10563 buf->b_p_inde = vim_strsave(p_inde);
10564 buf->b_p_indk = vim_strsave(p_indk);
10565#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010566#if defined(FEAT_EVAL)
10567 buf->b_p_fex = vim_strsave(p_fex);
10568#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569#ifdef FEAT_CRYPT
10570 buf->b_p_key = vim_strsave(p_key);
10571#endif
10572#ifdef FEAT_SEARCHPATH
10573 buf->b_p_sua = vim_strsave(p_sua);
10574#endif
10575#ifdef FEAT_KEYMAP
10576 buf->b_p_keymap = vim_strsave(p_keymap);
10577 buf->b_kmap_state |= KEYMAP_INIT;
10578#endif
10579 /* This isn't really an option, but copying the langmap and IME
10580 * state from the current buffer is better than resetting it. */
10581 buf->b_p_iminsert = p_iminsert;
10582 buf->b_p_imsearch = p_imsearch;
10583
10584 /* options that are normally global but also have a local value
10585 * are not copied, start using the global value */
10586 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010587 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588#ifdef FEAT_QUICKFIX
10589 buf->b_p_gp = empty_option;
10590 buf->b_p_mp = empty_option;
10591 buf->b_p_efm = empty_option;
10592#endif
10593 buf->b_p_ep = empty_option;
10594 buf->b_p_kp = empty_option;
10595 buf->b_p_path = empty_option;
10596 buf->b_p_tags = empty_option;
10597#ifdef FEAT_FIND_ID
10598 buf->b_p_def = empty_option;
10599 buf->b_p_inc = empty_option;
10600# ifdef FEAT_EVAL
10601 buf->b_p_inex = vim_strsave(p_inex);
10602# endif
10603#endif
10604#ifdef FEAT_INS_EXPAND
10605 buf->b_p_dict = empty_option;
10606 buf->b_p_tsr = empty_option;
10607#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010608#ifdef FEAT_TEXTOBJ
10609 buf->b_p_qe = vim_strsave(p_qe);
10610#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010611#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10612 buf->b_p_bexpr = empty_option;
10613#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010614#if defined(FEAT_CRYPT)
10615 buf->b_p_cm = empty_option;
10616#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010617#ifdef FEAT_PERSISTENT_UNDO
10618 buf->b_p_udf = p_udf;
10619#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010620#ifdef FEAT_LISP
10621 buf->b_p_lw = empty_option;
10622#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010623
10624 /*
10625 * Don't copy the options set by ex_help(), use the saved values,
10626 * when going from a help buffer to a non-help buffer.
10627 * Don't touch these at all when BCO_NOHELP is used and going from
10628 * or to a help buffer.
10629 */
10630 if (dont_do_help)
10631 buf->b_p_isk = save_p_isk;
10632 else
10633 {
10634 buf->b_p_isk = vim_strsave(p_isk);
10635 did_isk = TRUE;
10636 buf->b_p_ts = p_ts;
10637 buf->b_help = FALSE;
10638#ifdef FEAT_QUICKFIX
10639 if (buf->b_p_bt[0] == 'h')
10640 clear_string_option(&buf->b_p_bt);
10641#endif
10642 buf->b_p_ma = p_ma;
10643 }
10644 }
10645
10646 /*
10647 * When the options should be copied (ignoring BCO_ALWAYS), set the
10648 * flag that indicates that the options have been initialized.
10649 */
10650 if (should_copy)
10651 buf->b_p_initialized = TRUE;
10652 }
10653
10654 check_buf_options(buf); /* make sure we don't have NULLs */
10655 if (did_isk)
10656 (void)buf_init_chartab(buf, FALSE);
10657}
10658
10659/*
10660 * Reset the 'modifiable' option and its default value.
10661 */
10662 void
10663reset_modifiable()
10664{
10665 int opt_idx;
10666
10667 curbuf->b_p_ma = FALSE;
10668 p_ma = FALSE;
10669 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010670 if (opt_idx >= 0)
10671 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010672}
10673
10674/*
10675 * Set the global value for 'iminsert' to the local value.
10676 */
10677 void
10678set_iminsert_global()
10679{
10680 p_iminsert = curbuf->b_p_iminsert;
10681}
10682
10683/*
10684 * Set the global value for 'imsearch' to the local value.
10685 */
10686 void
10687set_imsearch_global()
10688{
10689 p_imsearch = curbuf->b_p_imsearch;
10690}
10691
10692#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10693static int expand_option_idx = -1;
10694static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10695static int expand_option_flags = 0;
10696
10697 void
10698set_context_in_set_cmd(xp, arg, opt_flags)
10699 expand_T *xp;
10700 char_u *arg;
10701 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10702{
10703 int nextchar;
10704 long_u flags = 0; /* init for GCC */
10705 int opt_idx = 0; /* init for GCC */
10706 char_u *p;
10707 char_u *s;
10708 int is_term_option = FALSE;
10709 int key;
10710
10711 expand_option_flags = opt_flags;
10712
10713 xp->xp_context = EXPAND_SETTINGS;
10714 if (*arg == NUL)
10715 {
10716 xp->xp_pattern = arg;
10717 return;
10718 }
10719 p = arg + STRLEN(arg) - 1;
10720 if (*p == ' ' && *(p - 1) != '\\')
10721 {
10722 xp->xp_pattern = p + 1;
10723 return;
10724 }
10725 while (p > arg)
10726 {
10727 s = p;
10728 /* count number of backslashes before ' ' or ',' */
10729 if (*p == ' ' || *p == ',')
10730 {
10731 while (s > arg && *(s - 1) == '\\')
10732 --s;
10733 }
10734 /* break at a space with an even number of backslashes */
10735 if (*p == ' ' && ((p - s) & 1) == 0)
10736 {
10737 ++p;
10738 break;
10739 }
10740 --p;
10741 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010742 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743 {
10744 xp->xp_context = EXPAND_BOOL_SETTINGS;
10745 p += 2;
10746 }
10747 if (STRNCMP(p, "inv", 3) == 0)
10748 {
10749 xp->xp_context = EXPAND_BOOL_SETTINGS;
10750 p += 3;
10751 }
10752 xp->xp_pattern = arg = p;
10753 if (*arg == '<')
10754 {
10755 while (*p != '>')
10756 if (*p++ == NUL) /* expand terminal option name */
10757 return;
10758 key = get_special_key_code(arg + 1);
10759 if (key == 0) /* unknown name */
10760 {
10761 xp->xp_context = EXPAND_NOTHING;
10762 return;
10763 }
10764 nextchar = *++p;
10765 is_term_option = TRUE;
10766 expand_option_name[2] = KEY2TERMCAP0(key);
10767 expand_option_name[3] = KEY2TERMCAP1(key);
10768 }
10769 else
10770 {
10771 if (p[0] == 't' && p[1] == '_')
10772 {
10773 p += 2;
10774 if (*p != NUL)
10775 ++p;
10776 if (*p == NUL)
10777 return; /* expand option name */
10778 nextchar = *++p;
10779 is_term_option = TRUE;
10780 expand_option_name[2] = p[-2];
10781 expand_option_name[3] = p[-1];
10782 }
10783 else
10784 {
10785 /* Allow * wildcard */
10786 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10787 p++;
10788 if (*p == NUL)
10789 return;
10790 nextchar = *p;
10791 *p = NUL;
10792 opt_idx = findoption(arg);
10793 *p = nextchar;
10794 if (opt_idx == -1 || options[opt_idx].var == NULL)
10795 {
10796 xp->xp_context = EXPAND_NOTHING;
10797 return;
10798 }
10799 flags = options[opt_idx].flags;
10800 if (flags & P_BOOL)
10801 {
10802 xp->xp_context = EXPAND_NOTHING;
10803 return;
10804 }
10805 }
10806 }
10807 /* handle "-=" and "+=" */
10808 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10809 {
10810 ++p;
10811 nextchar = '=';
10812 }
10813 if ((nextchar != '=' && nextchar != ':')
10814 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10815 {
10816 xp->xp_context = EXPAND_UNSUCCESSFUL;
10817 return;
10818 }
10819 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10820 {
10821 xp->xp_context = EXPAND_OLD_SETTING;
10822 if (is_term_option)
10823 expand_option_idx = -1;
10824 else
10825 expand_option_idx = opt_idx;
10826 xp->xp_pattern = p + 1;
10827 return;
10828 }
10829 xp->xp_context = EXPAND_NOTHING;
10830 if (is_term_option || (flags & P_NUM))
10831 return;
10832
10833 xp->xp_pattern = p + 1;
10834
10835 if (flags & P_EXPAND)
10836 {
10837 p = options[opt_idx].var;
10838 if (p == (char_u *)&p_bdir
10839 || p == (char_u *)&p_dir
10840 || p == (char_u *)&p_path
10841 || p == (char_u *)&p_rtp
10842#ifdef FEAT_SEARCHPATH
10843 || p == (char_u *)&p_cdpath
10844#endif
10845#ifdef FEAT_SESSION
10846 || p == (char_u *)&p_vdir
10847#endif
10848 )
10849 {
10850 xp->xp_context = EXPAND_DIRECTORIES;
10851 if (p == (char_u *)&p_path
10852#ifdef FEAT_SEARCHPATH
10853 || p == (char_u *)&p_cdpath
10854#endif
10855 )
10856 xp->xp_backslash = XP_BS_THREE;
10857 else
10858 xp->xp_backslash = XP_BS_ONE;
10859 }
10860 else
10861 {
10862 xp->xp_context = EXPAND_FILES;
10863 /* for 'tags' need three backslashes for a space */
10864 if (p == (char_u *)&p_tags)
10865 xp->xp_backslash = XP_BS_THREE;
10866 else
10867 xp->xp_backslash = XP_BS_ONE;
10868 }
10869 }
10870
10871 /* For an option that is a list of file names, find the start of the
10872 * last file name. */
10873 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10874 {
10875 /* count number of backslashes before ' ' or ',' */
10876 if (*p == ' ' || *p == ',')
10877 {
10878 s = p;
10879 while (s > xp->xp_pattern && *(s - 1) == '\\')
10880 --s;
10881 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10882 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10883 {
10884 xp->xp_pattern = p + 1;
10885 break;
10886 }
10887 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010888
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010889#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010890 /* for 'spellsuggest' start at "file:" */
10891 if (options[opt_idx].var == (char_u *)&p_sps
10892 && STRNCMP(p, "file:", 5) == 0)
10893 {
10894 xp->xp_pattern = p + 5;
10895 break;
10896 }
10897#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010898 }
10899
10900 return;
10901}
10902
10903 int
10904ExpandSettings(xp, regmatch, num_file, file)
10905 expand_T *xp;
10906 regmatch_T *regmatch;
10907 int *num_file;
10908 char_u ***file;
10909{
10910 int num_normal = 0; /* Nr of matching non-term-code settings */
10911 int num_term = 0; /* Nr of matching terminal code settings */
10912 int opt_idx;
10913 int match;
10914 int count = 0;
10915 char_u *str;
10916 int loop;
10917 int is_term_opt;
10918 char_u name_buf[MAX_KEY_NAME_LEN];
10919 static char *(names[]) = {"all", "termcap"};
10920 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10921
10922 /* do this loop twice:
10923 * loop == 0: count the number of matching options
10924 * loop == 1: copy the matching options into allocated memory
10925 */
10926 for (loop = 0; loop <= 1; ++loop)
10927 {
10928 regmatch->rm_ic = ic;
10929 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10930 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010931 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10932 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010933 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10934 {
10935 if (loop == 0)
10936 num_normal++;
10937 else
10938 (*file)[count++] = vim_strsave((char_u *)names[match]);
10939 }
10940 }
10941 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10942 opt_idx++)
10943 {
10944 if (options[opt_idx].var == NULL)
10945 continue;
10946 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10947 && !(options[opt_idx].flags & P_BOOL))
10948 continue;
10949 is_term_opt = istermoption(&options[opt_idx]);
10950 if (is_term_opt && num_normal > 0)
10951 continue;
10952 match = FALSE;
10953 if (vim_regexec(regmatch, str, (colnr_T)0)
10954 || (options[opt_idx].shortname != NULL
10955 && vim_regexec(regmatch,
10956 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10957 match = TRUE;
10958 else if (is_term_opt)
10959 {
10960 name_buf[0] = '<';
10961 name_buf[1] = 't';
10962 name_buf[2] = '_';
10963 name_buf[3] = str[2];
10964 name_buf[4] = str[3];
10965 name_buf[5] = '>';
10966 name_buf[6] = NUL;
10967 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10968 {
10969 match = TRUE;
10970 str = name_buf;
10971 }
10972 }
10973 if (match)
10974 {
10975 if (loop == 0)
10976 {
10977 if (is_term_opt)
10978 num_term++;
10979 else
10980 num_normal++;
10981 }
10982 else
10983 (*file)[count++] = vim_strsave(str);
10984 }
10985 }
10986 /*
10987 * Check terminal key codes, these are not in the option table
10988 */
10989 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10990 {
10991 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10992 {
10993 if (!isprint(str[0]) || !isprint(str[1]))
10994 continue;
10995
10996 name_buf[0] = 't';
10997 name_buf[1] = '_';
10998 name_buf[2] = str[0];
10999 name_buf[3] = str[1];
11000 name_buf[4] = NUL;
11001
11002 match = FALSE;
11003 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11004 match = TRUE;
11005 else
11006 {
11007 name_buf[0] = '<';
11008 name_buf[1] = 't';
11009 name_buf[2] = '_';
11010 name_buf[3] = str[0];
11011 name_buf[4] = str[1];
11012 name_buf[5] = '>';
11013 name_buf[6] = NUL;
11014
11015 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11016 match = TRUE;
11017 }
11018 if (match)
11019 {
11020 if (loop == 0)
11021 num_term++;
11022 else
11023 (*file)[count++] = vim_strsave(name_buf);
11024 }
11025 }
11026
11027 /*
11028 * Check special key names.
11029 */
11030 regmatch->rm_ic = TRUE; /* ignore case here */
11031 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11032 {
11033 name_buf[0] = '<';
11034 STRCPY(name_buf + 1, str);
11035 STRCAT(name_buf, ">");
11036
11037 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11038 {
11039 if (loop == 0)
11040 num_term++;
11041 else
11042 (*file)[count++] = vim_strsave(name_buf);
11043 }
11044 }
11045 }
11046 if (loop == 0)
11047 {
11048 if (num_normal > 0)
11049 *num_file = num_normal;
11050 else if (num_term > 0)
11051 *num_file = num_term;
11052 else
11053 return OK;
11054 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11055 if (*file == NULL)
11056 {
11057 *file = (char_u **)"";
11058 return FAIL;
11059 }
11060 }
11061 }
11062 return OK;
11063}
11064
11065 int
11066ExpandOldSetting(num_file, file)
11067 int *num_file;
11068 char_u ***file;
11069{
11070 char_u *var = NULL; /* init for GCC */
11071 char_u *buf;
11072
11073 *num_file = 0;
11074 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11075 if (*file == NULL)
11076 return FAIL;
11077
11078 /*
11079 * For a terminal key code expand_option_idx is < 0.
11080 */
11081 if (expand_option_idx < 0)
11082 {
11083 var = find_termcode(expand_option_name + 2);
11084 if (var == NULL)
11085 expand_option_idx = findoption(expand_option_name);
11086 }
11087
11088 if (expand_option_idx >= 0)
11089 {
11090 /* put string of option value in NameBuff */
11091 option_value2string(&options[expand_option_idx], expand_option_flags);
11092 var = NameBuff;
11093 }
11094 else if (var == NULL)
11095 var = (char_u *)"";
11096
11097 /* A backslash is required before some characters. This is the reverse of
11098 * what happens in do_set(). */
11099 buf = vim_strsave_escaped(var, escape_chars);
11100
11101 if (buf == NULL)
11102 {
11103 vim_free(*file);
11104 *file = NULL;
11105 return FAIL;
11106 }
11107
11108#ifdef BACKSLASH_IN_FILENAME
11109 /* For MS-Windows et al. we don't double backslashes at the start and
11110 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011111 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011112 if (var[0] == '\\' && var[1] == '\\'
11113 && expand_option_idx >= 0
11114 && (options[expand_option_idx].flags & P_EXPAND)
11115 && vim_isfilec(var[2])
11116 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011117 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118#endif
11119
11120 *file[0] = buf;
11121 *num_file = 1;
11122 return OK;
11123}
11124#endif
11125
11126/*
11127 * Get the value for the numeric or string option *opp in a nice format into
11128 * NameBuff[]. Must not be called with a hidden option!
11129 */
11130 static void
11131option_value2string(opp, opt_flags)
11132 struct vimoption *opp;
11133 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11134{
11135 char_u *varp;
11136
11137 varp = get_varp_scope(opp, opt_flags);
11138
11139 if (opp->flags & P_NUM)
11140 {
11141 long wc = 0;
11142
11143 if (wc_use_keyname(varp, &wc))
11144 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11145 else if (wc != 0)
11146 STRCPY(NameBuff, transchar((int)wc));
11147 else
11148 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11149 }
11150 else /* P_STRING */
11151 {
11152 varp = *(char_u **)(varp);
11153 if (varp == NULL) /* just in case */
11154 NameBuff[0] = NUL;
11155#ifdef FEAT_CRYPT
11156 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011157 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011158 STRCPY(NameBuff, "*****");
11159#endif
11160 else if (opp->flags & P_EXPAND)
11161 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11162 /* Translate 'pastetoggle' into special key names */
11163 else if ((char_u **)opp->var == &p_pt)
11164 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11165 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011166 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011167 }
11168}
11169
11170/*
11171 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11172 * printed as a keyname.
11173 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11174 */
11175 static int
11176wc_use_keyname(varp, wcp)
11177 char_u *varp;
11178 long *wcp;
11179{
11180 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11181 {
11182 *wcp = *(long *)varp;
11183 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11184 return TRUE;
11185 }
11186 return FALSE;
11187}
11188
11189#ifdef FEAT_LANGMAP
11190/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011191 * Any character has an equivalent 'langmap' character. This is used for
11192 * keyboards that have a special language mode that sends characters above
11193 * 128 (although other characters can be translated too). The "to" field is a
11194 * Vim command character. This avoids having to switch the keyboard back to
11195 * ASCII mode when leaving Insert mode.
11196 *
11197 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11198 * commands.
11199 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11200 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11201 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011203# ifdef FEAT_MBYTE
11204/*
11205 * With multi-byte support use growarray for 'langmap' chars >= 256
11206 */
11207typedef struct
11208{
11209 int from;
11210 int to;
11211} langmap_entry_T;
11212
11213static garray_T langmap_mapga;
11214static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011215
11216/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011217 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11218 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011219 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011220 static void
11221langmap_set_entry(from, to)
11222 int from;
11223 int to;
11224{
11225 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011226 int a = 0;
11227 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011228
11229 /* Do a binary search for an existing entry. */
11230 while (a != b)
11231 {
11232 int i = (a + b) / 2;
11233 int d = entries[i].from - from;
11234
11235 if (d == 0)
11236 {
11237 entries[i].to = to;
11238 return;
11239 }
11240 if (d < 0)
11241 a = i + 1;
11242 else
11243 b = i;
11244 }
11245
11246 if (ga_grow(&langmap_mapga, 1) != OK)
11247 return; /* out of memory */
11248
11249 /* insert new entry at position "a" */
11250 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11251 mch_memmove(entries + 1, entries,
11252 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11253 ++langmap_mapga.ga_len;
11254 entries[0].from = from;
11255 entries[0].to = to;
11256}
11257
11258/*
11259 * Apply 'langmap' to multi-byte character "c" and return the result.
11260 */
11261 int
11262langmap_adjust_mb(c)
11263 int c;
11264{
11265 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11266 int a = 0;
11267 int b = langmap_mapga.ga_len;
11268
11269 while (a != b)
11270 {
11271 int i = (a + b) / 2;
11272 int d = entries[i].from - c;
11273
11274 if (d == 0)
11275 return entries[i].to; /* found matching entry */
11276 if (d < 0)
11277 a = i + 1;
11278 else
11279 b = i;
11280 }
11281 return c; /* no entry found, return "c" unmodified */
11282}
11283# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011284
11285 static void
11286langmap_init()
11287{
11288 int i;
11289
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011290 for (i = 0; i < 256; i++)
11291 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11292# ifdef FEAT_MBYTE
11293 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11294# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011295}
11296
11297/*
11298 * Called when langmap option is set; the language map can be
11299 * changed at any time!
11300 */
11301 static void
11302langmap_set()
11303{
11304 char_u *p;
11305 char_u *p2;
11306 int from, to;
11307
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011308#ifdef FEAT_MBYTE
11309 ga_clear(&langmap_mapga); /* clear the previous map first */
11310#endif
11311 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011312
11313 for (p = p_langmap; p[0] != NUL; )
11314 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011315 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11316 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011317 {
11318 if (p2[0] == '\\' && p2[1] != NUL)
11319 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011320 }
11321 if (p2[0] == ';')
11322 ++p2; /* abcd;ABCD form, p2 points to A */
11323 else
11324 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11325 while (p[0])
11326 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011327 if (p[0] == ',')
11328 {
11329 ++p;
11330 break;
11331 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332 if (p[0] == '\\' && p[1] != NUL)
11333 ++p;
11334#ifdef FEAT_MBYTE
11335 from = (*mb_ptr2char)(p);
11336#else
11337 from = p[0];
11338#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011339 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011340 if (p2 == NULL)
11341 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011342 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011343 if (p[0] != ',')
11344 {
11345 if (p[0] == '\\')
11346 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011347#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011348 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011350 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011351#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011352 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011353 }
11354 else
11355 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011356 if (p2[0] != ',')
11357 {
11358 if (p2[0] == '\\')
11359 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011360#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011361 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011362#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011363 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011364#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011365 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366 }
11367 if (to == NUL)
11368 {
11369 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11370 transchar(from));
11371 return;
11372 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011373
11374#ifdef FEAT_MBYTE
11375 if (from >= 256)
11376 langmap_set_entry(from, to);
11377 else
11378#endif
11379 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011380
11381 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011382 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011383 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011384 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011385 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011386 if (*p == ';')
11387 {
11388 p = p2;
11389 if (p[0] != NUL)
11390 {
11391 if (p[0] != ',')
11392 {
11393 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11394 return;
11395 }
11396 ++p;
11397 }
11398 break;
11399 }
11400 }
11401 }
11402 }
11403}
11404#endif
11405
11406/*
11407 * Return TRUE if format option 'x' is in effect.
11408 * Take care of no formatting when 'paste' is set.
11409 */
11410 int
11411has_format_option(x)
11412 int x;
11413{
11414 if (p_paste)
11415 return FALSE;
11416 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11417}
11418
11419/*
11420 * Return TRUE if "x" is present in 'shortmess' option, or
11421 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11422 */
11423 int
11424shortmess(x)
11425 int x;
11426{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011427 return p_shm != NULL &&
11428 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011429 || (vim_strchr(p_shm, 'a') != NULL
11430 && vim_strchr((char_u *)SHM_A, x) != NULL));
11431}
11432
11433/*
11434 * paste_option_changed() - Called after p_paste was set or reset.
11435 */
11436 static void
11437paste_option_changed()
11438{
11439 static int old_p_paste = FALSE;
11440 static int save_sm = 0;
11441#ifdef FEAT_CMDL_INFO
11442 static int save_ru = 0;
11443#endif
11444#ifdef FEAT_RIGHTLEFT
11445 static int save_ri = 0;
11446 static int save_hkmap = 0;
11447#endif
11448 buf_T *buf;
11449
11450 if (p_paste)
11451 {
11452 /*
11453 * Paste switched from off to on.
11454 * Save the current values, so they can be restored later.
11455 */
11456 if (!old_p_paste)
11457 {
11458 /* save options for each buffer */
11459 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11460 {
11461 buf->b_p_tw_nopaste = buf->b_p_tw;
11462 buf->b_p_wm_nopaste = buf->b_p_wm;
11463 buf->b_p_sts_nopaste = buf->b_p_sts;
11464 buf->b_p_ai_nopaste = buf->b_p_ai;
11465 }
11466
11467 /* save global options */
11468 save_sm = p_sm;
11469#ifdef FEAT_CMDL_INFO
11470 save_ru = p_ru;
11471#endif
11472#ifdef FEAT_RIGHTLEFT
11473 save_ri = p_ri;
11474 save_hkmap = p_hkmap;
11475#endif
11476 /* save global values for local buffer options */
11477 p_tw_nopaste = p_tw;
11478 p_wm_nopaste = p_wm;
11479 p_sts_nopaste = p_sts;
11480 p_ai_nopaste = p_ai;
11481 }
11482
11483 /*
11484 * Always set the option values, also when 'paste' is set when it is
11485 * already on.
11486 */
11487 /* set options for each buffer */
11488 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11489 {
11490 buf->b_p_tw = 0; /* textwidth is 0 */
11491 buf->b_p_wm = 0; /* wrapmargin is 0 */
11492 buf->b_p_sts = 0; /* softtabstop is 0 */
11493 buf->b_p_ai = 0; /* no auto-indent */
11494 }
11495
11496 /* set global options */
11497 p_sm = 0; /* no showmatch */
11498#ifdef FEAT_CMDL_INFO
11499# ifdef FEAT_WINDOWS
11500 if (p_ru)
11501 status_redraw_all(); /* redraw to remove the ruler */
11502# endif
11503 p_ru = 0; /* no ruler */
11504#endif
11505#ifdef FEAT_RIGHTLEFT
11506 p_ri = 0; /* no reverse insert */
11507 p_hkmap = 0; /* no Hebrew keyboard */
11508#endif
11509 /* set global values for local buffer options */
11510 p_tw = 0;
11511 p_wm = 0;
11512 p_sts = 0;
11513 p_ai = 0;
11514 }
11515
11516 /*
11517 * Paste switched from on to off: Restore saved values.
11518 */
11519 else if (old_p_paste)
11520 {
11521 /* restore options for each buffer */
11522 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11523 {
11524 buf->b_p_tw = buf->b_p_tw_nopaste;
11525 buf->b_p_wm = buf->b_p_wm_nopaste;
11526 buf->b_p_sts = buf->b_p_sts_nopaste;
11527 buf->b_p_ai = buf->b_p_ai_nopaste;
11528 }
11529
11530 /* restore global options */
11531 p_sm = save_sm;
11532#ifdef FEAT_CMDL_INFO
11533# ifdef FEAT_WINDOWS
11534 if (p_ru != save_ru)
11535 status_redraw_all(); /* redraw to draw the ruler */
11536# endif
11537 p_ru = save_ru;
11538#endif
11539#ifdef FEAT_RIGHTLEFT
11540 p_ri = save_ri;
11541 p_hkmap = save_hkmap;
11542#endif
11543 /* set global values for local buffer options */
11544 p_tw = p_tw_nopaste;
11545 p_wm = p_wm_nopaste;
11546 p_sts = p_sts_nopaste;
11547 p_ai = p_ai_nopaste;
11548 }
11549
11550 old_p_paste = p_paste;
11551}
11552
11553/*
11554 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11555 *
11556 * Reset 'compatible' and set the values for options that didn't get set yet
11557 * to the Vim defaults.
11558 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011559 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011560 */
11561 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011562vimrc_found(fname, envname)
11563 char_u *fname;
11564 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011565{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011566 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011567 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011568 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011569
11570 if (!option_was_set((char_u *)"cp"))
11571 {
11572 p_cp = FALSE;
11573 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11574 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11575 set_option_default(opt_idx, OPT_FREE, FALSE);
11576 didset_options();
11577 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011578
11579 if (fname != NULL)
11580 {
11581 p = vim_getenv(envname, &dofree);
11582 if (p == NULL)
11583 {
11584 /* Set $MYVIMRC to the first vimrc file found. */
11585 p = FullName_save(fname, FALSE);
11586 if (p != NULL)
11587 {
11588 vim_setenv(envname, p);
11589 vim_free(p);
11590 }
11591 }
11592 else if (dofree)
11593 vim_free(p);
11594 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011595}
11596
11597/*
11598 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11599 */
11600 void
11601change_compatible(on)
11602 int on;
11603{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011604 int opt_idx;
11605
Bram Moolenaar071d4272004-06-13 20:20:40 +000011606 if (p_cp != on)
11607 {
11608 p_cp = on;
11609 compatible_set();
11610 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011611 opt_idx = findoption((char_u *)"cp");
11612 if (opt_idx >= 0)
11613 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011614}
11615
11616/*
11617 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011618 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011619 */
11620 int
11621option_was_set(name)
11622 char_u *name;
11623{
11624 int idx;
11625
11626 idx = findoption(name);
11627 if (idx < 0) /* unknown option */
11628 return FALSE;
11629 if (options[idx].flags & P_WAS_SET)
11630 return TRUE;
11631 return FALSE;
11632}
11633
11634/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011635 * Reset the flag indicating option "name" was set.
11636 */
11637 void
11638reset_option_was_set(name)
11639 char_u *name;
11640{
11641 int idx = findoption(name);
11642
11643 if (idx >= 0)
11644 options[idx].flags &= ~P_WAS_SET;
11645}
11646
11647/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011648 * compatible_set() - Called when 'compatible' has been set or unset.
11649 *
11650 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11651 * flag) to a Vi compatible value.
11652 * When 'compatible' is unset: Set all options that have a different default
11653 * for Vim (without the P_VI_DEF flag) to that default.
11654 */
11655 static void
11656compatible_set()
11657{
11658 int opt_idx;
11659
11660 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11661 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11662 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11663 set_option_default(opt_idx, OPT_FREE, p_cp);
11664 didset_options();
11665}
11666
11667#ifdef FEAT_LINEBREAK
11668
11669# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11670 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011671 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011672# endif
11673
11674/*
11675 * fill_breakat_flags() -- called when 'breakat' changes value.
11676 */
11677 static void
11678fill_breakat_flags()
11679{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011680 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011681 int i;
11682
11683 for (i = 0; i < 256; i++)
11684 breakat_flags[i] = FALSE;
11685
11686 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011687 for (p = p_breakat; *p; p++)
11688 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011689}
11690
11691# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011692 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011693# endif
11694
11695#endif
11696
11697/*
11698 * Check an option that can be a range of string values.
11699 *
11700 * Return OK for correct value, FAIL otherwise.
11701 * Empty is always OK.
11702 */
11703 static int
11704check_opt_strings(val, values, list)
11705 char_u *val;
11706 char **values;
11707 int list; /* when TRUE: accept a list of values */
11708{
11709 return opt_strings_flags(val, values, NULL, list);
11710}
11711
11712/*
11713 * Handle an option that can be a range of string values.
11714 * Set a flag in "*flagp" for each string present.
11715 *
11716 * Return OK for correct value, FAIL otherwise.
11717 * Empty is always OK.
11718 */
11719 static int
11720opt_strings_flags(val, values, flagp, list)
11721 char_u *val; /* new value */
11722 char **values; /* array of valid string values */
11723 unsigned *flagp;
11724 int list; /* when TRUE: accept a list of values */
11725{
11726 int i;
11727 int len;
11728 unsigned new_flags = 0;
11729
11730 while (*val)
11731 {
11732 for (i = 0; ; ++i)
11733 {
11734 if (values[i] == NULL) /* val not found in values[] */
11735 return FAIL;
11736
11737 len = (int)STRLEN(values[i]);
11738 if (STRNCMP(values[i], val, len) == 0
11739 && ((list && val[len] == ',') || val[len] == NUL))
11740 {
11741 val += len + (val[len] == ',');
11742 new_flags |= (1 << i);
11743 break; /* check next item in val list */
11744 }
11745 }
11746 }
11747 if (flagp != NULL)
11748 *flagp = new_flags;
11749
11750 return OK;
11751}
11752
11753/*
11754 * Read the 'wildmode' option, fill wim_flags[].
11755 */
11756 static int
11757check_opt_wim()
11758{
11759 char_u new_wim_flags[4];
11760 char_u *p;
11761 int i;
11762 int idx = 0;
11763
11764 for (i = 0; i < 4; ++i)
11765 new_wim_flags[i] = 0;
11766
11767 for (p = p_wim; *p; ++p)
11768 {
11769 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11770 ;
11771 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11772 return FAIL;
11773 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11774 new_wim_flags[idx] |= WIM_LONGEST;
11775 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11776 new_wim_flags[idx] |= WIM_FULL;
11777 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11778 new_wim_flags[idx] |= WIM_LIST;
11779 else
11780 return FAIL;
11781 p += i;
11782 if (*p == NUL)
11783 break;
11784 if (*p == ',')
11785 {
11786 if (idx == 3)
11787 return FAIL;
11788 ++idx;
11789 }
11790 }
11791
11792 /* fill remaining entries with last flag */
11793 while (idx < 3)
11794 {
11795 new_wim_flags[idx + 1] = new_wim_flags[idx];
11796 ++idx;
11797 }
11798
11799 /* only when there are no errors, wim_flags[] is changed */
11800 for (i = 0; i < 4; ++i)
11801 wim_flags[i] = new_wim_flags[i];
11802 return OK;
11803}
11804
11805/*
11806 * Check if backspacing over something is allowed.
11807 */
11808 int
11809can_bs(what)
11810 int what; /* BS_INDENT, BS_EOL or BS_START */
11811{
11812 switch (*p_bs)
11813 {
11814 case '2': return TRUE;
11815 case '1': return (what != BS_START);
11816 case '0': return FALSE;
11817 }
11818 return vim_strchr(p_bs, what) != NULL;
11819}
11820
11821/*
11822 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11823 * the file must be considered changed when the value is different.
11824 */
11825 void
11826save_file_ff(buf)
11827 buf_T *buf;
11828{
11829 buf->b_start_ffc = *buf->b_p_ff;
11830 buf->b_start_eol = buf->b_p_eol;
11831#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011832 buf->b_start_bomb = buf->b_p_bomb;
11833
Bram Moolenaar071d4272004-06-13 20:20:40 +000011834 /* Only use free/alloc when necessary, they take time. */
11835 if (buf->b_start_fenc == NULL
11836 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11837 {
11838 vim_free(buf->b_start_fenc);
11839 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11840 }
11841#endif
11842}
11843
11844/*
11845 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11846 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011847 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11848 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011849 * When "ignore_empty" is true don't consider a new, empty buffer to be
11850 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011851 */
11852 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011853file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011854 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011855 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011857 /* In a buffer that was never loaded the options are not valid. */
11858 if (buf->b_flags & BF_NEVERLOADED)
11859 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011860 if (ignore_empty
11861 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011862 && buf->b_ml.ml_line_count == 1
11863 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11864 return FALSE;
11865 if (buf->b_start_ffc != *buf->b_p_ff)
11866 return TRUE;
11867 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11868 return TRUE;
11869#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011870 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11871 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011872 if (buf->b_start_fenc == NULL)
11873 return (*buf->b_p_fenc != NUL);
11874 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11875#else
11876 return FALSE;
11877#endif
11878}
11879
11880/*
11881 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11882 */
11883 int
11884check_ff_value(p)
11885 char_u *p;
11886{
11887 return check_opt_strings(p, p_ff_values, FALSE);
11888}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011889
11890/*
11891 * Return the effective shiftwidth value for current buffer, using the
11892 * 'tabstop' value when 'shiftwidth' is zero.
11893 */
11894 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011895get_sw_value(buf)
11896 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011897{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011898 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011899}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011900
11901/*
11902 * Return the effective softtabstop value for the current buffer, using the
11903 * 'tabstop' value when 'softtabstop' is negative.
11904 */
11905 long
11906get_sts_value()
11907{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011908 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011909}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011910
11911/*
11912 * Check matchpairs option for "*initc".
11913 * If there is a match set "*initc" to the matching character and "*findc" to
11914 * the opposite character. Set "*backwards" to the direction.
11915 * When "switchit" is TRUE swap the direction.
11916 */
11917 void
11918find_mps_values(initc, findc, backwards, switchit)
11919 int *initc;
11920 int *findc;
11921 int *backwards;
11922 int switchit;
11923{
11924 char_u *ptr;
11925
11926 ptr = curbuf->b_p_mps;
11927 while (*ptr != NUL)
11928 {
11929#ifdef FEAT_MBYTE
11930 if (has_mbyte)
11931 {
11932 char_u *prev;
11933
11934 if (mb_ptr2char(ptr) == *initc)
11935 {
11936 if (switchit)
11937 {
11938 *findc = *initc;
11939 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11940 *backwards = TRUE;
11941 }
11942 else
11943 {
11944 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11945 *backwards = FALSE;
11946 }
11947 return;
11948 }
11949 prev = ptr;
11950 ptr += mb_ptr2len(ptr) + 1;
11951 if (mb_ptr2char(ptr) == *initc)
11952 {
11953 if (switchit)
11954 {
11955 *findc = *initc;
11956 *initc = mb_ptr2char(prev);
11957 *backwards = FALSE;
11958 }
11959 else
11960 {
11961 *findc = mb_ptr2char(prev);
11962 *backwards = TRUE;
11963 }
11964 return;
11965 }
11966 ptr += mb_ptr2len(ptr);
11967 }
11968 else
11969#endif
11970 {
11971 if (*ptr == *initc)
11972 {
11973 if (switchit)
11974 {
11975 *backwards = TRUE;
11976 *findc = *initc;
11977 *initc = ptr[2];
11978 }
11979 else
11980 {
11981 *backwards = FALSE;
11982 *findc = ptr[2];
11983 }
11984 return;
11985 }
11986 ptr += 2;
11987 if (*ptr == *initc)
11988 {
11989 if (switchit)
11990 {
11991 *backwards = FALSE;
11992 *findc = *initc;
11993 *initc = ptr[-2];
11994 }
11995 else
11996 {
11997 *backwards = TRUE;
11998 *findc = ptr[-2];
11999 }
12000 return;
12001 }
12002 ++ptr;
12003 }
12004 if (*ptr == ',')
12005 ++ptr;
12006 }
12007}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012008
12009#if defined(FEAT_LINEBREAK) || defined(PROTO)
12010/*
12011 * This is called when 'breakindentopt' is changed and when a window is
12012 * initialized.
12013 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012014 static int
12015briopt_check(wp)
12016 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012017{
12018 char_u *p;
12019 int bri_shift = 0;
12020 long bri_min = 20;
12021 int bri_sbr = FALSE;
12022
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012023 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012024 while (*p != NUL)
12025 {
12026 if (STRNCMP(p, "shift:", 6) == 0
12027 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12028 {
12029 p += 6;
12030 bri_shift = getdigits(&p);
12031 }
12032 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12033 {
12034 p += 4;
12035 bri_min = getdigits(&p);
12036 }
12037 else if (STRNCMP(p, "sbr", 3) == 0)
12038 {
12039 p += 3;
12040 bri_sbr = TRUE;
12041 }
12042 if (*p != ',' && *p != NUL)
12043 return FAIL;
12044 if (*p == ',')
12045 ++p;
12046 }
12047
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012048 wp->w_p_brishift = bri_shift;
12049 wp->w_p_brimin = bri_min;
12050 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012051
12052 return OK;
12053}
12054#endif