blob: 05dc992d960491861eabd996cb86b239d0d4274c [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));
3077static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3078#ifdef FEAT_LANGMAP
3079static void langmap_init __ARGS((void));
3080static void langmap_set __ARGS((void));
3081#endif
3082static void paste_option_changed __ARGS((void));
3083static void compatible_set __ARGS((void));
3084#ifdef FEAT_LINEBREAK
3085static void fill_breakat_flags __ARGS((void));
3086#endif
3087static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3088static int check_opt_strings __ARGS((char_u *val, char **values, int));
3089static int check_opt_wim __ARGS((void));
3090
3091/*
3092 * Initialize the options, first part.
3093 *
3094 * Called only once from main(), just after creating the first buffer.
3095 */
3096 void
3097set_init_1()
3098{
3099 char_u *p;
3100 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003101 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102
3103#ifdef FEAT_LANGMAP
3104 langmap_init();
3105#endif
3106
3107 /* Be Vi compatible by default */
3108 p_cp = TRUE;
3109
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003110 /* Use POSIX compatibility when $VIM_POSIX is set. */
3111 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003112 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003113 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003114 set_string_default("shm", (char_u *)"A");
3115 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003116
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 /*
3118 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003119 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003120 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003121 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3123# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003124 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003126 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003128 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129# endif
3130#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003131 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 set_string_default("sh", p);
3133
3134#ifdef FEAT_WILDIGN
3135 /*
3136 * Set the default for 'backupskip' to include environment variables for
3137 * temp files.
3138 */
3139 {
3140# ifdef UNIX
3141 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3142# else
3143 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3144# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003145 int len;
3146 garray_T ga;
3147 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148
3149 ga_init2(&ga, 1, 100);
3150 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3151 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003152 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153# ifdef UNIX
3154 if (*names[n] == NUL)
3155 p = (char_u *)"/tmp";
3156 else
3157# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003158 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 if (p != NULL && *p != NUL)
3160 {
3161 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003162 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 if (ga_grow(&ga, len) == OK)
3164 {
3165 if (ga.ga_len > 0)
3166 STRCAT(ga.ga_data, ",");
3167 STRCAT(ga.ga_data, p);
3168 add_pathsep(ga.ga_data);
3169 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 ga.ga_len += len;
3171 }
3172 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003173 if (mustfree)
3174 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 }
3176 if (ga.ga_data != NULL)
3177 {
3178 set_string_default("bsk", ga.ga_data);
3179 vim_free(ga.ga_data);
3180 }
3181 }
3182#endif
3183
3184 /*
3185 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3186 */
3187 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003188 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003190#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3191 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3192#endif
3193 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003195 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003196 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197#else
3198# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003199 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003200 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003202 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203# endif
3204#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003206 opt_idx = findoption((char_u *)"maxmem");
3207 if (opt_idx >= 0)
3208 {
3209#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003210 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003211 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3212#endif
3213 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3214 }
3215 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 }
3217
3218#ifdef FEAT_GUI_W32
3219 /* force 'shortname' for Win32s */
3220 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003221 {
3222 opt_idx = findoption((char_u *)"shortname");
3223 if (opt_idx >= 0)
3224 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226#endif
3227
3228#ifdef FEAT_SEARCHPATH
3229 {
3230 char_u *cdpath;
3231 char_u *buf;
3232 int i;
3233 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003234 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235
3236 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003237 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 if (cdpath != NULL)
3239 {
3240 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3241 if (buf != NULL)
3242 {
3243 buf[0] = ','; /* start with ",", current dir first */
3244 j = 1;
3245 for (i = 0; cdpath[i] != NUL; ++i)
3246 {
3247 if (vim_ispathlistsep(cdpath[i]))
3248 buf[j++] = ',';
3249 else
3250 {
3251 if (cdpath[i] == ' ' || cdpath[i] == ',')
3252 buf[j++] = '\\';
3253 buf[j++] = cdpath[i];
3254 }
3255 }
3256 buf[j] = NUL;
3257 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003258 if (opt_idx >= 0)
3259 {
3260 options[opt_idx].def_val[VI_DEFAULT] = buf;
3261 options[opt_idx].flags |= P_DEF_ALLOCED;
3262 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003263 else
3264 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003266 if (mustfree)
3267 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268 }
3269 }
3270#endif
3271
3272#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3273 /* Set print encoding on platforms that don't default to latin1 */
3274 set_string_default("penc",
3275# if defined(MSWIN) || defined(OS2)
3276 (char_u *)"cp1252"
3277# else
3278# ifdef VMS
3279 (char_u *)"dec-mcs"
3280# else
3281# ifdef EBCDIC
3282 (char_u *)"ebcdic-uk"
3283# else
3284# ifdef MAC
3285 (char_u *)"mac-roman"
3286# else /* HPUX */
3287 (char_u *)"hp-roman8"
3288# endif
3289# endif
3290# endif
3291# endif
3292 );
3293#endif
3294
3295#ifdef FEAT_POSTSCRIPT
3296 /* 'printexpr' must be allocated to be able to evaluate it. */
3297 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003298# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3299 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300# else
3301# ifdef VMS
3302 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3303
3304# else
3305 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3306# endif
3307# endif
3308 );
3309#endif
3310
3311 /*
3312 * Set all the options (except the terminal options) to their default
3313 * value. Also set the global value for local options.
3314 */
3315 set_options_default(0);
3316
3317#ifdef FEAT_GUI
3318 if (found_reverse_arg)
3319 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3320#endif
3321
3322 curbuf->b_p_initialized = TRUE;
3323 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003324 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325 check_buf_options(curbuf);
3326 check_win_options(curwin);
3327 check_options();
3328
3329 /* Must be before option_expand(), because that one needs vim_isIDc() */
3330 didset_options();
3331
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003332#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003333 /* Use the current chartab for the generic chartab. */
3334 init_spell_chartab();
3335#endif
3336
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337#ifdef FEAT_LINEBREAK
3338 /*
3339 * initialize the table for 'breakat'.
3340 */
3341 fill_breakat_flags();
3342#endif
3343
3344 /*
3345 * Expand environment variables and things like "~" for the defaults.
3346 * If option_expand() returns non-NULL the variable is expanded. This can
3347 * only happen for non-indirect options.
3348 * Also set the default to the expanded value, so ":set" does not list
3349 * them.
3350 * Don't set the P_ALLOCED flag, because we don't want to free the
3351 * default.
3352 */
3353 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3354 {
3355 if ((options[opt_idx].flags & P_GETTEXT)
3356 && options[opt_idx].var != NULL)
3357 p = (char_u *)_(*(char **)options[opt_idx].var);
3358 else
3359 p = option_expand(opt_idx, NULL);
3360 if (p != NULL && (p = vim_strsave(p)) != NULL)
3361 {
3362 *(char_u **)options[opt_idx].var = p;
3363 /* VIMEXP
3364 * Defaults for all expanded options are currently the same for Vi
3365 * and Vim. When this changes, add some code here! Also need to
3366 * split P_DEF_ALLOCED in two.
3367 */
3368 if (options[opt_idx].flags & P_DEF_ALLOCED)
3369 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3370 options[opt_idx].def_val[VI_DEFAULT] = p;
3371 options[opt_idx].flags |= P_DEF_ALLOCED;
3372 }
3373 }
3374
3375 /* Initialize the highlight_attr[] table. */
3376 highlight_changed();
3377
3378 save_file_ff(curbuf); /* Buffer is unchanged */
3379
3380 /* Parse default for 'wildmode' */
3381 check_opt_wim();
3382
3383#if defined(FEAT_ARABIC)
3384 /* Detect use of mlterm.
3385 * Mlterm is a terminal emulator akin to xterm that has some special
3386 * abilities (bidi namely).
3387 * NOTE: mlterm's author is being asked to 'set' a variable
3388 * instead of an environment variable due to inheritance.
3389 */
3390 if (mch_getenv((char_u *)"MLTERM") != NULL)
3391 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3392#endif
3393
3394#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3395 /* Parse default for 'fillchars'. */
3396 (void)set_chars_option(&p_fcs);
3397#endif
3398
3399#ifdef FEAT_CLIPBOARD
3400 /* Parse default for 'clipboard' */
3401 (void)check_clipboard_option();
3402#endif
3403
3404#ifdef FEAT_MBYTE
3405# if defined(WIN3264) && defined(FEAT_GETTEXT)
3406 /*
3407 * If $LANG isn't set, try to get a good value for it. This makes the
3408 * right language be used automatically. Don't do this for English.
3409 */
3410 if (mch_getenv((char_u *)"LANG") == NULL)
3411 {
3412 char buf[20];
3413
3414 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3415 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3416 * only the first two. */
3417 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3418 (LPTSTR)buf, 20);
3419 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3420 {
3421 /* There are a few exceptions (probably more) */
3422 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3423 STRCPY(buf, "zh_TW");
3424 else if (STRNICMP(buf, "chs", 3) == 0
3425 || STRNICMP(buf, "zhc", 3) == 0)
3426 STRCPY(buf, "zh_CN");
3427 else if (STRNICMP(buf, "jp", 2) == 0)
3428 STRCPY(buf, "ja");
3429 else
3430 buf[2] = NUL; /* truncate to two-letter code */
3431 vim_setenv("LANG", buf);
3432 }
3433 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003434# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003435# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003436 /* Moved to os_mac_conv.c to avoid dependency problems. */
3437 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003438# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439# endif
3440
3441 /* enc_locale() will try to find the encoding of the current locale. */
3442 p = enc_locale();
3443 if (p != NULL)
3444 {
3445 char_u *save_enc;
3446
3447 /* Try setting 'encoding' and check if the value is valid.
3448 * If not, go back to the default "latin1". */
3449 save_enc = p_enc;
3450 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003451 if (STRCMP(p_enc, "gb18030") == 0)
3452 {
3453 /* We don't support "gb18030", but "cp936" is a good substitute
3454 * for practical purposes, thus use that. It's not an alias to
3455 * still support conversion between gb18030 and utf-8. */
3456 p_enc = vim_strsave((char_u *)"cp936");
3457 vim_free(p);
3458 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459 if (mb_init() == NULL)
3460 {
3461 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003462 if (opt_idx >= 0)
3463 {
3464 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3465 options[opt_idx].flags |= P_DEF_ALLOCED;
3466 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003468#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3469 || defined(VMS)
3470 if (STRCMP(p_enc, "latin1") == 0
3471# ifdef FEAT_MBYTE
3472 || enc_utf8
3473# endif
3474 )
3475 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003476 /* Adjust the default for 'isprint' and 'iskeyword' to match
3477 * latin1. Also set the defaults for when 'nocompatible' is
3478 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003479 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003480 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003481 set_string_option_direct((char_u *)"isk", -1,
3482 ISK_LATIN1, OPT_FREE, SID_NONE);
3483 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003484 if (opt_idx >= 0)
3485 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003486 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003487 if (opt_idx >= 0)
3488 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003489 (void)init_chartab();
3490 }
3491#endif
3492
Bram Moolenaar071d4272004-06-13 20:20:40 +00003493# if defined(WIN3264) && !defined(FEAT_GUI)
3494 /* Win32 console: When GetACP() returns a different value from
3495 * GetConsoleCP() set 'termencoding'. */
3496 if (GetACP() != GetConsoleCP())
3497 {
3498 char buf[50];
3499
3500 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3501 p_tenc = vim_strsave((char_u *)buf);
3502 if (p_tenc != NULL)
3503 {
3504 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003505 if (opt_idx >= 0)
3506 {
3507 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3508 options[opt_idx].flags |= P_DEF_ALLOCED;
3509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510 convert_setup(&input_conv, p_tenc, p_enc);
3511 convert_setup(&output_conv, p_enc, p_tenc);
3512 }
3513 else
3514 p_tenc = empty_option;
3515 }
3516# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003517# if defined(WIN3264) && defined(FEAT_MBYTE)
3518 /* $HOME may have characters in active code page. */
3519 init_homedir();
3520# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003521 }
3522 else
3523 {
3524 vim_free(p_enc);
3525 p_enc = save_enc;
3526 }
3527 }
3528#endif
3529
3530#ifdef FEAT_MULTI_LANG
3531 /* Set the default for 'helplang'. */
3532 set_helplang_default(get_mess_lang());
3533#endif
3534}
3535
3536/*
3537 * Set an option to its default value.
3538 * This does not take care of side effects!
3539 */
3540 static void
3541set_option_default(opt_idx, opt_flags, compatible)
3542 int opt_idx;
3543 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3544 int compatible; /* use Vi default value */
3545{
3546 char_u *varp; /* pointer to variable for current option */
3547 int dvi; /* index in def_val[] */
3548 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003549 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003550 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3551
3552 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3553 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003554 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003555 {
3556 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3557 if (flags & P_STRING)
3558 {
3559 /* Use set_string_option_direct() for local options to handle
3560 * freeing and allocating the value. */
3561 if (options[opt_idx].indir != PV_NONE)
3562 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003563 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564 else
3565 {
3566 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3567 free_string_option(*(char_u **)(varp));
3568 *(char_u **)varp = options[opt_idx].def_val[dvi];
3569 options[opt_idx].flags &= ~P_ALLOCED;
3570 }
3571 }
3572 else if (flags & P_NUM)
3573 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003574 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003575 win_comp_scroll(curwin);
3576 else
3577 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003578 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003579 /* May also set global value for local option. */
3580 if (both)
3581 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3582 *(long *)varp;
3583 }
3584 }
3585 else /* P_BOOL */
3586 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003587 /* the cast to long is required for Manx C, long_i is needed for
3588 * MSVC */
3589 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003590#ifdef UNIX
3591 /* 'modeline' defaults to off for root */
3592 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3593 *(int *)varp = FALSE;
3594#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003595 /* May also set global value for local option. */
3596 if (both)
3597 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3598 *(int *)varp;
3599 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003600
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003601 /* The default value is not insecure. */
3602 flagsp = insecure_flag(opt_idx, opt_flags);
3603 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604 }
3605
3606#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003607 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608#endif
3609}
3610
3611/*
3612 * Set all options (except terminal options) to their default value.
3613 */
3614 static void
3615set_options_default(opt_flags)
3616 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3617{
3618 int i;
3619#ifdef FEAT_WINDOWS
3620 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003621 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622#endif
3623
3624 for (i = 0; !istermoption(&options[i]); i++)
3625 if (!(options[i].flags & P_NODEFAULT))
3626 set_option_default(i, opt_flags, p_cp);
3627
3628#ifdef FEAT_WINDOWS
3629 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003630 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003631 win_comp_scroll(wp);
3632#else
3633 win_comp_scroll(curwin);
3634#endif
3635}
3636
3637/*
3638 * Set the Vi-default value of a string option.
3639 * Used for 'sh', 'backupskip' and 'term'.
3640 */
3641 void
3642set_string_default(name, val)
3643 char *name;
3644 char_u *val;
3645{
3646 char_u *p;
3647 int opt_idx;
3648
3649 p = vim_strsave(val);
3650 if (p != NULL) /* we don't want a NULL */
3651 {
3652 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003653 if (opt_idx >= 0)
3654 {
3655 if (options[opt_idx].flags & P_DEF_ALLOCED)
3656 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3657 options[opt_idx].def_val[VI_DEFAULT] = p;
3658 options[opt_idx].flags |= P_DEF_ALLOCED;
3659 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003660 }
3661}
3662
3663/*
3664 * Set the Vi-default value of a number option.
3665 * Used for 'lines' and 'columns'.
3666 */
3667 void
3668set_number_default(name, val)
3669 char *name;
3670 long val;
3671{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003672 int opt_idx;
3673
3674 opt_idx = findoption((char_u *)name);
3675 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003676 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677}
3678
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003679#if defined(EXITFREE) || defined(PROTO)
3680/*
3681 * Free all options.
3682 */
3683 void
3684free_all_options()
3685{
3686 int i;
3687
3688 for (i = 0; !istermoption(&options[i]); i++)
3689 {
3690 if (options[i].indir == PV_NONE)
3691 {
3692 /* global option: free value and default value. */
3693 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3694 free_string_option(*(char_u **)options[i].var);
3695 if (options[i].flags & P_DEF_ALLOCED)
3696 free_string_option(options[i].def_val[VI_DEFAULT]);
3697 }
3698 else if (options[i].var != VAR_WIN
3699 && (options[i].flags & P_STRING))
3700 /* buffer-local option: free global value */
3701 free_string_option(*(char_u **)options[i].var);
3702 }
3703}
3704#endif
3705
3706
Bram Moolenaar071d4272004-06-13 20:20:40 +00003707/*
3708 * Initialize the options, part two: After getting Rows and Columns and
3709 * setting 'term'.
3710 */
3711 void
3712set_init_2()
3713{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003714 int idx;
3715
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716 /*
3717 * 'scroll' defaults to half the window height. Note that this default is
3718 * wrong when the window height changes.
3719 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003720 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003721 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003722 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003723 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003724 comp_col();
3725
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003726 /*
3727 * 'window' is only for backwards compatibility with Vi.
3728 * Default is Rows - 1.
3729 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003730 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003731 p_window = Rows - 1;
3732 set_number_default("window", Rows - 1);
3733
Bram Moolenaarf740b292006-02-16 22:11:02 +00003734 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003735#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003736 /*
3737 * If 'background' wasn't set by the user, try guessing the value,
3738 * depending on the terminal name. Only need to check for terminals
3739 * with a dark background, that can handle color.
3740 */
3741 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003742 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3743 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003745 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003746 /* don't mark it as set, when starting the GUI it may be
3747 * changed again */
3748 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749 }
3750#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003751
3752#ifdef CURSOR_SHAPE
3753 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3754#endif
3755#ifdef FEAT_MOUSESHAPE
3756 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3757#endif
3758#ifdef FEAT_PRINTER
3759 (void)parse_printoptions(); /* parse 'printoptions' default value */
3760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761}
3762
3763/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003764 * Return "dark" or "light" depending on the kind of terminal.
3765 * This is just guessing! Recognized are:
3766 * "linux" Linux console
3767 * "screen.linux" Linux console with screen
3768 * "cygwin" Cygwin shell
3769 * "putty" Putty program
3770 * We also check the COLORFGBG environment variable, which is set by
3771 * rxvt and derivatives. This variable contains either two or three
3772 * values separated by semicolons; we want the last value in either
3773 * case. If this value is 0-6 or 8, our background is dark.
3774 */
3775 static char_u *
3776term_bg_default()
3777{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003778#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3779 /* DOS console nearly always black */
3780 return (char_u *)"dark";
3781#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003782 char_u *p;
3783
Bram Moolenaarf740b292006-02-16 22:11:02 +00003784 if (STRCMP(T_NAME, "linux") == 0
3785 || STRCMP(T_NAME, "screen.linux") == 0
3786 || STRCMP(T_NAME, "cygwin") == 0
3787 || STRCMP(T_NAME, "putty") == 0
3788 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3789 && (p = vim_strrchr(p, ';')) != NULL
3790 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3791 && p[2] == NUL))
3792 return (char_u *)"dark";
3793 return (char_u *)"light";
3794#endif
3795}
3796
3797/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798 * Initialize the options, part three: After reading the .vimrc
3799 */
3800 void
3801set_init_3()
3802{
3803#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3804/*
3805 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3806 * This is done after other initializations, where 'shell' might have been
3807 * set, but only if they have not been set before.
3808 */
3809 char_u *p;
3810 int idx_srr;
3811 int do_srr;
3812#ifdef FEAT_QUICKFIX
3813 int idx_sp;
3814 int do_sp;
3815#endif
3816
3817 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003818 if (idx_srr < 0)
3819 do_srr = FALSE;
3820 else
3821 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822#ifdef FEAT_QUICKFIX
3823 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003824 if (idx_sp < 0)
3825 do_sp = FALSE;
3826 else
3827 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003828#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003829 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003830 if (p != NULL)
3831 {
3832 /*
3833 * Default for p_sp is "| tee", for p_srr is ">".
3834 * For known shells it is changed here to include stderr.
3835 */
3836 if ( fnamecmp(p, "csh") == 0
3837 || fnamecmp(p, "tcsh") == 0
3838# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3839 || fnamecmp(p, "csh.exe") == 0
3840 || fnamecmp(p, "tcsh.exe") == 0
3841# endif
3842 )
3843 {
3844#if defined(FEAT_QUICKFIX)
3845 if (do_sp)
3846 {
3847# ifdef WIN3264
3848 p_sp = (char_u *)">&";
3849# else
3850 p_sp = (char_u *)"|& tee";
3851# endif
3852 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3853 }
3854#endif
3855 if (do_srr)
3856 {
3857 p_srr = (char_u *)">&";
3858 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3859 }
3860 }
3861 else
3862# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3863 if ( fnamecmp(p, "sh") == 0
3864 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003865 || fnamecmp(p, "mksh") == 0
3866 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003867 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003868 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003870 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871# ifdef WIN3264
3872 || fnamecmp(p, "cmd") == 0
3873 || fnamecmp(p, "sh.exe") == 0
3874 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003875 || fnamecmp(p, "mksh.exe") == 0
3876 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003878 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 || fnamecmp(p, "bash.exe") == 0
3880 || fnamecmp(p, "cmd.exe") == 0
3881# endif
3882 )
3883# endif
3884 {
3885#if defined(FEAT_QUICKFIX)
3886 if (do_sp)
3887 {
3888# ifdef WIN3264
3889 p_sp = (char_u *)">%s 2>&1";
3890# else
3891 p_sp = (char_u *)"2>&1| tee";
3892# endif
3893 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3894 }
3895#endif
3896 if (do_srr)
3897 {
3898 p_srr = (char_u *)">%s 2>&1";
3899 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3900 }
3901 }
3902 vim_free(p);
3903 }
3904#endif
3905
3906#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3907 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003908 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3909 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910 * This is done after other initializations, where 'shell' might have been
3911 * set, but only if they have not been set before. Default for p_shcf is
3912 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3913 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3914 * command.com. And for Win32 we need to set p_sxq instead.
3915 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003916 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 {
3918 int idx3;
3919
3920 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003921 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922 {
3923 p_shcf = (char_u *)"-c";
3924 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3925 }
3926
3927# ifndef DJGPP
3928# ifdef WIN3264
3929 /* Somehow Win32 requires the quotes around the redirection too */
3930 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003931 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932 {
3933 p_sxq = (char_u *)"\"";
3934 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3935 }
3936# else
3937 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003938 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 {
3940 p_shq = (char_u *)"\"";
3941 options[idx3].def_val[VI_DEFAULT] = p_shq;
3942 }
3943# endif
3944# endif
3945 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003946 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3947 {
3948 int idx3;
3949
3950 /*
3951 * cmd.exe on Windows will strip the first and last double quote given
3952 * on the command line, e.g. most of the time things like:
3953 * cmd /c "my path/to/echo" "my args to echo"
3954 * become:
3955 * my path/to/echo" "my args to echo
3956 * when executed.
3957 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003958 * To avoid this, set shellxquote to surround the command in
3959 * parenthesis. This appears to make most commands work, without
3960 * breaking commands that worked previously, such as
3961 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003962 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003963 idx3 = findoption((char_u *)"sxq");
3964 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3965 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003966 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003967 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3968 }
3969
Bram Moolenaara64ba222012-02-12 23:23:31 +01003970 idx3 = findoption((char_u *)"shcf");
3971 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3972 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003973 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003974 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3975 }
3976 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977#endif
3978
3979#ifdef FEAT_TITLE
3980 set_title_defaults();
3981#endif
3982}
3983
3984#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3985/*
3986 * When 'helplang' is still at its default value, set it to "lang".
3987 * Only the first two characters of "lang" are used.
3988 */
3989 void
3990set_helplang_default(lang)
3991 char_u *lang;
3992{
3993 int idx;
3994
3995 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
3996 return;
3997 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003998 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003999 {
4000 if (options[idx].flags & P_ALLOCED)
4001 free_string_option(p_hlg);
4002 p_hlg = vim_strsave(lang);
4003 if (p_hlg == NULL)
4004 p_hlg = empty_option;
4005 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004006 {
4007 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4008 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4009 {
4010 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4011 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4012 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004013 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004014 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015 options[idx].flags |= P_ALLOCED;
4016 }
4017}
4018#endif
4019
4020#ifdef FEAT_GUI
4021static char_u *gui_bg_default __ARGS((void));
4022
4023 static char_u *
4024gui_bg_default()
4025{
4026 if (gui_get_lightness(gui.back_pixel) < 127)
4027 return (char_u *)"dark";
4028 return (char_u *)"light";
4029}
4030
4031/*
4032 * Option initializations that can only be done after opening the GUI window.
4033 */
4034 void
4035init_gui_options()
4036{
4037 /* Set the 'background' option according to the lightness of the
4038 * background color, unless the user has set it already. */
4039 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4040 {
4041 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4042 highlight_changed();
4043 }
4044}
4045#endif
4046
4047#ifdef FEAT_TITLE
4048/*
4049 * 'title' and 'icon' only default to true if they have not been set or reset
4050 * in .vimrc and we can read the old value.
4051 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4052 * they can be reset. This reduces startup time when using X on a remote
4053 * machine.
4054 */
4055 void
4056set_title_defaults()
4057{
4058 int idx1;
4059 long val;
4060
4061 /*
4062 * If GUI is (going to be) used, we can always set the window title and
4063 * icon name. Saves a bit of time, because the X11 display server does
4064 * not need to be contacted.
4065 */
4066 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004067 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 {
4069#ifdef FEAT_GUI
4070 if (gui.starting || gui.in_use)
4071 val = TRUE;
4072 else
4073#endif
4074 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004075 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 p_title = val;
4077 }
4078 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004079 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 {
4081#ifdef FEAT_GUI
4082 if (gui.starting || gui.in_use)
4083 val = TRUE;
4084 else
4085#endif
4086 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004087 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 p_icon = val;
4089 }
4090}
4091#endif
4092
4093/*
4094 * Parse 'arg' for option settings.
4095 *
4096 * 'arg' may be IObuff, but only when no errors can be present and option
4097 * does not need to be expanded with option_expand().
4098 * "opt_flags":
4099 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004100 * OPT_GLOBAL for ":setglobal"
4101 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004103 * OPT_WINONLY to only set window-local options
4104 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 *
4106 * returns FAIL if an error is detected, OK otherwise
4107 */
4108 int
4109do_set(arg, opt_flags)
4110 char_u *arg; /* option string (may be written to!) */
4111 int opt_flags;
4112{
4113 int opt_idx;
4114 char_u *errmsg;
4115 char_u errbuf[80];
4116 char_u *startarg;
4117 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4118 int nextchar; /* next non-white char after option name */
4119 int afterchar; /* character just after option name */
4120 int len;
4121 int i;
4122 long value;
4123 int key;
4124 long_u flags; /* flags for current option */
4125 char_u *varp = NULL; /* pointer to variable for current option */
4126 int did_show = FALSE; /* already showed one value */
4127 int adding; /* "opt+=arg" */
4128 int prepending; /* "opt^=arg" */
4129 int removing; /* "opt-=arg" */
4130 int cp_val = 0;
4131 char_u key_name[2];
4132
4133 if (*arg == NUL)
4134 {
4135 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004136 did_show = TRUE;
4137 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 }
4139
4140 while (*arg != NUL) /* loop to process all options */
4141 {
4142 errmsg = NULL;
4143 startarg = arg; /* remember for error message */
4144
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004145 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4146 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 {
4148 /*
4149 * ":set all" show all options.
4150 * ":set all&" set all options to their default value.
4151 */
4152 arg += 3;
4153 if (*arg == '&')
4154 {
4155 ++arg;
4156 /* Only for :set command set global value of local options. */
4157 set_options_default(OPT_FREE | opt_flags);
4158 }
4159 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004160 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004162 did_show = TRUE;
4163 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004164 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004165 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166 {
4167 showoptions(2, opt_flags);
4168 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004169 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004170 arg += 7;
4171 }
4172 else
4173 {
4174 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004175 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004176 {
4177 prefix = 0;
4178 arg += 2;
4179 }
4180 else if (STRNCMP(arg, "inv", 3) == 0)
4181 {
4182 prefix = 2;
4183 arg += 3;
4184 }
4185
4186 /* find end of name */
4187 key = 0;
4188 if (*arg == '<')
4189 {
4190 nextchar = 0;
4191 opt_idx = -1;
4192 /* look out for <t_>;> */
4193 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4194 len = 5;
4195 else
4196 {
4197 len = 1;
4198 while (arg[len] != NUL && arg[len] != '>')
4199 ++len;
4200 }
4201 if (arg[len] != '>')
4202 {
4203 errmsg = e_invarg;
4204 goto skip;
4205 }
4206 arg[len] = NUL; /* put NUL after name */
4207 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4208 opt_idx = findoption(arg + 1);
4209 arg[len++] = '>'; /* restore '>' */
4210 if (opt_idx == -1)
4211 key = find_key_option(arg + 1);
4212 }
4213 else
4214 {
4215 len = 0;
4216 /*
4217 * The two characters after "t_" may not be alphanumeric.
4218 */
4219 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4220 len = 4;
4221 else
4222 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4223 ++len;
4224 nextchar = arg[len];
4225 arg[len] = NUL; /* put NUL after name */
4226 opt_idx = findoption(arg);
4227 arg[len] = nextchar; /* restore nextchar */
4228 if (opt_idx == -1)
4229 key = find_key_option(arg);
4230 }
4231
4232 /* remember character after option name */
4233 afterchar = arg[len];
4234
4235 /* skip white space, allow ":set ai ?" */
4236 while (vim_iswhite(arg[len]))
4237 ++len;
4238
4239 adding = FALSE;
4240 prepending = FALSE;
4241 removing = FALSE;
4242 if (arg[len] != NUL && arg[len + 1] == '=')
4243 {
4244 if (arg[len] == '+')
4245 {
4246 adding = TRUE; /* "+=" */
4247 ++len;
4248 }
4249 else if (arg[len] == '^')
4250 {
4251 prepending = TRUE; /* "^=" */
4252 ++len;
4253 }
4254 else if (arg[len] == '-')
4255 {
4256 removing = TRUE; /* "-=" */
4257 ++len;
4258 }
4259 }
4260 nextchar = arg[len];
4261
4262 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4263 {
4264 errmsg = (char_u *)N_("E518: Unknown option");
4265 goto skip;
4266 }
4267
4268 if (opt_idx >= 0)
4269 {
4270 if (options[opt_idx].var == NULL) /* hidden option: skip */
4271 {
4272 /* Only give an error message when requesting the value of
4273 * a hidden option, ignore setting it. */
4274 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4275 && (!(options[opt_idx].flags & P_BOOL)
4276 || nextchar == '?'))
4277 errmsg = (char_u *)N_("E519: Option not supported");
4278 goto skip;
4279 }
4280
4281 flags = options[opt_idx].flags;
4282 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4283 }
4284 else
4285 {
4286 flags = P_STRING;
4287 if (key < 0)
4288 {
4289 key_name[0] = KEY2TERMCAP0(key);
4290 key_name[1] = KEY2TERMCAP1(key);
4291 }
4292 else
4293 {
4294 key_name[0] = KS_KEY;
4295 key_name[1] = (key & 0xff);
4296 }
4297 }
4298
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004299 /* Skip all options that are not window-local (used when showing
4300 * an already loaded buffer in a window). */
4301 if ((opt_flags & OPT_WINONLY)
4302 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4303 goto skip;
4304
Bram Moolenaara3227e22006-03-08 21:32:40 +00004305 /* Skip all options that are window-local (used for :vimgrep). */
4306 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4307 && options[opt_idx].var == VAR_WIN)
4308 goto skip;
4309
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004310 /* Disallow changing some options from modelines. */
4311 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004312 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004313 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004314 {
4315 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4316 goto skip;
4317 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004318#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004319 /* In diff mode some options are overruled. This avoids that
4320 * 'foldmethod' becomes "marker" instead of "diff" and that
4321 * "wrap" gets set. */
4322 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004323 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004324 && (options[opt_idx].indir == PV_FDM
4325 || options[opt_idx].indir == PV_WRAP))
4326 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004327#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004328 }
4329
4330#ifdef HAVE_SANDBOX
4331 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004332 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004333 {
4334 errmsg = (char_u *)_(e_sandbox);
4335 goto skip;
4336 }
4337#endif
4338
4339 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4340 {
4341 arg += len;
4342 cp_val = p_cp;
4343 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4344 {
4345 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4346 {
4347 cp_val = FALSE;
4348 arg += 3;
4349 }
4350 else /* "opt&vi": set to Vi default */
4351 {
4352 cp_val = TRUE;
4353 arg += 2;
4354 }
4355 }
4356 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4357 && arg[1] != NUL && !vim_iswhite(arg[1]))
4358 {
4359 errmsg = e_trailing;
4360 goto skip;
4361 }
4362 }
4363
4364 /*
4365 * allow '=' and ':' as MSDOS command.com allows only one
4366 * '=' character per "set" command line. grrr. (jw)
4367 */
4368 if (nextchar == '?'
4369 || (prefix == 1
4370 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4371 && !(flags & P_BOOL)))
4372 {
4373 /*
4374 * print value
4375 */
4376 if (did_show)
4377 msg_putchar('\n'); /* cursor below last one */
4378 else
4379 {
4380 gotocmdline(TRUE); /* cursor at status line */
4381 did_show = TRUE; /* remember that we did a line */
4382 }
4383 if (opt_idx >= 0)
4384 {
4385 showoneopt(&options[opt_idx], opt_flags);
4386#ifdef FEAT_EVAL
4387 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004388 {
4389 /* Mention where the option was last set. */
4390 if (varp == options[opt_idx].var)
4391 last_set_msg(options[opt_idx].scriptID);
4392 else if ((int)options[opt_idx].indir & PV_WIN)
4393 last_set_msg(curwin->w_p_scriptID[
4394 (int)options[opt_idx].indir & PV_MASK]);
4395 else if ((int)options[opt_idx].indir & PV_BUF)
4396 last_set_msg(curbuf->b_p_scriptID[
4397 (int)options[opt_idx].indir & PV_MASK]);
4398 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399#endif
4400 }
4401 else
4402 {
4403 char_u *p;
4404
4405 p = find_termcode(key_name);
4406 if (p == NULL)
4407 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004408 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004409 goto skip;
4410 }
4411 else
4412 (void)show_one_termcode(key_name, p, TRUE);
4413 }
4414 if (nextchar != '?'
4415 && nextchar != NUL && !vim_iswhite(afterchar))
4416 errmsg = e_trailing;
4417 }
4418 else
4419 {
4420 if (flags & P_BOOL) /* boolean */
4421 {
4422 if (nextchar == '=' || nextchar == ':')
4423 {
4424 errmsg = e_invarg;
4425 goto skip;
4426 }
4427
4428 /*
4429 * ":set opt!": invert
4430 * ":set opt&": reset to default value
4431 * ":set opt<": reset to global value
4432 */
4433 if (nextchar == '!')
4434 value = *(int *)(varp) ^ 1;
4435 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004436 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004437 ((flags & P_VI_DEF) || cp_val)
4438 ? VI_DEFAULT : VIM_DEFAULT];
4439 else if (nextchar == '<')
4440 {
4441 /* For 'autoread' -1 means to use global value. */
4442 if ((int *)varp == &curbuf->b_p_ar
4443 && opt_flags == OPT_LOCAL)
4444 value = -1;
4445 else
4446 value = *(int *)get_varp_scope(&(options[opt_idx]),
4447 OPT_GLOBAL);
4448 }
4449 else
4450 {
4451 /*
4452 * ":set invopt": invert
4453 * ":set opt" or ":set noopt": set or reset
4454 */
4455 if (nextchar != NUL && !vim_iswhite(afterchar))
4456 {
4457 errmsg = e_trailing;
4458 goto skip;
4459 }
4460 if (prefix == 2) /* inv */
4461 value = *(int *)(varp) ^ 1;
4462 else
4463 value = prefix;
4464 }
4465
4466 errmsg = set_bool_option(opt_idx, varp, (int)value,
4467 opt_flags);
4468 }
4469 else /* numeric or string */
4470 {
4471 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4472 || prefix != 1)
4473 {
4474 errmsg = e_invarg;
4475 goto skip;
4476 }
4477
4478 if (flags & P_NUM) /* numeric */
4479 {
4480 /*
4481 * Different ways to set a number option:
4482 * & set to default value
4483 * < set to global value
4484 * <xx> accept special key codes for 'wildchar'
4485 * c accept any non-digit for 'wildchar'
4486 * [-]0-9 set number
4487 * other error
4488 */
4489 ++arg;
4490 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004491 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004492 ((flags & P_VI_DEF) || cp_val)
4493 ? VI_DEFAULT : VIM_DEFAULT];
4494 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004495 {
4496 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4497 * use the global value. */
4498 if ((long *)varp == &curbuf->b_p_ul
4499 && opt_flags == OPT_LOCAL)
4500 value = NO_LOCAL_UNDOLEVEL;
4501 else
4502 value = *(long *)get_varp_scope(
4503 &(options[opt_idx]), OPT_GLOBAL);
4504 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004505 else if (((long *)varp == &p_wc
4506 || (long *)varp == &p_wcm)
4507 && (*arg == '<'
4508 || *arg == '^'
4509 || ((!arg[1] || vim_iswhite(arg[1]))
4510 && !VIM_ISDIGIT(*arg))))
4511 {
4512 value = string_to_key(arg);
4513 if (value == 0 && (long *)varp != &p_wcm)
4514 {
4515 errmsg = e_invarg;
4516 goto skip;
4517 }
4518 }
4519 /* allow negative numbers (for 'undolevels') */
4520 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4521 {
4522 i = 0;
4523 if (*arg == '-')
4524 i = 1;
4525#ifdef HAVE_STRTOL
4526 value = strtol((char *)arg, NULL, 0);
4527 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4528 i += 2;
4529#else
4530 value = atol((char *)arg);
4531#endif
4532 while (VIM_ISDIGIT(arg[i]))
4533 ++i;
4534 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4535 {
4536 errmsg = e_invarg;
4537 goto skip;
4538 }
4539 }
4540 else
4541 {
4542 errmsg = (char_u *)N_("E521: Number required after =");
4543 goto skip;
4544 }
4545
4546 if (adding)
4547 value = *(long *)varp + value;
4548 if (prepending)
4549 value = *(long *)varp * value;
4550 if (removing)
4551 value = *(long *)varp - value;
4552 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004553 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004554 }
4555 else if (opt_idx >= 0) /* string */
4556 {
4557 char_u *save_arg = NULL;
4558 char_u *s = NULL;
4559 char_u *oldval; /* previous value if *varp */
4560 char_u *newval;
4561 char_u *origval;
4562 unsigned newlen;
4563 int comma;
4564 int bs;
4565 int new_value_alloced; /* new string option
4566 was allocated */
4567
4568 /* When using ":set opt=val" for a global option
4569 * with a local value the local value will be
4570 * reset, use the global value here. */
4571 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004572 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004573 varp = options[opt_idx].var;
4574
4575 /* The old value is kept until we are sure that the
4576 * new value is valid. */
4577 oldval = *(char_u **)varp;
4578 if (nextchar == '&') /* set to default val */
4579 {
4580 newval = options[opt_idx].def_val[
4581 ((flags & P_VI_DEF) || cp_val)
4582 ? VI_DEFAULT : VIM_DEFAULT];
4583 if ((char_u **)varp == &p_bg)
4584 {
4585 /* guess the value of 'background' */
4586#ifdef FEAT_GUI
4587 if (gui.in_use)
4588 newval = gui_bg_default();
4589 else
4590#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004591 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004592 }
4593
4594 /* expand environment variables and ~ (since the
4595 * default value was already expanded, only
4596 * required when an environment variable was set
4597 * later */
4598 if (newval == NULL)
4599 newval = empty_option;
4600 else
4601 {
4602 s = option_expand(opt_idx, newval);
4603 if (s == NULL)
4604 s = newval;
4605 newval = vim_strsave(s);
4606 }
4607 new_value_alloced = TRUE;
4608 }
4609 else if (nextchar == '<') /* set to global val */
4610 {
4611 newval = vim_strsave(*(char_u **)get_varp_scope(
4612 &(options[opt_idx]), OPT_GLOBAL));
4613 new_value_alloced = TRUE;
4614 }
4615 else
4616 {
4617 ++arg; /* jump to after the '=' or ':' */
4618
4619 /*
4620 * Set 'keywordprg' to ":help" if an empty
4621 * value was passed to :set by the user.
4622 * Misuse errbuf[] for the resulting string.
4623 */
4624 if (varp == (char_u *)&p_kp
4625 && (*arg == NUL || *arg == ' '))
4626 {
4627 STRCPY(errbuf, ":help");
4628 save_arg = arg;
4629 arg = errbuf;
4630 }
4631 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004632 * Convert 'backspace' number to string, for
4633 * adding, prepending and removing string.
4634 */
4635 else if (varp == (char_u *)&p_bs
4636 && VIM_ISDIGIT(**(char_u **)varp))
4637 {
4638 i = getdigits((char_u **)varp);
4639 switch (i)
4640 {
4641 case 0:
4642 *(char_u **)varp = empty_option;
4643 break;
4644 case 1:
4645 *(char_u **)varp = vim_strsave(
4646 (char_u *)"indent,eol");
4647 break;
4648 case 2:
4649 *(char_u **)varp = vim_strsave(
4650 (char_u *)"indent,eol,start");
4651 break;
4652 }
4653 vim_free(oldval);
4654 oldval = *(char_u **)varp;
4655 }
4656 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004657 * Convert 'whichwrap' number to string, for
4658 * backwards compatibility with Vim 3.0.
4659 * Misuse errbuf[] for the resulting string.
4660 */
4661 else if (varp == (char_u *)&p_ww
4662 && VIM_ISDIGIT(*arg))
4663 {
4664 *errbuf = NUL;
4665 i = getdigits(&arg);
4666 if (i & 1)
4667 STRCAT(errbuf, "b,");
4668 if (i & 2)
4669 STRCAT(errbuf, "s,");
4670 if (i & 4)
4671 STRCAT(errbuf, "h,l,");
4672 if (i & 8)
4673 STRCAT(errbuf, "<,>,");
4674 if (i & 16)
4675 STRCAT(errbuf, "[,],");
4676 if (*errbuf != NUL) /* remove trailing , */
4677 errbuf[STRLEN(errbuf) - 1] = NUL;
4678 save_arg = arg;
4679 arg = errbuf;
4680 }
4681 /*
4682 * Remove '>' before 'dir' and 'bdir', for
4683 * backwards compatibility with version 3.0
4684 */
4685 else if ( *arg == '>'
4686 && (varp == (char_u *)&p_dir
4687 || varp == (char_u *)&p_bdir))
4688 {
4689 ++arg;
4690 }
4691
4692 /* When setting the local value of a global
4693 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004694 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004695 && (opt_flags & OPT_LOCAL))
4696 origval = *(char_u **)get_varp(
4697 &options[opt_idx]);
4698 else
4699 origval = oldval;
4700
4701 /*
4702 * Copy the new string into allocated memory.
4703 * Can't use set_string_option_direct(), because
4704 * we need to remove the backslashes.
4705 */
4706 /* get a bit too much */
4707 newlen = (unsigned)STRLEN(arg) + 1;
4708 if (adding || prepending || removing)
4709 newlen += (unsigned)STRLEN(origval) + 1;
4710 newval = alloc(newlen);
4711 if (newval == NULL) /* out of mem, don't change */
4712 break;
4713 s = newval;
4714
4715 /*
4716 * Copy the string, skip over escaped chars.
4717 * For MS-DOS and WIN32 backslashes before normal
4718 * file name characters are not removed, and keep
4719 * backslash at start, for "\\machine\path", but
4720 * do remove it for "\\\\machine\\path".
4721 * The reverse is found in ExpandOldSetting().
4722 */
4723 while (*arg && !vim_iswhite(*arg))
4724 {
4725 if (*arg == '\\' && arg[1] != NUL
4726#ifdef BACKSLASH_IN_FILENAME
4727 && !((flags & P_EXPAND)
4728 && vim_isfilec(arg[1])
4729 && (arg[1] != '\\'
4730 || (s == newval
4731 && arg[2] != '\\')))
4732#endif
4733 )
4734 ++arg; /* remove backslash */
4735#ifdef FEAT_MBYTE
4736 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004737 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004738 {
4739 /* copy multibyte char */
4740 mch_memmove(s, arg, (size_t)i);
4741 arg += i;
4742 s += i;
4743 }
4744 else
4745#endif
4746 *s++ = *arg++;
4747 }
4748 *s = NUL;
4749
4750 /*
4751 * Expand environment variables and ~.
4752 * Don't do it when adding without inserting a
4753 * comma.
4754 */
4755 if (!(adding || prepending || removing)
4756 || (flags & P_COMMA))
4757 {
4758 s = option_expand(opt_idx, newval);
4759 if (s != NULL)
4760 {
4761 vim_free(newval);
4762 newlen = (unsigned)STRLEN(s) + 1;
4763 if (adding || prepending || removing)
4764 newlen += (unsigned)STRLEN(origval) + 1;
4765 newval = alloc(newlen);
4766 if (newval == NULL)
4767 break;
4768 STRCPY(newval, s);
4769 }
4770 }
4771
4772 /* locate newval[] in origval[] when removing it
4773 * and when adding to avoid duplicates */
4774 i = 0; /* init for GCC */
4775 if (removing || (flags & P_NODUP))
4776 {
4777 i = (int)STRLEN(newval);
4778 bs = 0;
4779 for (s = origval; *s; ++s)
4780 {
4781 if ((!(flags & P_COMMA)
4782 || s == origval
4783 || (s[-1] == ',' && !(bs & 1)))
4784 && STRNCMP(s, newval, i) == 0
4785 && (!(flags & P_COMMA)
4786 || s[i] == ','
4787 || s[i] == NUL))
4788 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004789 /* Count backslashes. Only a comma with an
4790 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004791 * recognized as a separator */
4792 if (s > origval && s[-1] == '\\')
4793 ++bs;
4794 else
4795 bs = 0;
4796 }
4797
4798 /* do not add if already there */
4799 if ((adding || prepending) && *s)
4800 {
4801 prepending = FALSE;
4802 adding = FALSE;
4803 STRCPY(newval, origval);
4804 }
4805 }
4806
4807 /* concatenate the two strings; add a ',' if
4808 * needed */
4809 if (adding || prepending)
4810 {
4811 comma = ((flags & P_COMMA) && *origval != NUL
4812 && *newval != NUL);
4813 if (adding)
4814 {
4815 i = (int)STRLEN(origval);
4816 mch_memmove(newval + i + comma, newval,
4817 STRLEN(newval) + 1);
4818 mch_memmove(newval, origval, (size_t)i);
4819 }
4820 else
4821 {
4822 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004823 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004824 }
4825 if (comma)
4826 newval[i] = ',';
4827 }
4828
4829 /* Remove newval[] from origval[]. (Note: "i" has
4830 * been set above and is used here). */
4831 if (removing)
4832 {
4833 STRCPY(newval, origval);
4834 if (*s)
4835 {
4836 /* may need to remove a comma */
4837 if (flags & P_COMMA)
4838 {
4839 if (s == origval)
4840 {
4841 /* include comma after string */
4842 if (s[i] == ',')
4843 ++i;
4844 }
4845 else
4846 {
4847 /* include comma before string */
4848 --s;
4849 ++i;
4850 }
4851 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004852 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004853 }
4854 }
4855
4856 if (flags & P_FLAGLIST)
4857 {
4858 /* Remove flags that appear twice. */
4859 for (s = newval; *s; ++s)
4860 if ((!(flags & P_COMMA) || *s != ',')
4861 && vim_strchr(s + 1, *s) != NULL)
4862 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004863 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004864 --s;
4865 }
4866 }
4867
4868 if (save_arg != NULL) /* number for 'whichwrap' */
4869 arg = save_arg;
4870 new_value_alloced = TRUE;
4871 }
4872
4873 /* Set the new value. */
4874 *(char_u **)(varp) = newval;
4875
4876 /* Handle side effects, and set the global value for
4877 * ":set" on local options. */
4878 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4879 new_value_alloced, oldval, errbuf, opt_flags);
4880
4881 /* If error detected, print the error message. */
4882 if (errmsg != NULL)
4883 goto skip;
4884 }
4885 else /* key code option */
4886 {
4887 char_u *p;
4888
4889 if (nextchar == '&')
4890 {
4891 if (add_termcap_entry(key_name, TRUE) == FAIL)
4892 errmsg = (char_u *)N_("E522: Not found in termcap");
4893 }
4894 else
4895 {
4896 ++arg; /* jump to after the '=' or ':' */
4897 for (p = arg; *p && !vim_iswhite(*p); ++p)
4898 if (*p == '\\' && p[1] != NUL)
4899 ++p;
4900 nextchar = *p;
4901 *p = NUL;
4902 add_termcode(key_name, arg, FALSE);
4903 *p = nextchar;
4904 }
4905 if (full_screen)
4906 ttest(FALSE);
4907 redraw_all_later(CLEAR);
4908 }
4909 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004910
Bram Moolenaar071d4272004-06-13 20:20:40 +00004911 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004912 did_set_option(opt_idx, opt_flags,
4913 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004914 }
4915
4916skip:
4917 /*
4918 * Advance to next argument.
4919 * - skip until a blank found, taking care of backslashes
4920 * - skip blanks
4921 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4922 */
4923 for (i = 0; i < 2 ; ++i)
4924 {
4925 while (*arg != NUL && !vim_iswhite(*arg))
4926 if (*arg++ == '\\' && *arg != NUL)
4927 ++arg;
4928 arg = skipwhite(arg);
4929 if (*arg != '=')
4930 break;
4931 }
4932 }
4933
4934 if (errmsg != NULL)
4935 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004936 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004937 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004938 if (i + (arg - startarg) < IOSIZE)
4939 {
4940 /* append the argument with the error */
4941 STRCAT(IObuff, ": ");
4942 mch_memmove(IObuff + i, startarg, (arg - startarg));
4943 IObuff[i + (arg - startarg)] = NUL;
4944 }
4945 /* make sure all characters are printable */
4946 trans_characters(IObuff, IOSIZE);
4947
4948 ++no_wait_return; /* wait_return done later */
4949 emsg(IObuff); /* show error highlighted */
4950 --no_wait_return;
4951
4952 return FAIL;
4953 }
4954
4955 arg = skipwhite(arg);
4956 }
4957
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004958theend:
4959 if (silent_mode && did_show)
4960 {
4961 /* After displaying option values in silent mode. */
4962 silent_mode = FALSE;
4963 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4964 msg_putchar('\n');
4965 cursor_on(); /* msg_start() switches it off */
4966 out_flush();
4967 silent_mode = TRUE;
4968 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4969 }
4970
Bram Moolenaar071d4272004-06-13 20:20:40 +00004971 return OK;
4972}
4973
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004974/*
4975 * Call this when an option has been given a new value through a user command.
4976 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4977 */
4978 static void
4979did_set_option(opt_idx, opt_flags, new_value)
4980 int opt_idx;
4981 int opt_flags; /* possibly with OPT_MODELINE */
4982 int new_value; /* value was replaced completely */
4983{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004984 long_u *p;
4985
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004986 options[opt_idx].flags |= P_WAS_SET;
4987
4988 /* When an option is set in the sandbox, from a modeline or in secure mode
4989 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004990 * flag. */
4991 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004992 if (secure
4993#ifdef HAVE_SANDBOX
4994 || sandbox != 0
4995#endif
4996 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004997 *p = *p | P_INSECURE;
4998 else if (new_value)
4999 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005000}
5001
Bram Moolenaar071d4272004-06-13 20:20:40 +00005002 static char_u *
5003illegal_char(errbuf, c)
5004 char_u *errbuf;
5005 int c;
5006{
5007 if (errbuf == NULL)
5008 return (char_u *)"";
5009 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005010 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005011 return errbuf;
5012}
5013
5014/*
5015 * Convert a key name or string into a key value.
5016 * Used for 'wildchar' and 'cedit' options.
5017 */
5018 static int
5019string_to_key(arg)
5020 char_u *arg;
5021{
5022 if (*arg == '<')
5023 return find_key_option(arg + 1);
5024 if (*arg == '^')
5025 return Ctrl_chr(arg[1]);
5026 return *arg;
5027}
5028
5029#ifdef FEAT_CMDWIN
5030/*
5031 * Check value of 'cedit' and set cedit_key.
5032 * Returns NULL if value is OK, error message otherwise.
5033 */
5034 static char_u *
5035check_cedit()
5036{
5037 int n;
5038
5039 if (*p_cedit == NUL)
5040 cedit_key = -1;
5041 else
5042 {
5043 n = string_to_key(p_cedit);
5044 if (vim_isprintc(n))
5045 return e_invarg;
5046 cedit_key = n;
5047 }
5048 return NULL;
5049}
5050#endif
5051
5052#ifdef FEAT_TITLE
5053/*
5054 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5055 * maketitle() to create and display it.
5056 * When switching the title or icon off, call mch_restore_title() to get
5057 * the old value back.
5058 */
5059 static void
5060did_set_title(icon)
5061 int icon; /* Did set icon instead of title */
5062{
5063 if (starting != NO_SCREEN
5064#ifdef FEAT_GUI
5065 && !gui.starting
5066#endif
5067 )
5068 {
5069 maketitle();
5070 if (icon)
5071 {
5072 if (!p_icon)
5073 mch_restore_title(2);
5074 }
5075 else
5076 {
5077 if (!p_title)
5078 mch_restore_title(1);
5079 }
5080 }
5081}
5082#endif
5083
5084/*
5085 * set_options_bin - called when 'bin' changes value.
5086 */
5087 void
5088set_options_bin(oldval, newval, opt_flags)
5089 int oldval;
5090 int newval;
5091 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5092{
5093 /*
5094 * The option values that are changed when 'bin' changes are
5095 * copied when 'bin is set and restored when 'bin' is reset.
5096 */
5097 if (newval)
5098 {
5099 if (!oldval) /* switched on */
5100 {
5101 if (!(opt_flags & OPT_GLOBAL))
5102 {
5103 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5104 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5105 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5106 curbuf->b_p_et_nobin = curbuf->b_p_et;
5107 }
5108 if (!(opt_flags & OPT_LOCAL))
5109 {
5110 p_tw_nobin = p_tw;
5111 p_wm_nobin = p_wm;
5112 p_ml_nobin = p_ml;
5113 p_et_nobin = p_et;
5114 }
5115 }
5116
5117 if (!(opt_flags & OPT_GLOBAL))
5118 {
5119 curbuf->b_p_tw = 0; /* no automatic line wrap */
5120 curbuf->b_p_wm = 0; /* no automatic line wrap */
5121 curbuf->b_p_ml = 0; /* no modelines */
5122 curbuf->b_p_et = 0; /* no expandtab */
5123 }
5124 if (!(opt_flags & OPT_LOCAL))
5125 {
5126 p_tw = 0;
5127 p_wm = 0;
5128 p_ml = FALSE;
5129 p_et = FALSE;
5130 p_bin = TRUE; /* needed when called for the "-b" argument */
5131 }
5132 }
5133 else if (oldval) /* switched off */
5134 {
5135 if (!(opt_flags & OPT_GLOBAL))
5136 {
5137 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5138 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5139 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5140 curbuf->b_p_et = curbuf->b_p_et_nobin;
5141 }
5142 if (!(opt_flags & OPT_LOCAL))
5143 {
5144 p_tw = p_tw_nobin;
5145 p_wm = p_wm_nobin;
5146 p_ml = p_ml_nobin;
5147 p_et = p_et_nobin;
5148 }
5149 }
5150}
5151
5152#ifdef FEAT_VIMINFO
5153/*
5154 * Find the parameter represented by the given character (eg ', :, ", or /),
5155 * and return its associated value in the 'viminfo' string.
5156 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005157 * If the parameter is not specified in the string or there is no following
5158 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005159 */
5160 int
5161get_viminfo_parameter(type)
5162 int type;
5163{
5164 char_u *p;
5165
5166 p = find_viminfo_parameter(type);
5167 if (p != NULL && VIM_ISDIGIT(*p))
5168 return atoi((char *)p);
5169 return -1;
5170}
5171
5172/*
5173 * Find the parameter represented by the given character (eg ''', ':', '"', or
5174 * '/') in the 'viminfo' option and return a pointer to the string after it.
5175 * Return NULL if the parameter is not specified in the string.
5176 */
5177 char_u *
5178find_viminfo_parameter(type)
5179 int type;
5180{
5181 char_u *p;
5182
5183 for (p = p_viminfo; *p; ++p)
5184 {
5185 if (*p == type)
5186 return p + 1;
5187 if (*p == 'n') /* 'n' is always the last one */
5188 break;
5189 p = vim_strchr(p, ','); /* skip until next ',' */
5190 if (p == NULL) /* hit the end without finding parameter */
5191 break;
5192 }
5193 return NULL;
5194}
5195#endif
5196
5197/*
5198 * Expand environment variables for some string options.
5199 * These string options cannot be indirect!
5200 * If "val" is NULL expand the current value of the option.
5201 * Return pointer to NameBuff, or NULL when not expanded.
5202 */
5203 static char_u *
5204option_expand(opt_idx, val)
5205 int opt_idx;
5206 char_u *val;
5207{
5208 /* if option doesn't need expansion nothing to do */
5209 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5210 return NULL;
5211
5212 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5213 * expand_env() would truncate the string. */
5214 if (val != NULL && STRLEN(val) > MAXPATHL)
5215 return NULL;
5216
5217 if (val == NULL)
5218 val = *(char_u **)options[opt_idx].var;
5219
5220 /*
5221 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5222 * Escape spaces when expanding 'tags', they are used to separate file
5223 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005224 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005225 */
5226 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005227 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005228#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005229 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5230#endif
5231 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005232 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5233 return NULL;
5234
5235 return NameBuff;
5236}
5237
5238/*
5239 * After setting various option values: recompute variables that depend on
5240 * option values.
5241 */
5242 static void
5243didset_options()
5244{
5245 /* initialize the table for 'iskeyword' et.al. */
5246 (void)init_chartab();
5247
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005248#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005249 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005250#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005251 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5252#ifdef FEAT_SESSION
5253 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5254 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5255#endif
5256#ifdef FEAT_FOLDING
5257 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5258#endif
5259 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5260#ifdef FEAT_VIRTUALEDIT
5261 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5262#endif
5263#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5264 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5265#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005266#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005267 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005268 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005269 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005270#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005271#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5272 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5273#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005274#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005275 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5276#endif
5277#ifdef FEAT_CMDWIN
5278 /* set cedit_key */
5279 (void)check_cedit();
5280#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005281#ifdef FEAT_LINEBREAK
5282 briopt_check();
5283#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005284}
5285
5286/*
5287 * Check for string options that are NULL (normally only termcap options).
5288 */
5289 void
5290check_options()
5291{
5292 int opt_idx;
5293
5294 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5295 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5296 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5297}
5298
5299/*
5300 * Check string options in a buffer for NULL value.
5301 */
5302 void
5303check_buf_options(buf)
5304 buf_T *buf;
5305{
5306#if defined(FEAT_QUICKFIX)
5307 check_string_option(&buf->b_p_bh);
5308 check_string_option(&buf->b_p_bt);
5309#endif
5310#ifdef FEAT_MBYTE
5311 check_string_option(&buf->b_p_fenc);
5312#endif
5313 check_string_option(&buf->b_p_ff);
5314#ifdef FEAT_FIND_ID
5315 check_string_option(&buf->b_p_def);
5316 check_string_option(&buf->b_p_inc);
5317# ifdef FEAT_EVAL
5318 check_string_option(&buf->b_p_inex);
5319# endif
5320#endif
5321#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5322 check_string_option(&buf->b_p_inde);
5323 check_string_option(&buf->b_p_indk);
5324#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005325#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5326 check_string_option(&buf->b_p_bexpr);
5327#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005328#if defined(FEAT_CRYPT)
5329 check_string_option(&buf->b_p_cm);
5330#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005331#if defined(FEAT_EVAL)
5332 check_string_option(&buf->b_p_fex);
5333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005334#ifdef FEAT_CRYPT
5335 check_string_option(&buf->b_p_key);
5336#endif
5337 check_string_option(&buf->b_p_kp);
5338 check_string_option(&buf->b_p_mps);
5339 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005340 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005341 check_string_option(&buf->b_p_isk);
5342#ifdef FEAT_COMMENTS
5343 check_string_option(&buf->b_p_com);
5344#endif
5345#ifdef FEAT_FOLDING
5346 check_string_option(&buf->b_p_cms);
5347#endif
5348 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005349#ifdef FEAT_TEXTOBJ
5350 check_string_option(&buf->b_p_qe);
5351#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352#ifdef FEAT_SYN_HL
5353 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005354#endif
5355#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005356 check_string_option(&buf->b_s.b_p_spc);
5357 check_string_option(&buf->b_s.b_p_spf);
5358 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005359#endif
5360#ifdef FEAT_SEARCHPATH
5361 check_string_option(&buf->b_p_sua);
5362#endif
5363#ifdef FEAT_CINDENT
5364 check_string_option(&buf->b_p_cink);
5365 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005366 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005367#endif
5368#ifdef FEAT_AUTOCMD
5369 check_string_option(&buf->b_p_ft);
5370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005371#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5372 check_string_option(&buf->b_p_cinw);
5373#endif
5374#ifdef FEAT_INS_EXPAND
5375 check_string_option(&buf->b_p_cpt);
5376#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005377#ifdef FEAT_COMPL_FUNC
5378 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005379 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005380#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005381#ifdef FEAT_KEYMAP
5382 check_string_option(&buf->b_p_keymap);
5383#endif
5384#ifdef FEAT_QUICKFIX
5385 check_string_option(&buf->b_p_gp);
5386 check_string_option(&buf->b_p_mp);
5387 check_string_option(&buf->b_p_efm);
5388#endif
5389 check_string_option(&buf->b_p_ep);
5390 check_string_option(&buf->b_p_path);
5391 check_string_option(&buf->b_p_tags);
5392#ifdef FEAT_INS_EXPAND
5393 check_string_option(&buf->b_p_dict);
5394 check_string_option(&buf->b_p_tsr);
5395#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005396#ifdef FEAT_LISP
5397 check_string_option(&buf->b_p_lw);
5398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005399}
5400
5401/*
5402 * Free the string allocated for an option.
5403 * Checks for the string being empty_option. This may happen if we're out of
5404 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5405 * check_options().
5406 * Does NOT check for P_ALLOCED flag!
5407 */
5408 void
5409free_string_option(p)
5410 char_u *p;
5411{
5412 if (p != empty_option)
5413 vim_free(p);
5414}
5415
5416 void
5417clear_string_option(pp)
5418 char_u **pp;
5419{
5420 if (*pp != empty_option)
5421 vim_free(*pp);
5422 *pp = empty_option;
5423}
5424
5425 static void
5426check_string_option(pp)
5427 char_u **pp;
5428{
5429 if (*pp == NULL)
5430 *pp = empty_option;
5431}
5432
5433/*
5434 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5435 */
5436 void
5437set_term_option_alloced(p)
5438 char_u **p;
5439{
5440 int opt_idx;
5441
5442 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5443 if (options[opt_idx].var == (char_u *)p)
5444 {
5445 options[opt_idx].flags |= P_ALLOCED;
5446 return;
5447 }
5448 return; /* cannot happen: didn't find it! */
5449}
5450
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005451#if defined(FEAT_EVAL) || defined(PROTO)
5452/*
5453 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5454 * Return FALSE when it wasn't.
5455 * Return -1 for an unknown option.
5456 */
5457 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005458was_set_insecurely(opt, opt_flags)
5459 char_u *opt;
5460 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005461{
5462 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005463 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005464
5465 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005466 {
5467 flagp = insecure_flag(idx, opt_flags);
5468 return (*flagp & P_INSECURE) != 0;
5469 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005470 EMSG2(_(e_intern2), "was_set_insecurely()");
5471 return -1;
5472}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005473
5474/*
5475 * Get a pointer to the flags used for the P_INSECURE flag of option
5476 * "opt_idx". For some local options a local flags field is used.
5477 */
5478 static long_u *
5479insecure_flag(opt_idx, opt_flags)
5480 int opt_idx;
5481 int opt_flags;
5482{
5483 if (opt_flags & OPT_LOCAL)
5484 switch ((int)options[opt_idx].indir)
5485 {
5486#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005487 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005488#endif
5489#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005490# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005491 case PV_FDE: return &curwin->w_p_fde_flags;
5492 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005493# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005494# ifdef FEAT_BEVAL
5495 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5496# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005497# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005498 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005499# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005500 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005501# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005502 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005503# endif
5504#endif
5505 }
5506
5507 /* Nothing special, return global flags field. */
5508 return &options[opt_idx].flags;
5509}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005510#endif
5511
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005512#ifdef FEAT_TITLE
5513static void redraw_titles __ARGS((void));
5514
5515/*
5516 * Redraw the window title and/or tab page text later.
5517 */
5518static void redraw_titles()
5519{
5520 need_maketitle = TRUE;
5521# ifdef FEAT_WINDOWS
5522 redraw_tabline = TRUE;
5523# endif
5524}
5525#endif
5526
Bram Moolenaar071d4272004-06-13 20:20:40 +00005527/*
5528 * Set a string option to a new value (without checking the effect).
5529 * The string is copied into allocated memory.
5530 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005531 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005532 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533 */
5534 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005535set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536 char_u *name;
5537 int opt_idx;
5538 char_u *val;
5539 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005540 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541{
5542 char_u *s;
5543 char_u **varp;
5544 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005545 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546
Bram Moolenaar89d40322006-08-29 15:30:07 +00005547 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005548 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005549 idx = findoption(name);
5550 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005551 {
5552 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005553 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005554 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005555 }
5556
Bram Moolenaar89d40322006-08-29 15:30:07 +00005557 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558 return;
5559
5560 s = vim_strsave(val);
5561 if (s != NULL)
5562 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005563 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005565 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566 free_string_option(*varp);
5567 *varp = s;
5568
5569 /* For buffer/window local option may also set the global value. */
5570 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005571 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005572
Bram Moolenaar89d40322006-08-29 15:30:07 +00005573 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005574
5575 /* When setting both values of a global option with a local value,
5576 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005577 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578 {
5579 free_string_option(*varp);
5580 *varp = empty_option;
5581 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005582# ifdef FEAT_EVAL
5583 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005584 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005585 set_sid == 0 ? current_SID : set_sid);
5586# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005587 }
5588}
5589
5590/*
5591 * Set global value for string option when it's a local option.
5592 */
5593 static void
5594set_string_option_global(opt_idx, varp)
5595 int opt_idx; /* option index */
5596 char_u **varp; /* pointer to option variable */
5597{
5598 char_u **p, *s;
5599
5600 /* the global value is always allocated */
5601 if (options[opt_idx].var == VAR_WIN)
5602 p = (char_u **)GLOBAL_WO(varp);
5603 else
5604 p = (char_u **)options[opt_idx].var;
5605 if (options[opt_idx].indir != PV_NONE
5606 && p != varp
5607 && (s = vim_strsave(*varp)) != NULL)
5608 {
5609 free_string_option(*p);
5610 *p = s;
5611 }
5612}
5613
5614/*
5615 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005616 *
5617 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005618 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005619 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005620set_string_option(opt_idx, value, opt_flags)
5621 int opt_idx;
5622 char_u *value;
5623 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5624{
5625 char_u *s;
5626 char_u **varp;
5627 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005628 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005629
5630 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005631 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005632
5633 s = vim_strsave(value);
5634 if (s != NULL)
5635 {
5636 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5637 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005638 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639 ? OPT_GLOBAL : OPT_LOCAL)
5640 : opt_flags);
5641 oldval = *varp;
5642 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005643 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5644 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005645 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005646 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005647 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005648}
5649
5650/*
5651 * Handle string options that need some action to perform when changed.
5652 * Returns NULL for success, or an error message for an error.
5653 */
5654 static char_u *
5655did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5656 opt_flags)
5657 int opt_idx; /* index in options[] table */
5658 char_u **varp; /* pointer to the option variable */
5659 int new_value_alloced; /* new value was allocated */
5660 char_u *oldval; /* previous value of the option */
5661 char_u *errbuf; /* buffer for errors, or NULL */
5662 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5663{
5664 char_u *errmsg = NULL;
5665 char_u *s, *p;
5666 int did_chartab = FALSE;
5667 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005668 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005669#ifdef FEAT_GUI
5670 /* set when changing an option that only requires a redraw in the GUI */
5671 int redraw_gui_only = FALSE;
5672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673
5674 /* Get the global option to compare with, otherwise we would have to check
5675 * two values for all local options. */
5676 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5677
5678 /* Disallow changing some options from secure mode */
5679 if ((secure
5680#ifdef HAVE_SANDBOX
5681 || sandbox != 0
5682#endif
5683 ) && (options[opt_idx].flags & P_SECURE))
5684 {
5685 errmsg = e_secure;
5686 }
5687
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005688 /* Check for a "normal" file name in some options. Disallow a path
5689 * separator (slash and/or backslash), wildcards and characters that are
5690 * often illegal in a file name. */
5691 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005692 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005693 {
5694 errmsg = e_invarg;
5695 }
5696
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697 /* 'term' */
5698 else if (varp == &T_NAME)
5699 {
5700 if (T_NAME[0] == NUL)
5701 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5702#ifdef FEAT_GUI
5703 if (gui.in_use)
5704 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5705 else if (term_is_gui(T_NAME))
5706 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5707#endif
5708 else if (set_termname(T_NAME) == FAIL)
5709 errmsg = (char_u *)N_("E522: Not found in termcap");
5710 else
5711 /* Screen colors may have changed. */
5712 redraw_later_clear();
5713 }
5714
5715 /* 'backupcopy' */
5716 else if (varp == &p_bkc)
5717 {
5718 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5719 errmsg = e_invarg;
5720 if (((bkc_flags & BKC_AUTO) != 0)
5721 + ((bkc_flags & BKC_YES) != 0)
5722 + ((bkc_flags & BKC_NO) != 0) != 1)
5723 {
5724 /* Must have exactly one of "auto", "yes" and "no". */
5725 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5726 errmsg = e_invarg;
5727 }
5728 }
5729
5730 /* 'backupext' and 'patchmode' */
5731 else if (varp == &p_bex || varp == &p_pm)
5732 {
5733 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5734 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5735 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5736 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005737#ifdef FEAT_LINEBREAK
5738 /* 'breakindentopt' */
5739 else if (varp == &curwin->w_p_briopt)
5740 {
5741 if (briopt_check() == FAIL)
5742 errmsg = e_invarg;
5743 }
5744#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745
5746 /*
5747 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5748 * If the new option is invalid, use old value. 'lisp' option: refill
5749 * chartab[] for '-' char
5750 */
5751 else if ( varp == &p_isi
5752 || varp == &(curbuf->b_p_isk)
5753 || varp == &p_isp
5754 || varp == &p_isf)
5755 {
5756 if (init_chartab() == FAIL)
5757 {
5758 did_chartab = TRUE; /* need to restore it below */
5759 errmsg = e_invarg; /* error in value */
5760 }
5761 }
5762
5763 /* 'helpfile' */
5764 else if (varp == &p_hf)
5765 {
5766 /* May compute new values for $VIM and $VIMRUNTIME */
5767 if (didset_vim)
5768 {
5769 vim_setenv((char_u *)"VIM", (char_u *)"");
5770 didset_vim = FALSE;
5771 }
5772 if (didset_vimruntime)
5773 {
5774 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5775 didset_vimruntime = FALSE;
5776 }
5777 }
5778
Bram Moolenaar1a384422010-07-14 19:53:30 +02005779#ifdef FEAT_SYN_HL
5780 /* 'colorcolumn' */
5781 else if (varp == &curwin->w_p_cc)
5782 errmsg = check_colorcolumn(curwin);
5783#endif
5784
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785#ifdef FEAT_MULTI_LANG
5786 /* 'helplang' */
5787 else if (varp == &p_hlg)
5788 {
5789 /* Check for "", "ab", "ab,cd", etc. */
5790 for (s = p_hlg; *s != NUL; s += 3)
5791 {
5792 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5793 {
5794 errmsg = e_invarg;
5795 break;
5796 }
5797 if (s[2] == NUL)
5798 break;
5799 }
5800 }
5801#endif
5802
5803 /* 'highlight' */
5804 else if (varp == &p_hl)
5805 {
5806 if (highlight_changed() == FAIL)
5807 errmsg = e_invarg; /* invalid flags */
5808 }
5809
5810 /* 'nrformats' */
5811 else if (gvarp == &p_nf)
5812 {
5813 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5814 errmsg = e_invarg;
5815 }
5816
5817#ifdef FEAT_SESSION
5818 /* 'sessionoptions' */
5819 else if (varp == &p_ssop)
5820 {
5821 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5822 errmsg = e_invarg;
5823 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5824 {
5825 /* Don't allow both "sesdir" and "curdir". */
5826 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5827 errmsg = e_invarg;
5828 }
5829 }
5830 /* 'viewoptions' */
5831 else if (varp == &p_vop)
5832 {
5833 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5834 errmsg = e_invarg;
5835 }
5836#endif
5837
5838 /* 'scrollopt' */
5839#ifdef FEAT_SCROLLBIND
5840 else if (varp == &p_sbo)
5841 {
5842 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5843 errmsg = e_invarg;
5844 }
5845#endif
5846
5847 /* 'ambiwidth' */
5848#ifdef FEAT_MBYTE
5849 else if (varp == &p_ambw)
5850 {
5851 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5852 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005853 else if (set_chars_option(&p_lcs) != NULL)
5854 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5855# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5856 else if (set_chars_option(&p_fcs) != NULL)
5857 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5858# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005859 }
5860#endif
5861
5862 /* 'background' */
5863 else if (varp == &p_bg)
5864 {
5865 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5866 {
5867#ifdef FEAT_EVAL
5868 int dark = (*p_bg == 'd');
5869#endif
5870
5871 init_highlight(FALSE, FALSE);
5872
5873#ifdef FEAT_EVAL
5874 if (dark != (*p_bg == 'd')
5875 && get_var_value((char_u *)"g:colors_name") != NULL)
5876 {
5877 /* The color scheme must have set 'background' back to another
5878 * value, that's not what we want here. Disable the color
5879 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005880 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005881 free_string_option(p_bg);
5882 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5883 check_string_option(&p_bg);
5884 init_highlight(FALSE, FALSE);
5885 }
5886#endif
5887 }
5888 else
5889 errmsg = e_invarg;
5890 }
5891
5892 /* 'wildmode' */
5893 else if (varp == &p_wim)
5894 {
5895 if (check_opt_wim() == FAIL)
5896 errmsg = e_invarg;
5897 }
5898
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005899#ifdef FEAT_CMDL_COMPL
5900 /* 'wildoptions' */
5901 else if (varp == &p_wop)
5902 {
5903 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5904 errmsg = e_invarg;
5905 }
5906#endif
5907
Bram Moolenaar071d4272004-06-13 20:20:40 +00005908#ifdef FEAT_WAK
5909 /* 'winaltkeys' */
5910 else if (varp == &p_wak)
5911 {
5912 if (*p_wak == NUL
5913 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5914 errmsg = e_invarg;
5915# ifdef FEAT_MENU
5916# ifdef FEAT_GUI_MOTIF
5917 else if (gui.in_use)
5918 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5919# else
5920# ifdef FEAT_GUI_GTK
5921 else if (gui.in_use)
5922 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5923# endif
5924# endif
5925# endif
5926 }
5927#endif
5928
5929#ifdef FEAT_AUTOCMD
5930 /* 'eventignore' */
5931 else if (varp == &p_ei)
5932 {
5933 if (check_ei() == FAIL)
5934 errmsg = e_invarg;
5935 }
5936#endif
5937
5938#ifdef FEAT_MBYTE
5939 /* 'encoding' and 'fileencoding' */
5940 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5941 {
5942 if (gvarp == &p_fenc)
5943 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005944 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005945 errmsg = e_modifiable;
5946 else if (vim_strchr(*varp, ',') != NULL)
5947 /* No comma allowed in 'fileencoding'; catches confusing it
5948 * with 'fileencodings'. */
5949 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005950 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005951 {
5952# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005953 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005954 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005955# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005956 /* Add 'fileencoding' to the swap file. */
5957 ml_setflags(curbuf);
5958 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005959 }
5960 if (errmsg == NULL)
5961 {
5962 /* canonize the value, so that STRCMP() can be used on it */
5963 p = enc_canonize(*varp);
5964 if (p != NULL)
5965 {
5966 vim_free(*varp);
5967 *varp = p;
5968 }
5969 if (varp == &p_enc)
5970 {
5971 errmsg = mb_init();
5972# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005973 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005974# endif
5975 }
5976 }
5977
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005978# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005979 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5980 {
5981 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5982 if (STRCMP(p_tenc, "utf-8") != 0)
5983 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5984 }
5985# endif
5986
5987 if (errmsg == NULL)
5988 {
5989# ifdef FEAT_KEYMAP
5990 /* When 'keymap' is used and 'encoding' changes, reload the keymap
5991 * (with another encoding). */
5992 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
5993 (void)keymap_init();
5994# endif
5995
5996 /* When 'termencoding' is not empty and 'encoding' changes or when
5997 * 'termencoding' changes, need to setup for keyboard input and
5998 * display output conversion. */
5999 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6000 {
6001 convert_setup(&input_conv, p_tenc, p_enc);
6002 convert_setup(&output_conv, p_enc, p_tenc);
6003 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006004
6005# if defined(WIN3264) && defined(FEAT_MBYTE)
6006 /* $HOME may have characters in active code page. */
6007 if (varp == &p_enc)
6008 init_homedir();
6009# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006010 }
6011 }
6012#endif
6013
6014#if defined(FEAT_POSTSCRIPT)
6015 else if (varp == &p_penc)
6016 {
6017 /* Canonize printencoding if VIM standard one */
6018 p = enc_canonize(p_penc);
6019 if (p != NULL)
6020 {
6021 vim_free(p_penc);
6022 p_penc = p;
6023 }
6024 else
6025 {
6026 /* Ensure lower case and '-' for '_' */
6027 for (s = p_penc; *s != NUL; s++)
6028 {
6029 if (*s == '_')
6030 *s = '-';
6031 else
6032 *s = TOLOWER_ASC(*s);
6033 }
6034 }
6035 }
6036#endif
6037
Bram Moolenaar9372a112005-12-06 19:59:18 +00006038#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006039 else if (varp == &p_imak)
6040 {
6041 if (gui.in_use && !im_xim_isvalid_imactivate())
6042 errmsg = e_invarg;
6043 }
6044#endif
6045
6046#ifdef FEAT_KEYMAP
6047 else if (varp == &curbuf->b_p_keymap)
6048 {
6049 /* load or unload key mapping tables */
6050 errmsg = keymap_init();
6051
Bram Moolenaarfab06232009-03-04 03:13:35 +00006052 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006053 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006054 if (*curbuf->b_p_keymap != NUL)
6055 {
6056 /* Installed a new keymap, switch on using it. */
6057 curbuf->b_p_iminsert = B_IMODE_LMAP;
6058 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6059 curbuf->b_p_imsearch = B_IMODE_LMAP;
6060 }
6061 else
6062 {
6063 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6064 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6065 curbuf->b_p_iminsert = B_IMODE_NONE;
6066 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6067 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6068 }
6069 if ((opt_flags & OPT_LOCAL) == 0)
6070 {
6071 set_iminsert_global();
6072 set_imsearch_global();
6073 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006074# ifdef FEAT_WINDOWS
6075 status_redraw_curbuf();
6076# endif
6077 }
6078 }
6079#endif
6080
6081 /* 'fileformat' */
6082 else if (gvarp == &p_ff)
6083 {
6084 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6085 errmsg = e_modifiable;
6086 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6087 errmsg = e_invarg;
6088 else
6089 {
6090 /* may also change 'textmode' */
6091 if (get_fileformat(curbuf) == EOL_DOS)
6092 curbuf->b_p_tx = TRUE;
6093 else
6094 curbuf->b_p_tx = FALSE;
6095#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006096 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006097#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006098 /* update flag in swap file */
6099 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006100 /* Redraw needed when switching to/from "mac": a CR in the text
6101 * will be displayed differently. */
6102 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6103 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006104 }
6105 }
6106
6107 /* 'fileformats' */
6108 else if (varp == &p_ffs)
6109 {
6110 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6111 errmsg = e_invarg;
6112 else
6113 {
6114 /* also change 'textauto' */
6115 if (*p_ffs == NUL)
6116 p_ta = FALSE;
6117 else
6118 p_ta = TRUE;
6119 }
6120 }
6121
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006122#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006123 /* 'cryptkey' */
6124 else if (gvarp == &p_key)
6125 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006126# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127 /* Make sure the ":set" command doesn't show the new value in the
6128 * history. */
6129 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006130# endif
6131 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6132 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006133 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6134 }
6135
6136 else if (gvarp == &p_cm)
6137 {
6138 if (opt_flags & OPT_LOCAL)
6139 p = curbuf->b_p_cm;
6140 else
6141 p = p_cm;
6142 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6143 errmsg = e_invarg;
6144 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6145 errmsg = e_invarg;
6146 else
6147 {
6148 /* When setting the global value to empty, make it "zip". */
6149 if (*p_cm == NUL)
6150 {
6151 if (new_value_alloced)
6152 free_string_option(p_cm);
6153 p_cm = vim_strsave((char_u *)"zip");
6154 new_value_alloced = TRUE;
6155 }
6156
6157 /* Need to update the swapfile when the effective method changed.
6158 * Set "s" to the effective old value, "p" to the effective new
6159 * method and compare. */
6160 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6161 s = p_cm; /* was previously using the global value */
6162 else
6163 s = oldval;
6164 if (*curbuf->b_p_cm == NUL)
6165 p = p_cm; /* is now using the global value */
6166 else
6167 p = curbuf->b_p_cm;
6168 if (STRCMP(s, p) != 0)
6169 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6170 crypt_method_from_string(s));
6171
6172 /* If the global value changes need to update the swapfile for all
6173 * buffers using that value. */
6174 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6175 {
6176 buf_T *buf;
6177
6178 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6179 if (buf != curbuf && *buf->b_p_cm == NUL)
6180 ml_set_crypt_key(buf, buf->b_p_key,
6181 crypt_method_from_string(oldval));
6182 }
6183 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006184 }
6185#endif
6186
6187 /* 'matchpairs' */
6188 else if (gvarp == &p_mps)
6189 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006190#ifdef FEAT_MBYTE
6191 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006192 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006193 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006194 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006195 int x2 = -1;
6196 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006197
6198 if (*p != NUL)
6199 p += mb_ptr2len(p);
6200 if (*p != NUL)
6201 x2 = *p++;
6202 if (*p != NUL)
6203 {
6204 x3 = mb_ptr2char(p);
6205 p += mb_ptr2len(p);
6206 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006207 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006208 {
6209 errmsg = e_invarg;
6210 break;
6211 }
6212 if (*p == NUL)
6213 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006214 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006215 }
6216 else
6217#endif
6218 {
6219 /* Check for "x:y,x:y" */
6220 for (p = *varp; *p != NUL; p += 4)
6221 {
6222 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6223 {
6224 errmsg = e_invarg;
6225 break;
6226 }
6227 if (p[3] == NUL)
6228 break;
6229 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006230 }
6231 }
6232
6233#ifdef FEAT_COMMENTS
6234 /* 'comments' */
6235 else if (gvarp == &p_com)
6236 {
6237 for (s = *varp; *s; )
6238 {
6239 while (*s && *s != ':')
6240 {
6241 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6242 && !VIM_ISDIGIT(*s) && *s != '-')
6243 {
6244 errmsg = illegal_char(errbuf, *s);
6245 break;
6246 }
6247 ++s;
6248 }
6249 if (*s++ == NUL)
6250 errmsg = (char_u *)N_("E524: Missing colon");
6251 else if (*s == ',' || *s == NUL)
6252 errmsg = (char_u *)N_("E525: Zero length string");
6253 if (errmsg != NULL)
6254 break;
6255 while (*s && *s != ',')
6256 {
6257 if (*s == '\\' && s[1] != NUL)
6258 ++s;
6259 ++s;
6260 }
6261 s = skip_to_option_part(s);
6262 }
6263 }
6264#endif
6265
6266 /* 'listchars' */
6267 else if (varp == &p_lcs)
6268 {
6269 errmsg = set_chars_option(varp);
6270 }
6271
6272#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6273 /* 'fillchars' */
6274 else if (varp == &p_fcs)
6275 {
6276 errmsg = set_chars_option(varp);
6277 }
6278#endif
6279
6280#ifdef FEAT_CMDWIN
6281 /* 'cedit' */
6282 else if (varp == &p_cedit)
6283 {
6284 errmsg = check_cedit();
6285 }
6286#endif
6287
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006288 /* 'verbosefile' */
6289 else if (varp == &p_vfile)
6290 {
6291 verbose_stop();
6292 if (*p_vfile != NUL && verbose_open() == FAIL)
6293 errmsg = e_invarg;
6294 }
6295
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296#ifdef FEAT_VIMINFO
6297 /* 'viminfo' */
6298 else if (varp == &p_viminfo)
6299 {
6300 for (s = p_viminfo; *s;)
6301 {
6302 /* Check it's a valid character */
6303 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6304 {
6305 errmsg = illegal_char(errbuf, *s);
6306 break;
6307 }
6308 if (*s == 'n') /* name is always last one */
6309 {
6310 break;
6311 }
6312 else if (*s == 'r') /* skip until next ',' */
6313 {
6314 while (*++s && *s != ',')
6315 ;
6316 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006317 else if (*s == '%')
6318 {
6319 /* optional number */
6320 while (vim_isdigit(*++s))
6321 ;
6322 }
6323 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006324 ++s; /* no extra chars */
6325 else /* must have a number */
6326 {
6327 while (vim_isdigit(*++s))
6328 ;
6329
6330 if (!VIM_ISDIGIT(*(s - 1)))
6331 {
6332 if (errbuf != NULL)
6333 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006334 sprintf((char *)errbuf,
6335 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006336 transchar_byte(*(s - 1)));
6337 errmsg = errbuf;
6338 }
6339 else
6340 errmsg = (char_u *)"";
6341 break;
6342 }
6343 }
6344 if (*s == ',')
6345 ++s;
6346 else if (*s)
6347 {
6348 if (errbuf != NULL)
6349 errmsg = (char_u *)N_("E527: Missing comma");
6350 else
6351 errmsg = (char_u *)"";
6352 break;
6353 }
6354 }
6355 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6356 errmsg = (char_u *)N_("E528: Must specify a ' value");
6357 }
6358#endif /* FEAT_VIMINFO */
6359
6360 /* terminal options */
6361 else if (istermoption(&options[opt_idx]) && full_screen)
6362 {
6363 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6364 if (varp == &T_CCO)
6365 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006366 int colors = atoi((char *)T_CCO);
6367
6368 /* Only reinitialize colors if t_Co value has really changed to
6369 * avoid expensive reload of colorscheme if t_Co is set to the
6370 * same value multiple times. */
6371 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006372 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006373 t_colors = colors;
6374 if (t_colors <= 1)
6375 {
6376 if (new_value_alloced)
6377 vim_free(T_CCO);
6378 T_CCO = empty_option;
6379 }
6380 /* We now have a different color setup, initialize it again. */
6381 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006382 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 }
6384 ttest(FALSE);
6385 if (varp == &T_ME)
6386 {
6387 out_str(T_ME);
6388 redraw_later(CLEAR);
6389#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6390 /* Since t_me has been set, this probably means that the user
6391 * wants to use this as default colors. Need to reset default
6392 * background/foreground colors. */
6393 mch_set_normal_colors();
6394#endif
6395 }
6396 }
6397
6398#ifdef FEAT_LINEBREAK
6399 /* 'showbreak' */
6400 else if (varp == &p_sbr)
6401 {
6402 for (s = p_sbr; *s; )
6403 {
6404 if (ptr2cells(s) != 1)
6405 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006406 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006407 }
6408 }
6409#endif
6410
6411#ifdef FEAT_GUI
6412 /* 'guifont' */
6413 else if (varp == &p_guifont)
6414 {
6415 if (gui.in_use)
6416 {
6417 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006418# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006419 /*
6420 * Put up a font dialog and let the user select a new value.
6421 * If this is cancelled go back to the old value but don't
6422 * give an error message.
6423 */
6424 if (STRCMP(p, "*") == 0)
6425 {
6426 p = gui_mch_font_dialog(oldval);
6427
6428 if (new_value_alloced)
6429 free_string_option(p_guifont);
6430
6431 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6432 new_value_alloced = TRUE;
6433 }
6434# endif
6435 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6436 {
6437# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6438 if (STRCMP(p_guifont, "*") == 0)
6439 {
6440 /* Dialog was cancelled: Keep the old value without giving
6441 * an error message. */
6442 if (new_value_alloced)
6443 free_string_option(p_guifont);
6444 p_guifont = vim_strsave(oldval);
6445 new_value_alloced = TRUE;
6446 }
6447 else
6448# endif
6449 errmsg = (char_u *)N_("E596: Invalid font(s)");
6450 }
6451 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006452 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006453 }
6454# ifdef FEAT_XFONTSET
6455 else if (varp == &p_guifontset)
6456 {
6457 if (STRCMP(p_guifontset, "*") == 0)
6458 errmsg = (char_u *)N_("E597: can't select fontset");
6459 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6460 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006461 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006462 }
6463# endif
6464# ifdef FEAT_MBYTE
6465 else if (varp == &p_guifontwide)
6466 {
6467 if (STRCMP(p_guifontwide, "*") == 0)
6468 errmsg = (char_u *)N_("E533: can't select wide font");
6469 else if (gui_get_wide_font() == FAIL)
6470 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006471 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006472 }
6473# endif
6474#endif
6475
6476#ifdef CURSOR_SHAPE
6477 /* 'guicursor' */
6478 else if (varp == &p_guicursor)
6479 errmsg = parse_shape_opt(SHAPE_CURSOR);
6480#endif
6481
6482#ifdef FEAT_MOUSESHAPE
6483 /* 'mouseshape' */
6484 else if (varp == &p_mouseshape)
6485 {
6486 errmsg = parse_shape_opt(SHAPE_MOUSE);
6487 update_mouseshape(-1);
6488 }
6489#endif
6490
6491#ifdef FEAT_PRINTER
6492 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006493 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006494# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006495 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006496 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006497# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498#endif
6499
6500#ifdef FEAT_LANGMAP
6501 /* 'langmap' */
6502 else if (varp == &p_langmap)
6503 langmap_set();
6504#endif
6505
6506#ifdef FEAT_LINEBREAK
6507 /* 'breakat' */
6508 else if (varp == &p_breakat)
6509 fill_breakat_flags();
6510#endif
6511
6512#ifdef FEAT_TITLE
6513 /* 'titlestring' and 'iconstring' */
6514 else if (varp == &p_titlestring || varp == &p_iconstring)
6515 {
6516# ifdef FEAT_STL_OPT
6517 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6518
6519 /* NULL => statusline syntax */
6520 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6521 stl_syntax |= flagval;
6522 else
6523 stl_syntax &= ~flagval;
6524# endif
6525 did_set_title(varp == &p_iconstring);
6526
6527 }
6528#endif
6529
6530#ifdef FEAT_GUI
6531 /* 'guioptions' */
6532 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006533 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006534 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006535 redraw_gui_only = TRUE;
6536 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006537#endif
6538
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006539#if defined(FEAT_GUI_TABLINE)
6540 /* 'guitablabel' */
6541 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006542 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006543 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006544 redraw_gui_only = TRUE;
6545 }
6546 /* 'guitabtooltip' */
6547 else if (varp == &p_gtt)
6548 {
6549 redraw_gui_only = TRUE;
6550 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006551#endif
6552
Bram Moolenaar071d4272004-06-13 20:20:40 +00006553#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6554 /* 'ttymouse' */
6555 else if (varp == &p_ttym)
6556 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006557 /* Switch the mouse off before changing the escape sequences used for
6558 * that. */
6559 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006560 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6561 errmsg = e_invarg;
6562 else
6563 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006564 if (termcap_active)
6565 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566 }
6567#endif
6568
Bram Moolenaar071d4272004-06-13 20:20:40 +00006569 /* 'selection' */
6570 else if (varp == &p_sel)
6571 {
6572 if (*p_sel == NUL
6573 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6574 errmsg = e_invarg;
6575 }
6576
6577 /* 'selectmode' */
6578 else if (varp == &p_slm)
6579 {
6580 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6581 errmsg = e_invarg;
6582 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006583
6584#ifdef FEAT_BROWSE
6585 /* 'browsedir' */
6586 else if (varp == &p_bsdir)
6587 {
6588 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6589 && !mch_isdir(p_bsdir))
6590 errmsg = e_invarg;
6591 }
6592#endif
6593
Bram Moolenaar071d4272004-06-13 20:20:40 +00006594 /* 'keymodel' */
6595 else if (varp == &p_km)
6596 {
6597 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6598 errmsg = e_invarg;
6599 else
6600 {
6601 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6602 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6603 }
6604 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006605
6606 /* 'mousemodel' */
6607 else if (varp == &p_mousem)
6608 {
6609 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6610 errmsg = e_invarg;
6611#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6612 else if (*p_mousem != *oldval)
6613 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6614 * to create or delete the popup menus. */
6615 gui_motif_update_mousemodel(root_menu);
6616#endif
6617 }
6618
6619 /* 'switchbuf' */
6620 else if (varp == &p_swb)
6621 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006622 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006623 errmsg = e_invarg;
6624 }
6625
6626 /* 'debug' */
6627 else if (varp == &p_debug)
6628 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006629 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006630 errmsg = e_invarg;
6631 }
6632
6633 /* 'display' */
6634 else if (varp == &p_dy)
6635 {
6636 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6637 errmsg = e_invarg;
6638 else
6639 (void)init_chartab();
6640
6641 }
6642
6643#ifdef FEAT_VERTSPLIT
6644 /* 'eadirection' */
6645 else if (varp == &p_ead)
6646 {
6647 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6648 errmsg = e_invarg;
6649 }
6650#endif
6651
6652#ifdef FEAT_CLIPBOARD
6653 /* 'clipboard' */
6654 else if (varp == &p_cb)
6655 errmsg = check_clipboard_option();
6656#endif
6657
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006658#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006659 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6660 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006661 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006662 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006663 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006664 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006665
Bram Moolenaar860cae12010-06-05 23:22:07 +02006666 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006667 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006668 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6669 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006670 ".add") != 0))
6671 errmsg = e_invarg;
6672 }
6673
6674 if (errmsg == NULL)
6675 {
6676 FOR_ALL_WINDOWS(wp)
6677 if (wp->w_buffer == curbuf && wp->w_p_spell)
6678 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006679 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006680# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006681 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006682# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006683 }
6684 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006685 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006686 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006687 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006688 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006689 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006690 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006691 /* 'spellsuggest' */
6692 else if (varp == &p_sps)
6693 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006694 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006695 errmsg = e_invarg;
6696 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006697 /* 'mkspellmem' */
6698 else if (varp == &p_msm)
6699 {
6700 if (spell_check_msm() != OK)
6701 errmsg = e_invarg;
6702 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006703#endif
6704
Bram Moolenaar071d4272004-06-13 20:20:40 +00006705#ifdef FEAT_QUICKFIX
6706 /* When 'bufhidden' is set, check for valid value. */
6707 else if (gvarp == &p_bh)
6708 {
6709 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6710 errmsg = e_invarg;
6711 }
6712
6713 /* When 'buftype' is set, check for valid value. */
6714 else if (gvarp == &p_bt)
6715 {
6716 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6717 errmsg = e_invarg;
6718 else
6719 {
6720# ifdef FEAT_WINDOWS
6721 if (curwin->w_status_height)
6722 {
6723 curwin->w_redr_status = TRUE;
6724 redraw_later(VALID);
6725 }
6726# endif
6727 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006728# ifdef FEAT_TITLE
6729 redraw_titles();
6730# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006731 }
6732 }
6733#endif
6734
6735#ifdef FEAT_STL_OPT
6736 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006737 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006738 {
6739 int wid;
6740
6741 if (varp == &p_ruf) /* reset ru_wid first */
6742 ru_wid = 0;
6743 s = *varp;
6744 if (varp == &p_ruf && *s == '%')
6745 {
6746 /* set ru_wid if 'ruf' starts with "%99(" */
6747 if (*++s == '-') /* ignore a '-' */
6748 s++;
6749 wid = getdigits(&s);
6750 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6751 ru_wid = wid;
6752 else
6753 errmsg = check_stl_option(p_ruf);
6754 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006755 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006756 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006758 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006759 comp_col();
6760 }
6761#endif
6762
6763#ifdef FEAT_INS_EXPAND
6764 /* check if it is a valid value for 'complete' -- Acevedo */
6765 else if (gvarp == &p_cpt)
6766 {
6767 for (s = *varp; *s;)
6768 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006769 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006770 s++;
6771 if (!*s)
6772 break;
6773 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6774 {
6775 errmsg = illegal_char(errbuf, *s);
6776 break;
6777 }
6778 if (*++s != NUL && *s != ',' && *s != ' ')
6779 {
6780 if (s[-1] == 'k' || s[-1] == 's')
6781 {
6782 /* skip optional filename after 'k' and 's' */
6783 while (*s && *s != ',' && *s != ' ')
6784 {
6785 if (*s == '\\')
6786 ++s;
6787 ++s;
6788 }
6789 }
6790 else
6791 {
6792 if (errbuf != NULL)
6793 {
6794 sprintf((char *)errbuf,
6795 _("E535: Illegal character after <%c>"),
6796 *--s);
6797 errmsg = errbuf;
6798 }
6799 else
6800 errmsg = (char_u *)"";
6801 break;
6802 }
6803 }
6804 }
6805 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006806
6807 /* 'completeopt' */
6808 else if (varp == &p_cot)
6809 {
6810 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6811 errmsg = e_invarg;
6812 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006813#endif /* FEAT_INS_EXPAND */
6814
6815
6816#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6817 else if (varp == &p_toolbar)
6818 {
6819 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6820 &toolbar_flags, TRUE) != OK)
6821 errmsg = e_invarg;
6822 else
6823 {
6824 out_flush();
6825 gui_mch_show_toolbar((toolbar_flags &
6826 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6827 }
6828 }
6829#endif
6830
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006831#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006832 /* 'toolbariconsize': GTK+ 2 only */
6833 else if (varp == &p_tbis)
6834 {
6835 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6836 errmsg = e_invarg;
6837 else
6838 {
6839 out_flush();
6840 gui_mch_show_toolbar((toolbar_flags &
6841 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6842 }
6843 }
6844#endif
6845
6846 /* 'pastetoggle': translate key codes like in a mapping */
6847 else if (varp == &p_pt)
6848 {
6849 if (*p_pt)
6850 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006851 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006852 if (p != NULL)
6853 {
6854 if (new_value_alloced)
6855 free_string_option(p_pt);
6856 p_pt = p;
6857 new_value_alloced = TRUE;
6858 }
6859 }
6860 }
6861
6862 /* 'backspace' */
6863 else if (varp == &p_bs)
6864 {
6865 if (VIM_ISDIGIT(*p_bs))
6866 {
6867 if (*p_bs >'2' || p_bs[1] != NUL)
6868 errmsg = e_invarg;
6869 }
6870 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6871 errmsg = e_invarg;
6872 }
6873
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006874#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006875 /* 'casemap' */
6876 else if (varp == &p_cmp)
6877 {
6878 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6879 errmsg = e_invarg;
6880 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006881#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006882
6883#ifdef FEAT_DIFF
6884 /* 'diffopt' */
6885 else if (varp == &p_dip)
6886 {
6887 if (diffopt_changed() == FAIL)
6888 errmsg = e_invarg;
6889 }
6890#endif
6891
6892#ifdef FEAT_FOLDING
6893 /* 'foldmethod' */
6894 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6895 {
6896 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6897 || *curwin->w_p_fdm == NUL)
6898 errmsg = e_invarg;
6899 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006900 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006901 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006902 if (foldmethodIsDiff(curwin))
6903 newFoldLevel();
6904 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006905 }
6906# ifdef FEAT_EVAL
6907 /* 'foldexpr' */
6908 else if (varp == &curwin->w_p_fde)
6909 {
6910 if (foldmethodIsExpr(curwin))
6911 foldUpdateAll(curwin);
6912 }
6913# endif
6914 /* 'foldmarker' */
6915 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6916 {
6917 p = vim_strchr(*varp, ',');
6918 if (p == NULL)
6919 errmsg = (char_u *)N_("E536: comma required");
6920 else if (p == *varp || p[1] == NUL)
6921 errmsg = e_invarg;
6922 else if (foldmethodIsMarker(curwin))
6923 foldUpdateAll(curwin);
6924 }
6925 /* 'commentstring' */
6926 else if (gvarp == &p_cms)
6927 {
6928 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6929 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6930 }
6931 /* 'foldopen' */
6932 else if (varp == &p_fdo)
6933 {
6934 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6935 errmsg = e_invarg;
6936 }
6937 /* 'foldclose' */
6938 else if (varp == &p_fcl)
6939 {
6940 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6941 errmsg = e_invarg;
6942 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006943 /* 'foldignore' */
6944 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6945 {
6946 if (foldmethodIsIndent(curwin))
6947 foldUpdateAll(curwin);
6948 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006949#endif
6950
6951#ifdef FEAT_VIRTUALEDIT
6952 /* 'virtualedit' */
6953 else if (varp == &p_ve)
6954 {
6955 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6956 errmsg = e_invarg;
6957 else if (STRCMP(p_ve, oldval) != 0)
6958 {
6959 /* Recompute cursor position in case the new 've' setting
6960 * changes something. */
6961 validate_virtcol();
6962 coladvance(curwin->w_virtcol);
6963 }
6964 }
6965#endif
6966
6967#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6968 else if (varp == &p_csqf)
6969 {
6970 if (p_csqf != NULL)
6971 {
6972 p = p_csqf;
6973 while (*p != NUL)
6974 {
6975 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6976 || p[1] == NUL
6977 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6978 || (p[2] != NUL && p[2] != ','))
6979 {
6980 errmsg = e_invarg;
6981 break;
6982 }
6983 else if (p[2] == NUL)
6984 break;
6985 else
6986 p += 3;
6987 }
6988 }
6989 }
6990#endif
6991
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01006992#ifdef FEAT_CINDENT
6993 /* 'cinoptions' */
6994 else if (gvarp == &p_cino)
6995 {
6996 /* TODO: recognize errors */
6997 parse_cino(curbuf);
6998 }
6999#endif
7000
Bram Moolenaar071d4272004-06-13 20:20:40 +00007001 /* Options that are a list of flags. */
7002 else
7003 {
7004 p = NULL;
7005 if (varp == &p_ww)
7006 p = (char_u *)WW_ALL;
7007 if (varp == &p_shm)
7008 p = (char_u *)SHM_ALL;
7009 else if (varp == &(p_cpo))
7010 p = (char_u *)CPO_ALL;
7011 else if (varp == &(curbuf->b_p_fo))
7012 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007013#ifdef FEAT_CONCEAL
7014 else if (varp == &curwin->w_p_cocu)
7015 p = (char_u *)COCU_ALL;
7016#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 else if (varp == &p_mouse)
7018 {
7019#ifdef FEAT_MOUSE
7020 p = (char_u *)MOUSE_ALL;
7021#else
7022 if (*p_mouse != NUL)
7023 errmsg = (char_u *)N_("E538: No mouse support");
7024#endif
7025 }
7026#if defined(FEAT_GUI)
7027 else if (varp == &p_go)
7028 p = (char_u *)GO_ALL;
7029#endif
7030 if (p != NULL)
7031 {
7032 for (s = *varp; *s; ++s)
7033 if (vim_strchr(p, *s) == NULL)
7034 {
7035 errmsg = illegal_char(errbuf, *s);
7036 break;
7037 }
7038 }
7039 }
7040
7041 /*
7042 * If error detected, restore the previous value.
7043 */
7044 if (errmsg != NULL)
7045 {
7046 if (new_value_alloced)
7047 free_string_option(*varp);
7048 *varp = oldval;
7049 /*
7050 * When resetting some values, need to act on it.
7051 */
7052 if (did_chartab)
7053 (void)init_chartab();
7054 if (varp == &p_hl)
7055 (void)highlight_changed();
7056 }
7057 else
7058 {
7059#ifdef FEAT_EVAL
7060 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007061 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007062#endif
7063 /*
7064 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007065 * Use "free_oldval", because recursiveness may change the flags under
7066 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007068 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007069 free_string_option(oldval);
7070 if (new_value_alloced)
7071 options[opt_idx].flags |= P_ALLOCED;
7072 else
7073 options[opt_idx].flags &= ~P_ALLOCED;
7074
7075 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007076 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077 {
7078 /* global option with local value set to use global value; free
7079 * the local value and make it empty */
7080 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7081 free_string_option(*(char_u **)p);
7082 *(char_u **)p = empty_option;
7083 }
7084
7085 /* May set global value for local option. */
7086 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7087 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007088
7089#ifdef FEAT_AUTOCMD
7090 /*
7091 * Trigger the autocommand only after setting the flags.
7092 */
7093# ifdef FEAT_SYN_HL
7094 /* When 'syntax' is set, load the syntax of that name */
7095 if (varp == &(curbuf->b_p_syn))
7096 {
7097 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7098 curbuf->b_fname, TRUE, curbuf);
7099 }
7100# endif
7101 else if (varp == &(curbuf->b_p_ft))
7102 {
7103 /* 'filetype' is set, trigger the FileType autocommand */
7104 did_filetype = TRUE;
7105 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7106 curbuf->b_fname, TRUE, curbuf);
7107 }
7108#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007109#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007110 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007111 {
7112 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007113 char_u *q = curwin->w_s->b_p_spl;
7114
7115 /* Skip the first name if it is "cjk". */
7116 if (STRNCMP(q, "cjk,", 4) == 0)
7117 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007118
7119 /*
7120 * Source the spell/LANG.vim in 'runtimepath'.
7121 * They could set 'spellcapcheck' depending on the language.
7122 * Use the first name in 'spelllang' up to '_region' or
7123 * '.encoding'.
7124 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007125 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007126 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7127 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007128 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007129 source_runtime(fname, TRUE);
7130 }
7131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007132 }
7133
7134#ifdef FEAT_MOUSE
7135 if (varp == &p_mouse)
7136 {
7137# ifdef FEAT_MOUSE_TTY
7138 if (*p_mouse == NUL)
7139 mch_setmouse(FALSE); /* switch mouse off */
7140 else
7141# endif
7142 setmouse(); /* in case 'mouse' changed */
7143 }
7144#endif
7145
Bram Moolenaar913077c2012-03-28 19:59:04 +02007146 if (curwin->w_curswant != MAXCOL
7147 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7148 curwin->w_set_curswant = TRUE;
7149
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007150#ifdef FEAT_GUI
7151 /* check redraw when it's not a GUI option or the GUI is active. */
7152 if (!redraw_gui_only || gui.in_use)
7153#endif
7154 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007155
7156 return errmsg;
7157}
7158
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007159#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007160/*
7161 * Simple int comparison function for use with qsort()
7162 */
7163 static int
7164int_cmp(a, b)
7165 const void *a;
7166 const void *b;
7167{
7168 return *(const int *)a - *(const int *)b;
7169}
7170
7171/*
7172 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7173 * Returns error message, NULL if it's OK.
7174 */
7175 char_u *
7176check_colorcolumn(wp)
7177 win_T *wp;
7178{
7179 char_u *s;
7180 int col;
7181 int count = 0;
7182 int color_cols[256];
7183 int i;
7184 int j = 0;
7185
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007186 if (wp->w_buffer == NULL)
7187 return NULL; /* buffer was closed */
7188
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007189 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007190 {
7191 if (*s == '-' || *s == '+')
7192 {
7193 /* -N and +N: add to 'textwidth' */
7194 col = (*s == '-') ? -1 : 1;
7195 ++s;
7196 if (!VIM_ISDIGIT(*s))
7197 return e_invarg;
7198 col = col * getdigits(&s);
7199 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007200 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007201 col += wp->w_buffer->b_p_tw;
7202 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007203 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007204 }
7205 else if (VIM_ISDIGIT(*s))
7206 col = getdigits(&s);
7207 else
7208 return e_invarg;
7209 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007210skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007211 if (*s == NUL)
7212 break;
7213 if (*s != ',')
7214 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007215 if (*++s == NUL)
7216 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007217 }
7218
7219 vim_free(wp->w_p_cc_cols);
7220 if (count == 0)
7221 wp->w_p_cc_cols = NULL;
7222 else
7223 {
7224 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7225 if (wp->w_p_cc_cols != NULL)
7226 {
7227 /* sort the columns for faster usage on screen redraw inside
7228 * win_line() */
7229 qsort(color_cols, count, sizeof(int), int_cmp);
7230
7231 for (i = 0; i < count; ++i)
7232 /* skip duplicates */
7233 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7234 wp->w_p_cc_cols[j++] = color_cols[i];
7235 wp->w_p_cc_cols[j] = -1; /* end marker */
7236 }
7237 }
7238
7239 return NULL; /* no error */
7240}
7241#endif
7242
Bram Moolenaar071d4272004-06-13 20:20:40 +00007243/*
7244 * Handle setting 'listchars' or 'fillchars'.
7245 * Returns error message, NULL if it's OK.
7246 */
7247 static char_u *
7248set_chars_option(varp)
7249 char_u **varp;
7250{
7251 int round, i, len, entries;
7252 char_u *p, *s;
7253 int c1, c2 = 0;
7254 struct charstab
7255 {
7256 int *cp;
7257 char *name;
7258 };
7259#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7260 static struct charstab filltab[] =
7261 {
7262 {&fill_stl, "stl"},
7263 {&fill_stlnc, "stlnc"},
7264 {&fill_vert, "vert"},
7265 {&fill_fold, "fold"},
7266 {&fill_diff, "diff"},
7267 };
7268#endif
7269 static struct charstab lcstab[] =
7270 {
7271 {&lcs_eol, "eol"},
7272 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007273 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007274 {&lcs_prec, "precedes"},
7275 {&lcs_tab2, "tab"},
7276 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007277#ifdef FEAT_CONCEAL
7278 {&lcs_conceal, "conceal"},
7279#else
7280 {NULL, "conceal"},
7281#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282 };
7283 struct charstab *tab;
7284
7285#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7286 if (varp == &p_lcs)
7287#endif
7288 {
7289 tab = lcstab;
7290 entries = sizeof(lcstab) / sizeof(struct charstab);
7291 }
7292#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7293 else
7294 {
7295 tab = filltab;
7296 entries = sizeof(filltab) / sizeof(struct charstab);
7297 }
7298#endif
7299
7300 /* first round: check for valid value, second round: assign values */
7301 for (round = 0; round <= 1; ++round)
7302 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007303 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007304 {
7305 /* After checking that the value is valid: set defaults: space for
7306 * 'fillchars', NUL for 'listchars' */
7307 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007308 if (tab[i].cp != NULL)
7309 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310 if (varp == &p_lcs)
7311 lcs_tab1 = NUL;
7312#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7313 else
7314 fill_diff = '-';
7315#endif
7316 }
7317 p = *varp;
7318 while (*p)
7319 {
7320 for (i = 0; i < entries; ++i)
7321 {
7322 len = (int)STRLEN(tab[i].name);
7323 if (STRNCMP(p, tab[i].name, len) == 0
7324 && p[len] == ':'
7325 && p[len + 1] != NUL)
7326 {
7327 s = p + len + 1;
7328#ifdef FEAT_MBYTE
7329 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007330 if (mb_char2cells(c1) > 1)
7331 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007332#else
7333 c1 = *s++;
7334#endif
7335 if (tab[i].cp == &lcs_tab2)
7336 {
7337 if (*s == NUL)
7338 continue;
7339#ifdef FEAT_MBYTE
7340 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007341 if (mb_char2cells(c2) > 1)
7342 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007343#else
7344 c2 = *s++;
7345#endif
7346 }
7347 if (*s == ',' || *s == NUL)
7348 {
7349 if (round)
7350 {
7351 if (tab[i].cp == &lcs_tab2)
7352 {
7353 lcs_tab1 = c1;
7354 lcs_tab2 = c2;
7355 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007356 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007357 *(tab[i].cp) = c1;
7358
7359 }
7360 p = s;
7361 break;
7362 }
7363 }
7364 }
7365
7366 if (i == entries)
7367 return e_invarg;
7368 if (*p == ',')
7369 ++p;
7370 }
7371 }
7372
7373 return NULL; /* no error */
7374}
7375
7376#ifdef FEAT_STL_OPT
7377/*
7378 * Check validity of options with the 'statusline' format.
7379 * Return error message or NULL.
7380 */
7381 char_u *
7382check_stl_option(s)
7383 char_u *s;
7384{
7385 int itemcnt = 0;
7386 int groupdepth = 0;
7387 static char_u errbuf[80];
7388
7389 while (*s && itemcnt < STL_MAX_ITEM)
7390 {
7391 /* Check for valid keys after % sequences */
7392 while (*s && *s != '%')
7393 s++;
7394 if (!*s)
7395 break;
7396 s++;
7397 if (*s != '%' && *s != ')')
7398 ++itemcnt;
7399 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7400 {
7401 s++;
7402 continue;
7403 }
7404 if (*s == ')')
7405 {
7406 s++;
7407 if (--groupdepth < 0)
7408 break;
7409 continue;
7410 }
7411 if (*s == '-')
7412 s++;
7413 while (VIM_ISDIGIT(*s))
7414 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007415 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007416 continue;
7417 if (*s == '.')
7418 {
7419 s++;
7420 while (*s && VIM_ISDIGIT(*s))
7421 s++;
7422 }
7423 if (*s == '(')
7424 {
7425 groupdepth++;
7426 continue;
7427 }
7428 if (vim_strchr(STL_ALL, *s) == NULL)
7429 {
7430 return illegal_char(errbuf, *s);
7431 }
7432 if (*s == '{')
7433 {
7434 s++;
7435 while (*s != '}' && *s)
7436 s++;
7437 if (*s != '}')
7438 return (char_u *)N_("E540: Unclosed expression sequence");
7439 }
7440 }
7441 if (itemcnt >= STL_MAX_ITEM)
7442 return (char_u *)N_("E541: too many items");
7443 if (groupdepth != 0)
7444 return (char_u *)N_("E542: unbalanced groups");
7445 return NULL;
7446}
7447#endif
7448
7449#ifdef FEAT_CLIPBOARD
7450/*
7451 * Extract the items in the 'clipboard' option and set global values.
7452 */
7453 static char_u *
7454check_clipboard_option()
7455{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007456 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007457 int new_autoselect_star = FALSE;
7458 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007459 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007460 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007461 regprog_T *new_exclude_prog = NULL;
7462 char_u *errmsg = NULL;
7463 char_u *p;
7464
7465 for (p = p_cb; *p != NUL; )
7466 {
7467 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7468 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007469 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007470 p += 7;
7471 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007472 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007473 && (p[11] == ',' || p[11] == NUL))
7474 {
7475 new_unnamed |= CLIP_UNNAMED_PLUS;
7476 p += 11;
7477 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007478 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007479 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007480 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007481 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 p += 10;
7483 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007484 else if (STRNCMP(p, "autoselectplus", 14) == 0
7485 && (p[14] == ',' || p[14] == NUL))
7486 {
7487 new_autoselect_plus = TRUE;
7488 p += 14;
7489 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007490 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007491 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 {
7493 new_autoselectml = TRUE;
7494 p += 12;
7495 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007496 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7497 {
7498 new_html = TRUE;
7499 p += 4;
7500 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007501 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7502 {
7503 p += 8;
7504 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7505 if (new_exclude_prog == NULL)
7506 errmsg = e_invarg;
7507 break;
7508 }
7509 else
7510 {
7511 errmsg = e_invarg;
7512 break;
7513 }
7514 if (*p == ',')
7515 ++p;
7516 }
7517 if (errmsg == NULL)
7518 {
7519 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007520 clip_autoselect_star = new_autoselect_star;
7521 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007522 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007523 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007524 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007526#ifdef FEAT_GUI_GTK
7527 if (gui.in_use)
7528 {
7529 gui_gtk_set_selection_targets();
7530 gui_gtk_set_dnd_targets();
7531 }
7532#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007533 }
7534 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007535 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007536
7537 return errmsg;
7538}
7539#endif
7540
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007541#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007542/*
7543 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7544 * Return error message when failed, NULL when OK.
7545 */
7546 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007547compile_cap_prog(synblock)
7548 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007549{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007550 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007551 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007552
Bram Moolenaar860cae12010-06-05 23:22:07 +02007553 if (*synblock->b_p_spc == NUL)
7554 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007555 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007556 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007557 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007558 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007559 if (re != NULL)
7560 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007561 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007562 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007563 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007564 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007565 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007566 return e_invarg;
7567 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007568 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007569 }
7570
Bram Moolenaar473de612013-06-08 18:19:48 +02007571 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007572 return NULL;
7573}
7574#endif
7575
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007576#if defined(FEAT_EVAL) || defined(PROTO)
7577/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007578 * Set the scriptID for an option, taking care of setting the buffer- or
7579 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007580 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007581 static void
7582set_option_scriptID_idx(opt_idx, opt_flags, id)
7583 int opt_idx;
7584 int opt_flags;
7585 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007586{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007587 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7588 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007589
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007590 /* Remember where the option was set. For local options need to do that
7591 * in the buffer or window structure. */
7592 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007593 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007594 if (both || (opt_flags & OPT_LOCAL))
7595 {
7596 if (indir & PV_BUF)
7597 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7598 else if (indir & PV_WIN)
7599 curwin->w_p_scriptID[indir & PV_MASK] = id;
7600 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007601}
7602#endif
7603
Bram Moolenaar071d4272004-06-13 20:20:40 +00007604/*
7605 * Set the value of a boolean option, and take care of side effects.
7606 * Returns NULL for success, or an error message for an error.
7607 */
7608 static char_u *
7609set_bool_option(opt_idx, varp, value, opt_flags)
7610 int opt_idx; /* index in options[] table */
7611 char_u *varp; /* pointer to the option variable */
7612 int value; /* new value */
7613 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7614{
7615 int old_value = *(int *)varp;
7616
Bram Moolenaar071d4272004-06-13 20:20:40 +00007617 /* Disallow changing some options from secure mode */
7618 if ((secure
7619#ifdef HAVE_SANDBOX
7620 || sandbox != 0
7621#endif
7622 ) && (options[opt_idx].flags & P_SECURE))
7623 return e_secure;
7624
7625 *(int *)varp = value; /* set the new value */
7626#ifdef FEAT_EVAL
7627 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007628 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007629#endif
7630
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007631#ifdef FEAT_GUI
7632 need_mouse_correct = TRUE;
7633#endif
7634
Bram Moolenaar071d4272004-06-13 20:20:40 +00007635 /* May set global value for local option. */
7636 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7637 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7638
7639 /*
7640 * Handle side effects of changing a bool option.
7641 */
7642
7643 /* 'compatible' */
7644 if ((int *)varp == &p_cp)
7645 {
7646 compatible_set();
7647 }
7648
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007649#ifdef FEAT_PERSISTENT_UNDO
7650 /* 'undofile' */
7651 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7652 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007653 /* Only take action when the option was set. When reset we do not
7654 * delete the undo file, the option may be set again without making
7655 * any changes in between. */
7656 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007657 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007658 char_u hash[UNDO_HASH_SIZE];
7659 buf_T *save_curbuf = curbuf;
7660
7661 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007662 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007663 /* When 'undofile' is set globally: for every buffer, otherwise
7664 * only for the current buffer: Try to read in the undofile,
7665 * if one exists, the buffer wasn't changed and the buffer was
7666 * loaded */
7667 if ((curbuf == save_curbuf
7668 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7669 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7670 {
7671 u_compute_hash(hash);
7672 u_read_undo(NULL, hash, curbuf->b_fname);
7673 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007674 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007675 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007676 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007677 }
7678#endif
7679
Bram Moolenaar071d4272004-06-13 20:20:40 +00007680 else if ((int *)varp == &curbuf->b_p_ro)
7681 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007682 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007683 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7684 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007685
7686 /* when 'readonly' is set may give W10 again */
7687 if (curbuf->b_p_ro)
7688 curbuf->b_did_warn = FALSE;
7689
Bram Moolenaar071d4272004-06-13 20:20:40 +00007690#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007691 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007692#endif
7693 }
7694
Bram Moolenaar9c449722010-07-20 18:44:27 +02007695#ifdef FEAT_GUI
7696 else if ((int *)varp == &p_mh)
7697 {
7698 if (!p_mh)
7699 gui_mch_mousehide(FALSE);
7700 }
7701#endif
7702
Bram Moolenaara539df02010-08-01 14:35:05 +02007703#ifdef FEAT_TITLE
7704 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007706 {
7707 redraw_titles();
7708 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007709 /* when 'endofline' is changed, redraw the window title */
7710 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007711 {
7712 redraw_titles();
7713 }
7714# ifdef FEAT_MBYTE
7715 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007716 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007717 {
7718 redraw_titles();
7719 }
7720# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007721#endif
7722
7723 /* when 'bin' is set also set some other options */
7724 else if ((int *)varp == &curbuf->b_p_bin)
7725 {
7726 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7727#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007728 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729#endif
7730 }
7731
7732#ifdef FEAT_AUTOCMD
7733 /* when 'buflisted' changes, trigger autocommands */
7734 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7735 {
7736 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7737 NULL, NULL, TRUE, curbuf);
7738 }
7739#endif
7740
7741 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7742 else if ((int *)varp == &curbuf->b_p_swf)
7743 {
7744 if (curbuf->b_p_swf && p_uc)
7745 ml_open_file(curbuf); /* create the swap file */
7746 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007747 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7748 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007749 mf_close_file(curbuf, TRUE); /* remove the swap file */
7750 }
7751
7752 /* when 'terse' is set change 'shortmess' */
7753 else if ((int *)varp == &p_terse)
7754 {
7755 char_u *p;
7756
7757 p = vim_strchr(p_shm, SHM_SEARCH);
7758
7759 /* insert 's' in p_shm */
7760 if (p_terse && p == NULL)
7761 {
7762 STRCPY(IObuff, p_shm);
7763 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007764 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007765 }
7766 /* remove 's' from p_shm */
7767 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007768 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007769 }
7770
7771 /* when 'paste' is set or reset also change other options */
7772 else if ((int *)varp == &p_paste)
7773 {
7774 paste_option_changed();
7775 }
7776
7777 /* when 'insertmode' is set from an autocommand need to do work here */
7778 else if ((int *)varp == &p_im)
7779 {
7780 if (p_im)
7781 {
7782 if ((State & INSERT) == 0)
7783 need_start_insertmode = TRUE;
7784 stop_insert_mode = FALSE;
7785 }
7786 else
7787 {
7788 need_start_insertmode = FALSE;
7789 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007790 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 clear_cmdline = TRUE; /* remove "(insert)" */
7792 restart_edit = 0;
7793 }
7794 }
7795
7796 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7797 else if ((int *)varp == &p_ic && p_hls)
7798 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007799 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800 }
7801
7802#ifdef FEAT_SEARCH_EXTRA
7803 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7804 else if ((int *)varp == &p_hls)
7805 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007806 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007807 }
7808#endif
7809
7810#ifdef FEAT_SCROLLBIND
7811 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7812 * at the end of normal_cmd() */
7813 else if ((int *)varp == &curwin->w_p_scb)
7814 {
7815 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007816 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007817 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007818 curwin->w_scbind_pos = curwin->w_topline;
7819 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007820 }
7821#endif
7822
7823#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7824 /* There can be only one window with 'previewwindow' set. */
7825 else if ((int *)varp == &curwin->w_p_pvw)
7826 {
7827 if (curwin->w_p_pvw)
7828 {
7829 win_T *win;
7830
7831 for (win = firstwin; win != NULL; win = win->w_next)
7832 if (win->w_p_pvw && win != curwin)
7833 {
7834 curwin->w_p_pvw = FALSE;
7835 return (char_u *)N_("E590: A preview window already exists");
7836 }
7837 }
7838 }
7839#endif
7840
7841 /* when 'textmode' is set or reset also change 'fileformat' */
7842 else if ((int *)varp == &curbuf->b_p_tx)
7843 {
7844 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7845 }
7846
7847 /* when 'textauto' is set or reset also change 'fileformats' */
7848 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849 set_string_option_direct((char_u *)"ffs", -1,
7850 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007851 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007852
7853 /*
7854 * When 'lisp' option changes include/exclude '-' in
7855 * keyword characters.
7856 */
7857#ifdef FEAT_LISP
7858 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7859 {
7860 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7861 }
7862#endif
7863
7864#ifdef FEAT_TITLE
7865 /* when 'title' changed, may need to change the title; same for 'icon' */
7866 else if ((int *)varp == &p_title)
7867 {
7868 did_set_title(FALSE);
7869 }
7870
7871 else if ((int *)varp == &p_icon)
7872 {
7873 did_set_title(TRUE);
7874 }
7875#endif
7876
7877 else if ((int *)varp == &curbuf->b_changed)
7878 {
7879 if (!value)
7880 save_file_ff(curbuf); /* Buffer is unchanged */
7881#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007882 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007883#endif
7884#ifdef FEAT_AUTOCMD
7885 modified_was_set = value;
7886#endif
7887 }
7888
7889#ifdef BACKSLASH_IN_FILENAME
7890 else if ((int *)varp == &p_ssl)
7891 {
7892 if (p_ssl)
7893 {
7894 psepc = '/';
7895 psepcN = '\\';
7896 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007897 }
7898 else
7899 {
7900 psepc = '\\';
7901 psepcN = '/';
7902 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 }
7904
7905 /* need to adjust the file name arguments and buffer names. */
7906 buflist_slash_adjust();
7907 alist_slash_adjust();
7908# ifdef FEAT_EVAL
7909 scriptnames_slash_adjust();
7910# endif
7911 }
7912#endif
7913
7914 /* If 'wrap' is set, set w_leftcol to zero. */
7915 else if ((int *)varp == &curwin->w_p_wrap)
7916 {
7917 if (curwin->w_p_wrap)
7918 curwin->w_leftcol = 0;
7919 }
7920
7921#ifdef FEAT_WINDOWS
7922 else if ((int *)varp == &p_ea)
7923 {
7924 if (p_ea && !old_value)
7925 win_equal(curwin, FALSE, 0);
7926 }
7927#endif
7928
7929 else if ((int *)varp == &p_wiv)
7930 {
7931 /*
7932 * When 'weirdinvert' changed, set/reset 't_xs'.
7933 * Then set 'weirdinvert' according to value of 't_xs'.
7934 */
7935 if (p_wiv && !old_value)
7936 T_XS = (char_u *)"y";
7937 else if (!p_wiv && old_value)
7938 T_XS = empty_option;
7939 p_wiv = (*T_XS != NUL);
7940 }
7941
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007942#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943 else if ((int *)varp == &p_beval)
7944 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007945 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007947 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007948 gui_mch_disable_beval_area(balloonEval);
7949 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007950#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007951
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007952#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953 else if ((int *)varp == &p_acd)
7954 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007955 /* Change directories when the 'acd' option is set now. */
7956 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957 }
7958#endif
7959
7960#ifdef FEAT_DIFF
7961 /* 'diff' */
7962 else if ((int *)varp == &curwin->w_p_diff)
7963 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007964 /* May add or remove the buffer from the list of diff buffers. */
7965 diff_buf_adjust(curwin);
7966# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 if (foldmethodIsDiff(curwin))
7968 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007969# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970 }
7971#endif
7972
7973#ifdef USE_IM_CONTROL
7974 /* 'imdisable' */
7975 else if ((int *)varp == &p_imdisable)
7976 {
7977 /* Only de-activate it here, it will be enabled when changing mode. */
7978 if (p_imdisable)
7979 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02007980 else if (State & INSERT)
7981 /* When the option is set from an autocommand, it may need to take
7982 * effect right away. */
7983 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007984 }
7985#endif
7986
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007987#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007988 /* 'spell' */
7989 else if ((int *)varp == &curwin->w_p_spell)
7990 {
7991 if (curwin->w_p_spell)
7992 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007993 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00007994 if (errmsg != NULL)
7995 EMSG(_(errmsg));
7996 }
7997 }
7998#endif
7999
Bram Moolenaar071d4272004-06-13 20:20:40 +00008000#ifdef FEAT_FKMAP
8001 else if ((int *)varp == &p_altkeymap)
8002 {
8003 if (old_value != p_altkeymap)
8004 {
8005 if (!p_altkeymap)
8006 {
8007 p_hkmap = p_fkmap;
8008 p_fkmap = 0;
8009 }
8010 else
8011 {
8012 p_fkmap = p_hkmap;
8013 p_hkmap = 0;
8014 }
8015 (void)init_chartab();
8016 }
8017 }
8018
8019 /*
8020 * In case some second language keymapping options have changed, check
8021 * and correct the setting in a consistent way.
8022 */
8023
8024 /*
8025 * If hkmap or fkmap are set, reset Arabic keymapping.
8026 */
8027 if ((p_hkmap || p_fkmap) && p_altkeymap)
8028 {
8029 p_altkeymap = p_fkmap;
8030# ifdef FEAT_ARABIC
8031 curwin->w_p_arab = FALSE;
8032# endif
8033 (void)init_chartab();
8034 }
8035
8036 /*
8037 * If hkmap set, reset Farsi keymapping.
8038 */
8039 if (p_hkmap && p_altkeymap)
8040 {
8041 p_altkeymap = 0;
8042 p_fkmap = 0;
8043# ifdef FEAT_ARABIC
8044 curwin->w_p_arab = FALSE;
8045# endif
8046 (void)init_chartab();
8047 }
8048
8049 /*
8050 * If fkmap set, reset Hebrew keymapping.
8051 */
8052 if (p_fkmap && !p_altkeymap)
8053 {
8054 p_altkeymap = 1;
8055 p_hkmap = 0;
8056# ifdef FEAT_ARABIC
8057 curwin->w_p_arab = FALSE;
8058# endif
8059 (void)init_chartab();
8060 }
8061#endif
8062
8063#ifdef FEAT_ARABIC
8064 if ((int *)varp == &curwin->w_p_arab)
8065 {
8066 if (curwin->w_p_arab)
8067 {
8068 /*
8069 * 'arabic' is set, handle various sub-settings.
8070 */
8071 if (!p_tbidi)
8072 {
8073 /* set rightleft mode */
8074 if (!curwin->w_p_rl)
8075 {
8076 curwin->w_p_rl = TRUE;
8077 changed_window_setting();
8078 }
8079
8080 /* Enable Arabic shaping (major part of what Arabic requires) */
8081 if (!p_arshape)
8082 {
8083 p_arshape = TRUE;
8084 redraw_later_clear();
8085 }
8086 }
8087
8088 /* Arabic requires a utf-8 encoding, inform the user if its not
8089 * set. */
8090 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008091 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008092 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8093
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008094 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008095 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8096#ifdef FEAT_EVAL
8097 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8098#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008099 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008100
8101# ifdef FEAT_MBYTE
8102 /* set 'delcombine' */
8103 p_deco = TRUE;
8104# endif
8105
8106# ifdef FEAT_KEYMAP
8107 /* Force-set the necessary keymap for arabic */
8108 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8109 OPT_LOCAL);
8110# endif
8111# ifdef FEAT_FKMAP
8112 p_altkeymap = 0;
8113 p_hkmap = 0;
8114 p_fkmap = 0;
8115 (void)init_chartab();
8116# endif
8117 }
8118 else
8119 {
8120 /*
8121 * 'arabic' is reset, handle various sub-settings.
8122 */
8123 if (!p_tbidi)
8124 {
8125 /* reset rightleft mode */
8126 if (curwin->w_p_rl)
8127 {
8128 curwin->w_p_rl = FALSE;
8129 changed_window_setting();
8130 }
8131
8132 /* 'arabicshape' isn't reset, it is a global option and
8133 * another window may still need it "on". */
8134 }
8135
8136 /* 'delcombine' isn't reset, it is a global option and another
8137 * window may still want it "on". */
8138
8139# ifdef FEAT_KEYMAP
8140 /* Revert to the default keymap */
8141 curbuf->b_p_iminsert = B_IMODE_NONE;
8142 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8143# endif
8144 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008145 }
8146
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008147#endif
8148
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 /*
8150 * End of handling side effects for bool options.
8151 */
8152
8153 options[opt_idx].flags |= P_WAS_SET;
8154
8155 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008156 if (curwin->w_curswant != MAXCOL
8157 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8158 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008159 check_redraw(options[opt_idx].flags);
8160
8161 return NULL;
8162}
8163
8164/*
8165 * Set the value of a number option, and take care of side effects.
8166 * Returns NULL for success, or an error message for an error.
8167 */
8168 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008169set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008170 int opt_idx; /* index in options[] table */
8171 char_u *varp; /* pointer to the option variable */
8172 long value; /* new value */
8173 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008174 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8176 OPT_MODELINE */
8177{
8178 char_u *errmsg = NULL;
8179 long old_value = *(long *)varp;
8180 long old_Rows = Rows; /* remember old Rows */
8181 long old_Columns = Columns; /* remember old Columns */
8182 long *pp = (long *)varp;
8183
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008184 /* Disallow changing some options from secure mode. */
8185 if ((secure
8186#ifdef HAVE_SANDBOX
8187 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008189 ) && (options[opt_idx].flags & P_SECURE))
8190 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008191
8192 *pp = value;
8193#ifdef FEAT_EVAL
8194 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008195 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008197#ifdef FEAT_GUI
8198 need_mouse_correct = TRUE;
8199#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200
Bram Moolenaar14f24742012-08-08 18:01:05 +02008201 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 {
8203 errmsg = e_positive;
8204 curbuf->b_p_sw = curbuf->b_p_ts;
8205 }
8206
8207 /*
8208 * Number options that need some action when changed
8209 */
8210#ifdef FEAT_WINDOWS
8211 if (pp == &p_wh || pp == &p_hh)
8212 {
8213 if (p_wh < 1)
8214 {
8215 errmsg = e_positive;
8216 p_wh = 1;
8217 }
8218 if (p_wmh > p_wh)
8219 {
8220 errmsg = e_winheight;
8221 p_wh = p_wmh;
8222 }
8223 if (p_hh < 0)
8224 {
8225 errmsg = e_positive;
8226 p_hh = 0;
8227 }
8228
8229 /* Change window height NOW */
8230 if (lastwin != firstwin)
8231 {
8232 if (pp == &p_wh && curwin->w_height < p_wh)
8233 win_setheight((int)p_wh);
8234 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8235 win_setheight((int)p_hh);
8236 }
8237 }
8238
8239 /* 'winminheight' */
8240 else if (pp == &p_wmh)
8241 {
8242 if (p_wmh < 0)
8243 {
8244 errmsg = e_positive;
8245 p_wmh = 0;
8246 }
8247 if (p_wmh > p_wh)
8248 {
8249 errmsg = e_winheight;
8250 p_wmh = p_wh;
8251 }
8252 win_setminheight();
8253 }
8254
8255# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008256 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008257 {
8258 if (p_wiw < 1)
8259 {
8260 errmsg = e_positive;
8261 p_wiw = 1;
8262 }
8263 if (p_wmw > p_wiw)
8264 {
8265 errmsg = e_winwidth;
8266 p_wiw = p_wmw;
8267 }
8268
8269 /* Change window width NOW */
8270 if (lastwin != firstwin && curwin->w_width < p_wiw)
8271 win_setwidth((int)p_wiw);
8272 }
8273
8274 /* 'winminwidth' */
8275 else if (pp == &p_wmw)
8276 {
8277 if (p_wmw < 0)
8278 {
8279 errmsg = e_positive;
8280 p_wmw = 0;
8281 }
8282 if (p_wmw > p_wiw)
8283 {
8284 errmsg = e_winwidth;
8285 p_wmw = p_wiw;
8286 }
8287 win_setminheight();
8288 }
8289# endif
8290
8291#endif
8292
8293#ifdef FEAT_WINDOWS
8294 /* (re)set last window status line */
8295 else if (pp == &p_ls)
8296 {
8297 last_status(FALSE);
8298 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008299
8300 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008301 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008302 {
8303 shell_new_rows(); /* recompute window positions and heights */
8304 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008305#endif
8306
8307#ifdef FEAT_GUI
8308 else if (pp == &p_linespace)
8309 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008310 /* Recompute gui.char_height and resize the Vim window to keep the
8311 * same number of lines. */
8312 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008313 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 }
8315#endif
8316
8317#ifdef FEAT_FOLDING
8318 /* 'foldlevel' */
8319 else if (pp == &curwin->w_p_fdl)
8320 {
8321 if (curwin->w_p_fdl < 0)
8322 curwin->w_p_fdl = 0;
8323 newFoldLevel();
8324 }
8325
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008326 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008327 else if (pp == &curwin->w_p_fml)
8328 {
8329 foldUpdateAll(curwin);
8330 }
8331
8332 /* 'foldnestmax' */
8333 else if (pp == &curwin->w_p_fdn)
8334 {
8335 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8336 foldUpdateAll(curwin);
8337 }
8338
8339 /* 'foldcolumn' */
8340 else if (pp == &curwin->w_p_fdc)
8341 {
8342 if (curwin->w_p_fdc < 0)
8343 {
8344 errmsg = e_positive;
8345 curwin->w_p_fdc = 0;
8346 }
8347 else if (curwin->w_p_fdc > 12)
8348 {
8349 errmsg = e_invarg;
8350 curwin->w_p_fdc = 12;
8351 }
8352 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008353#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008354
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008355#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008356 /* 'shiftwidth' or 'tabstop' */
8357 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8358 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008359# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360 if (foldmethodIsIndent(curwin))
8361 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008362# endif
8363# ifdef FEAT_CINDENT
8364 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8365 * parse 'cinoptions'. */
8366 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8367 parse_cino(curbuf);
8368# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008369 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008371
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008372#ifdef FEAT_MBYTE
8373 /* 'maxcombine' */
8374 else if (pp == &p_mco)
8375 {
8376 if (p_mco > MAX_MCO)
8377 p_mco = MAX_MCO;
8378 else if (p_mco < 0)
8379 p_mco = 0;
8380 screenclear(); /* will re-allocate the screen */
8381 }
8382#endif
8383
Bram Moolenaar071d4272004-06-13 20:20:40 +00008384 else if (pp == &curbuf->b_p_iminsert)
8385 {
8386 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8387 {
8388 errmsg = e_invarg;
8389 curbuf->b_p_iminsert = B_IMODE_NONE;
8390 }
8391 p_iminsert = curbuf->b_p_iminsert;
8392 if (termcap_active) /* don't do this in the alternate screen */
8393 showmode();
8394#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8395 /* Show/unshow value of 'keymap' in status lines. */
8396 status_redraw_curbuf();
8397#endif
8398 }
8399
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008400 else if (pp == &p_window)
8401 {
8402 if (p_window < 1)
8403 p_window = 1;
8404 else if (p_window >= Rows)
8405 p_window = Rows - 1;
8406 }
8407
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408 else if (pp == &curbuf->b_p_imsearch)
8409 {
8410 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8411 {
8412 errmsg = e_invarg;
8413 curbuf->b_p_imsearch = B_IMODE_NONE;
8414 }
8415 p_imsearch = curbuf->b_p_imsearch;
8416 }
8417
8418#ifdef FEAT_TITLE
8419 /* if 'titlelen' has changed, redraw the title */
8420 else if (pp == &p_titlelen)
8421 {
8422 if (p_titlelen < 0)
8423 {
8424 errmsg = e_positive;
8425 p_titlelen = 85;
8426 }
8427 if (starting != NO_SCREEN && old_value != p_titlelen)
8428 need_maketitle = TRUE;
8429 }
8430#endif
8431
8432 /* if p_ch changed value, change the command line height */
8433 else if (pp == &p_ch)
8434 {
8435 if (p_ch < 1)
8436 {
8437 errmsg = e_positive;
8438 p_ch = 1;
8439 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008440 if (p_ch > Rows - min_rows() + 1)
8441 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008442
8443 /* Only compute the new window layout when startup has been
8444 * completed. Otherwise the frame sizes may be wrong. */
8445 if (p_ch != old_value && full_screen
8446#ifdef FEAT_GUI
8447 && !gui.starting
8448#endif
8449 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008450 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451 }
8452
8453 /* when 'updatecount' changes from zero to non-zero, open swap files */
8454 else if (pp == &p_uc)
8455 {
8456 if (p_uc < 0)
8457 {
8458 errmsg = e_positive;
8459 p_uc = 100;
8460 }
8461 if (p_uc && !old_value)
8462 ml_open_files();
8463 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008464#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008465 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008466 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008467 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008468 {
8469 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008470 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008471 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008472 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008473 {
8474 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008475 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008476 }
8477 }
8478#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008479#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008480 else if (pp == &p_mzq)
8481 mzvim_reset_timer();
8482#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483
8484 /* sync undo before 'undolevels' changes */
8485 else if (pp == &p_ul)
8486 {
8487 /* use the old value, otherwise u_sync() may not work properly */
8488 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008489 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008490 p_ul = value;
8491 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008492 else if (pp == &curbuf->b_p_ul)
8493 {
8494 /* use the old value, otherwise u_sync() may not work properly */
8495 curbuf->b_p_ul = old_value;
8496 u_sync(TRUE);
8497 curbuf->b_p_ul = value;
8498 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008499
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008500#ifdef FEAT_LINEBREAK
8501 /* 'numberwidth' must be positive */
8502 else if (pp == &curwin->w_p_nuw)
8503 {
8504 if (curwin->w_p_nuw < 1)
8505 {
8506 errmsg = e_positive;
8507 curwin->w_p_nuw = 1;
8508 }
8509 if (curwin->w_p_nuw > 10)
8510 {
8511 errmsg = e_invarg;
8512 curwin->w_p_nuw = 10;
8513 }
8514 curwin->w_nrwidth_line_count = 0;
8515 }
8516#endif
8517
Bram Moolenaar1a384422010-07-14 19:53:30 +02008518 else if (pp == &curbuf->b_p_tw)
8519 {
8520 if (curbuf->b_p_tw < 0)
8521 {
8522 errmsg = e_positive;
8523 curbuf->b_p_tw = 0;
8524 }
8525#ifdef FEAT_SYN_HL
8526# ifdef FEAT_WINDOWS
8527 {
8528 win_T *wp;
8529 tabpage_T *tp;
8530
8531 FOR_ALL_TAB_WINDOWS(tp, wp)
8532 check_colorcolumn(wp);
8533 }
8534# else
8535 check_colorcolumn(curwin);
8536# endif
8537#endif
8538 }
8539
Bram Moolenaar071d4272004-06-13 20:20:40 +00008540 /*
8541 * Check the bounds for numeric options here
8542 */
8543 if (Rows < min_rows() && full_screen)
8544 {
8545 if (errbuf != NULL)
8546 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008547 vim_snprintf((char *)errbuf, errbuflen,
8548 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008549 errmsg = errbuf;
8550 }
8551 Rows = min_rows();
8552 }
8553 if (Columns < MIN_COLUMNS && full_screen)
8554 {
8555 if (errbuf != NULL)
8556 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008557 vim_snprintf((char *)errbuf, errbuflen,
8558 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008559 errmsg = errbuf;
8560 }
8561 Columns = MIN_COLUMNS;
8562 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008563 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008564
8565#ifdef DJGPP
8566 /* avoid a crash by checking for a too large value of 'columns' */
8567 if (old_Columns != Columns && full_screen && term_console)
8568 mch_check_columns();
8569#endif
8570
8571 /*
8572 * If the screen (shell) height has been changed, assume it is the
8573 * physical screenheight.
8574 */
8575 if (old_Rows != Rows || old_Columns != Columns)
8576 {
8577 /* Changing the screen size is not allowed while updating the screen. */
8578 if (updating_screen)
8579 *pp = old_value;
8580 else if (full_screen
8581#ifdef FEAT_GUI
8582 && !gui.starting
8583#endif
8584 )
8585 set_shellsize((int)Columns, (int)Rows, TRUE);
8586 else
8587 {
8588 /* Postpone the resizing; check the size and cmdline position for
8589 * messages. */
8590 check_shellsize();
8591 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8592 cmdline_row = Rows - p_ch;
8593 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008594 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008595 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008596 }
8597
Bram Moolenaar071d4272004-06-13 20:20:40 +00008598 if (curbuf->b_p_ts <= 0)
8599 {
8600 errmsg = e_positive;
8601 curbuf->b_p_ts = 8;
8602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008603 if (p_tm < 0)
8604 {
8605 errmsg = e_positive;
8606 p_tm = 0;
8607 }
8608 if ((curwin->w_p_scr <= 0
8609 || (curwin->w_p_scr > curwin->w_height
8610 && curwin->w_height > 0))
8611 && full_screen)
8612 {
8613 if (pp == &(curwin->w_p_scr))
8614 {
8615 if (curwin->w_p_scr != 0)
8616 errmsg = e_scroll;
8617 win_comp_scroll(curwin);
8618 }
8619 /* If 'scroll' became invalid because of a side effect silently adjust
8620 * it. */
8621 else if (curwin->w_p_scr <= 0)
8622 curwin->w_p_scr = 1;
8623 else /* curwin->w_p_scr > curwin->w_height */
8624 curwin->w_p_scr = curwin->w_height;
8625 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008626 if (p_hi < 0)
8627 {
8628 errmsg = e_positive;
8629 p_hi = 0;
8630 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008631 else if (p_hi > 10000)
8632 {
8633 errmsg = e_invarg;
8634 p_hi = 10000;
8635 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008636 if (p_re < 0 || p_re > 2)
8637 {
8638 errmsg = e_invarg;
8639 p_re = 0;
8640 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 if (p_report < 0)
8642 {
8643 errmsg = e_positive;
8644 p_report = 1;
8645 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008646 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008647 {
8648 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8649 p_sj = Rows / 2;
8650 else
8651 {
8652 errmsg = e_scroll;
8653 p_sj = 1;
8654 }
8655 }
8656 if (p_so < 0 && full_screen)
8657 {
8658 errmsg = e_scroll;
8659 p_so = 0;
8660 }
8661 if (p_siso < 0 && full_screen)
8662 {
8663 errmsg = e_positive;
8664 p_siso = 0;
8665 }
8666#ifdef FEAT_CMDWIN
8667 if (p_cwh < 1)
8668 {
8669 errmsg = e_positive;
8670 p_cwh = 1;
8671 }
8672#endif
8673 if (p_ut < 0)
8674 {
8675 errmsg = e_positive;
8676 p_ut = 2000;
8677 }
8678 if (p_ss < 0)
8679 {
8680 errmsg = e_positive;
8681 p_ss = 0;
8682 }
8683
8684 /* May set global value for local option. */
8685 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8686 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8687
8688 options[opt_idx].flags |= P_WAS_SET;
8689
8690 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008691 if (curwin->w_curswant != MAXCOL
8692 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8693 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008694 check_redraw(options[opt_idx].flags);
8695
8696 return errmsg;
8697}
8698
8699/*
8700 * Called after an option changed: check if something needs to be redrawn.
8701 */
8702 static void
8703check_redraw(flags)
8704 long_u flags;
8705{
8706 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008707 int doclear = (flags & P_RCLR) == P_RCLR;
8708 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709
8710#ifdef FEAT_WINDOWS
8711 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8712 status_redraw_all();
8713#endif
8714
8715 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8716 changed_window_setting();
8717 if (flags & P_RBUF)
8718 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008719 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720 redraw_all_later(CLEAR);
8721 else if (all)
8722 redraw_all_later(NOT_VALID);
8723}
8724
8725/*
8726 * Find index for option 'arg'.
8727 * Return -1 if not found.
8728 */
8729 static int
8730findoption(arg)
8731 char_u *arg;
8732{
8733 int opt_idx;
8734 char *s, *p;
8735 static short quick_tab[27] = {0, 0}; /* quick access table */
8736 int is_term_opt;
8737
8738 /*
8739 * For first call: Initialize the quick-access table.
8740 * It contains the index for the first option that starts with a certain
8741 * letter. There are 26 letters, plus the first "t_" option.
8742 */
8743 if (quick_tab[1] == 0)
8744 {
8745 p = options[0].fullname;
8746 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8747 {
8748 if (s[0] != p[0])
8749 {
8750 if (s[0] == 't' && s[1] == '_')
8751 quick_tab[26] = opt_idx;
8752 else
8753 quick_tab[CharOrdLow(s[0])] = opt_idx;
8754 }
8755 p = s;
8756 }
8757 }
8758
8759 /*
8760 * Check for name starting with an illegal character.
8761 */
8762#ifdef EBCDIC
8763 if (!islower(arg[0]))
8764#else
8765 if (arg[0] < 'a' || arg[0] > 'z')
8766#endif
8767 return -1;
8768
8769 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8770 if (is_term_opt)
8771 opt_idx = quick_tab[26];
8772 else
8773 opt_idx = quick_tab[CharOrdLow(arg[0])];
8774 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8775 {
8776 if (STRCMP(arg, s) == 0) /* match full name */
8777 break;
8778 }
8779 if (s == NULL && !is_term_opt)
8780 {
8781 opt_idx = quick_tab[CharOrdLow(arg[0])];
8782 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8783 {
8784 s = options[opt_idx].shortname;
8785 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8786 break;
8787 s = NULL;
8788 }
8789 }
8790 if (s == NULL)
8791 opt_idx = -1;
8792 return opt_idx;
8793}
8794
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008795#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796/*
8797 * Get the value for an option.
8798 *
8799 * Returns:
8800 * Number or Toggle option: 1, *numval gets value.
8801 * String option: 0, *stringval gets allocated string.
8802 * Hidden Number or Toggle option: -1.
8803 * hidden String option: -2.
8804 * unknown option: -3.
8805 */
8806 int
8807get_option_value(name, numval, stringval, opt_flags)
8808 char_u *name;
8809 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008810 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008811 int opt_flags;
8812{
8813 int opt_idx;
8814 char_u *varp;
8815
8816 opt_idx = findoption(name);
8817 if (opt_idx < 0) /* unknown option */
8818 return -3;
8819
8820 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8821
8822 if (options[opt_idx].flags & P_STRING)
8823 {
8824 if (varp == NULL) /* hidden option */
8825 return -2;
8826 if (stringval != NULL)
8827 {
8828#ifdef FEAT_CRYPT
8829 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008830 if ((char_u **)varp == &curbuf->b_p_key
8831 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008832 *stringval = vim_strsave((char_u *)"*****");
8833 else
8834#endif
8835 *stringval = vim_strsave(*(char_u **)(varp));
8836 }
8837 return 0;
8838 }
8839
8840 if (varp == NULL) /* hidden option */
8841 return -1;
8842 if (options[opt_idx].flags & P_NUM)
8843 *numval = *(long *)varp;
8844 else
8845 {
8846 /* Special case: 'modified' is b_changed, but we also want to consider
8847 * it set when 'ff' or 'fenc' changed. */
8848 if ((int *)varp == &curbuf->b_changed)
8849 *numval = curbufIsChanged();
8850 else
8851 *numval = *(int *)varp;
8852 }
8853 return 1;
8854}
8855#endif
8856
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008857#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008858/*
8859 * Returns the option attributes and its value. Unlike the above function it
8860 * will return either global value or local value of the option depending on
8861 * what was requested, but it will never return global value if it was
8862 * requested to return local one and vice versa. Neither it will return
8863 * buffer-local value if it was requested to return window-local one.
8864 *
8865 * Pretends that option is absent if it is not present in the requested scope
8866 * (i.e. has no global, window-local or buffer-local value depending on
8867 * opt_type). Uses
8868 *
8869 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008870 * 0 hidden or unknown option, also option that does not have requested
8871 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008872 * see SOPT_* in vim.h for other flags
8873 *
8874 * Possible opt_type values: see SREQ_* in vim.h
8875 */
8876 int
8877get_option_value_strict(name, numval, stringval, opt_type, from)
8878 char_u *name;
8879 long *numval;
8880 char_u **stringval; /* NULL when only obtaining attributes */
8881 int opt_type;
8882 void *from;
8883{
8884 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008885 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008886 struct vimoption *p;
8887 int r = 0;
8888
8889 opt_idx = findoption(name);
8890 if (opt_idx < 0)
8891 return 0;
8892
8893 p = &(options[opt_idx]);
8894
8895 /* Hidden option */
8896 if (p->var == NULL)
8897 return 0;
8898
8899 if (p->flags & P_BOOL)
8900 r |= SOPT_BOOL;
8901 else if (p->flags & P_NUM)
8902 r |= SOPT_NUM;
8903 else if (p->flags & P_STRING)
8904 r |= SOPT_STRING;
8905
8906 if (p->indir == PV_NONE)
8907 {
8908 if (opt_type == SREQ_GLOBAL)
8909 r |= SOPT_GLOBAL;
8910 else
8911 return 0; /* Did not request global-only option */
8912 }
8913 else
8914 {
8915 if (p->indir & PV_BOTH)
8916 r |= SOPT_GLOBAL;
8917 else if (opt_type == SREQ_GLOBAL)
8918 return 0; /* Requested global option */
8919
8920 if (p->indir & PV_WIN)
8921 {
8922 if (opt_type == SREQ_BUF)
8923 return 0; /* Did not request window-local option */
8924 else
8925 r |= SOPT_WIN;
8926 }
8927 else if (p->indir & PV_BUF)
8928 {
8929 if (opt_type == SREQ_WIN)
8930 return 0; /* Did not request buffer-local option */
8931 else
8932 r |= SOPT_BUF;
8933 }
8934 }
8935
8936 if (stringval == NULL)
8937 return r;
8938
8939 if (opt_type == SREQ_GLOBAL)
8940 varp = p->var;
8941 else
8942 {
8943 if (opt_type == SREQ_BUF)
8944 {
8945 /* Special case: 'modified' is b_changed, but we also want to
8946 * consider it set when 'ff' or 'fenc' changed. */
8947 if (p->indir == PV_MOD)
8948 {
8949 *numval = bufIsChanged((buf_T *) from);
8950 varp = NULL;
8951 }
8952#ifdef FEAT_CRYPT
8953 else if (p->indir == PV_KEY)
8954 {
8955 /* never return the value of the crypt key */
8956 *stringval = NULL;
8957 varp = NULL;
8958 }
8959#endif
8960 else
8961 {
8962 aco_save_T aco;
8963 aucmd_prepbuf(&aco, (buf_T *) from);
8964 varp = get_varp(p);
8965 aucmd_restbuf(&aco);
8966 }
8967 }
8968 else if (opt_type == SREQ_WIN)
8969 {
8970 win_T *save_curwin;
8971 save_curwin = curwin;
8972 curwin = (win_T *) from;
8973 curbuf = curwin->w_buffer;
8974 varp = get_varp(p);
8975 curwin = save_curwin;
8976 curbuf = curwin->w_buffer;
8977 }
8978 if (varp == p->var)
8979 return (r | SOPT_UNSET);
8980 }
8981
8982 if (varp != NULL)
8983 {
8984 if (p->flags & P_STRING)
8985 *stringval = vim_strsave(*(char_u **)(varp));
8986 else if (p->flags & P_NUM)
8987 *numval = *(long *) varp;
8988 else
8989 *numval = *(int *)varp;
8990 }
8991
8992 return r;
8993}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008994
8995/*
8996 * Iterate over options. First argument is a pointer to a pointer to a structure
8997 * inside options[] array, second is option type like in the above function.
8998 *
8999 * If first argument points to NULL it is assumed that iteration just started
9000 * and caller needs the very first value.
9001 * If first argument points to the end marker function returns NULL and sets
9002 * first argument to NULL.
9003 *
9004 * Returns full option name for current option on each call.
9005 */
9006 char_u *
9007option_iter_next(option, opt_type)
9008 void **option;
9009 int opt_type;
9010{
9011 struct vimoption *ret = NULL;
9012 do
9013 {
9014 if (*option == NULL)
9015 *option = (void *) options;
9016 else if (((struct vimoption *) (*option))->fullname == NULL)
9017 {
9018 *option = NULL;
9019 return NULL;
9020 }
9021 else
9022 *option = (void *) (((struct vimoption *) (*option)) + 1);
9023
9024 ret = ((struct vimoption *) (*option));
9025
9026 /* Hidden option */
9027 if (ret->var == NULL)
9028 {
9029 ret = NULL;
9030 continue;
9031 }
9032
9033 switch (opt_type)
9034 {
9035 case SREQ_GLOBAL:
9036 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9037 ret = NULL;
9038 break;
9039 case SREQ_BUF:
9040 if (!(ret->indir & PV_BUF))
9041 ret = NULL;
9042 break;
9043 case SREQ_WIN:
9044 if (!(ret->indir & PV_WIN))
9045 ret = NULL;
9046 break;
9047 default:
9048 EMSG2(_(e_intern2), "option_iter_next()");
9049 return NULL;
9050 }
9051 }
9052 while (ret == NULL);
9053
9054 return (char_u *)ret->fullname;
9055}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009056#endif
9057
Bram Moolenaar071d4272004-06-13 20:20:40 +00009058/*
9059 * Set the value of option "name".
9060 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009061 *
9062 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009063 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009064 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009065set_option_value(name, number, string, opt_flags)
9066 char_u *name;
9067 long number;
9068 char_u *string;
9069 int opt_flags; /* OPT_LOCAL or 0 (both) */
9070{
9071 int opt_idx;
9072 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009073 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009074
9075 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009076 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009077 EMSG2(_("E355: Unknown option: %s"), name);
9078 else
9079 {
9080 flags = options[opt_idx].flags;
9081#ifdef HAVE_SANDBOX
9082 /* Disallow changing some options in the sandbox */
9083 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009084 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009085 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009086 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009088#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009089 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009090 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009091 else
9092 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009093 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094 if (varp != NULL) /* hidden option is not changed */
9095 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009096 if (number == 0 && string != NULL)
9097 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009098 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009099
9100 /* Either we are given a string or we are setting option
9101 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009102 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009103 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009104 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009105 {
9106 /* There's another character after zeros or the string
9107 * is empty. In both cases, we are trying to set a
9108 * num option using a string. */
9109 EMSG3(_("E521: Number required: &%s = '%s'"),
9110 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009111 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009112
9113 }
9114 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009115 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009116 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009117 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009118 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009119 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009120 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121 }
9122 }
9123 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009124 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009125}
9126
9127/*
9128 * Get the terminal code for a terminal option.
9129 * Returns NULL when not found.
9130 */
9131 char_u *
9132get_term_code(tname)
9133 char_u *tname;
9134{
9135 int opt_idx;
9136 char_u *varp;
9137
9138 if (tname[0] != 't' || tname[1] != '_' ||
9139 tname[2] == NUL || tname[3] == NUL)
9140 return NULL;
9141 if ((opt_idx = findoption(tname)) >= 0)
9142 {
9143 varp = get_varp(&(options[opt_idx]));
9144 if (varp != NULL)
9145 varp = *(char_u **)(varp);
9146 return varp;
9147 }
9148 return find_termcode(tname + 2);
9149}
9150
9151 char_u *
9152get_highlight_default()
9153{
9154 int i;
9155
9156 i = findoption((char_u *)"hl");
9157 if (i >= 0)
9158 return options[i].def_val[VI_DEFAULT];
9159 return (char_u *)NULL;
9160}
9161
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009162#if defined(FEAT_MBYTE) || defined(PROTO)
9163 char_u *
9164get_encoding_default()
9165{
9166 int i;
9167
9168 i = findoption((char_u *)"enc");
9169 if (i >= 0)
9170 return options[i].def_val[VI_DEFAULT];
9171 return (char_u *)NULL;
9172}
9173#endif
9174
Bram Moolenaar071d4272004-06-13 20:20:40 +00009175/*
9176 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9177 */
9178 static int
9179find_key_option(arg)
9180 char_u *arg;
9181{
9182 int key;
9183 int modifiers;
9184
9185 /*
9186 * Don't use get_special_key_code() for t_xx, we don't want it to call
9187 * add_termcap_entry().
9188 */
9189 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9190 key = TERMCAP2KEY(arg[2], arg[3]);
9191 else
9192 {
9193 --arg; /* put arg at the '<' */
9194 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009195 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009196 if (modifiers) /* can't handle modifiers here */
9197 key = 0;
9198 }
9199 return key;
9200}
9201
9202/*
9203 * if 'all' == 0: show changed options
9204 * if 'all' == 1: show all normal options
9205 * if 'all' == 2: show all terminal options
9206 */
9207 static void
9208showoptions(all, opt_flags)
9209 int all;
9210 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9211{
9212 struct vimoption *p;
9213 int col;
9214 int isterm;
9215 char_u *varp;
9216 struct vimoption **items;
9217 int item_count;
9218 int run;
9219 int row, rows;
9220 int cols;
9221 int i;
9222 int len;
9223
9224#define INC 20
9225#define GAP 3
9226
9227 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9228 PARAM_COUNT));
9229 if (items == NULL)
9230 return;
9231
9232 /* Highlight title */
9233 if (all == 2)
9234 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9235 else if (opt_flags & OPT_GLOBAL)
9236 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9237 else if (opt_flags & OPT_LOCAL)
9238 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9239 else
9240 MSG_PUTS_TITLE(_("\n--- Options ---"));
9241
9242 /*
9243 * do the loop two times:
9244 * 1. display the short items
9245 * 2. display the long items (only strings and numbers)
9246 */
9247 for (run = 1; run <= 2 && !got_int; ++run)
9248 {
9249 /*
9250 * collect the items in items[]
9251 */
9252 item_count = 0;
9253 for (p = &options[0]; p->fullname != NULL; p++)
9254 {
9255 varp = NULL;
9256 isterm = istermoption(p);
9257 if (opt_flags != 0)
9258 {
9259 if (p->indir != PV_NONE && !isterm)
9260 varp = get_varp_scope(p, opt_flags);
9261 }
9262 else
9263 varp = get_varp(p);
9264 if (varp != NULL
9265 && ((all == 2 && isterm)
9266 || (all == 1 && !isterm)
9267 || (all == 0 && !optval_default(p, varp))))
9268 {
9269 if (p->flags & P_BOOL)
9270 len = 1; /* a toggle option fits always */
9271 else
9272 {
9273 option_value2string(p, opt_flags);
9274 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9275 }
9276 if ((len <= INC - GAP && run == 1) ||
9277 (len > INC - GAP && run == 2))
9278 items[item_count++] = p;
9279 }
9280 }
9281
9282 /*
9283 * display the items
9284 */
9285 if (run == 1)
9286 {
9287 cols = (Columns + GAP - 3) / INC;
9288 if (cols == 0)
9289 cols = 1;
9290 rows = (item_count + cols - 1) / cols;
9291 }
9292 else /* run == 2 */
9293 rows = item_count;
9294 for (row = 0; row < rows && !got_int; ++row)
9295 {
9296 msg_putchar('\n'); /* go to next line */
9297 if (got_int) /* 'q' typed in more */
9298 break;
9299 col = 0;
9300 for (i = row; i < item_count; i += rows)
9301 {
9302 msg_col = col; /* make columns */
9303 showoneopt(items[i], opt_flags);
9304 col += INC;
9305 }
9306 out_flush();
9307 ui_breakcheck();
9308 }
9309 }
9310 vim_free(items);
9311}
9312
9313/*
9314 * Return TRUE if option "p" has its default value.
9315 */
9316 static int
9317optval_default(p, varp)
9318 struct vimoption *p;
9319 char_u *varp;
9320{
9321 int dvi;
9322
9323 if (varp == NULL)
9324 return TRUE; /* hidden option is always at default */
9325 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9326 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009327 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009328 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009329 /* the cast to long is required for Manx C, long_i is
9330 * needed for MSVC */
9331 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009332 /* P_STRING */
9333 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9334}
9335
9336/*
9337 * showoneopt: show the value of one option
9338 * must not be called with a hidden option!
9339 */
9340 static void
9341showoneopt(p, opt_flags)
9342 struct vimoption *p;
9343 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9344{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009345 char_u *varp;
9346 int save_silent = silent_mode;
9347
9348 silent_mode = FALSE;
9349 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009350
9351 varp = get_varp_scope(p, opt_flags);
9352
9353 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9354 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9355 ? !curbufIsChanged() : !*(int *)varp))
9356 MSG_PUTS("no");
9357 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9358 MSG_PUTS("--");
9359 else
9360 MSG_PUTS(" ");
9361 MSG_PUTS(p->fullname);
9362 if (!(p->flags & P_BOOL))
9363 {
9364 msg_putchar('=');
9365 /* put value string in NameBuff */
9366 option_value2string(p, opt_flags);
9367 msg_outtrans(NameBuff);
9368 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009369
9370 silent_mode = save_silent;
9371 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009372}
9373
9374/*
9375 * Write modified options as ":set" commands to a file.
9376 *
9377 * There are three values for "opt_flags":
9378 * OPT_GLOBAL: Write global option values and fresh values of
9379 * buffer-local options (used for start of a session
9380 * file).
9381 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9382 * curwin (used for a vimrc file).
9383 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9384 * and local values for window-local options of
9385 * curwin. Local values are also written when at the
9386 * default value, because a modeline or autocommand
9387 * may have set them when doing ":edit file" and the
9388 * user has set them back at the default or fresh
9389 * value.
9390 * When "local_only" is TRUE, don't write fresh
9391 * values, only local values (for ":mkview").
9392 * (fresh value = value used for a new buffer or window for a local option).
9393 *
9394 * Return FAIL on error, OK otherwise.
9395 */
9396 int
9397makeset(fd, opt_flags, local_only)
9398 FILE *fd;
9399 int opt_flags;
9400 int local_only;
9401{
9402 struct vimoption *p;
9403 char_u *varp; /* currently used value */
9404 char_u *varp_fresh; /* local value */
9405 char_u *varp_local = NULL; /* fresh value */
9406 char *cmd;
9407 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009408 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009409
9410 /*
9411 * The options that don't have a default (terminal name, columns, lines)
9412 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009413 * Do the loop over "options[]" twice: once for options with the
9414 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009415 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009416 for (pri = 1; pri >= 0; --pri)
9417 {
9418 for (p = &options[0]; !istermoption(p); p++)
9419 if (!(p->flags & P_NO_MKRC)
9420 && !istermoption(p)
9421 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009422 {
9423 /* skip global option when only doing locals */
9424 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9425 continue;
9426
9427 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9428 * file, they are always buffer-specific. */
9429 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9430 continue;
9431
9432 /* Global values are only written when not at the default value. */
9433 varp = get_varp_scope(p, opt_flags);
9434 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9435 continue;
9436
9437 round = 2;
9438 if (p->indir != PV_NONE)
9439 {
9440 if (p->var == VAR_WIN)
9441 {
9442 /* skip window-local option when only doing globals */
9443 if (!(opt_flags & OPT_LOCAL))
9444 continue;
9445 /* When fresh value of window-local option is not at the
9446 * default, need to write it too. */
9447 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9448 {
9449 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9450 if (!optval_default(p, varp_fresh))
9451 {
9452 round = 1;
9453 varp_local = varp;
9454 varp = varp_fresh;
9455 }
9456 }
9457 }
9458 }
9459
9460 /* Round 1: fresh value for window-local options.
9461 * Round 2: other values */
9462 for ( ; round <= 2; varp = varp_local, ++round)
9463 {
9464 if (round == 1 || (opt_flags & OPT_GLOBAL))
9465 cmd = "set";
9466 else
9467 cmd = "setlocal";
9468
9469 if (p->flags & P_BOOL)
9470 {
9471 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9472 return FAIL;
9473 }
9474 else if (p->flags & P_NUM)
9475 {
9476 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9477 return FAIL;
9478 }
9479 else /* P_STRING */
9480 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009481#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9482 int do_endif = FALSE;
9483
Bram Moolenaar071d4272004-06-13 20:20:40 +00009484 /* Don't set 'syntax' and 'filetype' again if the value is
9485 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009486 if (
9487# if defined(FEAT_SYN_HL)
9488 p->indir == PV_SYN
9489# if defined(FEAT_AUTOCMD)
9490 ||
9491# endif
9492# endif
9493# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009494 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009495# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009496 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009497 {
9498 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9499 *(char_u **)(varp)) < 0
9500 || put_eol(fd) < 0)
9501 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009502 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009503 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009504#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009505 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9506 (p->flags & P_EXPAND) != 0) == FAIL)
9507 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009508#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9509 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009510 {
9511 if (put_line(fd, "endif") == FAIL)
9512 return FAIL;
9513 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009514#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009515 }
9516 }
9517 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009518 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009519 return OK;
9520}
9521
9522#if defined(FEAT_FOLDING) || defined(PROTO)
9523/*
9524 * Generate set commands for the local fold options only. Used when
9525 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9526 */
9527 int
9528makefoldset(fd)
9529 FILE *fd;
9530{
9531 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9532# ifdef FEAT_EVAL
9533 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9534 == FAIL
9535# endif
9536 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9537 == FAIL
9538 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9539 == FAIL
9540 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9541 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9542 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9543 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9544 )
9545 return FAIL;
9546
9547 return OK;
9548}
9549#endif
9550
9551 static int
9552put_setstring(fd, cmd, name, valuep, expand)
9553 FILE *fd;
9554 char *cmd;
9555 char *name;
9556 char_u **valuep;
9557 int expand;
9558{
9559 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009560 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009561
9562 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9563 return FAIL;
9564 if (*valuep != NULL)
9565 {
9566 /* Output 'pastetoggle' as key names. For other
9567 * options some characters have to be escaped with
9568 * CTRL-V or backslash */
9569 if (valuep == &p_pt)
9570 {
9571 s = *valuep;
9572 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009573 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009574 return FAIL;
9575 }
9576 else if (expand)
9577 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009578 buf = alloc(MAXPATHL);
9579 if (buf == NULL)
9580 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009581 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9582 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009583 {
9584 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009586 }
9587 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009588 }
9589 else if (put_escstr(fd, *valuep, 2) == FAIL)
9590 return FAIL;
9591 }
9592 if (put_eol(fd) < 0)
9593 return FAIL;
9594 return OK;
9595}
9596
9597 static int
9598put_setnum(fd, cmd, name, valuep)
9599 FILE *fd;
9600 char *cmd;
9601 char *name;
9602 long *valuep;
9603{
9604 long wc;
9605
9606 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9607 return FAIL;
9608 if (wc_use_keyname((char_u *)valuep, &wc))
9609 {
9610 /* print 'wildchar' and 'wildcharm' as a key name */
9611 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9612 return FAIL;
9613 }
9614 else if (fprintf(fd, "%ld", *valuep) < 0)
9615 return FAIL;
9616 if (put_eol(fd) < 0)
9617 return FAIL;
9618 return OK;
9619}
9620
9621 static int
9622put_setbool(fd, cmd, name, value)
9623 FILE *fd;
9624 char *cmd;
9625 char *name;
9626 int value;
9627{
Bram Moolenaar893de922007-10-02 18:40:57 +00009628 if (value < 0) /* global/local option using global value */
9629 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009630 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9631 || put_eol(fd) < 0)
9632 return FAIL;
9633 return OK;
9634}
9635
9636/*
9637 * Clear all the terminal options.
9638 * If the option has been allocated, free the memory.
9639 * Terminal options are never hidden or indirect.
9640 */
9641 void
9642clear_termoptions()
9643{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009644 /*
9645 * Reset a few things before clearing the old options. This may cause
9646 * outputting a few things that the terminal doesn't understand, but the
9647 * screen will be cleared later, so this is OK.
9648 */
9649#ifdef FEAT_MOUSE_TTY
9650 mch_setmouse(FALSE); /* switch mouse off */
9651#endif
9652#ifdef FEAT_TITLE
9653 mch_restore_title(3); /* restore window titles */
9654#endif
9655#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9656 /* When starting the GUI close the display opened for the clipboard.
9657 * After restoring the title, because that will need the display. */
9658 if (gui.starting)
9659 clear_xterm_clip();
9660#endif
9661#ifdef WIN3264
9662 /*
9663 * Check if this is allowed now.
9664 */
9665 if (can_end_termcap_mode(FALSE) == TRUE)
9666#endif
9667 stoptermcap(); /* stop termcap mode */
9668
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009669 free_termoptions();
9670}
9671
9672 void
9673free_termoptions()
9674{
9675 struct vimoption *p;
9676
Bram Moolenaar071d4272004-06-13 20:20:40 +00009677 for (p = &options[0]; p->fullname != NULL; p++)
9678 if (istermoption(p))
9679 {
9680 if (p->flags & P_ALLOCED)
9681 free_string_option(*(char_u **)(p->var));
9682 if (p->flags & P_DEF_ALLOCED)
9683 free_string_option(p->def_val[VI_DEFAULT]);
9684 *(char_u **)(p->var) = empty_option;
9685 p->def_val[VI_DEFAULT] = empty_option;
9686 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9687 }
9688 clear_termcodes();
9689}
9690
9691/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009692 * Free the string for one term option, if it was allocated.
9693 * Set the string to empty_option and clear allocated flag.
9694 * "var" points to the option value.
9695 */
9696 void
9697free_one_termoption(var)
9698 char_u *var;
9699{
9700 struct vimoption *p;
9701
9702 for (p = &options[0]; p->fullname != NULL; p++)
9703 if (p->var == var)
9704 {
9705 if (p->flags & P_ALLOCED)
9706 free_string_option(*(char_u **)(p->var));
9707 *(char_u **)(p->var) = empty_option;
9708 p->flags &= ~P_ALLOCED;
9709 break;
9710 }
9711}
9712
9713/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009714 * Set the terminal option defaults to the current value.
9715 * Used after setting the terminal name.
9716 */
9717 void
9718set_term_defaults()
9719{
9720 struct vimoption *p;
9721
9722 for (p = &options[0]; p->fullname != NULL; p++)
9723 {
9724 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9725 {
9726 if (p->flags & P_DEF_ALLOCED)
9727 {
9728 free_string_option(p->def_val[VI_DEFAULT]);
9729 p->flags &= ~P_DEF_ALLOCED;
9730 }
9731 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9732 if (p->flags & P_ALLOCED)
9733 {
9734 p->flags |= P_DEF_ALLOCED;
9735 p->flags &= ~P_ALLOCED; /* don't free the value now */
9736 }
9737 }
9738 }
9739}
9740
9741/*
9742 * return TRUE if 'p' starts with 't_'
9743 */
9744 static int
9745istermoption(p)
9746 struct vimoption *p;
9747{
9748 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9749}
9750
9751/*
9752 * Compute columns for ruler and shown command. 'sc_col' is also used to
9753 * decide what the maximum length of a message on the status line can be.
9754 * If there is a status line for the last window, 'sc_col' is independent
9755 * of 'ru_col'.
9756 */
9757
9758#define COL_RULER 17 /* columns needed by standard ruler */
9759
9760 void
9761comp_col()
9762{
9763#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9764 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9765
9766 sc_col = 0;
9767 ru_col = 0;
9768 if (p_ru)
9769 {
9770#ifdef FEAT_STL_OPT
9771 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9772#else
9773 ru_col = COL_RULER + 1;
9774#endif
9775 /* no last status line, adjust sc_col */
9776 if (!last_has_status)
9777 sc_col = ru_col;
9778 }
9779 if (p_sc)
9780 {
9781 sc_col += SHOWCMD_COLS;
9782 if (!p_ru || last_has_status) /* no need for separating space */
9783 ++sc_col;
9784 }
9785 sc_col = Columns - sc_col;
9786 ru_col = Columns - ru_col;
9787 if (sc_col <= 0) /* screen too narrow, will become a mess */
9788 sc_col = 1;
9789 if (ru_col <= 0)
9790 ru_col = 1;
9791#else
9792 sc_col = Columns;
9793 ru_col = Columns;
9794#endif
9795}
9796
9797/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009798 * Unset local option value, similar to ":set opt<".
9799 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009800 void
9801unset_global_local_option(name, from)
9802 char_u *name;
9803 void *from;
9804{
9805 struct vimoption *p;
9806 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009807 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009808
9809 opt_idx = findoption(name);
9810 p = &(options[opt_idx]);
9811
9812 switch ((int)p->indir)
9813 {
9814 /* global option with local value: use local value if it's been set */
9815 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009816 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009817 break;
9818 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009819 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009820 break;
9821 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009822 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009823 break;
9824 case PV_AR:
9825 buf->b_p_ar = -1;
9826 break;
9827 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009828 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009829 break;
9830#ifdef FEAT_FIND_ID
9831 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009832 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009833 break;
9834 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009835 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009836 break;
9837#endif
9838#ifdef FEAT_INS_EXPAND
9839 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009840 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009841 break;
9842 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009843 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009844 break;
9845#endif
9846#ifdef FEAT_QUICKFIX
9847 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009848 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009849 break;
9850 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009851 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009852 break;
9853 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009854 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009855 break;
9856#endif
9857#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9858 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009859 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009860 break;
9861#endif
9862#if defined(FEAT_CRYPT)
9863 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009864 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009865 break;
9866#endif
9867#ifdef FEAT_STL_OPT
9868 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009869 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009870 break;
9871#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009872 case PV_UL:
9873 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9874 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009875#ifdef FEAT_LISP
9876 case PV_LW:
9877 clear_string_option(&buf->b_p_lw);
9878 break;
9879#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009880 }
9881}
9882
9883/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009884 * Get pointer to option variable, depending on local or global scope.
9885 */
9886 static char_u *
9887get_varp_scope(p, opt_flags)
9888 struct vimoption *p;
9889 int opt_flags;
9890{
9891 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9892 {
9893 if (p->var == VAR_WIN)
9894 return (char_u *)GLOBAL_WO(get_varp(p));
9895 return p->var;
9896 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009897 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009898 {
9899 switch ((int)p->indir)
9900 {
9901#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009902 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9903 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9904 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009905#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009906 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9907 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9908 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009909 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009910 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009911#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009912 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9913 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009914#endif
9915#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009916 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9917 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009918#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009919#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9920 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9921#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009922#if defined(FEAT_CRYPT)
9923 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9924#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009925#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009926 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009927#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009928 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009929#ifdef FEAT_LISP
9930 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9931#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009932 }
9933 return NULL; /* "cannot happen" */
9934 }
9935 return get_varp(p);
9936}
9937
9938/*
9939 * Get pointer to option variable.
9940 */
9941 static char_u *
9942get_varp(p)
9943 struct vimoption *p;
9944{
9945 /* hidden option, always return NULL */
9946 if (p->var == NULL)
9947 return NULL;
9948
9949 switch ((int)p->indir)
9950 {
9951 case PV_NONE: return p->var;
9952
9953 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009954 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009955 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009956 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009957 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009958 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009960 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009962 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009963 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9964#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009965 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009967 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009968 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9969#endif
9970#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009971 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009972 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009973 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9975#endif
9976#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009977 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009979 case PV_GP: return *curbuf->b_p_gp != NUL
9980 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9981 case PV_MP: return *curbuf->b_p_mp != NUL
9982 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009983#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009984#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9985 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
9986 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
9987#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009988#if defined(FEAT_CRYPT)
9989 case PV_CM: return *curbuf->b_p_cm != NUL
9990 ? (char_u *)&(curbuf->b_p_cm) : p->var;
9991#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009992#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009993 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009994 ? (char_u *)&(curwin->w_p_stl) : p->var;
9995#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009996 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
9997 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009998#ifdef FEAT_LISP
9999 case PV_LW: return *curbuf->b_p_lw != NUL
10000 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10001#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010002
10003#ifdef FEAT_ARABIC
10004 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10005#endif
10006 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010007#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010008 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10009#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010010#ifdef FEAT_SYN_HL
10011 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10012 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010013 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010014#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010015#ifdef FEAT_DIFF
10016 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10017#endif
10018#ifdef FEAT_FOLDING
10019 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10020 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10021 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10022 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10023 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10024 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10025 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10026# ifdef FEAT_EVAL
10027 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10028 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10029# endif
10030 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10031#endif
10032 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010033 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010034#ifdef FEAT_LINEBREAK
10035 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10036#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010037#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010038 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10039#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010040#ifdef FEAT_VERTSPLIT
10041 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10042#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010043#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10044 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10045#endif
10046#ifdef FEAT_RIGHTLEFT
10047 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10048 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10049#endif
10050 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10051 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10052#ifdef FEAT_LINEBREAK
10053 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010054 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10055 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056#endif
10057#ifdef FEAT_SCROLLBIND
10058 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10059#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010060#ifdef FEAT_CURSORBIND
10061 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10062#endif
10063#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010064 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10065 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010066#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010067
10068 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10069 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10070#ifdef FEAT_MBYTE
10071 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10072#endif
10073#if defined(FEAT_QUICKFIX)
10074 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10075 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10076#endif
10077 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10078 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10079#ifdef FEAT_CINDENT
10080 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10081 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10082 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10083#endif
10084#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10085 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10086#endif
10087#ifdef FEAT_COMMENTS
10088 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10089#endif
10090#ifdef FEAT_FOLDING
10091 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10092#endif
10093#ifdef FEAT_INS_EXPAND
10094 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10095#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010096#ifdef FEAT_COMPL_FUNC
10097 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010098 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010099#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010100 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10101 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10102#ifdef FEAT_MBYTE
10103 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10104#endif
10105 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10106#ifdef FEAT_AUTOCMD
10107 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10108#endif
10109 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010110 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010111 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10112 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10113 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10114 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10115#ifdef FEAT_FIND_ID
10116# ifdef FEAT_EVAL
10117 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10118# endif
10119#endif
10120#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10121 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10122 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10123#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010124#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010125 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127#ifdef FEAT_CRYPT
10128 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10129#endif
10130#ifdef FEAT_LISP
10131 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10132#endif
10133 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10134 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10135 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10136 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10137 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010138 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010139#ifdef FEAT_TEXTOBJ
10140 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10141#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010142 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10143#ifdef FEAT_SMARTINDENT
10144 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10145#endif
10146#ifndef SHORT_FNAME
10147 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10148#endif
10149 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10150#ifdef FEAT_SEARCHPATH
10151 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10152#endif
10153 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10154#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010155 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010156 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10157#endif
10158#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010159 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10160 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10161 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010162#endif
10163 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10164 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10165 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10166 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010167#ifdef FEAT_PERSISTENT_UNDO
10168 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10169#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010170 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10171#ifdef FEAT_KEYMAP
10172 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10173#endif
10174 default: EMSG(_("E356: get_varp ERROR"));
10175 }
10176 /* always return a valid pointer to avoid a crash! */
10177 return (char_u *)&(curbuf->b_p_wm);
10178}
10179
10180/*
10181 * Get the value of 'equalprg', either the buffer-local one or the global one.
10182 */
10183 char_u *
10184get_equalprg()
10185{
10186 if (*curbuf->b_p_ep == NUL)
10187 return p_ep;
10188 return curbuf->b_p_ep;
10189}
10190
10191#if defined(FEAT_WINDOWS) || defined(PROTO)
10192/*
10193 * Copy options from one window to another.
10194 * Used when splitting a window.
10195 */
10196 void
10197win_copy_options(wp_from, wp_to)
10198 win_T *wp_from;
10199 win_T *wp_to;
10200{
10201 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10202 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10203# ifdef FEAT_RIGHTLEFT
10204# ifdef FEAT_FKMAP
10205 /* Is this right? */
10206 wp_to->w_farsi = wp_from->w_farsi;
10207# endif
10208# endif
10209}
10210#endif
10211
10212/*
10213 * Copy the options from one winopt_T to another.
10214 * Doesn't free the old option values in "to", use clear_winopt() for that.
10215 * The 'scroll' option is not copied, because it depends on the window height.
10216 * The 'previewwindow' option is reset, there can be only one preview window.
10217 */
10218 void
10219copy_winopt(from, to)
10220 winopt_T *from;
10221 winopt_T *to;
10222{
10223#ifdef FEAT_ARABIC
10224 to->wo_arab = from->wo_arab;
10225#endif
10226 to->wo_list = from->wo_list;
10227 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010228 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010229#ifdef FEAT_LINEBREAK
10230 to->wo_nuw = from->wo_nuw;
10231#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232#ifdef FEAT_RIGHTLEFT
10233 to->wo_rl = from->wo_rl;
10234 to->wo_rlc = vim_strsave(from->wo_rlc);
10235#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010236#ifdef FEAT_STL_OPT
10237 to->wo_stl = vim_strsave(from->wo_stl);
10238#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010240#ifdef FEAT_DIFF
10241 to->wo_wrap_save = from->wo_wrap_save;
10242#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010243#ifdef FEAT_LINEBREAK
10244 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010245 to->wo_bri = from->wo_bri;
10246 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247#endif
10248#ifdef FEAT_SCROLLBIND
10249 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010250 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010251#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010252#ifdef FEAT_CURSORBIND
10253 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010254 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010255#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010256#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010257 to->wo_spell = from->wo_spell;
10258#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010259#ifdef FEAT_SYN_HL
10260 to->wo_cuc = from->wo_cuc;
10261 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010262 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010263#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264#ifdef FEAT_DIFF
10265 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010266 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010267#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010268#ifdef FEAT_CONCEAL
10269 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010270 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010271#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272#ifdef FEAT_FOLDING
10273 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010274 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010275 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010276 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010277 to->wo_fdi = vim_strsave(from->wo_fdi);
10278 to->wo_fml = from->wo_fml;
10279 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010280 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010281 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010282 to->wo_fdm_save = from->wo_diff_saved
10283 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010284 to->wo_fdn = from->wo_fdn;
10285# ifdef FEAT_EVAL
10286 to->wo_fde = vim_strsave(from->wo_fde);
10287 to->wo_fdt = vim_strsave(from->wo_fdt);
10288# endif
10289 to->wo_fmr = vim_strsave(from->wo_fmr);
10290#endif
10291 check_winopt(to); /* don't want NULL pointers */
10292}
10293
10294/*
10295 * Check string options in a window for a NULL value.
10296 */
10297 void
10298check_win_options(win)
10299 win_T *win;
10300{
10301 check_winopt(&win->w_onebuf_opt);
10302 check_winopt(&win->w_allbuf_opt);
10303}
10304
10305/*
10306 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10307 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010308 void
10309check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010310 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311{
10312#ifdef FEAT_FOLDING
10313 check_string_option(&wop->wo_fdi);
10314 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010315 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010316# ifdef FEAT_EVAL
10317 check_string_option(&wop->wo_fde);
10318 check_string_option(&wop->wo_fdt);
10319# endif
10320 check_string_option(&wop->wo_fmr);
10321#endif
10322#ifdef FEAT_RIGHTLEFT
10323 check_string_option(&wop->wo_rlc);
10324#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010325#ifdef FEAT_STL_OPT
10326 check_string_option(&wop->wo_stl);
10327#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010328#ifdef FEAT_SYN_HL
10329 check_string_option(&wop->wo_cc);
10330#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010331#ifdef FEAT_CONCEAL
10332 check_string_option(&wop->wo_cocu);
10333#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010334#ifdef FEAT_LINEBREAK
10335 check_string_option(&wop->wo_briopt);
10336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337}
10338
10339/*
10340 * Free the allocated memory inside a winopt_T.
10341 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342 void
10343clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010344 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345{
10346#ifdef FEAT_FOLDING
10347 clear_string_option(&wop->wo_fdi);
10348 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010349 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010350# ifdef FEAT_EVAL
10351 clear_string_option(&wop->wo_fde);
10352 clear_string_option(&wop->wo_fdt);
10353# endif
10354 clear_string_option(&wop->wo_fmr);
10355#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010356#ifdef FEAT_LINEBREAK
10357 clear_string_option(&wop->wo_briopt);
10358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010359#ifdef FEAT_RIGHTLEFT
10360 clear_string_option(&wop->wo_rlc);
10361#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010362#ifdef FEAT_STL_OPT
10363 clear_string_option(&wop->wo_stl);
10364#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010365#ifdef FEAT_SYN_HL
10366 clear_string_option(&wop->wo_cc);
10367#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010368#ifdef FEAT_CONCEAL
10369 clear_string_option(&wop->wo_cocu);
10370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010371}
10372
10373/*
10374 * Copy global option values to local options for one buffer.
10375 * Used when creating a new buffer and sometimes when entering a buffer.
10376 * flags:
10377 * BCO_ENTER We will enter the buf buffer.
10378 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10379 * appropriate.
10380 * BCO_NOHELP Don't copy the values to a help buffer.
10381 */
10382 void
10383buf_copy_options(buf, flags)
10384 buf_T *buf;
10385 int flags;
10386{
10387 int should_copy = TRUE;
10388 char_u *save_p_isk = NULL; /* init for GCC */
10389 int dont_do_help;
10390 int did_isk = FALSE;
10391
10392 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010393 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010394 */
10395 if (buf == NULL || !buf_valid(buf))
10396 return;
10397
10398 /*
10399 * Skip this when the option defaults have not been set yet. Happens when
10400 * main() allocates the first buffer.
10401 */
10402 if (p_cpo != NULL)
10403 {
10404 /*
10405 * Always copy when entering and 'cpo' contains 'S'.
10406 * Don't copy when already initialized.
10407 * Don't copy when 'cpo' contains 's' and not entering.
10408 * 'S' BCO_ENTER initialized 's' should_copy
10409 * yes yes X X TRUE
10410 * yes no yes X FALSE
10411 * no X yes X FALSE
10412 * X no no yes FALSE
10413 * X no no no TRUE
10414 * no yes no X TRUE
10415 */
10416 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10417 && (buf->b_p_initialized
10418 || (!(flags & BCO_ENTER)
10419 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10420 should_copy = FALSE;
10421
10422 if (should_copy || (flags & BCO_ALWAYS))
10423 {
10424 /* Don't copy the options specific to a help buffer when
10425 * BCO_NOHELP is given or the options were initialized already
10426 * (jumping back to a help file with CTRL-T or CTRL-O) */
10427 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10428 || buf->b_p_initialized;
10429 if (dont_do_help) /* don't free b_p_isk */
10430 {
10431 save_p_isk = buf->b_p_isk;
10432 buf->b_p_isk = NULL;
10433 }
10434 /*
10435 * Always free the allocated strings.
10436 * If not already initialized, set 'readonly' and copy 'fileformat'.
10437 */
10438 if (!buf->b_p_initialized)
10439 {
10440 free_buf_options(buf, TRUE);
10441 buf->b_p_ro = FALSE; /* don't copy readonly */
10442 buf->b_p_tx = p_tx;
10443#ifdef FEAT_MBYTE
10444 buf->b_p_fenc = vim_strsave(p_fenc);
10445#endif
10446 buf->b_p_ff = vim_strsave(p_ff);
10447#if defined(FEAT_QUICKFIX)
10448 buf->b_p_bh = empty_option;
10449 buf->b_p_bt = empty_option;
10450#endif
10451 }
10452 else
10453 free_buf_options(buf, FALSE);
10454
10455 buf->b_p_ai = p_ai;
10456 buf->b_p_ai_nopaste = p_ai_nopaste;
10457 buf->b_p_sw = p_sw;
10458 buf->b_p_tw = p_tw;
10459 buf->b_p_tw_nopaste = p_tw_nopaste;
10460 buf->b_p_tw_nobin = p_tw_nobin;
10461 buf->b_p_wm = p_wm;
10462 buf->b_p_wm_nopaste = p_wm_nopaste;
10463 buf->b_p_wm_nobin = p_wm_nobin;
10464 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010465#ifdef FEAT_MBYTE
10466 buf->b_p_bomb = p_bomb;
10467#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010468 buf->b_p_et = p_et;
10469 buf->b_p_et_nobin = p_et_nobin;
10470 buf->b_p_ml = p_ml;
10471 buf->b_p_ml_nobin = p_ml_nobin;
10472 buf->b_p_inf = p_inf;
10473 buf->b_p_swf = p_swf;
10474#ifdef FEAT_INS_EXPAND
10475 buf->b_p_cpt = vim_strsave(p_cpt);
10476#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010477#ifdef FEAT_COMPL_FUNC
10478 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010479 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010480#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010481 buf->b_p_sts = p_sts;
10482 buf->b_p_sts_nopaste = p_sts_nopaste;
10483#ifndef SHORT_FNAME
10484 buf->b_p_sn = p_sn;
10485#endif
10486#ifdef FEAT_COMMENTS
10487 buf->b_p_com = vim_strsave(p_com);
10488#endif
10489#ifdef FEAT_FOLDING
10490 buf->b_p_cms = vim_strsave(p_cms);
10491#endif
10492 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010493 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494 buf->b_p_nf = vim_strsave(p_nf);
10495 buf->b_p_mps = vim_strsave(p_mps);
10496#ifdef FEAT_SMARTINDENT
10497 buf->b_p_si = p_si;
10498#endif
10499 buf->b_p_ci = p_ci;
10500#ifdef FEAT_CINDENT
10501 buf->b_p_cin = p_cin;
10502 buf->b_p_cink = vim_strsave(p_cink);
10503 buf->b_p_cino = vim_strsave(p_cino);
10504#endif
10505#ifdef FEAT_AUTOCMD
10506 /* Don't copy 'filetype', it must be detected */
10507 buf->b_p_ft = empty_option;
10508#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010509 buf->b_p_pi = p_pi;
10510#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10511 buf->b_p_cinw = vim_strsave(p_cinw);
10512#endif
10513#ifdef FEAT_LISP
10514 buf->b_p_lisp = p_lisp;
10515#endif
10516#ifdef FEAT_SYN_HL
10517 /* Don't copy 'syntax', it must be set */
10518 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010519 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010520#endif
10521#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010522 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010523 (void)compile_cap_prog(&buf->b_s);
10524 buf->b_s.b_p_spf = vim_strsave(p_spf);
10525 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526#endif
10527#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10528 buf->b_p_inde = vim_strsave(p_inde);
10529 buf->b_p_indk = vim_strsave(p_indk);
10530#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010531#if defined(FEAT_EVAL)
10532 buf->b_p_fex = vim_strsave(p_fex);
10533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534#ifdef FEAT_CRYPT
10535 buf->b_p_key = vim_strsave(p_key);
10536#endif
10537#ifdef FEAT_SEARCHPATH
10538 buf->b_p_sua = vim_strsave(p_sua);
10539#endif
10540#ifdef FEAT_KEYMAP
10541 buf->b_p_keymap = vim_strsave(p_keymap);
10542 buf->b_kmap_state |= KEYMAP_INIT;
10543#endif
10544 /* This isn't really an option, but copying the langmap and IME
10545 * state from the current buffer is better than resetting it. */
10546 buf->b_p_iminsert = p_iminsert;
10547 buf->b_p_imsearch = p_imsearch;
10548
10549 /* options that are normally global but also have a local value
10550 * are not copied, start using the global value */
10551 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010552 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553#ifdef FEAT_QUICKFIX
10554 buf->b_p_gp = empty_option;
10555 buf->b_p_mp = empty_option;
10556 buf->b_p_efm = empty_option;
10557#endif
10558 buf->b_p_ep = empty_option;
10559 buf->b_p_kp = empty_option;
10560 buf->b_p_path = empty_option;
10561 buf->b_p_tags = empty_option;
10562#ifdef FEAT_FIND_ID
10563 buf->b_p_def = empty_option;
10564 buf->b_p_inc = empty_option;
10565# ifdef FEAT_EVAL
10566 buf->b_p_inex = vim_strsave(p_inex);
10567# endif
10568#endif
10569#ifdef FEAT_INS_EXPAND
10570 buf->b_p_dict = empty_option;
10571 buf->b_p_tsr = empty_option;
10572#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010573#ifdef FEAT_TEXTOBJ
10574 buf->b_p_qe = vim_strsave(p_qe);
10575#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010576#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10577 buf->b_p_bexpr = empty_option;
10578#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010579#if defined(FEAT_CRYPT)
10580 buf->b_p_cm = empty_option;
10581#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010582#ifdef FEAT_PERSISTENT_UNDO
10583 buf->b_p_udf = p_udf;
10584#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010585#ifdef FEAT_LISP
10586 buf->b_p_lw = empty_option;
10587#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588
10589 /*
10590 * Don't copy the options set by ex_help(), use the saved values,
10591 * when going from a help buffer to a non-help buffer.
10592 * Don't touch these at all when BCO_NOHELP is used and going from
10593 * or to a help buffer.
10594 */
10595 if (dont_do_help)
10596 buf->b_p_isk = save_p_isk;
10597 else
10598 {
10599 buf->b_p_isk = vim_strsave(p_isk);
10600 did_isk = TRUE;
10601 buf->b_p_ts = p_ts;
10602 buf->b_help = FALSE;
10603#ifdef FEAT_QUICKFIX
10604 if (buf->b_p_bt[0] == 'h')
10605 clear_string_option(&buf->b_p_bt);
10606#endif
10607 buf->b_p_ma = p_ma;
10608 }
10609 }
10610
10611 /*
10612 * When the options should be copied (ignoring BCO_ALWAYS), set the
10613 * flag that indicates that the options have been initialized.
10614 */
10615 if (should_copy)
10616 buf->b_p_initialized = TRUE;
10617 }
10618
10619 check_buf_options(buf); /* make sure we don't have NULLs */
10620 if (did_isk)
10621 (void)buf_init_chartab(buf, FALSE);
10622}
10623
10624/*
10625 * Reset the 'modifiable' option and its default value.
10626 */
10627 void
10628reset_modifiable()
10629{
10630 int opt_idx;
10631
10632 curbuf->b_p_ma = FALSE;
10633 p_ma = FALSE;
10634 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010635 if (opt_idx >= 0)
10636 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010637}
10638
10639/*
10640 * Set the global value for 'iminsert' to the local value.
10641 */
10642 void
10643set_iminsert_global()
10644{
10645 p_iminsert = curbuf->b_p_iminsert;
10646}
10647
10648/*
10649 * Set the global value for 'imsearch' to the local value.
10650 */
10651 void
10652set_imsearch_global()
10653{
10654 p_imsearch = curbuf->b_p_imsearch;
10655}
10656
10657#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10658static int expand_option_idx = -1;
10659static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10660static int expand_option_flags = 0;
10661
10662 void
10663set_context_in_set_cmd(xp, arg, opt_flags)
10664 expand_T *xp;
10665 char_u *arg;
10666 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10667{
10668 int nextchar;
10669 long_u flags = 0; /* init for GCC */
10670 int opt_idx = 0; /* init for GCC */
10671 char_u *p;
10672 char_u *s;
10673 int is_term_option = FALSE;
10674 int key;
10675
10676 expand_option_flags = opt_flags;
10677
10678 xp->xp_context = EXPAND_SETTINGS;
10679 if (*arg == NUL)
10680 {
10681 xp->xp_pattern = arg;
10682 return;
10683 }
10684 p = arg + STRLEN(arg) - 1;
10685 if (*p == ' ' && *(p - 1) != '\\')
10686 {
10687 xp->xp_pattern = p + 1;
10688 return;
10689 }
10690 while (p > arg)
10691 {
10692 s = p;
10693 /* count number of backslashes before ' ' or ',' */
10694 if (*p == ' ' || *p == ',')
10695 {
10696 while (s > arg && *(s - 1) == '\\')
10697 --s;
10698 }
10699 /* break at a space with an even number of backslashes */
10700 if (*p == ' ' && ((p - s) & 1) == 0)
10701 {
10702 ++p;
10703 break;
10704 }
10705 --p;
10706 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010707 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010708 {
10709 xp->xp_context = EXPAND_BOOL_SETTINGS;
10710 p += 2;
10711 }
10712 if (STRNCMP(p, "inv", 3) == 0)
10713 {
10714 xp->xp_context = EXPAND_BOOL_SETTINGS;
10715 p += 3;
10716 }
10717 xp->xp_pattern = arg = p;
10718 if (*arg == '<')
10719 {
10720 while (*p != '>')
10721 if (*p++ == NUL) /* expand terminal option name */
10722 return;
10723 key = get_special_key_code(arg + 1);
10724 if (key == 0) /* unknown name */
10725 {
10726 xp->xp_context = EXPAND_NOTHING;
10727 return;
10728 }
10729 nextchar = *++p;
10730 is_term_option = TRUE;
10731 expand_option_name[2] = KEY2TERMCAP0(key);
10732 expand_option_name[3] = KEY2TERMCAP1(key);
10733 }
10734 else
10735 {
10736 if (p[0] == 't' && p[1] == '_')
10737 {
10738 p += 2;
10739 if (*p != NUL)
10740 ++p;
10741 if (*p == NUL)
10742 return; /* expand option name */
10743 nextchar = *++p;
10744 is_term_option = TRUE;
10745 expand_option_name[2] = p[-2];
10746 expand_option_name[3] = p[-1];
10747 }
10748 else
10749 {
10750 /* Allow * wildcard */
10751 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10752 p++;
10753 if (*p == NUL)
10754 return;
10755 nextchar = *p;
10756 *p = NUL;
10757 opt_idx = findoption(arg);
10758 *p = nextchar;
10759 if (opt_idx == -1 || options[opt_idx].var == NULL)
10760 {
10761 xp->xp_context = EXPAND_NOTHING;
10762 return;
10763 }
10764 flags = options[opt_idx].flags;
10765 if (flags & P_BOOL)
10766 {
10767 xp->xp_context = EXPAND_NOTHING;
10768 return;
10769 }
10770 }
10771 }
10772 /* handle "-=" and "+=" */
10773 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10774 {
10775 ++p;
10776 nextchar = '=';
10777 }
10778 if ((nextchar != '=' && nextchar != ':')
10779 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10780 {
10781 xp->xp_context = EXPAND_UNSUCCESSFUL;
10782 return;
10783 }
10784 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10785 {
10786 xp->xp_context = EXPAND_OLD_SETTING;
10787 if (is_term_option)
10788 expand_option_idx = -1;
10789 else
10790 expand_option_idx = opt_idx;
10791 xp->xp_pattern = p + 1;
10792 return;
10793 }
10794 xp->xp_context = EXPAND_NOTHING;
10795 if (is_term_option || (flags & P_NUM))
10796 return;
10797
10798 xp->xp_pattern = p + 1;
10799
10800 if (flags & P_EXPAND)
10801 {
10802 p = options[opt_idx].var;
10803 if (p == (char_u *)&p_bdir
10804 || p == (char_u *)&p_dir
10805 || p == (char_u *)&p_path
10806 || p == (char_u *)&p_rtp
10807#ifdef FEAT_SEARCHPATH
10808 || p == (char_u *)&p_cdpath
10809#endif
10810#ifdef FEAT_SESSION
10811 || p == (char_u *)&p_vdir
10812#endif
10813 )
10814 {
10815 xp->xp_context = EXPAND_DIRECTORIES;
10816 if (p == (char_u *)&p_path
10817#ifdef FEAT_SEARCHPATH
10818 || p == (char_u *)&p_cdpath
10819#endif
10820 )
10821 xp->xp_backslash = XP_BS_THREE;
10822 else
10823 xp->xp_backslash = XP_BS_ONE;
10824 }
10825 else
10826 {
10827 xp->xp_context = EXPAND_FILES;
10828 /* for 'tags' need three backslashes for a space */
10829 if (p == (char_u *)&p_tags)
10830 xp->xp_backslash = XP_BS_THREE;
10831 else
10832 xp->xp_backslash = XP_BS_ONE;
10833 }
10834 }
10835
10836 /* For an option that is a list of file names, find the start of the
10837 * last file name. */
10838 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10839 {
10840 /* count number of backslashes before ' ' or ',' */
10841 if (*p == ' ' || *p == ',')
10842 {
10843 s = p;
10844 while (s > xp->xp_pattern && *(s - 1) == '\\')
10845 --s;
10846 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10847 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10848 {
10849 xp->xp_pattern = p + 1;
10850 break;
10851 }
10852 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010853
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010854#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010855 /* for 'spellsuggest' start at "file:" */
10856 if (options[opt_idx].var == (char_u *)&p_sps
10857 && STRNCMP(p, "file:", 5) == 0)
10858 {
10859 xp->xp_pattern = p + 5;
10860 break;
10861 }
10862#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863 }
10864
10865 return;
10866}
10867
10868 int
10869ExpandSettings(xp, regmatch, num_file, file)
10870 expand_T *xp;
10871 regmatch_T *regmatch;
10872 int *num_file;
10873 char_u ***file;
10874{
10875 int num_normal = 0; /* Nr of matching non-term-code settings */
10876 int num_term = 0; /* Nr of matching terminal code settings */
10877 int opt_idx;
10878 int match;
10879 int count = 0;
10880 char_u *str;
10881 int loop;
10882 int is_term_opt;
10883 char_u name_buf[MAX_KEY_NAME_LEN];
10884 static char *(names[]) = {"all", "termcap"};
10885 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10886
10887 /* do this loop twice:
10888 * loop == 0: count the number of matching options
10889 * loop == 1: copy the matching options into allocated memory
10890 */
10891 for (loop = 0; loop <= 1; ++loop)
10892 {
10893 regmatch->rm_ic = ic;
10894 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10895 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010896 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10897 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010898 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10899 {
10900 if (loop == 0)
10901 num_normal++;
10902 else
10903 (*file)[count++] = vim_strsave((char_u *)names[match]);
10904 }
10905 }
10906 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10907 opt_idx++)
10908 {
10909 if (options[opt_idx].var == NULL)
10910 continue;
10911 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10912 && !(options[opt_idx].flags & P_BOOL))
10913 continue;
10914 is_term_opt = istermoption(&options[opt_idx]);
10915 if (is_term_opt && num_normal > 0)
10916 continue;
10917 match = FALSE;
10918 if (vim_regexec(regmatch, str, (colnr_T)0)
10919 || (options[opt_idx].shortname != NULL
10920 && vim_regexec(regmatch,
10921 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10922 match = TRUE;
10923 else if (is_term_opt)
10924 {
10925 name_buf[0] = '<';
10926 name_buf[1] = 't';
10927 name_buf[2] = '_';
10928 name_buf[3] = str[2];
10929 name_buf[4] = str[3];
10930 name_buf[5] = '>';
10931 name_buf[6] = NUL;
10932 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10933 {
10934 match = TRUE;
10935 str = name_buf;
10936 }
10937 }
10938 if (match)
10939 {
10940 if (loop == 0)
10941 {
10942 if (is_term_opt)
10943 num_term++;
10944 else
10945 num_normal++;
10946 }
10947 else
10948 (*file)[count++] = vim_strsave(str);
10949 }
10950 }
10951 /*
10952 * Check terminal key codes, these are not in the option table
10953 */
10954 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10955 {
10956 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10957 {
10958 if (!isprint(str[0]) || !isprint(str[1]))
10959 continue;
10960
10961 name_buf[0] = 't';
10962 name_buf[1] = '_';
10963 name_buf[2] = str[0];
10964 name_buf[3] = str[1];
10965 name_buf[4] = NUL;
10966
10967 match = FALSE;
10968 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10969 match = TRUE;
10970 else
10971 {
10972 name_buf[0] = '<';
10973 name_buf[1] = 't';
10974 name_buf[2] = '_';
10975 name_buf[3] = str[0];
10976 name_buf[4] = str[1];
10977 name_buf[5] = '>';
10978 name_buf[6] = NUL;
10979
10980 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10981 match = TRUE;
10982 }
10983 if (match)
10984 {
10985 if (loop == 0)
10986 num_term++;
10987 else
10988 (*file)[count++] = vim_strsave(name_buf);
10989 }
10990 }
10991
10992 /*
10993 * Check special key names.
10994 */
10995 regmatch->rm_ic = TRUE; /* ignore case here */
10996 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
10997 {
10998 name_buf[0] = '<';
10999 STRCPY(name_buf + 1, str);
11000 STRCAT(name_buf, ">");
11001
11002 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11003 {
11004 if (loop == 0)
11005 num_term++;
11006 else
11007 (*file)[count++] = vim_strsave(name_buf);
11008 }
11009 }
11010 }
11011 if (loop == 0)
11012 {
11013 if (num_normal > 0)
11014 *num_file = num_normal;
11015 else if (num_term > 0)
11016 *num_file = num_term;
11017 else
11018 return OK;
11019 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11020 if (*file == NULL)
11021 {
11022 *file = (char_u **)"";
11023 return FAIL;
11024 }
11025 }
11026 }
11027 return OK;
11028}
11029
11030 int
11031ExpandOldSetting(num_file, file)
11032 int *num_file;
11033 char_u ***file;
11034{
11035 char_u *var = NULL; /* init for GCC */
11036 char_u *buf;
11037
11038 *num_file = 0;
11039 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11040 if (*file == NULL)
11041 return FAIL;
11042
11043 /*
11044 * For a terminal key code expand_option_idx is < 0.
11045 */
11046 if (expand_option_idx < 0)
11047 {
11048 var = find_termcode(expand_option_name + 2);
11049 if (var == NULL)
11050 expand_option_idx = findoption(expand_option_name);
11051 }
11052
11053 if (expand_option_idx >= 0)
11054 {
11055 /* put string of option value in NameBuff */
11056 option_value2string(&options[expand_option_idx], expand_option_flags);
11057 var = NameBuff;
11058 }
11059 else if (var == NULL)
11060 var = (char_u *)"";
11061
11062 /* A backslash is required before some characters. This is the reverse of
11063 * what happens in do_set(). */
11064 buf = vim_strsave_escaped(var, escape_chars);
11065
11066 if (buf == NULL)
11067 {
11068 vim_free(*file);
11069 *file = NULL;
11070 return FAIL;
11071 }
11072
11073#ifdef BACKSLASH_IN_FILENAME
11074 /* For MS-Windows et al. we don't double backslashes at the start and
11075 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011076 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011077 if (var[0] == '\\' && var[1] == '\\'
11078 && expand_option_idx >= 0
11079 && (options[expand_option_idx].flags & P_EXPAND)
11080 && vim_isfilec(var[2])
11081 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011082 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083#endif
11084
11085 *file[0] = buf;
11086 *num_file = 1;
11087 return OK;
11088}
11089#endif
11090
11091/*
11092 * Get the value for the numeric or string option *opp in a nice format into
11093 * NameBuff[]. Must not be called with a hidden option!
11094 */
11095 static void
11096option_value2string(opp, opt_flags)
11097 struct vimoption *opp;
11098 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11099{
11100 char_u *varp;
11101
11102 varp = get_varp_scope(opp, opt_flags);
11103
11104 if (opp->flags & P_NUM)
11105 {
11106 long wc = 0;
11107
11108 if (wc_use_keyname(varp, &wc))
11109 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11110 else if (wc != 0)
11111 STRCPY(NameBuff, transchar((int)wc));
11112 else
11113 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11114 }
11115 else /* P_STRING */
11116 {
11117 varp = *(char_u **)(varp);
11118 if (varp == NULL) /* just in case */
11119 NameBuff[0] = NUL;
11120#ifdef FEAT_CRYPT
11121 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011122 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011123 STRCPY(NameBuff, "*****");
11124#endif
11125 else if (opp->flags & P_EXPAND)
11126 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11127 /* Translate 'pastetoggle' into special key names */
11128 else if ((char_u **)opp->var == &p_pt)
11129 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11130 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011131 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011132 }
11133}
11134
11135/*
11136 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11137 * printed as a keyname.
11138 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11139 */
11140 static int
11141wc_use_keyname(varp, wcp)
11142 char_u *varp;
11143 long *wcp;
11144{
11145 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11146 {
11147 *wcp = *(long *)varp;
11148 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11149 return TRUE;
11150 }
11151 return FALSE;
11152}
11153
11154#ifdef FEAT_LANGMAP
11155/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011156 * Any character has an equivalent 'langmap' character. This is used for
11157 * keyboards that have a special language mode that sends characters above
11158 * 128 (although other characters can be translated too). The "to" field is a
11159 * Vim command character. This avoids having to switch the keyboard back to
11160 * ASCII mode when leaving Insert mode.
11161 *
11162 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11163 * commands.
11164 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11165 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11166 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011167 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011168# ifdef FEAT_MBYTE
11169/*
11170 * With multi-byte support use growarray for 'langmap' chars >= 256
11171 */
11172typedef struct
11173{
11174 int from;
11175 int to;
11176} langmap_entry_T;
11177
11178static garray_T langmap_mapga;
11179static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011180
11181/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011182 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11183 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011184 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011185 static void
11186langmap_set_entry(from, to)
11187 int from;
11188 int to;
11189{
11190 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011191 int a = 0;
11192 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011193
11194 /* Do a binary search for an existing entry. */
11195 while (a != b)
11196 {
11197 int i = (a + b) / 2;
11198 int d = entries[i].from - from;
11199
11200 if (d == 0)
11201 {
11202 entries[i].to = to;
11203 return;
11204 }
11205 if (d < 0)
11206 a = i + 1;
11207 else
11208 b = i;
11209 }
11210
11211 if (ga_grow(&langmap_mapga, 1) != OK)
11212 return; /* out of memory */
11213
11214 /* insert new entry at position "a" */
11215 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11216 mch_memmove(entries + 1, entries,
11217 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11218 ++langmap_mapga.ga_len;
11219 entries[0].from = from;
11220 entries[0].to = to;
11221}
11222
11223/*
11224 * Apply 'langmap' to multi-byte character "c" and return the result.
11225 */
11226 int
11227langmap_adjust_mb(c)
11228 int c;
11229{
11230 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11231 int a = 0;
11232 int b = langmap_mapga.ga_len;
11233
11234 while (a != b)
11235 {
11236 int i = (a + b) / 2;
11237 int d = entries[i].from - c;
11238
11239 if (d == 0)
11240 return entries[i].to; /* found matching entry */
11241 if (d < 0)
11242 a = i + 1;
11243 else
11244 b = i;
11245 }
11246 return c; /* no entry found, return "c" unmodified */
11247}
11248# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011249
11250 static void
11251langmap_init()
11252{
11253 int i;
11254
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011255 for (i = 0; i < 256; i++)
11256 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11257# ifdef FEAT_MBYTE
11258 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11259# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011260}
11261
11262/*
11263 * Called when langmap option is set; the language map can be
11264 * changed at any time!
11265 */
11266 static void
11267langmap_set()
11268{
11269 char_u *p;
11270 char_u *p2;
11271 int from, to;
11272
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011273#ifdef FEAT_MBYTE
11274 ga_clear(&langmap_mapga); /* clear the previous map first */
11275#endif
11276 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011277
11278 for (p = p_langmap; p[0] != NUL; )
11279 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011280 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11281 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011282 {
11283 if (p2[0] == '\\' && p2[1] != NUL)
11284 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011285 }
11286 if (p2[0] == ';')
11287 ++p2; /* abcd;ABCD form, p2 points to A */
11288 else
11289 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11290 while (p[0])
11291 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011292 if (p[0] == ',')
11293 {
11294 ++p;
11295 break;
11296 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011297 if (p[0] == '\\' && p[1] != NUL)
11298 ++p;
11299#ifdef FEAT_MBYTE
11300 from = (*mb_ptr2char)(p);
11301#else
11302 from = p[0];
11303#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011304 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011305 if (p2 == NULL)
11306 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011307 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011308 if (p[0] != ',')
11309 {
11310 if (p[0] == '\\')
11311 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011312#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011313 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011314#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011315 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011317 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011318 }
11319 else
11320 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011321 if (p2[0] != ',')
11322 {
11323 if (p2[0] == '\\')
11324 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011325#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011326 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011327#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011328 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011329#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011330 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331 }
11332 if (to == NUL)
11333 {
11334 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11335 transchar(from));
11336 return;
11337 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011338
11339#ifdef FEAT_MBYTE
11340 if (from >= 256)
11341 langmap_set_entry(from, to);
11342 else
11343#endif
11344 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011345
11346 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011347 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011348 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011350 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011351 if (*p == ';')
11352 {
11353 p = p2;
11354 if (p[0] != NUL)
11355 {
11356 if (p[0] != ',')
11357 {
11358 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11359 return;
11360 }
11361 ++p;
11362 }
11363 break;
11364 }
11365 }
11366 }
11367 }
11368}
11369#endif
11370
11371/*
11372 * Return TRUE if format option 'x' is in effect.
11373 * Take care of no formatting when 'paste' is set.
11374 */
11375 int
11376has_format_option(x)
11377 int x;
11378{
11379 if (p_paste)
11380 return FALSE;
11381 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11382}
11383
11384/*
11385 * Return TRUE if "x" is present in 'shortmess' option, or
11386 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11387 */
11388 int
11389shortmess(x)
11390 int x;
11391{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011392 return p_shm != NULL &&
11393 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011394 || (vim_strchr(p_shm, 'a') != NULL
11395 && vim_strchr((char_u *)SHM_A, x) != NULL));
11396}
11397
11398/*
11399 * paste_option_changed() - Called after p_paste was set or reset.
11400 */
11401 static void
11402paste_option_changed()
11403{
11404 static int old_p_paste = FALSE;
11405 static int save_sm = 0;
11406#ifdef FEAT_CMDL_INFO
11407 static int save_ru = 0;
11408#endif
11409#ifdef FEAT_RIGHTLEFT
11410 static int save_ri = 0;
11411 static int save_hkmap = 0;
11412#endif
11413 buf_T *buf;
11414
11415 if (p_paste)
11416 {
11417 /*
11418 * Paste switched from off to on.
11419 * Save the current values, so they can be restored later.
11420 */
11421 if (!old_p_paste)
11422 {
11423 /* save options for each buffer */
11424 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11425 {
11426 buf->b_p_tw_nopaste = buf->b_p_tw;
11427 buf->b_p_wm_nopaste = buf->b_p_wm;
11428 buf->b_p_sts_nopaste = buf->b_p_sts;
11429 buf->b_p_ai_nopaste = buf->b_p_ai;
11430 }
11431
11432 /* save global options */
11433 save_sm = p_sm;
11434#ifdef FEAT_CMDL_INFO
11435 save_ru = p_ru;
11436#endif
11437#ifdef FEAT_RIGHTLEFT
11438 save_ri = p_ri;
11439 save_hkmap = p_hkmap;
11440#endif
11441 /* save global values for local buffer options */
11442 p_tw_nopaste = p_tw;
11443 p_wm_nopaste = p_wm;
11444 p_sts_nopaste = p_sts;
11445 p_ai_nopaste = p_ai;
11446 }
11447
11448 /*
11449 * Always set the option values, also when 'paste' is set when it is
11450 * already on.
11451 */
11452 /* set options for each buffer */
11453 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11454 {
11455 buf->b_p_tw = 0; /* textwidth is 0 */
11456 buf->b_p_wm = 0; /* wrapmargin is 0 */
11457 buf->b_p_sts = 0; /* softtabstop is 0 */
11458 buf->b_p_ai = 0; /* no auto-indent */
11459 }
11460
11461 /* set global options */
11462 p_sm = 0; /* no showmatch */
11463#ifdef FEAT_CMDL_INFO
11464# ifdef FEAT_WINDOWS
11465 if (p_ru)
11466 status_redraw_all(); /* redraw to remove the ruler */
11467# endif
11468 p_ru = 0; /* no ruler */
11469#endif
11470#ifdef FEAT_RIGHTLEFT
11471 p_ri = 0; /* no reverse insert */
11472 p_hkmap = 0; /* no Hebrew keyboard */
11473#endif
11474 /* set global values for local buffer options */
11475 p_tw = 0;
11476 p_wm = 0;
11477 p_sts = 0;
11478 p_ai = 0;
11479 }
11480
11481 /*
11482 * Paste switched from on to off: Restore saved values.
11483 */
11484 else if (old_p_paste)
11485 {
11486 /* restore options for each buffer */
11487 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11488 {
11489 buf->b_p_tw = buf->b_p_tw_nopaste;
11490 buf->b_p_wm = buf->b_p_wm_nopaste;
11491 buf->b_p_sts = buf->b_p_sts_nopaste;
11492 buf->b_p_ai = buf->b_p_ai_nopaste;
11493 }
11494
11495 /* restore global options */
11496 p_sm = save_sm;
11497#ifdef FEAT_CMDL_INFO
11498# ifdef FEAT_WINDOWS
11499 if (p_ru != save_ru)
11500 status_redraw_all(); /* redraw to draw the ruler */
11501# endif
11502 p_ru = save_ru;
11503#endif
11504#ifdef FEAT_RIGHTLEFT
11505 p_ri = save_ri;
11506 p_hkmap = save_hkmap;
11507#endif
11508 /* set global values for local buffer options */
11509 p_tw = p_tw_nopaste;
11510 p_wm = p_wm_nopaste;
11511 p_sts = p_sts_nopaste;
11512 p_ai = p_ai_nopaste;
11513 }
11514
11515 old_p_paste = p_paste;
11516}
11517
11518/*
11519 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11520 *
11521 * Reset 'compatible' and set the values for options that didn't get set yet
11522 * to the Vim defaults.
11523 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011524 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011525 */
11526 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011527vimrc_found(fname, envname)
11528 char_u *fname;
11529 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011530{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011531 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011532 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011533 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534
11535 if (!option_was_set((char_u *)"cp"))
11536 {
11537 p_cp = FALSE;
11538 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11539 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11540 set_option_default(opt_idx, OPT_FREE, FALSE);
11541 didset_options();
11542 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011543
11544 if (fname != NULL)
11545 {
11546 p = vim_getenv(envname, &dofree);
11547 if (p == NULL)
11548 {
11549 /* Set $MYVIMRC to the first vimrc file found. */
11550 p = FullName_save(fname, FALSE);
11551 if (p != NULL)
11552 {
11553 vim_setenv(envname, p);
11554 vim_free(p);
11555 }
11556 }
11557 else if (dofree)
11558 vim_free(p);
11559 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011560}
11561
11562/*
11563 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11564 */
11565 void
11566change_compatible(on)
11567 int on;
11568{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011569 int opt_idx;
11570
Bram Moolenaar071d4272004-06-13 20:20:40 +000011571 if (p_cp != on)
11572 {
11573 p_cp = on;
11574 compatible_set();
11575 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011576 opt_idx = findoption((char_u *)"cp");
11577 if (opt_idx >= 0)
11578 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011579}
11580
11581/*
11582 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011583 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011584 */
11585 int
11586option_was_set(name)
11587 char_u *name;
11588{
11589 int idx;
11590
11591 idx = findoption(name);
11592 if (idx < 0) /* unknown option */
11593 return FALSE;
11594 if (options[idx].flags & P_WAS_SET)
11595 return TRUE;
11596 return FALSE;
11597}
11598
11599/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011600 * Reset the flag indicating option "name" was set.
11601 */
11602 void
11603reset_option_was_set(name)
11604 char_u *name;
11605{
11606 int idx = findoption(name);
11607
11608 if (idx >= 0)
11609 options[idx].flags &= ~P_WAS_SET;
11610}
11611
11612/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011613 * compatible_set() - Called when 'compatible' has been set or unset.
11614 *
11615 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11616 * flag) to a Vi compatible value.
11617 * When 'compatible' is unset: Set all options that have a different default
11618 * for Vim (without the P_VI_DEF flag) to that default.
11619 */
11620 static void
11621compatible_set()
11622{
11623 int opt_idx;
11624
11625 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11626 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11627 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11628 set_option_default(opt_idx, OPT_FREE, p_cp);
11629 didset_options();
11630}
11631
11632#ifdef FEAT_LINEBREAK
11633
11634# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11635 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011636 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011637# endif
11638
11639/*
11640 * fill_breakat_flags() -- called when 'breakat' changes value.
11641 */
11642 static void
11643fill_breakat_flags()
11644{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011645 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011646 int i;
11647
11648 for (i = 0; i < 256; i++)
11649 breakat_flags[i] = FALSE;
11650
11651 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011652 for (p = p_breakat; *p; p++)
11653 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011654}
11655
11656# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011657 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011658# endif
11659
11660#endif
11661
11662/*
11663 * Check an option that can be a range of string values.
11664 *
11665 * Return OK for correct value, FAIL otherwise.
11666 * Empty is always OK.
11667 */
11668 static int
11669check_opt_strings(val, values, list)
11670 char_u *val;
11671 char **values;
11672 int list; /* when TRUE: accept a list of values */
11673{
11674 return opt_strings_flags(val, values, NULL, list);
11675}
11676
11677/*
11678 * Handle an option that can be a range of string values.
11679 * Set a flag in "*flagp" for each string present.
11680 *
11681 * Return OK for correct value, FAIL otherwise.
11682 * Empty is always OK.
11683 */
11684 static int
11685opt_strings_flags(val, values, flagp, list)
11686 char_u *val; /* new value */
11687 char **values; /* array of valid string values */
11688 unsigned *flagp;
11689 int list; /* when TRUE: accept a list of values */
11690{
11691 int i;
11692 int len;
11693 unsigned new_flags = 0;
11694
11695 while (*val)
11696 {
11697 for (i = 0; ; ++i)
11698 {
11699 if (values[i] == NULL) /* val not found in values[] */
11700 return FAIL;
11701
11702 len = (int)STRLEN(values[i]);
11703 if (STRNCMP(values[i], val, len) == 0
11704 && ((list && val[len] == ',') || val[len] == NUL))
11705 {
11706 val += len + (val[len] == ',');
11707 new_flags |= (1 << i);
11708 break; /* check next item in val list */
11709 }
11710 }
11711 }
11712 if (flagp != NULL)
11713 *flagp = new_flags;
11714
11715 return OK;
11716}
11717
11718/*
11719 * Read the 'wildmode' option, fill wim_flags[].
11720 */
11721 static int
11722check_opt_wim()
11723{
11724 char_u new_wim_flags[4];
11725 char_u *p;
11726 int i;
11727 int idx = 0;
11728
11729 for (i = 0; i < 4; ++i)
11730 new_wim_flags[i] = 0;
11731
11732 for (p = p_wim; *p; ++p)
11733 {
11734 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11735 ;
11736 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11737 return FAIL;
11738 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11739 new_wim_flags[idx] |= WIM_LONGEST;
11740 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11741 new_wim_flags[idx] |= WIM_FULL;
11742 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11743 new_wim_flags[idx] |= WIM_LIST;
11744 else
11745 return FAIL;
11746 p += i;
11747 if (*p == NUL)
11748 break;
11749 if (*p == ',')
11750 {
11751 if (idx == 3)
11752 return FAIL;
11753 ++idx;
11754 }
11755 }
11756
11757 /* fill remaining entries with last flag */
11758 while (idx < 3)
11759 {
11760 new_wim_flags[idx + 1] = new_wim_flags[idx];
11761 ++idx;
11762 }
11763
11764 /* only when there are no errors, wim_flags[] is changed */
11765 for (i = 0; i < 4; ++i)
11766 wim_flags[i] = new_wim_flags[i];
11767 return OK;
11768}
11769
11770/*
11771 * Check if backspacing over something is allowed.
11772 */
11773 int
11774can_bs(what)
11775 int what; /* BS_INDENT, BS_EOL or BS_START */
11776{
11777 switch (*p_bs)
11778 {
11779 case '2': return TRUE;
11780 case '1': return (what != BS_START);
11781 case '0': return FALSE;
11782 }
11783 return vim_strchr(p_bs, what) != NULL;
11784}
11785
11786/*
11787 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11788 * the file must be considered changed when the value is different.
11789 */
11790 void
11791save_file_ff(buf)
11792 buf_T *buf;
11793{
11794 buf->b_start_ffc = *buf->b_p_ff;
11795 buf->b_start_eol = buf->b_p_eol;
11796#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011797 buf->b_start_bomb = buf->b_p_bomb;
11798
Bram Moolenaar071d4272004-06-13 20:20:40 +000011799 /* Only use free/alloc when necessary, they take time. */
11800 if (buf->b_start_fenc == NULL
11801 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11802 {
11803 vim_free(buf->b_start_fenc);
11804 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11805 }
11806#endif
11807}
11808
11809/*
11810 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11811 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011812 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11813 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011814 * When "ignore_empty" is true don't consider a new, empty buffer to be
11815 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816 */
11817 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011818file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011820 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011821{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011822 /* In a buffer that was never loaded the options are not valid. */
11823 if (buf->b_flags & BF_NEVERLOADED)
11824 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011825 if (ignore_empty
11826 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011827 && buf->b_ml.ml_line_count == 1
11828 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11829 return FALSE;
11830 if (buf->b_start_ffc != *buf->b_p_ff)
11831 return TRUE;
11832 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11833 return TRUE;
11834#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011835 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11836 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011837 if (buf->b_start_fenc == NULL)
11838 return (*buf->b_p_fenc != NUL);
11839 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11840#else
11841 return FALSE;
11842#endif
11843}
11844
11845/*
11846 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11847 */
11848 int
11849check_ff_value(p)
11850 char_u *p;
11851{
11852 return check_opt_strings(p, p_ff_values, FALSE);
11853}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011854
11855/*
11856 * Return the effective shiftwidth value for current buffer, using the
11857 * 'tabstop' value when 'shiftwidth' is zero.
11858 */
11859 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011860get_sw_value(buf)
11861 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011862{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011863 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011864}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011865
11866/*
11867 * Return the effective softtabstop value for the current buffer, using the
11868 * 'tabstop' value when 'softtabstop' is negative.
11869 */
11870 long
11871get_sts_value()
11872{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011873 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011874}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011875
11876/*
11877 * Check matchpairs option for "*initc".
11878 * If there is a match set "*initc" to the matching character and "*findc" to
11879 * the opposite character. Set "*backwards" to the direction.
11880 * When "switchit" is TRUE swap the direction.
11881 */
11882 void
11883find_mps_values(initc, findc, backwards, switchit)
11884 int *initc;
11885 int *findc;
11886 int *backwards;
11887 int switchit;
11888{
11889 char_u *ptr;
11890
11891 ptr = curbuf->b_p_mps;
11892 while (*ptr != NUL)
11893 {
11894#ifdef FEAT_MBYTE
11895 if (has_mbyte)
11896 {
11897 char_u *prev;
11898
11899 if (mb_ptr2char(ptr) == *initc)
11900 {
11901 if (switchit)
11902 {
11903 *findc = *initc;
11904 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11905 *backwards = TRUE;
11906 }
11907 else
11908 {
11909 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11910 *backwards = FALSE;
11911 }
11912 return;
11913 }
11914 prev = ptr;
11915 ptr += mb_ptr2len(ptr) + 1;
11916 if (mb_ptr2char(ptr) == *initc)
11917 {
11918 if (switchit)
11919 {
11920 *findc = *initc;
11921 *initc = mb_ptr2char(prev);
11922 *backwards = FALSE;
11923 }
11924 else
11925 {
11926 *findc = mb_ptr2char(prev);
11927 *backwards = TRUE;
11928 }
11929 return;
11930 }
11931 ptr += mb_ptr2len(ptr);
11932 }
11933 else
11934#endif
11935 {
11936 if (*ptr == *initc)
11937 {
11938 if (switchit)
11939 {
11940 *backwards = TRUE;
11941 *findc = *initc;
11942 *initc = ptr[2];
11943 }
11944 else
11945 {
11946 *backwards = FALSE;
11947 *findc = ptr[2];
11948 }
11949 return;
11950 }
11951 ptr += 2;
11952 if (*ptr == *initc)
11953 {
11954 if (switchit)
11955 {
11956 *backwards = FALSE;
11957 *findc = *initc;
11958 *initc = ptr[-2];
11959 }
11960 else
11961 {
11962 *backwards = TRUE;
11963 *findc = ptr[-2];
11964 }
11965 return;
11966 }
11967 ++ptr;
11968 }
11969 if (*ptr == ',')
11970 ++ptr;
11971 }
11972}
Bram Moolenaar597a4222014-06-25 14:39:50 +020011973
11974#if defined(FEAT_LINEBREAK) || defined(PROTO)
11975/*
11976 * This is called when 'breakindentopt' is changed and when a window is
11977 * initialized.
11978 */
11979 int
11980briopt_check()
11981{
11982 char_u *p;
11983 int bri_shift = 0;
11984 long bri_min = 20;
11985 int bri_sbr = FALSE;
11986
11987 p = curwin->w_p_briopt;
11988 while (*p != NUL)
11989 {
11990 if (STRNCMP(p, "shift:", 6) == 0
11991 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
11992 {
11993 p += 6;
11994 bri_shift = getdigits(&p);
11995 }
11996 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
11997 {
11998 p += 4;
11999 bri_min = getdigits(&p);
12000 }
12001 else if (STRNCMP(p, "sbr", 3) == 0)
12002 {
12003 p += 3;
12004 bri_sbr = TRUE;
12005 }
12006 if (*p != ',' && *p != NUL)
12007 return FAIL;
12008 if (*p == ',')
12009 ++p;
12010 }
12011
12012 curwin->w_p_brishift = bri_shift;
12013 curwin->w_p_brimin = bri_min;
12014 curwin->w_p_brisbr = bri_sbr;
12015
12016 return OK;
12017}
12018#endif