blob: 05d8869eaa495efb71fb59125f5ffc57d03588a8 [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 Moolenaar071d4272004-06-13 20:20:40 +00002127 {"report", NULL, P_NUM|P_VI_DEF,
2128 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002129 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2131#ifdef WIN3264
2132 (char_u *)&p_rs, PV_NONE,
2133#else
2134 (char_u *)NULL, PV_NONE,
2135#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002136 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2138#ifdef FEAT_RIGHTLEFT
2139 (char_u *)&p_ri, PV_NONE,
2140#else
2141 (char_u *)NULL, PV_NONE,
2142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002143 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2145#ifdef FEAT_RIGHTLEFT
2146 (char_u *)VAR_WIN, PV_RL,
2147#else
2148 (char_u *)NULL, PV_NONE,
2149#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002150 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2152#ifdef FEAT_RIGHTLEFT
2153 (char_u *)VAR_WIN, PV_RLC,
2154 {(char_u *)"search", (char_u *)NULL}
2155#else
2156 (char_u *)NULL, PV_NONE,
2157 {(char_u *)NULL, (char_u *)0L}
2158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002159 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2161#ifdef FEAT_CMDL_INFO
2162 (char_u *)&p_ru, PV_NONE,
2163#else
2164 (char_u *)NULL, PV_NONE,
2165#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002166 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002167 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2168#ifdef FEAT_STL_OPT
2169 (char_u *)&p_ruf, PV_NONE,
2170#else
2171 (char_u *)NULL, PV_NONE,
2172#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002173 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2175 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002176 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2177 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2179 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002180 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2182#ifdef FEAT_SCROLLBIND
2183 (char_u *)VAR_WIN, PV_SCBIND,
2184#else
2185 (char_u *)NULL, PV_NONE,
2186#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002187 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2189 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002190 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2192 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002194 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2195#ifdef FEAT_SCROLLBIND
2196 (char_u *)&p_sbo, PV_NONE,
2197 {(char_u *)"ver,jump", (char_u *)0L}
2198#else
2199 (char_u *)NULL, PV_NONE,
2200 {(char_u *)0L, (char_u *)0L}
2201#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002202 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203 {"sections", "sect", P_STRING|P_VI_DEF,
2204 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002205 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2206 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2208 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002209 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002210 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002212 {(char_u *)"inclusive", (char_u *)0L}
2213 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002214 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002216 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2218#ifdef FEAT_SESSION
2219 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002220 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002221 (char_u *)0L}
2222#else
2223 (char_u *)NULL, PV_NONE,
2224 {(char_u *)0L, (char_u *)0L}
2225#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002226 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002227 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2228 (char_u *)&p_sh, PV_NONE,
2229 {
2230#ifdef VMS
2231 (char_u *)"-",
2232#else
2233# if defined(MSDOS)
2234 (char_u *)"command",
2235# else
2236# if defined(WIN16)
2237 (char_u *)"command.com",
2238# else
2239# if defined(WIN3264)
2240 (char_u *)"", /* set in set_init_1() */
2241# else
2242# if defined(OS2)
2243 (char_u *)"cmd.exe",
2244# else
2245# if defined(ARCHIE)
2246 (char_u *)"gos",
2247# else
2248 (char_u *)"sh",
2249# endif
2250# endif
2251# endif
2252# endif
2253# endif
2254#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002255 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002256 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2257 (char_u *)&p_shcf, PV_NONE,
2258 {
2259#if defined(MSDOS) || defined(MSWIN)
2260 (char_u *)"/c",
2261#else
2262# if defined(OS2)
2263 (char_u *)"/c",
2264# else
2265 (char_u *)"-c",
2266# endif
2267#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2270#ifdef FEAT_QUICKFIX
2271 (char_u *)&p_sp, PV_NONE,
2272 {
2273#if defined(UNIX) || defined(OS2)
2274# ifdef ARCHIE
2275 (char_u *)"2>",
2276# else
2277 (char_u *)"| tee",
2278# endif
2279#else
2280 (char_u *)">",
2281#endif
2282 (char_u *)0L}
2283#else
2284 (char_u *)NULL, PV_NONE,
2285 {(char_u *)0L, (char_u *)0L}
2286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2289 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2292 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002293 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2295#ifdef BACKSLASH_IN_FILENAME
2296 (char_u *)&p_ssl, PV_NONE,
2297#else
2298 (char_u *)NULL, PV_NONE,
2299#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002300 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002301 {"shelltemp", "stmp", P_BOOL,
2302 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002303 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304 {"shelltype", "st", P_NUM|P_VI_DEF,
2305#ifdef AMIGA
2306 (char_u *)&p_st, PV_NONE,
2307#else
2308 (char_u *)NULL, PV_NONE,
2309#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2312 (char_u *)&p_sxq, PV_NONE,
2313 {
2314#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2315 (char_u *)"\"",
2316#else
2317 (char_u *)"",
2318#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002319 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002320 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2321 (char_u *)&p_sxe, PV_NONE,
2322 {
2323#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2324 (char_u *)"\"&|<>()@^",
2325#else
2326 (char_u *)"",
2327#endif
2328 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2330 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2333 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002334 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2336 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)"", (char_u *)"filnxtToO"}
2338 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 {"shortname", "sn", P_BOOL|P_VI_DEF,
2340#ifdef SHORT_FNAME
2341 (char_u *)NULL, PV_NONE,
2342#else
2343 (char_u *)&p_sn, PV_SN,
2344#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002345 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2347#ifdef FEAT_LINEBREAK
2348 (char_u *)&p_sbr, PV_NONE,
2349#else
2350 (char_u *)NULL, PV_NONE,
2351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 {"showcmd", "sc", P_BOOL|P_VIM,
2354#ifdef FEAT_CMDL_INFO
2355 (char_u *)&p_sc, PV_NONE,
2356#else
2357 (char_u *)NULL, PV_NONE,
2358#endif
2359 {(char_u *)FALSE,
2360#ifdef UNIX
2361 (char_u *)FALSE
2362#else
2363 (char_u *)TRUE
2364#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002365 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2367 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2370 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"showmode", "smd", P_BOOL|P_VIM,
2373 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002375 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2376#ifdef FEAT_WINDOWS
2377 (char_u *)&p_stal, PV_NONE,
2378#else
2379 (char_u *)NULL, PV_NONE,
2380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2383 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2386 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2389 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2392 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2395#ifdef FEAT_SMARTINDENT
2396 (char_u *)&p_si, PV_SI,
2397#else
2398 (char_u *)NULL, PV_NONE,
2399#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2402 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2405 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2408 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002410 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002411#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002412 (char_u *)VAR_WIN, PV_SPELL,
2413#else
2414 (char_u *)NULL, PV_NONE,
2415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002417 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002418#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002419 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002420 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002421#else
2422 (char_u *)NULL, PV_NONE,
2423 {(char_u *)0L, (char_u *)0L}
2424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002426 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002427#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002428 (char_u *)&p_spf, PV_SPF,
2429 {(char_u *)"", (char_u *)0L}
2430#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 Moolenaar24bbcfe2005-06-28 23:32:02 +00002435 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002436#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002437 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002438 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002439#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 Moolenaar28e4c8d2006-05-09 16:15:42 +00002444 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002445#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002446 (char_u *)&p_sps, PV_NONE,
2447 {(char_u *)"best", (char_u *)0L}
2448#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 Moolenaar071d4272004-06-13 20:20:40 +00002453 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2454#ifdef FEAT_WINDOWS
2455 (char_u *)&p_sb, PV_NONE,
2456#else
2457 (char_u *)NULL, PV_NONE,
2458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 {"splitright", "spr", P_BOOL|P_VI_DEF,
2461#ifdef FEAT_VERTSPLIT
2462 (char_u *)&p_spr, PV_NONE,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2468 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2471#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002472 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473#else
2474 (char_u *)NULL, PV_NONE,
2475#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2478 (char_u *)&p_su, PV_NONE,
2479 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002480 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002482#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 (char_u *)&p_sua, PV_SUA,
2484 {(char_u *)"", (char_u *)0L}
2485#else
2486 (char_u *)NULL, PV_NONE,
2487 {(char_u *)0L, (char_u *)0L}
2488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2491 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 {"swapsync", "sws", P_STRING|P_VI_DEF,
2494 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002495 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2497 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002499 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2500#ifdef FEAT_SYN_HL
2501 (char_u *)&p_smc, PV_SMC,
2502 {(char_u *)3000L, (char_u *)0L}
2503#else
2504 (char_u *)NULL, PV_NONE,
2505 {(char_u *)0L, (char_u *)0L}
2506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002508 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509#ifdef FEAT_SYN_HL
2510 (char_u *)&p_syn, PV_SYN,
2511 {(char_u *)"", (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 Moolenaarfaa959a2006-02-20 21:37:40 +00002517 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2518#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002519 (char_u *)&p_tal, PV_NONE,
2520#else
2521 (char_u *)NULL, PV_NONE,
2522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002524 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2525#ifdef FEAT_WINDOWS
2526 (char_u *)&p_tpm, PV_NONE,
2527#else
2528 (char_u *)NULL, PV_NONE,
2529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002530 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2532 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2535 (char_u *)&p_tbs, PV_NONE,
2536#ifdef VMS /* binary searching doesn't appear to work on VMS */
2537 {(char_u *)0L, (char_u *)0L}
2538#else
2539 {(char_u *)TRUE, (char_u *)0L}
2540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"taglength", "tl", P_NUM|P_VI_DEF,
2543 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002545 {"tagrelative", "tr", P_BOOL|P_VIM,
2546 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002549 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550 {
2551#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2552 (char_u *)"./tags,./TAGS,tags,TAGS",
2553#else
2554 (char_u *)"./tags,tags",
2555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2558 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2561 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2564#ifdef FEAT_ARABIC
2565 (char_u *)&p_tbidi, PV_NONE,
2566#else
2567 (char_u *)NULL, PV_NONE,
2568#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2571#ifdef FEAT_MBYTE
2572 (char_u *)&p_tenc, PV_NONE,
2573 {(char_u *)"", (char_u *)0L}
2574#else
2575 (char_u *)NULL, PV_NONE,
2576 {(char_u *)0L, (char_u *)0L}
2577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"terse", NULL, P_BOOL|P_VI_DEF,
2580 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"textauto", "ta", P_BOOL|P_VIM,
2583 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2585 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2587 (char_u *)&p_tx, PV_TX,
2588 {
2589#ifdef USE_CRNL
2590 (char_u *)TRUE,
2591#else
2592 (char_u *)FALSE,
2593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002595 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002597 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2599#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002600 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601#else
2602 (char_u *)NULL, PV_NONE,
2603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002604 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2606 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"timeout", "to", P_BOOL|P_VI_DEF,
2609 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002610 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2612 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 {"title", NULL, P_BOOL|P_VI_DEF,
2615#ifdef FEAT_TITLE
2616 (char_u *)&p_title, PV_NONE,
2617#else
2618 (char_u *)NULL, PV_NONE,
2619#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {"titlelen", NULL, P_NUM|P_VI_DEF,
2622#ifdef FEAT_TITLE
2623 (char_u *)&p_titlelen, PV_NONE,
2624#else
2625 (char_u *)NULL, PV_NONE,
2626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002628 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629#ifdef FEAT_TITLE
2630 (char_u *)&p_titleold, PV_NONE,
2631 {(char_u *)N_("Thanks for flying Vim"),
2632 (char_u *)0L}
2633#else
2634 (char_u *)NULL, PV_NONE,
2635 {(char_u *)0L, (char_u *)0L}
2636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 {"titlestring", NULL, P_STRING|P_VI_DEF,
2639#ifdef FEAT_TITLE
2640 (char_u *)&p_titlestring, PV_NONE,
2641#else
2642 (char_u *)NULL, PV_NONE,
2643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2646 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2647 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 {(char_u *)"icons,tooltips", (char_u *)0L}
2649 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002651#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2653 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655#endif
2656 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2657 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2660 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2663 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2666 (char_u *)&p_tf, 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 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2669#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2670 (char_u *)&p_ttym, PV_NONE,
2671#else
2672 (char_u *)NULL, PV_NONE,
2673#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002674 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2676 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2679 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002681 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2682#ifdef FEAT_PERSISTENT_UNDO
2683 (char_u *)&p_udir, PV_NONE,
2684 {(char_u *)".", (char_u *)0L}
2685#else
2686 (char_u *)NULL, PV_NONE,
2687 {(char_u *)0L, (char_u *)0L}
2688#endif
2689 SCRIPTID_INIT},
2690 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2691#ifdef FEAT_PERSISTENT_UNDO
2692 (char_u *)&p_udf, PV_UDF,
2693#else
2694 (char_u *)NULL, PV_NONE,
2695#endif
2696 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002698 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {
2700#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2701 (char_u *)1000L,
2702#else
2703 (char_u *)100L,
2704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002705 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002706 {"undoreload", "ur", P_NUM|P_VI_DEF,
2707 (char_u *)&p_ur, PV_NONE,
2708 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"updatecount", "uc", P_NUM|P_VI_DEF,
2710 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"updatetime", "ut", P_NUM|P_VI_DEF,
2713 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"verbose", "vbs", P_NUM|P_VI_DEF,
2716 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002718 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2719 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2722#ifdef FEAT_SESSION
2723 (char_u *)&p_vdir, PV_NONE,
2724 {(char_u *)DFLT_VDIR, (char_u *)0L}
2725#else
2726 (char_u *)NULL, PV_NONE,
2727 {(char_u *)0L, (char_u *)0L}
2728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2731#ifdef FEAT_SESSION
2732 (char_u *)&p_vop, PV_NONE,
2733 {(char_u *)"folds,options,cursor", (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 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2740#ifdef FEAT_VIMINFO
2741 (char_u *)&p_viminfo, PV_NONE,
2742#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002743 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002744#else
2745# ifdef AMIGA
2746 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002747 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002749 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750# endif
2751#endif
2752#else
2753 (char_u *)NULL, PV_NONE,
2754 {(char_u *)0L, (char_u *)0L}
2755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002756 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002757 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758#ifdef FEAT_VIRTUALEDIT
2759 (char_u *)&p_ve, PV_NONE,
2760 {(char_u *)"", (char_u *)""}
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 Moolenaar071d4272004-06-13 20:20:40 +00002766 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2767 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002768 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 {"w300", NULL, P_NUM|P_VI_DEF,
2770 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002771 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"w1200", NULL, P_NUM|P_VI_DEF,
2773 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002774 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"w9600", NULL, P_NUM|P_VI_DEF,
2776 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"warn", NULL, P_BOOL|P_VI_DEF,
2779 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002780 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2782 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2785 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"wildchar", "wc", P_NUM|P_VIM,
2788 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002789 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2790 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002791 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002793 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2795#ifdef FEAT_WILDIGN
2796 (char_u *)&p_wig, PV_NONE,
2797#else
2798 (char_u *)NULL, PV_NONE,
2799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002801 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2802 (char_u *)&p_wic, PV_NONE,
2803 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2805#ifdef FEAT_WILDMENU
2806 (char_u *)&p_wmnu, PV_NONE,
2807#else
2808 (char_u *)NULL, PV_NONE,
2809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2812 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002813 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002814 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2815#ifdef FEAT_CMDL_COMPL
2816 (char_u *)&p_wop, PV_NONE,
2817 {(char_u *)"", (char_u *)0L}
2818#else
2819 (char_u *)NULL, PV_NONE,
2820 {(char_u *)NULL, (char_u *)0L}
2821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2824#ifdef FEAT_WAK
2825 (char_u *)&p_wak, PV_NONE,
2826 {(char_u *)"menu", (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 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002833 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"winheight", "wh", P_NUM|P_VI_DEF,
2836#ifdef FEAT_WINDOWS
2837 (char_u *)&p_wh, PV_NONE,
2838#else
2839 (char_u *)NULL, PV_NONE,
2840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002841 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002843#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 (char_u *)VAR_WIN, PV_WFH,
2845#else
2846 (char_u *)NULL, PV_NONE,
2847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002848 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002849 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2850#ifdef FEAT_VERTSPLIT
2851 (char_u *)VAR_WIN, PV_WFW,
2852#else
2853 (char_u *)NULL, PV_NONE,
2854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2857#ifdef FEAT_WINDOWS
2858 (char_u *)&p_wmh, PV_NONE,
2859#else
2860 (char_u *)NULL, PV_NONE,
2861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2864#ifdef FEAT_VERTSPLIT
2865 (char_u *)&p_wmw, PV_NONE,
2866#else
2867 (char_u *)NULL, PV_NONE,
2868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2871#ifdef FEAT_VERTSPLIT
2872 (char_u *)&p_wiw, PV_NONE,
2873#else
2874 (char_u *)NULL, PV_NONE,
2875#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2878 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2881 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002882 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2884 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002885 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 {"write", NULL, P_BOOL|P_VI_DEF,
2887 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"writeany", "wa", P_BOOL|P_VI_DEF,
2890 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2893 (char_u *)&p_wb, PV_NONE,
2894 {
2895#ifdef FEAT_WRITEBACKUP
2896 (char_u *)TRUE,
2897#else
2898 (char_u *)FALSE,
2899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"writedelay", "wd", P_NUM|P_VI_DEF,
2902 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002903 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002904
2905/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002906#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002908 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909
2910 p_term("t_AB", T_CAB)
2911 p_term("t_AF", T_CAF)
2912 p_term("t_AL", T_CAL)
2913 p_term("t_al", T_AL)
2914 p_term("t_bc", T_BC)
2915 p_term("t_cd", T_CD)
2916 p_term("t_ce", T_CE)
2917 p_term("t_cl", T_CL)
2918 p_term("t_cm", T_CM)
2919 p_term("t_Co", T_CCO)
2920 p_term("t_CS", T_CCS)
2921 p_term("t_cs", T_CS)
2922#ifdef FEAT_VERTSPLIT
2923 p_term("t_CV", T_CSV)
2924#endif
2925 p_term("t_ut", T_UT)
2926 p_term("t_da", T_DA)
2927 p_term("t_db", T_DB)
2928 p_term("t_DL", T_CDL)
2929 p_term("t_dl", T_DL)
2930 p_term("t_fs", T_FS)
2931 p_term("t_IE", T_CIE)
2932 p_term("t_IS", T_CIS)
2933 p_term("t_ke", T_KE)
2934 p_term("t_ks", T_KS)
2935 p_term("t_le", T_LE)
2936 p_term("t_mb", T_MB)
2937 p_term("t_md", T_MD)
2938 p_term("t_me", T_ME)
2939 p_term("t_mr", T_MR)
2940 p_term("t_ms", T_MS)
2941 p_term("t_nd", T_ND)
2942 p_term("t_op", T_OP)
2943 p_term("t_RI", T_CRI)
2944 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002945 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946 p_term("t_Sb", T_CSB)
2947 p_term("t_Sf", T_CSF)
2948 p_term("t_se", T_SE)
2949 p_term("t_so", T_SO)
2950 p_term("t_sr", T_SR)
2951 p_term("t_ts", T_TS)
2952 p_term("t_te", T_TE)
2953 p_term("t_ti", T_TI)
2954 p_term("t_ue", T_UE)
2955 p_term("t_us", T_US)
2956 p_term("t_vb", T_VB)
2957 p_term("t_ve", T_VE)
2958 p_term("t_vi", T_VI)
2959 p_term("t_vs", T_VS)
2960 p_term("t_WP", T_CWP)
2961 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002962 p_term("t_SI", T_CSI)
2963 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 p_term("t_xs", T_XS)
2965 p_term("t_ZH", T_CZH)
2966 p_term("t_ZR", T_CZR)
2967
2968/* terminal key codes are not in here */
2969
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002970 /* end marker */
2971 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972};
2973
2974#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2975
2976#ifdef FEAT_MBYTE
2977static char *(p_ambw_values[]) = {"single", "double", NULL};
2978#endif
2979static char *(p_bg_values[]) = {"light", "dark", NULL};
2980static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2981static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002982#ifdef FEAT_CRYPT
2983static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2984#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002985#ifdef FEAT_CMDL_COMPL
2986static char *(p_wop_values[]) = {"tagfile", NULL};
2987#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988#ifdef FEAT_WAK
2989static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2990#endif
2991static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
2993static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995#ifdef FEAT_BROWSE
2996static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
2997#endif
2998#ifdef FEAT_SCROLLBIND
2999static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3000#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003001static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002#ifdef FEAT_VERTSPLIT
3003static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3004#endif
3005#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003006# ifdef FEAT_AUTOCMD
3007static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3008# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003010# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3012#endif
3013static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3014#ifdef FEAT_FOLDING
3015static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003016# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003018# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 NULL};
3020static char *(p_fcl_values[]) = {"all", NULL};
3021#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003022#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003023static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003024#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025
3026static void set_option_default __ARGS((int, int opt_flags, int compatible));
3027static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003028static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003029static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030static char_u *illegal_char __ARGS((char_u *, int));
3031static int string_to_key __ARGS((char_u *arg));
3032#ifdef FEAT_CMDWIN
3033static char_u *check_cedit __ARGS((void));
3034#endif
3035#ifdef FEAT_TITLE
3036static void did_set_title __ARGS((int icon));
3037#endif
3038static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3039static void didset_options __ARGS((void));
3040static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003041#if defined(FEAT_EVAL) || defined(PROTO)
3042static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3043#else
3044# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3045#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003047static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048static 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));
3049static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003050#ifdef FEAT_SYN_HL
3051static int int_cmp __ARGS((const void *a, const void *b));
3052#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053#ifdef FEAT_CLIPBOARD
3054static char_u *check_clipboard_option __ARGS((void));
3055#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003056#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003057static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003058#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003059#ifdef FEAT_EVAL
3060static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3061#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003063static 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 +00003064static void check_redraw __ARGS((long_u flags));
3065static int findoption __ARGS((char_u *));
3066static int find_key_option __ARGS((char_u *));
3067static void showoptions __ARGS((int all, int opt_flags));
3068static int optval_default __ARGS((struct vimoption *, char_u *varp));
3069static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3070static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3071static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3072static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3073static int istermoption __ARGS((struct vimoption *));
3074static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3075static char_u *get_varp __ARGS((struct vimoption *));
3076static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003077static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3079#ifdef FEAT_LANGMAP
3080static void langmap_init __ARGS((void));
3081static void langmap_set __ARGS((void));
3082#endif
3083static void paste_option_changed __ARGS((void));
3084static void compatible_set __ARGS((void));
3085#ifdef FEAT_LINEBREAK
3086static void fill_breakat_flags __ARGS((void));
3087#endif
3088static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3089static int check_opt_strings __ARGS((char_u *val, char **values, int));
3090static int check_opt_wim __ARGS((void));
3091
3092/*
3093 * Initialize the options, first part.
3094 *
3095 * Called only once from main(), just after creating the first buffer.
3096 */
3097 void
3098set_init_1()
3099{
3100 char_u *p;
3101 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003102 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103
3104#ifdef FEAT_LANGMAP
3105 langmap_init();
3106#endif
3107
3108 /* Be Vi compatible by default */
3109 p_cp = TRUE;
3110
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003111 /* Use POSIX compatibility when $VIM_POSIX is set. */
3112 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003113 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003114 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003115 set_string_default("shm", (char_u *)"A");
3116 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003117
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 /*
3119 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003120 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003122 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3124# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003125 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003127 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003129 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130# endif
3131#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003132 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 set_string_default("sh", p);
3134
3135#ifdef FEAT_WILDIGN
3136 /*
3137 * Set the default for 'backupskip' to include environment variables for
3138 * temp files.
3139 */
3140 {
3141# ifdef UNIX
3142 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3143# else
3144 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3145# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003146 int len;
3147 garray_T ga;
3148 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149
3150 ga_init2(&ga, 1, 100);
3151 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3152 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003153 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154# ifdef UNIX
3155 if (*names[n] == NUL)
3156 p = (char_u *)"/tmp";
3157 else
3158# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003159 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 if (p != NULL && *p != NUL)
3161 {
3162 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003163 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 if (ga_grow(&ga, len) == OK)
3165 {
3166 if (ga.ga_len > 0)
3167 STRCAT(ga.ga_data, ",");
3168 STRCAT(ga.ga_data, p);
3169 add_pathsep(ga.ga_data);
3170 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 ga.ga_len += len;
3172 }
3173 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003174 if (mustfree)
3175 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 }
3177 if (ga.ga_data != NULL)
3178 {
3179 set_string_default("bsk", ga.ga_data);
3180 vim_free(ga.ga_data);
3181 }
3182 }
3183#endif
3184
3185 /*
3186 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3187 */
3188 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003189 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003191#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3192 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3193#endif
3194 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003196 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003197 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198#else
3199# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003200 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003201 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003203 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204# endif
3205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003207 opt_idx = findoption((char_u *)"maxmem");
3208 if (opt_idx >= 0)
3209 {
3210#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003211 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003212 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3213#endif
3214 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3215 }
3216 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003217 }
3218
3219#ifdef FEAT_GUI_W32
3220 /* force 'shortname' for Win32s */
3221 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003222 {
3223 opt_idx = findoption((char_u *)"shortname");
3224 if (opt_idx >= 0)
3225 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3226 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227#endif
3228
3229#ifdef FEAT_SEARCHPATH
3230 {
3231 char_u *cdpath;
3232 char_u *buf;
3233 int i;
3234 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003235 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236
3237 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003238 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239 if (cdpath != NULL)
3240 {
3241 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3242 if (buf != NULL)
3243 {
3244 buf[0] = ','; /* start with ",", current dir first */
3245 j = 1;
3246 for (i = 0; cdpath[i] != NUL; ++i)
3247 {
3248 if (vim_ispathlistsep(cdpath[i]))
3249 buf[j++] = ',';
3250 else
3251 {
3252 if (cdpath[i] == ' ' || cdpath[i] == ',')
3253 buf[j++] = '\\';
3254 buf[j++] = cdpath[i];
3255 }
3256 }
3257 buf[j] = NUL;
3258 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 if (opt_idx >= 0)
3260 {
3261 options[opt_idx].def_val[VI_DEFAULT] = buf;
3262 options[opt_idx].flags |= P_DEF_ALLOCED;
3263 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003264 else
3265 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003267 if (mustfree)
3268 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269 }
3270 }
3271#endif
3272
3273#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3274 /* Set print encoding on platforms that don't default to latin1 */
3275 set_string_default("penc",
3276# if defined(MSWIN) || defined(OS2)
3277 (char_u *)"cp1252"
3278# else
3279# ifdef VMS
3280 (char_u *)"dec-mcs"
3281# else
3282# ifdef EBCDIC
3283 (char_u *)"ebcdic-uk"
3284# else
3285# ifdef MAC
3286 (char_u *)"mac-roman"
3287# else /* HPUX */
3288 (char_u *)"hp-roman8"
3289# endif
3290# endif
3291# endif
3292# endif
3293 );
3294#endif
3295
3296#ifdef FEAT_POSTSCRIPT
3297 /* 'printexpr' must be allocated to be able to evaluate it. */
3298 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003299# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3300 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301# else
3302# ifdef VMS
3303 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3304
3305# else
3306 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3307# endif
3308# endif
3309 );
3310#endif
3311
3312 /*
3313 * Set all the options (except the terminal options) to their default
3314 * value. Also set the global value for local options.
3315 */
3316 set_options_default(0);
3317
3318#ifdef FEAT_GUI
3319 if (found_reverse_arg)
3320 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3321#endif
3322
3323 curbuf->b_p_initialized = TRUE;
3324 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003325 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326 check_buf_options(curbuf);
3327 check_win_options(curwin);
3328 check_options();
3329
3330 /* Must be before option_expand(), because that one needs vim_isIDc() */
3331 didset_options();
3332
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003333#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003334 /* Use the current chartab for the generic chartab. */
3335 init_spell_chartab();
3336#endif
3337
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338#ifdef FEAT_LINEBREAK
3339 /*
3340 * initialize the table for 'breakat'.
3341 */
3342 fill_breakat_flags();
3343#endif
3344
3345 /*
3346 * Expand environment variables and things like "~" for the defaults.
3347 * If option_expand() returns non-NULL the variable is expanded. This can
3348 * only happen for non-indirect options.
3349 * Also set the default to the expanded value, so ":set" does not list
3350 * them.
3351 * Don't set the P_ALLOCED flag, because we don't want to free the
3352 * default.
3353 */
3354 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3355 {
3356 if ((options[opt_idx].flags & P_GETTEXT)
3357 && options[opt_idx].var != NULL)
3358 p = (char_u *)_(*(char **)options[opt_idx].var);
3359 else
3360 p = option_expand(opt_idx, NULL);
3361 if (p != NULL && (p = vim_strsave(p)) != NULL)
3362 {
3363 *(char_u **)options[opt_idx].var = p;
3364 /* VIMEXP
3365 * Defaults for all expanded options are currently the same for Vi
3366 * and Vim. When this changes, add some code here! Also need to
3367 * split P_DEF_ALLOCED in two.
3368 */
3369 if (options[opt_idx].flags & P_DEF_ALLOCED)
3370 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3371 options[opt_idx].def_val[VI_DEFAULT] = p;
3372 options[opt_idx].flags |= P_DEF_ALLOCED;
3373 }
3374 }
3375
3376 /* Initialize the highlight_attr[] table. */
3377 highlight_changed();
3378
3379 save_file_ff(curbuf); /* Buffer is unchanged */
3380
3381 /* Parse default for 'wildmode' */
3382 check_opt_wim();
3383
3384#if defined(FEAT_ARABIC)
3385 /* Detect use of mlterm.
3386 * Mlterm is a terminal emulator akin to xterm that has some special
3387 * abilities (bidi namely).
3388 * NOTE: mlterm's author is being asked to 'set' a variable
3389 * instead of an environment variable due to inheritance.
3390 */
3391 if (mch_getenv((char_u *)"MLTERM") != NULL)
3392 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3393#endif
3394
3395#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3396 /* Parse default for 'fillchars'. */
3397 (void)set_chars_option(&p_fcs);
3398#endif
3399
3400#ifdef FEAT_CLIPBOARD
3401 /* Parse default for 'clipboard' */
3402 (void)check_clipboard_option();
3403#endif
3404
3405#ifdef FEAT_MBYTE
3406# if defined(WIN3264) && defined(FEAT_GETTEXT)
3407 /*
3408 * If $LANG isn't set, try to get a good value for it. This makes the
3409 * right language be used automatically. Don't do this for English.
3410 */
3411 if (mch_getenv((char_u *)"LANG") == NULL)
3412 {
3413 char buf[20];
3414
3415 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3416 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3417 * only the first two. */
3418 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3419 (LPTSTR)buf, 20);
3420 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3421 {
3422 /* There are a few exceptions (probably more) */
3423 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3424 STRCPY(buf, "zh_TW");
3425 else if (STRNICMP(buf, "chs", 3) == 0
3426 || STRNICMP(buf, "zhc", 3) == 0)
3427 STRCPY(buf, "zh_CN");
3428 else if (STRNICMP(buf, "jp", 2) == 0)
3429 STRCPY(buf, "ja");
3430 else
3431 buf[2] = NUL; /* truncate to two-letter code */
3432 vim_setenv("LANG", buf);
3433 }
3434 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003435# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003436# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003437 /* Moved to os_mac_conv.c to avoid dependency problems. */
3438 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003439# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440# endif
3441
3442 /* enc_locale() will try to find the encoding of the current locale. */
3443 p = enc_locale();
3444 if (p != NULL)
3445 {
3446 char_u *save_enc;
3447
3448 /* Try setting 'encoding' and check if the value is valid.
3449 * If not, go back to the default "latin1". */
3450 save_enc = p_enc;
3451 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003452 if (STRCMP(p_enc, "gb18030") == 0)
3453 {
3454 /* We don't support "gb18030", but "cp936" is a good substitute
3455 * for practical purposes, thus use that. It's not an alias to
3456 * still support conversion between gb18030 and utf-8. */
3457 p_enc = vim_strsave((char_u *)"cp936");
3458 vim_free(p);
3459 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003460 if (mb_init() == NULL)
3461 {
3462 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003463 if (opt_idx >= 0)
3464 {
3465 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3466 options[opt_idx].flags |= P_DEF_ALLOCED;
3467 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003468
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003469#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3470 || defined(VMS)
3471 if (STRCMP(p_enc, "latin1") == 0
3472# ifdef FEAT_MBYTE
3473 || enc_utf8
3474# endif
3475 )
3476 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003477 /* Adjust the default for 'isprint' and 'iskeyword' to match
3478 * latin1. Also set the defaults for when 'nocompatible' is
3479 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003480 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003481 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003482 set_string_option_direct((char_u *)"isk", -1,
3483 ISK_LATIN1, OPT_FREE, SID_NONE);
3484 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003485 if (opt_idx >= 0)
3486 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003487 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003488 if (opt_idx >= 0)
3489 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003490 (void)init_chartab();
3491 }
3492#endif
3493
Bram Moolenaar071d4272004-06-13 20:20:40 +00003494# if defined(WIN3264) && !defined(FEAT_GUI)
3495 /* Win32 console: When GetACP() returns a different value from
3496 * GetConsoleCP() set 'termencoding'. */
3497 if (GetACP() != GetConsoleCP())
3498 {
3499 char buf[50];
3500
3501 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3502 p_tenc = vim_strsave((char_u *)buf);
3503 if (p_tenc != NULL)
3504 {
3505 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003506 if (opt_idx >= 0)
3507 {
3508 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3509 options[opt_idx].flags |= P_DEF_ALLOCED;
3510 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003511 convert_setup(&input_conv, p_tenc, p_enc);
3512 convert_setup(&output_conv, p_enc, p_tenc);
3513 }
3514 else
3515 p_tenc = empty_option;
3516 }
3517# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003518# if defined(WIN3264) && defined(FEAT_MBYTE)
3519 /* $HOME may have characters in active code page. */
3520 init_homedir();
3521# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003522 }
3523 else
3524 {
3525 vim_free(p_enc);
3526 p_enc = save_enc;
3527 }
3528 }
3529#endif
3530
3531#ifdef FEAT_MULTI_LANG
3532 /* Set the default for 'helplang'. */
3533 set_helplang_default(get_mess_lang());
3534#endif
3535}
3536
3537/*
3538 * Set an option to its default value.
3539 * This does not take care of side effects!
3540 */
3541 static void
3542set_option_default(opt_idx, opt_flags, compatible)
3543 int opt_idx;
3544 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3545 int compatible; /* use Vi default value */
3546{
3547 char_u *varp; /* pointer to variable for current option */
3548 int dvi; /* index in def_val[] */
3549 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003550 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003551 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3552
3553 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3554 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003555 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003556 {
3557 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3558 if (flags & P_STRING)
3559 {
3560 /* Use set_string_option_direct() for local options to handle
3561 * freeing and allocating the value. */
3562 if (options[opt_idx].indir != PV_NONE)
3563 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003564 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565 else
3566 {
3567 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3568 free_string_option(*(char_u **)(varp));
3569 *(char_u **)varp = options[opt_idx].def_val[dvi];
3570 options[opt_idx].flags &= ~P_ALLOCED;
3571 }
3572 }
3573 else if (flags & P_NUM)
3574 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003575 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576 win_comp_scroll(curwin);
3577 else
3578 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003579 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003580 /* May also set global value for local option. */
3581 if (both)
3582 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3583 *(long *)varp;
3584 }
3585 }
3586 else /* P_BOOL */
3587 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003588 /* the cast to long is required for Manx C, long_i is needed for
3589 * MSVC */
3590 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003591#ifdef UNIX
3592 /* 'modeline' defaults to off for root */
3593 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3594 *(int *)varp = FALSE;
3595#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 /* May also set global value for local option. */
3597 if (both)
3598 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3599 *(int *)varp;
3600 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003601
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003602 /* The default value is not insecure. */
3603 flagsp = insecure_flag(opt_idx, opt_flags);
3604 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605 }
3606
3607#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003608 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609#endif
3610}
3611
3612/*
3613 * Set all options (except terminal options) to their default value.
3614 */
3615 static void
3616set_options_default(opt_flags)
3617 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3618{
3619 int i;
3620#ifdef FEAT_WINDOWS
3621 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003622 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623#endif
3624
3625 for (i = 0; !istermoption(&options[i]); i++)
3626 if (!(options[i].flags & P_NODEFAULT))
3627 set_option_default(i, opt_flags, p_cp);
3628
3629#ifdef FEAT_WINDOWS
3630 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003631 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632 win_comp_scroll(wp);
3633#else
3634 win_comp_scroll(curwin);
3635#endif
3636}
3637
3638/*
3639 * Set the Vi-default value of a string option.
3640 * Used for 'sh', 'backupskip' and 'term'.
3641 */
3642 void
3643set_string_default(name, val)
3644 char *name;
3645 char_u *val;
3646{
3647 char_u *p;
3648 int opt_idx;
3649
3650 p = vim_strsave(val);
3651 if (p != NULL) /* we don't want a NULL */
3652 {
3653 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003654 if (opt_idx >= 0)
3655 {
3656 if (options[opt_idx].flags & P_DEF_ALLOCED)
3657 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3658 options[opt_idx].def_val[VI_DEFAULT] = p;
3659 options[opt_idx].flags |= P_DEF_ALLOCED;
3660 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661 }
3662}
3663
3664/*
3665 * Set the Vi-default value of a number option.
3666 * Used for 'lines' and 'columns'.
3667 */
3668 void
3669set_number_default(name, val)
3670 char *name;
3671 long val;
3672{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003673 int opt_idx;
3674
3675 opt_idx = findoption((char_u *)name);
3676 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003677 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678}
3679
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003680#if defined(EXITFREE) || defined(PROTO)
3681/*
3682 * Free all options.
3683 */
3684 void
3685free_all_options()
3686{
3687 int i;
3688
3689 for (i = 0; !istermoption(&options[i]); i++)
3690 {
3691 if (options[i].indir == PV_NONE)
3692 {
3693 /* global option: free value and default value. */
3694 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3695 free_string_option(*(char_u **)options[i].var);
3696 if (options[i].flags & P_DEF_ALLOCED)
3697 free_string_option(options[i].def_val[VI_DEFAULT]);
3698 }
3699 else if (options[i].var != VAR_WIN
3700 && (options[i].flags & P_STRING))
3701 /* buffer-local option: free global value */
3702 free_string_option(*(char_u **)options[i].var);
3703 }
3704}
3705#endif
3706
3707
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708/*
3709 * Initialize the options, part two: After getting Rows and Columns and
3710 * setting 'term'.
3711 */
3712 void
3713set_init_2()
3714{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003715 int idx;
3716
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717 /*
3718 * 'scroll' defaults to half the window height. Note that this default is
3719 * wrong when the window height changes.
3720 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003721 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003722 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003723 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003724 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003725 comp_col();
3726
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003727 /*
3728 * 'window' is only for backwards compatibility with Vi.
3729 * Default is Rows - 1.
3730 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003731 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003732 p_window = Rows - 1;
3733 set_number_default("window", Rows - 1);
3734
Bram Moolenaarf740b292006-02-16 22:11:02 +00003735 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003736#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003737 /*
3738 * If 'background' wasn't set by the user, try guessing the value,
3739 * depending on the terminal name. Only need to check for terminals
3740 * with a dark background, that can handle color.
3741 */
3742 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003743 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3744 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003745 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003746 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003747 /* don't mark it as set, when starting the GUI it may be
3748 * changed again */
3749 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750 }
3751#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003752
3753#ifdef CURSOR_SHAPE
3754 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3755#endif
3756#ifdef FEAT_MOUSESHAPE
3757 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3758#endif
3759#ifdef FEAT_PRINTER
3760 (void)parse_printoptions(); /* parse 'printoptions' default value */
3761#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762}
3763
3764/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003765 * Return "dark" or "light" depending on the kind of terminal.
3766 * This is just guessing! Recognized are:
3767 * "linux" Linux console
3768 * "screen.linux" Linux console with screen
3769 * "cygwin" Cygwin shell
3770 * "putty" Putty program
3771 * We also check the COLORFGBG environment variable, which is set by
3772 * rxvt and derivatives. This variable contains either two or three
3773 * values separated by semicolons; we want the last value in either
3774 * case. If this value is 0-6 or 8, our background is dark.
3775 */
3776 static char_u *
3777term_bg_default()
3778{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003779#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3780 /* DOS console nearly always black */
3781 return (char_u *)"dark";
3782#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003783 char_u *p;
3784
Bram Moolenaarf740b292006-02-16 22:11:02 +00003785 if (STRCMP(T_NAME, "linux") == 0
3786 || STRCMP(T_NAME, "screen.linux") == 0
3787 || STRCMP(T_NAME, "cygwin") == 0
3788 || STRCMP(T_NAME, "putty") == 0
3789 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3790 && (p = vim_strrchr(p, ';')) != NULL
3791 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3792 && p[2] == NUL))
3793 return (char_u *)"dark";
3794 return (char_u *)"light";
3795#endif
3796}
3797
3798/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799 * Initialize the options, part three: After reading the .vimrc
3800 */
3801 void
3802set_init_3()
3803{
3804#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3805/*
3806 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3807 * This is done after other initializations, where 'shell' might have been
3808 * set, but only if they have not been set before.
3809 */
3810 char_u *p;
3811 int idx_srr;
3812 int do_srr;
3813#ifdef FEAT_QUICKFIX
3814 int idx_sp;
3815 int do_sp;
3816#endif
3817
3818 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003819 if (idx_srr < 0)
3820 do_srr = FALSE;
3821 else
3822 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823#ifdef FEAT_QUICKFIX
3824 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003825 if (idx_sp < 0)
3826 do_sp = FALSE;
3827 else
3828 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003830 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831 if (p != NULL)
3832 {
3833 /*
3834 * Default for p_sp is "| tee", for p_srr is ">".
3835 * For known shells it is changed here to include stderr.
3836 */
3837 if ( fnamecmp(p, "csh") == 0
3838 || fnamecmp(p, "tcsh") == 0
3839# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3840 || fnamecmp(p, "csh.exe") == 0
3841 || fnamecmp(p, "tcsh.exe") == 0
3842# endif
3843 )
3844 {
3845#if defined(FEAT_QUICKFIX)
3846 if (do_sp)
3847 {
3848# ifdef WIN3264
3849 p_sp = (char_u *)">&";
3850# else
3851 p_sp = (char_u *)"|& tee";
3852# endif
3853 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3854 }
3855#endif
3856 if (do_srr)
3857 {
3858 p_srr = (char_u *)">&";
3859 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3860 }
3861 }
3862 else
3863# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3864 if ( fnamecmp(p, "sh") == 0
3865 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003866 || fnamecmp(p, "mksh") == 0
3867 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003869 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003871 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872# ifdef WIN3264
3873 || fnamecmp(p, "cmd") == 0
3874 || fnamecmp(p, "sh.exe") == 0
3875 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003876 || fnamecmp(p, "mksh.exe") == 0
3877 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003879 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880 || fnamecmp(p, "bash.exe") == 0
3881 || fnamecmp(p, "cmd.exe") == 0
3882# endif
3883 )
3884# endif
3885 {
3886#if defined(FEAT_QUICKFIX)
3887 if (do_sp)
3888 {
3889# ifdef WIN3264
3890 p_sp = (char_u *)">%s 2>&1";
3891# else
3892 p_sp = (char_u *)"2>&1| tee";
3893# endif
3894 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3895 }
3896#endif
3897 if (do_srr)
3898 {
3899 p_srr = (char_u *)">%s 2>&1";
3900 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3901 }
3902 }
3903 vim_free(p);
3904 }
3905#endif
3906
3907#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3908 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003909 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3910 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 * This is done after other initializations, where 'shell' might have been
3912 * set, but only if they have not been set before. Default for p_shcf is
3913 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3914 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3915 * command.com. And for Win32 we need to set p_sxq instead.
3916 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003917 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 {
3919 int idx3;
3920
3921 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003922 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 {
3924 p_shcf = (char_u *)"-c";
3925 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3926 }
3927
3928# ifndef DJGPP
3929# ifdef WIN3264
3930 /* Somehow Win32 requires the quotes around the redirection too */
3931 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003932 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 {
3934 p_sxq = (char_u *)"\"";
3935 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3936 }
3937# else
3938 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003939 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 {
3941 p_shq = (char_u *)"\"";
3942 options[idx3].def_val[VI_DEFAULT] = p_shq;
3943 }
3944# endif
3945# endif
3946 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003947 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3948 {
3949 int idx3;
3950
3951 /*
3952 * cmd.exe on Windows will strip the first and last double quote given
3953 * on the command line, e.g. most of the time things like:
3954 * cmd /c "my path/to/echo" "my args to echo"
3955 * become:
3956 * my path/to/echo" "my args to echo
3957 * when executed.
3958 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003959 * To avoid this, set shellxquote to surround the command in
3960 * parenthesis. This appears to make most commands work, without
3961 * breaking commands that worked previously, such as
3962 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003963 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003964 idx3 = findoption((char_u *)"sxq");
3965 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3966 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003967 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003968 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3969 }
3970
Bram Moolenaara64ba222012-02-12 23:23:31 +01003971 idx3 = findoption((char_u *)"shcf");
3972 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3973 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003974 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003975 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3976 }
3977 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978#endif
3979
3980#ifdef FEAT_TITLE
3981 set_title_defaults();
3982#endif
3983}
3984
3985#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3986/*
3987 * When 'helplang' is still at its default value, set it to "lang".
3988 * Only the first two characters of "lang" are used.
3989 */
3990 void
3991set_helplang_default(lang)
3992 char_u *lang;
3993{
3994 int idx;
3995
3996 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3997 return;
3998 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003999 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 {
4001 if (options[idx].flags & P_ALLOCED)
4002 free_string_option(p_hlg);
4003 p_hlg = vim_strsave(lang);
4004 if (p_hlg == NULL)
4005 p_hlg = empty_option;
4006 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004007 {
4008 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4009 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4010 {
4011 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4012 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4013 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004015 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004016 options[idx].flags |= P_ALLOCED;
4017 }
4018}
4019#endif
4020
4021#ifdef FEAT_GUI
4022static char_u *gui_bg_default __ARGS((void));
4023
4024 static char_u *
4025gui_bg_default()
4026{
4027 if (gui_get_lightness(gui.back_pixel) < 127)
4028 return (char_u *)"dark";
4029 return (char_u *)"light";
4030}
4031
4032/*
4033 * Option initializations that can only be done after opening the GUI window.
4034 */
4035 void
4036init_gui_options()
4037{
4038 /* Set the 'background' option according to the lightness of the
4039 * background color, unless the user has set it already. */
4040 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4041 {
4042 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4043 highlight_changed();
4044 }
4045}
4046#endif
4047
4048#ifdef FEAT_TITLE
4049/*
4050 * 'title' and 'icon' only default to true if they have not been set or reset
4051 * in .vimrc and we can read the old value.
4052 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4053 * they can be reset. This reduces startup time when using X on a remote
4054 * machine.
4055 */
4056 void
4057set_title_defaults()
4058{
4059 int idx1;
4060 long val;
4061
4062 /*
4063 * If GUI is (going to be) used, we can always set the window title and
4064 * icon name. Saves a bit of time, because the X11 display server does
4065 * not need to be contacted.
4066 */
4067 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004068 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 {
4070#ifdef FEAT_GUI
4071 if (gui.starting || gui.in_use)
4072 val = TRUE;
4073 else
4074#endif
4075 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004076 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 p_title = val;
4078 }
4079 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004080 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 {
4082#ifdef FEAT_GUI
4083 if (gui.starting || gui.in_use)
4084 val = TRUE;
4085 else
4086#endif
4087 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004088 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 p_icon = val;
4090 }
4091}
4092#endif
4093
4094/*
4095 * Parse 'arg' for option settings.
4096 *
4097 * 'arg' may be IObuff, but only when no errors can be present and option
4098 * does not need to be expanded with option_expand().
4099 * "opt_flags":
4100 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004101 * OPT_GLOBAL for ":setglobal"
4102 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004104 * OPT_WINONLY to only set window-local options
4105 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 *
4107 * returns FAIL if an error is detected, OK otherwise
4108 */
4109 int
4110do_set(arg, opt_flags)
4111 char_u *arg; /* option string (may be written to!) */
4112 int opt_flags;
4113{
4114 int opt_idx;
4115 char_u *errmsg;
4116 char_u errbuf[80];
4117 char_u *startarg;
4118 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4119 int nextchar; /* next non-white char after option name */
4120 int afterchar; /* character just after option name */
4121 int len;
4122 int i;
4123 long value;
4124 int key;
4125 long_u flags; /* flags for current option */
4126 char_u *varp = NULL; /* pointer to variable for current option */
4127 int did_show = FALSE; /* already showed one value */
4128 int adding; /* "opt+=arg" */
4129 int prepending; /* "opt^=arg" */
4130 int removing; /* "opt-=arg" */
4131 int cp_val = 0;
4132 char_u key_name[2];
4133
4134 if (*arg == NUL)
4135 {
4136 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004137 did_show = TRUE;
4138 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 }
4140
4141 while (*arg != NUL) /* loop to process all options */
4142 {
4143 errmsg = NULL;
4144 startarg = arg; /* remember for error message */
4145
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004146 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4147 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 {
4149 /*
4150 * ":set all" show all options.
4151 * ":set all&" set all options to their default value.
4152 */
4153 arg += 3;
4154 if (*arg == '&')
4155 {
4156 ++arg;
4157 /* Only for :set command set global value of local options. */
4158 set_options_default(OPT_FREE | opt_flags);
4159 }
4160 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004161 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004162 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004163 did_show = TRUE;
4164 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004166 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004167 {
4168 showoptions(2, opt_flags);
4169 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004170 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 arg += 7;
4172 }
4173 else
4174 {
4175 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004176 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 {
4178 prefix = 0;
4179 arg += 2;
4180 }
4181 else if (STRNCMP(arg, "inv", 3) == 0)
4182 {
4183 prefix = 2;
4184 arg += 3;
4185 }
4186
4187 /* find end of name */
4188 key = 0;
4189 if (*arg == '<')
4190 {
4191 nextchar = 0;
4192 opt_idx = -1;
4193 /* look out for <t_>;> */
4194 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4195 len = 5;
4196 else
4197 {
4198 len = 1;
4199 while (arg[len] != NUL && arg[len] != '>')
4200 ++len;
4201 }
4202 if (arg[len] != '>')
4203 {
4204 errmsg = e_invarg;
4205 goto skip;
4206 }
4207 arg[len] = NUL; /* put NUL after name */
4208 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4209 opt_idx = findoption(arg + 1);
4210 arg[len++] = '>'; /* restore '>' */
4211 if (opt_idx == -1)
4212 key = find_key_option(arg + 1);
4213 }
4214 else
4215 {
4216 len = 0;
4217 /*
4218 * The two characters after "t_" may not be alphanumeric.
4219 */
4220 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4221 len = 4;
4222 else
4223 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4224 ++len;
4225 nextchar = arg[len];
4226 arg[len] = NUL; /* put NUL after name */
4227 opt_idx = findoption(arg);
4228 arg[len] = nextchar; /* restore nextchar */
4229 if (opt_idx == -1)
4230 key = find_key_option(arg);
4231 }
4232
4233 /* remember character after option name */
4234 afterchar = arg[len];
4235
4236 /* skip white space, allow ":set ai ?" */
4237 while (vim_iswhite(arg[len]))
4238 ++len;
4239
4240 adding = FALSE;
4241 prepending = FALSE;
4242 removing = FALSE;
4243 if (arg[len] != NUL && arg[len + 1] == '=')
4244 {
4245 if (arg[len] == '+')
4246 {
4247 adding = TRUE; /* "+=" */
4248 ++len;
4249 }
4250 else if (arg[len] == '^')
4251 {
4252 prepending = TRUE; /* "^=" */
4253 ++len;
4254 }
4255 else if (arg[len] == '-')
4256 {
4257 removing = TRUE; /* "-=" */
4258 ++len;
4259 }
4260 }
4261 nextchar = arg[len];
4262
4263 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4264 {
4265 errmsg = (char_u *)N_("E518: Unknown option");
4266 goto skip;
4267 }
4268
4269 if (opt_idx >= 0)
4270 {
4271 if (options[opt_idx].var == NULL) /* hidden option: skip */
4272 {
4273 /* Only give an error message when requesting the value of
4274 * a hidden option, ignore setting it. */
4275 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4276 && (!(options[opt_idx].flags & P_BOOL)
4277 || nextchar == '?'))
4278 errmsg = (char_u *)N_("E519: Option not supported");
4279 goto skip;
4280 }
4281
4282 flags = options[opt_idx].flags;
4283 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4284 }
4285 else
4286 {
4287 flags = P_STRING;
4288 if (key < 0)
4289 {
4290 key_name[0] = KEY2TERMCAP0(key);
4291 key_name[1] = KEY2TERMCAP1(key);
4292 }
4293 else
4294 {
4295 key_name[0] = KS_KEY;
4296 key_name[1] = (key & 0xff);
4297 }
4298 }
4299
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004300 /* Skip all options that are not window-local (used when showing
4301 * an already loaded buffer in a window). */
4302 if ((opt_flags & OPT_WINONLY)
4303 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4304 goto skip;
4305
Bram Moolenaara3227e22006-03-08 21:32:40 +00004306 /* Skip all options that are window-local (used for :vimgrep). */
4307 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4308 && options[opt_idx].var == VAR_WIN)
4309 goto skip;
4310
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004311 /* Disallow changing some options from modelines. */
4312 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004313 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004314 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004315 {
4316 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4317 goto skip;
4318 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004319#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004320 /* In diff mode some options are overruled. This avoids that
4321 * 'foldmethod' becomes "marker" instead of "diff" and that
4322 * "wrap" gets set. */
4323 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004324 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004325 && (options[opt_idx].indir == PV_FDM
4326 || options[opt_idx].indir == PV_WRAP))
4327 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004328#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004329 }
4330
4331#ifdef HAVE_SANDBOX
4332 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004333 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334 {
4335 errmsg = (char_u *)_(e_sandbox);
4336 goto skip;
4337 }
4338#endif
4339
4340 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4341 {
4342 arg += len;
4343 cp_val = p_cp;
4344 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4345 {
4346 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4347 {
4348 cp_val = FALSE;
4349 arg += 3;
4350 }
4351 else /* "opt&vi": set to Vi default */
4352 {
4353 cp_val = TRUE;
4354 arg += 2;
4355 }
4356 }
4357 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4358 && arg[1] != NUL && !vim_iswhite(arg[1]))
4359 {
4360 errmsg = e_trailing;
4361 goto skip;
4362 }
4363 }
4364
4365 /*
4366 * allow '=' and ':' as MSDOS command.com allows only one
4367 * '=' character per "set" command line. grrr. (jw)
4368 */
4369 if (nextchar == '?'
4370 || (prefix == 1
4371 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4372 && !(flags & P_BOOL)))
4373 {
4374 /*
4375 * print value
4376 */
4377 if (did_show)
4378 msg_putchar('\n'); /* cursor below last one */
4379 else
4380 {
4381 gotocmdline(TRUE); /* cursor at status line */
4382 did_show = TRUE; /* remember that we did a line */
4383 }
4384 if (opt_idx >= 0)
4385 {
4386 showoneopt(&options[opt_idx], opt_flags);
4387#ifdef FEAT_EVAL
4388 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004389 {
4390 /* Mention where the option was last set. */
4391 if (varp == options[opt_idx].var)
4392 last_set_msg(options[opt_idx].scriptID);
4393 else if ((int)options[opt_idx].indir & PV_WIN)
4394 last_set_msg(curwin->w_p_scriptID[
4395 (int)options[opt_idx].indir & PV_MASK]);
4396 else if ((int)options[opt_idx].indir & PV_BUF)
4397 last_set_msg(curbuf->b_p_scriptID[
4398 (int)options[opt_idx].indir & PV_MASK]);
4399 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004400#endif
4401 }
4402 else
4403 {
4404 char_u *p;
4405
4406 p = find_termcode(key_name);
4407 if (p == NULL)
4408 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004409 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004410 goto skip;
4411 }
4412 else
4413 (void)show_one_termcode(key_name, p, TRUE);
4414 }
4415 if (nextchar != '?'
4416 && nextchar != NUL && !vim_iswhite(afterchar))
4417 errmsg = e_trailing;
4418 }
4419 else
4420 {
4421 if (flags & P_BOOL) /* boolean */
4422 {
4423 if (nextchar == '=' || nextchar == ':')
4424 {
4425 errmsg = e_invarg;
4426 goto skip;
4427 }
4428
4429 /*
4430 * ":set opt!": invert
4431 * ":set opt&": reset to default value
4432 * ":set opt<": reset to global value
4433 */
4434 if (nextchar == '!')
4435 value = *(int *)(varp) ^ 1;
4436 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004437 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004438 ((flags & P_VI_DEF) || cp_val)
4439 ? VI_DEFAULT : VIM_DEFAULT];
4440 else if (nextchar == '<')
4441 {
4442 /* For 'autoread' -1 means to use global value. */
4443 if ((int *)varp == &curbuf->b_p_ar
4444 && opt_flags == OPT_LOCAL)
4445 value = -1;
4446 else
4447 value = *(int *)get_varp_scope(&(options[opt_idx]),
4448 OPT_GLOBAL);
4449 }
4450 else
4451 {
4452 /*
4453 * ":set invopt": invert
4454 * ":set opt" or ":set noopt": set or reset
4455 */
4456 if (nextchar != NUL && !vim_iswhite(afterchar))
4457 {
4458 errmsg = e_trailing;
4459 goto skip;
4460 }
4461 if (prefix == 2) /* inv */
4462 value = *(int *)(varp) ^ 1;
4463 else
4464 value = prefix;
4465 }
4466
4467 errmsg = set_bool_option(opt_idx, varp, (int)value,
4468 opt_flags);
4469 }
4470 else /* numeric or string */
4471 {
4472 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4473 || prefix != 1)
4474 {
4475 errmsg = e_invarg;
4476 goto skip;
4477 }
4478
4479 if (flags & P_NUM) /* numeric */
4480 {
4481 /*
4482 * Different ways to set a number option:
4483 * & set to default value
4484 * < set to global value
4485 * <xx> accept special key codes for 'wildchar'
4486 * c accept any non-digit for 'wildchar'
4487 * [-]0-9 set number
4488 * other error
4489 */
4490 ++arg;
4491 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004492 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004493 ((flags & P_VI_DEF) || cp_val)
4494 ? VI_DEFAULT : VIM_DEFAULT];
4495 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004496 {
4497 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4498 * use the global value. */
4499 if ((long *)varp == &curbuf->b_p_ul
4500 && opt_flags == OPT_LOCAL)
4501 value = NO_LOCAL_UNDOLEVEL;
4502 else
4503 value = *(long *)get_varp_scope(
4504 &(options[opt_idx]), OPT_GLOBAL);
4505 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004506 else if (((long *)varp == &p_wc
4507 || (long *)varp == &p_wcm)
4508 && (*arg == '<'
4509 || *arg == '^'
4510 || ((!arg[1] || vim_iswhite(arg[1]))
4511 && !VIM_ISDIGIT(*arg))))
4512 {
4513 value = string_to_key(arg);
4514 if (value == 0 && (long *)varp != &p_wcm)
4515 {
4516 errmsg = e_invarg;
4517 goto skip;
4518 }
4519 }
4520 /* allow negative numbers (for 'undolevels') */
4521 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4522 {
4523 i = 0;
4524 if (*arg == '-')
4525 i = 1;
4526#ifdef HAVE_STRTOL
4527 value = strtol((char *)arg, NULL, 0);
4528 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4529 i += 2;
4530#else
4531 value = atol((char *)arg);
4532#endif
4533 while (VIM_ISDIGIT(arg[i]))
4534 ++i;
4535 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4536 {
4537 errmsg = e_invarg;
4538 goto skip;
4539 }
4540 }
4541 else
4542 {
4543 errmsg = (char_u *)N_("E521: Number required after =");
4544 goto skip;
4545 }
4546
4547 if (adding)
4548 value = *(long *)varp + value;
4549 if (prepending)
4550 value = *(long *)varp * value;
4551 if (removing)
4552 value = *(long *)varp - value;
4553 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004554 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004555 }
4556 else if (opt_idx >= 0) /* string */
4557 {
4558 char_u *save_arg = NULL;
4559 char_u *s = NULL;
4560 char_u *oldval; /* previous value if *varp */
4561 char_u *newval;
4562 char_u *origval;
4563 unsigned newlen;
4564 int comma;
4565 int bs;
4566 int new_value_alloced; /* new string option
4567 was allocated */
4568
4569 /* When using ":set opt=val" for a global option
4570 * with a local value the local value will be
4571 * reset, use the global value here. */
4572 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004573 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004574 varp = options[opt_idx].var;
4575
4576 /* The old value is kept until we are sure that the
4577 * new value is valid. */
4578 oldval = *(char_u **)varp;
4579 if (nextchar == '&') /* set to default val */
4580 {
4581 newval = options[opt_idx].def_val[
4582 ((flags & P_VI_DEF) || cp_val)
4583 ? VI_DEFAULT : VIM_DEFAULT];
4584 if ((char_u **)varp == &p_bg)
4585 {
4586 /* guess the value of 'background' */
4587#ifdef FEAT_GUI
4588 if (gui.in_use)
4589 newval = gui_bg_default();
4590 else
4591#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004592 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004593 }
4594
4595 /* expand environment variables and ~ (since the
4596 * default value was already expanded, only
4597 * required when an environment variable was set
4598 * later */
4599 if (newval == NULL)
4600 newval = empty_option;
4601 else
4602 {
4603 s = option_expand(opt_idx, newval);
4604 if (s == NULL)
4605 s = newval;
4606 newval = vim_strsave(s);
4607 }
4608 new_value_alloced = TRUE;
4609 }
4610 else if (nextchar == '<') /* set to global val */
4611 {
4612 newval = vim_strsave(*(char_u **)get_varp_scope(
4613 &(options[opt_idx]), OPT_GLOBAL));
4614 new_value_alloced = TRUE;
4615 }
4616 else
4617 {
4618 ++arg; /* jump to after the '=' or ':' */
4619
4620 /*
4621 * Set 'keywordprg' to ":help" if an empty
4622 * value was passed to :set by the user.
4623 * Misuse errbuf[] for the resulting string.
4624 */
4625 if (varp == (char_u *)&p_kp
4626 && (*arg == NUL || *arg == ' '))
4627 {
4628 STRCPY(errbuf, ":help");
4629 save_arg = arg;
4630 arg = errbuf;
4631 }
4632 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004633 * Convert 'backspace' number to string, for
4634 * adding, prepending and removing string.
4635 */
4636 else if (varp == (char_u *)&p_bs
4637 && VIM_ISDIGIT(**(char_u **)varp))
4638 {
4639 i = getdigits((char_u **)varp);
4640 switch (i)
4641 {
4642 case 0:
4643 *(char_u **)varp = empty_option;
4644 break;
4645 case 1:
4646 *(char_u **)varp = vim_strsave(
4647 (char_u *)"indent,eol");
4648 break;
4649 case 2:
4650 *(char_u **)varp = vim_strsave(
4651 (char_u *)"indent,eol,start");
4652 break;
4653 }
4654 vim_free(oldval);
4655 oldval = *(char_u **)varp;
4656 }
4657 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004658 * Convert 'whichwrap' number to string, for
4659 * backwards compatibility with Vim 3.0.
4660 * Misuse errbuf[] for the resulting string.
4661 */
4662 else if (varp == (char_u *)&p_ww
4663 && VIM_ISDIGIT(*arg))
4664 {
4665 *errbuf = NUL;
4666 i = getdigits(&arg);
4667 if (i & 1)
4668 STRCAT(errbuf, "b,");
4669 if (i & 2)
4670 STRCAT(errbuf, "s,");
4671 if (i & 4)
4672 STRCAT(errbuf, "h,l,");
4673 if (i & 8)
4674 STRCAT(errbuf, "<,>,");
4675 if (i & 16)
4676 STRCAT(errbuf, "[,],");
4677 if (*errbuf != NUL) /* remove trailing , */
4678 errbuf[STRLEN(errbuf) - 1] = NUL;
4679 save_arg = arg;
4680 arg = errbuf;
4681 }
4682 /*
4683 * Remove '>' before 'dir' and 'bdir', for
4684 * backwards compatibility with version 3.0
4685 */
4686 else if ( *arg == '>'
4687 && (varp == (char_u *)&p_dir
4688 || varp == (char_u *)&p_bdir))
4689 {
4690 ++arg;
4691 }
4692
4693 /* When setting the local value of a global
4694 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004695 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004696 && (opt_flags & OPT_LOCAL))
4697 origval = *(char_u **)get_varp(
4698 &options[opt_idx]);
4699 else
4700 origval = oldval;
4701
4702 /*
4703 * Copy the new string into allocated memory.
4704 * Can't use set_string_option_direct(), because
4705 * we need to remove the backslashes.
4706 */
4707 /* get a bit too much */
4708 newlen = (unsigned)STRLEN(arg) + 1;
4709 if (adding || prepending || removing)
4710 newlen += (unsigned)STRLEN(origval) + 1;
4711 newval = alloc(newlen);
4712 if (newval == NULL) /* out of mem, don't change */
4713 break;
4714 s = newval;
4715
4716 /*
4717 * Copy the string, skip over escaped chars.
4718 * For MS-DOS and WIN32 backslashes before normal
4719 * file name characters are not removed, and keep
4720 * backslash at start, for "\\machine\path", but
4721 * do remove it for "\\\\machine\\path".
4722 * The reverse is found in ExpandOldSetting().
4723 */
4724 while (*arg && !vim_iswhite(*arg))
4725 {
4726 if (*arg == '\\' && arg[1] != NUL
4727#ifdef BACKSLASH_IN_FILENAME
4728 && !((flags & P_EXPAND)
4729 && vim_isfilec(arg[1])
4730 && (arg[1] != '\\'
4731 || (s == newval
4732 && arg[2] != '\\')))
4733#endif
4734 )
4735 ++arg; /* remove backslash */
4736#ifdef FEAT_MBYTE
4737 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004738 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004739 {
4740 /* copy multibyte char */
4741 mch_memmove(s, arg, (size_t)i);
4742 arg += i;
4743 s += i;
4744 }
4745 else
4746#endif
4747 *s++ = *arg++;
4748 }
4749 *s = NUL;
4750
4751 /*
4752 * Expand environment variables and ~.
4753 * Don't do it when adding without inserting a
4754 * comma.
4755 */
4756 if (!(adding || prepending || removing)
4757 || (flags & P_COMMA))
4758 {
4759 s = option_expand(opt_idx, newval);
4760 if (s != NULL)
4761 {
4762 vim_free(newval);
4763 newlen = (unsigned)STRLEN(s) + 1;
4764 if (adding || prepending || removing)
4765 newlen += (unsigned)STRLEN(origval) + 1;
4766 newval = alloc(newlen);
4767 if (newval == NULL)
4768 break;
4769 STRCPY(newval, s);
4770 }
4771 }
4772
4773 /* locate newval[] in origval[] when removing it
4774 * and when adding to avoid duplicates */
4775 i = 0; /* init for GCC */
4776 if (removing || (flags & P_NODUP))
4777 {
4778 i = (int)STRLEN(newval);
4779 bs = 0;
4780 for (s = origval; *s; ++s)
4781 {
4782 if ((!(flags & P_COMMA)
4783 || s == origval
4784 || (s[-1] == ',' && !(bs & 1)))
4785 && STRNCMP(s, newval, i) == 0
4786 && (!(flags & P_COMMA)
4787 || s[i] == ','
4788 || s[i] == NUL))
4789 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004790 /* Count backslashes. Only a comma with an
4791 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004792 * recognized as a separator */
4793 if (s > origval && s[-1] == '\\')
4794 ++bs;
4795 else
4796 bs = 0;
4797 }
4798
4799 /* do not add if already there */
4800 if ((adding || prepending) && *s)
4801 {
4802 prepending = FALSE;
4803 adding = FALSE;
4804 STRCPY(newval, origval);
4805 }
4806 }
4807
4808 /* concatenate the two strings; add a ',' if
4809 * needed */
4810 if (adding || prepending)
4811 {
4812 comma = ((flags & P_COMMA) && *origval != NUL
4813 && *newval != NUL);
4814 if (adding)
4815 {
4816 i = (int)STRLEN(origval);
4817 mch_memmove(newval + i + comma, newval,
4818 STRLEN(newval) + 1);
4819 mch_memmove(newval, origval, (size_t)i);
4820 }
4821 else
4822 {
4823 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004824 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004825 }
4826 if (comma)
4827 newval[i] = ',';
4828 }
4829
4830 /* Remove newval[] from origval[]. (Note: "i" has
4831 * been set above and is used here). */
4832 if (removing)
4833 {
4834 STRCPY(newval, origval);
4835 if (*s)
4836 {
4837 /* may need to remove a comma */
4838 if (flags & P_COMMA)
4839 {
4840 if (s == origval)
4841 {
4842 /* include comma after string */
4843 if (s[i] == ',')
4844 ++i;
4845 }
4846 else
4847 {
4848 /* include comma before string */
4849 --s;
4850 ++i;
4851 }
4852 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004853 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004854 }
4855 }
4856
4857 if (flags & P_FLAGLIST)
4858 {
4859 /* Remove flags that appear twice. */
4860 for (s = newval; *s; ++s)
4861 if ((!(flags & P_COMMA) || *s != ',')
4862 && vim_strchr(s + 1, *s) != NULL)
4863 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004864 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004865 --s;
4866 }
4867 }
4868
4869 if (save_arg != NULL) /* number for 'whichwrap' */
4870 arg = save_arg;
4871 new_value_alloced = TRUE;
4872 }
4873
4874 /* Set the new value. */
4875 *(char_u **)(varp) = newval;
4876
4877 /* Handle side effects, and set the global value for
4878 * ":set" on local options. */
4879 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4880 new_value_alloced, oldval, errbuf, opt_flags);
4881
4882 /* If error detected, print the error message. */
4883 if (errmsg != NULL)
4884 goto skip;
4885 }
4886 else /* key code option */
4887 {
4888 char_u *p;
4889
4890 if (nextchar == '&')
4891 {
4892 if (add_termcap_entry(key_name, TRUE) == FAIL)
4893 errmsg = (char_u *)N_("E522: Not found in termcap");
4894 }
4895 else
4896 {
4897 ++arg; /* jump to after the '=' or ':' */
4898 for (p = arg; *p && !vim_iswhite(*p); ++p)
4899 if (*p == '\\' && p[1] != NUL)
4900 ++p;
4901 nextchar = *p;
4902 *p = NUL;
4903 add_termcode(key_name, arg, FALSE);
4904 *p = nextchar;
4905 }
4906 if (full_screen)
4907 ttest(FALSE);
4908 redraw_all_later(CLEAR);
4909 }
4910 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004911
Bram Moolenaar071d4272004-06-13 20:20:40 +00004912 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004913 did_set_option(opt_idx, opt_flags,
4914 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004915 }
4916
4917skip:
4918 /*
4919 * Advance to next argument.
4920 * - skip until a blank found, taking care of backslashes
4921 * - skip blanks
4922 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4923 */
4924 for (i = 0; i < 2 ; ++i)
4925 {
4926 while (*arg != NUL && !vim_iswhite(*arg))
4927 if (*arg++ == '\\' && *arg != NUL)
4928 ++arg;
4929 arg = skipwhite(arg);
4930 if (*arg != '=')
4931 break;
4932 }
4933 }
4934
4935 if (errmsg != NULL)
4936 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004937 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004938 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004939 if (i + (arg - startarg) < IOSIZE)
4940 {
4941 /* append the argument with the error */
4942 STRCAT(IObuff, ": ");
4943 mch_memmove(IObuff + i, startarg, (arg - startarg));
4944 IObuff[i + (arg - startarg)] = NUL;
4945 }
4946 /* make sure all characters are printable */
4947 trans_characters(IObuff, IOSIZE);
4948
4949 ++no_wait_return; /* wait_return done later */
4950 emsg(IObuff); /* show error highlighted */
4951 --no_wait_return;
4952
4953 return FAIL;
4954 }
4955
4956 arg = skipwhite(arg);
4957 }
4958
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004959theend:
4960 if (silent_mode && did_show)
4961 {
4962 /* After displaying option values in silent mode. */
4963 silent_mode = FALSE;
4964 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4965 msg_putchar('\n');
4966 cursor_on(); /* msg_start() switches it off */
4967 out_flush();
4968 silent_mode = TRUE;
4969 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4970 }
4971
Bram Moolenaar071d4272004-06-13 20:20:40 +00004972 return OK;
4973}
4974
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004975/*
4976 * Call this when an option has been given a new value through a user command.
4977 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4978 */
4979 static void
4980did_set_option(opt_idx, opt_flags, new_value)
4981 int opt_idx;
4982 int opt_flags; /* possibly with OPT_MODELINE */
4983 int new_value; /* value was replaced completely */
4984{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004985 long_u *p;
4986
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004987 options[opt_idx].flags |= P_WAS_SET;
4988
4989 /* When an option is set in the sandbox, from a modeline or in secure mode
4990 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004991 * flag. */
4992 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004993 if (secure
4994#ifdef HAVE_SANDBOX
4995 || sandbox != 0
4996#endif
4997 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004998 *p = *p | P_INSECURE;
4999 else if (new_value)
5000 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005001}
5002
Bram Moolenaar071d4272004-06-13 20:20:40 +00005003 static char_u *
5004illegal_char(errbuf, c)
5005 char_u *errbuf;
5006 int c;
5007{
5008 if (errbuf == NULL)
5009 return (char_u *)"";
5010 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005011 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005012 return errbuf;
5013}
5014
5015/*
5016 * Convert a key name or string into a key value.
5017 * Used for 'wildchar' and 'cedit' options.
5018 */
5019 static int
5020string_to_key(arg)
5021 char_u *arg;
5022{
5023 if (*arg == '<')
5024 return find_key_option(arg + 1);
5025 if (*arg == '^')
5026 return Ctrl_chr(arg[1]);
5027 return *arg;
5028}
5029
5030#ifdef FEAT_CMDWIN
5031/*
5032 * Check value of 'cedit' and set cedit_key.
5033 * Returns NULL if value is OK, error message otherwise.
5034 */
5035 static char_u *
5036check_cedit()
5037{
5038 int n;
5039
5040 if (*p_cedit == NUL)
5041 cedit_key = -1;
5042 else
5043 {
5044 n = string_to_key(p_cedit);
5045 if (vim_isprintc(n))
5046 return e_invarg;
5047 cedit_key = n;
5048 }
5049 return NULL;
5050}
5051#endif
5052
5053#ifdef FEAT_TITLE
5054/*
5055 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5056 * maketitle() to create and display it.
5057 * When switching the title or icon off, call mch_restore_title() to get
5058 * the old value back.
5059 */
5060 static void
5061did_set_title(icon)
5062 int icon; /* Did set icon instead of title */
5063{
5064 if (starting != NO_SCREEN
5065#ifdef FEAT_GUI
5066 && !gui.starting
5067#endif
5068 )
5069 {
5070 maketitle();
5071 if (icon)
5072 {
5073 if (!p_icon)
5074 mch_restore_title(2);
5075 }
5076 else
5077 {
5078 if (!p_title)
5079 mch_restore_title(1);
5080 }
5081 }
5082}
5083#endif
5084
5085/*
5086 * set_options_bin - called when 'bin' changes value.
5087 */
5088 void
5089set_options_bin(oldval, newval, opt_flags)
5090 int oldval;
5091 int newval;
5092 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5093{
5094 /*
5095 * The option values that are changed when 'bin' changes are
5096 * copied when 'bin is set and restored when 'bin' is reset.
5097 */
5098 if (newval)
5099 {
5100 if (!oldval) /* switched on */
5101 {
5102 if (!(opt_flags & OPT_GLOBAL))
5103 {
5104 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5105 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5106 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5107 curbuf->b_p_et_nobin = curbuf->b_p_et;
5108 }
5109 if (!(opt_flags & OPT_LOCAL))
5110 {
5111 p_tw_nobin = p_tw;
5112 p_wm_nobin = p_wm;
5113 p_ml_nobin = p_ml;
5114 p_et_nobin = p_et;
5115 }
5116 }
5117
5118 if (!(opt_flags & OPT_GLOBAL))
5119 {
5120 curbuf->b_p_tw = 0; /* no automatic line wrap */
5121 curbuf->b_p_wm = 0; /* no automatic line wrap */
5122 curbuf->b_p_ml = 0; /* no modelines */
5123 curbuf->b_p_et = 0; /* no expandtab */
5124 }
5125 if (!(opt_flags & OPT_LOCAL))
5126 {
5127 p_tw = 0;
5128 p_wm = 0;
5129 p_ml = FALSE;
5130 p_et = FALSE;
5131 p_bin = TRUE; /* needed when called for the "-b" argument */
5132 }
5133 }
5134 else if (oldval) /* switched off */
5135 {
5136 if (!(opt_flags & OPT_GLOBAL))
5137 {
5138 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5139 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5140 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5141 curbuf->b_p_et = curbuf->b_p_et_nobin;
5142 }
5143 if (!(opt_flags & OPT_LOCAL))
5144 {
5145 p_tw = p_tw_nobin;
5146 p_wm = p_wm_nobin;
5147 p_ml = p_ml_nobin;
5148 p_et = p_et_nobin;
5149 }
5150 }
5151}
5152
5153#ifdef FEAT_VIMINFO
5154/*
5155 * Find the parameter represented by the given character (eg ', :, ", or /),
5156 * and return its associated value in the 'viminfo' string.
5157 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005158 * If the parameter is not specified in the string or there is no following
5159 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005160 */
5161 int
5162get_viminfo_parameter(type)
5163 int type;
5164{
5165 char_u *p;
5166
5167 p = find_viminfo_parameter(type);
5168 if (p != NULL && VIM_ISDIGIT(*p))
5169 return atoi((char *)p);
5170 return -1;
5171}
5172
5173/*
5174 * Find the parameter represented by the given character (eg ''', ':', '"', or
5175 * '/') in the 'viminfo' option and return a pointer to the string after it.
5176 * Return NULL if the parameter is not specified in the string.
5177 */
5178 char_u *
5179find_viminfo_parameter(type)
5180 int type;
5181{
5182 char_u *p;
5183
5184 for (p = p_viminfo; *p; ++p)
5185 {
5186 if (*p == type)
5187 return p + 1;
5188 if (*p == 'n') /* 'n' is always the last one */
5189 break;
5190 p = vim_strchr(p, ','); /* skip until next ',' */
5191 if (p == NULL) /* hit the end without finding parameter */
5192 break;
5193 }
5194 return NULL;
5195}
5196#endif
5197
5198/*
5199 * Expand environment variables for some string options.
5200 * These string options cannot be indirect!
5201 * If "val" is NULL expand the current value of the option.
5202 * Return pointer to NameBuff, or NULL when not expanded.
5203 */
5204 static char_u *
5205option_expand(opt_idx, val)
5206 int opt_idx;
5207 char_u *val;
5208{
5209 /* if option doesn't need expansion nothing to do */
5210 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5211 return NULL;
5212
5213 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5214 * expand_env() would truncate the string. */
5215 if (val != NULL && STRLEN(val) > MAXPATHL)
5216 return NULL;
5217
5218 if (val == NULL)
5219 val = *(char_u **)options[opt_idx].var;
5220
5221 /*
5222 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5223 * Escape spaces when expanding 'tags', they are used to separate file
5224 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005225 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005226 */
5227 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005228 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005229#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005230 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5231#endif
5232 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005233 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5234 return NULL;
5235
5236 return NameBuff;
5237}
5238
5239/*
5240 * After setting various option values: recompute variables that depend on
5241 * option values.
5242 */
5243 static void
5244didset_options()
5245{
5246 /* initialize the table for 'iskeyword' et.al. */
5247 (void)init_chartab();
5248
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005249#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005250 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005251#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005252 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5253#ifdef FEAT_SESSION
5254 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5255 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5256#endif
5257#ifdef FEAT_FOLDING
5258 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5259#endif
5260 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5261#ifdef FEAT_VIRTUALEDIT
5262 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5263#endif
5264#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5265 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5266#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005267#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005268 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005269 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005270 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005271#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005272#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5273 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5274#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005275#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005276 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5277#endif
5278#ifdef FEAT_CMDWIN
5279 /* set cedit_key */
5280 (void)check_cedit();
5281#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005282#ifdef FEAT_LINEBREAK
5283 briopt_check();
5284#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285}
5286
5287/*
5288 * Check for string options that are NULL (normally only termcap options).
5289 */
5290 void
5291check_options()
5292{
5293 int opt_idx;
5294
5295 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5296 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5297 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5298}
5299
5300/*
5301 * Check string options in a buffer for NULL value.
5302 */
5303 void
5304check_buf_options(buf)
5305 buf_T *buf;
5306{
5307#if defined(FEAT_QUICKFIX)
5308 check_string_option(&buf->b_p_bh);
5309 check_string_option(&buf->b_p_bt);
5310#endif
5311#ifdef FEAT_MBYTE
5312 check_string_option(&buf->b_p_fenc);
5313#endif
5314 check_string_option(&buf->b_p_ff);
5315#ifdef FEAT_FIND_ID
5316 check_string_option(&buf->b_p_def);
5317 check_string_option(&buf->b_p_inc);
5318# ifdef FEAT_EVAL
5319 check_string_option(&buf->b_p_inex);
5320# endif
5321#endif
5322#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5323 check_string_option(&buf->b_p_inde);
5324 check_string_option(&buf->b_p_indk);
5325#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005326#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5327 check_string_option(&buf->b_p_bexpr);
5328#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005329#if defined(FEAT_CRYPT)
5330 check_string_option(&buf->b_p_cm);
5331#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005332#if defined(FEAT_EVAL)
5333 check_string_option(&buf->b_p_fex);
5334#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335#ifdef FEAT_CRYPT
5336 check_string_option(&buf->b_p_key);
5337#endif
5338 check_string_option(&buf->b_p_kp);
5339 check_string_option(&buf->b_p_mps);
5340 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005341 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005342 check_string_option(&buf->b_p_isk);
5343#ifdef FEAT_COMMENTS
5344 check_string_option(&buf->b_p_com);
5345#endif
5346#ifdef FEAT_FOLDING
5347 check_string_option(&buf->b_p_cms);
5348#endif
5349 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005350#ifdef FEAT_TEXTOBJ
5351 check_string_option(&buf->b_p_qe);
5352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353#ifdef FEAT_SYN_HL
5354 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005355#endif
5356#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005357 check_string_option(&buf->b_s.b_p_spc);
5358 check_string_option(&buf->b_s.b_p_spf);
5359 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005360#endif
5361#ifdef FEAT_SEARCHPATH
5362 check_string_option(&buf->b_p_sua);
5363#endif
5364#ifdef FEAT_CINDENT
5365 check_string_option(&buf->b_p_cink);
5366 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005367 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005368#endif
5369#ifdef FEAT_AUTOCMD
5370 check_string_option(&buf->b_p_ft);
5371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5373 check_string_option(&buf->b_p_cinw);
5374#endif
5375#ifdef FEAT_INS_EXPAND
5376 check_string_option(&buf->b_p_cpt);
5377#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005378#ifdef FEAT_COMPL_FUNC
5379 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005380 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005382#ifdef FEAT_KEYMAP
5383 check_string_option(&buf->b_p_keymap);
5384#endif
5385#ifdef FEAT_QUICKFIX
5386 check_string_option(&buf->b_p_gp);
5387 check_string_option(&buf->b_p_mp);
5388 check_string_option(&buf->b_p_efm);
5389#endif
5390 check_string_option(&buf->b_p_ep);
5391 check_string_option(&buf->b_p_path);
5392 check_string_option(&buf->b_p_tags);
5393#ifdef FEAT_INS_EXPAND
5394 check_string_option(&buf->b_p_dict);
5395 check_string_option(&buf->b_p_tsr);
5396#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005397#ifdef FEAT_LISP
5398 check_string_option(&buf->b_p_lw);
5399#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005400}
5401
5402/*
5403 * Free the string allocated for an option.
5404 * Checks for the string being empty_option. This may happen if we're out of
5405 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5406 * check_options().
5407 * Does NOT check for P_ALLOCED flag!
5408 */
5409 void
5410free_string_option(p)
5411 char_u *p;
5412{
5413 if (p != empty_option)
5414 vim_free(p);
5415}
5416
5417 void
5418clear_string_option(pp)
5419 char_u **pp;
5420{
5421 if (*pp != empty_option)
5422 vim_free(*pp);
5423 *pp = empty_option;
5424}
5425
5426 static void
5427check_string_option(pp)
5428 char_u **pp;
5429{
5430 if (*pp == NULL)
5431 *pp = empty_option;
5432}
5433
5434/*
5435 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5436 */
5437 void
5438set_term_option_alloced(p)
5439 char_u **p;
5440{
5441 int opt_idx;
5442
5443 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5444 if (options[opt_idx].var == (char_u *)p)
5445 {
5446 options[opt_idx].flags |= P_ALLOCED;
5447 return;
5448 }
5449 return; /* cannot happen: didn't find it! */
5450}
5451
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005452#if defined(FEAT_EVAL) || defined(PROTO)
5453/*
5454 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5455 * Return FALSE when it wasn't.
5456 * Return -1 for an unknown option.
5457 */
5458 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005459was_set_insecurely(opt, opt_flags)
5460 char_u *opt;
5461 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005462{
5463 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005464 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005465
5466 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005467 {
5468 flagp = insecure_flag(idx, opt_flags);
5469 return (*flagp & P_INSECURE) != 0;
5470 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005471 EMSG2(_(e_intern2), "was_set_insecurely()");
5472 return -1;
5473}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005474
5475/*
5476 * Get a pointer to the flags used for the P_INSECURE flag of option
5477 * "opt_idx". For some local options a local flags field is used.
5478 */
5479 static long_u *
5480insecure_flag(opt_idx, opt_flags)
5481 int opt_idx;
5482 int opt_flags;
5483{
5484 if (opt_flags & OPT_LOCAL)
5485 switch ((int)options[opt_idx].indir)
5486 {
5487#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005488 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005489#endif
5490#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005491# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005492 case PV_FDE: return &curwin->w_p_fde_flags;
5493 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005494# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005495# ifdef FEAT_BEVAL
5496 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5497# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005498# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005499 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005500# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005501 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005502# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005503 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005504# endif
5505#endif
5506 }
5507
5508 /* Nothing special, return global flags field. */
5509 return &options[opt_idx].flags;
5510}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005511#endif
5512
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005513#ifdef FEAT_TITLE
5514static void redraw_titles __ARGS((void));
5515
5516/*
5517 * Redraw the window title and/or tab page text later.
5518 */
5519static void redraw_titles()
5520{
5521 need_maketitle = TRUE;
5522# ifdef FEAT_WINDOWS
5523 redraw_tabline = TRUE;
5524# endif
5525}
5526#endif
5527
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528/*
5529 * Set a string option to a new value (without checking the effect).
5530 * The string is copied into allocated memory.
5531 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005532 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005533 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005534 */
5535 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005536set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005537 char_u *name;
5538 int opt_idx;
5539 char_u *val;
5540 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005541 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005542{
5543 char_u *s;
5544 char_u **varp;
5545 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005546 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547
Bram Moolenaar89d40322006-08-29 15:30:07 +00005548 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005550 idx = findoption(name);
5551 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005552 {
5553 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005554 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005555 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005556 }
5557
Bram Moolenaar89d40322006-08-29 15:30:07 +00005558 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559 return;
5560
5561 s = vim_strsave(val);
5562 if (s != NULL)
5563 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005564 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005565 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005566 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005567 free_string_option(*varp);
5568 *varp = s;
5569
5570 /* For buffer/window local option may also set the global value. */
5571 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005572 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573
Bram Moolenaar89d40322006-08-29 15:30:07 +00005574 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575
5576 /* When setting both values of a global option with a local value,
5577 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005578 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005579 {
5580 free_string_option(*varp);
5581 *varp = empty_option;
5582 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005583# ifdef FEAT_EVAL
5584 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005585 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005586 set_sid == 0 ? current_SID : set_sid);
5587# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588 }
5589}
5590
5591/*
5592 * Set global value for string option when it's a local option.
5593 */
5594 static void
5595set_string_option_global(opt_idx, varp)
5596 int opt_idx; /* option index */
5597 char_u **varp; /* pointer to option variable */
5598{
5599 char_u **p, *s;
5600
5601 /* the global value is always allocated */
5602 if (options[opt_idx].var == VAR_WIN)
5603 p = (char_u **)GLOBAL_WO(varp);
5604 else
5605 p = (char_u **)options[opt_idx].var;
5606 if (options[opt_idx].indir != PV_NONE
5607 && p != varp
5608 && (s = vim_strsave(*varp)) != NULL)
5609 {
5610 free_string_option(*p);
5611 *p = s;
5612 }
5613}
5614
5615/*
5616 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005617 *
5618 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005619 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005620 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005621set_string_option(opt_idx, value, opt_flags)
5622 int opt_idx;
5623 char_u *value;
5624 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5625{
5626 char_u *s;
5627 char_u **varp;
5628 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005629 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630
5631 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005632 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005633
5634 s = vim_strsave(value);
5635 if (s != NULL)
5636 {
5637 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5638 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005639 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640 ? OPT_GLOBAL : OPT_LOCAL)
5641 : opt_flags);
5642 oldval = *varp;
5643 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005644 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5645 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005646 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005647 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005648 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649}
5650
5651/*
5652 * Handle string options that need some action to perform when changed.
5653 * Returns NULL for success, or an error message for an error.
5654 */
5655 static char_u *
5656did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5657 opt_flags)
5658 int opt_idx; /* index in options[] table */
5659 char_u **varp; /* pointer to the option variable */
5660 int new_value_alloced; /* new value was allocated */
5661 char_u *oldval; /* previous value of the option */
5662 char_u *errbuf; /* buffer for errors, or NULL */
5663 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5664{
5665 char_u *errmsg = NULL;
5666 char_u *s, *p;
5667 int did_chartab = FALSE;
5668 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005669 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005670#ifdef FEAT_GUI
5671 /* set when changing an option that only requires a redraw in the GUI */
5672 int redraw_gui_only = FALSE;
5673#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005674
5675 /* Get the global option to compare with, otherwise we would have to check
5676 * two values for all local options. */
5677 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5678
5679 /* Disallow changing some options from secure mode */
5680 if ((secure
5681#ifdef HAVE_SANDBOX
5682 || sandbox != 0
5683#endif
5684 ) && (options[opt_idx].flags & P_SECURE))
5685 {
5686 errmsg = e_secure;
5687 }
5688
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005689 /* Check for a "normal" file name in some options. Disallow a path
5690 * separator (slash and/or backslash), wildcards and characters that are
5691 * often illegal in a file name. */
5692 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005693 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005694 {
5695 errmsg = e_invarg;
5696 }
5697
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698 /* 'term' */
5699 else if (varp == &T_NAME)
5700 {
5701 if (T_NAME[0] == NUL)
5702 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5703#ifdef FEAT_GUI
5704 if (gui.in_use)
5705 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5706 else if (term_is_gui(T_NAME))
5707 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5708#endif
5709 else if (set_termname(T_NAME) == FAIL)
5710 errmsg = (char_u *)N_("E522: Not found in termcap");
5711 else
5712 /* Screen colors may have changed. */
5713 redraw_later_clear();
5714 }
5715
5716 /* 'backupcopy' */
5717 else if (varp == &p_bkc)
5718 {
5719 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5720 errmsg = e_invarg;
5721 if (((bkc_flags & BKC_AUTO) != 0)
5722 + ((bkc_flags & BKC_YES) != 0)
5723 + ((bkc_flags & BKC_NO) != 0) != 1)
5724 {
5725 /* Must have exactly one of "auto", "yes" and "no". */
5726 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5727 errmsg = e_invarg;
5728 }
5729 }
5730
5731 /* 'backupext' and 'patchmode' */
5732 else if (varp == &p_bex || varp == &p_pm)
5733 {
5734 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5735 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5736 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5737 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005738#ifdef FEAT_LINEBREAK
5739 /* 'breakindentopt' */
5740 else if (varp == &curwin->w_p_briopt)
5741 {
5742 if (briopt_check() == FAIL)
5743 errmsg = e_invarg;
5744 }
5745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746
5747 /*
5748 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5749 * If the new option is invalid, use old value. 'lisp' option: refill
5750 * chartab[] for '-' char
5751 */
5752 else if ( varp == &p_isi
5753 || varp == &(curbuf->b_p_isk)
5754 || varp == &p_isp
5755 || varp == &p_isf)
5756 {
5757 if (init_chartab() == FAIL)
5758 {
5759 did_chartab = TRUE; /* need to restore it below */
5760 errmsg = e_invarg; /* error in value */
5761 }
5762 }
5763
5764 /* 'helpfile' */
5765 else if (varp == &p_hf)
5766 {
5767 /* May compute new values for $VIM and $VIMRUNTIME */
5768 if (didset_vim)
5769 {
5770 vim_setenv((char_u *)"VIM", (char_u *)"");
5771 didset_vim = FALSE;
5772 }
5773 if (didset_vimruntime)
5774 {
5775 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5776 didset_vimruntime = FALSE;
5777 }
5778 }
5779
Bram Moolenaar1a384422010-07-14 19:53:30 +02005780#ifdef FEAT_SYN_HL
5781 /* 'colorcolumn' */
5782 else if (varp == &curwin->w_p_cc)
5783 errmsg = check_colorcolumn(curwin);
5784#endif
5785
Bram Moolenaar071d4272004-06-13 20:20:40 +00005786#ifdef FEAT_MULTI_LANG
5787 /* 'helplang' */
5788 else if (varp == &p_hlg)
5789 {
5790 /* Check for "", "ab", "ab,cd", etc. */
5791 for (s = p_hlg; *s != NUL; s += 3)
5792 {
5793 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5794 {
5795 errmsg = e_invarg;
5796 break;
5797 }
5798 if (s[2] == NUL)
5799 break;
5800 }
5801 }
5802#endif
5803
5804 /* 'highlight' */
5805 else if (varp == &p_hl)
5806 {
5807 if (highlight_changed() == FAIL)
5808 errmsg = e_invarg; /* invalid flags */
5809 }
5810
5811 /* 'nrformats' */
5812 else if (gvarp == &p_nf)
5813 {
5814 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5815 errmsg = e_invarg;
5816 }
5817
5818#ifdef FEAT_SESSION
5819 /* 'sessionoptions' */
5820 else if (varp == &p_ssop)
5821 {
5822 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5823 errmsg = e_invarg;
5824 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5825 {
5826 /* Don't allow both "sesdir" and "curdir". */
5827 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5828 errmsg = e_invarg;
5829 }
5830 }
5831 /* 'viewoptions' */
5832 else if (varp == &p_vop)
5833 {
5834 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5835 errmsg = e_invarg;
5836 }
5837#endif
5838
5839 /* 'scrollopt' */
5840#ifdef FEAT_SCROLLBIND
5841 else if (varp == &p_sbo)
5842 {
5843 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5844 errmsg = e_invarg;
5845 }
5846#endif
5847
5848 /* 'ambiwidth' */
5849#ifdef FEAT_MBYTE
5850 else if (varp == &p_ambw)
5851 {
5852 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5853 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005854 else if (set_chars_option(&p_lcs) != NULL)
5855 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5856# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5857 else if (set_chars_option(&p_fcs) != NULL)
5858 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5859# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 }
5861#endif
5862
5863 /* 'background' */
5864 else if (varp == &p_bg)
5865 {
5866 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5867 {
5868#ifdef FEAT_EVAL
5869 int dark = (*p_bg == 'd');
5870#endif
5871
5872 init_highlight(FALSE, FALSE);
5873
5874#ifdef FEAT_EVAL
5875 if (dark != (*p_bg == 'd')
5876 && get_var_value((char_u *)"g:colors_name") != NULL)
5877 {
5878 /* The color scheme must have set 'background' back to another
5879 * value, that's not what we want here. Disable the color
5880 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005881 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005882 free_string_option(p_bg);
5883 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5884 check_string_option(&p_bg);
5885 init_highlight(FALSE, FALSE);
5886 }
5887#endif
5888 }
5889 else
5890 errmsg = e_invarg;
5891 }
5892
5893 /* 'wildmode' */
5894 else if (varp == &p_wim)
5895 {
5896 if (check_opt_wim() == FAIL)
5897 errmsg = e_invarg;
5898 }
5899
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005900#ifdef FEAT_CMDL_COMPL
5901 /* 'wildoptions' */
5902 else if (varp == &p_wop)
5903 {
5904 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5905 errmsg = e_invarg;
5906 }
5907#endif
5908
Bram Moolenaar071d4272004-06-13 20:20:40 +00005909#ifdef FEAT_WAK
5910 /* 'winaltkeys' */
5911 else if (varp == &p_wak)
5912 {
5913 if (*p_wak == NUL
5914 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5915 errmsg = e_invarg;
5916# ifdef FEAT_MENU
5917# ifdef FEAT_GUI_MOTIF
5918 else if (gui.in_use)
5919 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5920# else
5921# ifdef FEAT_GUI_GTK
5922 else if (gui.in_use)
5923 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5924# endif
5925# endif
5926# endif
5927 }
5928#endif
5929
5930#ifdef FEAT_AUTOCMD
5931 /* 'eventignore' */
5932 else if (varp == &p_ei)
5933 {
5934 if (check_ei() == FAIL)
5935 errmsg = e_invarg;
5936 }
5937#endif
5938
5939#ifdef FEAT_MBYTE
5940 /* 'encoding' and 'fileencoding' */
5941 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5942 {
5943 if (gvarp == &p_fenc)
5944 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005945 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946 errmsg = e_modifiable;
5947 else if (vim_strchr(*varp, ',') != NULL)
5948 /* No comma allowed in 'fileencoding'; catches confusing it
5949 * with 'fileencodings'. */
5950 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005951 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005952 {
5953# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005954 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005955 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005957 /* Add 'fileencoding' to the swap file. */
5958 ml_setflags(curbuf);
5959 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005960 }
5961 if (errmsg == NULL)
5962 {
5963 /* canonize the value, so that STRCMP() can be used on it */
5964 p = enc_canonize(*varp);
5965 if (p != NULL)
5966 {
5967 vim_free(*varp);
5968 *varp = p;
5969 }
5970 if (varp == &p_enc)
5971 {
5972 errmsg = mb_init();
5973# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005974 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975# endif
5976 }
5977 }
5978
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005979# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005980 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5981 {
5982 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5983 if (STRCMP(p_tenc, "utf-8") != 0)
5984 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5985 }
5986# endif
5987
5988 if (errmsg == NULL)
5989 {
5990# ifdef FEAT_KEYMAP
5991 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5992 * (with another encoding). */
5993 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5994 (void)keymap_init();
5995# endif
5996
5997 /* When 'termencoding' is not empty and 'encoding' changes or when
5998 * 'termencoding' changes, need to setup for keyboard input and
5999 * display output conversion. */
6000 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6001 {
6002 convert_setup(&input_conv, p_tenc, p_enc);
6003 convert_setup(&output_conv, p_enc, p_tenc);
6004 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006005
6006# if defined(WIN3264) && defined(FEAT_MBYTE)
6007 /* $HOME may have characters in active code page. */
6008 if (varp == &p_enc)
6009 init_homedir();
6010# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011 }
6012 }
6013#endif
6014
6015#if defined(FEAT_POSTSCRIPT)
6016 else if (varp == &p_penc)
6017 {
6018 /* Canonize printencoding if VIM standard one */
6019 p = enc_canonize(p_penc);
6020 if (p != NULL)
6021 {
6022 vim_free(p_penc);
6023 p_penc = p;
6024 }
6025 else
6026 {
6027 /* Ensure lower case and '-' for '_' */
6028 for (s = p_penc; *s != NUL; s++)
6029 {
6030 if (*s == '_')
6031 *s = '-';
6032 else
6033 *s = TOLOWER_ASC(*s);
6034 }
6035 }
6036 }
6037#endif
6038
Bram Moolenaar9372a112005-12-06 19:59:18 +00006039#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006040 else if (varp == &p_imak)
6041 {
6042 if (gui.in_use && !im_xim_isvalid_imactivate())
6043 errmsg = e_invarg;
6044 }
6045#endif
6046
6047#ifdef FEAT_KEYMAP
6048 else if (varp == &curbuf->b_p_keymap)
6049 {
6050 /* load or unload key mapping tables */
6051 errmsg = keymap_init();
6052
Bram Moolenaarfab06232009-03-04 03:13:35 +00006053 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006054 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006055 if (*curbuf->b_p_keymap != NUL)
6056 {
6057 /* Installed a new keymap, switch on using it. */
6058 curbuf->b_p_iminsert = B_IMODE_LMAP;
6059 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6060 curbuf->b_p_imsearch = B_IMODE_LMAP;
6061 }
6062 else
6063 {
6064 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6065 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6066 curbuf->b_p_iminsert = B_IMODE_NONE;
6067 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6068 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6069 }
6070 if ((opt_flags & OPT_LOCAL) == 0)
6071 {
6072 set_iminsert_global();
6073 set_imsearch_global();
6074 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006075# ifdef FEAT_WINDOWS
6076 status_redraw_curbuf();
6077# endif
6078 }
6079 }
6080#endif
6081
6082 /* 'fileformat' */
6083 else if (gvarp == &p_ff)
6084 {
6085 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6086 errmsg = e_modifiable;
6087 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6088 errmsg = e_invarg;
6089 else
6090 {
6091 /* may also change 'textmode' */
6092 if (get_fileformat(curbuf) == EOL_DOS)
6093 curbuf->b_p_tx = TRUE;
6094 else
6095 curbuf->b_p_tx = FALSE;
6096#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006097 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006098#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006099 /* update flag in swap file */
6100 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006101 /* Redraw needed when switching to/from "mac": a CR in the text
6102 * will be displayed differently. */
6103 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6104 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006105 }
6106 }
6107
6108 /* 'fileformats' */
6109 else if (varp == &p_ffs)
6110 {
6111 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6112 errmsg = e_invarg;
6113 else
6114 {
6115 /* also change 'textauto' */
6116 if (*p_ffs == NUL)
6117 p_ta = FALSE;
6118 else
6119 p_ta = TRUE;
6120 }
6121 }
6122
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006123#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 /* 'cryptkey' */
6125 else if (gvarp == &p_key)
6126 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006127# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006128 /* Make sure the ":set" command doesn't show the new value in the
6129 * history. */
6130 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006131# endif
6132 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6133 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006134 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6135 }
6136
6137 else if (gvarp == &p_cm)
6138 {
6139 if (opt_flags & OPT_LOCAL)
6140 p = curbuf->b_p_cm;
6141 else
6142 p = p_cm;
6143 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6144 errmsg = e_invarg;
6145 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6146 errmsg = e_invarg;
6147 else
6148 {
6149 /* When setting the global value to empty, make it "zip". */
6150 if (*p_cm == NUL)
6151 {
6152 if (new_value_alloced)
6153 free_string_option(p_cm);
6154 p_cm = vim_strsave((char_u *)"zip");
6155 new_value_alloced = TRUE;
6156 }
6157
6158 /* Need to update the swapfile when the effective method changed.
6159 * Set "s" to the effective old value, "p" to the effective new
6160 * method and compare. */
6161 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6162 s = p_cm; /* was previously using the global value */
6163 else
6164 s = oldval;
6165 if (*curbuf->b_p_cm == NUL)
6166 p = p_cm; /* is now using the global value */
6167 else
6168 p = curbuf->b_p_cm;
6169 if (STRCMP(s, p) != 0)
6170 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6171 crypt_method_from_string(s));
6172
6173 /* If the global value changes need to update the swapfile for all
6174 * buffers using that value. */
6175 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6176 {
6177 buf_T *buf;
6178
6179 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6180 if (buf != curbuf && *buf->b_p_cm == NUL)
6181 ml_set_crypt_key(buf, buf->b_p_key,
6182 crypt_method_from_string(oldval));
6183 }
6184 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006185 }
6186#endif
6187
6188 /* 'matchpairs' */
6189 else if (gvarp == &p_mps)
6190 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006191#ifdef FEAT_MBYTE
6192 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006193 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006194 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006195 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006196 int x2 = -1;
6197 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006198
6199 if (*p != NUL)
6200 p += mb_ptr2len(p);
6201 if (*p != NUL)
6202 x2 = *p++;
6203 if (*p != NUL)
6204 {
6205 x3 = mb_ptr2char(p);
6206 p += mb_ptr2len(p);
6207 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006208 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006209 {
6210 errmsg = e_invarg;
6211 break;
6212 }
6213 if (*p == NUL)
6214 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006215 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006216 }
6217 else
6218#endif
6219 {
6220 /* Check for "x:y,x:y" */
6221 for (p = *varp; *p != NUL; p += 4)
6222 {
6223 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6224 {
6225 errmsg = e_invarg;
6226 break;
6227 }
6228 if (p[3] == NUL)
6229 break;
6230 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006231 }
6232 }
6233
6234#ifdef FEAT_COMMENTS
6235 /* 'comments' */
6236 else if (gvarp == &p_com)
6237 {
6238 for (s = *varp; *s; )
6239 {
6240 while (*s && *s != ':')
6241 {
6242 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6243 && !VIM_ISDIGIT(*s) && *s != '-')
6244 {
6245 errmsg = illegal_char(errbuf, *s);
6246 break;
6247 }
6248 ++s;
6249 }
6250 if (*s++ == NUL)
6251 errmsg = (char_u *)N_("E524: Missing colon");
6252 else if (*s == ',' || *s == NUL)
6253 errmsg = (char_u *)N_("E525: Zero length string");
6254 if (errmsg != NULL)
6255 break;
6256 while (*s && *s != ',')
6257 {
6258 if (*s == '\\' && s[1] != NUL)
6259 ++s;
6260 ++s;
6261 }
6262 s = skip_to_option_part(s);
6263 }
6264 }
6265#endif
6266
6267 /* 'listchars' */
6268 else if (varp == &p_lcs)
6269 {
6270 errmsg = set_chars_option(varp);
6271 }
6272
6273#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6274 /* 'fillchars' */
6275 else if (varp == &p_fcs)
6276 {
6277 errmsg = set_chars_option(varp);
6278 }
6279#endif
6280
6281#ifdef FEAT_CMDWIN
6282 /* 'cedit' */
6283 else if (varp == &p_cedit)
6284 {
6285 errmsg = check_cedit();
6286 }
6287#endif
6288
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006289 /* 'verbosefile' */
6290 else if (varp == &p_vfile)
6291 {
6292 verbose_stop();
6293 if (*p_vfile != NUL && verbose_open() == FAIL)
6294 errmsg = e_invarg;
6295 }
6296
Bram Moolenaar071d4272004-06-13 20:20:40 +00006297#ifdef FEAT_VIMINFO
6298 /* 'viminfo' */
6299 else if (varp == &p_viminfo)
6300 {
6301 for (s = p_viminfo; *s;)
6302 {
6303 /* Check it's a valid character */
6304 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6305 {
6306 errmsg = illegal_char(errbuf, *s);
6307 break;
6308 }
6309 if (*s == 'n') /* name is always last one */
6310 {
6311 break;
6312 }
6313 else if (*s == 'r') /* skip until next ',' */
6314 {
6315 while (*++s && *s != ',')
6316 ;
6317 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006318 else if (*s == '%')
6319 {
6320 /* optional number */
6321 while (vim_isdigit(*++s))
6322 ;
6323 }
6324 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325 ++s; /* no extra chars */
6326 else /* must have a number */
6327 {
6328 while (vim_isdigit(*++s))
6329 ;
6330
6331 if (!VIM_ISDIGIT(*(s - 1)))
6332 {
6333 if (errbuf != NULL)
6334 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006335 sprintf((char *)errbuf,
6336 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006337 transchar_byte(*(s - 1)));
6338 errmsg = errbuf;
6339 }
6340 else
6341 errmsg = (char_u *)"";
6342 break;
6343 }
6344 }
6345 if (*s == ',')
6346 ++s;
6347 else if (*s)
6348 {
6349 if (errbuf != NULL)
6350 errmsg = (char_u *)N_("E527: Missing comma");
6351 else
6352 errmsg = (char_u *)"";
6353 break;
6354 }
6355 }
6356 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6357 errmsg = (char_u *)N_("E528: Must specify a ' value");
6358 }
6359#endif /* FEAT_VIMINFO */
6360
6361 /* terminal options */
6362 else if (istermoption(&options[opt_idx]) && full_screen)
6363 {
6364 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6365 if (varp == &T_CCO)
6366 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006367 int colors = atoi((char *)T_CCO);
6368
6369 /* Only reinitialize colors if t_Co value has really changed to
6370 * avoid expensive reload of colorscheme if t_Co is set to the
6371 * same value multiple times. */
6372 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006373 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006374 t_colors = colors;
6375 if (t_colors <= 1)
6376 {
6377 if (new_value_alloced)
6378 vim_free(T_CCO);
6379 T_CCO = empty_option;
6380 }
6381 /* We now have a different color setup, initialize it again. */
6382 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006384 }
6385 ttest(FALSE);
6386 if (varp == &T_ME)
6387 {
6388 out_str(T_ME);
6389 redraw_later(CLEAR);
6390#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6391 /* Since t_me has been set, this probably means that the user
6392 * wants to use this as default colors. Need to reset default
6393 * background/foreground colors. */
6394 mch_set_normal_colors();
6395#endif
6396 }
6397 }
6398
6399#ifdef FEAT_LINEBREAK
6400 /* 'showbreak' */
6401 else if (varp == &p_sbr)
6402 {
6403 for (s = p_sbr; *s; )
6404 {
6405 if (ptr2cells(s) != 1)
6406 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006407 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 }
6409 }
6410#endif
6411
6412#ifdef FEAT_GUI
6413 /* 'guifont' */
6414 else if (varp == &p_guifont)
6415 {
6416 if (gui.in_use)
6417 {
6418 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006419# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006420 /*
6421 * Put up a font dialog and let the user select a new value.
6422 * If this is cancelled go back to the old value but don't
6423 * give an error message.
6424 */
6425 if (STRCMP(p, "*") == 0)
6426 {
6427 p = gui_mch_font_dialog(oldval);
6428
6429 if (new_value_alloced)
6430 free_string_option(p_guifont);
6431
6432 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6433 new_value_alloced = TRUE;
6434 }
6435# endif
6436 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6437 {
6438# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6439 if (STRCMP(p_guifont, "*") == 0)
6440 {
6441 /* Dialog was cancelled: Keep the old value without giving
6442 * an error message. */
6443 if (new_value_alloced)
6444 free_string_option(p_guifont);
6445 p_guifont = vim_strsave(oldval);
6446 new_value_alloced = TRUE;
6447 }
6448 else
6449# endif
6450 errmsg = (char_u *)N_("E596: Invalid font(s)");
6451 }
6452 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006453 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454 }
6455# ifdef FEAT_XFONTSET
6456 else if (varp == &p_guifontset)
6457 {
6458 if (STRCMP(p_guifontset, "*") == 0)
6459 errmsg = (char_u *)N_("E597: can't select fontset");
6460 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6461 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006462 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006463 }
6464# endif
6465# ifdef FEAT_MBYTE
6466 else if (varp == &p_guifontwide)
6467 {
6468 if (STRCMP(p_guifontwide, "*") == 0)
6469 errmsg = (char_u *)N_("E533: can't select wide font");
6470 else if (gui_get_wide_font() == FAIL)
6471 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006472 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006473 }
6474# endif
6475#endif
6476
6477#ifdef CURSOR_SHAPE
6478 /* 'guicursor' */
6479 else if (varp == &p_guicursor)
6480 errmsg = parse_shape_opt(SHAPE_CURSOR);
6481#endif
6482
6483#ifdef FEAT_MOUSESHAPE
6484 /* 'mouseshape' */
6485 else if (varp == &p_mouseshape)
6486 {
6487 errmsg = parse_shape_opt(SHAPE_MOUSE);
6488 update_mouseshape(-1);
6489 }
6490#endif
6491
6492#ifdef FEAT_PRINTER
6493 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006494 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006495# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006496 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006497 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006498# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006499#endif
6500
6501#ifdef FEAT_LANGMAP
6502 /* 'langmap' */
6503 else if (varp == &p_langmap)
6504 langmap_set();
6505#endif
6506
6507#ifdef FEAT_LINEBREAK
6508 /* 'breakat' */
6509 else if (varp == &p_breakat)
6510 fill_breakat_flags();
6511#endif
6512
6513#ifdef FEAT_TITLE
6514 /* 'titlestring' and 'iconstring' */
6515 else if (varp == &p_titlestring || varp == &p_iconstring)
6516 {
6517# ifdef FEAT_STL_OPT
6518 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6519
6520 /* NULL => statusline syntax */
6521 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6522 stl_syntax |= flagval;
6523 else
6524 stl_syntax &= ~flagval;
6525# endif
6526 did_set_title(varp == &p_iconstring);
6527
6528 }
6529#endif
6530
6531#ifdef FEAT_GUI
6532 /* 'guioptions' */
6533 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006534 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006535 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006536 redraw_gui_only = TRUE;
6537 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006538#endif
6539
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006540#if defined(FEAT_GUI_TABLINE)
6541 /* 'guitablabel' */
6542 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006543 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006544 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006545 redraw_gui_only = TRUE;
6546 }
6547 /* 'guitabtooltip' */
6548 else if (varp == &p_gtt)
6549 {
6550 redraw_gui_only = TRUE;
6551 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006552#endif
6553
Bram Moolenaar071d4272004-06-13 20:20:40 +00006554#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6555 /* 'ttymouse' */
6556 else if (varp == &p_ttym)
6557 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006558 /* Switch the mouse off before changing the escape sequences used for
6559 * that. */
6560 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006561 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6562 errmsg = e_invarg;
6563 else
6564 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006565 if (termcap_active)
6566 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006567 }
6568#endif
6569
Bram Moolenaar071d4272004-06-13 20:20:40 +00006570 /* 'selection' */
6571 else if (varp == &p_sel)
6572 {
6573 if (*p_sel == NUL
6574 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6575 errmsg = e_invarg;
6576 }
6577
6578 /* 'selectmode' */
6579 else if (varp == &p_slm)
6580 {
6581 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6582 errmsg = e_invarg;
6583 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006584
6585#ifdef FEAT_BROWSE
6586 /* 'browsedir' */
6587 else if (varp == &p_bsdir)
6588 {
6589 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6590 && !mch_isdir(p_bsdir))
6591 errmsg = e_invarg;
6592 }
6593#endif
6594
Bram Moolenaar071d4272004-06-13 20:20:40 +00006595 /* 'keymodel' */
6596 else if (varp == &p_km)
6597 {
6598 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6599 errmsg = e_invarg;
6600 else
6601 {
6602 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6603 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6604 }
6605 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606
6607 /* 'mousemodel' */
6608 else if (varp == &p_mousem)
6609 {
6610 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6611 errmsg = e_invarg;
6612#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6613 else if (*p_mousem != *oldval)
6614 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6615 * to create or delete the popup menus. */
6616 gui_motif_update_mousemodel(root_menu);
6617#endif
6618 }
6619
6620 /* 'switchbuf' */
6621 else if (varp == &p_swb)
6622 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006623 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 errmsg = e_invarg;
6625 }
6626
6627 /* 'debug' */
6628 else if (varp == &p_debug)
6629 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006630 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631 errmsg = e_invarg;
6632 }
6633
6634 /* 'display' */
6635 else if (varp == &p_dy)
6636 {
6637 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6638 errmsg = e_invarg;
6639 else
6640 (void)init_chartab();
6641
6642 }
6643
6644#ifdef FEAT_VERTSPLIT
6645 /* 'eadirection' */
6646 else if (varp == &p_ead)
6647 {
6648 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6649 errmsg = e_invarg;
6650 }
6651#endif
6652
6653#ifdef FEAT_CLIPBOARD
6654 /* 'clipboard' */
6655 else if (varp == &p_cb)
6656 errmsg = check_clipboard_option();
6657#endif
6658
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006659#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006660 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6661 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006662 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006663 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006664 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006665 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006666
Bram Moolenaar860cae12010-06-05 23:22:07 +02006667 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006668 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006669 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6670 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006671 ".add") != 0))
6672 errmsg = e_invarg;
6673 }
6674
6675 if (errmsg == NULL)
6676 {
6677 FOR_ALL_WINDOWS(wp)
6678 if (wp->w_buffer == curbuf && wp->w_p_spell)
6679 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006680 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006681# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006682 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006683# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006684 }
6685 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006686 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006687 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006688 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006689 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006690 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006691 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006692 /* 'spellsuggest' */
6693 else if (varp == &p_sps)
6694 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006695 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006696 errmsg = e_invarg;
6697 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006698 /* 'mkspellmem' */
6699 else if (varp == &p_msm)
6700 {
6701 if (spell_check_msm() != OK)
6702 errmsg = e_invarg;
6703 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006704#endif
6705
Bram Moolenaar071d4272004-06-13 20:20:40 +00006706#ifdef FEAT_QUICKFIX
6707 /* When 'bufhidden' is set, check for valid value. */
6708 else if (gvarp == &p_bh)
6709 {
6710 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6711 errmsg = e_invarg;
6712 }
6713
6714 /* When 'buftype' is set, check for valid value. */
6715 else if (gvarp == &p_bt)
6716 {
6717 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6718 errmsg = e_invarg;
6719 else
6720 {
6721# ifdef FEAT_WINDOWS
6722 if (curwin->w_status_height)
6723 {
6724 curwin->w_redr_status = TRUE;
6725 redraw_later(VALID);
6726 }
6727# endif
6728 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006729# ifdef FEAT_TITLE
6730 redraw_titles();
6731# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006732 }
6733 }
6734#endif
6735
6736#ifdef FEAT_STL_OPT
6737 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006738 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006739 {
6740 int wid;
6741
6742 if (varp == &p_ruf) /* reset ru_wid first */
6743 ru_wid = 0;
6744 s = *varp;
6745 if (varp == &p_ruf && *s == '%')
6746 {
6747 /* set ru_wid if 'ruf' starts with "%99(" */
6748 if (*++s == '-') /* ignore a '-' */
6749 s++;
6750 wid = getdigits(&s);
6751 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6752 ru_wid = wid;
6753 else
6754 errmsg = check_stl_option(p_ruf);
6755 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006756 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006757 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006758 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006759 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006760 comp_col();
6761 }
6762#endif
6763
6764#ifdef FEAT_INS_EXPAND
6765 /* check if it is a valid value for 'complete' -- Acevedo */
6766 else if (gvarp == &p_cpt)
6767 {
6768 for (s = *varp; *s;)
6769 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006770 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006771 s++;
6772 if (!*s)
6773 break;
6774 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6775 {
6776 errmsg = illegal_char(errbuf, *s);
6777 break;
6778 }
6779 if (*++s != NUL && *s != ',' && *s != ' ')
6780 {
6781 if (s[-1] == 'k' || s[-1] == 's')
6782 {
6783 /* skip optional filename after 'k' and 's' */
6784 while (*s && *s != ',' && *s != ' ')
6785 {
6786 if (*s == '\\')
6787 ++s;
6788 ++s;
6789 }
6790 }
6791 else
6792 {
6793 if (errbuf != NULL)
6794 {
6795 sprintf((char *)errbuf,
6796 _("E535: Illegal character after <%c>"),
6797 *--s);
6798 errmsg = errbuf;
6799 }
6800 else
6801 errmsg = (char_u *)"";
6802 break;
6803 }
6804 }
6805 }
6806 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006807
6808 /* 'completeopt' */
6809 else if (varp == &p_cot)
6810 {
6811 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6812 errmsg = e_invarg;
6813 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006814#endif /* FEAT_INS_EXPAND */
6815
6816
6817#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6818 else if (varp == &p_toolbar)
6819 {
6820 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6821 &toolbar_flags, TRUE) != OK)
6822 errmsg = e_invarg;
6823 else
6824 {
6825 out_flush();
6826 gui_mch_show_toolbar((toolbar_flags &
6827 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6828 }
6829 }
6830#endif
6831
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006832#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006833 /* 'toolbariconsize': GTK+ 2 only */
6834 else if (varp == &p_tbis)
6835 {
6836 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6837 errmsg = e_invarg;
6838 else
6839 {
6840 out_flush();
6841 gui_mch_show_toolbar((toolbar_flags &
6842 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6843 }
6844 }
6845#endif
6846
6847 /* 'pastetoggle': translate key codes like in a mapping */
6848 else if (varp == &p_pt)
6849 {
6850 if (*p_pt)
6851 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006852 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006853 if (p != NULL)
6854 {
6855 if (new_value_alloced)
6856 free_string_option(p_pt);
6857 p_pt = p;
6858 new_value_alloced = TRUE;
6859 }
6860 }
6861 }
6862
6863 /* 'backspace' */
6864 else if (varp == &p_bs)
6865 {
6866 if (VIM_ISDIGIT(*p_bs))
6867 {
6868 if (*p_bs >'2' || p_bs[1] != NUL)
6869 errmsg = e_invarg;
6870 }
6871 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6872 errmsg = e_invarg;
6873 }
6874
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006875#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006876 /* 'casemap' */
6877 else if (varp == &p_cmp)
6878 {
6879 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6880 errmsg = e_invarg;
6881 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006882#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006883
6884#ifdef FEAT_DIFF
6885 /* 'diffopt' */
6886 else if (varp == &p_dip)
6887 {
6888 if (diffopt_changed() == FAIL)
6889 errmsg = e_invarg;
6890 }
6891#endif
6892
6893#ifdef FEAT_FOLDING
6894 /* 'foldmethod' */
6895 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6896 {
6897 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6898 || *curwin->w_p_fdm == NUL)
6899 errmsg = e_invarg;
6900 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006901 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006902 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006903 if (foldmethodIsDiff(curwin))
6904 newFoldLevel();
6905 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906 }
6907# ifdef FEAT_EVAL
6908 /* 'foldexpr' */
6909 else if (varp == &curwin->w_p_fde)
6910 {
6911 if (foldmethodIsExpr(curwin))
6912 foldUpdateAll(curwin);
6913 }
6914# endif
6915 /* 'foldmarker' */
6916 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6917 {
6918 p = vim_strchr(*varp, ',');
6919 if (p == NULL)
6920 errmsg = (char_u *)N_("E536: comma required");
6921 else if (p == *varp || p[1] == NUL)
6922 errmsg = e_invarg;
6923 else if (foldmethodIsMarker(curwin))
6924 foldUpdateAll(curwin);
6925 }
6926 /* 'commentstring' */
6927 else if (gvarp == &p_cms)
6928 {
6929 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6930 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6931 }
6932 /* 'foldopen' */
6933 else if (varp == &p_fdo)
6934 {
6935 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6936 errmsg = e_invarg;
6937 }
6938 /* 'foldclose' */
6939 else if (varp == &p_fcl)
6940 {
6941 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6942 errmsg = e_invarg;
6943 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006944 /* 'foldignore' */
6945 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6946 {
6947 if (foldmethodIsIndent(curwin))
6948 foldUpdateAll(curwin);
6949 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006950#endif
6951
6952#ifdef FEAT_VIRTUALEDIT
6953 /* 'virtualedit' */
6954 else if (varp == &p_ve)
6955 {
6956 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6957 errmsg = e_invarg;
6958 else if (STRCMP(p_ve, oldval) != 0)
6959 {
6960 /* Recompute cursor position in case the new 've' setting
6961 * changes something. */
6962 validate_virtcol();
6963 coladvance(curwin->w_virtcol);
6964 }
6965 }
6966#endif
6967
6968#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6969 else if (varp == &p_csqf)
6970 {
6971 if (p_csqf != NULL)
6972 {
6973 p = p_csqf;
6974 while (*p != NUL)
6975 {
6976 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6977 || p[1] == NUL
6978 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6979 || (p[2] != NUL && p[2] != ','))
6980 {
6981 errmsg = e_invarg;
6982 break;
6983 }
6984 else if (p[2] == NUL)
6985 break;
6986 else
6987 p += 3;
6988 }
6989 }
6990 }
6991#endif
6992
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01006993#ifdef FEAT_CINDENT
6994 /* 'cinoptions' */
6995 else if (gvarp == &p_cino)
6996 {
6997 /* TODO: recognize errors */
6998 parse_cino(curbuf);
6999 }
7000#endif
7001
Bram Moolenaar071d4272004-06-13 20:20:40 +00007002 /* Options that are a list of flags. */
7003 else
7004 {
7005 p = NULL;
7006 if (varp == &p_ww)
7007 p = (char_u *)WW_ALL;
7008 if (varp == &p_shm)
7009 p = (char_u *)SHM_ALL;
7010 else if (varp == &(p_cpo))
7011 p = (char_u *)CPO_ALL;
7012 else if (varp == &(curbuf->b_p_fo))
7013 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007014#ifdef FEAT_CONCEAL
7015 else if (varp == &curwin->w_p_cocu)
7016 p = (char_u *)COCU_ALL;
7017#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018 else if (varp == &p_mouse)
7019 {
7020#ifdef FEAT_MOUSE
7021 p = (char_u *)MOUSE_ALL;
7022#else
7023 if (*p_mouse != NUL)
7024 errmsg = (char_u *)N_("E538: No mouse support");
7025#endif
7026 }
7027#if defined(FEAT_GUI)
7028 else if (varp == &p_go)
7029 p = (char_u *)GO_ALL;
7030#endif
7031 if (p != NULL)
7032 {
7033 for (s = *varp; *s; ++s)
7034 if (vim_strchr(p, *s) == NULL)
7035 {
7036 errmsg = illegal_char(errbuf, *s);
7037 break;
7038 }
7039 }
7040 }
7041
7042 /*
7043 * If error detected, restore the previous value.
7044 */
7045 if (errmsg != NULL)
7046 {
7047 if (new_value_alloced)
7048 free_string_option(*varp);
7049 *varp = oldval;
7050 /*
7051 * When resetting some values, need to act on it.
7052 */
7053 if (did_chartab)
7054 (void)init_chartab();
7055 if (varp == &p_hl)
7056 (void)highlight_changed();
7057 }
7058 else
7059 {
7060#ifdef FEAT_EVAL
7061 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007062 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063#endif
7064 /*
7065 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007066 * Use "free_oldval", because recursiveness may change the flags under
7067 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007068 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007069 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 free_string_option(oldval);
7071 if (new_value_alloced)
7072 options[opt_idx].flags |= P_ALLOCED;
7073 else
7074 options[opt_idx].flags &= ~P_ALLOCED;
7075
7076 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007077 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 {
7079 /* global option with local value set to use global value; free
7080 * the local value and make it empty */
7081 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7082 free_string_option(*(char_u **)p);
7083 *(char_u **)p = empty_option;
7084 }
7085
7086 /* May set global value for local option. */
7087 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7088 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007089
7090#ifdef FEAT_AUTOCMD
7091 /*
7092 * Trigger the autocommand only after setting the flags.
7093 */
7094# ifdef FEAT_SYN_HL
7095 /* When 'syntax' is set, load the syntax of that name */
7096 if (varp == &(curbuf->b_p_syn))
7097 {
7098 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7099 curbuf->b_fname, TRUE, curbuf);
7100 }
7101# endif
7102 else if (varp == &(curbuf->b_p_ft))
7103 {
7104 /* 'filetype' is set, trigger the FileType autocommand */
7105 did_filetype = TRUE;
7106 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7107 curbuf->b_fname, TRUE, curbuf);
7108 }
7109#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007110#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007111 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007112 {
7113 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007114 char_u *q = curwin->w_s->b_p_spl;
7115
7116 /* Skip the first name if it is "cjk". */
7117 if (STRNCMP(q, "cjk,", 4) == 0)
7118 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007119
7120 /*
7121 * Source the spell/LANG.vim in 'runtimepath'.
7122 * They could set 'spellcapcheck' depending on the language.
7123 * Use the first name in 'spelllang' up to '_region' or
7124 * '.encoding'.
7125 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007126 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007127 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7128 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007129 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007130 source_runtime(fname, TRUE);
7131 }
7132#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 }
7134
7135#ifdef FEAT_MOUSE
7136 if (varp == &p_mouse)
7137 {
7138# ifdef FEAT_MOUSE_TTY
7139 if (*p_mouse == NUL)
7140 mch_setmouse(FALSE); /* switch mouse off */
7141 else
7142# endif
7143 setmouse(); /* in case 'mouse' changed */
7144 }
7145#endif
7146
Bram Moolenaar913077c2012-03-28 19:59:04 +02007147 if (curwin->w_curswant != MAXCOL
7148 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7149 curwin->w_set_curswant = TRUE;
7150
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007151#ifdef FEAT_GUI
7152 /* check redraw when it's not a GUI option or the GUI is active. */
7153 if (!redraw_gui_only || gui.in_use)
7154#endif
7155 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007156
7157 return errmsg;
7158}
7159
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007160#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007161/*
7162 * Simple int comparison function for use with qsort()
7163 */
7164 static int
7165int_cmp(a, b)
7166 const void *a;
7167 const void *b;
7168{
7169 return *(const int *)a - *(const int *)b;
7170}
7171
7172/*
7173 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7174 * Returns error message, NULL if it's OK.
7175 */
7176 char_u *
7177check_colorcolumn(wp)
7178 win_T *wp;
7179{
7180 char_u *s;
7181 int col;
7182 int count = 0;
7183 int color_cols[256];
7184 int i;
7185 int j = 0;
7186
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007187 if (wp->w_buffer == NULL)
7188 return NULL; /* buffer was closed */
7189
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007190 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007191 {
7192 if (*s == '-' || *s == '+')
7193 {
7194 /* -N and +N: add to 'textwidth' */
7195 col = (*s == '-') ? -1 : 1;
7196 ++s;
7197 if (!VIM_ISDIGIT(*s))
7198 return e_invarg;
7199 col = col * getdigits(&s);
7200 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007201 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007202 col += wp->w_buffer->b_p_tw;
7203 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007204 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007205 }
7206 else if (VIM_ISDIGIT(*s))
7207 col = getdigits(&s);
7208 else
7209 return e_invarg;
7210 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007211skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007212 if (*s == NUL)
7213 break;
7214 if (*s != ',')
7215 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007216 if (*++s == NUL)
7217 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007218 }
7219
7220 vim_free(wp->w_p_cc_cols);
7221 if (count == 0)
7222 wp->w_p_cc_cols = NULL;
7223 else
7224 {
7225 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7226 if (wp->w_p_cc_cols != NULL)
7227 {
7228 /* sort the columns for faster usage on screen redraw inside
7229 * win_line() */
7230 qsort(color_cols, count, sizeof(int), int_cmp);
7231
7232 for (i = 0; i < count; ++i)
7233 /* skip duplicates */
7234 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7235 wp->w_p_cc_cols[j++] = color_cols[i];
7236 wp->w_p_cc_cols[j] = -1; /* end marker */
7237 }
7238 }
7239
7240 return NULL; /* no error */
7241}
7242#endif
7243
Bram Moolenaar071d4272004-06-13 20:20:40 +00007244/*
7245 * Handle setting 'listchars' or 'fillchars'.
7246 * Returns error message, NULL if it's OK.
7247 */
7248 static char_u *
7249set_chars_option(varp)
7250 char_u **varp;
7251{
7252 int round, i, len, entries;
7253 char_u *p, *s;
7254 int c1, c2 = 0;
7255 struct charstab
7256 {
7257 int *cp;
7258 char *name;
7259 };
7260#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7261 static struct charstab filltab[] =
7262 {
7263 {&fill_stl, "stl"},
7264 {&fill_stlnc, "stlnc"},
7265 {&fill_vert, "vert"},
7266 {&fill_fold, "fold"},
7267 {&fill_diff, "diff"},
7268 };
7269#endif
7270 static struct charstab lcstab[] =
7271 {
7272 {&lcs_eol, "eol"},
7273 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007274 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275 {&lcs_prec, "precedes"},
7276 {&lcs_tab2, "tab"},
7277 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007278#ifdef FEAT_CONCEAL
7279 {&lcs_conceal, "conceal"},
7280#else
7281 {NULL, "conceal"},
7282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007283 };
7284 struct charstab *tab;
7285
7286#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7287 if (varp == &p_lcs)
7288#endif
7289 {
7290 tab = lcstab;
7291 entries = sizeof(lcstab) / sizeof(struct charstab);
7292 }
7293#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7294 else
7295 {
7296 tab = filltab;
7297 entries = sizeof(filltab) / sizeof(struct charstab);
7298 }
7299#endif
7300
7301 /* first round: check for valid value, second round: assign values */
7302 for (round = 0; round <= 1; ++round)
7303 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007304 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007305 {
7306 /* After checking that the value is valid: set defaults: space for
7307 * 'fillchars', NUL for 'listchars' */
7308 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007309 if (tab[i].cp != NULL)
7310 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 if (varp == &p_lcs)
7312 lcs_tab1 = NUL;
7313#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7314 else
7315 fill_diff = '-';
7316#endif
7317 }
7318 p = *varp;
7319 while (*p)
7320 {
7321 for (i = 0; i < entries; ++i)
7322 {
7323 len = (int)STRLEN(tab[i].name);
7324 if (STRNCMP(p, tab[i].name, len) == 0
7325 && p[len] == ':'
7326 && p[len + 1] != NUL)
7327 {
7328 s = p + len + 1;
7329#ifdef FEAT_MBYTE
7330 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007331 if (mb_char2cells(c1) > 1)
7332 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007333#else
7334 c1 = *s++;
7335#endif
7336 if (tab[i].cp == &lcs_tab2)
7337 {
7338 if (*s == NUL)
7339 continue;
7340#ifdef FEAT_MBYTE
7341 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007342 if (mb_char2cells(c2) > 1)
7343 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007344#else
7345 c2 = *s++;
7346#endif
7347 }
7348 if (*s == ',' || *s == NUL)
7349 {
7350 if (round)
7351 {
7352 if (tab[i].cp == &lcs_tab2)
7353 {
7354 lcs_tab1 = c1;
7355 lcs_tab2 = c2;
7356 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007357 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007358 *(tab[i].cp) = c1;
7359
7360 }
7361 p = s;
7362 break;
7363 }
7364 }
7365 }
7366
7367 if (i == entries)
7368 return e_invarg;
7369 if (*p == ',')
7370 ++p;
7371 }
7372 }
7373
7374 return NULL; /* no error */
7375}
7376
7377#ifdef FEAT_STL_OPT
7378/*
7379 * Check validity of options with the 'statusline' format.
7380 * Return error message or NULL.
7381 */
7382 char_u *
7383check_stl_option(s)
7384 char_u *s;
7385{
7386 int itemcnt = 0;
7387 int groupdepth = 0;
7388 static char_u errbuf[80];
7389
7390 while (*s && itemcnt < STL_MAX_ITEM)
7391 {
7392 /* Check for valid keys after % sequences */
7393 while (*s && *s != '%')
7394 s++;
7395 if (!*s)
7396 break;
7397 s++;
7398 if (*s != '%' && *s != ')')
7399 ++itemcnt;
7400 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7401 {
7402 s++;
7403 continue;
7404 }
7405 if (*s == ')')
7406 {
7407 s++;
7408 if (--groupdepth < 0)
7409 break;
7410 continue;
7411 }
7412 if (*s == '-')
7413 s++;
7414 while (VIM_ISDIGIT(*s))
7415 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007416 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007417 continue;
7418 if (*s == '.')
7419 {
7420 s++;
7421 while (*s && VIM_ISDIGIT(*s))
7422 s++;
7423 }
7424 if (*s == '(')
7425 {
7426 groupdepth++;
7427 continue;
7428 }
7429 if (vim_strchr(STL_ALL, *s) == NULL)
7430 {
7431 return illegal_char(errbuf, *s);
7432 }
7433 if (*s == '{')
7434 {
7435 s++;
7436 while (*s != '}' && *s)
7437 s++;
7438 if (*s != '}')
7439 return (char_u *)N_("E540: Unclosed expression sequence");
7440 }
7441 }
7442 if (itemcnt >= STL_MAX_ITEM)
7443 return (char_u *)N_("E541: too many items");
7444 if (groupdepth != 0)
7445 return (char_u *)N_("E542: unbalanced groups");
7446 return NULL;
7447}
7448#endif
7449
7450#ifdef FEAT_CLIPBOARD
7451/*
7452 * Extract the items in the 'clipboard' option and set global values.
7453 */
7454 static char_u *
7455check_clipboard_option()
7456{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007457 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007458 int new_autoselect_star = FALSE;
7459 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007461 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462 regprog_T *new_exclude_prog = NULL;
7463 char_u *errmsg = NULL;
7464 char_u *p;
7465
7466 for (p = p_cb; *p != NUL; )
7467 {
7468 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7469 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007470 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007471 p += 7;
7472 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007473 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007474 && (p[11] == ',' || p[11] == NUL))
7475 {
7476 new_unnamed |= CLIP_UNNAMED_PLUS;
7477 p += 11;
7478 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007479 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007480 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007481 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007482 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007483 p += 10;
7484 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007485 else if (STRNCMP(p, "autoselectplus", 14) == 0
7486 && (p[14] == ',' || p[14] == NUL))
7487 {
7488 new_autoselect_plus = TRUE;
7489 p += 14;
7490 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007492 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007493 {
7494 new_autoselectml = TRUE;
7495 p += 12;
7496 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007497 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7498 {
7499 new_html = TRUE;
7500 p += 4;
7501 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007502 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7503 {
7504 p += 8;
7505 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7506 if (new_exclude_prog == NULL)
7507 errmsg = e_invarg;
7508 break;
7509 }
7510 else
7511 {
7512 errmsg = e_invarg;
7513 break;
7514 }
7515 if (*p == ',')
7516 ++p;
7517 }
7518 if (errmsg == NULL)
7519 {
7520 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007521 clip_autoselect_star = new_autoselect_star;
7522 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007523 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007524 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007525 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007526 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007527#ifdef FEAT_GUI_GTK
7528 if (gui.in_use)
7529 {
7530 gui_gtk_set_selection_targets();
7531 gui_gtk_set_dnd_targets();
7532 }
7533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007534 }
7535 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007536 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007537
7538 return errmsg;
7539}
7540#endif
7541
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007542#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007543/*
7544 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7545 * Return error message when failed, NULL when OK.
7546 */
7547 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007548compile_cap_prog(synblock)
7549 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007550{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007551 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007552 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007553
Bram Moolenaar860cae12010-06-05 23:22:07 +02007554 if (*synblock->b_p_spc == NUL)
7555 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007556 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007557 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007558 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007559 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007560 if (re != NULL)
7561 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007562 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007563 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007564 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007565 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007566 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007567 return e_invarg;
7568 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007569 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007570 }
7571
Bram Moolenaar473de612013-06-08 18:19:48 +02007572 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007573 return NULL;
7574}
7575#endif
7576
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007577#if defined(FEAT_EVAL) || defined(PROTO)
7578/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007579 * Set the scriptID for an option, taking care of setting the buffer- or
7580 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007581 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007582 static void
7583set_option_scriptID_idx(opt_idx, opt_flags, id)
7584 int opt_idx;
7585 int opt_flags;
7586 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007587{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007588 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7589 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007590
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007591 /* Remember where the option was set. For local options need to do that
7592 * in the buffer or window structure. */
7593 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007594 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007595 if (both || (opt_flags & OPT_LOCAL))
7596 {
7597 if (indir & PV_BUF)
7598 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7599 else if (indir & PV_WIN)
7600 curwin->w_p_scriptID[indir & PV_MASK] = id;
7601 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007602}
7603#endif
7604
Bram Moolenaar071d4272004-06-13 20:20:40 +00007605/*
7606 * Set the value of a boolean option, and take care of side effects.
7607 * Returns NULL for success, or an error message for an error.
7608 */
7609 static char_u *
7610set_bool_option(opt_idx, varp, value, opt_flags)
7611 int opt_idx; /* index in options[] table */
7612 char_u *varp; /* pointer to the option variable */
7613 int value; /* new value */
7614 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7615{
7616 int old_value = *(int *)varp;
7617
Bram Moolenaar071d4272004-06-13 20:20:40 +00007618 /* Disallow changing some options from secure mode */
7619 if ((secure
7620#ifdef HAVE_SANDBOX
7621 || sandbox != 0
7622#endif
7623 ) && (options[opt_idx].flags & P_SECURE))
7624 return e_secure;
7625
7626 *(int *)varp = value; /* set the new value */
7627#ifdef FEAT_EVAL
7628 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007629 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007630#endif
7631
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007632#ifdef FEAT_GUI
7633 need_mouse_correct = TRUE;
7634#endif
7635
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636 /* May set global value for local option. */
7637 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7638 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7639
7640 /*
7641 * Handle side effects of changing a bool option.
7642 */
7643
7644 /* 'compatible' */
7645 if ((int *)varp == &p_cp)
7646 {
7647 compatible_set();
7648 }
7649
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007650#ifdef FEAT_PERSISTENT_UNDO
7651 /* 'undofile' */
7652 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7653 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007654 /* Only take action when the option was set. When reset we do not
7655 * delete the undo file, the option may be set again without making
7656 * any changes in between. */
7657 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007658 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007659 char_u hash[UNDO_HASH_SIZE];
7660 buf_T *save_curbuf = curbuf;
7661
7662 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007663 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007664 /* When 'undofile' is set globally: for every buffer, otherwise
7665 * only for the current buffer: Try to read in the undofile,
7666 * if one exists, the buffer wasn't changed and the buffer was
7667 * loaded */
7668 if ((curbuf == save_curbuf
7669 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7670 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7671 {
7672 u_compute_hash(hash);
7673 u_read_undo(NULL, hash, curbuf->b_fname);
7674 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007675 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007676 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007677 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007678 }
7679#endif
7680
Bram Moolenaar071d4272004-06-13 20:20:40 +00007681 else if ((int *)varp == &curbuf->b_p_ro)
7682 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007683 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007684 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7685 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007686
7687 /* when 'readonly' is set may give W10 again */
7688 if (curbuf->b_p_ro)
7689 curbuf->b_did_warn = FALSE;
7690
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007692 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007693#endif
7694 }
7695
Bram Moolenaar9c449722010-07-20 18:44:27 +02007696#ifdef FEAT_GUI
7697 else if ((int *)varp == &p_mh)
7698 {
7699 if (!p_mh)
7700 gui_mch_mousehide(FALSE);
7701 }
7702#endif
7703
Bram Moolenaara539df02010-08-01 14:35:05 +02007704#ifdef FEAT_TITLE
7705 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007706 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007707 {
7708 redraw_titles();
7709 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710 /* when 'endofline' is changed, redraw the window title */
7711 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007712 {
7713 redraw_titles();
7714 }
7715# ifdef FEAT_MBYTE
7716 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007717 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007718 {
7719 redraw_titles();
7720 }
7721# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007722#endif
7723
7724 /* when 'bin' is set also set some other options */
7725 else if ((int *)varp == &curbuf->b_p_bin)
7726 {
7727 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7728#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007729 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007730#endif
7731 }
7732
7733#ifdef FEAT_AUTOCMD
7734 /* when 'buflisted' changes, trigger autocommands */
7735 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7736 {
7737 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7738 NULL, NULL, TRUE, curbuf);
7739 }
7740#endif
7741
7742 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7743 else if ((int *)varp == &curbuf->b_p_swf)
7744 {
7745 if (curbuf->b_p_swf && p_uc)
7746 ml_open_file(curbuf); /* create the swap file */
7747 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007748 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7749 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 mf_close_file(curbuf, TRUE); /* remove the swap file */
7751 }
7752
7753 /* when 'terse' is set change 'shortmess' */
7754 else if ((int *)varp == &p_terse)
7755 {
7756 char_u *p;
7757
7758 p = vim_strchr(p_shm, SHM_SEARCH);
7759
7760 /* insert 's' in p_shm */
7761 if (p_terse && p == NULL)
7762 {
7763 STRCPY(IObuff, p_shm);
7764 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007765 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766 }
7767 /* remove 's' from p_shm */
7768 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007769 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770 }
7771
7772 /* when 'paste' is set or reset also change other options */
7773 else if ((int *)varp == &p_paste)
7774 {
7775 paste_option_changed();
7776 }
7777
7778 /* when 'insertmode' is set from an autocommand need to do work here */
7779 else if ((int *)varp == &p_im)
7780 {
7781 if (p_im)
7782 {
7783 if ((State & INSERT) == 0)
7784 need_start_insertmode = TRUE;
7785 stop_insert_mode = FALSE;
7786 }
7787 else
7788 {
7789 need_start_insertmode = FALSE;
7790 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007791 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792 clear_cmdline = TRUE; /* remove "(insert)" */
7793 restart_edit = 0;
7794 }
7795 }
7796
7797 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7798 else if ((int *)varp == &p_ic && p_hls)
7799 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007800 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801 }
7802
7803#ifdef FEAT_SEARCH_EXTRA
7804 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7805 else if ((int *)varp == &p_hls)
7806 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007807 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007808 }
7809#endif
7810
7811#ifdef FEAT_SCROLLBIND
7812 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7813 * at the end of normal_cmd() */
7814 else if ((int *)varp == &curwin->w_p_scb)
7815 {
7816 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007817 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007819 curwin->w_scbind_pos = curwin->w_topline;
7820 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007821 }
7822#endif
7823
7824#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7825 /* There can be only one window with 'previewwindow' set. */
7826 else if ((int *)varp == &curwin->w_p_pvw)
7827 {
7828 if (curwin->w_p_pvw)
7829 {
7830 win_T *win;
7831
7832 for (win = firstwin; win != NULL; win = win->w_next)
7833 if (win->w_p_pvw && win != curwin)
7834 {
7835 curwin->w_p_pvw = FALSE;
7836 return (char_u *)N_("E590: A preview window already exists");
7837 }
7838 }
7839 }
7840#endif
7841
7842 /* when 'textmode' is set or reset also change 'fileformat' */
7843 else if ((int *)varp == &curbuf->b_p_tx)
7844 {
7845 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7846 }
7847
7848 /* when 'textauto' is set or reset also change 'fileformats' */
7849 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850 set_string_option_direct((char_u *)"ffs", -1,
7851 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007852 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007853
7854 /*
7855 * When 'lisp' option changes include/exclude '-' in
7856 * keyword characters.
7857 */
7858#ifdef FEAT_LISP
7859 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7860 {
7861 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7862 }
7863#endif
7864
7865#ifdef FEAT_TITLE
7866 /* when 'title' changed, may need to change the title; same for 'icon' */
7867 else if ((int *)varp == &p_title)
7868 {
7869 did_set_title(FALSE);
7870 }
7871
7872 else if ((int *)varp == &p_icon)
7873 {
7874 did_set_title(TRUE);
7875 }
7876#endif
7877
7878 else if ((int *)varp == &curbuf->b_changed)
7879 {
7880 if (!value)
7881 save_file_ff(curbuf); /* Buffer is unchanged */
7882#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007883 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007884#endif
7885#ifdef FEAT_AUTOCMD
7886 modified_was_set = value;
7887#endif
7888 }
7889
7890#ifdef BACKSLASH_IN_FILENAME
7891 else if ((int *)varp == &p_ssl)
7892 {
7893 if (p_ssl)
7894 {
7895 psepc = '/';
7896 psepcN = '\\';
7897 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898 }
7899 else
7900 {
7901 psepc = '\\';
7902 psepcN = '/';
7903 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 }
7905
7906 /* need to adjust the file name arguments and buffer names. */
7907 buflist_slash_adjust();
7908 alist_slash_adjust();
7909# ifdef FEAT_EVAL
7910 scriptnames_slash_adjust();
7911# endif
7912 }
7913#endif
7914
7915 /* If 'wrap' is set, set w_leftcol to zero. */
7916 else if ((int *)varp == &curwin->w_p_wrap)
7917 {
7918 if (curwin->w_p_wrap)
7919 curwin->w_leftcol = 0;
7920 }
7921
7922#ifdef FEAT_WINDOWS
7923 else if ((int *)varp == &p_ea)
7924 {
7925 if (p_ea && !old_value)
7926 win_equal(curwin, FALSE, 0);
7927 }
7928#endif
7929
7930 else if ((int *)varp == &p_wiv)
7931 {
7932 /*
7933 * When 'weirdinvert' changed, set/reset 't_xs'.
7934 * Then set 'weirdinvert' according to value of 't_xs'.
7935 */
7936 if (p_wiv && !old_value)
7937 T_XS = (char_u *)"y";
7938 else if (!p_wiv && old_value)
7939 T_XS = empty_option;
7940 p_wiv = (*T_XS != NUL);
7941 }
7942
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007943#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 else if ((int *)varp == &p_beval)
7945 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007946 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007948 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 gui_mch_disable_beval_area(balloonEval);
7950 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007951#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007952
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007953#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954 else if ((int *)varp == &p_acd)
7955 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007956 /* Change directories when the 'acd' option is set now. */
7957 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 }
7959#endif
7960
7961#ifdef FEAT_DIFF
7962 /* 'diff' */
7963 else if ((int *)varp == &curwin->w_p_diff)
7964 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007965 /* May add or remove the buffer from the list of diff buffers. */
7966 diff_buf_adjust(curwin);
7967# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968 if (foldmethodIsDiff(curwin))
7969 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007970# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007971 }
7972#endif
7973
7974#ifdef USE_IM_CONTROL
7975 /* 'imdisable' */
7976 else if ((int *)varp == &p_imdisable)
7977 {
7978 /* Only de-activate it here, it will be enabled when changing mode. */
7979 if (p_imdisable)
7980 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02007981 else if (State & INSERT)
7982 /* When the option is set from an autocommand, it may need to take
7983 * effect right away. */
7984 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 }
7986#endif
7987
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007988#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007989 /* 'spell' */
7990 else if ((int *)varp == &curwin->w_p_spell)
7991 {
7992 if (curwin->w_p_spell)
7993 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007994 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007995 if (errmsg != NULL)
7996 EMSG(_(errmsg));
7997 }
7998 }
7999#endif
8000
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001#ifdef FEAT_FKMAP
8002 else if ((int *)varp == &p_altkeymap)
8003 {
8004 if (old_value != p_altkeymap)
8005 {
8006 if (!p_altkeymap)
8007 {
8008 p_hkmap = p_fkmap;
8009 p_fkmap = 0;
8010 }
8011 else
8012 {
8013 p_fkmap = p_hkmap;
8014 p_hkmap = 0;
8015 }
8016 (void)init_chartab();
8017 }
8018 }
8019
8020 /*
8021 * In case some second language keymapping options have changed, check
8022 * and correct the setting in a consistent way.
8023 */
8024
8025 /*
8026 * If hkmap or fkmap are set, reset Arabic keymapping.
8027 */
8028 if ((p_hkmap || p_fkmap) && p_altkeymap)
8029 {
8030 p_altkeymap = p_fkmap;
8031# ifdef FEAT_ARABIC
8032 curwin->w_p_arab = FALSE;
8033# endif
8034 (void)init_chartab();
8035 }
8036
8037 /*
8038 * If hkmap set, reset Farsi keymapping.
8039 */
8040 if (p_hkmap && p_altkeymap)
8041 {
8042 p_altkeymap = 0;
8043 p_fkmap = 0;
8044# ifdef FEAT_ARABIC
8045 curwin->w_p_arab = FALSE;
8046# endif
8047 (void)init_chartab();
8048 }
8049
8050 /*
8051 * If fkmap set, reset Hebrew keymapping.
8052 */
8053 if (p_fkmap && !p_altkeymap)
8054 {
8055 p_altkeymap = 1;
8056 p_hkmap = 0;
8057# ifdef FEAT_ARABIC
8058 curwin->w_p_arab = FALSE;
8059# endif
8060 (void)init_chartab();
8061 }
8062#endif
8063
8064#ifdef FEAT_ARABIC
8065 if ((int *)varp == &curwin->w_p_arab)
8066 {
8067 if (curwin->w_p_arab)
8068 {
8069 /*
8070 * 'arabic' is set, handle various sub-settings.
8071 */
8072 if (!p_tbidi)
8073 {
8074 /* set rightleft mode */
8075 if (!curwin->w_p_rl)
8076 {
8077 curwin->w_p_rl = TRUE;
8078 changed_window_setting();
8079 }
8080
8081 /* Enable Arabic shaping (major part of what Arabic requires) */
8082 if (!p_arshape)
8083 {
8084 p_arshape = TRUE;
8085 redraw_later_clear();
8086 }
8087 }
8088
8089 /* Arabic requires a utf-8 encoding, inform the user if its not
8090 * set. */
8091 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008092 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008093 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8094
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008095 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008096 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8097#ifdef FEAT_EVAL
8098 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8099#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008100 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008101
8102# ifdef FEAT_MBYTE
8103 /* set 'delcombine' */
8104 p_deco = TRUE;
8105# endif
8106
8107# ifdef FEAT_KEYMAP
8108 /* Force-set the necessary keymap for arabic */
8109 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8110 OPT_LOCAL);
8111# endif
8112# ifdef FEAT_FKMAP
8113 p_altkeymap = 0;
8114 p_hkmap = 0;
8115 p_fkmap = 0;
8116 (void)init_chartab();
8117# endif
8118 }
8119 else
8120 {
8121 /*
8122 * 'arabic' is reset, handle various sub-settings.
8123 */
8124 if (!p_tbidi)
8125 {
8126 /* reset rightleft mode */
8127 if (curwin->w_p_rl)
8128 {
8129 curwin->w_p_rl = FALSE;
8130 changed_window_setting();
8131 }
8132
8133 /* 'arabicshape' isn't reset, it is a global option and
8134 * another window may still need it "on". */
8135 }
8136
8137 /* 'delcombine' isn't reset, it is a global option and another
8138 * window may still want it "on". */
8139
8140# ifdef FEAT_KEYMAP
8141 /* Revert to the default keymap */
8142 curbuf->b_p_iminsert = B_IMODE_NONE;
8143 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8144# endif
8145 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008146 }
8147
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008148#endif
8149
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 /*
8151 * End of handling side effects for bool options.
8152 */
8153
8154 options[opt_idx].flags |= P_WAS_SET;
8155
8156 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008157 if (curwin->w_curswant != MAXCOL
8158 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8159 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 check_redraw(options[opt_idx].flags);
8161
8162 return NULL;
8163}
8164
8165/*
8166 * Set the value of a number option, and take care of side effects.
8167 * Returns NULL for success, or an error message for an error.
8168 */
8169 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008170set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 int opt_idx; /* index in options[] table */
8172 char_u *varp; /* pointer to the option variable */
8173 long value; /* new value */
8174 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008175 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008176 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8177 OPT_MODELINE */
8178{
8179 char_u *errmsg = NULL;
8180 long old_value = *(long *)varp;
8181 long old_Rows = Rows; /* remember old Rows */
8182 long old_Columns = Columns; /* remember old Columns */
8183 long *pp = (long *)varp;
8184
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008185 /* Disallow changing some options from secure mode. */
8186 if ((secure
8187#ifdef HAVE_SANDBOX
8188 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008190 ) && (options[opt_idx].flags & P_SECURE))
8191 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192
8193 *pp = value;
8194#ifdef FEAT_EVAL
8195 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008196 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008198#ifdef FEAT_GUI
8199 need_mouse_correct = TRUE;
8200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008201
Bram Moolenaar14f24742012-08-08 18:01:05 +02008202 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008203 {
8204 errmsg = e_positive;
8205 curbuf->b_p_sw = curbuf->b_p_ts;
8206 }
8207
8208 /*
8209 * Number options that need some action when changed
8210 */
8211#ifdef FEAT_WINDOWS
8212 if (pp == &p_wh || pp == &p_hh)
8213 {
8214 if (p_wh < 1)
8215 {
8216 errmsg = e_positive;
8217 p_wh = 1;
8218 }
8219 if (p_wmh > p_wh)
8220 {
8221 errmsg = e_winheight;
8222 p_wh = p_wmh;
8223 }
8224 if (p_hh < 0)
8225 {
8226 errmsg = e_positive;
8227 p_hh = 0;
8228 }
8229
8230 /* Change window height NOW */
8231 if (lastwin != firstwin)
8232 {
8233 if (pp == &p_wh && curwin->w_height < p_wh)
8234 win_setheight((int)p_wh);
8235 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8236 win_setheight((int)p_hh);
8237 }
8238 }
8239
8240 /* 'winminheight' */
8241 else if (pp == &p_wmh)
8242 {
8243 if (p_wmh < 0)
8244 {
8245 errmsg = e_positive;
8246 p_wmh = 0;
8247 }
8248 if (p_wmh > p_wh)
8249 {
8250 errmsg = e_winheight;
8251 p_wmh = p_wh;
8252 }
8253 win_setminheight();
8254 }
8255
8256# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008257 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008258 {
8259 if (p_wiw < 1)
8260 {
8261 errmsg = e_positive;
8262 p_wiw = 1;
8263 }
8264 if (p_wmw > p_wiw)
8265 {
8266 errmsg = e_winwidth;
8267 p_wiw = p_wmw;
8268 }
8269
8270 /* Change window width NOW */
8271 if (lastwin != firstwin && curwin->w_width < p_wiw)
8272 win_setwidth((int)p_wiw);
8273 }
8274
8275 /* 'winminwidth' */
8276 else if (pp == &p_wmw)
8277 {
8278 if (p_wmw < 0)
8279 {
8280 errmsg = e_positive;
8281 p_wmw = 0;
8282 }
8283 if (p_wmw > p_wiw)
8284 {
8285 errmsg = e_winwidth;
8286 p_wmw = p_wiw;
8287 }
8288 win_setminheight();
8289 }
8290# endif
8291
8292#endif
8293
8294#ifdef FEAT_WINDOWS
8295 /* (re)set last window status line */
8296 else if (pp == &p_ls)
8297 {
8298 last_status(FALSE);
8299 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008300
8301 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008302 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008303 {
8304 shell_new_rows(); /* recompute window positions and heights */
8305 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306#endif
8307
8308#ifdef FEAT_GUI
8309 else if (pp == &p_linespace)
8310 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008311 /* Recompute gui.char_height and resize the Vim window to keep the
8312 * same number of lines. */
8313 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008314 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008315 }
8316#endif
8317
8318#ifdef FEAT_FOLDING
8319 /* 'foldlevel' */
8320 else if (pp == &curwin->w_p_fdl)
8321 {
8322 if (curwin->w_p_fdl < 0)
8323 curwin->w_p_fdl = 0;
8324 newFoldLevel();
8325 }
8326
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008327 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008328 else if (pp == &curwin->w_p_fml)
8329 {
8330 foldUpdateAll(curwin);
8331 }
8332
8333 /* 'foldnestmax' */
8334 else if (pp == &curwin->w_p_fdn)
8335 {
8336 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8337 foldUpdateAll(curwin);
8338 }
8339
8340 /* 'foldcolumn' */
8341 else if (pp == &curwin->w_p_fdc)
8342 {
8343 if (curwin->w_p_fdc < 0)
8344 {
8345 errmsg = e_positive;
8346 curwin->w_p_fdc = 0;
8347 }
8348 else if (curwin->w_p_fdc > 12)
8349 {
8350 errmsg = e_invarg;
8351 curwin->w_p_fdc = 12;
8352 }
8353 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008354#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008355
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008356#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008357 /* 'shiftwidth' or 'tabstop' */
8358 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8359 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008360# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008361 if (foldmethodIsIndent(curwin))
8362 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008363# endif
8364# ifdef FEAT_CINDENT
8365 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8366 * parse 'cinoptions'. */
8367 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8368 parse_cino(curbuf);
8369# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008373#ifdef FEAT_MBYTE
8374 /* 'maxcombine' */
8375 else if (pp == &p_mco)
8376 {
8377 if (p_mco > MAX_MCO)
8378 p_mco = MAX_MCO;
8379 else if (p_mco < 0)
8380 p_mco = 0;
8381 screenclear(); /* will re-allocate the screen */
8382 }
8383#endif
8384
Bram Moolenaar071d4272004-06-13 20:20:40 +00008385 else if (pp == &curbuf->b_p_iminsert)
8386 {
8387 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8388 {
8389 errmsg = e_invarg;
8390 curbuf->b_p_iminsert = B_IMODE_NONE;
8391 }
8392 p_iminsert = curbuf->b_p_iminsert;
8393 if (termcap_active) /* don't do this in the alternate screen */
8394 showmode();
8395#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8396 /* Show/unshow value of 'keymap' in status lines. */
8397 status_redraw_curbuf();
8398#endif
8399 }
8400
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008401 else if (pp == &p_window)
8402 {
8403 if (p_window < 1)
8404 p_window = 1;
8405 else if (p_window >= Rows)
8406 p_window = Rows - 1;
8407 }
8408
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409 else if (pp == &curbuf->b_p_imsearch)
8410 {
8411 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8412 {
8413 errmsg = e_invarg;
8414 curbuf->b_p_imsearch = B_IMODE_NONE;
8415 }
8416 p_imsearch = curbuf->b_p_imsearch;
8417 }
8418
8419#ifdef FEAT_TITLE
8420 /* if 'titlelen' has changed, redraw the title */
8421 else if (pp == &p_titlelen)
8422 {
8423 if (p_titlelen < 0)
8424 {
8425 errmsg = e_positive;
8426 p_titlelen = 85;
8427 }
8428 if (starting != NO_SCREEN && old_value != p_titlelen)
8429 need_maketitle = TRUE;
8430 }
8431#endif
8432
8433 /* if p_ch changed value, change the command line height */
8434 else if (pp == &p_ch)
8435 {
8436 if (p_ch < 1)
8437 {
8438 errmsg = e_positive;
8439 p_ch = 1;
8440 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008441 if (p_ch > Rows - min_rows() + 1)
8442 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443
8444 /* Only compute the new window layout when startup has been
8445 * completed. Otherwise the frame sizes may be wrong. */
8446 if (p_ch != old_value && full_screen
8447#ifdef FEAT_GUI
8448 && !gui.starting
8449#endif
8450 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008451 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008452 }
8453
8454 /* when 'updatecount' changes from zero to non-zero, open swap files */
8455 else if (pp == &p_uc)
8456 {
8457 if (p_uc < 0)
8458 {
8459 errmsg = e_positive;
8460 p_uc = 100;
8461 }
8462 if (p_uc && !old_value)
8463 ml_open_files();
8464 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008465#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008466 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008467 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008468 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008469 {
8470 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008471 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008472 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008473 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008474 {
8475 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008476 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008477 }
8478 }
8479#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008480#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008481 else if (pp == &p_mzq)
8482 mzvim_reset_timer();
8483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008484
8485 /* sync undo before 'undolevels' changes */
8486 else if (pp == &p_ul)
8487 {
8488 /* use the old value, otherwise u_sync() may not work properly */
8489 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008490 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008491 p_ul = value;
8492 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008493 else if (pp == &curbuf->b_p_ul)
8494 {
8495 /* use the old value, otherwise u_sync() may not work properly */
8496 curbuf->b_p_ul = old_value;
8497 u_sync(TRUE);
8498 curbuf->b_p_ul = value;
8499 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008501#ifdef FEAT_LINEBREAK
8502 /* 'numberwidth' must be positive */
8503 else if (pp == &curwin->w_p_nuw)
8504 {
8505 if (curwin->w_p_nuw < 1)
8506 {
8507 errmsg = e_positive;
8508 curwin->w_p_nuw = 1;
8509 }
8510 if (curwin->w_p_nuw > 10)
8511 {
8512 errmsg = e_invarg;
8513 curwin->w_p_nuw = 10;
8514 }
8515 curwin->w_nrwidth_line_count = 0;
8516 }
8517#endif
8518
Bram Moolenaar1a384422010-07-14 19:53:30 +02008519 else if (pp == &curbuf->b_p_tw)
8520 {
8521 if (curbuf->b_p_tw < 0)
8522 {
8523 errmsg = e_positive;
8524 curbuf->b_p_tw = 0;
8525 }
8526#ifdef FEAT_SYN_HL
8527# ifdef FEAT_WINDOWS
8528 {
8529 win_T *wp;
8530 tabpage_T *tp;
8531
8532 FOR_ALL_TAB_WINDOWS(tp, wp)
8533 check_colorcolumn(wp);
8534 }
8535# else
8536 check_colorcolumn(curwin);
8537# endif
8538#endif
8539 }
8540
Bram Moolenaar071d4272004-06-13 20:20:40 +00008541 /*
8542 * Check the bounds for numeric options here
8543 */
8544 if (Rows < min_rows() && full_screen)
8545 {
8546 if (errbuf != NULL)
8547 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008548 vim_snprintf((char *)errbuf, errbuflen,
8549 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008550 errmsg = errbuf;
8551 }
8552 Rows = min_rows();
8553 }
8554 if (Columns < MIN_COLUMNS && full_screen)
8555 {
8556 if (errbuf != NULL)
8557 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008558 vim_snprintf((char *)errbuf, errbuflen,
8559 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560 errmsg = errbuf;
8561 }
8562 Columns = MIN_COLUMNS;
8563 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008564 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008565
8566#ifdef DJGPP
8567 /* avoid a crash by checking for a too large value of 'columns' */
8568 if (old_Columns != Columns && full_screen && term_console)
8569 mch_check_columns();
8570#endif
8571
8572 /*
8573 * If the screen (shell) height has been changed, assume it is the
8574 * physical screenheight.
8575 */
8576 if (old_Rows != Rows || old_Columns != Columns)
8577 {
8578 /* Changing the screen size is not allowed while updating the screen. */
8579 if (updating_screen)
8580 *pp = old_value;
8581 else if (full_screen
8582#ifdef FEAT_GUI
8583 && !gui.starting
8584#endif
8585 )
8586 set_shellsize((int)Columns, (int)Rows, TRUE);
8587 else
8588 {
8589 /* Postpone the resizing; check the size and cmdline position for
8590 * messages. */
8591 check_shellsize();
8592 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8593 cmdline_row = Rows - p_ch;
8594 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008595 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008596 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008597 }
8598
Bram Moolenaar071d4272004-06-13 20:20:40 +00008599 if (curbuf->b_p_ts <= 0)
8600 {
8601 errmsg = e_positive;
8602 curbuf->b_p_ts = 8;
8603 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008604 if (p_tm < 0)
8605 {
8606 errmsg = e_positive;
8607 p_tm = 0;
8608 }
8609 if ((curwin->w_p_scr <= 0
8610 || (curwin->w_p_scr > curwin->w_height
8611 && curwin->w_height > 0))
8612 && full_screen)
8613 {
8614 if (pp == &(curwin->w_p_scr))
8615 {
8616 if (curwin->w_p_scr != 0)
8617 errmsg = e_scroll;
8618 win_comp_scroll(curwin);
8619 }
8620 /* If 'scroll' became invalid because of a side effect silently adjust
8621 * it. */
8622 else if (curwin->w_p_scr <= 0)
8623 curwin->w_p_scr = 1;
8624 else /* curwin->w_p_scr > curwin->w_height */
8625 curwin->w_p_scr = curwin->w_height;
8626 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008627 if (p_hi < 0)
8628 {
8629 errmsg = e_positive;
8630 p_hi = 0;
8631 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008632 else if (p_hi > 10000)
8633 {
8634 errmsg = e_invarg;
8635 p_hi = 10000;
8636 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008637 if (p_re < 0 || p_re > 2)
8638 {
8639 errmsg = e_invarg;
8640 p_re = 0;
8641 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642 if (p_report < 0)
8643 {
8644 errmsg = e_positive;
8645 p_report = 1;
8646 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008647 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648 {
8649 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8650 p_sj = Rows / 2;
8651 else
8652 {
8653 errmsg = e_scroll;
8654 p_sj = 1;
8655 }
8656 }
8657 if (p_so < 0 && full_screen)
8658 {
8659 errmsg = e_scroll;
8660 p_so = 0;
8661 }
8662 if (p_siso < 0 && full_screen)
8663 {
8664 errmsg = e_positive;
8665 p_siso = 0;
8666 }
8667#ifdef FEAT_CMDWIN
8668 if (p_cwh < 1)
8669 {
8670 errmsg = e_positive;
8671 p_cwh = 1;
8672 }
8673#endif
8674 if (p_ut < 0)
8675 {
8676 errmsg = e_positive;
8677 p_ut = 2000;
8678 }
8679 if (p_ss < 0)
8680 {
8681 errmsg = e_positive;
8682 p_ss = 0;
8683 }
8684
8685 /* May set global value for local option. */
8686 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8687 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8688
8689 options[opt_idx].flags |= P_WAS_SET;
8690
8691 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008692 if (curwin->w_curswant != MAXCOL
8693 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8694 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008695 check_redraw(options[opt_idx].flags);
8696
8697 return errmsg;
8698}
8699
8700/*
8701 * Called after an option changed: check if something needs to be redrawn.
8702 */
8703 static void
8704check_redraw(flags)
8705 long_u flags;
8706{
8707 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008708 int doclear = (flags & P_RCLR) == P_RCLR;
8709 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008710
8711#ifdef FEAT_WINDOWS
8712 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8713 status_redraw_all();
8714#endif
8715
8716 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8717 changed_window_setting();
8718 if (flags & P_RBUF)
8719 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008720 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008721 redraw_all_later(CLEAR);
8722 else if (all)
8723 redraw_all_later(NOT_VALID);
8724}
8725
8726/*
8727 * Find index for option 'arg'.
8728 * Return -1 if not found.
8729 */
8730 static int
8731findoption(arg)
8732 char_u *arg;
8733{
8734 int opt_idx;
8735 char *s, *p;
8736 static short quick_tab[27] = {0, 0}; /* quick access table */
8737 int is_term_opt;
8738
8739 /*
8740 * For first call: Initialize the quick-access table.
8741 * It contains the index for the first option that starts with a certain
8742 * letter. There are 26 letters, plus the first "t_" option.
8743 */
8744 if (quick_tab[1] == 0)
8745 {
8746 p = options[0].fullname;
8747 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8748 {
8749 if (s[0] != p[0])
8750 {
8751 if (s[0] == 't' && s[1] == '_')
8752 quick_tab[26] = opt_idx;
8753 else
8754 quick_tab[CharOrdLow(s[0])] = opt_idx;
8755 }
8756 p = s;
8757 }
8758 }
8759
8760 /*
8761 * Check for name starting with an illegal character.
8762 */
8763#ifdef EBCDIC
8764 if (!islower(arg[0]))
8765#else
8766 if (arg[0] < 'a' || arg[0] > 'z')
8767#endif
8768 return -1;
8769
8770 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8771 if (is_term_opt)
8772 opt_idx = quick_tab[26];
8773 else
8774 opt_idx = quick_tab[CharOrdLow(arg[0])];
8775 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8776 {
8777 if (STRCMP(arg, s) == 0) /* match full name */
8778 break;
8779 }
8780 if (s == NULL && !is_term_opt)
8781 {
8782 opt_idx = quick_tab[CharOrdLow(arg[0])];
8783 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8784 {
8785 s = options[opt_idx].shortname;
8786 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8787 break;
8788 s = NULL;
8789 }
8790 }
8791 if (s == NULL)
8792 opt_idx = -1;
8793 return opt_idx;
8794}
8795
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008796#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797/*
8798 * Get the value for an option.
8799 *
8800 * Returns:
8801 * Number or Toggle option: 1, *numval gets value.
8802 * String option: 0, *stringval gets allocated string.
8803 * Hidden Number or Toggle option: -1.
8804 * hidden String option: -2.
8805 * unknown option: -3.
8806 */
8807 int
8808get_option_value(name, numval, stringval, opt_flags)
8809 char_u *name;
8810 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008811 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008812 int opt_flags;
8813{
8814 int opt_idx;
8815 char_u *varp;
8816
8817 opt_idx = findoption(name);
8818 if (opt_idx < 0) /* unknown option */
8819 return -3;
8820
8821 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8822
8823 if (options[opt_idx].flags & P_STRING)
8824 {
8825 if (varp == NULL) /* hidden option */
8826 return -2;
8827 if (stringval != NULL)
8828 {
8829#ifdef FEAT_CRYPT
8830 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008831 if ((char_u **)varp == &curbuf->b_p_key
8832 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833 *stringval = vim_strsave((char_u *)"*****");
8834 else
8835#endif
8836 *stringval = vim_strsave(*(char_u **)(varp));
8837 }
8838 return 0;
8839 }
8840
8841 if (varp == NULL) /* hidden option */
8842 return -1;
8843 if (options[opt_idx].flags & P_NUM)
8844 *numval = *(long *)varp;
8845 else
8846 {
8847 /* Special case: 'modified' is b_changed, but we also want to consider
8848 * it set when 'ff' or 'fenc' changed. */
8849 if ((int *)varp == &curbuf->b_changed)
8850 *numval = curbufIsChanged();
8851 else
8852 *numval = *(int *)varp;
8853 }
8854 return 1;
8855}
8856#endif
8857
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008858#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008859/*
8860 * Returns the option attributes and its value. Unlike the above function it
8861 * will return either global value or local value of the option depending on
8862 * what was requested, but it will never return global value if it was
8863 * requested to return local one and vice versa. Neither it will return
8864 * buffer-local value if it was requested to return window-local one.
8865 *
8866 * Pretends that option is absent if it is not present in the requested scope
8867 * (i.e. has no global, window-local or buffer-local value depending on
8868 * opt_type). Uses
8869 *
8870 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008871 * 0 hidden or unknown option, also option that does not have requested
8872 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008873 * see SOPT_* in vim.h for other flags
8874 *
8875 * Possible opt_type values: see SREQ_* in vim.h
8876 */
8877 int
8878get_option_value_strict(name, numval, stringval, opt_type, from)
8879 char_u *name;
8880 long *numval;
8881 char_u **stringval; /* NULL when only obtaining attributes */
8882 int opt_type;
8883 void *from;
8884{
8885 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008886 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008887 struct vimoption *p;
8888 int r = 0;
8889
8890 opt_idx = findoption(name);
8891 if (opt_idx < 0)
8892 return 0;
8893
8894 p = &(options[opt_idx]);
8895
8896 /* Hidden option */
8897 if (p->var == NULL)
8898 return 0;
8899
8900 if (p->flags & P_BOOL)
8901 r |= SOPT_BOOL;
8902 else if (p->flags & P_NUM)
8903 r |= SOPT_NUM;
8904 else if (p->flags & P_STRING)
8905 r |= SOPT_STRING;
8906
8907 if (p->indir == PV_NONE)
8908 {
8909 if (opt_type == SREQ_GLOBAL)
8910 r |= SOPT_GLOBAL;
8911 else
8912 return 0; /* Did not request global-only option */
8913 }
8914 else
8915 {
8916 if (p->indir & PV_BOTH)
8917 r |= SOPT_GLOBAL;
8918 else if (opt_type == SREQ_GLOBAL)
8919 return 0; /* Requested global option */
8920
8921 if (p->indir & PV_WIN)
8922 {
8923 if (opt_type == SREQ_BUF)
8924 return 0; /* Did not request window-local option */
8925 else
8926 r |= SOPT_WIN;
8927 }
8928 else if (p->indir & PV_BUF)
8929 {
8930 if (opt_type == SREQ_WIN)
8931 return 0; /* Did not request buffer-local option */
8932 else
8933 r |= SOPT_BUF;
8934 }
8935 }
8936
8937 if (stringval == NULL)
8938 return r;
8939
8940 if (opt_type == SREQ_GLOBAL)
8941 varp = p->var;
8942 else
8943 {
8944 if (opt_type == SREQ_BUF)
8945 {
8946 /* Special case: 'modified' is b_changed, but we also want to
8947 * consider it set when 'ff' or 'fenc' changed. */
8948 if (p->indir == PV_MOD)
8949 {
8950 *numval = bufIsChanged((buf_T *) from);
8951 varp = NULL;
8952 }
8953#ifdef FEAT_CRYPT
8954 else if (p->indir == PV_KEY)
8955 {
8956 /* never return the value of the crypt key */
8957 *stringval = NULL;
8958 varp = NULL;
8959 }
8960#endif
8961 else
8962 {
8963 aco_save_T aco;
8964 aucmd_prepbuf(&aco, (buf_T *) from);
8965 varp = get_varp(p);
8966 aucmd_restbuf(&aco);
8967 }
8968 }
8969 else if (opt_type == SREQ_WIN)
8970 {
8971 win_T *save_curwin;
8972 save_curwin = curwin;
8973 curwin = (win_T *) from;
8974 curbuf = curwin->w_buffer;
8975 varp = get_varp(p);
8976 curwin = save_curwin;
8977 curbuf = curwin->w_buffer;
8978 }
8979 if (varp == p->var)
8980 return (r | SOPT_UNSET);
8981 }
8982
8983 if (varp != NULL)
8984 {
8985 if (p->flags & P_STRING)
8986 *stringval = vim_strsave(*(char_u **)(varp));
8987 else if (p->flags & P_NUM)
8988 *numval = *(long *) varp;
8989 else
8990 *numval = *(int *)varp;
8991 }
8992
8993 return r;
8994}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008995
8996/*
8997 * Iterate over options. First argument is a pointer to a pointer to a structure
8998 * inside options[] array, second is option type like in the above function.
8999 *
9000 * If first argument points to NULL it is assumed that iteration just started
9001 * and caller needs the very first value.
9002 * If first argument points to the end marker function returns NULL and sets
9003 * first argument to NULL.
9004 *
9005 * Returns full option name for current option on each call.
9006 */
9007 char_u *
9008option_iter_next(option, opt_type)
9009 void **option;
9010 int opt_type;
9011{
9012 struct vimoption *ret = NULL;
9013 do
9014 {
9015 if (*option == NULL)
9016 *option = (void *) options;
9017 else if (((struct vimoption *) (*option))->fullname == NULL)
9018 {
9019 *option = NULL;
9020 return NULL;
9021 }
9022 else
9023 *option = (void *) (((struct vimoption *) (*option)) + 1);
9024
9025 ret = ((struct vimoption *) (*option));
9026
9027 /* Hidden option */
9028 if (ret->var == NULL)
9029 {
9030 ret = NULL;
9031 continue;
9032 }
9033
9034 switch (opt_type)
9035 {
9036 case SREQ_GLOBAL:
9037 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9038 ret = NULL;
9039 break;
9040 case SREQ_BUF:
9041 if (!(ret->indir & PV_BUF))
9042 ret = NULL;
9043 break;
9044 case SREQ_WIN:
9045 if (!(ret->indir & PV_WIN))
9046 ret = NULL;
9047 break;
9048 default:
9049 EMSG2(_(e_intern2), "option_iter_next()");
9050 return NULL;
9051 }
9052 }
9053 while (ret == NULL);
9054
9055 return (char_u *)ret->fullname;
9056}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009057#endif
9058
Bram Moolenaar071d4272004-06-13 20:20:40 +00009059/*
9060 * Set the value of option "name".
9061 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009062 *
9063 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009064 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009065 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009066set_option_value(name, number, string, opt_flags)
9067 char_u *name;
9068 long number;
9069 char_u *string;
9070 int opt_flags; /* OPT_LOCAL or 0 (both) */
9071{
9072 int opt_idx;
9073 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009074 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075
9076 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009077 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009078 EMSG2(_("E355: Unknown option: %s"), name);
9079 else
9080 {
9081 flags = options[opt_idx].flags;
9082#ifdef HAVE_SANDBOX
9083 /* Disallow changing some options in the sandbox */
9084 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009085 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009086 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009087 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009088 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009089#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009090 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009091 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092 else
9093 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009094 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009095 if (varp != NULL) /* hidden option is not changed */
9096 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009097 if (number == 0 && string != NULL)
9098 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009099 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009100
9101 /* Either we are given a string or we are setting option
9102 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009103 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009104 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009105 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009106 {
9107 /* There's another character after zeros or the string
9108 * is empty. In both cases, we are trying to set a
9109 * num option using a string. */
9110 EMSG3(_("E521: Number required: &%s = '%s'"),
9111 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009112 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009113
9114 }
9115 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009117 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009118 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009119 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009120 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009121 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009122 }
9123 }
9124 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009125 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009126}
9127
9128/*
9129 * Get the terminal code for a terminal option.
9130 * Returns NULL when not found.
9131 */
9132 char_u *
9133get_term_code(tname)
9134 char_u *tname;
9135{
9136 int opt_idx;
9137 char_u *varp;
9138
9139 if (tname[0] != 't' || tname[1] != '_' ||
9140 tname[2] == NUL || tname[3] == NUL)
9141 return NULL;
9142 if ((opt_idx = findoption(tname)) >= 0)
9143 {
9144 varp = get_varp(&(options[opt_idx]));
9145 if (varp != NULL)
9146 varp = *(char_u **)(varp);
9147 return varp;
9148 }
9149 return find_termcode(tname + 2);
9150}
9151
9152 char_u *
9153get_highlight_default()
9154{
9155 int i;
9156
9157 i = findoption((char_u *)"hl");
9158 if (i >= 0)
9159 return options[i].def_val[VI_DEFAULT];
9160 return (char_u *)NULL;
9161}
9162
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009163#if defined(FEAT_MBYTE) || defined(PROTO)
9164 char_u *
9165get_encoding_default()
9166{
9167 int i;
9168
9169 i = findoption((char_u *)"enc");
9170 if (i >= 0)
9171 return options[i].def_val[VI_DEFAULT];
9172 return (char_u *)NULL;
9173}
9174#endif
9175
Bram Moolenaar071d4272004-06-13 20:20:40 +00009176/*
9177 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9178 */
9179 static int
9180find_key_option(arg)
9181 char_u *arg;
9182{
9183 int key;
9184 int modifiers;
9185
9186 /*
9187 * Don't use get_special_key_code() for t_xx, we don't want it to call
9188 * add_termcap_entry().
9189 */
9190 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9191 key = TERMCAP2KEY(arg[2], arg[3]);
9192 else
9193 {
9194 --arg; /* put arg at the '<' */
9195 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009196 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009197 if (modifiers) /* can't handle modifiers here */
9198 key = 0;
9199 }
9200 return key;
9201}
9202
9203/*
9204 * if 'all' == 0: show changed options
9205 * if 'all' == 1: show all normal options
9206 * if 'all' == 2: show all terminal options
9207 */
9208 static void
9209showoptions(all, opt_flags)
9210 int all;
9211 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9212{
9213 struct vimoption *p;
9214 int col;
9215 int isterm;
9216 char_u *varp;
9217 struct vimoption **items;
9218 int item_count;
9219 int run;
9220 int row, rows;
9221 int cols;
9222 int i;
9223 int len;
9224
9225#define INC 20
9226#define GAP 3
9227
9228 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9229 PARAM_COUNT));
9230 if (items == NULL)
9231 return;
9232
9233 /* Highlight title */
9234 if (all == 2)
9235 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9236 else if (opt_flags & OPT_GLOBAL)
9237 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9238 else if (opt_flags & OPT_LOCAL)
9239 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9240 else
9241 MSG_PUTS_TITLE(_("\n--- Options ---"));
9242
9243 /*
9244 * do the loop two times:
9245 * 1. display the short items
9246 * 2. display the long items (only strings and numbers)
9247 */
9248 for (run = 1; run <= 2 && !got_int; ++run)
9249 {
9250 /*
9251 * collect the items in items[]
9252 */
9253 item_count = 0;
9254 for (p = &options[0]; p->fullname != NULL; p++)
9255 {
9256 varp = NULL;
9257 isterm = istermoption(p);
9258 if (opt_flags != 0)
9259 {
9260 if (p->indir != PV_NONE && !isterm)
9261 varp = get_varp_scope(p, opt_flags);
9262 }
9263 else
9264 varp = get_varp(p);
9265 if (varp != NULL
9266 && ((all == 2 && isterm)
9267 || (all == 1 && !isterm)
9268 || (all == 0 && !optval_default(p, varp))))
9269 {
9270 if (p->flags & P_BOOL)
9271 len = 1; /* a toggle option fits always */
9272 else
9273 {
9274 option_value2string(p, opt_flags);
9275 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9276 }
9277 if ((len <= INC - GAP && run == 1) ||
9278 (len > INC - GAP && run == 2))
9279 items[item_count++] = p;
9280 }
9281 }
9282
9283 /*
9284 * display the items
9285 */
9286 if (run == 1)
9287 {
9288 cols = (Columns + GAP - 3) / INC;
9289 if (cols == 0)
9290 cols = 1;
9291 rows = (item_count + cols - 1) / cols;
9292 }
9293 else /* run == 2 */
9294 rows = item_count;
9295 for (row = 0; row < rows && !got_int; ++row)
9296 {
9297 msg_putchar('\n'); /* go to next line */
9298 if (got_int) /* 'q' typed in more */
9299 break;
9300 col = 0;
9301 for (i = row; i < item_count; i += rows)
9302 {
9303 msg_col = col; /* make columns */
9304 showoneopt(items[i], opt_flags);
9305 col += INC;
9306 }
9307 out_flush();
9308 ui_breakcheck();
9309 }
9310 }
9311 vim_free(items);
9312}
9313
9314/*
9315 * Return TRUE if option "p" has its default value.
9316 */
9317 static int
9318optval_default(p, varp)
9319 struct vimoption *p;
9320 char_u *varp;
9321{
9322 int dvi;
9323
9324 if (varp == NULL)
9325 return TRUE; /* hidden option is always at default */
9326 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9327 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009328 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009329 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009330 /* the cast to long is required for Manx C, long_i is
9331 * needed for MSVC */
9332 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009333 /* P_STRING */
9334 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9335}
9336
9337/*
9338 * showoneopt: show the value of one option
9339 * must not be called with a hidden option!
9340 */
9341 static void
9342showoneopt(p, opt_flags)
9343 struct vimoption *p;
9344 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9345{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009346 char_u *varp;
9347 int save_silent = silent_mode;
9348
9349 silent_mode = FALSE;
9350 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009351
9352 varp = get_varp_scope(p, opt_flags);
9353
9354 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9355 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9356 ? !curbufIsChanged() : !*(int *)varp))
9357 MSG_PUTS("no");
9358 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9359 MSG_PUTS("--");
9360 else
9361 MSG_PUTS(" ");
9362 MSG_PUTS(p->fullname);
9363 if (!(p->flags & P_BOOL))
9364 {
9365 msg_putchar('=');
9366 /* put value string in NameBuff */
9367 option_value2string(p, opt_flags);
9368 msg_outtrans(NameBuff);
9369 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009370
9371 silent_mode = save_silent;
9372 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009373}
9374
9375/*
9376 * Write modified options as ":set" commands to a file.
9377 *
9378 * There are three values for "opt_flags":
9379 * OPT_GLOBAL: Write global option values and fresh values of
9380 * buffer-local options (used for start of a session
9381 * file).
9382 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9383 * curwin (used for a vimrc file).
9384 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9385 * and local values for window-local options of
9386 * curwin. Local values are also written when at the
9387 * default value, because a modeline or autocommand
9388 * may have set them when doing ":edit file" and the
9389 * user has set them back at the default or fresh
9390 * value.
9391 * When "local_only" is TRUE, don't write fresh
9392 * values, only local values (for ":mkview").
9393 * (fresh value = value used for a new buffer or window for a local option).
9394 *
9395 * Return FAIL on error, OK otherwise.
9396 */
9397 int
9398makeset(fd, opt_flags, local_only)
9399 FILE *fd;
9400 int opt_flags;
9401 int local_only;
9402{
9403 struct vimoption *p;
9404 char_u *varp; /* currently used value */
9405 char_u *varp_fresh; /* local value */
9406 char_u *varp_local = NULL; /* fresh value */
9407 char *cmd;
9408 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009409 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009410
9411 /*
9412 * The options that don't have a default (terminal name, columns, lines)
9413 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009414 * Do the loop over "options[]" twice: once for options with the
9415 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009417 for (pri = 1; pri >= 0; --pri)
9418 {
9419 for (p = &options[0]; !istermoption(p); p++)
9420 if (!(p->flags & P_NO_MKRC)
9421 && !istermoption(p)
9422 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423 {
9424 /* skip global option when only doing locals */
9425 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9426 continue;
9427
9428 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9429 * file, they are always buffer-specific. */
9430 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9431 continue;
9432
9433 /* Global values are only written when not at the default value. */
9434 varp = get_varp_scope(p, opt_flags);
9435 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9436 continue;
9437
9438 round = 2;
9439 if (p->indir != PV_NONE)
9440 {
9441 if (p->var == VAR_WIN)
9442 {
9443 /* skip window-local option when only doing globals */
9444 if (!(opt_flags & OPT_LOCAL))
9445 continue;
9446 /* When fresh value of window-local option is not at the
9447 * default, need to write it too. */
9448 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9449 {
9450 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9451 if (!optval_default(p, varp_fresh))
9452 {
9453 round = 1;
9454 varp_local = varp;
9455 varp = varp_fresh;
9456 }
9457 }
9458 }
9459 }
9460
9461 /* Round 1: fresh value for window-local options.
9462 * Round 2: other values */
9463 for ( ; round <= 2; varp = varp_local, ++round)
9464 {
9465 if (round == 1 || (opt_flags & OPT_GLOBAL))
9466 cmd = "set";
9467 else
9468 cmd = "setlocal";
9469
9470 if (p->flags & P_BOOL)
9471 {
9472 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9473 return FAIL;
9474 }
9475 else if (p->flags & P_NUM)
9476 {
9477 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9478 return FAIL;
9479 }
9480 else /* P_STRING */
9481 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009482#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9483 int do_endif = FALSE;
9484
Bram Moolenaar071d4272004-06-13 20:20:40 +00009485 /* Don't set 'syntax' and 'filetype' again if the value is
9486 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009487 if (
9488# if defined(FEAT_SYN_HL)
9489 p->indir == PV_SYN
9490# if defined(FEAT_AUTOCMD)
9491 ||
9492# endif
9493# endif
9494# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009495 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009496# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009497 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009498 {
9499 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9500 *(char_u **)(varp)) < 0
9501 || put_eol(fd) < 0)
9502 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009503 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009504 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009506 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9507 (p->flags & P_EXPAND) != 0) == FAIL)
9508 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009509#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9510 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009511 {
9512 if (put_line(fd, "endif") == FAIL)
9513 return FAIL;
9514 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009515#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009516 }
9517 }
9518 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009519 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009520 return OK;
9521}
9522
9523#if defined(FEAT_FOLDING) || defined(PROTO)
9524/*
9525 * Generate set commands for the local fold options only. Used when
9526 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9527 */
9528 int
9529makefoldset(fd)
9530 FILE *fd;
9531{
9532 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9533# ifdef FEAT_EVAL
9534 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9535 == FAIL
9536# endif
9537 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9538 == FAIL
9539 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9540 == FAIL
9541 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9542 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9543 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9544 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9545 )
9546 return FAIL;
9547
9548 return OK;
9549}
9550#endif
9551
9552 static int
9553put_setstring(fd, cmd, name, valuep, expand)
9554 FILE *fd;
9555 char *cmd;
9556 char *name;
9557 char_u **valuep;
9558 int expand;
9559{
9560 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009561 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009562
9563 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9564 return FAIL;
9565 if (*valuep != NULL)
9566 {
9567 /* Output 'pastetoggle' as key names. For other
9568 * options some characters have to be escaped with
9569 * CTRL-V or backslash */
9570 if (valuep == &p_pt)
9571 {
9572 s = *valuep;
9573 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009574 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009575 return FAIL;
9576 }
9577 else if (expand)
9578 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009579 buf = alloc(MAXPATHL);
9580 if (buf == NULL)
9581 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009582 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9583 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009584 {
9585 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009586 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009587 }
9588 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009589 }
9590 else if (put_escstr(fd, *valuep, 2) == FAIL)
9591 return FAIL;
9592 }
9593 if (put_eol(fd) < 0)
9594 return FAIL;
9595 return OK;
9596}
9597
9598 static int
9599put_setnum(fd, cmd, name, valuep)
9600 FILE *fd;
9601 char *cmd;
9602 char *name;
9603 long *valuep;
9604{
9605 long wc;
9606
9607 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9608 return FAIL;
9609 if (wc_use_keyname((char_u *)valuep, &wc))
9610 {
9611 /* print 'wildchar' and 'wildcharm' as a key name */
9612 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9613 return FAIL;
9614 }
9615 else if (fprintf(fd, "%ld", *valuep) < 0)
9616 return FAIL;
9617 if (put_eol(fd) < 0)
9618 return FAIL;
9619 return OK;
9620}
9621
9622 static int
9623put_setbool(fd, cmd, name, value)
9624 FILE *fd;
9625 char *cmd;
9626 char *name;
9627 int value;
9628{
Bram Moolenaar893de922007-10-02 18:40:57 +00009629 if (value < 0) /* global/local option using global value */
9630 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009631 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9632 || put_eol(fd) < 0)
9633 return FAIL;
9634 return OK;
9635}
9636
9637/*
9638 * Clear all the terminal options.
9639 * If the option has been allocated, free the memory.
9640 * Terminal options are never hidden or indirect.
9641 */
9642 void
9643clear_termoptions()
9644{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645 /*
9646 * Reset a few things before clearing the old options. This may cause
9647 * outputting a few things that the terminal doesn't understand, but the
9648 * screen will be cleared later, so this is OK.
9649 */
9650#ifdef FEAT_MOUSE_TTY
9651 mch_setmouse(FALSE); /* switch mouse off */
9652#endif
9653#ifdef FEAT_TITLE
9654 mch_restore_title(3); /* restore window titles */
9655#endif
9656#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9657 /* When starting the GUI close the display opened for the clipboard.
9658 * After restoring the title, because that will need the display. */
9659 if (gui.starting)
9660 clear_xterm_clip();
9661#endif
9662#ifdef WIN3264
9663 /*
9664 * Check if this is allowed now.
9665 */
9666 if (can_end_termcap_mode(FALSE) == TRUE)
9667#endif
9668 stoptermcap(); /* stop termcap mode */
9669
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009670 free_termoptions();
9671}
9672
9673 void
9674free_termoptions()
9675{
9676 struct vimoption *p;
9677
Bram Moolenaar071d4272004-06-13 20:20:40 +00009678 for (p = &options[0]; p->fullname != NULL; p++)
9679 if (istermoption(p))
9680 {
9681 if (p->flags & P_ALLOCED)
9682 free_string_option(*(char_u **)(p->var));
9683 if (p->flags & P_DEF_ALLOCED)
9684 free_string_option(p->def_val[VI_DEFAULT]);
9685 *(char_u **)(p->var) = empty_option;
9686 p->def_val[VI_DEFAULT] = empty_option;
9687 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9688 }
9689 clear_termcodes();
9690}
9691
9692/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009693 * Free the string for one term option, if it was allocated.
9694 * Set the string to empty_option and clear allocated flag.
9695 * "var" points to the option value.
9696 */
9697 void
9698free_one_termoption(var)
9699 char_u *var;
9700{
9701 struct vimoption *p;
9702
9703 for (p = &options[0]; p->fullname != NULL; p++)
9704 if (p->var == var)
9705 {
9706 if (p->flags & P_ALLOCED)
9707 free_string_option(*(char_u **)(p->var));
9708 *(char_u **)(p->var) = empty_option;
9709 p->flags &= ~P_ALLOCED;
9710 break;
9711 }
9712}
9713
9714/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715 * Set the terminal option defaults to the current value.
9716 * Used after setting the terminal name.
9717 */
9718 void
9719set_term_defaults()
9720{
9721 struct vimoption *p;
9722
9723 for (p = &options[0]; p->fullname != NULL; p++)
9724 {
9725 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9726 {
9727 if (p->flags & P_DEF_ALLOCED)
9728 {
9729 free_string_option(p->def_val[VI_DEFAULT]);
9730 p->flags &= ~P_DEF_ALLOCED;
9731 }
9732 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9733 if (p->flags & P_ALLOCED)
9734 {
9735 p->flags |= P_DEF_ALLOCED;
9736 p->flags &= ~P_ALLOCED; /* don't free the value now */
9737 }
9738 }
9739 }
9740}
9741
9742/*
9743 * return TRUE if 'p' starts with 't_'
9744 */
9745 static int
9746istermoption(p)
9747 struct vimoption *p;
9748{
9749 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9750}
9751
9752/*
9753 * Compute columns for ruler and shown command. 'sc_col' is also used to
9754 * decide what the maximum length of a message on the status line can be.
9755 * If there is a status line for the last window, 'sc_col' is independent
9756 * of 'ru_col'.
9757 */
9758
9759#define COL_RULER 17 /* columns needed by standard ruler */
9760
9761 void
9762comp_col()
9763{
9764#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9765 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9766
9767 sc_col = 0;
9768 ru_col = 0;
9769 if (p_ru)
9770 {
9771#ifdef FEAT_STL_OPT
9772 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9773#else
9774 ru_col = COL_RULER + 1;
9775#endif
9776 /* no last status line, adjust sc_col */
9777 if (!last_has_status)
9778 sc_col = ru_col;
9779 }
9780 if (p_sc)
9781 {
9782 sc_col += SHOWCMD_COLS;
9783 if (!p_ru || last_has_status) /* no need for separating space */
9784 ++sc_col;
9785 }
9786 sc_col = Columns - sc_col;
9787 ru_col = Columns - ru_col;
9788 if (sc_col <= 0) /* screen too narrow, will become a mess */
9789 sc_col = 1;
9790 if (ru_col <= 0)
9791 ru_col = 1;
9792#else
9793 sc_col = Columns;
9794 ru_col = Columns;
9795#endif
9796}
9797
9798/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009799 * Unset local option value, similar to ":set opt<".
9800 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009801 void
9802unset_global_local_option(name, from)
9803 char_u *name;
9804 void *from;
9805{
9806 struct vimoption *p;
9807 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009808 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009809
9810 opt_idx = findoption(name);
9811 p = &(options[opt_idx]);
9812
9813 switch ((int)p->indir)
9814 {
9815 /* global option with local value: use local value if it's been set */
9816 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009817 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009818 break;
9819 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009820 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009821 break;
9822 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009823 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009824 break;
9825 case PV_AR:
9826 buf->b_p_ar = -1;
9827 break;
9828 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009829 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009830 break;
9831#ifdef FEAT_FIND_ID
9832 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009833 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009834 break;
9835 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009836 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009837 break;
9838#endif
9839#ifdef FEAT_INS_EXPAND
9840 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009841 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009842 break;
9843 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009844 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009845 break;
9846#endif
9847#ifdef FEAT_QUICKFIX
9848 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009849 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009850 break;
9851 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009852 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009853 break;
9854 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009855 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009856 break;
9857#endif
9858#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9859 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009860 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009861 break;
9862#endif
9863#if defined(FEAT_CRYPT)
9864 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009865 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009866 break;
9867#endif
9868#ifdef FEAT_STL_OPT
9869 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009870 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009871 break;
9872#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009873 case PV_UL:
9874 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9875 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009876#ifdef FEAT_LISP
9877 case PV_LW:
9878 clear_string_option(&buf->b_p_lw);
9879 break;
9880#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009881 }
9882}
9883
9884/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009885 * Get pointer to option variable, depending on local or global scope.
9886 */
9887 static char_u *
9888get_varp_scope(p, opt_flags)
9889 struct vimoption *p;
9890 int opt_flags;
9891{
9892 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9893 {
9894 if (p->var == VAR_WIN)
9895 return (char_u *)GLOBAL_WO(get_varp(p));
9896 return p->var;
9897 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009898 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899 {
9900 switch ((int)p->indir)
9901 {
9902#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009903 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9904 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9905 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009906#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009907 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9908 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9909 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009910 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009911 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009912#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009913 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9914 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915#endif
9916#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009917 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9918 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009919#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009920#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9921 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9922#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009923#if defined(FEAT_CRYPT)
9924 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9925#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009926#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009927 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009928#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009929 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009930#ifdef FEAT_LISP
9931 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9932#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009933 }
9934 return NULL; /* "cannot happen" */
9935 }
9936 return get_varp(p);
9937}
9938
9939/*
9940 * Get pointer to option variable.
9941 */
9942 static char_u *
9943get_varp(p)
9944 struct vimoption *p;
9945{
9946 /* hidden option, always return NULL */
9947 if (p->var == NULL)
9948 return NULL;
9949
9950 switch ((int)p->indir)
9951 {
9952 case PV_NONE: return p->var;
9953
9954 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009955 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009956 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009957 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009959 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009960 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009961 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009962 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009963 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009964 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9965#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009966 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009967 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009968 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009969 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9970#endif
9971#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009972 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009974 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009975 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9976#endif
9977#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009978 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009979 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009980 case PV_GP: return *curbuf->b_p_gp != NUL
9981 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9982 case PV_MP: return *curbuf->b_p_mp != NUL
9983 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009985#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9986 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9987 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9988#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009989#if defined(FEAT_CRYPT)
9990 case PV_CM: return *curbuf->b_p_cm != NUL
9991 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9992#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009993#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009994 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009995 ? (char_u *)&(curwin->w_p_stl) : p->var;
9996#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009997 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
9998 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009999#ifdef FEAT_LISP
10000 case PV_LW: return *curbuf->b_p_lw != NUL
10001 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10002#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010003
10004#ifdef FEAT_ARABIC
10005 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10006#endif
10007 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010008#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010009 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10010#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010011#ifdef FEAT_SYN_HL
10012 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10013 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010014 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016#ifdef FEAT_DIFF
10017 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10018#endif
10019#ifdef FEAT_FOLDING
10020 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10021 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10022 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10023 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10024 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10025 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10026 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10027# ifdef FEAT_EVAL
10028 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10029 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10030# endif
10031 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10032#endif
10033 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010034 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010035#ifdef FEAT_LINEBREAK
10036 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10037#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010038#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010039 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10040#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010041#ifdef FEAT_VERTSPLIT
10042 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10043#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010044#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10045 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10046#endif
10047#ifdef FEAT_RIGHTLEFT
10048 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10049 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10050#endif
10051 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10052 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10053#ifdef FEAT_LINEBREAK
10054 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010055 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10056 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010057#endif
10058#ifdef FEAT_SCROLLBIND
10059 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10060#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010061#ifdef FEAT_CURSORBIND
10062 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10063#endif
10064#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010065 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10066 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010067#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010068
10069 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10070 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10071#ifdef FEAT_MBYTE
10072 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10073#endif
10074#if defined(FEAT_QUICKFIX)
10075 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10076 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10077#endif
10078 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10079 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10080#ifdef FEAT_CINDENT
10081 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10082 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10083 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10084#endif
10085#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10086 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10087#endif
10088#ifdef FEAT_COMMENTS
10089 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10090#endif
10091#ifdef FEAT_FOLDING
10092 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10093#endif
10094#ifdef FEAT_INS_EXPAND
10095 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10096#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010097#ifdef FEAT_COMPL_FUNC
10098 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010099 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010101 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10102 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10103#ifdef FEAT_MBYTE
10104 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10105#endif
10106 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10107#ifdef FEAT_AUTOCMD
10108 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10109#endif
10110 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010111 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010112 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10113 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10114 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10115 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10116#ifdef FEAT_FIND_ID
10117# ifdef FEAT_EVAL
10118 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10119# endif
10120#endif
10121#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10122 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10123 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10124#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010125#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010126 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10127#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010128#ifdef FEAT_CRYPT
10129 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10130#endif
10131#ifdef FEAT_LISP
10132 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10133#endif
10134 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10135 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10136 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10137 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10138 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010139 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010140#ifdef FEAT_TEXTOBJ
10141 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10142#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010143 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10144#ifdef FEAT_SMARTINDENT
10145 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10146#endif
10147#ifndef SHORT_FNAME
10148 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10149#endif
10150 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10151#ifdef FEAT_SEARCHPATH
10152 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10153#endif
10154 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10155#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010156 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010157 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10158#endif
10159#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010160 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10161 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10162 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010163#endif
10164 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10165 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10166 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10167 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010168#ifdef FEAT_PERSISTENT_UNDO
10169 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10170#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10172#ifdef FEAT_KEYMAP
10173 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10174#endif
10175 default: EMSG(_("E356: get_varp ERROR"));
10176 }
10177 /* always return a valid pointer to avoid a crash! */
10178 return (char_u *)&(curbuf->b_p_wm);
10179}
10180
10181/*
10182 * Get the value of 'equalprg', either the buffer-local one or the global one.
10183 */
10184 char_u *
10185get_equalprg()
10186{
10187 if (*curbuf->b_p_ep == NUL)
10188 return p_ep;
10189 return curbuf->b_p_ep;
10190}
10191
10192#if defined(FEAT_WINDOWS) || defined(PROTO)
10193/*
10194 * Copy options from one window to another.
10195 * Used when splitting a window.
10196 */
10197 void
10198win_copy_options(wp_from, wp_to)
10199 win_T *wp_from;
10200 win_T *wp_to;
10201{
10202 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10203 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10204# ifdef FEAT_RIGHTLEFT
10205# ifdef FEAT_FKMAP
10206 /* Is this right? */
10207 wp_to->w_farsi = wp_from->w_farsi;
10208# endif
10209# endif
10210}
10211#endif
10212
10213/*
10214 * Copy the options from one winopt_T to another.
10215 * Doesn't free the old option values in "to", use clear_winopt() for that.
10216 * The 'scroll' option is not copied, because it depends on the window height.
10217 * The 'previewwindow' option is reset, there can be only one preview window.
10218 */
10219 void
10220copy_winopt(from, to)
10221 winopt_T *from;
10222 winopt_T *to;
10223{
10224#ifdef FEAT_ARABIC
10225 to->wo_arab = from->wo_arab;
10226#endif
10227 to->wo_list = from->wo_list;
10228 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010229 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010230#ifdef FEAT_LINEBREAK
10231 to->wo_nuw = from->wo_nuw;
10232#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233#ifdef FEAT_RIGHTLEFT
10234 to->wo_rl = from->wo_rl;
10235 to->wo_rlc = vim_strsave(from->wo_rlc);
10236#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010237#ifdef FEAT_STL_OPT
10238 to->wo_stl = vim_strsave(from->wo_stl);
10239#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010240 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010241#ifdef FEAT_DIFF
10242 to->wo_wrap_save = from->wo_wrap_save;
10243#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010244#ifdef FEAT_LINEBREAK
10245 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010246 to->wo_bri = from->wo_bri;
10247 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248#endif
10249#ifdef FEAT_SCROLLBIND
10250 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010251 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010253#ifdef FEAT_CURSORBIND
10254 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010255 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010256#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010257#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010258 to->wo_spell = from->wo_spell;
10259#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010260#ifdef FEAT_SYN_HL
10261 to->wo_cuc = from->wo_cuc;
10262 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010263 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010265#ifdef FEAT_DIFF
10266 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010267 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010269#ifdef FEAT_CONCEAL
10270 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010271 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010272#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273#ifdef FEAT_FOLDING
10274 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010275 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010276 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010277 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010278 to->wo_fdi = vim_strsave(from->wo_fdi);
10279 to->wo_fml = from->wo_fml;
10280 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010281 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010282 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010283 to->wo_fdm_save = from->wo_diff_saved
10284 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010285 to->wo_fdn = from->wo_fdn;
10286# ifdef FEAT_EVAL
10287 to->wo_fde = vim_strsave(from->wo_fde);
10288 to->wo_fdt = vim_strsave(from->wo_fdt);
10289# endif
10290 to->wo_fmr = vim_strsave(from->wo_fmr);
10291#endif
10292 check_winopt(to); /* don't want NULL pointers */
10293}
10294
10295/*
10296 * Check string options in a window for a NULL value.
10297 */
10298 void
10299check_win_options(win)
10300 win_T *win;
10301{
10302 check_winopt(&win->w_onebuf_opt);
10303 check_winopt(&win->w_allbuf_opt);
10304}
10305
10306/*
10307 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10308 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010309 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010310check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010311 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312{
10313#ifdef FEAT_FOLDING
10314 check_string_option(&wop->wo_fdi);
10315 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010316 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010317# ifdef FEAT_EVAL
10318 check_string_option(&wop->wo_fde);
10319 check_string_option(&wop->wo_fdt);
10320# endif
10321 check_string_option(&wop->wo_fmr);
10322#endif
10323#ifdef FEAT_RIGHTLEFT
10324 check_string_option(&wop->wo_rlc);
10325#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010326#ifdef FEAT_STL_OPT
10327 check_string_option(&wop->wo_stl);
10328#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010329#ifdef FEAT_SYN_HL
10330 check_string_option(&wop->wo_cc);
10331#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010332#ifdef FEAT_CONCEAL
10333 check_string_option(&wop->wo_cocu);
10334#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010335#ifdef FEAT_LINEBREAK
10336 check_string_option(&wop->wo_briopt);
10337#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010338}
10339
10340/*
10341 * Free the allocated memory inside a winopt_T.
10342 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343 void
10344clear_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 clear_string_option(&wop->wo_fdi);
10349 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010350 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351# ifdef FEAT_EVAL
10352 clear_string_option(&wop->wo_fde);
10353 clear_string_option(&wop->wo_fdt);
10354# endif
10355 clear_string_option(&wop->wo_fmr);
10356#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010357#ifdef FEAT_LINEBREAK
10358 clear_string_option(&wop->wo_briopt);
10359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010360#ifdef FEAT_RIGHTLEFT
10361 clear_string_option(&wop->wo_rlc);
10362#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010363#ifdef FEAT_STL_OPT
10364 clear_string_option(&wop->wo_stl);
10365#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010366#ifdef FEAT_SYN_HL
10367 clear_string_option(&wop->wo_cc);
10368#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010369#ifdef FEAT_CONCEAL
10370 clear_string_option(&wop->wo_cocu);
10371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010372}
10373
10374/*
10375 * Copy global option values to local options for one buffer.
10376 * Used when creating a new buffer and sometimes when entering a buffer.
10377 * flags:
10378 * BCO_ENTER We will enter the buf buffer.
10379 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10380 * appropriate.
10381 * BCO_NOHELP Don't copy the values to a help buffer.
10382 */
10383 void
10384buf_copy_options(buf, flags)
10385 buf_T *buf;
10386 int flags;
10387{
10388 int should_copy = TRUE;
10389 char_u *save_p_isk = NULL; /* init for GCC */
10390 int dont_do_help;
10391 int did_isk = FALSE;
10392
10393 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010394 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010395 */
10396 if (buf == NULL || !buf_valid(buf))
10397 return;
10398
10399 /*
10400 * Skip this when the option defaults have not been set yet. Happens when
10401 * main() allocates the first buffer.
10402 */
10403 if (p_cpo != NULL)
10404 {
10405 /*
10406 * Always copy when entering and 'cpo' contains 'S'.
10407 * Don't copy when already initialized.
10408 * Don't copy when 'cpo' contains 's' and not entering.
10409 * 'S' BCO_ENTER initialized 's' should_copy
10410 * yes yes X X TRUE
10411 * yes no yes X FALSE
10412 * no X yes X FALSE
10413 * X no no yes FALSE
10414 * X no no no TRUE
10415 * no yes no X TRUE
10416 */
10417 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10418 && (buf->b_p_initialized
10419 || (!(flags & BCO_ENTER)
10420 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10421 should_copy = FALSE;
10422
10423 if (should_copy || (flags & BCO_ALWAYS))
10424 {
10425 /* Don't copy the options specific to a help buffer when
10426 * BCO_NOHELP is given or the options were initialized already
10427 * (jumping back to a help file with CTRL-T or CTRL-O) */
10428 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10429 || buf->b_p_initialized;
10430 if (dont_do_help) /* don't free b_p_isk */
10431 {
10432 save_p_isk = buf->b_p_isk;
10433 buf->b_p_isk = NULL;
10434 }
10435 /*
10436 * Always free the allocated strings.
10437 * If not already initialized, set 'readonly' and copy 'fileformat'.
10438 */
10439 if (!buf->b_p_initialized)
10440 {
10441 free_buf_options(buf, TRUE);
10442 buf->b_p_ro = FALSE; /* don't copy readonly */
10443 buf->b_p_tx = p_tx;
10444#ifdef FEAT_MBYTE
10445 buf->b_p_fenc = vim_strsave(p_fenc);
10446#endif
10447 buf->b_p_ff = vim_strsave(p_ff);
10448#if defined(FEAT_QUICKFIX)
10449 buf->b_p_bh = empty_option;
10450 buf->b_p_bt = empty_option;
10451#endif
10452 }
10453 else
10454 free_buf_options(buf, FALSE);
10455
10456 buf->b_p_ai = p_ai;
10457 buf->b_p_ai_nopaste = p_ai_nopaste;
10458 buf->b_p_sw = p_sw;
10459 buf->b_p_tw = p_tw;
10460 buf->b_p_tw_nopaste = p_tw_nopaste;
10461 buf->b_p_tw_nobin = p_tw_nobin;
10462 buf->b_p_wm = p_wm;
10463 buf->b_p_wm_nopaste = p_wm_nopaste;
10464 buf->b_p_wm_nobin = p_wm_nobin;
10465 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010466#ifdef FEAT_MBYTE
10467 buf->b_p_bomb = p_bomb;
10468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010469 buf->b_p_et = p_et;
10470 buf->b_p_et_nobin = p_et_nobin;
10471 buf->b_p_ml = p_ml;
10472 buf->b_p_ml_nobin = p_ml_nobin;
10473 buf->b_p_inf = p_inf;
10474 buf->b_p_swf = p_swf;
10475#ifdef FEAT_INS_EXPAND
10476 buf->b_p_cpt = vim_strsave(p_cpt);
10477#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010478#ifdef FEAT_COMPL_FUNC
10479 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010480 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010481#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482 buf->b_p_sts = p_sts;
10483 buf->b_p_sts_nopaste = p_sts_nopaste;
10484#ifndef SHORT_FNAME
10485 buf->b_p_sn = p_sn;
10486#endif
10487#ifdef FEAT_COMMENTS
10488 buf->b_p_com = vim_strsave(p_com);
10489#endif
10490#ifdef FEAT_FOLDING
10491 buf->b_p_cms = vim_strsave(p_cms);
10492#endif
10493 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010494 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010495 buf->b_p_nf = vim_strsave(p_nf);
10496 buf->b_p_mps = vim_strsave(p_mps);
10497#ifdef FEAT_SMARTINDENT
10498 buf->b_p_si = p_si;
10499#endif
10500 buf->b_p_ci = p_ci;
10501#ifdef FEAT_CINDENT
10502 buf->b_p_cin = p_cin;
10503 buf->b_p_cink = vim_strsave(p_cink);
10504 buf->b_p_cino = vim_strsave(p_cino);
10505#endif
10506#ifdef FEAT_AUTOCMD
10507 /* Don't copy 'filetype', it must be detected */
10508 buf->b_p_ft = empty_option;
10509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510 buf->b_p_pi = p_pi;
10511#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10512 buf->b_p_cinw = vim_strsave(p_cinw);
10513#endif
10514#ifdef FEAT_LISP
10515 buf->b_p_lisp = p_lisp;
10516#endif
10517#ifdef FEAT_SYN_HL
10518 /* Don't copy 'syntax', it must be set */
10519 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010520 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010521#endif
10522#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010523 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010524 (void)compile_cap_prog(&buf->b_s);
10525 buf->b_s.b_p_spf = vim_strsave(p_spf);
10526 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527#endif
10528#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10529 buf->b_p_inde = vim_strsave(p_inde);
10530 buf->b_p_indk = vim_strsave(p_indk);
10531#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010532#if defined(FEAT_EVAL)
10533 buf->b_p_fex = vim_strsave(p_fex);
10534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535#ifdef FEAT_CRYPT
10536 buf->b_p_key = vim_strsave(p_key);
10537#endif
10538#ifdef FEAT_SEARCHPATH
10539 buf->b_p_sua = vim_strsave(p_sua);
10540#endif
10541#ifdef FEAT_KEYMAP
10542 buf->b_p_keymap = vim_strsave(p_keymap);
10543 buf->b_kmap_state |= KEYMAP_INIT;
10544#endif
10545 /* This isn't really an option, but copying the langmap and IME
10546 * state from the current buffer is better than resetting it. */
10547 buf->b_p_iminsert = p_iminsert;
10548 buf->b_p_imsearch = p_imsearch;
10549
10550 /* options that are normally global but also have a local value
10551 * are not copied, start using the global value */
10552 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010553 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554#ifdef FEAT_QUICKFIX
10555 buf->b_p_gp = empty_option;
10556 buf->b_p_mp = empty_option;
10557 buf->b_p_efm = empty_option;
10558#endif
10559 buf->b_p_ep = empty_option;
10560 buf->b_p_kp = empty_option;
10561 buf->b_p_path = empty_option;
10562 buf->b_p_tags = empty_option;
10563#ifdef FEAT_FIND_ID
10564 buf->b_p_def = empty_option;
10565 buf->b_p_inc = empty_option;
10566# ifdef FEAT_EVAL
10567 buf->b_p_inex = vim_strsave(p_inex);
10568# endif
10569#endif
10570#ifdef FEAT_INS_EXPAND
10571 buf->b_p_dict = empty_option;
10572 buf->b_p_tsr = empty_option;
10573#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010574#ifdef FEAT_TEXTOBJ
10575 buf->b_p_qe = vim_strsave(p_qe);
10576#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010577#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10578 buf->b_p_bexpr = empty_option;
10579#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010580#if defined(FEAT_CRYPT)
10581 buf->b_p_cm = empty_option;
10582#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010583#ifdef FEAT_PERSISTENT_UNDO
10584 buf->b_p_udf = p_udf;
10585#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010586#ifdef FEAT_LISP
10587 buf->b_p_lw = empty_option;
10588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589
10590 /*
10591 * Don't copy the options set by ex_help(), use the saved values,
10592 * when going from a help buffer to a non-help buffer.
10593 * Don't touch these at all when BCO_NOHELP is used and going from
10594 * or to a help buffer.
10595 */
10596 if (dont_do_help)
10597 buf->b_p_isk = save_p_isk;
10598 else
10599 {
10600 buf->b_p_isk = vim_strsave(p_isk);
10601 did_isk = TRUE;
10602 buf->b_p_ts = p_ts;
10603 buf->b_help = FALSE;
10604#ifdef FEAT_QUICKFIX
10605 if (buf->b_p_bt[0] == 'h')
10606 clear_string_option(&buf->b_p_bt);
10607#endif
10608 buf->b_p_ma = p_ma;
10609 }
10610 }
10611
10612 /*
10613 * When the options should be copied (ignoring BCO_ALWAYS), set the
10614 * flag that indicates that the options have been initialized.
10615 */
10616 if (should_copy)
10617 buf->b_p_initialized = TRUE;
10618 }
10619
10620 check_buf_options(buf); /* make sure we don't have NULLs */
10621 if (did_isk)
10622 (void)buf_init_chartab(buf, FALSE);
10623}
10624
10625/*
10626 * Reset the 'modifiable' option and its default value.
10627 */
10628 void
10629reset_modifiable()
10630{
10631 int opt_idx;
10632
10633 curbuf->b_p_ma = FALSE;
10634 p_ma = FALSE;
10635 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010636 if (opt_idx >= 0)
10637 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010638}
10639
10640/*
10641 * Set the global value for 'iminsert' to the local value.
10642 */
10643 void
10644set_iminsert_global()
10645{
10646 p_iminsert = curbuf->b_p_iminsert;
10647}
10648
10649/*
10650 * Set the global value for 'imsearch' to the local value.
10651 */
10652 void
10653set_imsearch_global()
10654{
10655 p_imsearch = curbuf->b_p_imsearch;
10656}
10657
10658#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10659static int expand_option_idx = -1;
10660static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10661static int expand_option_flags = 0;
10662
10663 void
10664set_context_in_set_cmd(xp, arg, opt_flags)
10665 expand_T *xp;
10666 char_u *arg;
10667 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10668{
10669 int nextchar;
10670 long_u flags = 0; /* init for GCC */
10671 int opt_idx = 0; /* init for GCC */
10672 char_u *p;
10673 char_u *s;
10674 int is_term_option = FALSE;
10675 int key;
10676
10677 expand_option_flags = opt_flags;
10678
10679 xp->xp_context = EXPAND_SETTINGS;
10680 if (*arg == NUL)
10681 {
10682 xp->xp_pattern = arg;
10683 return;
10684 }
10685 p = arg + STRLEN(arg) - 1;
10686 if (*p == ' ' && *(p - 1) != '\\')
10687 {
10688 xp->xp_pattern = p + 1;
10689 return;
10690 }
10691 while (p > arg)
10692 {
10693 s = p;
10694 /* count number of backslashes before ' ' or ',' */
10695 if (*p == ' ' || *p == ',')
10696 {
10697 while (s > arg && *(s - 1) == '\\')
10698 --s;
10699 }
10700 /* break at a space with an even number of backslashes */
10701 if (*p == ' ' && ((p - s) & 1) == 0)
10702 {
10703 ++p;
10704 break;
10705 }
10706 --p;
10707 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010708 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709 {
10710 xp->xp_context = EXPAND_BOOL_SETTINGS;
10711 p += 2;
10712 }
10713 if (STRNCMP(p, "inv", 3) == 0)
10714 {
10715 xp->xp_context = EXPAND_BOOL_SETTINGS;
10716 p += 3;
10717 }
10718 xp->xp_pattern = arg = p;
10719 if (*arg == '<')
10720 {
10721 while (*p != '>')
10722 if (*p++ == NUL) /* expand terminal option name */
10723 return;
10724 key = get_special_key_code(arg + 1);
10725 if (key == 0) /* unknown name */
10726 {
10727 xp->xp_context = EXPAND_NOTHING;
10728 return;
10729 }
10730 nextchar = *++p;
10731 is_term_option = TRUE;
10732 expand_option_name[2] = KEY2TERMCAP0(key);
10733 expand_option_name[3] = KEY2TERMCAP1(key);
10734 }
10735 else
10736 {
10737 if (p[0] == 't' && p[1] == '_')
10738 {
10739 p += 2;
10740 if (*p != NUL)
10741 ++p;
10742 if (*p == NUL)
10743 return; /* expand option name */
10744 nextchar = *++p;
10745 is_term_option = TRUE;
10746 expand_option_name[2] = p[-2];
10747 expand_option_name[3] = p[-1];
10748 }
10749 else
10750 {
10751 /* Allow * wildcard */
10752 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10753 p++;
10754 if (*p == NUL)
10755 return;
10756 nextchar = *p;
10757 *p = NUL;
10758 opt_idx = findoption(arg);
10759 *p = nextchar;
10760 if (opt_idx == -1 || options[opt_idx].var == NULL)
10761 {
10762 xp->xp_context = EXPAND_NOTHING;
10763 return;
10764 }
10765 flags = options[opt_idx].flags;
10766 if (flags & P_BOOL)
10767 {
10768 xp->xp_context = EXPAND_NOTHING;
10769 return;
10770 }
10771 }
10772 }
10773 /* handle "-=" and "+=" */
10774 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10775 {
10776 ++p;
10777 nextchar = '=';
10778 }
10779 if ((nextchar != '=' && nextchar != ':')
10780 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10781 {
10782 xp->xp_context = EXPAND_UNSUCCESSFUL;
10783 return;
10784 }
10785 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10786 {
10787 xp->xp_context = EXPAND_OLD_SETTING;
10788 if (is_term_option)
10789 expand_option_idx = -1;
10790 else
10791 expand_option_idx = opt_idx;
10792 xp->xp_pattern = p + 1;
10793 return;
10794 }
10795 xp->xp_context = EXPAND_NOTHING;
10796 if (is_term_option || (flags & P_NUM))
10797 return;
10798
10799 xp->xp_pattern = p + 1;
10800
10801 if (flags & P_EXPAND)
10802 {
10803 p = options[opt_idx].var;
10804 if (p == (char_u *)&p_bdir
10805 || p == (char_u *)&p_dir
10806 || p == (char_u *)&p_path
10807 || p == (char_u *)&p_rtp
10808#ifdef FEAT_SEARCHPATH
10809 || p == (char_u *)&p_cdpath
10810#endif
10811#ifdef FEAT_SESSION
10812 || p == (char_u *)&p_vdir
10813#endif
10814 )
10815 {
10816 xp->xp_context = EXPAND_DIRECTORIES;
10817 if (p == (char_u *)&p_path
10818#ifdef FEAT_SEARCHPATH
10819 || p == (char_u *)&p_cdpath
10820#endif
10821 )
10822 xp->xp_backslash = XP_BS_THREE;
10823 else
10824 xp->xp_backslash = XP_BS_ONE;
10825 }
10826 else
10827 {
10828 xp->xp_context = EXPAND_FILES;
10829 /* for 'tags' need three backslashes for a space */
10830 if (p == (char_u *)&p_tags)
10831 xp->xp_backslash = XP_BS_THREE;
10832 else
10833 xp->xp_backslash = XP_BS_ONE;
10834 }
10835 }
10836
10837 /* For an option that is a list of file names, find the start of the
10838 * last file name. */
10839 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10840 {
10841 /* count number of backslashes before ' ' or ',' */
10842 if (*p == ' ' || *p == ',')
10843 {
10844 s = p;
10845 while (s > xp->xp_pattern && *(s - 1) == '\\')
10846 --s;
10847 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10848 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10849 {
10850 xp->xp_pattern = p + 1;
10851 break;
10852 }
10853 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010854
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010855#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010856 /* for 'spellsuggest' start at "file:" */
10857 if (options[opt_idx].var == (char_u *)&p_sps
10858 && STRNCMP(p, "file:", 5) == 0)
10859 {
10860 xp->xp_pattern = p + 5;
10861 break;
10862 }
10863#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864 }
10865
10866 return;
10867}
10868
10869 int
10870ExpandSettings(xp, regmatch, num_file, file)
10871 expand_T *xp;
10872 regmatch_T *regmatch;
10873 int *num_file;
10874 char_u ***file;
10875{
10876 int num_normal = 0; /* Nr of matching non-term-code settings */
10877 int num_term = 0; /* Nr of matching terminal code settings */
10878 int opt_idx;
10879 int match;
10880 int count = 0;
10881 char_u *str;
10882 int loop;
10883 int is_term_opt;
10884 char_u name_buf[MAX_KEY_NAME_LEN];
10885 static char *(names[]) = {"all", "termcap"};
10886 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10887
10888 /* do this loop twice:
10889 * loop == 0: count the number of matching options
10890 * loop == 1: copy the matching options into allocated memory
10891 */
10892 for (loop = 0; loop <= 1; ++loop)
10893 {
10894 regmatch->rm_ic = ic;
10895 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10896 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010897 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10898 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010899 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10900 {
10901 if (loop == 0)
10902 num_normal++;
10903 else
10904 (*file)[count++] = vim_strsave((char_u *)names[match]);
10905 }
10906 }
10907 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10908 opt_idx++)
10909 {
10910 if (options[opt_idx].var == NULL)
10911 continue;
10912 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10913 && !(options[opt_idx].flags & P_BOOL))
10914 continue;
10915 is_term_opt = istermoption(&options[opt_idx]);
10916 if (is_term_opt && num_normal > 0)
10917 continue;
10918 match = FALSE;
10919 if (vim_regexec(regmatch, str, (colnr_T)0)
10920 || (options[opt_idx].shortname != NULL
10921 && vim_regexec(regmatch,
10922 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10923 match = TRUE;
10924 else if (is_term_opt)
10925 {
10926 name_buf[0] = '<';
10927 name_buf[1] = 't';
10928 name_buf[2] = '_';
10929 name_buf[3] = str[2];
10930 name_buf[4] = str[3];
10931 name_buf[5] = '>';
10932 name_buf[6] = NUL;
10933 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10934 {
10935 match = TRUE;
10936 str = name_buf;
10937 }
10938 }
10939 if (match)
10940 {
10941 if (loop == 0)
10942 {
10943 if (is_term_opt)
10944 num_term++;
10945 else
10946 num_normal++;
10947 }
10948 else
10949 (*file)[count++] = vim_strsave(str);
10950 }
10951 }
10952 /*
10953 * Check terminal key codes, these are not in the option table
10954 */
10955 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10956 {
10957 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10958 {
10959 if (!isprint(str[0]) || !isprint(str[1]))
10960 continue;
10961
10962 name_buf[0] = 't';
10963 name_buf[1] = '_';
10964 name_buf[2] = str[0];
10965 name_buf[3] = str[1];
10966 name_buf[4] = NUL;
10967
10968 match = FALSE;
10969 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10970 match = TRUE;
10971 else
10972 {
10973 name_buf[0] = '<';
10974 name_buf[1] = 't';
10975 name_buf[2] = '_';
10976 name_buf[3] = str[0];
10977 name_buf[4] = str[1];
10978 name_buf[5] = '>';
10979 name_buf[6] = NUL;
10980
10981 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10982 match = TRUE;
10983 }
10984 if (match)
10985 {
10986 if (loop == 0)
10987 num_term++;
10988 else
10989 (*file)[count++] = vim_strsave(name_buf);
10990 }
10991 }
10992
10993 /*
10994 * Check special key names.
10995 */
10996 regmatch->rm_ic = TRUE; /* ignore case here */
10997 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10998 {
10999 name_buf[0] = '<';
11000 STRCPY(name_buf + 1, str);
11001 STRCAT(name_buf, ">");
11002
11003 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11004 {
11005 if (loop == 0)
11006 num_term++;
11007 else
11008 (*file)[count++] = vim_strsave(name_buf);
11009 }
11010 }
11011 }
11012 if (loop == 0)
11013 {
11014 if (num_normal > 0)
11015 *num_file = num_normal;
11016 else if (num_term > 0)
11017 *num_file = num_term;
11018 else
11019 return OK;
11020 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11021 if (*file == NULL)
11022 {
11023 *file = (char_u **)"";
11024 return FAIL;
11025 }
11026 }
11027 }
11028 return OK;
11029}
11030
11031 int
11032ExpandOldSetting(num_file, file)
11033 int *num_file;
11034 char_u ***file;
11035{
11036 char_u *var = NULL; /* init for GCC */
11037 char_u *buf;
11038
11039 *num_file = 0;
11040 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11041 if (*file == NULL)
11042 return FAIL;
11043
11044 /*
11045 * For a terminal key code expand_option_idx is < 0.
11046 */
11047 if (expand_option_idx < 0)
11048 {
11049 var = find_termcode(expand_option_name + 2);
11050 if (var == NULL)
11051 expand_option_idx = findoption(expand_option_name);
11052 }
11053
11054 if (expand_option_idx >= 0)
11055 {
11056 /* put string of option value in NameBuff */
11057 option_value2string(&options[expand_option_idx], expand_option_flags);
11058 var = NameBuff;
11059 }
11060 else if (var == NULL)
11061 var = (char_u *)"";
11062
11063 /* A backslash is required before some characters. This is the reverse of
11064 * what happens in do_set(). */
11065 buf = vim_strsave_escaped(var, escape_chars);
11066
11067 if (buf == NULL)
11068 {
11069 vim_free(*file);
11070 *file = NULL;
11071 return FAIL;
11072 }
11073
11074#ifdef BACKSLASH_IN_FILENAME
11075 /* For MS-Windows et al. we don't double backslashes at the start and
11076 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011077 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078 if (var[0] == '\\' && var[1] == '\\'
11079 && expand_option_idx >= 0
11080 && (options[expand_option_idx].flags & P_EXPAND)
11081 && vim_isfilec(var[2])
11082 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011083 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011084#endif
11085
11086 *file[0] = buf;
11087 *num_file = 1;
11088 return OK;
11089}
11090#endif
11091
11092/*
11093 * Get the value for the numeric or string option *opp in a nice format into
11094 * NameBuff[]. Must not be called with a hidden option!
11095 */
11096 static void
11097option_value2string(opp, opt_flags)
11098 struct vimoption *opp;
11099 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11100{
11101 char_u *varp;
11102
11103 varp = get_varp_scope(opp, opt_flags);
11104
11105 if (opp->flags & P_NUM)
11106 {
11107 long wc = 0;
11108
11109 if (wc_use_keyname(varp, &wc))
11110 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11111 else if (wc != 0)
11112 STRCPY(NameBuff, transchar((int)wc));
11113 else
11114 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11115 }
11116 else /* P_STRING */
11117 {
11118 varp = *(char_u **)(varp);
11119 if (varp == NULL) /* just in case */
11120 NameBuff[0] = NUL;
11121#ifdef FEAT_CRYPT
11122 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011123 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124 STRCPY(NameBuff, "*****");
11125#endif
11126 else if (opp->flags & P_EXPAND)
11127 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11128 /* Translate 'pastetoggle' into special key names */
11129 else if ((char_u **)opp->var == &p_pt)
11130 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11131 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011132 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133 }
11134}
11135
11136/*
11137 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11138 * printed as a keyname.
11139 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11140 */
11141 static int
11142wc_use_keyname(varp, wcp)
11143 char_u *varp;
11144 long *wcp;
11145{
11146 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11147 {
11148 *wcp = *(long *)varp;
11149 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11150 return TRUE;
11151 }
11152 return FALSE;
11153}
11154
11155#ifdef FEAT_LANGMAP
11156/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011157 * Any character has an equivalent 'langmap' character. This is used for
11158 * keyboards that have a special language mode that sends characters above
11159 * 128 (although other characters can be translated too). The "to" field is a
11160 * Vim command character. This avoids having to switch the keyboard back to
11161 * ASCII mode when leaving Insert mode.
11162 *
11163 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11164 * commands.
11165 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11166 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11167 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011168 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011169# ifdef FEAT_MBYTE
11170/*
11171 * With multi-byte support use growarray for 'langmap' chars >= 256
11172 */
11173typedef struct
11174{
11175 int from;
11176 int to;
11177} langmap_entry_T;
11178
11179static garray_T langmap_mapga;
11180static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011181
11182/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011183 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11184 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011186 static void
11187langmap_set_entry(from, to)
11188 int from;
11189 int to;
11190{
11191 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011192 int a = 0;
11193 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011194
11195 /* Do a binary search for an existing entry. */
11196 while (a != b)
11197 {
11198 int i = (a + b) / 2;
11199 int d = entries[i].from - from;
11200
11201 if (d == 0)
11202 {
11203 entries[i].to = to;
11204 return;
11205 }
11206 if (d < 0)
11207 a = i + 1;
11208 else
11209 b = i;
11210 }
11211
11212 if (ga_grow(&langmap_mapga, 1) != OK)
11213 return; /* out of memory */
11214
11215 /* insert new entry at position "a" */
11216 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11217 mch_memmove(entries + 1, entries,
11218 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11219 ++langmap_mapga.ga_len;
11220 entries[0].from = from;
11221 entries[0].to = to;
11222}
11223
11224/*
11225 * Apply 'langmap' to multi-byte character "c" and return the result.
11226 */
11227 int
11228langmap_adjust_mb(c)
11229 int c;
11230{
11231 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11232 int a = 0;
11233 int b = langmap_mapga.ga_len;
11234
11235 while (a != b)
11236 {
11237 int i = (a + b) / 2;
11238 int d = entries[i].from - c;
11239
11240 if (d == 0)
11241 return entries[i].to; /* found matching entry */
11242 if (d < 0)
11243 a = i + 1;
11244 else
11245 b = i;
11246 }
11247 return c; /* no entry found, return "c" unmodified */
11248}
11249# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011250
11251 static void
11252langmap_init()
11253{
11254 int i;
11255
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011256 for (i = 0; i < 256; i++)
11257 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11258# ifdef FEAT_MBYTE
11259 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11260# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011261}
11262
11263/*
11264 * Called when langmap option is set; the language map can be
11265 * changed at any time!
11266 */
11267 static void
11268langmap_set()
11269{
11270 char_u *p;
11271 char_u *p2;
11272 int from, to;
11273
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011274#ifdef FEAT_MBYTE
11275 ga_clear(&langmap_mapga); /* clear the previous map first */
11276#endif
11277 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278
11279 for (p = p_langmap; p[0] != NUL; )
11280 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011281 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11282 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011283 {
11284 if (p2[0] == '\\' && p2[1] != NUL)
11285 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286 }
11287 if (p2[0] == ';')
11288 ++p2; /* abcd;ABCD form, p2 points to A */
11289 else
11290 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11291 while (p[0])
11292 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011293 if (p[0] == ',')
11294 {
11295 ++p;
11296 break;
11297 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011298 if (p[0] == '\\' && p[1] != NUL)
11299 ++p;
11300#ifdef FEAT_MBYTE
11301 from = (*mb_ptr2char)(p);
11302#else
11303 from = p[0];
11304#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011305 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011306 if (p2 == NULL)
11307 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011308 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011309 if (p[0] != ',')
11310 {
11311 if (p[0] == '\\')
11312 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011313#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011314 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011316 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011317#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011318 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011319 }
11320 else
11321 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011322 if (p2[0] != ',')
11323 {
11324 if (p2[0] == '\\')
11325 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011326#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011327 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011328#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011329 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011331 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332 }
11333 if (to == NUL)
11334 {
11335 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11336 transchar(from));
11337 return;
11338 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011339
11340#ifdef FEAT_MBYTE
11341 if (from >= 256)
11342 langmap_set_entry(from, to);
11343 else
11344#endif
11345 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011346
11347 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011348 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011349 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011351 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011352 if (*p == ';')
11353 {
11354 p = p2;
11355 if (p[0] != NUL)
11356 {
11357 if (p[0] != ',')
11358 {
11359 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11360 return;
11361 }
11362 ++p;
11363 }
11364 break;
11365 }
11366 }
11367 }
11368 }
11369}
11370#endif
11371
11372/*
11373 * Return TRUE if format option 'x' is in effect.
11374 * Take care of no formatting when 'paste' is set.
11375 */
11376 int
11377has_format_option(x)
11378 int x;
11379{
11380 if (p_paste)
11381 return FALSE;
11382 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11383}
11384
11385/*
11386 * Return TRUE if "x" is present in 'shortmess' option, or
11387 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11388 */
11389 int
11390shortmess(x)
11391 int x;
11392{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011393 return p_shm != NULL &&
11394 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011395 || (vim_strchr(p_shm, 'a') != NULL
11396 && vim_strchr((char_u *)SHM_A, x) != NULL));
11397}
11398
11399/*
11400 * paste_option_changed() - Called after p_paste was set or reset.
11401 */
11402 static void
11403paste_option_changed()
11404{
11405 static int old_p_paste = FALSE;
11406 static int save_sm = 0;
11407#ifdef FEAT_CMDL_INFO
11408 static int save_ru = 0;
11409#endif
11410#ifdef FEAT_RIGHTLEFT
11411 static int save_ri = 0;
11412 static int save_hkmap = 0;
11413#endif
11414 buf_T *buf;
11415
11416 if (p_paste)
11417 {
11418 /*
11419 * Paste switched from off to on.
11420 * Save the current values, so they can be restored later.
11421 */
11422 if (!old_p_paste)
11423 {
11424 /* save options for each buffer */
11425 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11426 {
11427 buf->b_p_tw_nopaste = buf->b_p_tw;
11428 buf->b_p_wm_nopaste = buf->b_p_wm;
11429 buf->b_p_sts_nopaste = buf->b_p_sts;
11430 buf->b_p_ai_nopaste = buf->b_p_ai;
11431 }
11432
11433 /* save global options */
11434 save_sm = p_sm;
11435#ifdef FEAT_CMDL_INFO
11436 save_ru = p_ru;
11437#endif
11438#ifdef FEAT_RIGHTLEFT
11439 save_ri = p_ri;
11440 save_hkmap = p_hkmap;
11441#endif
11442 /* save global values for local buffer options */
11443 p_tw_nopaste = p_tw;
11444 p_wm_nopaste = p_wm;
11445 p_sts_nopaste = p_sts;
11446 p_ai_nopaste = p_ai;
11447 }
11448
11449 /*
11450 * Always set the option values, also when 'paste' is set when it is
11451 * already on.
11452 */
11453 /* set options for each buffer */
11454 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11455 {
11456 buf->b_p_tw = 0; /* textwidth is 0 */
11457 buf->b_p_wm = 0; /* wrapmargin is 0 */
11458 buf->b_p_sts = 0; /* softtabstop is 0 */
11459 buf->b_p_ai = 0; /* no auto-indent */
11460 }
11461
11462 /* set global options */
11463 p_sm = 0; /* no showmatch */
11464#ifdef FEAT_CMDL_INFO
11465# ifdef FEAT_WINDOWS
11466 if (p_ru)
11467 status_redraw_all(); /* redraw to remove the ruler */
11468# endif
11469 p_ru = 0; /* no ruler */
11470#endif
11471#ifdef FEAT_RIGHTLEFT
11472 p_ri = 0; /* no reverse insert */
11473 p_hkmap = 0; /* no Hebrew keyboard */
11474#endif
11475 /* set global values for local buffer options */
11476 p_tw = 0;
11477 p_wm = 0;
11478 p_sts = 0;
11479 p_ai = 0;
11480 }
11481
11482 /*
11483 * Paste switched from on to off: Restore saved values.
11484 */
11485 else if (old_p_paste)
11486 {
11487 /* restore options for each buffer */
11488 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11489 {
11490 buf->b_p_tw = buf->b_p_tw_nopaste;
11491 buf->b_p_wm = buf->b_p_wm_nopaste;
11492 buf->b_p_sts = buf->b_p_sts_nopaste;
11493 buf->b_p_ai = buf->b_p_ai_nopaste;
11494 }
11495
11496 /* restore global options */
11497 p_sm = save_sm;
11498#ifdef FEAT_CMDL_INFO
11499# ifdef FEAT_WINDOWS
11500 if (p_ru != save_ru)
11501 status_redraw_all(); /* redraw to draw the ruler */
11502# endif
11503 p_ru = save_ru;
11504#endif
11505#ifdef FEAT_RIGHTLEFT
11506 p_ri = save_ri;
11507 p_hkmap = save_hkmap;
11508#endif
11509 /* set global values for local buffer options */
11510 p_tw = p_tw_nopaste;
11511 p_wm = p_wm_nopaste;
11512 p_sts = p_sts_nopaste;
11513 p_ai = p_ai_nopaste;
11514 }
11515
11516 old_p_paste = p_paste;
11517}
11518
11519/*
11520 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11521 *
11522 * Reset 'compatible' and set the values for options that didn't get set yet
11523 * to the Vim defaults.
11524 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011525 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011526 */
11527 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011528vimrc_found(fname, envname)
11529 char_u *fname;
11530 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011531{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011532 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011533 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011534 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535
11536 if (!option_was_set((char_u *)"cp"))
11537 {
11538 p_cp = FALSE;
11539 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11540 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11541 set_option_default(opt_idx, OPT_FREE, FALSE);
11542 didset_options();
11543 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011544
11545 if (fname != NULL)
11546 {
11547 p = vim_getenv(envname, &dofree);
11548 if (p == NULL)
11549 {
11550 /* Set $MYVIMRC to the first vimrc file found. */
11551 p = FullName_save(fname, FALSE);
11552 if (p != NULL)
11553 {
11554 vim_setenv(envname, p);
11555 vim_free(p);
11556 }
11557 }
11558 else if (dofree)
11559 vim_free(p);
11560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561}
11562
11563/*
11564 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11565 */
11566 void
11567change_compatible(on)
11568 int on;
11569{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011570 int opt_idx;
11571
Bram Moolenaar071d4272004-06-13 20:20:40 +000011572 if (p_cp != on)
11573 {
11574 p_cp = on;
11575 compatible_set();
11576 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011577 opt_idx = findoption((char_u *)"cp");
11578 if (opt_idx >= 0)
11579 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580}
11581
11582/*
11583 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011584 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011585 */
11586 int
11587option_was_set(name)
11588 char_u *name;
11589{
11590 int idx;
11591
11592 idx = findoption(name);
11593 if (idx < 0) /* unknown option */
11594 return FALSE;
11595 if (options[idx].flags & P_WAS_SET)
11596 return TRUE;
11597 return FALSE;
11598}
11599
11600/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011601 * Reset the flag indicating option "name" was set.
11602 */
11603 void
11604reset_option_was_set(name)
11605 char_u *name;
11606{
11607 int idx = findoption(name);
11608
11609 if (idx >= 0)
11610 options[idx].flags &= ~P_WAS_SET;
11611}
11612
11613/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011614 * compatible_set() - Called when 'compatible' has been set or unset.
11615 *
11616 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11617 * flag) to a Vi compatible value.
11618 * When 'compatible' is unset: Set all options that have a different default
11619 * for Vim (without the P_VI_DEF flag) to that default.
11620 */
11621 static void
11622compatible_set()
11623{
11624 int opt_idx;
11625
11626 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11627 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11628 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11629 set_option_default(opt_idx, OPT_FREE, p_cp);
11630 didset_options();
11631}
11632
11633#ifdef FEAT_LINEBREAK
11634
11635# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11636 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011637 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011638# endif
11639
11640/*
11641 * fill_breakat_flags() -- called when 'breakat' changes value.
11642 */
11643 static void
11644fill_breakat_flags()
11645{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011646 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011647 int i;
11648
11649 for (i = 0; i < 256; i++)
11650 breakat_flags[i] = FALSE;
11651
11652 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011653 for (p = p_breakat; *p; p++)
11654 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011655}
11656
11657# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011658 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011659# endif
11660
11661#endif
11662
11663/*
11664 * Check an option that can be a range of string values.
11665 *
11666 * Return OK for correct value, FAIL otherwise.
11667 * Empty is always OK.
11668 */
11669 static int
11670check_opt_strings(val, values, list)
11671 char_u *val;
11672 char **values;
11673 int list; /* when TRUE: accept a list of values */
11674{
11675 return opt_strings_flags(val, values, NULL, list);
11676}
11677
11678/*
11679 * Handle an option that can be a range of string values.
11680 * Set a flag in "*flagp" for each string present.
11681 *
11682 * Return OK for correct value, FAIL otherwise.
11683 * Empty is always OK.
11684 */
11685 static int
11686opt_strings_flags(val, values, flagp, list)
11687 char_u *val; /* new value */
11688 char **values; /* array of valid string values */
11689 unsigned *flagp;
11690 int list; /* when TRUE: accept a list of values */
11691{
11692 int i;
11693 int len;
11694 unsigned new_flags = 0;
11695
11696 while (*val)
11697 {
11698 for (i = 0; ; ++i)
11699 {
11700 if (values[i] == NULL) /* val not found in values[] */
11701 return FAIL;
11702
11703 len = (int)STRLEN(values[i]);
11704 if (STRNCMP(values[i], val, len) == 0
11705 && ((list && val[len] == ',') || val[len] == NUL))
11706 {
11707 val += len + (val[len] == ',');
11708 new_flags |= (1 << i);
11709 break; /* check next item in val list */
11710 }
11711 }
11712 }
11713 if (flagp != NULL)
11714 *flagp = new_flags;
11715
11716 return OK;
11717}
11718
11719/*
11720 * Read the 'wildmode' option, fill wim_flags[].
11721 */
11722 static int
11723check_opt_wim()
11724{
11725 char_u new_wim_flags[4];
11726 char_u *p;
11727 int i;
11728 int idx = 0;
11729
11730 for (i = 0; i < 4; ++i)
11731 new_wim_flags[i] = 0;
11732
11733 for (p = p_wim; *p; ++p)
11734 {
11735 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11736 ;
11737 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11738 return FAIL;
11739 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11740 new_wim_flags[idx] |= WIM_LONGEST;
11741 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11742 new_wim_flags[idx] |= WIM_FULL;
11743 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11744 new_wim_flags[idx] |= WIM_LIST;
11745 else
11746 return FAIL;
11747 p += i;
11748 if (*p == NUL)
11749 break;
11750 if (*p == ',')
11751 {
11752 if (idx == 3)
11753 return FAIL;
11754 ++idx;
11755 }
11756 }
11757
11758 /* fill remaining entries with last flag */
11759 while (idx < 3)
11760 {
11761 new_wim_flags[idx + 1] = new_wim_flags[idx];
11762 ++idx;
11763 }
11764
11765 /* only when there are no errors, wim_flags[] is changed */
11766 for (i = 0; i < 4; ++i)
11767 wim_flags[i] = new_wim_flags[i];
11768 return OK;
11769}
11770
11771/*
11772 * Check if backspacing over something is allowed.
11773 */
11774 int
11775can_bs(what)
11776 int what; /* BS_INDENT, BS_EOL or BS_START */
11777{
11778 switch (*p_bs)
11779 {
11780 case '2': return TRUE;
11781 case '1': return (what != BS_START);
11782 case '0': return FALSE;
11783 }
11784 return vim_strchr(p_bs, what) != NULL;
11785}
11786
11787/*
11788 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11789 * the file must be considered changed when the value is different.
11790 */
11791 void
11792save_file_ff(buf)
11793 buf_T *buf;
11794{
11795 buf->b_start_ffc = *buf->b_p_ff;
11796 buf->b_start_eol = buf->b_p_eol;
11797#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011798 buf->b_start_bomb = buf->b_p_bomb;
11799
Bram Moolenaar071d4272004-06-13 20:20:40 +000011800 /* Only use free/alloc when necessary, they take time. */
11801 if (buf->b_start_fenc == NULL
11802 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11803 {
11804 vim_free(buf->b_start_fenc);
11805 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11806 }
11807#endif
11808}
11809
11810/*
11811 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11812 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011813 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11814 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011815 * When "ignore_empty" is true don't consider a new, empty buffer to be
11816 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011817 */
11818 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011819file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011820 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011821 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011822{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011823 /* In a buffer that was never loaded the options are not valid. */
11824 if (buf->b_flags & BF_NEVERLOADED)
11825 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011826 if (ignore_empty
11827 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011828 && buf->b_ml.ml_line_count == 1
11829 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11830 return FALSE;
11831 if (buf->b_start_ffc != *buf->b_p_ff)
11832 return TRUE;
11833 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11834 return TRUE;
11835#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011836 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11837 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011838 if (buf->b_start_fenc == NULL)
11839 return (*buf->b_p_fenc != NUL);
11840 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11841#else
11842 return FALSE;
11843#endif
11844}
11845
11846/*
11847 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11848 */
11849 int
11850check_ff_value(p)
11851 char_u *p;
11852{
11853 return check_opt_strings(p, p_ff_values, FALSE);
11854}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011855
11856/*
11857 * Return the effective shiftwidth value for current buffer, using the
11858 * 'tabstop' value when 'shiftwidth' is zero.
11859 */
11860 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011861get_sw_value(buf)
11862 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011863{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011864 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011865}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011866
11867/*
11868 * Return the effective softtabstop value for the current buffer, using the
11869 * 'tabstop' value when 'softtabstop' is negative.
11870 */
11871 long
11872get_sts_value()
11873{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011874 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011875}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011876
11877/*
11878 * Check matchpairs option for "*initc".
11879 * If there is a match set "*initc" to the matching character and "*findc" to
11880 * the opposite character. Set "*backwards" to the direction.
11881 * When "switchit" is TRUE swap the direction.
11882 */
11883 void
11884find_mps_values(initc, findc, backwards, switchit)
11885 int *initc;
11886 int *findc;
11887 int *backwards;
11888 int switchit;
11889{
11890 char_u *ptr;
11891
11892 ptr = curbuf->b_p_mps;
11893 while (*ptr != NUL)
11894 {
11895#ifdef FEAT_MBYTE
11896 if (has_mbyte)
11897 {
11898 char_u *prev;
11899
11900 if (mb_ptr2char(ptr) == *initc)
11901 {
11902 if (switchit)
11903 {
11904 *findc = *initc;
11905 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11906 *backwards = TRUE;
11907 }
11908 else
11909 {
11910 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11911 *backwards = FALSE;
11912 }
11913 return;
11914 }
11915 prev = ptr;
11916 ptr += mb_ptr2len(ptr) + 1;
11917 if (mb_ptr2char(ptr) == *initc)
11918 {
11919 if (switchit)
11920 {
11921 *findc = *initc;
11922 *initc = mb_ptr2char(prev);
11923 *backwards = FALSE;
11924 }
11925 else
11926 {
11927 *findc = mb_ptr2char(prev);
11928 *backwards = TRUE;
11929 }
11930 return;
11931 }
11932 ptr += mb_ptr2len(ptr);
11933 }
11934 else
11935#endif
11936 {
11937 if (*ptr == *initc)
11938 {
11939 if (switchit)
11940 {
11941 *backwards = TRUE;
11942 *findc = *initc;
11943 *initc = ptr[2];
11944 }
11945 else
11946 {
11947 *backwards = FALSE;
11948 *findc = ptr[2];
11949 }
11950 return;
11951 }
11952 ptr += 2;
11953 if (*ptr == *initc)
11954 {
11955 if (switchit)
11956 {
11957 *backwards = FALSE;
11958 *findc = *initc;
11959 *initc = ptr[-2];
11960 }
11961 else
11962 {
11963 *backwards = TRUE;
11964 *findc = ptr[-2];
11965 }
11966 return;
11967 }
11968 ++ptr;
11969 }
11970 if (*ptr == ',')
11971 ++ptr;
11972 }
11973}
Bram Moolenaar597a4222014-06-25 14:39:50 +020011974
11975#if defined(FEAT_LINEBREAK) || defined(PROTO)
11976/*
11977 * This is called when 'breakindentopt' is changed and when a window is
11978 * initialized.
11979 */
11980 int
11981briopt_check()
11982{
11983 char_u *p;
11984 int bri_shift = 0;
11985 long bri_min = 20;
11986 int bri_sbr = FALSE;
11987
11988 p = curwin->w_p_briopt;
11989 while (*p != NUL)
11990 {
11991 if (STRNCMP(p, "shift:", 6) == 0
11992 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
11993 {
11994 p += 6;
11995 bri_shift = getdigits(&p);
11996 }
11997 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
11998 {
11999 p += 4;
12000 bri_min = getdigits(&p);
12001 }
12002 else if (STRNCMP(p, "sbr", 3) == 0)
12003 {
12004 p += 3;
12005 bri_sbr = TRUE;
12006 }
12007 if (*p != ',' && *p != NUL)
12008 return FAIL;
12009 if (*p == ',')
12010 ++p;
12011 }
12012
12013 curwin->w_p_brishift = bri_shift;
12014 curwin->w_p_brimin = bri_min;
12015 curwin->w_p_brisbr = bri_sbr;
12016
12017 return OK;
12018}
12019#endif