blob: 3e6164e5a6527950e1dcb24cbe3255ad8f87ac62 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020080#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100137# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000138#endif
139#define PV_MA OPT_BUF(BV_MA)
140#define PV_ML OPT_BUF(BV_ML)
141#define PV_MOD OPT_BUF(BV_MOD)
142#define PV_MPS OPT_BUF(BV_MPS)
143#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000144#ifdef FEAT_COMPL_FUNC
145# define PV_OFU OPT_BUF(BV_OFU)
146#endif
147#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
148#define PV_PI OPT_BUF(BV_PI)
149#ifdef FEAT_TEXTOBJ
150# define PV_QE OPT_BUF(BV_QE)
151#endif
152#define PV_RO OPT_BUF(BV_RO)
153#ifdef FEAT_SMARTINDENT
154# define PV_SI OPT_BUF(BV_SI)
155#endif
156#ifndef SHORT_FNAME
157# define PV_SN OPT_BUF(BV_SN)
158#endif
159#ifdef FEAT_SYN_HL
160# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000161# define PV_SYN OPT_BUF(BV_SYN)
162#endif
163#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164# define PV_SPC OPT_BUF(BV_SPC)
165# define PV_SPF OPT_BUF(BV_SPF)
166# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000167#endif
168#define PV_STS OPT_BUF(BV_STS)
169#ifdef FEAT_SEARCHPATH
170# define PV_SUA OPT_BUF(BV_SUA)
171#endif
172#define PV_SW OPT_BUF(BV_SW)
173#define PV_SWF OPT_BUF(BV_SWF)
174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
175#define PV_TS OPT_BUF(BV_TS)
176#define PV_TW OPT_BUF(BV_TW)
177#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200178#ifdef FEAT_PERSISTENT_UNDO
179# define PV_UDF OPT_BUF(BV_UDF)
180#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000181#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000182
183/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184 * Definition of the PV_ values for window-local options.
185 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187#define PV_LIST OPT_WIN(WV_LIST)
188#ifdef FEAT_ARABIC
189# define PV_ARAB OPT_WIN(WV_ARAB)
190#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200191#ifdef FEAT_LINEBREAK
192# define PV_BRI OPT_WIN(WV_BRI)
193# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
194#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000195#ifdef FEAT_DIFF
196# define PV_DIFF OPT_WIN(WV_DIFF)
197#endif
198#ifdef FEAT_FOLDING
199# define PV_FDC OPT_WIN(WV_FDC)
200# define PV_FEN OPT_WIN(WV_FEN)
201# define PV_FDI OPT_WIN(WV_FDI)
202# define PV_FDL OPT_WIN(WV_FDL)
203# define PV_FDM OPT_WIN(WV_FDM)
204# define PV_FML OPT_WIN(WV_FML)
205# define PV_FDN OPT_WIN(WV_FDN)
206# ifdef FEAT_EVAL
207# define PV_FDE OPT_WIN(WV_FDE)
208# define PV_FDT OPT_WIN(WV_FDT)
209# endif
210# define PV_FMR OPT_WIN(WV_FMR)
211#endif
212#ifdef FEAT_LINEBREAK
213# define PV_LBR OPT_WIN(WV_LBR)
214#endif
215#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200216#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000217#ifdef FEAT_LINEBREAK
218# define PV_NUW OPT_WIN(WV_NUW)
219#endif
220#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
221# define PV_PVW OPT_WIN(WV_PVW)
222#endif
223#ifdef FEAT_RIGHTLEFT
224# define PV_RL OPT_WIN(WV_RL)
225# define PV_RLC OPT_WIN(WV_RLC)
226#endif
227#ifdef FEAT_SCROLLBIND
228# define PV_SCBIND OPT_WIN(WV_SCBIND)
229#endif
230#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000231#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000232# define PV_SPELL OPT_WIN(WV_SPELL)
233#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000234#ifdef FEAT_SYN_HL
235# define PV_CUC OPT_WIN(WV_CUC)
236# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200237# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000238#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000239#ifdef FEAT_STL_OPT
240# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
241#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100242#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000243#ifdef FEAT_WINDOWS
244# define PV_WFH OPT_WIN(WV_WFH)
245#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000246#ifdef FEAT_VERTSPLIT
247# define PV_WFW OPT_WIN(WV_WFW)
248#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000249#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200250#ifdef FEAT_CURSORBIND
251# define PV_CRBIND OPT_WIN(WV_CRBIND)
252#endif
253#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200254# define PV_COCU OPT_WIN(WV_COCU)
255# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200256#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000257
258/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259typedef enum
260{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000261 PV_NONE = 0,
262 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000263} idopt_T;
264
265/*
266 * Options local to a window have a value local to a buffer and global to all
267 * buffers. Indicate this by setting "var" to VAR_WIN.
268 */
269#define VAR_WIN ((char_u *)-1)
270
271/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000272 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273 * Only to be used in option.c!
274 */
275static int p_ai;
276static int p_bin;
277#ifdef FEAT_MBYTE
278static int p_bomb;
279#endif
280#if defined(FEAT_QUICKFIX)
281static char_u *p_bh;
282static char_u *p_bt;
283#endif
284static int p_bl;
285static int p_ci;
286#ifdef FEAT_CINDENT
287static int p_cin;
288static char_u *p_cink;
289static char_u *p_cino;
290#endif
291#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
292static char_u *p_cinw;
293#endif
294#ifdef FEAT_COMMENTS
295static char_u *p_com;
296#endif
297#ifdef FEAT_FOLDING
298static char_u *p_cms;
299#endif
300#ifdef FEAT_INS_EXPAND
301static char_u *p_cpt;
302#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000303#ifdef FEAT_COMPL_FUNC
304static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000305static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307static int p_eol;
308static int p_et;
309#ifdef FEAT_MBYTE
310static char_u *p_fenc;
311#endif
312static char_u *p_ff;
313static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000314static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315#ifdef FEAT_AUTOCMD
316static char_u *p_ft;
317#endif
318static long p_iminsert;
319static long p_imsearch;
320#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
321static char_u *p_inex;
322#endif
323#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
324static char_u *p_inde;
325static char_u *p_indk;
326#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000327#if defined(FEAT_EVAL)
328static char_u *p_fex;
329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330static int p_inf;
331static char_u *p_isk;
332#ifdef FEAT_CRYPT
333static char_u *p_key;
334#endif
335#ifdef FEAT_LISP
336static int p_lisp;
337#endif
338static int p_ml;
339static int p_ma;
340static int p_mod;
341static char_u *p_mps;
342static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344#ifdef FEAT_TEXTOBJ
345static char_u *p_qe;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_ro;
348#ifdef FEAT_SMARTINDENT
349static int p_si;
350#endif
351#ifndef SHORT_FNAME
352static int p_sn;
353#endif
354static long p_sts;
355#if defined(FEAT_SEARCHPATH)
356static char_u *p_sua;
357#endif
358static long p_sw;
359static int p_swf;
360#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000361static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000363#endif
364#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000365static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000366static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000367static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368#endif
369static long p_ts;
370static long p_tw;
371static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200372#ifdef FEAT_PERSISTENT_UNDO
373static int p_udf;
374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375static long p_wm;
376#ifdef FEAT_KEYMAP
377static char_u *p_keymap;
378#endif
379
380/* Saved values for when 'bin' is set. */
381static int p_et_nobin;
382static int p_ml_nobin;
383static long p_tw_nobin;
384static long p_wm_nobin;
385
386/* Saved values for when 'paste' is set */
387static long p_tw_nopaste;
388static long p_wm_nopaste;
389static long p_sts_nopaste;
390static int p_ai_nopaste;
391
392struct vimoption
393{
394 char *fullname; /* full option name */
395 char *shortname; /* permissible abbreviation */
396 long_u flags; /* see below */
397 char_u *var; /* global option: pointer to variable;
398 * window-local option: VAR_WIN;
399 * buffer-local option: global value */
400 idopt_T indir; /* global option: PV_NONE;
401 * local option: indirect option index */
402 char_u *def_val[2]; /* default values for variable (vi and vim) */
403#ifdef FEAT_EVAL
404 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000405# define SCRIPTID_INIT , 0
406#else
407# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408#endif
409};
410
411#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
412#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
413
414/*
415 * Flags
416 */
417#define P_BOOL 0x01 /* the option is boolean */
418#define P_NUM 0x02 /* the option is numeric */
419#define P_STRING 0x04 /* the option is a string */
420#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000421 must use free_string_option() when
422 assigning new value. Not set if default is
423 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000424#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
425 never be used for local or hidden options! */
426#define P_NODEFAULT 0x40 /* don't set to default value */
427#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
428 use vim_free() when assigning new value */
429#define P_WAS_SET 0x100 /* option has been set/reset */
430#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
431#define P_VI_DEF 0x400 /* Use Vi default for Vim */
432#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
433
434 /* when option changed, what to display: */
435#define P_RSTAT 0x1000 /* redraw status lines */
436#define P_RWIN 0x2000 /* redraw current window */
437#define P_RBUF 0x4000 /* redraw current buffer */
438#define P_RALL 0x6000 /* redraw all windows */
439#define P_RCLR 0x7000 /* clear and redraw all */
440
441#define P_COMMA 0x8000 /* comma separated list */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200442#define P_NODUP 0x10000L /* don't allow duplicate strings */
443#define P_FLAGLIST 0x20000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444
Bram Moolenaar913077c2012-03-28 19:59:04 +0200445#define P_SECURE 0x40000L /* cannot change in modeline or secure mode */
446#define P_GETTEXT 0x80000L /* expand default value with _() */
447#define P_NOGLOB 0x100000L /* do not use local value for global vimrc */
448#define P_NFNAME 0x200000L /* only normal file name chars allowed */
449#define P_INSECURE 0x400000L /* option was set from a modeline */
450#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000451 side effects) */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200452#define P_NO_ML 0x1000000L /* not allowed in modeline */
453#define P_CURSWANT 0x2000000L /* update curswant required; not needed when
454 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000455
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000456#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
457
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000458/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
459 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000460#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000461# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000462#else
463# define ISP_LATIN1 (char_u *)"@,161-255"
464#endif
465
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000466/* The 16 bit MS-DOS version is low on space, make the string as short as
467 * possible when compiling with few features. */
468#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
469 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200470 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100471# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000472#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100473# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000474#endif
475
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476/*
477 * options[] is initialized here.
478 * The order of the options MUST be alphabetic for ":set all" and findoption().
479 * All option names MUST start with a lowercase letter (for findoption()).
480 * Exception: "t_" options are at the end.
481 * The options with a NULL variable are 'hidden': a set command for them is
482 * ignored and they are not printed.
483 */
484static struct vimoption
485#ifdef FEAT_GUI_W16
486 _far
487#endif
488 options[] =
489{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200490 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000491#ifdef FEAT_RIGHTLEFT
492 (char_u *)&p_aleph, PV_NONE,
493#else
494 (char_u *)NULL, PV_NONE,
495#endif
496 {
497#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
498 (char_u *)128L,
499#else
500 (char_u *)224L,
501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000502 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
504#if defined(FEAT_GUI) && defined(MACOS_X)
505 (char_u *)&p_antialias, PV_NONE,
506 {(char_u *)FALSE, (char_u *)FALSE}
507#else
508 (char_u *)NULL, PV_NONE,
509 {(char_u *)FALSE, (char_u *)FALSE}
510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000511 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200512 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000513#ifdef FEAT_ARABIC
514 (char_u *)VAR_WIN, PV_ARAB,
515#else
516 (char_u *)NULL, PV_NONE,
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
520#ifdef FEAT_ARABIC
521 (char_u *)&p_arshape, PV_NONE,
522#else
523 (char_u *)NULL, PV_NONE,
524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000525 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
527#ifdef FEAT_RIGHTLEFT
528 (char_u *)&p_ari, PV_NONE,
529#else
530 (char_u *)NULL, PV_NONE,
531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000532 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
534#ifdef FEAT_FKMAP
535 (char_u *)&p_altkeymap, PV_NONE,
536#else
537 (char_u *)NULL, PV_NONE,
538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000540 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
541#if defined(FEAT_MBYTE)
542 (char_u *)&p_ambw, PV_NONE,
543 {(char_u *)"single", (char_u *)0L}
544#else
545 (char_u *)NULL, PV_NONE,
546 {(char_u *)0L, (char_u *)0L}
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000549#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"autochdir", "acd", P_BOOL|P_VI_DEF,
551 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553#endif
554 {"autoindent", "ai", P_BOOL|P_VI_DEF,
555 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autoprint", "ap", P_BOOL|P_VI_DEF,
558 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000561 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autowrite", "aw", P_BOOL|P_VI_DEF,
564 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autowriteall","awa", P_BOOL|P_VI_DEF,
567 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
570 (char_u *)&p_bg, PV_NONE,
571 {
572#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
573 (char_u *)"dark",
574#else
575 (char_u *)"light",
576#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000577 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
579 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
582 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
585 (char_u *)&p_bkc, PV_NONE,
586#ifdef UNIX
587 {(char_u *)"yes", (char_u *)"auto"}
588#else
589 {(char_u *)"auto", (char_u *)"auto"}
590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
593 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000594 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000595 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 (char_u *)&p_bex, PV_NONE,
597 {
598#ifdef VMS
599 (char_u *)"_",
600#else
601 (char_u *)"~",
602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
605#ifdef FEAT_WILDIGN
606 (char_u *)&p_bsk, PV_NONE,
607 {(char_u *)"", (char_u *)0L}
608#else
609 (char_u *)NULL, PV_NONE,
610 {(char_u *)0L, (char_u *)0L}
611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613#ifdef FEAT_BEVAL
614 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
615 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
618 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000620# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000621 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000622 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000624# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625#endif
626 {"beautify", "bf", P_BOOL|P_VI_DEF,
627 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
630 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
633#ifdef MSDOS
634 (char_u *)&p_biosk, PV_NONE,
635#else
636 (char_u *)NULL, PV_NONE,
637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000638 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
640#ifdef FEAT_MBYTE
641 (char_u *)&p_bomb, PV_BOMB,
642#else
643 (char_u *)NULL, PV_NONE,
644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000645 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
647#ifdef FEAT_LINEBREAK
648 (char_u *)&p_breakat, PV_NONE,
649 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
650#else
651 (char_u *)NULL, PV_NONE,
652 {(char_u *)0L, (char_u *)0L}
653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000654 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200655 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
656#ifdef FEAT_LINEBREAK
657 (char_u *)VAR_WIN, PV_BRI,
658 {(char_u *)FALSE, (char_u *)0L}
659#else
660 (char_u *)NULL, PV_NONE,
661 {(char_u *)0L, (char_u *)0L}
662#endif
663 SCRIPTID_INIT},
664 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_COMMA|P_NODUP,
665#ifdef FEAT_LINEBREAK
666 (char_u *)VAR_WIN, PV_BRIOPT,
667 {(char_u *)"", (char_u *)NULL}
668#else
669 (char_u *)NULL, PV_NONE,
670 {(char_u *)"", (char_u *)NULL}
671#endif
672 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
674#ifdef FEAT_BROWSE
675 (char_u *)&p_bsdir, PV_NONE,
676 {(char_u *)"last", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
683#if defined(FEAT_QUICKFIX)
684 (char_u *)&p_bh, PV_BH,
685 {(char_u *)"", (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
692 (char_u *)&p_bl, PV_BL,
693 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000694 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
696#if defined(FEAT_QUICKFIX)
697 (char_u *)&p_bt, PV_BT,
698 {(char_u *)"", (char_u *)0L}
699#else
700 (char_u *)NULL, PV_NONE,
701 {(char_u *)0L, (char_u *)0L}
702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000703 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000705#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 (char_u *)&p_cmp, PV_NONE,
707 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000708#else
709 (char_u *)NULL, PV_NONE,
710 {(char_u *)0L, (char_u *)0L}
711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
714#ifdef FEAT_SEARCHPATH
715 (char_u *)&p_cdpath, PV_NONE,
716 {(char_u *)",,", (char_u *)0L}
717#else
718 (char_u *)NULL, PV_NONE,
719 {(char_u *)0L, (char_u *)0L}
720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 {"cedit", NULL, P_STRING,
723#ifdef FEAT_CMDWIN
724 (char_u *)&p_cedit, PV_NONE,
725 {(char_u *)"", (char_u *)CTRL_F_STR}
726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
732#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
733 (char_u *)&p_ccv, PV_NONE,
734 {(char_u *)"", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
741#ifdef FEAT_CINDENT
742 (char_u *)&p_cin, PV_CIN,
743#else
744 (char_u *)NULL, PV_NONE,
745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
748#ifdef FEAT_CINDENT
749 (char_u *)&p_cink, PV_CINK,
750 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
751#else
752 (char_u *)NULL, PV_NONE,
753 {(char_u *)0L, (char_u *)0L}
754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000755 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
757#ifdef FEAT_CINDENT
758 (char_u *)&p_cino, PV_CINO,
759#else
760 (char_u *)NULL, PV_NONE,
761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000762 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000763 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
764#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
765 (char_u *)&p_cinw, PV_CINW,
766 {(char_u *)"if,else,while,do,for,switch",
767 (char_u *)0L}
768#else
769 (char_u *)NULL, PV_NONE,
770 {(char_u *)0L, (char_u *)0L}
771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000772 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000773 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
774#ifdef FEAT_CLIPBOARD
775 (char_u *)&p_cb, PV_NONE,
776# ifdef FEAT_XCLIPBOARD
777 {(char_u *)"autoselect,exclude:cons\\|linux",
778 (char_u *)0L}
779# else
780 {(char_u *)"", (char_u *)0L}
781# endif
782#else
783 (char_u *)NULL, PV_NONE,
784 {(char_u *)"", (char_u *)0L}
785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
788 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
791#ifdef FEAT_CMDWIN
792 (char_u *)&p_cwh, PV_NONE,
793#else
794 (char_u *)NULL, PV_NONE,
795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000796 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200797 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
798#ifdef FEAT_SYN_HL
799 (char_u *)VAR_WIN, PV_CC,
800#else
801 (char_u *)NULL, PV_NONE,
802#endif
803 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
805 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000806 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200807 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808#ifdef FEAT_COMMENTS
809 (char_u *)&p_com, PV_COM,
810 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
811 (char_u *)0L}
812#else
813 (char_u *)NULL, PV_NONE,
814 {(char_u *)0L, (char_u *)0L}
815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000816 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200817 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818#ifdef FEAT_FOLDING
819 (char_u *)&p_cms, PV_CMS,
820 {(char_u *)"/*%s*/", (char_u *)0L}
821#else
822 (char_u *)NULL, PV_NONE,
823 {(char_u *)0L, (char_u *)0L}
824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000826 /* P_PRI_MKRC isn't needed here, optval_default()
827 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000828 {"compatible", "cp", P_BOOL|P_RALL,
829 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000830 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
832#ifdef FEAT_INS_EXPAND
833 (char_u *)&p_cpt, PV_CPT,
834 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
835#else
836 (char_u *)NULL, PV_NONE,
837 {(char_u *)0L, (char_u *)0L}
838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000839 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200840 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200841#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200842 (char_u *)VAR_WIN, PV_COCU,
843 {(char_u *)"", (char_u *)NULL}
844#else
845 (char_u *)NULL, PV_NONE,
846 {(char_u *)NULL, (char_u *)0L}
847#endif
848 SCRIPTID_INIT},
849 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
850#ifdef FEAT_CONCEAL
851 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200852#else
853 (char_u *)NULL, PV_NONE,
854#endif
855 {(char_u *)0L, (char_u *)0L}
856 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000857 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
858#ifdef FEAT_COMPL_FUNC
859 (char_u *)&p_cfu, PV_CFU,
860 {(char_u *)"", (char_u *)0L}
861#else
862 (char_u *)NULL, PV_NONE,
863 {(char_u *)0L, (char_u *)0L}
864#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000865 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000866 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
867#ifdef FEAT_INS_EXPAND
868 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000869 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000870#else
871 (char_u *)NULL, PV_NONE,
872 {(char_u *)0L, (char_u *)0L}
873#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000874 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000875 {"confirm", "cf", P_BOOL|P_VI_DEF,
876#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
877 (char_u *)&p_confirm, PV_NONE,
878#else
879 (char_u *)NULL, PV_NONE,
880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000881 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000882 {"conskey", "consk",P_BOOL|P_VI_DEF,
883#ifdef MSDOS
884 (char_u *)&p_consk, PV_NONE,
885#else
886 (char_u *)NULL, PV_NONE,
887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
890 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
893 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
895 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200896 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200897#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200898 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200899 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200900#else
901 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200902 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200903#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200904 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
906#ifdef FEAT_CSCOPE
907 (char_u *)&p_cspc, PV_NONE,
908#else
909 (char_u *)NULL, PV_NONE,
910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
913#ifdef FEAT_CSCOPE
914 (char_u *)&p_csprg, PV_NONE,
915 {(char_u *)"cscope", (char_u *)0L}
916#else
917 (char_u *)NULL, PV_NONE,
918 {(char_u *)0L, (char_u *)0L}
919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
922#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
923 (char_u *)&p_csqf, PV_NONE,
924 {(char_u *)"", (char_u *)0L}
925#else
926 (char_u *)NULL, PV_NONE,
927 {(char_u *)0L, (char_u *)0L}
928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000929 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200930 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
931#ifdef FEAT_CSCOPE
932 (char_u *)&p_csre, PV_NONE,
933#else
934 (char_u *)NULL, PV_NONE,
935#endif
936 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
938#ifdef FEAT_CSCOPE
939 (char_u *)&p_cst, PV_NONE,
940#else
941 (char_u *)NULL, PV_NONE,
942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000943 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
945#ifdef FEAT_CSCOPE
946 (char_u *)&p_csto, PV_NONE,
947#else
948 (char_u *)NULL, PV_NONE,
949#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000950 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000951 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
952#ifdef FEAT_CSCOPE
953 (char_u *)&p_csverbose, PV_NONE,
954#else
955 (char_u *)NULL, PV_NONE,
956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000957 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200958 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
959#ifdef FEAT_CURSORBIND
960 (char_u *)VAR_WIN, PV_CRBIND,
961#else
962 (char_u *)NULL, PV_NONE,
963#endif
964 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000965 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
966#ifdef FEAT_SYN_HL
967 (char_u *)VAR_WIN, PV_CUC,
968#else
969 (char_u *)NULL, PV_NONE,
970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000971 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000972 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
973#ifdef FEAT_SYN_HL
974 (char_u *)VAR_WIN, PV_CUL,
975#else
976 (char_u *)NULL, PV_NONE,
977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979 {"debug", NULL, P_STRING|P_VI_DEF,
980 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000981 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200982 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000984 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000985 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000986#else
987 (char_u *)NULL, PV_NONE,
988 {(char_u *)NULL, (char_u *)0L}
989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
992#ifdef FEAT_MBYTE
993 (char_u *)&p_deco, PV_NONE,
994#else
995 (char_u *)NULL, PV_NONE,
996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
999#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001000 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001#else
1002 (char_u *)NULL, PV_NONE,
1003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1006#ifdef FEAT_DIFF
1007 (char_u *)VAR_WIN, PV_DIFF,
1008#else
1009 (char_u *)NULL, PV_NONE,
1010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001011 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001012 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1014 (char_u *)&p_dex, PV_NONE,
1015 {(char_u *)"", (char_u *)0L}
1016#else
1017 (char_u *)NULL, PV_NONE,
1018 {(char_u *)0L, (char_u *)0L}
1019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001020 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
1022#ifdef FEAT_DIFF
1023 (char_u *)&p_dip, PV_NONE,
1024 {(char_u *)"filler", (char_u *)NULL}
1025#else
1026 (char_u *)NULL, PV_NONE,
1027 {(char_u *)"", (char_u *)NULL}
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1031#ifdef FEAT_DIGRAPHS
1032 (char_u *)&p_dg, PV_NONE,
1033#else
1034 (char_u *)NULL, PV_NONE,
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1038 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001039 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1041 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001042 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 {"eadirection", "ead", P_STRING|P_VI_DEF,
1044#ifdef FEAT_VERTSPLIT
1045 (char_u *)&p_ead, PV_NONE,
1046 {(char_u *)"both", (char_u *)0L}
1047#else
1048 (char_u *)NULL, PV_NONE,
1049 {(char_u *)NULL, (char_u *)0L}
1050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1053 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001055 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056#ifdef FEAT_MBYTE
1057 (char_u *)&p_enc, PV_NONE,
1058 {(char_u *)ENC_DFLT, (char_u *)0L}
1059#else
1060 (char_u *)NULL, PV_NONE,
1061 {(char_u *)0L, (char_u *)0L}
1062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1065 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1068 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001071 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1074 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001075 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1077#ifdef FEAT_QUICKFIX
1078 (char_u *)&p_ef, PV_NONE,
1079 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)NULL, (char_u *)0L}
1083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1086#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001087 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089#else
1090 (char_u *)NULL, PV_NONE,
1091 {(char_u *)NULL, (char_u *)0L}
1092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"esckeys", "ek", P_BOOL|P_VIM,
1095 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1098#ifdef FEAT_AUTOCMD
1099 (char_u *)&p_ei, PV_NONE,
1100#else
1101 (char_u *)NULL, PV_NONE,
1102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1105 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1108 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1111#ifdef FEAT_MBYTE
1112 (char_u *)&p_fenc, PV_FENC,
1113 {(char_u *)"", (char_u *)0L}
1114#else
1115 (char_u *)NULL, PV_NONE,
1116 {(char_u *)0L, (char_u *)0L}
1117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1120#ifdef FEAT_MBYTE
1121 (char_u *)&p_fencs, PV_NONE,
1122 {(char_u *)"ucs-bom", (char_u *)0L}
1123#else
1124 (char_u *)NULL, PV_NONE,
1125 {(char_u *)0L, (char_u *)0L}
1126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001128 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1132 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1134 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001135 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1136 (char_u *)&p_fic, PV_NONE,
1137 {
1138#ifdef CASE_INSENSITIVE_FILENAME
1139 (char_u *)TRUE,
1140#else
1141 (char_u *)FALSE,
1142#endif
1143 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001144 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145#ifdef FEAT_AUTOCMD
1146 (char_u *)&p_ft, PV_FT,
1147 {(char_u *)"", (char_u *)0L}
1148#else
1149 (char_u *)NULL, PV_NONE,
1150 {(char_u *)0L, (char_u *)0L}
1151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001152 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1154#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1155 (char_u *)&p_fcs, PV_NONE,
1156 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1157#else
1158 (char_u *)NULL, PV_NONE,
1159 {(char_u *)"", (char_u *)0L}
1160#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001161 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1163#ifdef FEAT_FKMAP
1164 (char_u *)&p_fkmap, PV_NONE,
1165#else
1166 (char_u *)NULL, PV_NONE,
1167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"flash", "fl", P_BOOL|P_VI_DEF,
1170 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172#ifdef FEAT_FOLDING
1173 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1174 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1177 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1180 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1183# ifdef FEAT_EVAL
1184 (char_u *)VAR_WIN, PV_FDE,
1185 {(char_u *)"0", (char_u *)NULL}
1186# else
1187 (char_u *)NULL, PV_NONE,
1188 {(char_u *)NULL, (char_u *)0L}
1189# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001190 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1192 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001193 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1195 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001196 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001197 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001199 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001200 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1201 P_RWIN|P_COMMA|P_NODUP,
1202 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 {(char_u *)"{{{,}}}", (char_u *)NULL}
1204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001205 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1206 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001207 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001208 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1209 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1212 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001214 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 (char_u *)&p_fdo, PV_NONE,
1216 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1219# ifdef FEAT_EVAL
1220 (char_u *)VAR_WIN, PV_FDT,
1221 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001222# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 (char_u *)NULL, PV_NONE,
1224 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001225# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001228 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001229#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001230 (char_u *)&p_fex, PV_FEX,
1231 {(char_u *)"", (char_u *)0L}
1232#else
1233 (char_u *)NULL, PV_NONE,
1234 {(char_u *)0L, (char_u *)0L}
1235#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1238 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001239 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1240 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001241 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1242 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001243 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1244 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1246 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001247 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001248 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1249#ifdef HAVE_FSYNC
1250 (char_u *)&p_fs, PV_NONE,
1251 {(char_u *)TRUE, (char_u *)0L}
1252#else
1253 (char_u *)NULL, PV_NONE,
1254 {(char_u *)FALSE, (char_u *)0L}
1255#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001257 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1258 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001259 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001260 {"graphic", "gr", P_BOOL|P_VI_DEF,
1261 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001262 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001263 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1264#ifdef FEAT_QUICKFIX
1265 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)NULL, (char_u *)0L}
1270#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001271 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001272 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1273#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001274 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001275 {
1276# ifdef WIN3264
1277 /* may be changed to "grep -n" in os_win32.c */
1278 (char_u *)"findstr /n",
1279# else
1280# ifdef UNIX
1281 /* Add an extra file name so that grep will always
1282 * insert a file name in the match line. */
1283 (char_u *)"grep -n $* /dev/null",
1284# else
1285# ifdef VMS
1286 (char_u *)"SEARCH/NUMBERS ",
1287# else
1288 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001289# endif
1290# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001292 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001293#else
1294 (char_u *)NULL, PV_NONE,
1295 {(char_u *)NULL, (char_u *)0L}
1296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001297 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1299#ifdef CURSOR_SHAPE
1300 (char_u *)&p_guicursor, PV_NONE,
1301 {
1302# ifdef FEAT_GUI
1303 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
1304# else /* MSDOS or Win32 console */
1305 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1306# endif
1307 (char_u *)0L}
1308#else
1309 (char_u *)NULL, PV_NONE,
1310 {(char_u *)NULL, (char_u *)0L}
1311#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1314#ifdef FEAT_GUI
1315 (char_u *)&p_guifont, PV_NONE,
1316 {(char_u *)"", (char_u *)0L}
1317#else
1318 (char_u *)NULL, PV_NONE,
1319 {(char_u *)NULL, (char_u *)0L}
1320#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001321 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001322 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1323#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1324 (char_u *)&p_guifontset, PV_NONE,
1325 {(char_u *)"", (char_u *)0L}
1326#else
1327 (char_u *)NULL, PV_NONE,
1328 {(char_u *)NULL, (char_u *)0L}
1329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001330 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001331 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1332#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1333 (char_u *)&p_guifontwide, PV_NONE,
1334 {(char_u *)"", (char_u *)0L}
1335#else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)NULL, (char_u *)0L}
1338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001339 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001341#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 (char_u *)&p_ghr, PV_NONE,
1343#else
1344 (char_u *)NULL, PV_NONE,
1345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001348#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 (char_u *)&p_go, PV_NONE,
1350# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001351 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001353 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354# endif
1355#else
1356 (char_u *)NULL, PV_NONE,
1357 {(char_u *)NULL, (char_u *)0L}
1358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 {"guipty", NULL, P_BOOL|P_VI_DEF,
1361#if defined(FEAT_GUI)
1362 (char_u *)&p_guipty, PV_NONE,
1363#else
1364 (char_u *)NULL, PV_NONE,
1365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001366 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001367 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001368#if defined(FEAT_GUI_TABLINE)
1369 (char_u *)&p_gtl, PV_NONE,
1370 {(char_u *)"", (char_u *)0L}
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001375 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001376 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001377#if defined(FEAT_GUI_TABLINE)
1378 (char_u *)&p_gtt, PV_NONE,
1379 {(char_u *)"", (char_u *)0L}
1380#else
1381 (char_u *)NULL, PV_NONE,
1382 {(char_u *)NULL, (char_u *)0L}
1383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001384 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1386 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001387 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001388 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1389 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001390 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1391 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392 {"helpheight", "hh", P_NUM|P_VI_DEF,
1393#ifdef FEAT_WINDOWS
1394 (char_u *)&p_hh, PV_NONE,
1395#else
1396 (char_u *)NULL, PV_NONE,
1397#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001398 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1400#ifdef FEAT_MULTI_LANG
1401 (char_u *)&p_hlg, PV_NONE,
1402 {(char_u *)"", (char_u *)0L}
1403#else
1404 (char_u *)NULL, PV_NONE,
1405 {(char_u *)0L, (char_u *)0L}
1406#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001407 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"hidden", "hid", P_BOOL|P_VI_DEF,
1409 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001410 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001411 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1412 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001413 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1414 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415 {"history", "hi", P_NUM|P_VIM,
1416 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001417 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1419#ifdef FEAT_RIGHTLEFT
1420 (char_u *)&p_hkmap, PV_NONE,
1421#else
1422 (char_u *)NULL, PV_NONE,
1423#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001424 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1426#ifdef FEAT_RIGHTLEFT
1427 (char_u *)&p_hkmapp, PV_NONE,
1428#else
1429 (char_u *)NULL, PV_NONE,
1430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1433 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"icon", NULL, P_BOOL|P_VI_DEF,
1436#ifdef FEAT_TITLE
1437 (char_u *)&p_icon, PV_NONE,
1438#else
1439 (char_u *)NULL, PV_NONE,
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"iconstring", NULL, P_STRING|P_VI_DEF,
1443#ifdef FEAT_TITLE
1444 (char_u *)&p_iconstring, PV_NONE,
1445#else
1446 (char_u *)NULL, PV_NONE,
1447#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001448 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1450 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001452 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1453# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1454 (char_u *)&p_imaf, PV_NONE,
1455 {(char_u *)"", (char_u *)NULL}
1456# else
1457 (char_u *)NULL, PV_NONE,
1458 {(char_u *)NULL, (char_u *)0L}
1459# endif
1460 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001462#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463 (char_u *)&p_imak, PV_NONE,
1464#else
1465 (char_u *)NULL, PV_NONE,
1466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001467 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1469#ifdef USE_IM_CONTROL
1470 (char_u *)&p_imcmdline, PV_NONE,
1471#else
1472 (char_u *)NULL, PV_NONE,
1473#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001474 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001475 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1476#ifdef USE_IM_CONTROL
1477 (char_u *)&p_imdisable, PV_NONE,
1478#else
1479 (char_u *)NULL, PV_NONE,
1480#endif
1481#ifdef __sgi
1482 {(char_u *)TRUE, (char_u *)0L}
1483#else
1484 {(char_u *)FALSE, (char_u *)0L}
1485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001486 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 {"iminsert", "imi", P_NUM|P_VI_DEF,
1488 (char_u *)&p_iminsert, PV_IMI,
1489#ifdef B_IMODE_IM
1490 {(char_u *)B_IMODE_IM, (char_u *)0L}
1491#else
1492 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001494 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"imsearch", "ims", P_NUM|P_VI_DEF,
1496 (char_u *)&p_imsearch, PV_IMS,
1497#ifdef B_IMODE_IM
1498 {(char_u *)B_IMODE_IM, (char_u *)0L}
1499#else
1500 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001503 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001504# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1505 (char_u *)&p_imsf, PV_NONE,
1506 {(char_u *)"", (char_u *)NULL}
1507# else
1508 (char_u *)NULL, PV_NONE,
1509 {(char_u *)NULL, (char_u *)0L}
1510# endif
1511 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1513#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001514 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1516#else
1517 (char_u *)NULL, PV_NONE,
1518 {(char_u *)0L, (char_u *)0L}
1519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001520 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1522#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1523 (char_u *)&p_inex, PV_INEX,
1524 {(char_u *)"", (char_u *)0L}
1525#else
1526 (char_u *)NULL, PV_NONE,
1527 {(char_u *)0L, (char_u *)0L}
1528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001529 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1531 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001532 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001533 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1534#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1535 (char_u *)&p_inde, PV_INDE,
1536 {(char_u *)"", (char_u *)0L}
1537#else
1538 (char_u *)NULL, PV_NONE,
1539 {(char_u *)0L, (char_u *)0L}
1540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001541 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1543#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1544 (char_u *)&p_indk, PV_INDK,
1545 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1546#else
1547 (char_u *)NULL, PV_NONE,
1548 {(char_u *)0L, (char_u *)0L}
1549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001550 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001551 {"infercase", "inf", P_BOOL|P_VI_DEF,
1552 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1555 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1558 (char_u *)&p_isf, PV_NONE,
1559 {
1560#ifdef BACKSLASH_IN_FILENAME
1561 /* Excluded are: & and ^ are special in cmd.exe
1562 * ( and ) are used in text separating fnames */
1563 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1564#else
1565# ifdef AMIGA
1566 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1567# else
1568# ifdef VMS
1569 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1570# else /* UNIX et al. */
1571# ifdef EBCDIC
1572 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1573# else
1574 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1575# endif
1576# endif
1577# endif
1578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1581 (char_u *)&p_isi, PV_NONE,
1582 {
1583#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1584 (char_u *)"@,48-57,_,128-167,224-235",
1585#else
1586# ifdef EBCDIC
1587 /* TODO: EBCDIC Check this! @ == isalpha()*/
1588 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1589 "112-120,128,140-142,156,158,172,"
1590 "174,186,191,203-207,219-225,235-239,"
1591 "251-254",
1592# else
1593 (char_u *)"@,48-57,_,192-255",
1594# endif
1595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001596 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001597 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1598 (char_u *)&p_isk, PV_ISK,
1599 {
1600#ifdef EBCDIC
1601 (char_u *)"@,240-249,_",
1602 /* TODO: EBCDIC Check this! @ == isalpha()*/
1603 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1604 "112-120,128,140-142,156,158,172,"
1605 "174,186,191,203-207,219-225,235-239,"
1606 "251-254",
1607#else
1608 (char_u *)"@,48-57,_",
1609# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1610 (char_u *)"@,48-57,_,128-167,224-235"
1611# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001612 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613# endif
1614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001615 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001616 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1617 (char_u *)&p_isp, PV_NONE,
1618 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001619#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1620 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001621 || defined(VMS)
1622 (char_u *)"@,~-255",
1623#else
1624# ifdef EBCDIC
1625 /* all chars above 63 are printable */
1626 (char_u *)"63-255",
1627# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001628 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629# endif
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1633 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1636#ifdef FEAT_CRYPT
1637 (char_u *)&p_key, PV_KEY,
1638 {(char_u *)"", (char_u *)0L}
1639#else
1640 (char_u *)NULL, PV_NONE,
1641 {(char_u *)0L, (char_u *)0L}
1642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001644 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645#ifdef FEAT_KEYMAP
1646 (char_u *)&p_keymap, PV_KMAP,
1647 {(char_u *)"", (char_u *)0L}
1648#else
1649 (char_u *)NULL, PV_NONE,
1650 {(char_u *)"", (char_u *)0L}
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001656 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001657 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658 {
1659#if defined(MSDOS) || defined(MSWIN)
1660 (char_u *)":help",
1661#else
1662#ifdef VMS
1663 (char_u *)"help",
1664#else
1665# if defined(OS2)
1666 (char_u *)"view /",
1667# else
1668# ifdef USEMAN_S
1669 (char_u *)"man -s",
1670# else
1671 (char_u *)"man",
1672# endif
1673# endif
1674#endif
1675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001676 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaared7547d2014-05-13 12:17:15 +02001677 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678#ifdef FEAT_LANGMAP
1679 (char_u *)&p_langmap, PV_NONE,
1680 {(char_u *)"", /* unmatched } */
1681#else
1682 (char_u *)NULL, PV_NONE,
1683 {(char_u *)NULL,
1684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001685 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001686 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1688 (char_u *)&p_lm, PV_NONE,
1689#else
1690 (char_u *)NULL, PV_NONE,
1691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1694#ifdef FEAT_WINDOWS
1695 (char_u *)&p_ls, PV_NONE,
1696#else
1697 (char_u *)NULL, PV_NONE,
1698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001699 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1701 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001702 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1704#ifdef FEAT_LINEBREAK
1705 (char_u *)VAR_WIN, PV_LBR,
1706#else
1707 (char_u *)NULL, PV_NONE,
1708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001709 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1711 (char_u *)&Rows, PV_NONE,
1712 {
1713#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1714 (char_u *)25L,
1715#else
1716 (char_u *)24L,
1717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001718 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1720#ifdef FEAT_GUI
1721 (char_u *)&p_linespace, PV_NONE,
1722#else
1723 (char_u *)NULL, PV_NONE,
1724#endif
1725#ifdef FEAT_GUI_W32
1726 {(char_u *)1L, (char_u *)0L}
1727#else
1728 {(char_u *)0L, (char_u *)0L}
1729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 {"lisp", NULL, P_BOOL|P_VI_DEF,
1732#ifdef FEAT_LISP
1733 (char_u *)&p_lisp, PV_LISP,
1734#else
1735 (char_u *)NULL, PV_NONE,
1736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001737 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1739#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001740 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1742#else
1743 (char_u *)NULL, PV_NONE,
1744 {(char_u *)"", (char_u *)0L}
1745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001746 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1748 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1751 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1754 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001755 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001756#ifdef FEAT_GUI_MAC
1757 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1758 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"magic", NULL, P_BOOL|P_VI_DEF,
1762 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001764 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765#ifdef FEAT_QUICKFIX
1766 (char_u *)&p_mef, PV_NONE,
1767 {(char_u *)"", (char_u *)0L}
1768#else
1769 (char_u *)NULL, PV_NONE,
1770 {(char_u *)NULL, (char_u *)0L}
1771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1774#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001775 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776# ifdef VMS
1777 {(char_u *)"MMS", (char_u *)0L}
1778# else
1779 {(char_u *)"make", (char_u *)0L}
1780# endif
1781#else
1782 (char_u *)NULL, PV_NONE,
1783 {(char_u *)NULL, (char_u *)0L}
1784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1787 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1789 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"matchtime", "mat", P_NUM|P_VI_DEF,
1791 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001793 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001794#ifdef FEAT_MBYTE
1795 (char_u *)&p_mco, PV_NONE,
1796#else
1797 (char_u *)NULL, PV_NONE,
1798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001799 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1801#ifdef FEAT_EVAL
1802 (char_u *)&p_mfd, PV_NONE,
1803#else
1804 (char_u *)NULL, PV_NONE,
1805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001806 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1808 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001809 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810 {"maxmem", "mm", P_NUM|P_VI_DEF,
1811 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001812 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1813 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001814 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1815 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1818 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1820 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"menuitems", "mis", P_NUM|P_VI_DEF,
1822#ifdef FEAT_MENU
1823 (char_u *)&p_mis, PV_NONE,
1824#else
1825 (char_u *)NULL, PV_NONE,
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"mesg", NULL, P_BOOL|P_VI_DEF,
1829 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001831 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001832#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001833 (char_u *)&p_msm, PV_NONE,
1834 {(char_u *)"460000,2000,500", (char_u *)0L}
1835#else
1836 (char_u *)NULL, PV_NONE,
1837 {(char_u *)0L, (char_u *)0L}
1838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001839 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001840 {"modeline", "ml", P_BOOL|P_VIM,
1841 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001842 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001843 {"modelines", "mls", P_NUM|P_VI_DEF,
1844 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1847 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1850 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"more", NULL, P_BOOL|P_VIM,
1853 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001854 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1856 (char_u *)&p_mouse, PV_NONE,
1857 {
1858#if defined(MSDOS) || defined(WIN3264)
1859 (char_u *)"a",
1860#else
1861 (char_u *)"",
1862#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1865#ifdef FEAT_GUI
1866 (char_u *)&p_mousef, PV_NONE,
1867#else
1868 (char_u *)NULL, PV_NONE,
1869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1872#ifdef FEAT_GUI
1873 (char_u *)&p_mh, PV_NONE,
1874#else
1875 (char_u *)NULL, PV_NONE,
1876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1879 (char_u *)&p_mousem, PV_NONE,
1880 {
1881#if defined(MSDOS) || defined(MSWIN)
1882 (char_u *)"popup",
1883#else
1884# if defined(MACOS)
1885 (char_u *)"popup_setpos",
1886# else
1887 (char_u *)"extend",
1888# endif
1889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001890 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1892#ifdef FEAT_MOUSESHAPE
1893 (char_u *)&p_mouseshape, PV_NONE,
1894 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1895#else
1896 (char_u *)NULL, PV_NONE,
1897 {(char_u *)NULL, (char_u *)0L}
1898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1901 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001903 {"mzquantum", "mzq", P_NUM,
1904#ifdef FEAT_MZSCHEME
1905 (char_u *)&p_mzq, PV_NONE,
1906#else
1907 (char_u *)NULL, PV_NONE,
1908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001909 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 {"novice", NULL, P_BOOL|P_VI_DEF,
1911 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1914 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)"octal,hex", (char_u *)0L}
1916 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1918 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001920 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1921#ifdef FEAT_LINEBREAK
1922 (char_u *)VAR_WIN, PV_NUW,
1923#else
1924 (char_u *)NULL, PV_NONE,
1925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001927 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001928#ifdef FEAT_COMPL_FUNC
1929 (char_u *)&p_ofu, PV_OFU,
1930 {(char_u *)"", (char_u *)0L}
1931#else
1932 (char_u *)NULL, PV_NONE,
1933 {(char_u *)0L, (char_u *)0L}
1934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {"open", NULL, P_BOOL|P_VI_DEF,
1937 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001939 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1940#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1941 (char_u *)&p_odev, PV_NONE,
1942#else
1943 (char_u *)NULL, PV_NONE,
1944#endif
1945 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001947 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1948 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"optimize", "opt", P_BOOL|P_VI_DEF,
1951 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001955 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"paragraphs", "para", P_STRING|P_VI_DEF,
1957 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001958 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001960 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1964 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001965 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1967#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1968 (char_u *)&p_pex, PV_NONE,
1969 {(char_u *)"", (char_u *)0L}
1970#else
1971 (char_u *)NULL, PV_NONE,
1972 {(char_u *)0L, (char_u *)0L}
1973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001975 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001979 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {
1981#if defined AMIGA || defined MSDOS || defined MSWIN
1982 (char_u *)".,,",
1983#else
1984# if defined(__EMX__)
1985 (char_u *)".,/emx/include,,",
1986# else /* Unix, probably */
1987 (char_u *)".,/usr/include,,",
1988# endif
1989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1992 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001994 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1996 (char_u *)&p_pvh, PV_NONE,
1997#else
1998 (char_u *)NULL, PV_NONE,
1999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2002#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2003 (char_u *)VAR_WIN, PV_PVW,
2004#else
2005 (char_u *)NULL, PV_NONE,
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002008 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009#ifdef FEAT_PRINTER
2010 (char_u *)&p_pdev, PV_NONE,
2011 {(char_u *)"", (char_u *)0L}
2012#else
2013 (char_u *)NULL, PV_NONE,
2014 {(char_u *)NULL, (char_u *)0L}
2015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 {"printencoding", "penc", P_STRING|P_VI_DEF,
2018#ifdef FEAT_POSTSCRIPT
2019 (char_u *)&p_penc, PV_NONE,
2020 {(char_u *)"", (char_u *)0L}
2021#else
2022 (char_u *)NULL, PV_NONE,
2023 {(char_u *)NULL, (char_u *)0L}
2024#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2027#ifdef FEAT_POSTSCRIPT
2028 (char_u *)&p_pexpr, PV_NONE,
2029 {(char_u *)"", (char_u *)0L}
2030#else
2031 (char_u *)NULL, PV_NONE,
2032 {(char_u *)NULL, (char_u *)0L}
2033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002034 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 {"printfont", "pfn", P_STRING|P_VI_DEF,
2036#ifdef FEAT_PRINTER
2037 (char_u *)&p_pfn, PV_NONE,
2038 {
2039# ifdef MSWIN
2040 (char_u *)"Courier_New:h10",
2041# else
2042 (char_u *)"courier",
2043# endif
2044 (char_u *)0L}
2045#else
2046 (char_u *)NULL, PV_NONE,
2047 {(char_u *)NULL, (char_u *)0L}
2048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002049 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2051#ifdef FEAT_PRINTER
2052 (char_u *)&p_header, PV_NONE,
2053 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2054#else
2055 (char_u *)NULL, PV_NONE,
2056 {(char_u *)NULL, (char_u *)0L}
2057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002058 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002059 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2060#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2061 (char_u *)&p_pmcs, PV_NONE,
2062 {(char_u *)"", (char_u *)0L}
2063#else
2064 (char_u *)NULL, PV_NONE,
2065 {(char_u *)NULL, (char_u *)0L}
2066#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002067 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002068 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2069#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2070 (char_u *)&p_pmfn, PV_NONE,
2071 {(char_u *)"", (char_u *)0L}
2072#else
2073 (char_u *)NULL, PV_NONE,
2074 {(char_u *)NULL, (char_u *)0L}
2075#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002076 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2078#ifdef FEAT_PRINTER
2079 (char_u *)&p_popt, PV_NONE,
2080 {(char_u *)"", (char_u *)0L}
2081#else
2082 (char_u *)NULL, PV_NONE,
2083 {(char_u *)NULL, (char_u *)0L}
2084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002087 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002089 {"pumheight", "ph", P_NUM|P_VI_DEF,
2090#ifdef FEAT_INS_EXPAND
2091 (char_u *)&p_ph, PV_NONE,
2092#else
2093 (char_u *)NULL, PV_NONE,
2094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002096 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2097#ifdef FEAT_TEXTOBJ
2098 (char_u *)&p_qe, PV_QE,
2099 {(char_u *)"\\", (char_u *)0L}
2100#else
2101 (char_u *)NULL, PV_NONE,
2102 {(char_u *)NULL, (char_u *)0L}
2103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2106 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"redraw", NULL, P_BOOL|P_VI_DEF,
2109 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002110 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002111 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2112#ifdef FEAT_RELTIME
2113 (char_u *)&p_rdt, PV_NONE,
2114#else
2115 (char_u *)NULL, PV_NONE,
2116#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002118 {"regexpengine", "re", P_NUM|P_VI_DEF,
2119 (char_u *)&p_re, PV_NONE,
2120 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002121 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2122 (char_u *)VAR_WIN, PV_RNU,
2123 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 {"remap", NULL, P_BOOL|P_VI_DEF,
2125 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002126 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002127 {"renderoptions", "rop", P_STRING|P_COMMA|P_RCLR|P_VI_DEF,
2128#ifdef FEAT_RENDER_OPTIONS
2129 (char_u *)&p_rop, PV_NONE,
2130 {(char_u *)"", (char_u *)0L}
2131#else
2132 (char_u *)NULL, PV_NONE,
2133 {(char_u *)NULL, (char_u *)0L}
2134#endif
2135 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 {"report", NULL, P_NUM|P_VI_DEF,
2137 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002138 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2140#ifdef WIN3264
2141 (char_u *)&p_rs, PV_NONE,
2142#else
2143 (char_u *)NULL, PV_NONE,
2144#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2147#ifdef FEAT_RIGHTLEFT
2148 (char_u *)&p_ri, PV_NONE,
2149#else
2150 (char_u *)NULL, PV_NONE,
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2154#ifdef FEAT_RIGHTLEFT
2155 (char_u *)VAR_WIN, PV_RL,
2156#else
2157 (char_u *)NULL, PV_NONE,
2158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002159 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2161#ifdef FEAT_RIGHTLEFT
2162 (char_u *)VAR_WIN, PV_RLC,
2163 {(char_u *)"search", (char_u *)NULL}
2164#else
2165 (char_u *)NULL, PV_NONE,
2166 {(char_u *)NULL, (char_u *)0L}
2167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002168 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2170#ifdef FEAT_CMDL_INFO
2171 (char_u *)&p_ru, PV_NONE,
2172#else
2173 (char_u *)NULL, PV_NONE,
2174#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002175 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2177#ifdef FEAT_STL_OPT
2178 (char_u *)&p_ruf, PV_NONE,
2179#else
2180 (char_u *)NULL, PV_NONE,
2181#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002182 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2184 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2186 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2188 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002189 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2191#ifdef FEAT_SCROLLBIND
2192 (char_u *)VAR_WIN, PV_SCBIND,
2193#else
2194 (char_u *)NULL, PV_NONE,
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2198 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002199 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2201 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002202 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2204#ifdef FEAT_SCROLLBIND
2205 (char_u *)&p_sbo, PV_NONE,
2206 {(char_u *)"ver,jump", (char_u *)0L}
2207#else
2208 (char_u *)NULL, PV_NONE,
2209 {(char_u *)0L, (char_u *)0L}
2210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002211 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212 {"sections", "sect", P_STRING|P_VI_DEF,
2213 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2215 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002216 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2217 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002218 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002219 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002220 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 {(char_u *)"inclusive", (char_u *)0L}
2222 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2227#ifdef FEAT_SESSION
2228 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002229 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230 (char_u *)0L}
2231#else
2232 (char_u *)NULL, PV_NONE,
2233 {(char_u *)0L, (char_u *)0L}
2234#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002235 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002236 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2237 (char_u *)&p_sh, PV_NONE,
2238 {
2239#ifdef VMS
2240 (char_u *)"-",
2241#else
2242# if defined(MSDOS)
2243 (char_u *)"command",
2244# else
2245# if defined(WIN16)
2246 (char_u *)"command.com",
2247# else
2248# if defined(WIN3264)
2249 (char_u *)"", /* set in set_init_1() */
2250# else
2251# if defined(OS2)
2252 (char_u *)"cmd.exe",
2253# else
2254# if defined(ARCHIE)
2255 (char_u *)"gos",
2256# else
2257 (char_u *)"sh",
2258# endif
2259# endif
2260# endif
2261# endif
2262# endif
2263#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002264 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2266 (char_u *)&p_shcf, PV_NONE,
2267 {
2268#if defined(MSDOS) || defined(MSWIN)
2269 (char_u *)"/c",
2270#else
2271# if defined(OS2)
2272 (char_u *)"/c",
2273# else
2274 (char_u *)"-c",
2275# endif
2276#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002277 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2279#ifdef FEAT_QUICKFIX
2280 (char_u *)&p_sp, PV_NONE,
2281 {
2282#if defined(UNIX) || defined(OS2)
2283# ifdef ARCHIE
2284 (char_u *)"2>",
2285# else
2286 (char_u *)"| tee",
2287# endif
2288#else
2289 (char_u *)">",
2290#endif
2291 (char_u *)0L}
2292#else
2293 (char_u *)NULL, PV_NONE,
2294 {(char_u *)0L, (char_u *)0L}
2295#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002296 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2298 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002299 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2301 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002302 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2304#ifdef BACKSLASH_IN_FILENAME
2305 (char_u *)&p_ssl, PV_NONE,
2306#else
2307 (char_u *)NULL, PV_NONE,
2308#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002310 {"shelltemp", "stmp", P_BOOL,
2311 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002312 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 {"shelltype", "st", P_NUM|P_VI_DEF,
2314#ifdef AMIGA
2315 (char_u *)&p_st, PV_NONE,
2316#else
2317 (char_u *)NULL, PV_NONE,
2318#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002319 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2321 (char_u *)&p_sxq, PV_NONE,
2322 {
2323#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2324 (char_u *)"\"",
2325#else
2326 (char_u *)"",
2327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002329 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2330 (char_u *)&p_sxe, PV_NONE,
2331 {
2332#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2333 (char_u *)"\"&|<>()@^",
2334#else
2335 (char_u *)"",
2336#endif
2337 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2339 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2342 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2345 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)"", (char_u *)"filnxtToO"}
2347 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 {"shortname", "sn", P_BOOL|P_VI_DEF,
2349#ifdef SHORT_FNAME
2350 (char_u *)NULL, PV_NONE,
2351#else
2352 (char_u *)&p_sn, PV_SN,
2353#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2356#ifdef FEAT_LINEBREAK
2357 (char_u *)&p_sbr, PV_NONE,
2358#else
2359 (char_u *)NULL, PV_NONE,
2360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"showcmd", "sc", P_BOOL|P_VIM,
2363#ifdef FEAT_CMDL_INFO
2364 (char_u *)&p_sc, PV_NONE,
2365#else
2366 (char_u *)NULL, PV_NONE,
2367#endif
2368 {(char_u *)FALSE,
2369#ifdef UNIX
2370 (char_u *)FALSE
2371#else
2372 (char_u *)TRUE
2373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2376 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2379 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"showmode", "smd", P_BOOL|P_VIM,
2382 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002383 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002384 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2385#ifdef FEAT_WINDOWS
2386 (char_u *)&p_stal, PV_NONE,
2387#else
2388 (char_u *)NULL, PV_NONE,
2389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2392 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2395 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2398 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2401 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2404#ifdef FEAT_SMARTINDENT
2405 (char_u *)&p_si, PV_SI,
2406#else
2407 (char_u *)NULL, PV_NONE,
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2411 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2414 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2417 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002419 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002420#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002421 (char_u *)VAR_WIN, PV_SPELL,
2422#else
2423 (char_u *)NULL, PV_NONE,
2424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002426 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002427#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002428 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002429 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002430#else
2431 (char_u *)NULL, PV_NONE,
2432 {(char_u *)0L, (char_u *)0L}
2433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002435 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002436#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002437 (char_u *)&p_spf, PV_SPF,
2438 {(char_u *)"", (char_u *)0L}
2439#else
2440 (char_u *)NULL, PV_NONE,
2441 {(char_u *)0L, (char_u *)0L}
2442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002443 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002444 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002445#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002446 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002447 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002448#else
2449 (char_u *)NULL, PV_NONE,
2450 {(char_u *)0L, (char_u *)0L}
2451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002453 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002454#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002455 (char_u *)&p_sps, PV_NONE,
2456 {(char_u *)"best", (char_u *)0L}
2457#else
2458 (char_u *)NULL, PV_NONE,
2459 {(char_u *)0L, (char_u *)0L}
2460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2463#ifdef FEAT_WINDOWS
2464 (char_u *)&p_sb, PV_NONE,
2465#else
2466 (char_u *)NULL, PV_NONE,
2467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"splitright", "spr", P_BOOL|P_VI_DEF,
2470#ifdef FEAT_VERTSPLIT
2471 (char_u *)&p_spr, PV_NONE,
2472#else
2473 (char_u *)NULL, PV_NONE,
2474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2477 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2480#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002481 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482#else
2483 (char_u *)NULL, PV_NONE,
2484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2487 (char_u *)&p_su, PV_NONE,
2488 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002491#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 (char_u *)&p_sua, PV_SUA,
2493 {(char_u *)"", (char_u *)0L}
2494#else
2495 (char_u *)NULL, PV_NONE,
2496 {(char_u *)0L, (char_u *)0L}
2497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2500 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"swapsync", "sws", P_STRING|P_VI_DEF,
2503 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2506 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002508 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2509#ifdef FEAT_SYN_HL
2510 (char_u *)&p_smc, PV_SMC,
2511 {(char_u *)3000L, (char_u *)0L}
2512#else
2513 (char_u *)NULL, PV_NONE,
2514 {(char_u *)0L, (char_u *)0L}
2515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002516 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002517 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518#ifdef FEAT_SYN_HL
2519 (char_u *)&p_syn, PV_SYN,
2520 {(char_u *)"", (char_u *)0L}
2521#else
2522 (char_u *)NULL, PV_NONE,
2523 {(char_u *)0L, (char_u *)0L}
2524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002526 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2527#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002528 (char_u *)&p_tal, PV_NONE,
2529#else
2530 (char_u *)NULL, PV_NONE,
2531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002533 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2534#ifdef FEAT_WINDOWS
2535 (char_u *)&p_tpm, PV_NONE,
2536#else
2537 (char_u *)NULL, PV_NONE,
2538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2541 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002542 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2544 (char_u *)&p_tbs, PV_NONE,
2545#ifdef VMS /* binary searching doesn't appear to work on VMS */
2546 {(char_u *)0L, (char_u *)0L}
2547#else
2548 {(char_u *)TRUE, (char_u *)0L}
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"taglength", "tl", P_NUM|P_VI_DEF,
2552 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"tagrelative", "tr", P_BOOL|P_VIM,
2555 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002558 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {
2560#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2561 (char_u *)"./tags,./TAGS,tags,TAGS",
2562#else
2563 (char_u *)"./tags,tags",
2564#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2567 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2570 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2573#ifdef FEAT_ARABIC
2574 (char_u *)&p_tbidi, PV_NONE,
2575#else
2576 (char_u *)NULL, PV_NONE,
2577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2580#ifdef FEAT_MBYTE
2581 (char_u *)&p_tenc, PV_NONE,
2582 {(char_u *)"", (char_u *)0L}
2583#else
2584 (char_u *)NULL, PV_NONE,
2585 {(char_u *)0L, (char_u *)0L}
2586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588 {"terse", NULL, P_BOOL|P_VI_DEF,
2589 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {"textauto", "ta", P_BOOL|P_VIM,
2592 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2594 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2596 (char_u *)&p_tx, PV_TX,
2597 {
2598#ifdef USE_CRNL
2599 (char_u *)TRUE,
2600#else
2601 (char_u *)FALSE,
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002604 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002606 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2608#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002609 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610#else
2611 (char_u *)NULL, PV_NONE,
2612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2615 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"timeout", "to", P_BOOL|P_VI_DEF,
2618 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2621 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"title", NULL, P_BOOL|P_VI_DEF,
2624#ifdef FEAT_TITLE
2625 (char_u *)&p_title, PV_NONE,
2626#else
2627 (char_u *)NULL, PV_NONE,
2628#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 {"titlelen", NULL, P_NUM|P_VI_DEF,
2631#ifdef FEAT_TITLE
2632 (char_u *)&p_titlelen, PV_NONE,
2633#else
2634 (char_u *)NULL, PV_NONE,
2635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002637 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638#ifdef FEAT_TITLE
2639 (char_u *)&p_titleold, PV_NONE,
2640 {(char_u *)N_("Thanks for flying Vim"),
2641 (char_u *)0L}
2642#else
2643 (char_u *)NULL, PV_NONE,
2644 {(char_u *)0L, (char_u *)0L}
2645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"titlestring", NULL, P_STRING|P_VI_DEF,
2648#ifdef FEAT_TITLE
2649 (char_u *)&p_titlestring, PV_NONE,
2650#else
2651 (char_u *)NULL, PV_NONE,
2652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2655 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2656 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)"icons,tooltips", (char_u *)0L}
2658 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002660#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2662 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664#endif
2665 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2666 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2669 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2672 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002673 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2675 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2678#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2679 (char_u *)&p_ttym, PV_NONE,
2680#else
2681 (char_u *)NULL, PV_NONE,
2682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2685 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002686 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2688 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002689 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002690 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2691#ifdef FEAT_PERSISTENT_UNDO
2692 (char_u *)&p_udir, PV_NONE,
2693 {(char_u *)".", (char_u *)0L}
2694#else
2695 (char_u *)NULL, PV_NONE,
2696 {(char_u *)0L, (char_u *)0L}
2697#endif
2698 SCRIPTID_INIT},
2699 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2700#ifdef FEAT_PERSISTENT_UNDO
2701 (char_u *)&p_udf, PV_UDF,
2702#else
2703 (char_u *)NULL, PV_NONE,
2704#endif
2705 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002707 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {
2709#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2710 (char_u *)1000L,
2711#else
2712 (char_u *)100L,
2713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002715 {"undoreload", "ur", P_NUM|P_VI_DEF,
2716 (char_u *)&p_ur, PV_NONE,
2717 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"updatecount", "uc", P_NUM|P_VI_DEF,
2719 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"updatetime", "ut", P_NUM|P_VI_DEF,
2722 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"verbose", "vbs", P_NUM|P_VI_DEF,
2725 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002727 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2728 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2731#ifdef FEAT_SESSION
2732 (char_u *)&p_vdir, PV_NONE,
2733 {(char_u *)DFLT_VDIR, (char_u *)0L}
2734#else
2735 (char_u *)NULL, PV_NONE,
2736 {(char_u *)0L, (char_u *)0L}
2737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2740#ifdef FEAT_SESSION
2741 (char_u *)&p_vop, PV_NONE,
2742 {(char_u *)"folds,options,cursor", (char_u *)0L}
2743#else
2744 (char_u *)NULL, PV_NONE,
2745 {(char_u *)0L, (char_u *)0L}
2746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2749#ifdef FEAT_VIMINFO
2750 (char_u *)&p_viminfo, PV_NONE,
2751#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002752 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753#else
2754# ifdef AMIGA
2755 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002756 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002758 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759# endif
2760#endif
2761#else
2762 (char_u *)NULL, PV_NONE,
2763 {(char_u *)0L, (char_u *)0L}
2764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002765 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002766 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767#ifdef FEAT_VIRTUALEDIT
2768 (char_u *)&p_ve, PV_NONE,
2769 {(char_u *)"", (char_u *)""}
2770#else
2771 (char_u *)NULL, PV_NONE,
2772 {(char_u *)0L, (char_u *)0L}
2773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002774 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2776 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"w300", NULL, P_NUM|P_VI_DEF,
2779 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002780 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 {"w1200", NULL, P_NUM|P_VI_DEF,
2782 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"w9600", NULL, P_NUM|P_VI_DEF,
2785 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"warn", NULL, P_BOOL|P_VI_DEF,
2788 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002789 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2791 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002792 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2794 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 {"wildchar", "wc", P_NUM|P_VIM,
2797 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2799 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002800 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2804#ifdef FEAT_WILDIGN
2805 (char_u *)&p_wig, PV_NONE,
2806#else
2807 (char_u *)NULL, PV_NONE,
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002810 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2811 (char_u *)&p_wic, PV_NONE,
2812 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2814#ifdef FEAT_WILDMENU
2815 (char_u *)&p_wmnu, PV_NONE,
2816#else
2817 (char_u *)NULL, PV_NONE,
2818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2821 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002823 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2824#ifdef FEAT_CMDL_COMPL
2825 (char_u *)&p_wop, PV_NONE,
2826 {(char_u *)"", (char_u *)0L}
2827#else
2828 (char_u *)NULL, PV_NONE,
2829 {(char_u *)NULL, (char_u *)0L}
2830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2833#ifdef FEAT_WAK
2834 (char_u *)&p_wak, PV_NONE,
2835 {(char_u *)"menu", (char_u *)0L}
2836#else
2837 (char_u *)NULL, PV_NONE,
2838 {(char_u *)NULL, (char_u *)0L}
2839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002842 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"winheight", "wh", P_NUM|P_VI_DEF,
2845#ifdef FEAT_WINDOWS
2846 (char_u *)&p_wh, PV_NONE,
2847#else
2848 (char_u *)NULL, PV_NONE,
2849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002852#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 (char_u *)VAR_WIN, PV_WFH,
2854#else
2855 (char_u *)NULL, PV_NONE,
2856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002858 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2859#ifdef FEAT_VERTSPLIT
2860 (char_u *)VAR_WIN, PV_WFW,
2861#else
2862 (char_u *)NULL, PV_NONE,
2863#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002864 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2866#ifdef FEAT_WINDOWS
2867 (char_u *)&p_wmh, PV_NONE,
2868#else
2869 (char_u *)NULL, PV_NONE,
2870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002871 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2873#ifdef FEAT_VERTSPLIT
2874 (char_u *)&p_wmw, PV_NONE,
2875#else
2876 (char_u *)NULL, PV_NONE,
2877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2880#ifdef FEAT_VERTSPLIT
2881 (char_u *)&p_wiw, PV_NONE,
2882#else
2883 (char_u *)NULL, PV_NONE,
2884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002885 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2887 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2890 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2893 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002894 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895 {"write", NULL, P_BOOL|P_VI_DEF,
2896 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"writeany", "wa", P_BOOL|P_VI_DEF,
2899 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2902 (char_u *)&p_wb, PV_NONE,
2903 {
2904#ifdef FEAT_WRITEBACKUP
2905 (char_u *)TRUE,
2906#else
2907 (char_u *)FALSE,
2908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002909 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 {"writedelay", "wd", P_NUM|P_VI_DEF,
2911 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002912 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913
2914/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002915#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918
2919 p_term("t_AB", T_CAB)
2920 p_term("t_AF", T_CAF)
2921 p_term("t_AL", T_CAL)
2922 p_term("t_al", T_AL)
2923 p_term("t_bc", T_BC)
2924 p_term("t_cd", T_CD)
2925 p_term("t_ce", T_CE)
2926 p_term("t_cl", T_CL)
2927 p_term("t_cm", T_CM)
2928 p_term("t_Co", T_CCO)
2929 p_term("t_CS", T_CCS)
2930 p_term("t_cs", T_CS)
2931#ifdef FEAT_VERTSPLIT
2932 p_term("t_CV", T_CSV)
2933#endif
2934 p_term("t_ut", T_UT)
2935 p_term("t_da", T_DA)
2936 p_term("t_db", T_DB)
2937 p_term("t_DL", T_CDL)
2938 p_term("t_dl", T_DL)
2939 p_term("t_fs", T_FS)
2940 p_term("t_IE", T_CIE)
2941 p_term("t_IS", T_CIS)
2942 p_term("t_ke", T_KE)
2943 p_term("t_ks", T_KS)
2944 p_term("t_le", T_LE)
2945 p_term("t_mb", T_MB)
2946 p_term("t_md", T_MD)
2947 p_term("t_me", T_ME)
2948 p_term("t_mr", T_MR)
2949 p_term("t_ms", T_MS)
2950 p_term("t_nd", T_ND)
2951 p_term("t_op", T_OP)
2952 p_term("t_RI", T_CRI)
2953 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002954 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 p_term("t_Sb", T_CSB)
2956 p_term("t_Sf", T_CSF)
2957 p_term("t_se", T_SE)
2958 p_term("t_so", T_SO)
2959 p_term("t_sr", T_SR)
2960 p_term("t_ts", T_TS)
2961 p_term("t_te", T_TE)
2962 p_term("t_ti", T_TI)
2963 p_term("t_ue", T_UE)
2964 p_term("t_us", T_US)
2965 p_term("t_vb", T_VB)
2966 p_term("t_ve", T_VE)
2967 p_term("t_vi", T_VI)
2968 p_term("t_vs", T_VS)
2969 p_term("t_WP", T_CWP)
2970 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002971 p_term("t_SI", T_CSI)
2972 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973 p_term("t_xs", T_XS)
2974 p_term("t_ZH", T_CZH)
2975 p_term("t_ZR", T_CZR)
2976
2977/* terminal key codes are not in here */
2978
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002979 /* end marker */
2980 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981};
2982
2983#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2984
2985#ifdef FEAT_MBYTE
2986static char *(p_ambw_values[]) = {"single", "double", NULL};
2987#endif
2988static char *(p_bg_values[]) = {"light", "dark", NULL};
2989static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2990static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002991#ifdef FEAT_CRYPT
2992static char *(p_cm_values[]) = {"zip", "blowfish", NULL};
2993#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002994#ifdef FEAT_CMDL_COMPL
2995static char *(p_wop_values[]) = {"tagfile", NULL};
2996#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997#ifdef FEAT_WAK
2998static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2999#endif
3000static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3002static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004#ifdef FEAT_BROWSE
3005static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3006#endif
3007#ifdef FEAT_SCROLLBIND
3008static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3009#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003010static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011#ifdef FEAT_VERTSPLIT
3012static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3013#endif
3014#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003015# ifdef FEAT_AUTOCMD
3016static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3017# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003019# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3021#endif
3022static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3023#ifdef FEAT_FOLDING
3024static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003025# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003027# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 NULL};
3029static char *(p_fcl_values[]) = {"all", NULL};
3030#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003031#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003032static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003033#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034
3035static void set_option_default __ARGS((int, int opt_flags, int compatible));
3036static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003037static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003038static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039static char_u *illegal_char __ARGS((char_u *, int));
3040static int string_to_key __ARGS((char_u *arg));
3041#ifdef FEAT_CMDWIN
3042static char_u *check_cedit __ARGS((void));
3043#endif
3044#ifdef FEAT_TITLE
3045static void did_set_title __ARGS((int icon));
3046#endif
3047static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3048static void didset_options __ARGS((void));
3049static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003050#if defined(FEAT_EVAL) || defined(PROTO)
3051static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3052#else
3053# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3054#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003056static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
3058static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003059#ifdef FEAT_SYN_HL
3060static int int_cmp __ARGS((const void *a, const void *b));
3061#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062#ifdef FEAT_CLIPBOARD
3063static char_u *check_clipboard_option __ARGS((void));
3064#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003065#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003066static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003067#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003068#ifdef FEAT_EVAL
3069static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3070#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003072static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073static void check_redraw __ARGS((long_u flags));
3074static int findoption __ARGS((char_u *));
3075static int find_key_option __ARGS((char_u *));
3076static void showoptions __ARGS((int all, int opt_flags));
3077static int optval_default __ARGS((struct vimoption *, char_u *varp));
3078static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3079static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3080static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3081static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3082static int istermoption __ARGS((struct vimoption *));
3083static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3084static char_u *get_varp __ARGS((struct vimoption *));
3085static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003086static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3088#ifdef FEAT_LANGMAP
3089static void langmap_init __ARGS((void));
3090static void langmap_set __ARGS((void));
3091#endif
3092static void paste_option_changed __ARGS((void));
3093static void compatible_set __ARGS((void));
3094#ifdef FEAT_LINEBREAK
3095static void fill_breakat_flags __ARGS((void));
3096#endif
3097static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3098static int check_opt_strings __ARGS((char_u *val, char **values, int));
3099static int check_opt_wim __ARGS((void));
3100
3101/*
3102 * Initialize the options, first part.
3103 *
3104 * Called only once from main(), just after creating the first buffer.
3105 */
3106 void
3107set_init_1()
3108{
3109 char_u *p;
3110 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003111 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112
3113#ifdef FEAT_LANGMAP
3114 langmap_init();
3115#endif
3116
3117 /* Be Vi compatible by default */
3118 p_cp = TRUE;
3119
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003120 /* Use POSIX compatibility when $VIM_POSIX is set. */
3121 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003122 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003123 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003124 set_string_default("shm", (char_u *)"A");
3125 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003126
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 /*
3128 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003129 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003131 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3133# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003134 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003136 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003138 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139# endif
3140#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003141 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 set_string_default("sh", p);
3143
3144#ifdef FEAT_WILDIGN
3145 /*
3146 * Set the default for 'backupskip' to include environment variables for
3147 * temp files.
3148 */
3149 {
3150# ifdef UNIX
3151 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3152# else
3153 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3154# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003155 int len;
3156 garray_T ga;
3157 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158
3159 ga_init2(&ga, 1, 100);
3160 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3161 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003162 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163# ifdef UNIX
3164 if (*names[n] == NUL)
3165 p = (char_u *)"/tmp";
3166 else
3167# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003168 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 if (p != NULL && *p != NUL)
3170 {
3171 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003172 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 if (ga_grow(&ga, len) == OK)
3174 {
3175 if (ga.ga_len > 0)
3176 STRCAT(ga.ga_data, ",");
3177 STRCAT(ga.ga_data, p);
3178 add_pathsep(ga.ga_data);
3179 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 ga.ga_len += len;
3181 }
3182 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003183 if (mustfree)
3184 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 }
3186 if (ga.ga_data != NULL)
3187 {
3188 set_string_default("bsk", ga.ga_data);
3189 vim_free(ga.ga_data);
3190 }
3191 }
3192#endif
3193
3194 /*
3195 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3196 */
3197 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003198 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003200#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3201 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3202#endif
3203 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003205 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003206 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207#else
3208# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003209 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003210 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003212 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213# endif
3214#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003216 opt_idx = findoption((char_u *)"maxmem");
3217 if (opt_idx >= 0)
3218 {
3219#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003220 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003221 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3222#endif
3223 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3224 }
3225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 }
3227
3228#ifdef FEAT_GUI_W32
3229 /* force 'shortname' for Win32s */
3230 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003231 {
3232 opt_idx = findoption((char_u *)"shortname");
3233 if (opt_idx >= 0)
3234 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236#endif
3237
3238#ifdef FEAT_SEARCHPATH
3239 {
3240 char_u *cdpath;
3241 char_u *buf;
3242 int i;
3243 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003244 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245
3246 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003247 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248 if (cdpath != NULL)
3249 {
3250 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3251 if (buf != NULL)
3252 {
3253 buf[0] = ','; /* start with ",", current dir first */
3254 j = 1;
3255 for (i = 0; cdpath[i] != NUL; ++i)
3256 {
3257 if (vim_ispathlistsep(cdpath[i]))
3258 buf[j++] = ',';
3259 else
3260 {
3261 if (cdpath[i] == ' ' || cdpath[i] == ',')
3262 buf[j++] = '\\';
3263 buf[j++] = cdpath[i];
3264 }
3265 }
3266 buf[j] = NUL;
3267 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003268 if (opt_idx >= 0)
3269 {
3270 options[opt_idx].def_val[VI_DEFAULT] = buf;
3271 options[opt_idx].flags |= P_DEF_ALLOCED;
3272 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003273 else
3274 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003276 if (mustfree)
3277 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278 }
3279 }
3280#endif
3281
3282#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3283 /* Set print encoding on platforms that don't default to latin1 */
3284 set_string_default("penc",
3285# if defined(MSWIN) || defined(OS2)
3286 (char_u *)"cp1252"
3287# else
3288# ifdef VMS
3289 (char_u *)"dec-mcs"
3290# else
3291# ifdef EBCDIC
3292 (char_u *)"ebcdic-uk"
3293# else
3294# ifdef MAC
3295 (char_u *)"mac-roman"
3296# else /* HPUX */
3297 (char_u *)"hp-roman8"
3298# endif
3299# endif
3300# endif
3301# endif
3302 );
3303#endif
3304
3305#ifdef FEAT_POSTSCRIPT
3306 /* 'printexpr' must be allocated to be able to evaluate it. */
3307 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003308# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3309 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310# else
3311# ifdef VMS
3312 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3313
3314# else
3315 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3316# endif
3317# endif
3318 );
3319#endif
3320
3321 /*
3322 * Set all the options (except the terminal options) to their default
3323 * value. Also set the global value for local options.
3324 */
3325 set_options_default(0);
3326
3327#ifdef FEAT_GUI
3328 if (found_reverse_arg)
3329 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3330#endif
3331
3332 curbuf->b_p_initialized = TRUE;
3333 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003334 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335 check_buf_options(curbuf);
3336 check_win_options(curwin);
3337 check_options();
3338
3339 /* Must be before option_expand(), because that one needs vim_isIDc() */
3340 didset_options();
3341
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003342#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003343 /* Use the current chartab for the generic chartab. */
3344 init_spell_chartab();
3345#endif
3346
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347#ifdef FEAT_LINEBREAK
3348 /*
3349 * initialize the table for 'breakat'.
3350 */
3351 fill_breakat_flags();
3352#endif
3353
3354 /*
3355 * Expand environment variables and things like "~" for the defaults.
3356 * If option_expand() returns non-NULL the variable is expanded. This can
3357 * only happen for non-indirect options.
3358 * Also set the default to the expanded value, so ":set" does not list
3359 * them.
3360 * Don't set the P_ALLOCED flag, because we don't want to free the
3361 * default.
3362 */
3363 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3364 {
3365 if ((options[opt_idx].flags & P_GETTEXT)
3366 && options[opt_idx].var != NULL)
3367 p = (char_u *)_(*(char **)options[opt_idx].var);
3368 else
3369 p = option_expand(opt_idx, NULL);
3370 if (p != NULL && (p = vim_strsave(p)) != NULL)
3371 {
3372 *(char_u **)options[opt_idx].var = p;
3373 /* VIMEXP
3374 * Defaults for all expanded options are currently the same for Vi
3375 * and Vim. When this changes, add some code here! Also need to
3376 * split P_DEF_ALLOCED in two.
3377 */
3378 if (options[opt_idx].flags & P_DEF_ALLOCED)
3379 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3380 options[opt_idx].def_val[VI_DEFAULT] = p;
3381 options[opt_idx].flags |= P_DEF_ALLOCED;
3382 }
3383 }
3384
3385 /* Initialize the highlight_attr[] table. */
3386 highlight_changed();
3387
3388 save_file_ff(curbuf); /* Buffer is unchanged */
3389
3390 /* Parse default for 'wildmode' */
3391 check_opt_wim();
3392
3393#if defined(FEAT_ARABIC)
3394 /* Detect use of mlterm.
3395 * Mlterm is a terminal emulator akin to xterm that has some special
3396 * abilities (bidi namely).
3397 * NOTE: mlterm's author is being asked to 'set' a variable
3398 * instead of an environment variable due to inheritance.
3399 */
3400 if (mch_getenv((char_u *)"MLTERM") != NULL)
3401 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3402#endif
3403
3404#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3405 /* Parse default for 'fillchars'. */
3406 (void)set_chars_option(&p_fcs);
3407#endif
3408
3409#ifdef FEAT_CLIPBOARD
3410 /* Parse default for 'clipboard' */
3411 (void)check_clipboard_option();
3412#endif
3413
3414#ifdef FEAT_MBYTE
3415# if defined(WIN3264) && defined(FEAT_GETTEXT)
3416 /*
3417 * If $LANG isn't set, try to get a good value for it. This makes the
3418 * right language be used automatically. Don't do this for English.
3419 */
3420 if (mch_getenv((char_u *)"LANG") == NULL)
3421 {
3422 char buf[20];
3423
3424 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3425 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3426 * only the first two. */
3427 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3428 (LPTSTR)buf, 20);
3429 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3430 {
3431 /* There are a few exceptions (probably more) */
3432 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3433 STRCPY(buf, "zh_TW");
3434 else if (STRNICMP(buf, "chs", 3) == 0
3435 || STRNICMP(buf, "zhc", 3) == 0)
3436 STRCPY(buf, "zh_CN");
3437 else if (STRNICMP(buf, "jp", 2) == 0)
3438 STRCPY(buf, "ja");
3439 else
3440 buf[2] = NUL; /* truncate to two-letter code */
3441 vim_setenv("LANG", buf);
3442 }
3443 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003444# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003445# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003446 /* Moved to os_mac_conv.c to avoid dependency problems. */
3447 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003448# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449# endif
3450
3451 /* enc_locale() will try to find the encoding of the current locale. */
3452 p = enc_locale();
3453 if (p != NULL)
3454 {
3455 char_u *save_enc;
3456
3457 /* Try setting 'encoding' and check if the value is valid.
3458 * If not, go back to the default "latin1". */
3459 save_enc = p_enc;
3460 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003461 if (STRCMP(p_enc, "gb18030") == 0)
3462 {
3463 /* We don't support "gb18030", but "cp936" is a good substitute
3464 * for practical purposes, thus use that. It's not an alias to
3465 * still support conversion between gb18030 and utf-8. */
3466 p_enc = vim_strsave((char_u *)"cp936");
3467 vim_free(p);
3468 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 if (mb_init() == NULL)
3470 {
3471 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003472 if (opt_idx >= 0)
3473 {
3474 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3475 options[opt_idx].flags |= P_DEF_ALLOCED;
3476 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003478#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3479 || defined(VMS)
3480 if (STRCMP(p_enc, "latin1") == 0
3481# ifdef FEAT_MBYTE
3482 || enc_utf8
3483# endif
3484 )
3485 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003486 /* Adjust the default for 'isprint' and 'iskeyword' to match
3487 * latin1. Also set the defaults for when 'nocompatible' is
3488 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003489 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003490 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003491 set_string_option_direct((char_u *)"isk", -1,
3492 ISK_LATIN1, OPT_FREE, SID_NONE);
3493 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003494 if (opt_idx >= 0)
3495 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003496 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003497 if (opt_idx >= 0)
3498 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003499 (void)init_chartab();
3500 }
3501#endif
3502
Bram Moolenaar071d4272004-06-13 20:20:40 +00003503# if defined(WIN3264) && !defined(FEAT_GUI)
3504 /* Win32 console: When GetACP() returns a different value from
3505 * GetConsoleCP() set 'termencoding'. */
3506 if (GetACP() != GetConsoleCP())
3507 {
3508 char buf[50];
3509
3510 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3511 p_tenc = vim_strsave((char_u *)buf);
3512 if (p_tenc != NULL)
3513 {
3514 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003515 if (opt_idx >= 0)
3516 {
3517 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3518 options[opt_idx].flags |= P_DEF_ALLOCED;
3519 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003520 convert_setup(&input_conv, p_tenc, p_enc);
3521 convert_setup(&output_conv, p_enc, p_tenc);
3522 }
3523 else
3524 p_tenc = empty_option;
3525 }
3526# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003527# if defined(WIN3264) && defined(FEAT_MBYTE)
3528 /* $HOME may have characters in active code page. */
3529 init_homedir();
3530# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003531 }
3532 else
3533 {
3534 vim_free(p_enc);
3535 p_enc = save_enc;
3536 }
3537 }
3538#endif
3539
3540#ifdef FEAT_MULTI_LANG
3541 /* Set the default for 'helplang'. */
3542 set_helplang_default(get_mess_lang());
3543#endif
3544}
3545
3546/*
3547 * Set an option to its default value.
3548 * This does not take care of side effects!
3549 */
3550 static void
3551set_option_default(opt_idx, opt_flags, compatible)
3552 int opt_idx;
3553 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3554 int compatible; /* use Vi default value */
3555{
3556 char_u *varp; /* pointer to variable for current option */
3557 int dvi; /* index in def_val[] */
3558 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003559 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003560 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3561
3562 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3563 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003564 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565 {
3566 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3567 if (flags & P_STRING)
3568 {
3569 /* Use set_string_option_direct() for local options to handle
3570 * freeing and allocating the value. */
3571 if (options[opt_idx].indir != PV_NONE)
3572 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003573 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574 else
3575 {
3576 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3577 free_string_option(*(char_u **)(varp));
3578 *(char_u **)varp = options[opt_idx].def_val[dvi];
3579 options[opt_idx].flags &= ~P_ALLOCED;
3580 }
3581 }
3582 else if (flags & P_NUM)
3583 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003584 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585 win_comp_scroll(curwin);
3586 else
3587 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003588 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003589 /* May also set global value for local option. */
3590 if (both)
3591 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3592 *(long *)varp;
3593 }
3594 }
3595 else /* P_BOOL */
3596 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003597 /* the cast to long is required for Manx C, long_i is needed for
3598 * MSVC */
3599 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003600#ifdef UNIX
3601 /* 'modeline' defaults to off for root */
3602 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3603 *(int *)varp = FALSE;
3604#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605 /* May also set global value for local option. */
3606 if (both)
3607 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3608 *(int *)varp;
3609 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003610
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003611 /* The default value is not insecure. */
3612 flagsp = insecure_flag(opt_idx, opt_flags);
3613 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003614 }
3615
3616#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003617 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618#endif
3619}
3620
3621/*
3622 * Set all options (except terminal options) to their default value.
3623 */
3624 static void
3625set_options_default(opt_flags)
3626 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3627{
3628 int i;
3629#ifdef FEAT_WINDOWS
3630 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003631 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632#endif
3633
3634 for (i = 0; !istermoption(&options[i]); i++)
3635 if (!(options[i].flags & P_NODEFAULT))
3636 set_option_default(i, opt_flags, p_cp);
3637
3638#ifdef FEAT_WINDOWS
3639 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003640 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641 win_comp_scroll(wp);
3642#else
3643 win_comp_scroll(curwin);
3644#endif
3645}
3646
3647/*
3648 * Set the Vi-default value of a string option.
3649 * Used for 'sh', 'backupskip' and 'term'.
3650 */
3651 void
3652set_string_default(name, val)
3653 char *name;
3654 char_u *val;
3655{
3656 char_u *p;
3657 int opt_idx;
3658
3659 p = vim_strsave(val);
3660 if (p != NULL) /* we don't want a NULL */
3661 {
3662 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003663 if (opt_idx >= 0)
3664 {
3665 if (options[opt_idx].flags & P_DEF_ALLOCED)
3666 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3667 options[opt_idx].def_val[VI_DEFAULT] = p;
3668 options[opt_idx].flags |= P_DEF_ALLOCED;
3669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003670 }
3671}
3672
3673/*
3674 * Set the Vi-default value of a number option.
3675 * Used for 'lines' and 'columns'.
3676 */
3677 void
3678set_number_default(name, val)
3679 char *name;
3680 long val;
3681{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003682 int opt_idx;
3683
3684 opt_idx = findoption((char_u *)name);
3685 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003686 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687}
3688
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003689#if defined(EXITFREE) || defined(PROTO)
3690/*
3691 * Free all options.
3692 */
3693 void
3694free_all_options()
3695{
3696 int i;
3697
3698 for (i = 0; !istermoption(&options[i]); i++)
3699 {
3700 if (options[i].indir == PV_NONE)
3701 {
3702 /* global option: free value and default value. */
3703 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3704 free_string_option(*(char_u **)options[i].var);
3705 if (options[i].flags & P_DEF_ALLOCED)
3706 free_string_option(options[i].def_val[VI_DEFAULT]);
3707 }
3708 else if (options[i].var != VAR_WIN
3709 && (options[i].flags & P_STRING))
3710 /* buffer-local option: free global value */
3711 free_string_option(*(char_u **)options[i].var);
3712 }
3713}
3714#endif
3715
3716
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717/*
3718 * Initialize the options, part two: After getting Rows and Columns and
3719 * setting 'term'.
3720 */
3721 void
3722set_init_2()
3723{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003724 int idx;
3725
Bram Moolenaar071d4272004-06-13 20:20:40 +00003726 /*
3727 * 'scroll' defaults to half the window height. Note that this default is
3728 * wrong when the window height changes.
3729 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003730 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003731 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003732 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003733 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734 comp_col();
3735
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003736 /*
3737 * 'window' is only for backwards compatibility with Vi.
3738 * Default is Rows - 1.
3739 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003740 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003741 p_window = Rows - 1;
3742 set_number_default("window", Rows - 1);
3743
Bram Moolenaarf740b292006-02-16 22:11:02 +00003744 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003745#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003746 /*
3747 * If 'background' wasn't set by the user, try guessing the value,
3748 * depending on the terminal name. Only need to check for terminals
3749 * with a dark background, that can handle color.
3750 */
3751 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003752 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3753 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003754 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003755 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003756 /* don't mark it as set, when starting the GUI it may be
3757 * changed again */
3758 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759 }
3760#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003761
3762#ifdef CURSOR_SHAPE
3763 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3764#endif
3765#ifdef FEAT_MOUSESHAPE
3766 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3767#endif
3768#ifdef FEAT_PRINTER
3769 (void)parse_printoptions(); /* parse 'printoptions' default value */
3770#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771}
3772
3773/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003774 * Return "dark" or "light" depending on the kind of terminal.
3775 * This is just guessing! Recognized are:
3776 * "linux" Linux console
3777 * "screen.linux" Linux console with screen
3778 * "cygwin" Cygwin shell
3779 * "putty" Putty program
3780 * We also check the COLORFGBG environment variable, which is set by
3781 * rxvt and derivatives. This variable contains either two or three
3782 * values separated by semicolons; we want the last value in either
3783 * case. If this value is 0-6 or 8, our background is dark.
3784 */
3785 static char_u *
3786term_bg_default()
3787{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003788#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3789 /* DOS console nearly always black */
3790 return (char_u *)"dark";
3791#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003792 char_u *p;
3793
Bram Moolenaarf740b292006-02-16 22:11:02 +00003794 if (STRCMP(T_NAME, "linux") == 0
3795 || STRCMP(T_NAME, "screen.linux") == 0
3796 || STRCMP(T_NAME, "cygwin") == 0
3797 || STRCMP(T_NAME, "putty") == 0
3798 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3799 && (p = vim_strrchr(p, ';')) != NULL
3800 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3801 && p[2] == NUL))
3802 return (char_u *)"dark";
3803 return (char_u *)"light";
3804#endif
3805}
3806
3807/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 * Initialize the options, part three: After reading the .vimrc
3809 */
3810 void
3811set_init_3()
3812{
3813#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3814/*
3815 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3816 * This is done after other initializations, where 'shell' might have been
3817 * set, but only if they have not been set before.
3818 */
3819 char_u *p;
3820 int idx_srr;
3821 int do_srr;
3822#ifdef FEAT_QUICKFIX
3823 int idx_sp;
3824 int do_sp;
3825#endif
3826
3827 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003828 if (idx_srr < 0)
3829 do_srr = FALSE;
3830 else
3831 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003832#ifdef FEAT_QUICKFIX
3833 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003834 if (idx_sp < 0)
3835 do_sp = FALSE;
3836 else
3837 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003839 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003840 if (p != NULL)
3841 {
3842 /*
3843 * Default for p_sp is "| tee", for p_srr is ">".
3844 * For known shells it is changed here to include stderr.
3845 */
3846 if ( fnamecmp(p, "csh") == 0
3847 || fnamecmp(p, "tcsh") == 0
3848# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3849 || fnamecmp(p, "csh.exe") == 0
3850 || fnamecmp(p, "tcsh.exe") == 0
3851# endif
3852 )
3853 {
3854#if defined(FEAT_QUICKFIX)
3855 if (do_sp)
3856 {
3857# ifdef WIN3264
3858 p_sp = (char_u *)">&";
3859# else
3860 p_sp = (char_u *)"|& tee";
3861# endif
3862 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3863 }
3864#endif
3865 if (do_srr)
3866 {
3867 p_srr = (char_u *)">&";
3868 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3869 }
3870 }
3871 else
3872# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3873 if ( fnamecmp(p, "sh") == 0
3874 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003875 || fnamecmp(p, "mksh") == 0
3876 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003878 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003880 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003881# ifdef WIN3264
3882 || fnamecmp(p, "cmd") == 0
3883 || fnamecmp(p, "sh.exe") == 0
3884 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003885 || fnamecmp(p, "mksh.exe") == 0
3886 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003888 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889 || fnamecmp(p, "bash.exe") == 0
3890 || fnamecmp(p, "cmd.exe") == 0
3891# endif
3892 )
3893# endif
3894 {
3895#if defined(FEAT_QUICKFIX)
3896 if (do_sp)
3897 {
3898# ifdef WIN3264
3899 p_sp = (char_u *)">%s 2>&1";
3900# else
3901 p_sp = (char_u *)"2>&1| tee";
3902# endif
3903 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3904 }
3905#endif
3906 if (do_srr)
3907 {
3908 p_srr = (char_u *)">%s 2>&1";
3909 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3910 }
3911 }
3912 vim_free(p);
3913 }
3914#endif
3915
3916#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3917 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003918 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3919 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920 * This is done after other initializations, where 'shell' might have been
3921 * set, but only if they have not been set before. Default for p_shcf is
3922 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3923 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3924 * command.com. And for Win32 we need to set p_sxq instead.
3925 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003926 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003927 {
3928 int idx3;
3929
3930 idx3 = findoption((char_u *)"shcf");
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_shcf = (char_u *)"-c";
3934 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3935 }
3936
3937# ifndef DJGPP
3938# ifdef WIN3264
3939 /* Somehow Win32 requires the quotes around the redirection too */
3940 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003941 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 {
3943 p_sxq = (char_u *)"\"";
3944 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3945 }
3946# else
3947 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003948 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 {
3950 p_shq = (char_u *)"\"";
3951 options[idx3].def_val[VI_DEFAULT] = p_shq;
3952 }
3953# endif
3954# endif
3955 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003956 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3957 {
3958 int idx3;
3959
3960 /*
3961 * cmd.exe on Windows will strip the first and last double quote given
3962 * on the command line, e.g. most of the time things like:
3963 * cmd /c "my path/to/echo" "my args to echo"
3964 * become:
3965 * my path/to/echo" "my args to echo
3966 * when executed.
3967 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003968 * To avoid this, set shellxquote to surround the command in
3969 * parenthesis. This appears to make most commands work, without
3970 * breaking commands that worked previously, such as
3971 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003972 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003973 idx3 = findoption((char_u *)"sxq");
3974 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3975 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003976 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003977 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3978 }
3979
Bram Moolenaara64ba222012-02-12 23:23:31 +01003980 idx3 = findoption((char_u *)"shcf");
3981 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3982 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003983 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003984 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3985 }
3986 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987#endif
3988
3989#ifdef FEAT_TITLE
3990 set_title_defaults();
3991#endif
3992}
3993
3994#if defined(FEAT_MULTI_LANG) || defined(PROTO)
3995/*
3996 * When 'helplang' is still at its default value, set it to "lang".
3997 * Only the first two characters of "lang" are used.
3998 */
3999 void
4000set_helplang_default(lang)
4001 char_u *lang;
4002{
4003 int idx;
4004
4005 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4006 return;
4007 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004008 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009 {
4010 if (options[idx].flags & P_ALLOCED)
4011 free_string_option(p_hlg);
4012 p_hlg = vim_strsave(lang);
4013 if (p_hlg == NULL)
4014 p_hlg = empty_option;
4015 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004016 {
4017 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4018 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4019 {
4020 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4021 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4022 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004024 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004025 options[idx].flags |= P_ALLOCED;
4026 }
4027}
4028#endif
4029
4030#ifdef FEAT_GUI
4031static char_u *gui_bg_default __ARGS((void));
4032
4033 static char_u *
4034gui_bg_default()
4035{
4036 if (gui_get_lightness(gui.back_pixel) < 127)
4037 return (char_u *)"dark";
4038 return (char_u *)"light";
4039}
4040
4041/*
4042 * Option initializations that can only be done after opening the GUI window.
4043 */
4044 void
4045init_gui_options()
4046{
4047 /* Set the 'background' option according to the lightness of the
4048 * background color, unless the user has set it already. */
4049 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4050 {
4051 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4052 highlight_changed();
4053 }
4054}
4055#endif
4056
4057#ifdef FEAT_TITLE
4058/*
4059 * 'title' and 'icon' only default to true if they have not been set or reset
4060 * in .vimrc and we can read the old value.
4061 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4062 * they can be reset. This reduces startup time when using X on a remote
4063 * machine.
4064 */
4065 void
4066set_title_defaults()
4067{
4068 int idx1;
4069 long val;
4070
4071 /*
4072 * If GUI is (going to be) used, we can always set the window title and
4073 * icon name. Saves a bit of time, because the X11 display server does
4074 * not need to be contacted.
4075 */
4076 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004077 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 {
4079#ifdef FEAT_GUI
4080 if (gui.starting || gui.in_use)
4081 val = TRUE;
4082 else
4083#endif
4084 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004085 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 p_title = val;
4087 }
4088 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004089 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 {
4091#ifdef FEAT_GUI
4092 if (gui.starting || gui.in_use)
4093 val = TRUE;
4094 else
4095#endif
4096 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004097 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 p_icon = val;
4099 }
4100}
4101#endif
4102
4103/*
4104 * Parse 'arg' for option settings.
4105 *
4106 * 'arg' may be IObuff, but only when no errors can be present and option
4107 * does not need to be expanded with option_expand().
4108 * "opt_flags":
4109 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004110 * OPT_GLOBAL for ":setglobal"
4111 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004113 * OPT_WINONLY to only set window-local options
4114 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 *
4116 * returns FAIL if an error is detected, OK otherwise
4117 */
4118 int
4119do_set(arg, opt_flags)
4120 char_u *arg; /* option string (may be written to!) */
4121 int opt_flags;
4122{
4123 int opt_idx;
4124 char_u *errmsg;
4125 char_u errbuf[80];
4126 char_u *startarg;
4127 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4128 int nextchar; /* next non-white char after option name */
4129 int afterchar; /* character just after option name */
4130 int len;
4131 int i;
4132 long value;
4133 int key;
4134 long_u flags; /* flags for current option */
4135 char_u *varp = NULL; /* pointer to variable for current option */
4136 int did_show = FALSE; /* already showed one value */
4137 int adding; /* "opt+=arg" */
4138 int prepending; /* "opt^=arg" */
4139 int removing; /* "opt-=arg" */
4140 int cp_val = 0;
4141 char_u key_name[2];
4142
4143 if (*arg == NUL)
4144 {
4145 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004146 did_show = TRUE;
4147 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 }
4149
4150 while (*arg != NUL) /* loop to process all options */
4151 {
4152 errmsg = NULL;
4153 startarg = arg; /* remember for error message */
4154
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004155 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4156 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 {
4158 /*
4159 * ":set all" show all options.
4160 * ":set all&" set all options to their default value.
4161 */
4162 arg += 3;
4163 if (*arg == '&')
4164 {
4165 ++arg;
4166 /* Only for :set command set global value of local options. */
4167 set_options_default(OPT_FREE | opt_flags);
4168 }
4169 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004170 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004172 did_show = TRUE;
4173 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004175 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004176 {
4177 showoptions(2, opt_flags);
4178 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004179 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180 arg += 7;
4181 }
4182 else
4183 {
4184 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004185 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186 {
4187 prefix = 0;
4188 arg += 2;
4189 }
4190 else if (STRNCMP(arg, "inv", 3) == 0)
4191 {
4192 prefix = 2;
4193 arg += 3;
4194 }
4195
4196 /* find end of name */
4197 key = 0;
4198 if (*arg == '<')
4199 {
4200 nextchar = 0;
4201 opt_idx = -1;
4202 /* look out for <t_>;> */
4203 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4204 len = 5;
4205 else
4206 {
4207 len = 1;
4208 while (arg[len] != NUL && arg[len] != '>')
4209 ++len;
4210 }
4211 if (arg[len] != '>')
4212 {
4213 errmsg = e_invarg;
4214 goto skip;
4215 }
4216 arg[len] = NUL; /* put NUL after name */
4217 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4218 opt_idx = findoption(arg + 1);
4219 arg[len++] = '>'; /* restore '>' */
4220 if (opt_idx == -1)
4221 key = find_key_option(arg + 1);
4222 }
4223 else
4224 {
4225 len = 0;
4226 /*
4227 * The two characters after "t_" may not be alphanumeric.
4228 */
4229 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4230 len = 4;
4231 else
4232 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4233 ++len;
4234 nextchar = arg[len];
4235 arg[len] = NUL; /* put NUL after name */
4236 opt_idx = findoption(arg);
4237 arg[len] = nextchar; /* restore nextchar */
4238 if (opt_idx == -1)
4239 key = find_key_option(arg);
4240 }
4241
4242 /* remember character after option name */
4243 afterchar = arg[len];
4244
4245 /* skip white space, allow ":set ai ?" */
4246 while (vim_iswhite(arg[len]))
4247 ++len;
4248
4249 adding = FALSE;
4250 prepending = FALSE;
4251 removing = FALSE;
4252 if (arg[len] != NUL && arg[len + 1] == '=')
4253 {
4254 if (arg[len] == '+')
4255 {
4256 adding = TRUE; /* "+=" */
4257 ++len;
4258 }
4259 else if (arg[len] == '^')
4260 {
4261 prepending = TRUE; /* "^=" */
4262 ++len;
4263 }
4264 else if (arg[len] == '-')
4265 {
4266 removing = TRUE; /* "-=" */
4267 ++len;
4268 }
4269 }
4270 nextchar = arg[len];
4271
4272 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4273 {
4274 errmsg = (char_u *)N_("E518: Unknown option");
4275 goto skip;
4276 }
4277
4278 if (opt_idx >= 0)
4279 {
4280 if (options[opt_idx].var == NULL) /* hidden option: skip */
4281 {
4282 /* Only give an error message when requesting the value of
4283 * a hidden option, ignore setting it. */
4284 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4285 && (!(options[opt_idx].flags & P_BOOL)
4286 || nextchar == '?'))
4287 errmsg = (char_u *)N_("E519: Option not supported");
4288 goto skip;
4289 }
4290
4291 flags = options[opt_idx].flags;
4292 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4293 }
4294 else
4295 {
4296 flags = P_STRING;
4297 if (key < 0)
4298 {
4299 key_name[0] = KEY2TERMCAP0(key);
4300 key_name[1] = KEY2TERMCAP1(key);
4301 }
4302 else
4303 {
4304 key_name[0] = KS_KEY;
4305 key_name[1] = (key & 0xff);
4306 }
4307 }
4308
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004309 /* Skip all options that are not window-local (used when showing
4310 * an already loaded buffer in a window). */
4311 if ((opt_flags & OPT_WINONLY)
4312 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4313 goto skip;
4314
Bram Moolenaara3227e22006-03-08 21:32:40 +00004315 /* Skip all options that are window-local (used for :vimgrep). */
4316 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4317 && options[opt_idx].var == VAR_WIN)
4318 goto skip;
4319
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004320 /* Disallow changing some options from modelines. */
4321 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004322 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004323 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004324 {
4325 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4326 goto skip;
4327 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004328#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004329 /* In diff mode some options are overruled. This avoids that
4330 * 'foldmethod' becomes "marker" instead of "diff" and that
4331 * "wrap" gets set. */
4332 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004333 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004334 && (options[opt_idx].indir == PV_FDM
4335 || options[opt_idx].indir == PV_WRAP))
4336 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004337#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004338 }
4339
4340#ifdef HAVE_SANDBOX
4341 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004342 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004343 {
4344 errmsg = (char_u *)_(e_sandbox);
4345 goto skip;
4346 }
4347#endif
4348
4349 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4350 {
4351 arg += len;
4352 cp_val = p_cp;
4353 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4354 {
4355 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4356 {
4357 cp_val = FALSE;
4358 arg += 3;
4359 }
4360 else /* "opt&vi": set to Vi default */
4361 {
4362 cp_val = TRUE;
4363 arg += 2;
4364 }
4365 }
4366 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4367 && arg[1] != NUL && !vim_iswhite(arg[1]))
4368 {
4369 errmsg = e_trailing;
4370 goto skip;
4371 }
4372 }
4373
4374 /*
4375 * allow '=' and ':' as MSDOS command.com allows only one
4376 * '=' character per "set" command line. grrr. (jw)
4377 */
4378 if (nextchar == '?'
4379 || (prefix == 1
4380 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4381 && !(flags & P_BOOL)))
4382 {
4383 /*
4384 * print value
4385 */
4386 if (did_show)
4387 msg_putchar('\n'); /* cursor below last one */
4388 else
4389 {
4390 gotocmdline(TRUE); /* cursor at status line */
4391 did_show = TRUE; /* remember that we did a line */
4392 }
4393 if (opt_idx >= 0)
4394 {
4395 showoneopt(&options[opt_idx], opt_flags);
4396#ifdef FEAT_EVAL
4397 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004398 {
4399 /* Mention where the option was last set. */
4400 if (varp == options[opt_idx].var)
4401 last_set_msg(options[opt_idx].scriptID);
4402 else if ((int)options[opt_idx].indir & PV_WIN)
4403 last_set_msg(curwin->w_p_scriptID[
4404 (int)options[opt_idx].indir & PV_MASK]);
4405 else if ((int)options[opt_idx].indir & PV_BUF)
4406 last_set_msg(curbuf->b_p_scriptID[
4407 (int)options[opt_idx].indir & PV_MASK]);
4408 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004409#endif
4410 }
4411 else
4412 {
4413 char_u *p;
4414
4415 p = find_termcode(key_name);
4416 if (p == NULL)
4417 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004418 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004419 goto skip;
4420 }
4421 else
4422 (void)show_one_termcode(key_name, p, TRUE);
4423 }
4424 if (nextchar != '?'
4425 && nextchar != NUL && !vim_iswhite(afterchar))
4426 errmsg = e_trailing;
4427 }
4428 else
4429 {
4430 if (flags & P_BOOL) /* boolean */
4431 {
4432 if (nextchar == '=' || nextchar == ':')
4433 {
4434 errmsg = e_invarg;
4435 goto skip;
4436 }
4437
4438 /*
4439 * ":set opt!": invert
4440 * ":set opt&": reset to default value
4441 * ":set opt<": reset to global value
4442 */
4443 if (nextchar == '!')
4444 value = *(int *)(varp) ^ 1;
4445 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004446 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004447 ((flags & P_VI_DEF) || cp_val)
4448 ? VI_DEFAULT : VIM_DEFAULT];
4449 else if (nextchar == '<')
4450 {
4451 /* For 'autoread' -1 means to use global value. */
4452 if ((int *)varp == &curbuf->b_p_ar
4453 && opt_flags == OPT_LOCAL)
4454 value = -1;
4455 else
4456 value = *(int *)get_varp_scope(&(options[opt_idx]),
4457 OPT_GLOBAL);
4458 }
4459 else
4460 {
4461 /*
4462 * ":set invopt": invert
4463 * ":set opt" or ":set noopt": set or reset
4464 */
4465 if (nextchar != NUL && !vim_iswhite(afterchar))
4466 {
4467 errmsg = e_trailing;
4468 goto skip;
4469 }
4470 if (prefix == 2) /* inv */
4471 value = *(int *)(varp) ^ 1;
4472 else
4473 value = prefix;
4474 }
4475
4476 errmsg = set_bool_option(opt_idx, varp, (int)value,
4477 opt_flags);
4478 }
4479 else /* numeric or string */
4480 {
4481 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4482 || prefix != 1)
4483 {
4484 errmsg = e_invarg;
4485 goto skip;
4486 }
4487
4488 if (flags & P_NUM) /* numeric */
4489 {
4490 /*
4491 * Different ways to set a number option:
4492 * & set to default value
4493 * < set to global value
4494 * <xx> accept special key codes for 'wildchar'
4495 * c accept any non-digit for 'wildchar'
4496 * [-]0-9 set number
4497 * other error
4498 */
4499 ++arg;
4500 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004501 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004502 ((flags & P_VI_DEF) || cp_val)
4503 ? VI_DEFAULT : VIM_DEFAULT];
4504 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004505 {
4506 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4507 * use the global value. */
4508 if ((long *)varp == &curbuf->b_p_ul
4509 && opt_flags == OPT_LOCAL)
4510 value = NO_LOCAL_UNDOLEVEL;
4511 else
4512 value = *(long *)get_varp_scope(
4513 &(options[opt_idx]), OPT_GLOBAL);
4514 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004515 else if (((long *)varp == &p_wc
4516 || (long *)varp == &p_wcm)
4517 && (*arg == '<'
4518 || *arg == '^'
4519 || ((!arg[1] || vim_iswhite(arg[1]))
4520 && !VIM_ISDIGIT(*arg))))
4521 {
4522 value = string_to_key(arg);
4523 if (value == 0 && (long *)varp != &p_wcm)
4524 {
4525 errmsg = e_invarg;
4526 goto skip;
4527 }
4528 }
4529 /* allow negative numbers (for 'undolevels') */
4530 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4531 {
4532 i = 0;
4533 if (*arg == '-')
4534 i = 1;
4535#ifdef HAVE_STRTOL
4536 value = strtol((char *)arg, NULL, 0);
4537 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4538 i += 2;
4539#else
4540 value = atol((char *)arg);
4541#endif
4542 while (VIM_ISDIGIT(arg[i]))
4543 ++i;
4544 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4545 {
4546 errmsg = e_invarg;
4547 goto skip;
4548 }
4549 }
4550 else
4551 {
4552 errmsg = (char_u *)N_("E521: Number required after =");
4553 goto skip;
4554 }
4555
4556 if (adding)
4557 value = *(long *)varp + value;
4558 if (prepending)
4559 value = *(long *)varp * value;
4560 if (removing)
4561 value = *(long *)varp - value;
4562 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004563 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004564 }
4565 else if (opt_idx >= 0) /* string */
4566 {
4567 char_u *save_arg = NULL;
4568 char_u *s = NULL;
4569 char_u *oldval; /* previous value if *varp */
4570 char_u *newval;
4571 char_u *origval;
4572 unsigned newlen;
4573 int comma;
4574 int bs;
4575 int new_value_alloced; /* new string option
4576 was allocated */
4577
4578 /* When using ":set opt=val" for a global option
4579 * with a local value the local value will be
4580 * reset, use the global value here. */
4581 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004582 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004583 varp = options[opt_idx].var;
4584
4585 /* The old value is kept until we are sure that the
4586 * new value is valid. */
4587 oldval = *(char_u **)varp;
4588 if (nextchar == '&') /* set to default val */
4589 {
4590 newval = options[opt_idx].def_val[
4591 ((flags & P_VI_DEF) || cp_val)
4592 ? VI_DEFAULT : VIM_DEFAULT];
4593 if ((char_u **)varp == &p_bg)
4594 {
4595 /* guess the value of 'background' */
4596#ifdef FEAT_GUI
4597 if (gui.in_use)
4598 newval = gui_bg_default();
4599 else
4600#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004601 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004602 }
4603
4604 /* expand environment variables and ~ (since the
4605 * default value was already expanded, only
4606 * required when an environment variable was set
4607 * later */
4608 if (newval == NULL)
4609 newval = empty_option;
4610 else
4611 {
4612 s = option_expand(opt_idx, newval);
4613 if (s == NULL)
4614 s = newval;
4615 newval = vim_strsave(s);
4616 }
4617 new_value_alloced = TRUE;
4618 }
4619 else if (nextchar == '<') /* set to global val */
4620 {
4621 newval = vim_strsave(*(char_u **)get_varp_scope(
4622 &(options[opt_idx]), OPT_GLOBAL));
4623 new_value_alloced = TRUE;
4624 }
4625 else
4626 {
4627 ++arg; /* jump to after the '=' or ':' */
4628
4629 /*
4630 * Set 'keywordprg' to ":help" if an empty
4631 * value was passed to :set by the user.
4632 * Misuse errbuf[] for the resulting string.
4633 */
4634 if (varp == (char_u *)&p_kp
4635 && (*arg == NUL || *arg == ' '))
4636 {
4637 STRCPY(errbuf, ":help");
4638 save_arg = arg;
4639 arg = errbuf;
4640 }
4641 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004642 * Convert 'backspace' number to string, for
4643 * adding, prepending and removing string.
4644 */
4645 else if (varp == (char_u *)&p_bs
4646 && VIM_ISDIGIT(**(char_u **)varp))
4647 {
4648 i = getdigits((char_u **)varp);
4649 switch (i)
4650 {
4651 case 0:
4652 *(char_u **)varp = empty_option;
4653 break;
4654 case 1:
4655 *(char_u **)varp = vim_strsave(
4656 (char_u *)"indent,eol");
4657 break;
4658 case 2:
4659 *(char_u **)varp = vim_strsave(
4660 (char_u *)"indent,eol,start");
4661 break;
4662 }
4663 vim_free(oldval);
4664 oldval = *(char_u **)varp;
4665 }
4666 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004667 * Convert 'whichwrap' number to string, for
4668 * backwards compatibility with Vim 3.0.
4669 * Misuse errbuf[] for the resulting string.
4670 */
4671 else if (varp == (char_u *)&p_ww
4672 && VIM_ISDIGIT(*arg))
4673 {
4674 *errbuf = NUL;
4675 i = getdigits(&arg);
4676 if (i & 1)
4677 STRCAT(errbuf, "b,");
4678 if (i & 2)
4679 STRCAT(errbuf, "s,");
4680 if (i & 4)
4681 STRCAT(errbuf, "h,l,");
4682 if (i & 8)
4683 STRCAT(errbuf, "<,>,");
4684 if (i & 16)
4685 STRCAT(errbuf, "[,],");
4686 if (*errbuf != NUL) /* remove trailing , */
4687 errbuf[STRLEN(errbuf) - 1] = NUL;
4688 save_arg = arg;
4689 arg = errbuf;
4690 }
4691 /*
4692 * Remove '>' before 'dir' and 'bdir', for
4693 * backwards compatibility with version 3.0
4694 */
4695 else if ( *arg == '>'
4696 && (varp == (char_u *)&p_dir
4697 || varp == (char_u *)&p_bdir))
4698 {
4699 ++arg;
4700 }
4701
4702 /* When setting the local value of a global
4703 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004704 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004705 && (opt_flags & OPT_LOCAL))
4706 origval = *(char_u **)get_varp(
4707 &options[opt_idx]);
4708 else
4709 origval = oldval;
4710
4711 /*
4712 * Copy the new string into allocated memory.
4713 * Can't use set_string_option_direct(), because
4714 * we need to remove the backslashes.
4715 */
4716 /* get a bit too much */
4717 newlen = (unsigned)STRLEN(arg) + 1;
4718 if (adding || prepending || removing)
4719 newlen += (unsigned)STRLEN(origval) + 1;
4720 newval = alloc(newlen);
4721 if (newval == NULL) /* out of mem, don't change */
4722 break;
4723 s = newval;
4724
4725 /*
4726 * Copy the string, skip over escaped chars.
4727 * For MS-DOS and WIN32 backslashes before normal
4728 * file name characters are not removed, and keep
4729 * backslash at start, for "\\machine\path", but
4730 * do remove it for "\\\\machine\\path".
4731 * The reverse is found in ExpandOldSetting().
4732 */
4733 while (*arg && !vim_iswhite(*arg))
4734 {
4735 if (*arg == '\\' && arg[1] != NUL
4736#ifdef BACKSLASH_IN_FILENAME
4737 && !((flags & P_EXPAND)
4738 && vim_isfilec(arg[1])
4739 && (arg[1] != '\\'
4740 || (s == newval
4741 && arg[2] != '\\')))
4742#endif
4743 )
4744 ++arg; /* remove backslash */
4745#ifdef FEAT_MBYTE
4746 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004747 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004748 {
4749 /* copy multibyte char */
4750 mch_memmove(s, arg, (size_t)i);
4751 arg += i;
4752 s += i;
4753 }
4754 else
4755#endif
4756 *s++ = *arg++;
4757 }
4758 *s = NUL;
4759
4760 /*
4761 * Expand environment variables and ~.
4762 * Don't do it when adding without inserting a
4763 * comma.
4764 */
4765 if (!(adding || prepending || removing)
4766 || (flags & P_COMMA))
4767 {
4768 s = option_expand(opt_idx, newval);
4769 if (s != NULL)
4770 {
4771 vim_free(newval);
4772 newlen = (unsigned)STRLEN(s) + 1;
4773 if (adding || prepending || removing)
4774 newlen += (unsigned)STRLEN(origval) + 1;
4775 newval = alloc(newlen);
4776 if (newval == NULL)
4777 break;
4778 STRCPY(newval, s);
4779 }
4780 }
4781
4782 /* locate newval[] in origval[] when removing it
4783 * and when adding to avoid duplicates */
4784 i = 0; /* init for GCC */
4785 if (removing || (flags & P_NODUP))
4786 {
4787 i = (int)STRLEN(newval);
4788 bs = 0;
4789 for (s = origval; *s; ++s)
4790 {
4791 if ((!(flags & P_COMMA)
4792 || s == origval
4793 || (s[-1] == ',' && !(bs & 1)))
4794 && STRNCMP(s, newval, i) == 0
4795 && (!(flags & P_COMMA)
4796 || s[i] == ','
4797 || s[i] == NUL))
4798 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004799 /* Count backslashes. Only a comma with an
4800 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004801 * recognized as a separator */
4802 if (s > origval && s[-1] == '\\')
4803 ++bs;
4804 else
4805 bs = 0;
4806 }
4807
4808 /* do not add if already there */
4809 if ((adding || prepending) && *s)
4810 {
4811 prepending = FALSE;
4812 adding = FALSE;
4813 STRCPY(newval, origval);
4814 }
4815 }
4816
4817 /* concatenate the two strings; add a ',' if
4818 * needed */
4819 if (adding || prepending)
4820 {
4821 comma = ((flags & P_COMMA) && *origval != NUL
4822 && *newval != NUL);
4823 if (adding)
4824 {
4825 i = (int)STRLEN(origval);
4826 mch_memmove(newval + i + comma, newval,
4827 STRLEN(newval) + 1);
4828 mch_memmove(newval, origval, (size_t)i);
4829 }
4830 else
4831 {
4832 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004833 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004834 }
4835 if (comma)
4836 newval[i] = ',';
4837 }
4838
4839 /* Remove newval[] from origval[]. (Note: "i" has
4840 * been set above and is used here). */
4841 if (removing)
4842 {
4843 STRCPY(newval, origval);
4844 if (*s)
4845 {
4846 /* may need to remove a comma */
4847 if (flags & P_COMMA)
4848 {
4849 if (s == origval)
4850 {
4851 /* include comma after string */
4852 if (s[i] == ',')
4853 ++i;
4854 }
4855 else
4856 {
4857 /* include comma before string */
4858 --s;
4859 ++i;
4860 }
4861 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004862 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004863 }
4864 }
4865
4866 if (flags & P_FLAGLIST)
4867 {
4868 /* Remove flags that appear twice. */
4869 for (s = newval; *s; ++s)
4870 if ((!(flags & P_COMMA) || *s != ',')
4871 && vim_strchr(s + 1, *s) != NULL)
4872 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004873 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004874 --s;
4875 }
4876 }
4877
4878 if (save_arg != NULL) /* number for 'whichwrap' */
4879 arg = save_arg;
4880 new_value_alloced = TRUE;
4881 }
4882
4883 /* Set the new value. */
4884 *(char_u **)(varp) = newval;
4885
4886 /* Handle side effects, and set the global value for
4887 * ":set" on local options. */
4888 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4889 new_value_alloced, oldval, errbuf, opt_flags);
4890
4891 /* If error detected, print the error message. */
4892 if (errmsg != NULL)
4893 goto skip;
4894 }
4895 else /* key code option */
4896 {
4897 char_u *p;
4898
4899 if (nextchar == '&')
4900 {
4901 if (add_termcap_entry(key_name, TRUE) == FAIL)
4902 errmsg = (char_u *)N_("E522: Not found in termcap");
4903 }
4904 else
4905 {
4906 ++arg; /* jump to after the '=' or ':' */
4907 for (p = arg; *p && !vim_iswhite(*p); ++p)
4908 if (*p == '\\' && p[1] != NUL)
4909 ++p;
4910 nextchar = *p;
4911 *p = NUL;
4912 add_termcode(key_name, arg, FALSE);
4913 *p = nextchar;
4914 }
4915 if (full_screen)
4916 ttest(FALSE);
4917 redraw_all_later(CLEAR);
4918 }
4919 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004920
Bram Moolenaar071d4272004-06-13 20:20:40 +00004921 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004922 did_set_option(opt_idx, opt_flags,
4923 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004924 }
4925
4926skip:
4927 /*
4928 * Advance to next argument.
4929 * - skip until a blank found, taking care of backslashes
4930 * - skip blanks
4931 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4932 */
4933 for (i = 0; i < 2 ; ++i)
4934 {
4935 while (*arg != NUL && !vim_iswhite(*arg))
4936 if (*arg++ == '\\' && *arg != NUL)
4937 ++arg;
4938 arg = skipwhite(arg);
4939 if (*arg != '=')
4940 break;
4941 }
4942 }
4943
4944 if (errmsg != NULL)
4945 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004946 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004947 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004948 if (i + (arg - startarg) < IOSIZE)
4949 {
4950 /* append the argument with the error */
4951 STRCAT(IObuff, ": ");
4952 mch_memmove(IObuff + i, startarg, (arg - startarg));
4953 IObuff[i + (arg - startarg)] = NUL;
4954 }
4955 /* make sure all characters are printable */
4956 trans_characters(IObuff, IOSIZE);
4957
4958 ++no_wait_return; /* wait_return done later */
4959 emsg(IObuff); /* show error highlighted */
4960 --no_wait_return;
4961
4962 return FAIL;
4963 }
4964
4965 arg = skipwhite(arg);
4966 }
4967
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004968theend:
4969 if (silent_mode && did_show)
4970 {
4971 /* After displaying option values in silent mode. */
4972 silent_mode = FALSE;
4973 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4974 msg_putchar('\n');
4975 cursor_on(); /* msg_start() switches it off */
4976 out_flush();
4977 silent_mode = TRUE;
4978 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4979 }
4980
Bram Moolenaar071d4272004-06-13 20:20:40 +00004981 return OK;
4982}
4983
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004984/*
4985 * Call this when an option has been given a new value through a user command.
4986 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4987 */
4988 static void
4989did_set_option(opt_idx, opt_flags, new_value)
4990 int opt_idx;
4991 int opt_flags; /* possibly with OPT_MODELINE */
4992 int new_value; /* value was replaced completely */
4993{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004994 long_u *p;
4995
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004996 options[opt_idx].flags |= P_WAS_SET;
4997
4998 /* When an option is set in the sandbox, from a modeline or in secure mode
4999 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005000 * flag. */
5001 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005002 if (secure
5003#ifdef HAVE_SANDBOX
5004 || sandbox != 0
5005#endif
5006 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005007 *p = *p | P_INSECURE;
5008 else if (new_value)
5009 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005010}
5011
Bram Moolenaar071d4272004-06-13 20:20:40 +00005012 static char_u *
5013illegal_char(errbuf, c)
5014 char_u *errbuf;
5015 int c;
5016{
5017 if (errbuf == NULL)
5018 return (char_u *)"";
5019 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005020 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005021 return errbuf;
5022}
5023
5024/*
5025 * Convert a key name or string into a key value.
5026 * Used for 'wildchar' and 'cedit' options.
5027 */
5028 static int
5029string_to_key(arg)
5030 char_u *arg;
5031{
5032 if (*arg == '<')
5033 return find_key_option(arg + 1);
5034 if (*arg == '^')
5035 return Ctrl_chr(arg[1]);
5036 return *arg;
5037}
5038
5039#ifdef FEAT_CMDWIN
5040/*
5041 * Check value of 'cedit' and set cedit_key.
5042 * Returns NULL if value is OK, error message otherwise.
5043 */
5044 static char_u *
5045check_cedit()
5046{
5047 int n;
5048
5049 if (*p_cedit == NUL)
5050 cedit_key = -1;
5051 else
5052 {
5053 n = string_to_key(p_cedit);
5054 if (vim_isprintc(n))
5055 return e_invarg;
5056 cedit_key = n;
5057 }
5058 return NULL;
5059}
5060#endif
5061
5062#ifdef FEAT_TITLE
5063/*
5064 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5065 * maketitle() to create and display it.
5066 * When switching the title or icon off, call mch_restore_title() to get
5067 * the old value back.
5068 */
5069 static void
5070did_set_title(icon)
5071 int icon; /* Did set icon instead of title */
5072{
5073 if (starting != NO_SCREEN
5074#ifdef FEAT_GUI
5075 && !gui.starting
5076#endif
5077 )
5078 {
5079 maketitle();
5080 if (icon)
5081 {
5082 if (!p_icon)
5083 mch_restore_title(2);
5084 }
5085 else
5086 {
5087 if (!p_title)
5088 mch_restore_title(1);
5089 }
5090 }
5091}
5092#endif
5093
5094/*
5095 * set_options_bin - called when 'bin' changes value.
5096 */
5097 void
5098set_options_bin(oldval, newval, opt_flags)
5099 int oldval;
5100 int newval;
5101 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5102{
5103 /*
5104 * The option values that are changed when 'bin' changes are
5105 * copied when 'bin is set and restored when 'bin' is reset.
5106 */
5107 if (newval)
5108 {
5109 if (!oldval) /* switched on */
5110 {
5111 if (!(opt_flags & OPT_GLOBAL))
5112 {
5113 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5114 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5115 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5116 curbuf->b_p_et_nobin = curbuf->b_p_et;
5117 }
5118 if (!(opt_flags & OPT_LOCAL))
5119 {
5120 p_tw_nobin = p_tw;
5121 p_wm_nobin = p_wm;
5122 p_ml_nobin = p_ml;
5123 p_et_nobin = p_et;
5124 }
5125 }
5126
5127 if (!(opt_flags & OPT_GLOBAL))
5128 {
5129 curbuf->b_p_tw = 0; /* no automatic line wrap */
5130 curbuf->b_p_wm = 0; /* no automatic line wrap */
5131 curbuf->b_p_ml = 0; /* no modelines */
5132 curbuf->b_p_et = 0; /* no expandtab */
5133 }
5134 if (!(opt_flags & OPT_LOCAL))
5135 {
5136 p_tw = 0;
5137 p_wm = 0;
5138 p_ml = FALSE;
5139 p_et = FALSE;
5140 p_bin = TRUE; /* needed when called for the "-b" argument */
5141 }
5142 }
5143 else if (oldval) /* switched off */
5144 {
5145 if (!(opt_flags & OPT_GLOBAL))
5146 {
5147 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5148 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5149 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5150 curbuf->b_p_et = curbuf->b_p_et_nobin;
5151 }
5152 if (!(opt_flags & OPT_LOCAL))
5153 {
5154 p_tw = p_tw_nobin;
5155 p_wm = p_wm_nobin;
5156 p_ml = p_ml_nobin;
5157 p_et = p_et_nobin;
5158 }
5159 }
5160}
5161
5162#ifdef FEAT_VIMINFO
5163/*
5164 * Find the parameter represented by the given character (eg ', :, ", or /),
5165 * and return its associated value in the 'viminfo' string.
5166 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005167 * If the parameter is not specified in the string or there is no following
5168 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005169 */
5170 int
5171get_viminfo_parameter(type)
5172 int type;
5173{
5174 char_u *p;
5175
5176 p = find_viminfo_parameter(type);
5177 if (p != NULL && VIM_ISDIGIT(*p))
5178 return atoi((char *)p);
5179 return -1;
5180}
5181
5182/*
5183 * Find the parameter represented by the given character (eg ''', ':', '"', or
5184 * '/') in the 'viminfo' option and return a pointer to the string after it.
5185 * Return NULL if the parameter is not specified in the string.
5186 */
5187 char_u *
5188find_viminfo_parameter(type)
5189 int type;
5190{
5191 char_u *p;
5192
5193 for (p = p_viminfo; *p; ++p)
5194 {
5195 if (*p == type)
5196 return p + 1;
5197 if (*p == 'n') /* 'n' is always the last one */
5198 break;
5199 p = vim_strchr(p, ','); /* skip until next ',' */
5200 if (p == NULL) /* hit the end without finding parameter */
5201 break;
5202 }
5203 return NULL;
5204}
5205#endif
5206
5207/*
5208 * Expand environment variables for some string options.
5209 * These string options cannot be indirect!
5210 * If "val" is NULL expand the current value of the option.
5211 * Return pointer to NameBuff, or NULL when not expanded.
5212 */
5213 static char_u *
5214option_expand(opt_idx, val)
5215 int opt_idx;
5216 char_u *val;
5217{
5218 /* if option doesn't need expansion nothing to do */
5219 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5220 return NULL;
5221
5222 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5223 * expand_env() would truncate the string. */
5224 if (val != NULL && STRLEN(val) > MAXPATHL)
5225 return NULL;
5226
5227 if (val == NULL)
5228 val = *(char_u **)options[opt_idx].var;
5229
5230 /*
5231 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5232 * Escape spaces when expanding 'tags', they are used to separate file
5233 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005234 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005235 */
5236 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005237 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005238#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005239 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5240#endif
5241 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5243 return NULL;
5244
5245 return NameBuff;
5246}
5247
5248/*
5249 * After setting various option values: recompute variables that depend on
5250 * option values.
5251 */
5252 static void
5253didset_options()
5254{
5255 /* initialize the table for 'iskeyword' et.al. */
5256 (void)init_chartab();
5257
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005258#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005259 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005260#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005261 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5262#ifdef FEAT_SESSION
5263 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5264 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5265#endif
5266#ifdef FEAT_FOLDING
5267 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5268#endif
5269 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5270#ifdef FEAT_VIRTUALEDIT
5271 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5272#endif
5273#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5274 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5275#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005276#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005277 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005278 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005279 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005280#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005281#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5282 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5283#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005284#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5286#endif
5287#ifdef FEAT_CMDWIN
5288 /* set cedit_key */
5289 (void)check_cedit();
5290#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005291#ifdef FEAT_LINEBREAK
5292 briopt_check();
5293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005294}
5295
5296/*
5297 * Check for string options that are NULL (normally only termcap options).
5298 */
5299 void
5300check_options()
5301{
5302 int opt_idx;
5303
5304 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5305 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5306 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5307}
5308
5309/*
5310 * Check string options in a buffer for NULL value.
5311 */
5312 void
5313check_buf_options(buf)
5314 buf_T *buf;
5315{
5316#if defined(FEAT_QUICKFIX)
5317 check_string_option(&buf->b_p_bh);
5318 check_string_option(&buf->b_p_bt);
5319#endif
5320#ifdef FEAT_MBYTE
5321 check_string_option(&buf->b_p_fenc);
5322#endif
5323 check_string_option(&buf->b_p_ff);
5324#ifdef FEAT_FIND_ID
5325 check_string_option(&buf->b_p_def);
5326 check_string_option(&buf->b_p_inc);
5327# ifdef FEAT_EVAL
5328 check_string_option(&buf->b_p_inex);
5329# endif
5330#endif
5331#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5332 check_string_option(&buf->b_p_inde);
5333 check_string_option(&buf->b_p_indk);
5334#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005335#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5336 check_string_option(&buf->b_p_bexpr);
5337#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005338#if defined(FEAT_CRYPT)
5339 check_string_option(&buf->b_p_cm);
5340#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005341#if defined(FEAT_EVAL)
5342 check_string_option(&buf->b_p_fex);
5343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005344#ifdef FEAT_CRYPT
5345 check_string_option(&buf->b_p_key);
5346#endif
5347 check_string_option(&buf->b_p_kp);
5348 check_string_option(&buf->b_p_mps);
5349 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005350 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351 check_string_option(&buf->b_p_isk);
5352#ifdef FEAT_COMMENTS
5353 check_string_option(&buf->b_p_com);
5354#endif
5355#ifdef FEAT_FOLDING
5356 check_string_option(&buf->b_p_cms);
5357#endif
5358 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005359#ifdef FEAT_TEXTOBJ
5360 check_string_option(&buf->b_p_qe);
5361#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362#ifdef FEAT_SYN_HL
5363 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005364#endif
5365#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005366 check_string_option(&buf->b_s.b_p_spc);
5367 check_string_option(&buf->b_s.b_p_spf);
5368 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369#endif
5370#ifdef FEAT_SEARCHPATH
5371 check_string_option(&buf->b_p_sua);
5372#endif
5373#ifdef FEAT_CINDENT
5374 check_string_option(&buf->b_p_cink);
5375 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005376 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005377#endif
5378#ifdef FEAT_AUTOCMD
5379 check_string_option(&buf->b_p_ft);
5380#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005381#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5382 check_string_option(&buf->b_p_cinw);
5383#endif
5384#ifdef FEAT_INS_EXPAND
5385 check_string_option(&buf->b_p_cpt);
5386#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005387#ifdef FEAT_COMPL_FUNC
5388 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005389 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005391#ifdef FEAT_KEYMAP
5392 check_string_option(&buf->b_p_keymap);
5393#endif
5394#ifdef FEAT_QUICKFIX
5395 check_string_option(&buf->b_p_gp);
5396 check_string_option(&buf->b_p_mp);
5397 check_string_option(&buf->b_p_efm);
5398#endif
5399 check_string_option(&buf->b_p_ep);
5400 check_string_option(&buf->b_p_path);
5401 check_string_option(&buf->b_p_tags);
5402#ifdef FEAT_INS_EXPAND
5403 check_string_option(&buf->b_p_dict);
5404 check_string_option(&buf->b_p_tsr);
5405#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005406#ifdef FEAT_LISP
5407 check_string_option(&buf->b_p_lw);
5408#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005409}
5410
5411/*
5412 * Free the string allocated for an option.
5413 * Checks for the string being empty_option. This may happen if we're out of
5414 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5415 * check_options().
5416 * Does NOT check for P_ALLOCED flag!
5417 */
5418 void
5419free_string_option(p)
5420 char_u *p;
5421{
5422 if (p != empty_option)
5423 vim_free(p);
5424}
5425
5426 void
5427clear_string_option(pp)
5428 char_u **pp;
5429{
5430 if (*pp != empty_option)
5431 vim_free(*pp);
5432 *pp = empty_option;
5433}
5434
5435 static void
5436check_string_option(pp)
5437 char_u **pp;
5438{
5439 if (*pp == NULL)
5440 *pp = empty_option;
5441}
5442
5443/*
5444 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5445 */
5446 void
5447set_term_option_alloced(p)
5448 char_u **p;
5449{
5450 int opt_idx;
5451
5452 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5453 if (options[opt_idx].var == (char_u *)p)
5454 {
5455 options[opt_idx].flags |= P_ALLOCED;
5456 return;
5457 }
5458 return; /* cannot happen: didn't find it! */
5459}
5460
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005461#if defined(FEAT_EVAL) || defined(PROTO)
5462/*
5463 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5464 * Return FALSE when it wasn't.
5465 * Return -1 for an unknown option.
5466 */
5467 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005468was_set_insecurely(opt, opt_flags)
5469 char_u *opt;
5470 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005471{
5472 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005473 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005474
5475 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005476 {
5477 flagp = insecure_flag(idx, opt_flags);
5478 return (*flagp & P_INSECURE) != 0;
5479 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005480 EMSG2(_(e_intern2), "was_set_insecurely()");
5481 return -1;
5482}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005483
5484/*
5485 * Get a pointer to the flags used for the P_INSECURE flag of option
5486 * "opt_idx". For some local options a local flags field is used.
5487 */
5488 static long_u *
5489insecure_flag(opt_idx, opt_flags)
5490 int opt_idx;
5491 int opt_flags;
5492{
5493 if (opt_flags & OPT_LOCAL)
5494 switch ((int)options[opt_idx].indir)
5495 {
5496#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005497 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005498#endif
5499#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005500# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005501 case PV_FDE: return &curwin->w_p_fde_flags;
5502 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005503# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005504# ifdef FEAT_BEVAL
5505 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5506# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005507# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005508 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005509# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005510 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005511# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005512 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005513# endif
5514#endif
5515 }
5516
5517 /* Nothing special, return global flags field. */
5518 return &options[opt_idx].flags;
5519}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005520#endif
5521
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005522#ifdef FEAT_TITLE
5523static void redraw_titles __ARGS((void));
5524
5525/*
5526 * Redraw the window title and/or tab page text later.
5527 */
5528static void redraw_titles()
5529{
5530 need_maketitle = TRUE;
5531# ifdef FEAT_WINDOWS
5532 redraw_tabline = TRUE;
5533# endif
5534}
5535#endif
5536
Bram Moolenaar071d4272004-06-13 20:20:40 +00005537/*
5538 * Set a string option to a new value (without checking the effect).
5539 * The string is copied into allocated memory.
5540 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005541 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005542 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005543 */
5544 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005545set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546 char_u *name;
5547 int opt_idx;
5548 char_u *val;
5549 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005550 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551{
5552 char_u *s;
5553 char_u **varp;
5554 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005555 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005556
Bram Moolenaar89d40322006-08-29 15:30:07 +00005557 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005559 idx = findoption(name);
5560 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005561 {
5562 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005563 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005564 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005565 }
5566
Bram Moolenaar89d40322006-08-29 15:30:07 +00005567 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568 return;
5569
5570 s = vim_strsave(val);
5571 if (s != NULL)
5572 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005573 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005574 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005575 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005576 free_string_option(*varp);
5577 *varp = s;
5578
5579 /* For buffer/window local option may also set the global value. */
5580 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005581 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582
Bram Moolenaar89d40322006-08-29 15:30:07 +00005583 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584
5585 /* When setting both values of a global option with a local value,
5586 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005587 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588 {
5589 free_string_option(*varp);
5590 *varp = empty_option;
5591 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005592# ifdef FEAT_EVAL
5593 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005594 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005595 set_sid == 0 ? current_SID : set_sid);
5596# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005597 }
5598}
5599
5600/*
5601 * Set global value for string option when it's a local option.
5602 */
5603 static void
5604set_string_option_global(opt_idx, varp)
5605 int opt_idx; /* option index */
5606 char_u **varp; /* pointer to option variable */
5607{
5608 char_u **p, *s;
5609
5610 /* the global value is always allocated */
5611 if (options[opt_idx].var == VAR_WIN)
5612 p = (char_u **)GLOBAL_WO(varp);
5613 else
5614 p = (char_u **)options[opt_idx].var;
5615 if (options[opt_idx].indir != PV_NONE
5616 && p != varp
5617 && (s = vim_strsave(*varp)) != NULL)
5618 {
5619 free_string_option(*p);
5620 *p = s;
5621 }
5622}
5623
5624/*
5625 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005626 *
5627 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005628 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005629 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005630set_string_option(opt_idx, value, opt_flags)
5631 int opt_idx;
5632 char_u *value;
5633 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5634{
5635 char_u *s;
5636 char_u **varp;
5637 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005638 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639
5640 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005641 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005642
5643 s = vim_strsave(value);
5644 if (s != NULL)
5645 {
5646 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5647 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005648 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649 ? OPT_GLOBAL : OPT_LOCAL)
5650 : opt_flags);
5651 oldval = *varp;
5652 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005653 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5654 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005655 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005656 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005657 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005658}
5659
5660/*
5661 * Handle string options that need some action to perform when changed.
5662 * Returns NULL for success, or an error message for an error.
5663 */
5664 static char_u *
5665did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5666 opt_flags)
5667 int opt_idx; /* index in options[] table */
5668 char_u **varp; /* pointer to the option variable */
5669 int new_value_alloced; /* new value was allocated */
5670 char_u *oldval; /* previous value of the option */
5671 char_u *errbuf; /* buffer for errors, or NULL */
5672 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5673{
5674 char_u *errmsg = NULL;
5675 char_u *s, *p;
5676 int did_chartab = FALSE;
5677 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005678 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005679#ifdef FEAT_GUI
5680 /* set when changing an option that only requires a redraw in the GUI */
5681 int redraw_gui_only = FALSE;
5682#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683
5684 /* Get the global option to compare with, otherwise we would have to check
5685 * two values for all local options. */
5686 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5687
5688 /* Disallow changing some options from secure mode */
5689 if ((secure
5690#ifdef HAVE_SANDBOX
5691 || sandbox != 0
5692#endif
5693 ) && (options[opt_idx].flags & P_SECURE))
5694 {
5695 errmsg = e_secure;
5696 }
5697
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005698 /* Check for a "normal" file name in some options. Disallow a path
5699 * separator (slash and/or backslash), wildcards and characters that are
5700 * often illegal in a file name. */
5701 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005702 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005703 {
5704 errmsg = e_invarg;
5705 }
5706
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707 /* 'term' */
5708 else if (varp == &T_NAME)
5709 {
5710 if (T_NAME[0] == NUL)
5711 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5712#ifdef FEAT_GUI
5713 if (gui.in_use)
5714 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5715 else if (term_is_gui(T_NAME))
5716 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5717#endif
5718 else if (set_termname(T_NAME) == FAIL)
5719 errmsg = (char_u *)N_("E522: Not found in termcap");
5720 else
5721 /* Screen colors may have changed. */
5722 redraw_later_clear();
5723 }
5724
5725 /* 'backupcopy' */
5726 else if (varp == &p_bkc)
5727 {
5728 if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
5729 errmsg = e_invarg;
5730 if (((bkc_flags & BKC_AUTO) != 0)
5731 + ((bkc_flags & BKC_YES) != 0)
5732 + ((bkc_flags & BKC_NO) != 0) != 1)
5733 {
5734 /* Must have exactly one of "auto", "yes" and "no". */
5735 (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
5736 errmsg = e_invarg;
5737 }
5738 }
5739
5740 /* 'backupext' and 'patchmode' */
5741 else if (varp == &p_bex || varp == &p_pm)
5742 {
5743 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5744 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5745 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5746 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005747#ifdef FEAT_LINEBREAK
5748 /* 'breakindentopt' */
5749 else if (varp == &curwin->w_p_briopt)
5750 {
5751 if (briopt_check() == FAIL)
5752 errmsg = e_invarg;
5753 }
5754#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005755
5756 /*
5757 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5758 * If the new option is invalid, use old value. 'lisp' option: refill
5759 * chartab[] for '-' char
5760 */
5761 else if ( varp == &p_isi
5762 || varp == &(curbuf->b_p_isk)
5763 || varp == &p_isp
5764 || varp == &p_isf)
5765 {
5766 if (init_chartab() == FAIL)
5767 {
5768 did_chartab = TRUE; /* need to restore it below */
5769 errmsg = e_invarg; /* error in value */
5770 }
5771 }
5772
5773 /* 'helpfile' */
5774 else if (varp == &p_hf)
5775 {
5776 /* May compute new values for $VIM and $VIMRUNTIME */
5777 if (didset_vim)
5778 {
5779 vim_setenv((char_u *)"VIM", (char_u *)"");
5780 didset_vim = FALSE;
5781 }
5782 if (didset_vimruntime)
5783 {
5784 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5785 didset_vimruntime = FALSE;
5786 }
5787 }
5788
Bram Moolenaar1a384422010-07-14 19:53:30 +02005789#ifdef FEAT_SYN_HL
5790 /* 'colorcolumn' */
5791 else if (varp == &curwin->w_p_cc)
5792 errmsg = check_colorcolumn(curwin);
5793#endif
5794
Bram Moolenaar071d4272004-06-13 20:20:40 +00005795#ifdef FEAT_MULTI_LANG
5796 /* 'helplang' */
5797 else if (varp == &p_hlg)
5798 {
5799 /* Check for "", "ab", "ab,cd", etc. */
5800 for (s = p_hlg; *s != NUL; s += 3)
5801 {
5802 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5803 {
5804 errmsg = e_invarg;
5805 break;
5806 }
5807 if (s[2] == NUL)
5808 break;
5809 }
5810 }
5811#endif
5812
5813 /* 'highlight' */
5814 else if (varp == &p_hl)
5815 {
5816 if (highlight_changed() == FAIL)
5817 errmsg = e_invarg; /* invalid flags */
5818 }
5819
5820 /* 'nrformats' */
5821 else if (gvarp == &p_nf)
5822 {
5823 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5824 errmsg = e_invarg;
5825 }
5826
5827#ifdef FEAT_SESSION
5828 /* 'sessionoptions' */
5829 else if (varp == &p_ssop)
5830 {
5831 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5832 errmsg = e_invarg;
5833 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5834 {
5835 /* Don't allow both "sesdir" and "curdir". */
5836 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5837 errmsg = e_invarg;
5838 }
5839 }
5840 /* 'viewoptions' */
5841 else if (varp == &p_vop)
5842 {
5843 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5844 errmsg = e_invarg;
5845 }
5846#endif
5847
5848 /* 'scrollopt' */
5849#ifdef FEAT_SCROLLBIND
5850 else if (varp == &p_sbo)
5851 {
5852 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5853 errmsg = e_invarg;
5854 }
5855#endif
5856
5857 /* 'ambiwidth' */
5858#ifdef FEAT_MBYTE
5859 else if (varp == &p_ambw)
5860 {
5861 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5862 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005863 else if (set_chars_option(&p_lcs) != NULL)
5864 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5865# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5866 else if (set_chars_option(&p_fcs) != NULL)
5867 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5868# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869 }
5870#endif
5871
5872 /* 'background' */
5873 else if (varp == &p_bg)
5874 {
5875 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5876 {
5877#ifdef FEAT_EVAL
5878 int dark = (*p_bg == 'd');
5879#endif
5880
5881 init_highlight(FALSE, FALSE);
5882
5883#ifdef FEAT_EVAL
5884 if (dark != (*p_bg == 'd')
5885 && get_var_value((char_u *)"g:colors_name") != NULL)
5886 {
5887 /* The color scheme must have set 'background' back to another
5888 * value, that's not what we want here. Disable the color
5889 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005890 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891 free_string_option(p_bg);
5892 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5893 check_string_option(&p_bg);
5894 init_highlight(FALSE, FALSE);
5895 }
5896#endif
5897 }
5898 else
5899 errmsg = e_invarg;
5900 }
5901
5902 /* 'wildmode' */
5903 else if (varp == &p_wim)
5904 {
5905 if (check_opt_wim() == FAIL)
5906 errmsg = e_invarg;
5907 }
5908
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005909#ifdef FEAT_CMDL_COMPL
5910 /* 'wildoptions' */
5911 else if (varp == &p_wop)
5912 {
5913 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5914 errmsg = e_invarg;
5915 }
5916#endif
5917
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918#ifdef FEAT_WAK
5919 /* 'winaltkeys' */
5920 else if (varp == &p_wak)
5921 {
5922 if (*p_wak == NUL
5923 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5924 errmsg = e_invarg;
5925# ifdef FEAT_MENU
5926# ifdef FEAT_GUI_MOTIF
5927 else if (gui.in_use)
5928 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5929# else
5930# ifdef FEAT_GUI_GTK
5931 else if (gui.in_use)
5932 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5933# endif
5934# endif
5935# endif
5936 }
5937#endif
5938
5939#ifdef FEAT_AUTOCMD
5940 /* 'eventignore' */
5941 else if (varp == &p_ei)
5942 {
5943 if (check_ei() == FAIL)
5944 errmsg = e_invarg;
5945 }
5946#endif
5947
5948#ifdef FEAT_MBYTE
5949 /* 'encoding' and 'fileencoding' */
5950 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5951 {
5952 if (gvarp == &p_fenc)
5953 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005954 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005955 errmsg = e_modifiable;
5956 else if (vim_strchr(*varp, ',') != NULL)
5957 /* No comma allowed in 'fileencoding'; catches confusing it
5958 * with 'fileencodings'. */
5959 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005960 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005961 {
5962# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005964 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005966 /* Add 'fileencoding' to the swap file. */
5967 ml_setflags(curbuf);
5968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969 }
5970 if (errmsg == NULL)
5971 {
5972 /* canonize the value, so that STRCMP() can be used on it */
5973 p = enc_canonize(*varp);
5974 if (p != NULL)
5975 {
5976 vim_free(*varp);
5977 *varp = p;
5978 }
5979 if (varp == &p_enc)
5980 {
5981 errmsg = mb_init();
5982# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005983 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984# endif
5985 }
5986 }
5987
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005988# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005989 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
5990 {
5991 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
5992 if (STRCMP(p_tenc, "utf-8") != 0)
5993 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
5994 }
5995# endif
5996
5997 if (errmsg == NULL)
5998 {
5999# ifdef FEAT_KEYMAP
6000 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6001 * (with another encoding). */
6002 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6003 (void)keymap_init();
6004# endif
6005
6006 /* When 'termencoding' is not empty and 'encoding' changes or when
6007 * 'termencoding' changes, need to setup for keyboard input and
6008 * display output conversion. */
6009 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6010 {
6011 convert_setup(&input_conv, p_tenc, p_enc);
6012 convert_setup(&output_conv, p_enc, p_tenc);
6013 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006014
6015# if defined(WIN3264) && defined(FEAT_MBYTE)
6016 /* $HOME may have characters in active code page. */
6017 if (varp == &p_enc)
6018 init_homedir();
6019# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006020 }
6021 }
6022#endif
6023
6024#if defined(FEAT_POSTSCRIPT)
6025 else if (varp == &p_penc)
6026 {
6027 /* Canonize printencoding if VIM standard one */
6028 p = enc_canonize(p_penc);
6029 if (p != NULL)
6030 {
6031 vim_free(p_penc);
6032 p_penc = p;
6033 }
6034 else
6035 {
6036 /* Ensure lower case and '-' for '_' */
6037 for (s = p_penc; *s != NUL; s++)
6038 {
6039 if (*s == '_')
6040 *s = '-';
6041 else
6042 *s = TOLOWER_ASC(*s);
6043 }
6044 }
6045 }
6046#endif
6047
Bram Moolenaar9372a112005-12-06 19:59:18 +00006048#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006049 else if (varp == &p_imak)
6050 {
6051 if (gui.in_use && !im_xim_isvalid_imactivate())
6052 errmsg = e_invarg;
6053 }
6054#endif
6055
6056#ifdef FEAT_KEYMAP
6057 else if (varp == &curbuf->b_p_keymap)
6058 {
6059 /* load or unload key mapping tables */
6060 errmsg = keymap_init();
6061
Bram Moolenaarfab06232009-03-04 03:13:35 +00006062 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006063 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006064 if (*curbuf->b_p_keymap != NUL)
6065 {
6066 /* Installed a new keymap, switch on using it. */
6067 curbuf->b_p_iminsert = B_IMODE_LMAP;
6068 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6069 curbuf->b_p_imsearch = B_IMODE_LMAP;
6070 }
6071 else
6072 {
6073 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6074 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6075 curbuf->b_p_iminsert = B_IMODE_NONE;
6076 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6077 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6078 }
6079 if ((opt_flags & OPT_LOCAL) == 0)
6080 {
6081 set_iminsert_global();
6082 set_imsearch_global();
6083 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006084# ifdef FEAT_WINDOWS
6085 status_redraw_curbuf();
6086# endif
6087 }
6088 }
6089#endif
6090
6091 /* 'fileformat' */
6092 else if (gvarp == &p_ff)
6093 {
6094 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6095 errmsg = e_modifiable;
6096 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6097 errmsg = e_invarg;
6098 else
6099 {
6100 /* may also change 'textmode' */
6101 if (get_fileformat(curbuf) == EOL_DOS)
6102 curbuf->b_p_tx = TRUE;
6103 else
6104 curbuf->b_p_tx = FALSE;
6105#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006106 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006108 /* update flag in swap file */
6109 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006110 /* Redraw needed when switching to/from "mac": a CR in the text
6111 * will be displayed differently. */
6112 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6113 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006114 }
6115 }
6116
6117 /* 'fileformats' */
6118 else if (varp == &p_ffs)
6119 {
6120 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6121 errmsg = e_invarg;
6122 else
6123 {
6124 /* also change 'textauto' */
6125 if (*p_ffs == NUL)
6126 p_ta = FALSE;
6127 else
6128 p_ta = TRUE;
6129 }
6130 }
6131
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006132#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006133 /* 'cryptkey' */
6134 else if (gvarp == &p_key)
6135 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006136# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 /* Make sure the ":set" command doesn't show the new value in the
6138 * history. */
6139 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006140# endif
6141 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6142 /* Need to update the swapfile. */
Bram Moolenaar49771f42010-07-20 17:32:38 +02006143 ml_set_crypt_key(curbuf, oldval, get_crypt_method(curbuf));
6144 }
6145
6146 else if (gvarp == &p_cm)
6147 {
6148 if (opt_flags & OPT_LOCAL)
6149 p = curbuf->b_p_cm;
6150 else
6151 p = p_cm;
6152 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6153 errmsg = e_invarg;
6154 else if (get_crypt_method(curbuf) > 0 && blowfish_self_test() == FAIL)
6155 errmsg = e_invarg;
6156 else
6157 {
6158 /* When setting the global value to empty, make it "zip". */
6159 if (*p_cm == NUL)
6160 {
6161 if (new_value_alloced)
6162 free_string_option(p_cm);
6163 p_cm = vim_strsave((char_u *)"zip");
6164 new_value_alloced = TRUE;
6165 }
6166
6167 /* Need to update the swapfile when the effective method changed.
6168 * Set "s" to the effective old value, "p" to the effective new
6169 * method and compare. */
6170 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6171 s = p_cm; /* was previously using the global value */
6172 else
6173 s = oldval;
6174 if (*curbuf->b_p_cm == NUL)
6175 p = p_cm; /* is now using the global value */
6176 else
6177 p = curbuf->b_p_cm;
6178 if (STRCMP(s, p) != 0)
6179 ml_set_crypt_key(curbuf, curbuf->b_p_key,
6180 crypt_method_from_string(s));
6181
6182 /* If the global value changes need to update the swapfile for all
6183 * buffers using that value. */
6184 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6185 {
6186 buf_T *buf;
6187
6188 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6189 if (buf != curbuf && *buf->b_p_cm == NUL)
6190 ml_set_crypt_key(buf, buf->b_p_key,
6191 crypt_method_from_string(oldval));
6192 }
6193 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006194 }
6195#endif
6196
6197 /* 'matchpairs' */
6198 else if (gvarp == &p_mps)
6199 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006200#ifdef FEAT_MBYTE
6201 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006202 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006203 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006204 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006205 int x2 = -1;
6206 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006207
6208 if (*p != NUL)
6209 p += mb_ptr2len(p);
6210 if (*p != NUL)
6211 x2 = *p++;
6212 if (*p != NUL)
6213 {
6214 x3 = mb_ptr2char(p);
6215 p += mb_ptr2len(p);
6216 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006217 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006218 {
6219 errmsg = e_invarg;
6220 break;
6221 }
6222 if (*p == NUL)
6223 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006224 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006225 }
6226 else
6227#endif
6228 {
6229 /* Check for "x:y,x:y" */
6230 for (p = *varp; *p != NUL; p += 4)
6231 {
6232 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6233 {
6234 errmsg = e_invarg;
6235 break;
6236 }
6237 if (p[3] == NUL)
6238 break;
6239 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240 }
6241 }
6242
6243#ifdef FEAT_COMMENTS
6244 /* 'comments' */
6245 else if (gvarp == &p_com)
6246 {
6247 for (s = *varp; *s; )
6248 {
6249 while (*s && *s != ':')
6250 {
6251 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6252 && !VIM_ISDIGIT(*s) && *s != '-')
6253 {
6254 errmsg = illegal_char(errbuf, *s);
6255 break;
6256 }
6257 ++s;
6258 }
6259 if (*s++ == NUL)
6260 errmsg = (char_u *)N_("E524: Missing colon");
6261 else if (*s == ',' || *s == NUL)
6262 errmsg = (char_u *)N_("E525: Zero length string");
6263 if (errmsg != NULL)
6264 break;
6265 while (*s && *s != ',')
6266 {
6267 if (*s == '\\' && s[1] != NUL)
6268 ++s;
6269 ++s;
6270 }
6271 s = skip_to_option_part(s);
6272 }
6273 }
6274#endif
6275
6276 /* 'listchars' */
6277 else if (varp == &p_lcs)
6278 {
6279 errmsg = set_chars_option(varp);
6280 }
6281
6282#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6283 /* 'fillchars' */
6284 else if (varp == &p_fcs)
6285 {
6286 errmsg = set_chars_option(varp);
6287 }
6288#endif
6289
6290#ifdef FEAT_CMDWIN
6291 /* 'cedit' */
6292 else if (varp == &p_cedit)
6293 {
6294 errmsg = check_cedit();
6295 }
6296#endif
6297
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006298 /* 'verbosefile' */
6299 else if (varp == &p_vfile)
6300 {
6301 verbose_stop();
6302 if (*p_vfile != NUL && verbose_open() == FAIL)
6303 errmsg = e_invarg;
6304 }
6305
Bram Moolenaar071d4272004-06-13 20:20:40 +00006306#ifdef FEAT_VIMINFO
6307 /* 'viminfo' */
6308 else if (varp == &p_viminfo)
6309 {
6310 for (s = p_viminfo; *s;)
6311 {
6312 /* Check it's a valid character */
6313 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6314 {
6315 errmsg = illegal_char(errbuf, *s);
6316 break;
6317 }
6318 if (*s == 'n') /* name is always last one */
6319 {
6320 break;
6321 }
6322 else if (*s == 'r') /* skip until next ',' */
6323 {
6324 while (*++s && *s != ',')
6325 ;
6326 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006327 else if (*s == '%')
6328 {
6329 /* optional number */
6330 while (vim_isdigit(*++s))
6331 ;
6332 }
6333 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006334 ++s; /* no extra chars */
6335 else /* must have a number */
6336 {
6337 while (vim_isdigit(*++s))
6338 ;
6339
6340 if (!VIM_ISDIGIT(*(s - 1)))
6341 {
6342 if (errbuf != NULL)
6343 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006344 sprintf((char *)errbuf,
6345 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006346 transchar_byte(*(s - 1)));
6347 errmsg = errbuf;
6348 }
6349 else
6350 errmsg = (char_u *)"";
6351 break;
6352 }
6353 }
6354 if (*s == ',')
6355 ++s;
6356 else if (*s)
6357 {
6358 if (errbuf != NULL)
6359 errmsg = (char_u *)N_("E527: Missing comma");
6360 else
6361 errmsg = (char_u *)"";
6362 break;
6363 }
6364 }
6365 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6366 errmsg = (char_u *)N_("E528: Must specify a ' value");
6367 }
6368#endif /* FEAT_VIMINFO */
6369
6370 /* terminal options */
6371 else if (istermoption(&options[opt_idx]) && full_screen)
6372 {
6373 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6374 if (varp == &T_CCO)
6375 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006376 int colors = atoi((char *)T_CCO);
6377
6378 /* Only reinitialize colors if t_Co value has really changed to
6379 * avoid expensive reload of colorscheme if t_Co is set to the
6380 * same value multiple times. */
6381 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006382 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006383 t_colors = colors;
6384 if (t_colors <= 1)
6385 {
6386 if (new_value_alloced)
6387 vim_free(T_CCO);
6388 T_CCO = empty_option;
6389 }
6390 /* We now have a different color setup, initialize it again. */
6391 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006393 }
6394 ttest(FALSE);
6395 if (varp == &T_ME)
6396 {
6397 out_str(T_ME);
6398 redraw_later(CLEAR);
6399#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6400 /* Since t_me has been set, this probably means that the user
6401 * wants to use this as default colors. Need to reset default
6402 * background/foreground colors. */
6403 mch_set_normal_colors();
6404#endif
6405 }
6406 }
6407
6408#ifdef FEAT_LINEBREAK
6409 /* 'showbreak' */
6410 else if (varp == &p_sbr)
6411 {
6412 for (s = p_sbr; *s; )
6413 {
6414 if (ptr2cells(s) != 1)
6415 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006416 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006417 }
6418 }
6419#endif
6420
6421#ifdef FEAT_GUI
6422 /* 'guifont' */
6423 else if (varp == &p_guifont)
6424 {
6425 if (gui.in_use)
6426 {
6427 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006428# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006429 /*
6430 * Put up a font dialog and let the user select a new value.
6431 * If this is cancelled go back to the old value but don't
6432 * give an error message.
6433 */
6434 if (STRCMP(p, "*") == 0)
6435 {
6436 p = gui_mch_font_dialog(oldval);
6437
6438 if (new_value_alloced)
6439 free_string_option(p_guifont);
6440
6441 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6442 new_value_alloced = TRUE;
6443 }
6444# endif
6445 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6446 {
6447# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6448 if (STRCMP(p_guifont, "*") == 0)
6449 {
6450 /* Dialog was cancelled: Keep the old value without giving
6451 * an error message. */
6452 if (new_value_alloced)
6453 free_string_option(p_guifont);
6454 p_guifont = vim_strsave(oldval);
6455 new_value_alloced = TRUE;
6456 }
6457 else
6458# endif
6459 errmsg = (char_u *)N_("E596: Invalid font(s)");
6460 }
6461 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006462 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006463 }
6464# ifdef FEAT_XFONTSET
6465 else if (varp == &p_guifontset)
6466 {
6467 if (STRCMP(p_guifontset, "*") == 0)
6468 errmsg = (char_u *)N_("E597: can't select fontset");
6469 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6470 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006471 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006472 }
6473# endif
6474# ifdef FEAT_MBYTE
6475 else if (varp == &p_guifontwide)
6476 {
6477 if (STRCMP(p_guifontwide, "*") == 0)
6478 errmsg = (char_u *)N_("E533: can't select wide font");
6479 else if (gui_get_wide_font() == FAIL)
6480 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006481 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006482 }
6483# endif
6484#endif
6485
6486#ifdef CURSOR_SHAPE
6487 /* 'guicursor' */
6488 else if (varp == &p_guicursor)
6489 errmsg = parse_shape_opt(SHAPE_CURSOR);
6490#endif
6491
6492#ifdef FEAT_MOUSESHAPE
6493 /* 'mouseshape' */
6494 else if (varp == &p_mouseshape)
6495 {
6496 errmsg = parse_shape_opt(SHAPE_MOUSE);
6497 update_mouseshape(-1);
6498 }
6499#endif
6500
6501#ifdef FEAT_PRINTER
6502 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006503 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006504# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006505 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006506 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006507# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006508#endif
6509
6510#ifdef FEAT_LANGMAP
6511 /* 'langmap' */
6512 else if (varp == &p_langmap)
6513 langmap_set();
6514#endif
6515
6516#ifdef FEAT_LINEBREAK
6517 /* 'breakat' */
6518 else if (varp == &p_breakat)
6519 fill_breakat_flags();
6520#endif
6521
6522#ifdef FEAT_TITLE
6523 /* 'titlestring' and 'iconstring' */
6524 else if (varp == &p_titlestring || varp == &p_iconstring)
6525 {
6526# ifdef FEAT_STL_OPT
6527 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6528
6529 /* NULL => statusline syntax */
6530 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6531 stl_syntax |= flagval;
6532 else
6533 stl_syntax &= ~flagval;
6534# endif
6535 did_set_title(varp == &p_iconstring);
6536
6537 }
6538#endif
6539
6540#ifdef FEAT_GUI
6541 /* 'guioptions' */
6542 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006543 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006544 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006545 redraw_gui_only = TRUE;
6546 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006547#endif
6548
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006549#if defined(FEAT_GUI_TABLINE)
6550 /* 'guitablabel' */
6551 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006552 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006553 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006554 redraw_gui_only = TRUE;
6555 }
6556 /* 'guitabtooltip' */
6557 else if (varp == &p_gtt)
6558 {
6559 redraw_gui_only = TRUE;
6560 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006561#endif
6562
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6564 /* 'ttymouse' */
6565 else if (varp == &p_ttym)
6566 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006567 /* Switch the mouse off before changing the escape sequences used for
6568 * that. */
6569 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006570 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6571 errmsg = e_invarg;
6572 else
6573 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006574 if (termcap_active)
6575 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006576 }
6577#endif
6578
Bram Moolenaar071d4272004-06-13 20:20:40 +00006579 /* 'selection' */
6580 else if (varp == &p_sel)
6581 {
6582 if (*p_sel == NUL
6583 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6584 errmsg = e_invarg;
6585 }
6586
6587 /* 'selectmode' */
6588 else if (varp == &p_slm)
6589 {
6590 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6591 errmsg = e_invarg;
6592 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593
6594#ifdef FEAT_BROWSE
6595 /* 'browsedir' */
6596 else if (varp == &p_bsdir)
6597 {
6598 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6599 && !mch_isdir(p_bsdir))
6600 errmsg = e_invarg;
6601 }
6602#endif
6603
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604 /* 'keymodel' */
6605 else if (varp == &p_km)
6606 {
6607 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6608 errmsg = e_invarg;
6609 else
6610 {
6611 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6612 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6613 }
6614 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006615
6616 /* 'mousemodel' */
6617 else if (varp == &p_mousem)
6618 {
6619 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6620 errmsg = e_invarg;
6621#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6622 else if (*p_mousem != *oldval)
6623 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6624 * to create or delete the popup menus. */
6625 gui_motif_update_mousemodel(root_menu);
6626#endif
6627 }
6628
6629 /* 'switchbuf' */
6630 else if (varp == &p_swb)
6631 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006632 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006633 errmsg = e_invarg;
6634 }
6635
6636 /* 'debug' */
6637 else if (varp == &p_debug)
6638 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006639 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006640 errmsg = e_invarg;
6641 }
6642
6643 /* 'display' */
6644 else if (varp == &p_dy)
6645 {
6646 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6647 errmsg = e_invarg;
6648 else
6649 (void)init_chartab();
6650
6651 }
6652
6653#ifdef FEAT_VERTSPLIT
6654 /* 'eadirection' */
6655 else if (varp == &p_ead)
6656 {
6657 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6658 errmsg = e_invarg;
6659 }
6660#endif
6661
6662#ifdef FEAT_CLIPBOARD
6663 /* 'clipboard' */
6664 else if (varp == &p_cb)
6665 errmsg = check_clipboard_option();
6666#endif
6667
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006668#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006669 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6670 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006671 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006672 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006673 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006674 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006675
Bram Moolenaar860cae12010-06-05 23:22:07 +02006676 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006677 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006678 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6679 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006680 ".add") != 0))
6681 errmsg = e_invarg;
6682 }
6683
6684 if (errmsg == NULL)
6685 {
6686 FOR_ALL_WINDOWS(wp)
6687 if (wp->w_buffer == curbuf && wp->w_p_spell)
6688 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006689 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006690# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006691 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006692# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006693 }
6694 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006695 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006696 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006697 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006698 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006699 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006700 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006701 /* 'spellsuggest' */
6702 else if (varp == &p_sps)
6703 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006704 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006705 errmsg = e_invarg;
6706 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006707 /* 'mkspellmem' */
6708 else if (varp == &p_msm)
6709 {
6710 if (spell_check_msm() != OK)
6711 errmsg = e_invarg;
6712 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006713#endif
6714
Bram Moolenaar071d4272004-06-13 20:20:40 +00006715#ifdef FEAT_QUICKFIX
6716 /* When 'bufhidden' is set, check for valid value. */
6717 else if (gvarp == &p_bh)
6718 {
6719 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6720 errmsg = e_invarg;
6721 }
6722
6723 /* When 'buftype' is set, check for valid value. */
6724 else if (gvarp == &p_bt)
6725 {
6726 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6727 errmsg = e_invarg;
6728 else
6729 {
6730# ifdef FEAT_WINDOWS
6731 if (curwin->w_status_height)
6732 {
6733 curwin->w_redr_status = TRUE;
6734 redraw_later(VALID);
6735 }
6736# endif
6737 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006738# ifdef FEAT_TITLE
6739 redraw_titles();
6740# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006741 }
6742 }
6743#endif
6744
6745#ifdef FEAT_STL_OPT
6746 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006747 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006748 {
6749 int wid;
6750
6751 if (varp == &p_ruf) /* reset ru_wid first */
6752 ru_wid = 0;
6753 s = *varp;
6754 if (varp == &p_ruf && *s == '%')
6755 {
6756 /* set ru_wid if 'ruf' starts with "%99(" */
6757 if (*++s == '-') /* ignore a '-' */
6758 s++;
6759 wid = getdigits(&s);
6760 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6761 ru_wid = wid;
6762 else
6763 errmsg = check_stl_option(p_ruf);
6764 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006765 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006766 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006767 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006768 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006769 comp_col();
6770 }
6771#endif
6772
6773#ifdef FEAT_INS_EXPAND
6774 /* check if it is a valid value for 'complete' -- Acevedo */
6775 else if (gvarp == &p_cpt)
6776 {
6777 for (s = *varp; *s;)
6778 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006779 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780 s++;
6781 if (!*s)
6782 break;
6783 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6784 {
6785 errmsg = illegal_char(errbuf, *s);
6786 break;
6787 }
6788 if (*++s != NUL && *s != ',' && *s != ' ')
6789 {
6790 if (s[-1] == 'k' || s[-1] == 's')
6791 {
6792 /* skip optional filename after 'k' and 's' */
6793 while (*s && *s != ',' && *s != ' ')
6794 {
6795 if (*s == '\\')
6796 ++s;
6797 ++s;
6798 }
6799 }
6800 else
6801 {
6802 if (errbuf != NULL)
6803 {
6804 sprintf((char *)errbuf,
6805 _("E535: Illegal character after <%c>"),
6806 *--s);
6807 errmsg = errbuf;
6808 }
6809 else
6810 errmsg = (char_u *)"";
6811 break;
6812 }
6813 }
6814 }
6815 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006816
6817 /* 'completeopt' */
6818 else if (varp == &p_cot)
6819 {
6820 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6821 errmsg = e_invarg;
6822 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006823#endif /* FEAT_INS_EXPAND */
6824
6825
6826#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6827 else if (varp == &p_toolbar)
6828 {
6829 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6830 &toolbar_flags, TRUE) != OK)
6831 errmsg = e_invarg;
6832 else
6833 {
6834 out_flush();
6835 gui_mch_show_toolbar((toolbar_flags &
6836 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6837 }
6838 }
6839#endif
6840
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006841#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006842 /* 'toolbariconsize': GTK+ 2 only */
6843 else if (varp == &p_tbis)
6844 {
6845 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6846 errmsg = e_invarg;
6847 else
6848 {
6849 out_flush();
6850 gui_mch_show_toolbar((toolbar_flags &
6851 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6852 }
6853 }
6854#endif
6855
6856 /* 'pastetoggle': translate key codes like in a mapping */
6857 else if (varp == &p_pt)
6858 {
6859 if (*p_pt)
6860 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006861 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006862 if (p != NULL)
6863 {
6864 if (new_value_alloced)
6865 free_string_option(p_pt);
6866 p_pt = p;
6867 new_value_alloced = TRUE;
6868 }
6869 }
6870 }
6871
6872 /* 'backspace' */
6873 else if (varp == &p_bs)
6874 {
6875 if (VIM_ISDIGIT(*p_bs))
6876 {
6877 if (*p_bs >'2' || p_bs[1] != NUL)
6878 errmsg = e_invarg;
6879 }
6880 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6881 errmsg = e_invarg;
6882 }
6883
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006884#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006885 /* 'casemap' */
6886 else if (varp == &p_cmp)
6887 {
6888 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6889 errmsg = e_invarg;
6890 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006891#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006892
6893#ifdef FEAT_DIFF
6894 /* 'diffopt' */
6895 else if (varp == &p_dip)
6896 {
6897 if (diffopt_changed() == FAIL)
6898 errmsg = e_invarg;
6899 }
6900#endif
6901
6902#ifdef FEAT_FOLDING
6903 /* 'foldmethod' */
6904 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6905 {
6906 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6907 || *curwin->w_p_fdm == NUL)
6908 errmsg = e_invarg;
6909 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006910 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006911 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006912 if (foldmethodIsDiff(curwin))
6913 newFoldLevel();
6914 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006915 }
6916# ifdef FEAT_EVAL
6917 /* 'foldexpr' */
6918 else if (varp == &curwin->w_p_fde)
6919 {
6920 if (foldmethodIsExpr(curwin))
6921 foldUpdateAll(curwin);
6922 }
6923# endif
6924 /* 'foldmarker' */
6925 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6926 {
6927 p = vim_strchr(*varp, ',');
6928 if (p == NULL)
6929 errmsg = (char_u *)N_("E536: comma required");
6930 else if (p == *varp || p[1] == NUL)
6931 errmsg = e_invarg;
6932 else if (foldmethodIsMarker(curwin))
6933 foldUpdateAll(curwin);
6934 }
6935 /* 'commentstring' */
6936 else if (gvarp == &p_cms)
6937 {
6938 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6939 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6940 }
6941 /* 'foldopen' */
6942 else if (varp == &p_fdo)
6943 {
6944 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6945 errmsg = e_invarg;
6946 }
6947 /* 'foldclose' */
6948 else if (varp == &p_fcl)
6949 {
6950 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6951 errmsg = e_invarg;
6952 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006953 /* 'foldignore' */
6954 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6955 {
6956 if (foldmethodIsIndent(curwin))
6957 foldUpdateAll(curwin);
6958 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006959#endif
6960
6961#ifdef FEAT_VIRTUALEDIT
6962 /* 'virtualedit' */
6963 else if (varp == &p_ve)
6964 {
6965 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6966 errmsg = e_invarg;
6967 else if (STRCMP(p_ve, oldval) != 0)
6968 {
6969 /* Recompute cursor position in case the new 've' setting
6970 * changes something. */
6971 validate_virtcol();
6972 coladvance(curwin->w_virtcol);
6973 }
6974 }
6975#endif
6976
6977#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6978 else if (varp == &p_csqf)
6979 {
6980 if (p_csqf != NULL)
6981 {
6982 p = p_csqf;
6983 while (*p != NUL)
6984 {
6985 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6986 || p[1] == NUL
6987 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6988 || (p[2] != NUL && p[2] != ','))
6989 {
6990 errmsg = e_invarg;
6991 break;
6992 }
6993 else if (p[2] == NUL)
6994 break;
6995 else
6996 p += 3;
6997 }
6998 }
6999 }
7000#endif
7001
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007002#ifdef FEAT_CINDENT
7003 /* 'cinoptions' */
7004 else if (gvarp == &p_cino)
7005 {
7006 /* TODO: recognize errors */
7007 parse_cino(curbuf);
7008 }
7009#endif
7010
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007011#if defined(FEAT_RENDER_OPTIONS)
7012 else if (varp == &p_rop && gui.in_use)
7013 {
7014 if (!gui_mch_set_rendering_options(p_rop))
7015 errmsg = e_invarg;
7016 }
7017#endif
7018
Bram Moolenaar071d4272004-06-13 20:20:40 +00007019 /* Options that are a list of flags. */
7020 else
7021 {
7022 p = NULL;
7023 if (varp == &p_ww)
7024 p = (char_u *)WW_ALL;
7025 if (varp == &p_shm)
7026 p = (char_u *)SHM_ALL;
7027 else if (varp == &(p_cpo))
7028 p = (char_u *)CPO_ALL;
7029 else if (varp == &(curbuf->b_p_fo))
7030 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007031#ifdef FEAT_CONCEAL
7032 else if (varp == &curwin->w_p_cocu)
7033 p = (char_u *)COCU_ALL;
7034#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007035 else if (varp == &p_mouse)
7036 {
7037#ifdef FEAT_MOUSE
7038 p = (char_u *)MOUSE_ALL;
7039#else
7040 if (*p_mouse != NUL)
7041 errmsg = (char_u *)N_("E538: No mouse support");
7042#endif
7043 }
7044#if defined(FEAT_GUI)
7045 else if (varp == &p_go)
7046 p = (char_u *)GO_ALL;
7047#endif
7048 if (p != NULL)
7049 {
7050 for (s = *varp; *s; ++s)
7051 if (vim_strchr(p, *s) == NULL)
7052 {
7053 errmsg = illegal_char(errbuf, *s);
7054 break;
7055 }
7056 }
7057 }
7058
7059 /*
7060 * If error detected, restore the previous value.
7061 */
7062 if (errmsg != NULL)
7063 {
7064 if (new_value_alloced)
7065 free_string_option(*varp);
7066 *varp = oldval;
7067 /*
7068 * When resetting some values, need to act on it.
7069 */
7070 if (did_chartab)
7071 (void)init_chartab();
7072 if (varp == &p_hl)
7073 (void)highlight_changed();
7074 }
7075 else
7076 {
7077#ifdef FEAT_EVAL
7078 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007079 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007080#endif
7081 /*
7082 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007083 * Use "free_oldval", because recursiveness may change the flags under
7084 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007086 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007087 free_string_option(oldval);
7088 if (new_value_alloced)
7089 options[opt_idx].flags |= P_ALLOCED;
7090 else
7091 options[opt_idx].flags &= ~P_ALLOCED;
7092
7093 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007094 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007095 {
7096 /* global option with local value set to use global value; free
7097 * the local value and make it empty */
7098 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7099 free_string_option(*(char_u **)p);
7100 *(char_u **)p = empty_option;
7101 }
7102
7103 /* May set global value for local option. */
7104 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7105 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007106
7107#ifdef FEAT_AUTOCMD
7108 /*
7109 * Trigger the autocommand only after setting the flags.
7110 */
7111# ifdef FEAT_SYN_HL
7112 /* When 'syntax' is set, load the syntax of that name */
7113 if (varp == &(curbuf->b_p_syn))
7114 {
7115 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7116 curbuf->b_fname, TRUE, curbuf);
7117 }
7118# endif
7119 else if (varp == &(curbuf->b_p_ft))
7120 {
7121 /* 'filetype' is set, trigger the FileType autocommand */
7122 did_filetype = TRUE;
7123 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7124 curbuf->b_fname, TRUE, curbuf);
7125 }
7126#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007127#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007128 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007129 {
7130 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007131 char_u *q = curwin->w_s->b_p_spl;
7132
7133 /* Skip the first name if it is "cjk". */
7134 if (STRNCMP(q, "cjk,", 4) == 0)
7135 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007136
7137 /*
7138 * Source the spell/LANG.vim in 'runtimepath'.
7139 * They could set 'spellcapcheck' depending on the language.
7140 * Use the first name in 'spelllang' up to '_region' or
7141 * '.encoding'.
7142 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007143 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007144 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7145 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007146 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007147 source_runtime(fname, TRUE);
7148 }
7149#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007150 }
7151
7152#ifdef FEAT_MOUSE
7153 if (varp == &p_mouse)
7154 {
7155# ifdef FEAT_MOUSE_TTY
7156 if (*p_mouse == NUL)
7157 mch_setmouse(FALSE); /* switch mouse off */
7158 else
7159# endif
7160 setmouse(); /* in case 'mouse' changed */
7161 }
7162#endif
7163
Bram Moolenaar913077c2012-03-28 19:59:04 +02007164 if (curwin->w_curswant != MAXCOL
7165 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7166 curwin->w_set_curswant = TRUE;
7167
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007168#ifdef FEAT_GUI
7169 /* check redraw when it's not a GUI option or the GUI is active. */
7170 if (!redraw_gui_only || gui.in_use)
7171#endif
7172 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007173
7174 return errmsg;
7175}
7176
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007177#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007178/*
7179 * Simple int comparison function for use with qsort()
7180 */
7181 static int
7182int_cmp(a, b)
7183 const void *a;
7184 const void *b;
7185{
7186 return *(const int *)a - *(const int *)b;
7187}
7188
7189/*
7190 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7191 * Returns error message, NULL if it's OK.
7192 */
7193 char_u *
7194check_colorcolumn(wp)
7195 win_T *wp;
7196{
7197 char_u *s;
7198 int col;
7199 int count = 0;
7200 int color_cols[256];
7201 int i;
7202 int j = 0;
7203
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007204 if (wp->w_buffer == NULL)
7205 return NULL; /* buffer was closed */
7206
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007207 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007208 {
7209 if (*s == '-' || *s == '+')
7210 {
7211 /* -N and +N: add to 'textwidth' */
7212 col = (*s == '-') ? -1 : 1;
7213 ++s;
7214 if (!VIM_ISDIGIT(*s))
7215 return e_invarg;
7216 col = col * getdigits(&s);
7217 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007218 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007219 col += wp->w_buffer->b_p_tw;
7220 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007221 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007222 }
7223 else if (VIM_ISDIGIT(*s))
7224 col = getdigits(&s);
7225 else
7226 return e_invarg;
7227 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007228skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007229 if (*s == NUL)
7230 break;
7231 if (*s != ',')
7232 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007233 if (*++s == NUL)
7234 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007235 }
7236
7237 vim_free(wp->w_p_cc_cols);
7238 if (count == 0)
7239 wp->w_p_cc_cols = NULL;
7240 else
7241 {
7242 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7243 if (wp->w_p_cc_cols != NULL)
7244 {
7245 /* sort the columns for faster usage on screen redraw inside
7246 * win_line() */
7247 qsort(color_cols, count, sizeof(int), int_cmp);
7248
7249 for (i = 0; i < count; ++i)
7250 /* skip duplicates */
7251 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7252 wp->w_p_cc_cols[j++] = color_cols[i];
7253 wp->w_p_cc_cols[j] = -1; /* end marker */
7254 }
7255 }
7256
7257 return NULL; /* no error */
7258}
7259#endif
7260
Bram Moolenaar071d4272004-06-13 20:20:40 +00007261/*
7262 * Handle setting 'listchars' or 'fillchars'.
7263 * Returns error message, NULL if it's OK.
7264 */
7265 static char_u *
7266set_chars_option(varp)
7267 char_u **varp;
7268{
7269 int round, i, len, entries;
7270 char_u *p, *s;
7271 int c1, c2 = 0;
7272 struct charstab
7273 {
7274 int *cp;
7275 char *name;
7276 };
7277#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7278 static struct charstab filltab[] =
7279 {
7280 {&fill_stl, "stl"},
7281 {&fill_stlnc, "stlnc"},
7282 {&fill_vert, "vert"},
7283 {&fill_fold, "fold"},
7284 {&fill_diff, "diff"},
7285 };
7286#endif
7287 static struct charstab lcstab[] =
7288 {
7289 {&lcs_eol, "eol"},
7290 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007291 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007292 {&lcs_prec, "precedes"},
7293 {&lcs_tab2, "tab"},
7294 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007295#ifdef FEAT_CONCEAL
7296 {&lcs_conceal, "conceal"},
7297#else
7298 {NULL, "conceal"},
7299#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007300 };
7301 struct charstab *tab;
7302
7303#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7304 if (varp == &p_lcs)
7305#endif
7306 {
7307 tab = lcstab;
7308 entries = sizeof(lcstab) / sizeof(struct charstab);
7309 }
7310#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7311 else
7312 {
7313 tab = filltab;
7314 entries = sizeof(filltab) / sizeof(struct charstab);
7315 }
7316#endif
7317
7318 /* first round: check for valid value, second round: assign values */
7319 for (round = 0; round <= 1; ++round)
7320 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007321 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007322 {
7323 /* After checking that the value is valid: set defaults: space for
7324 * 'fillchars', NUL for 'listchars' */
7325 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007326 if (tab[i].cp != NULL)
7327 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007328 if (varp == &p_lcs)
7329 lcs_tab1 = NUL;
7330#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7331 else
7332 fill_diff = '-';
7333#endif
7334 }
7335 p = *varp;
7336 while (*p)
7337 {
7338 for (i = 0; i < entries; ++i)
7339 {
7340 len = (int)STRLEN(tab[i].name);
7341 if (STRNCMP(p, tab[i].name, len) == 0
7342 && p[len] == ':'
7343 && p[len + 1] != NUL)
7344 {
7345 s = p + len + 1;
7346#ifdef FEAT_MBYTE
7347 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007348 if (mb_char2cells(c1) > 1)
7349 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350#else
7351 c1 = *s++;
7352#endif
7353 if (tab[i].cp == &lcs_tab2)
7354 {
7355 if (*s == NUL)
7356 continue;
7357#ifdef FEAT_MBYTE
7358 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007359 if (mb_char2cells(c2) > 1)
7360 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007361#else
7362 c2 = *s++;
7363#endif
7364 }
7365 if (*s == ',' || *s == NUL)
7366 {
7367 if (round)
7368 {
7369 if (tab[i].cp == &lcs_tab2)
7370 {
7371 lcs_tab1 = c1;
7372 lcs_tab2 = c2;
7373 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007374 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007375 *(tab[i].cp) = c1;
7376
7377 }
7378 p = s;
7379 break;
7380 }
7381 }
7382 }
7383
7384 if (i == entries)
7385 return e_invarg;
7386 if (*p == ',')
7387 ++p;
7388 }
7389 }
7390
7391 return NULL; /* no error */
7392}
7393
7394#ifdef FEAT_STL_OPT
7395/*
7396 * Check validity of options with the 'statusline' format.
7397 * Return error message or NULL.
7398 */
7399 char_u *
7400check_stl_option(s)
7401 char_u *s;
7402{
7403 int itemcnt = 0;
7404 int groupdepth = 0;
7405 static char_u errbuf[80];
7406
7407 while (*s && itemcnt < STL_MAX_ITEM)
7408 {
7409 /* Check for valid keys after % sequences */
7410 while (*s && *s != '%')
7411 s++;
7412 if (!*s)
7413 break;
7414 s++;
7415 if (*s != '%' && *s != ')')
7416 ++itemcnt;
7417 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7418 {
7419 s++;
7420 continue;
7421 }
7422 if (*s == ')')
7423 {
7424 s++;
7425 if (--groupdepth < 0)
7426 break;
7427 continue;
7428 }
7429 if (*s == '-')
7430 s++;
7431 while (VIM_ISDIGIT(*s))
7432 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007433 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007434 continue;
7435 if (*s == '.')
7436 {
7437 s++;
7438 while (*s && VIM_ISDIGIT(*s))
7439 s++;
7440 }
7441 if (*s == '(')
7442 {
7443 groupdepth++;
7444 continue;
7445 }
7446 if (vim_strchr(STL_ALL, *s) == NULL)
7447 {
7448 return illegal_char(errbuf, *s);
7449 }
7450 if (*s == '{')
7451 {
7452 s++;
7453 while (*s != '}' && *s)
7454 s++;
7455 if (*s != '}')
7456 return (char_u *)N_("E540: Unclosed expression sequence");
7457 }
7458 }
7459 if (itemcnt >= STL_MAX_ITEM)
7460 return (char_u *)N_("E541: too many items");
7461 if (groupdepth != 0)
7462 return (char_u *)N_("E542: unbalanced groups");
7463 return NULL;
7464}
7465#endif
7466
7467#ifdef FEAT_CLIPBOARD
7468/*
7469 * Extract the items in the 'clipboard' option and set global values.
7470 */
7471 static char_u *
7472check_clipboard_option()
7473{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007474 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007475 int new_autoselect_star = FALSE;
7476 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007478 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007479 regprog_T *new_exclude_prog = NULL;
7480 char_u *errmsg = NULL;
7481 char_u *p;
7482
7483 for (p = p_cb; *p != NUL; )
7484 {
7485 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7486 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007487 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007488 p += 7;
7489 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007490 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007491 && (p[11] == ',' || p[11] == NUL))
7492 {
7493 new_unnamed |= CLIP_UNNAMED_PLUS;
7494 p += 11;
7495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007497 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007499 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007500 p += 10;
7501 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007502 else if (STRNCMP(p, "autoselectplus", 14) == 0
7503 && (p[14] == ',' || p[14] == NUL))
7504 {
7505 new_autoselect_plus = TRUE;
7506 p += 14;
7507 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007508 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007509 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510 {
7511 new_autoselectml = TRUE;
7512 p += 12;
7513 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007514 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7515 {
7516 new_html = TRUE;
7517 p += 4;
7518 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7520 {
7521 p += 8;
7522 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7523 if (new_exclude_prog == NULL)
7524 errmsg = e_invarg;
7525 break;
7526 }
7527 else
7528 {
7529 errmsg = e_invarg;
7530 break;
7531 }
7532 if (*p == ',')
7533 ++p;
7534 }
7535 if (errmsg == NULL)
7536 {
7537 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007538 clip_autoselect_star = new_autoselect_star;
7539 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007540 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007541 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007542 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007544#ifdef FEAT_GUI_GTK
7545 if (gui.in_use)
7546 {
7547 gui_gtk_set_selection_targets();
7548 gui_gtk_set_dnd_targets();
7549 }
7550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007551 }
7552 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007553 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007554
7555 return errmsg;
7556}
7557#endif
7558
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007559#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007560/*
7561 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7562 * Return error message when failed, NULL when OK.
7563 */
7564 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007565compile_cap_prog(synblock)
7566 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007567{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007568 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007569 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007570
Bram Moolenaar860cae12010-06-05 23:22:07 +02007571 if (*synblock->b_p_spc == NUL)
7572 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007573 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007574 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007575 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007576 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007577 if (re != NULL)
7578 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007579 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007580 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007581 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007582 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007583 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007584 return e_invarg;
7585 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007586 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007587 }
7588
Bram Moolenaar473de612013-06-08 18:19:48 +02007589 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007590 return NULL;
7591}
7592#endif
7593
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007594#if defined(FEAT_EVAL) || defined(PROTO)
7595/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007596 * Set the scriptID for an option, taking care of setting the buffer- or
7597 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007598 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007599 static void
7600set_option_scriptID_idx(opt_idx, opt_flags, id)
7601 int opt_idx;
7602 int opt_flags;
7603 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007604{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007605 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7606 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007607
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007608 /* Remember where the option was set. For local options need to do that
7609 * in the buffer or window structure. */
7610 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007611 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007612 if (both || (opt_flags & OPT_LOCAL))
7613 {
7614 if (indir & PV_BUF)
7615 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7616 else if (indir & PV_WIN)
7617 curwin->w_p_scriptID[indir & PV_MASK] = id;
7618 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007619}
7620#endif
7621
Bram Moolenaar071d4272004-06-13 20:20:40 +00007622/*
7623 * Set the value of a boolean option, and take care of side effects.
7624 * Returns NULL for success, or an error message for an error.
7625 */
7626 static char_u *
7627set_bool_option(opt_idx, varp, value, opt_flags)
7628 int opt_idx; /* index in options[] table */
7629 char_u *varp; /* pointer to the option variable */
7630 int value; /* new value */
7631 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7632{
7633 int old_value = *(int *)varp;
7634
Bram Moolenaar071d4272004-06-13 20:20:40 +00007635 /* Disallow changing some options from secure mode */
7636 if ((secure
7637#ifdef HAVE_SANDBOX
7638 || sandbox != 0
7639#endif
7640 ) && (options[opt_idx].flags & P_SECURE))
7641 return e_secure;
7642
7643 *(int *)varp = value; /* set the new value */
7644#ifdef FEAT_EVAL
7645 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007646 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647#endif
7648
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007649#ifdef FEAT_GUI
7650 need_mouse_correct = TRUE;
7651#endif
7652
Bram Moolenaar071d4272004-06-13 20:20:40 +00007653 /* May set global value for local option. */
7654 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7655 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7656
7657 /*
7658 * Handle side effects of changing a bool option.
7659 */
7660
7661 /* 'compatible' */
7662 if ((int *)varp == &p_cp)
7663 {
7664 compatible_set();
7665 }
7666
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007667#ifdef FEAT_PERSISTENT_UNDO
7668 /* 'undofile' */
7669 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7670 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007671 /* Only take action when the option was set. When reset we do not
7672 * delete the undo file, the option may be set again without making
7673 * any changes in between. */
7674 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007675 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007676 char_u hash[UNDO_HASH_SIZE];
7677 buf_T *save_curbuf = curbuf;
7678
7679 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007680 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007681 /* When 'undofile' is set globally: for every buffer, otherwise
7682 * only for the current buffer: Try to read in the undofile,
7683 * if one exists, the buffer wasn't changed and the buffer was
7684 * loaded */
7685 if ((curbuf == save_curbuf
7686 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7687 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7688 {
7689 u_compute_hash(hash);
7690 u_read_undo(NULL, hash, curbuf->b_fname);
7691 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007692 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007693 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007694 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007695 }
7696#endif
7697
Bram Moolenaar071d4272004-06-13 20:20:40 +00007698 else if ((int *)varp == &curbuf->b_p_ro)
7699 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007700 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007701 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7702 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007703
7704 /* when 'readonly' is set may give W10 again */
7705 if (curbuf->b_p_ro)
7706 curbuf->b_did_warn = FALSE;
7707
Bram Moolenaar071d4272004-06-13 20:20:40 +00007708#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007709 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007710#endif
7711 }
7712
Bram Moolenaar9c449722010-07-20 18:44:27 +02007713#ifdef FEAT_GUI
7714 else if ((int *)varp == &p_mh)
7715 {
7716 if (!p_mh)
7717 gui_mch_mousehide(FALSE);
7718 }
7719#endif
7720
Bram Moolenaara539df02010-08-01 14:35:05 +02007721#ifdef FEAT_TITLE
7722 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007724 {
7725 redraw_titles();
7726 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007727 /* when 'endofline' is changed, redraw the window title */
7728 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007729 {
7730 redraw_titles();
7731 }
7732# ifdef FEAT_MBYTE
7733 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007734 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007735 {
7736 redraw_titles();
7737 }
7738# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739#endif
7740
7741 /* when 'bin' is set also set some other options */
7742 else if ((int *)varp == &curbuf->b_p_bin)
7743 {
7744 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7745#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007746 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007747#endif
7748 }
7749
7750#ifdef FEAT_AUTOCMD
7751 /* when 'buflisted' changes, trigger autocommands */
7752 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7753 {
7754 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7755 NULL, NULL, TRUE, curbuf);
7756 }
7757#endif
7758
7759 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7760 else if ((int *)varp == &curbuf->b_p_swf)
7761 {
7762 if (curbuf->b_p_swf && p_uc)
7763 ml_open_file(curbuf); /* create the swap file */
7764 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007765 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7766 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767 mf_close_file(curbuf, TRUE); /* remove the swap file */
7768 }
7769
7770 /* when 'terse' is set change 'shortmess' */
7771 else if ((int *)varp == &p_terse)
7772 {
7773 char_u *p;
7774
7775 p = vim_strchr(p_shm, SHM_SEARCH);
7776
7777 /* insert 's' in p_shm */
7778 if (p_terse && p == NULL)
7779 {
7780 STRCPY(IObuff, p_shm);
7781 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007782 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007783 }
7784 /* remove 's' from p_shm */
7785 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007786 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787 }
7788
7789 /* when 'paste' is set or reset also change other options */
7790 else if ((int *)varp == &p_paste)
7791 {
7792 paste_option_changed();
7793 }
7794
7795 /* when 'insertmode' is set from an autocommand need to do work here */
7796 else if ((int *)varp == &p_im)
7797 {
7798 if (p_im)
7799 {
7800 if ((State & INSERT) == 0)
7801 need_start_insertmode = TRUE;
7802 stop_insert_mode = FALSE;
7803 }
7804 else
7805 {
7806 need_start_insertmode = FALSE;
7807 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007808 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007809 clear_cmdline = TRUE; /* remove "(insert)" */
7810 restart_edit = 0;
7811 }
7812 }
7813
7814 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7815 else if ((int *)varp == &p_ic && p_hls)
7816 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007817 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818 }
7819
7820#ifdef FEAT_SEARCH_EXTRA
7821 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7822 else if ((int *)varp == &p_hls)
7823 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007824 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007825 }
7826#endif
7827
7828#ifdef FEAT_SCROLLBIND
7829 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7830 * at the end of normal_cmd() */
7831 else if ((int *)varp == &curwin->w_p_scb)
7832 {
7833 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007834 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007835 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007836 curwin->w_scbind_pos = curwin->w_topline;
7837 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007838 }
7839#endif
7840
7841#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7842 /* There can be only one window with 'previewwindow' set. */
7843 else if ((int *)varp == &curwin->w_p_pvw)
7844 {
7845 if (curwin->w_p_pvw)
7846 {
7847 win_T *win;
7848
7849 for (win = firstwin; win != NULL; win = win->w_next)
7850 if (win->w_p_pvw && win != curwin)
7851 {
7852 curwin->w_p_pvw = FALSE;
7853 return (char_u *)N_("E590: A preview window already exists");
7854 }
7855 }
7856 }
7857#endif
7858
7859 /* when 'textmode' is set or reset also change 'fileformat' */
7860 else if ((int *)varp == &curbuf->b_p_tx)
7861 {
7862 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7863 }
7864
7865 /* when 'textauto' is set or reset also change 'fileformats' */
7866 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007867 set_string_option_direct((char_u *)"ffs", -1,
7868 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007869 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007870
7871 /*
7872 * When 'lisp' option changes include/exclude '-' in
7873 * keyword characters.
7874 */
7875#ifdef FEAT_LISP
7876 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7877 {
7878 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7879 }
7880#endif
7881
7882#ifdef FEAT_TITLE
7883 /* when 'title' changed, may need to change the title; same for 'icon' */
7884 else if ((int *)varp == &p_title)
7885 {
7886 did_set_title(FALSE);
7887 }
7888
7889 else if ((int *)varp == &p_icon)
7890 {
7891 did_set_title(TRUE);
7892 }
7893#endif
7894
7895 else if ((int *)varp == &curbuf->b_changed)
7896 {
7897 if (!value)
7898 save_file_ff(curbuf); /* Buffer is unchanged */
7899#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007900 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901#endif
7902#ifdef FEAT_AUTOCMD
7903 modified_was_set = value;
7904#endif
7905 }
7906
7907#ifdef BACKSLASH_IN_FILENAME
7908 else if ((int *)varp == &p_ssl)
7909 {
7910 if (p_ssl)
7911 {
7912 psepc = '/';
7913 psepcN = '\\';
7914 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 }
7916 else
7917 {
7918 psepc = '\\';
7919 psepcN = '/';
7920 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007921 }
7922
7923 /* need to adjust the file name arguments and buffer names. */
7924 buflist_slash_adjust();
7925 alist_slash_adjust();
7926# ifdef FEAT_EVAL
7927 scriptnames_slash_adjust();
7928# endif
7929 }
7930#endif
7931
7932 /* If 'wrap' is set, set w_leftcol to zero. */
7933 else if ((int *)varp == &curwin->w_p_wrap)
7934 {
7935 if (curwin->w_p_wrap)
7936 curwin->w_leftcol = 0;
7937 }
7938
7939#ifdef FEAT_WINDOWS
7940 else if ((int *)varp == &p_ea)
7941 {
7942 if (p_ea && !old_value)
7943 win_equal(curwin, FALSE, 0);
7944 }
7945#endif
7946
7947 else if ((int *)varp == &p_wiv)
7948 {
7949 /*
7950 * When 'weirdinvert' changed, set/reset 't_xs'.
7951 * Then set 'weirdinvert' according to value of 't_xs'.
7952 */
7953 if (p_wiv && !old_value)
7954 T_XS = (char_u *)"y";
7955 else if (!p_wiv && old_value)
7956 T_XS = empty_option;
7957 p_wiv = (*T_XS != NUL);
7958 }
7959
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007960#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007961 else if ((int *)varp == &p_beval)
7962 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007963 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007965 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 gui_mch_disable_beval_area(balloonEval);
7967 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007968#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007969
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007970#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007971 else if ((int *)varp == &p_acd)
7972 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007973 /* Change directories when the 'acd' option is set now. */
7974 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007975 }
7976#endif
7977
7978#ifdef FEAT_DIFF
7979 /* 'diff' */
7980 else if ((int *)varp == &curwin->w_p_diff)
7981 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007982 /* May add or remove the buffer from the list of diff buffers. */
7983 diff_buf_adjust(curwin);
7984# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 if (foldmethodIsDiff(curwin))
7986 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007987# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007988 }
7989#endif
7990
7991#ifdef USE_IM_CONTROL
7992 /* 'imdisable' */
7993 else if ((int *)varp == &p_imdisable)
7994 {
7995 /* Only de-activate it here, it will be enabled when changing mode. */
7996 if (p_imdisable)
7997 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02007998 else if (State & INSERT)
7999 /* When the option is set from an autocommand, it may need to take
8000 * effect right away. */
8001 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 }
8003#endif
8004
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008005#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008006 /* 'spell' */
8007 else if ((int *)varp == &curwin->w_p_spell)
8008 {
8009 if (curwin->w_p_spell)
8010 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008011 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008012 if (errmsg != NULL)
8013 EMSG(_(errmsg));
8014 }
8015 }
8016#endif
8017
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018#ifdef FEAT_FKMAP
8019 else if ((int *)varp == &p_altkeymap)
8020 {
8021 if (old_value != p_altkeymap)
8022 {
8023 if (!p_altkeymap)
8024 {
8025 p_hkmap = p_fkmap;
8026 p_fkmap = 0;
8027 }
8028 else
8029 {
8030 p_fkmap = p_hkmap;
8031 p_hkmap = 0;
8032 }
8033 (void)init_chartab();
8034 }
8035 }
8036
8037 /*
8038 * In case some second language keymapping options have changed, check
8039 * and correct the setting in a consistent way.
8040 */
8041
8042 /*
8043 * If hkmap or fkmap are set, reset Arabic keymapping.
8044 */
8045 if ((p_hkmap || p_fkmap) && p_altkeymap)
8046 {
8047 p_altkeymap = p_fkmap;
8048# ifdef FEAT_ARABIC
8049 curwin->w_p_arab = FALSE;
8050# endif
8051 (void)init_chartab();
8052 }
8053
8054 /*
8055 * If hkmap set, reset Farsi keymapping.
8056 */
8057 if (p_hkmap && p_altkeymap)
8058 {
8059 p_altkeymap = 0;
8060 p_fkmap = 0;
8061# ifdef FEAT_ARABIC
8062 curwin->w_p_arab = FALSE;
8063# endif
8064 (void)init_chartab();
8065 }
8066
8067 /*
8068 * If fkmap set, reset Hebrew keymapping.
8069 */
8070 if (p_fkmap && !p_altkeymap)
8071 {
8072 p_altkeymap = 1;
8073 p_hkmap = 0;
8074# ifdef FEAT_ARABIC
8075 curwin->w_p_arab = FALSE;
8076# endif
8077 (void)init_chartab();
8078 }
8079#endif
8080
8081#ifdef FEAT_ARABIC
8082 if ((int *)varp == &curwin->w_p_arab)
8083 {
8084 if (curwin->w_p_arab)
8085 {
8086 /*
8087 * 'arabic' is set, handle various sub-settings.
8088 */
8089 if (!p_tbidi)
8090 {
8091 /* set rightleft mode */
8092 if (!curwin->w_p_rl)
8093 {
8094 curwin->w_p_rl = TRUE;
8095 changed_window_setting();
8096 }
8097
8098 /* Enable Arabic shaping (major part of what Arabic requires) */
8099 if (!p_arshape)
8100 {
8101 p_arshape = TRUE;
8102 redraw_later_clear();
8103 }
8104 }
8105
8106 /* Arabic requires a utf-8 encoding, inform the user if its not
8107 * set. */
8108 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008109 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008110 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8111
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008112 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008113 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8114#ifdef FEAT_EVAL
8115 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8116#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008117 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118
8119# ifdef FEAT_MBYTE
8120 /* set 'delcombine' */
8121 p_deco = TRUE;
8122# endif
8123
8124# ifdef FEAT_KEYMAP
8125 /* Force-set the necessary keymap for arabic */
8126 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8127 OPT_LOCAL);
8128# endif
8129# ifdef FEAT_FKMAP
8130 p_altkeymap = 0;
8131 p_hkmap = 0;
8132 p_fkmap = 0;
8133 (void)init_chartab();
8134# endif
8135 }
8136 else
8137 {
8138 /*
8139 * 'arabic' is reset, handle various sub-settings.
8140 */
8141 if (!p_tbidi)
8142 {
8143 /* reset rightleft mode */
8144 if (curwin->w_p_rl)
8145 {
8146 curwin->w_p_rl = FALSE;
8147 changed_window_setting();
8148 }
8149
8150 /* 'arabicshape' isn't reset, it is a global option and
8151 * another window may still need it "on". */
8152 }
8153
8154 /* 'delcombine' isn't reset, it is a global option and another
8155 * window may still want it "on". */
8156
8157# ifdef FEAT_KEYMAP
8158 /* Revert to the default keymap */
8159 curbuf->b_p_iminsert = B_IMODE_NONE;
8160 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8161# endif
8162 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008163 }
8164
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008165#endif
8166
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 /*
8168 * End of handling side effects for bool options.
8169 */
8170
8171 options[opt_idx].flags |= P_WAS_SET;
8172
8173 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008174 if (curwin->w_curswant != MAXCOL
8175 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8176 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008177 check_redraw(options[opt_idx].flags);
8178
8179 return NULL;
8180}
8181
8182/*
8183 * Set the value of a number option, and take care of side effects.
8184 * Returns NULL for success, or an error message for an error.
8185 */
8186 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008187set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188 int opt_idx; /* index in options[] table */
8189 char_u *varp; /* pointer to the option variable */
8190 long value; /* new value */
8191 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008192 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8194 OPT_MODELINE */
8195{
8196 char_u *errmsg = NULL;
8197 long old_value = *(long *)varp;
8198 long old_Rows = Rows; /* remember old Rows */
8199 long old_Columns = Columns; /* remember old Columns */
8200 long *pp = (long *)varp;
8201
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008202 /* Disallow changing some options from secure mode. */
8203 if ((secure
8204#ifdef HAVE_SANDBOX
8205 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008207 ) && (options[opt_idx].flags & P_SECURE))
8208 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209
8210 *pp = value;
8211#ifdef FEAT_EVAL
8212 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008213 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008214#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008215#ifdef FEAT_GUI
8216 need_mouse_correct = TRUE;
8217#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218
Bram Moolenaar14f24742012-08-08 18:01:05 +02008219 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220 {
8221 errmsg = e_positive;
8222 curbuf->b_p_sw = curbuf->b_p_ts;
8223 }
8224
8225 /*
8226 * Number options that need some action when changed
8227 */
8228#ifdef FEAT_WINDOWS
8229 if (pp == &p_wh || pp == &p_hh)
8230 {
8231 if (p_wh < 1)
8232 {
8233 errmsg = e_positive;
8234 p_wh = 1;
8235 }
8236 if (p_wmh > p_wh)
8237 {
8238 errmsg = e_winheight;
8239 p_wh = p_wmh;
8240 }
8241 if (p_hh < 0)
8242 {
8243 errmsg = e_positive;
8244 p_hh = 0;
8245 }
8246
8247 /* Change window height NOW */
8248 if (lastwin != firstwin)
8249 {
8250 if (pp == &p_wh && curwin->w_height < p_wh)
8251 win_setheight((int)p_wh);
8252 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8253 win_setheight((int)p_hh);
8254 }
8255 }
8256
8257 /* 'winminheight' */
8258 else if (pp == &p_wmh)
8259 {
8260 if (p_wmh < 0)
8261 {
8262 errmsg = e_positive;
8263 p_wmh = 0;
8264 }
8265 if (p_wmh > p_wh)
8266 {
8267 errmsg = e_winheight;
8268 p_wmh = p_wh;
8269 }
8270 win_setminheight();
8271 }
8272
8273# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008274 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008275 {
8276 if (p_wiw < 1)
8277 {
8278 errmsg = e_positive;
8279 p_wiw = 1;
8280 }
8281 if (p_wmw > p_wiw)
8282 {
8283 errmsg = e_winwidth;
8284 p_wiw = p_wmw;
8285 }
8286
8287 /* Change window width NOW */
8288 if (lastwin != firstwin && curwin->w_width < p_wiw)
8289 win_setwidth((int)p_wiw);
8290 }
8291
8292 /* 'winminwidth' */
8293 else if (pp == &p_wmw)
8294 {
8295 if (p_wmw < 0)
8296 {
8297 errmsg = e_positive;
8298 p_wmw = 0;
8299 }
8300 if (p_wmw > p_wiw)
8301 {
8302 errmsg = e_winwidth;
8303 p_wmw = p_wiw;
8304 }
8305 win_setminheight();
8306 }
8307# endif
8308
8309#endif
8310
8311#ifdef FEAT_WINDOWS
8312 /* (re)set last window status line */
8313 else if (pp == &p_ls)
8314 {
8315 last_status(FALSE);
8316 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008317
8318 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008319 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008320 {
8321 shell_new_rows(); /* recompute window positions and heights */
8322 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008323#endif
8324
8325#ifdef FEAT_GUI
8326 else if (pp == &p_linespace)
8327 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008328 /* Recompute gui.char_height and resize the Vim window to keep the
8329 * same number of lines. */
8330 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008331 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008332 }
8333#endif
8334
8335#ifdef FEAT_FOLDING
8336 /* 'foldlevel' */
8337 else if (pp == &curwin->w_p_fdl)
8338 {
8339 if (curwin->w_p_fdl < 0)
8340 curwin->w_p_fdl = 0;
8341 newFoldLevel();
8342 }
8343
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008344 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 else if (pp == &curwin->w_p_fml)
8346 {
8347 foldUpdateAll(curwin);
8348 }
8349
8350 /* 'foldnestmax' */
8351 else if (pp == &curwin->w_p_fdn)
8352 {
8353 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8354 foldUpdateAll(curwin);
8355 }
8356
8357 /* 'foldcolumn' */
8358 else if (pp == &curwin->w_p_fdc)
8359 {
8360 if (curwin->w_p_fdc < 0)
8361 {
8362 errmsg = e_positive;
8363 curwin->w_p_fdc = 0;
8364 }
8365 else if (curwin->w_p_fdc > 12)
8366 {
8367 errmsg = e_invarg;
8368 curwin->w_p_fdc = 12;
8369 }
8370 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008371#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008373#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008374 /* 'shiftwidth' or 'tabstop' */
8375 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8376 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008377# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008378 if (foldmethodIsIndent(curwin))
8379 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008380# endif
8381# ifdef FEAT_CINDENT
8382 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8383 * parse 'cinoptions'. */
8384 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8385 parse_cino(curbuf);
8386# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008388#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008389
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008390#ifdef FEAT_MBYTE
8391 /* 'maxcombine' */
8392 else if (pp == &p_mco)
8393 {
8394 if (p_mco > MAX_MCO)
8395 p_mco = MAX_MCO;
8396 else if (p_mco < 0)
8397 p_mco = 0;
8398 screenclear(); /* will re-allocate the screen */
8399 }
8400#endif
8401
Bram Moolenaar071d4272004-06-13 20:20:40 +00008402 else if (pp == &curbuf->b_p_iminsert)
8403 {
8404 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8405 {
8406 errmsg = e_invarg;
8407 curbuf->b_p_iminsert = B_IMODE_NONE;
8408 }
8409 p_iminsert = curbuf->b_p_iminsert;
8410 if (termcap_active) /* don't do this in the alternate screen */
8411 showmode();
8412#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8413 /* Show/unshow value of 'keymap' in status lines. */
8414 status_redraw_curbuf();
8415#endif
8416 }
8417
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008418 else if (pp == &p_window)
8419 {
8420 if (p_window < 1)
8421 p_window = 1;
8422 else if (p_window >= Rows)
8423 p_window = Rows - 1;
8424 }
8425
Bram Moolenaar071d4272004-06-13 20:20:40 +00008426 else if (pp == &curbuf->b_p_imsearch)
8427 {
8428 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8429 {
8430 errmsg = e_invarg;
8431 curbuf->b_p_imsearch = B_IMODE_NONE;
8432 }
8433 p_imsearch = curbuf->b_p_imsearch;
8434 }
8435
8436#ifdef FEAT_TITLE
8437 /* if 'titlelen' has changed, redraw the title */
8438 else if (pp == &p_titlelen)
8439 {
8440 if (p_titlelen < 0)
8441 {
8442 errmsg = e_positive;
8443 p_titlelen = 85;
8444 }
8445 if (starting != NO_SCREEN && old_value != p_titlelen)
8446 need_maketitle = TRUE;
8447 }
8448#endif
8449
8450 /* if p_ch changed value, change the command line height */
8451 else if (pp == &p_ch)
8452 {
8453 if (p_ch < 1)
8454 {
8455 errmsg = e_positive;
8456 p_ch = 1;
8457 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008458 if (p_ch > Rows - min_rows() + 1)
8459 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460
8461 /* Only compute the new window layout when startup has been
8462 * completed. Otherwise the frame sizes may be wrong. */
8463 if (p_ch != old_value && full_screen
8464#ifdef FEAT_GUI
8465 && !gui.starting
8466#endif
8467 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008468 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008469 }
8470
8471 /* when 'updatecount' changes from zero to non-zero, open swap files */
8472 else if (pp == &p_uc)
8473 {
8474 if (p_uc < 0)
8475 {
8476 errmsg = e_positive;
8477 p_uc = 100;
8478 }
8479 if (p_uc && !old_value)
8480 ml_open_files();
8481 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008482#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008483 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008484 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008485 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008486 {
8487 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008488 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008489 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008490 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008491 {
8492 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008493 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008494 }
8495 }
8496#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008497#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008498 else if (pp == &p_mzq)
8499 mzvim_reset_timer();
8500#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008501
8502 /* sync undo before 'undolevels' changes */
8503 else if (pp == &p_ul)
8504 {
8505 /* use the old value, otherwise u_sync() may not work properly */
8506 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008507 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008508 p_ul = value;
8509 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008510 else if (pp == &curbuf->b_p_ul)
8511 {
8512 /* use the old value, otherwise u_sync() may not work properly */
8513 curbuf->b_p_ul = old_value;
8514 u_sync(TRUE);
8515 curbuf->b_p_ul = value;
8516 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008517
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008518#ifdef FEAT_LINEBREAK
8519 /* 'numberwidth' must be positive */
8520 else if (pp == &curwin->w_p_nuw)
8521 {
8522 if (curwin->w_p_nuw < 1)
8523 {
8524 errmsg = e_positive;
8525 curwin->w_p_nuw = 1;
8526 }
8527 if (curwin->w_p_nuw > 10)
8528 {
8529 errmsg = e_invarg;
8530 curwin->w_p_nuw = 10;
8531 }
8532 curwin->w_nrwidth_line_count = 0;
8533 }
8534#endif
8535
Bram Moolenaar1a384422010-07-14 19:53:30 +02008536 else if (pp == &curbuf->b_p_tw)
8537 {
8538 if (curbuf->b_p_tw < 0)
8539 {
8540 errmsg = e_positive;
8541 curbuf->b_p_tw = 0;
8542 }
8543#ifdef FEAT_SYN_HL
8544# ifdef FEAT_WINDOWS
8545 {
8546 win_T *wp;
8547 tabpage_T *tp;
8548
8549 FOR_ALL_TAB_WINDOWS(tp, wp)
8550 check_colorcolumn(wp);
8551 }
8552# else
8553 check_colorcolumn(curwin);
8554# endif
8555#endif
8556 }
8557
Bram Moolenaar071d4272004-06-13 20:20:40 +00008558 /*
8559 * Check the bounds for numeric options here
8560 */
8561 if (Rows < min_rows() && full_screen)
8562 {
8563 if (errbuf != NULL)
8564 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008565 vim_snprintf((char *)errbuf, errbuflen,
8566 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008567 errmsg = errbuf;
8568 }
8569 Rows = min_rows();
8570 }
8571 if (Columns < MIN_COLUMNS && full_screen)
8572 {
8573 if (errbuf != NULL)
8574 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008575 vim_snprintf((char *)errbuf, errbuflen,
8576 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008577 errmsg = errbuf;
8578 }
8579 Columns = MIN_COLUMNS;
8580 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008581 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008582
8583#ifdef DJGPP
8584 /* avoid a crash by checking for a too large value of 'columns' */
8585 if (old_Columns != Columns && full_screen && term_console)
8586 mch_check_columns();
8587#endif
8588
8589 /*
8590 * If the screen (shell) height has been changed, assume it is the
8591 * physical screenheight.
8592 */
8593 if (old_Rows != Rows || old_Columns != Columns)
8594 {
8595 /* Changing the screen size is not allowed while updating the screen. */
8596 if (updating_screen)
8597 *pp = old_value;
8598 else if (full_screen
8599#ifdef FEAT_GUI
8600 && !gui.starting
8601#endif
8602 )
8603 set_shellsize((int)Columns, (int)Rows, TRUE);
8604 else
8605 {
8606 /* Postpone the resizing; check the size and cmdline position for
8607 * messages. */
8608 check_shellsize();
8609 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8610 cmdline_row = Rows - p_ch;
8611 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008612 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008613 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008614 }
8615
Bram Moolenaar071d4272004-06-13 20:20:40 +00008616 if (curbuf->b_p_ts <= 0)
8617 {
8618 errmsg = e_positive;
8619 curbuf->b_p_ts = 8;
8620 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008621 if (p_tm < 0)
8622 {
8623 errmsg = e_positive;
8624 p_tm = 0;
8625 }
8626 if ((curwin->w_p_scr <= 0
8627 || (curwin->w_p_scr > curwin->w_height
8628 && curwin->w_height > 0))
8629 && full_screen)
8630 {
8631 if (pp == &(curwin->w_p_scr))
8632 {
8633 if (curwin->w_p_scr != 0)
8634 errmsg = e_scroll;
8635 win_comp_scroll(curwin);
8636 }
8637 /* If 'scroll' became invalid because of a side effect silently adjust
8638 * it. */
8639 else if (curwin->w_p_scr <= 0)
8640 curwin->w_p_scr = 1;
8641 else /* curwin->w_p_scr > curwin->w_height */
8642 curwin->w_p_scr = curwin->w_height;
8643 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008644 if (p_hi < 0)
8645 {
8646 errmsg = e_positive;
8647 p_hi = 0;
8648 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008649 else if (p_hi > 10000)
8650 {
8651 errmsg = e_invarg;
8652 p_hi = 10000;
8653 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008654 if (p_re < 0 || p_re > 2)
8655 {
8656 errmsg = e_invarg;
8657 p_re = 0;
8658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008659 if (p_report < 0)
8660 {
8661 errmsg = e_positive;
8662 p_report = 1;
8663 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008664 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008665 {
8666 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8667 p_sj = Rows / 2;
8668 else
8669 {
8670 errmsg = e_scroll;
8671 p_sj = 1;
8672 }
8673 }
8674 if (p_so < 0 && full_screen)
8675 {
8676 errmsg = e_scroll;
8677 p_so = 0;
8678 }
8679 if (p_siso < 0 && full_screen)
8680 {
8681 errmsg = e_positive;
8682 p_siso = 0;
8683 }
8684#ifdef FEAT_CMDWIN
8685 if (p_cwh < 1)
8686 {
8687 errmsg = e_positive;
8688 p_cwh = 1;
8689 }
8690#endif
8691 if (p_ut < 0)
8692 {
8693 errmsg = e_positive;
8694 p_ut = 2000;
8695 }
8696 if (p_ss < 0)
8697 {
8698 errmsg = e_positive;
8699 p_ss = 0;
8700 }
8701
8702 /* May set global value for local option. */
8703 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8704 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8705
8706 options[opt_idx].flags |= P_WAS_SET;
8707
8708 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008709 if (curwin->w_curswant != MAXCOL
8710 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8711 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008712 check_redraw(options[opt_idx].flags);
8713
8714 return errmsg;
8715}
8716
8717/*
8718 * Called after an option changed: check if something needs to be redrawn.
8719 */
8720 static void
8721check_redraw(flags)
8722 long_u flags;
8723{
8724 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008725 int doclear = (flags & P_RCLR) == P_RCLR;
8726 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008727
8728#ifdef FEAT_WINDOWS
8729 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8730 status_redraw_all();
8731#endif
8732
8733 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8734 changed_window_setting();
8735 if (flags & P_RBUF)
8736 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008737 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008738 redraw_all_later(CLEAR);
8739 else if (all)
8740 redraw_all_later(NOT_VALID);
8741}
8742
8743/*
8744 * Find index for option 'arg'.
8745 * Return -1 if not found.
8746 */
8747 static int
8748findoption(arg)
8749 char_u *arg;
8750{
8751 int opt_idx;
8752 char *s, *p;
8753 static short quick_tab[27] = {0, 0}; /* quick access table */
8754 int is_term_opt;
8755
8756 /*
8757 * For first call: Initialize the quick-access table.
8758 * It contains the index for the first option that starts with a certain
8759 * letter. There are 26 letters, plus the first "t_" option.
8760 */
8761 if (quick_tab[1] == 0)
8762 {
8763 p = options[0].fullname;
8764 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8765 {
8766 if (s[0] != p[0])
8767 {
8768 if (s[0] == 't' && s[1] == '_')
8769 quick_tab[26] = opt_idx;
8770 else
8771 quick_tab[CharOrdLow(s[0])] = opt_idx;
8772 }
8773 p = s;
8774 }
8775 }
8776
8777 /*
8778 * Check for name starting with an illegal character.
8779 */
8780#ifdef EBCDIC
8781 if (!islower(arg[0]))
8782#else
8783 if (arg[0] < 'a' || arg[0] > 'z')
8784#endif
8785 return -1;
8786
8787 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8788 if (is_term_opt)
8789 opt_idx = quick_tab[26];
8790 else
8791 opt_idx = quick_tab[CharOrdLow(arg[0])];
8792 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8793 {
8794 if (STRCMP(arg, s) == 0) /* match full name */
8795 break;
8796 }
8797 if (s == NULL && !is_term_opt)
8798 {
8799 opt_idx = quick_tab[CharOrdLow(arg[0])];
8800 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8801 {
8802 s = options[opt_idx].shortname;
8803 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8804 break;
8805 s = NULL;
8806 }
8807 }
8808 if (s == NULL)
8809 opt_idx = -1;
8810 return opt_idx;
8811}
8812
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008813#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008814/*
8815 * Get the value for an option.
8816 *
8817 * Returns:
8818 * Number or Toggle option: 1, *numval gets value.
8819 * String option: 0, *stringval gets allocated string.
8820 * Hidden Number or Toggle option: -1.
8821 * hidden String option: -2.
8822 * unknown option: -3.
8823 */
8824 int
8825get_option_value(name, numval, stringval, opt_flags)
8826 char_u *name;
8827 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008828 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008829 int opt_flags;
8830{
8831 int opt_idx;
8832 char_u *varp;
8833
8834 opt_idx = findoption(name);
8835 if (opt_idx < 0) /* unknown option */
8836 return -3;
8837
8838 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8839
8840 if (options[opt_idx].flags & P_STRING)
8841 {
8842 if (varp == NULL) /* hidden option */
8843 return -2;
8844 if (stringval != NULL)
8845 {
8846#ifdef FEAT_CRYPT
8847 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008848 if ((char_u **)varp == &curbuf->b_p_key
8849 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008850 *stringval = vim_strsave((char_u *)"*****");
8851 else
8852#endif
8853 *stringval = vim_strsave(*(char_u **)(varp));
8854 }
8855 return 0;
8856 }
8857
8858 if (varp == NULL) /* hidden option */
8859 return -1;
8860 if (options[opt_idx].flags & P_NUM)
8861 *numval = *(long *)varp;
8862 else
8863 {
8864 /* Special case: 'modified' is b_changed, but we also want to consider
8865 * it set when 'ff' or 'fenc' changed. */
8866 if ((int *)varp == &curbuf->b_changed)
8867 *numval = curbufIsChanged();
8868 else
8869 *numval = *(int *)varp;
8870 }
8871 return 1;
8872}
8873#endif
8874
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008875#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008876/*
8877 * Returns the option attributes and its value. Unlike the above function it
8878 * will return either global value or local value of the option depending on
8879 * what was requested, but it will never return global value if it was
8880 * requested to return local one and vice versa. Neither it will return
8881 * buffer-local value if it was requested to return window-local one.
8882 *
8883 * Pretends that option is absent if it is not present in the requested scope
8884 * (i.e. has no global, window-local or buffer-local value depending on
8885 * opt_type). Uses
8886 *
8887 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008888 * 0 hidden or unknown option, also option that does not have requested
8889 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008890 * see SOPT_* in vim.h for other flags
8891 *
8892 * Possible opt_type values: see SREQ_* in vim.h
8893 */
8894 int
8895get_option_value_strict(name, numval, stringval, opt_type, from)
8896 char_u *name;
8897 long *numval;
8898 char_u **stringval; /* NULL when only obtaining attributes */
8899 int opt_type;
8900 void *from;
8901{
8902 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008903 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008904 struct vimoption *p;
8905 int r = 0;
8906
8907 opt_idx = findoption(name);
8908 if (opt_idx < 0)
8909 return 0;
8910
8911 p = &(options[opt_idx]);
8912
8913 /* Hidden option */
8914 if (p->var == NULL)
8915 return 0;
8916
8917 if (p->flags & P_BOOL)
8918 r |= SOPT_BOOL;
8919 else if (p->flags & P_NUM)
8920 r |= SOPT_NUM;
8921 else if (p->flags & P_STRING)
8922 r |= SOPT_STRING;
8923
8924 if (p->indir == PV_NONE)
8925 {
8926 if (opt_type == SREQ_GLOBAL)
8927 r |= SOPT_GLOBAL;
8928 else
8929 return 0; /* Did not request global-only option */
8930 }
8931 else
8932 {
8933 if (p->indir & PV_BOTH)
8934 r |= SOPT_GLOBAL;
8935 else if (opt_type == SREQ_GLOBAL)
8936 return 0; /* Requested global option */
8937
8938 if (p->indir & PV_WIN)
8939 {
8940 if (opt_type == SREQ_BUF)
8941 return 0; /* Did not request window-local option */
8942 else
8943 r |= SOPT_WIN;
8944 }
8945 else if (p->indir & PV_BUF)
8946 {
8947 if (opt_type == SREQ_WIN)
8948 return 0; /* Did not request buffer-local option */
8949 else
8950 r |= SOPT_BUF;
8951 }
8952 }
8953
8954 if (stringval == NULL)
8955 return r;
8956
8957 if (opt_type == SREQ_GLOBAL)
8958 varp = p->var;
8959 else
8960 {
8961 if (opt_type == SREQ_BUF)
8962 {
8963 /* Special case: 'modified' is b_changed, but we also want to
8964 * consider it set when 'ff' or 'fenc' changed. */
8965 if (p->indir == PV_MOD)
8966 {
8967 *numval = bufIsChanged((buf_T *) from);
8968 varp = NULL;
8969 }
8970#ifdef FEAT_CRYPT
8971 else if (p->indir == PV_KEY)
8972 {
8973 /* never return the value of the crypt key */
8974 *stringval = NULL;
8975 varp = NULL;
8976 }
8977#endif
8978 else
8979 {
8980 aco_save_T aco;
8981 aucmd_prepbuf(&aco, (buf_T *) from);
8982 varp = get_varp(p);
8983 aucmd_restbuf(&aco);
8984 }
8985 }
8986 else if (opt_type == SREQ_WIN)
8987 {
8988 win_T *save_curwin;
8989 save_curwin = curwin;
8990 curwin = (win_T *) from;
8991 curbuf = curwin->w_buffer;
8992 varp = get_varp(p);
8993 curwin = save_curwin;
8994 curbuf = curwin->w_buffer;
8995 }
8996 if (varp == p->var)
8997 return (r | SOPT_UNSET);
8998 }
8999
9000 if (varp != NULL)
9001 {
9002 if (p->flags & P_STRING)
9003 *stringval = vim_strsave(*(char_u **)(varp));
9004 else if (p->flags & P_NUM)
9005 *numval = *(long *) varp;
9006 else
9007 *numval = *(int *)varp;
9008 }
9009
9010 return r;
9011}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009012
9013/*
9014 * Iterate over options. First argument is a pointer to a pointer to a structure
9015 * inside options[] array, second is option type like in the above function.
9016 *
9017 * If first argument points to NULL it is assumed that iteration just started
9018 * and caller needs the very first value.
9019 * If first argument points to the end marker function returns NULL and sets
9020 * first argument to NULL.
9021 *
9022 * Returns full option name for current option on each call.
9023 */
9024 char_u *
9025option_iter_next(option, opt_type)
9026 void **option;
9027 int opt_type;
9028{
9029 struct vimoption *ret = NULL;
9030 do
9031 {
9032 if (*option == NULL)
9033 *option = (void *) options;
9034 else if (((struct vimoption *) (*option))->fullname == NULL)
9035 {
9036 *option = NULL;
9037 return NULL;
9038 }
9039 else
9040 *option = (void *) (((struct vimoption *) (*option)) + 1);
9041
9042 ret = ((struct vimoption *) (*option));
9043
9044 /* Hidden option */
9045 if (ret->var == NULL)
9046 {
9047 ret = NULL;
9048 continue;
9049 }
9050
9051 switch (opt_type)
9052 {
9053 case SREQ_GLOBAL:
9054 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9055 ret = NULL;
9056 break;
9057 case SREQ_BUF:
9058 if (!(ret->indir & PV_BUF))
9059 ret = NULL;
9060 break;
9061 case SREQ_WIN:
9062 if (!(ret->indir & PV_WIN))
9063 ret = NULL;
9064 break;
9065 default:
9066 EMSG2(_(e_intern2), "option_iter_next()");
9067 return NULL;
9068 }
9069 }
9070 while (ret == NULL);
9071
9072 return (char_u *)ret->fullname;
9073}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009074#endif
9075
Bram Moolenaar071d4272004-06-13 20:20:40 +00009076/*
9077 * Set the value of option "name".
9078 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009079 *
9080 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009081 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009082 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009083set_option_value(name, number, string, opt_flags)
9084 char_u *name;
9085 long number;
9086 char_u *string;
9087 int opt_flags; /* OPT_LOCAL or 0 (both) */
9088{
9089 int opt_idx;
9090 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009091 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009092
9093 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009094 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009095 EMSG2(_("E355: Unknown option: %s"), name);
9096 else
9097 {
9098 flags = options[opt_idx].flags;
9099#ifdef HAVE_SANDBOX
9100 /* Disallow changing some options in the sandbox */
9101 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009102 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009104 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009105 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009106#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009107 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009108 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009109 else
9110 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009111 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009112 if (varp != NULL) /* hidden option is not changed */
9113 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009114 if (number == 0 && string != NULL)
9115 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009116 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009117
9118 /* Either we are given a string or we are setting option
9119 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009120 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009121 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009122 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009123 {
9124 /* There's another character after zeros or the string
9125 * is empty. In both cases, we are trying to set a
9126 * num option using a string. */
9127 EMSG3(_("E521: Number required: &%s = '%s'"),
9128 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009129 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009130
9131 }
9132 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009133 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009134 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009135 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009136 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009137 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009138 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009139 }
9140 }
9141 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009142 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009143}
9144
9145/*
9146 * Get the terminal code for a terminal option.
9147 * Returns NULL when not found.
9148 */
9149 char_u *
9150get_term_code(tname)
9151 char_u *tname;
9152{
9153 int opt_idx;
9154 char_u *varp;
9155
9156 if (tname[0] != 't' || tname[1] != '_' ||
9157 tname[2] == NUL || tname[3] == NUL)
9158 return NULL;
9159 if ((opt_idx = findoption(tname)) >= 0)
9160 {
9161 varp = get_varp(&(options[opt_idx]));
9162 if (varp != NULL)
9163 varp = *(char_u **)(varp);
9164 return varp;
9165 }
9166 return find_termcode(tname + 2);
9167}
9168
9169 char_u *
9170get_highlight_default()
9171{
9172 int i;
9173
9174 i = findoption((char_u *)"hl");
9175 if (i >= 0)
9176 return options[i].def_val[VI_DEFAULT];
9177 return (char_u *)NULL;
9178}
9179
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009180#if defined(FEAT_MBYTE) || defined(PROTO)
9181 char_u *
9182get_encoding_default()
9183{
9184 int i;
9185
9186 i = findoption((char_u *)"enc");
9187 if (i >= 0)
9188 return options[i].def_val[VI_DEFAULT];
9189 return (char_u *)NULL;
9190}
9191#endif
9192
Bram Moolenaar071d4272004-06-13 20:20:40 +00009193/*
9194 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9195 */
9196 static int
9197find_key_option(arg)
9198 char_u *arg;
9199{
9200 int key;
9201 int modifiers;
9202
9203 /*
9204 * Don't use get_special_key_code() for t_xx, we don't want it to call
9205 * add_termcap_entry().
9206 */
9207 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9208 key = TERMCAP2KEY(arg[2], arg[3]);
9209 else
9210 {
9211 --arg; /* put arg at the '<' */
9212 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009213 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009214 if (modifiers) /* can't handle modifiers here */
9215 key = 0;
9216 }
9217 return key;
9218}
9219
9220/*
9221 * if 'all' == 0: show changed options
9222 * if 'all' == 1: show all normal options
9223 * if 'all' == 2: show all terminal options
9224 */
9225 static void
9226showoptions(all, opt_flags)
9227 int all;
9228 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9229{
9230 struct vimoption *p;
9231 int col;
9232 int isterm;
9233 char_u *varp;
9234 struct vimoption **items;
9235 int item_count;
9236 int run;
9237 int row, rows;
9238 int cols;
9239 int i;
9240 int len;
9241
9242#define INC 20
9243#define GAP 3
9244
9245 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9246 PARAM_COUNT));
9247 if (items == NULL)
9248 return;
9249
9250 /* Highlight title */
9251 if (all == 2)
9252 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9253 else if (opt_flags & OPT_GLOBAL)
9254 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9255 else if (opt_flags & OPT_LOCAL)
9256 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9257 else
9258 MSG_PUTS_TITLE(_("\n--- Options ---"));
9259
9260 /*
9261 * do the loop two times:
9262 * 1. display the short items
9263 * 2. display the long items (only strings and numbers)
9264 */
9265 for (run = 1; run <= 2 && !got_int; ++run)
9266 {
9267 /*
9268 * collect the items in items[]
9269 */
9270 item_count = 0;
9271 for (p = &options[0]; p->fullname != NULL; p++)
9272 {
9273 varp = NULL;
9274 isterm = istermoption(p);
9275 if (opt_flags != 0)
9276 {
9277 if (p->indir != PV_NONE && !isterm)
9278 varp = get_varp_scope(p, opt_flags);
9279 }
9280 else
9281 varp = get_varp(p);
9282 if (varp != NULL
9283 && ((all == 2 && isterm)
9284 || (all == 1 && !isterm)
9285 || (all == 0 && !optval_default(p, varp))))
9286 {
9287 if (p->flags & P_BOOL)
9288 len = 1; /* a toggle option fits always */
9289 else
9290 {
9291 option_value2string(p, opt_flags);
9292 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9293 }
9294 if ((len <= INC - GAP && run == 1) ||
9295 (len > INC - GAP && run == 2))
9296 items[item_count++] = p;
9297 }
9298 }
9299
9300 /*
9301 * display the items
9302 */
9303 if (run == 1)
9304 {
9305 cols = (Columns + GAP - 3) / INC;
9306 if (cols == 0)
9307 cols = 1;
9308 rows = (item_count + cols - 1) / cols;
9309 }
9310 else /* run == 2 */
9311 rows = item_count;
9312 for (row = 0; row < rows && !got_int; ++row)
9313 {
9314 msg_putchar('\n'); /* go to next line */
9315 if (got_int) /* 'q' typed in more */
9316 break;
9317 col = 0;
9318 for (i = row; i < item_count; i += rows)
9319 {
9320 msg_col = col; /* make columns */
9321 showoneopt(items[i], opt_flags);
9322 col += INC;
9323 }
9324 out_flush();
9325 ui_breakcheck();
9326 }
9327 }
9328 vim_free(items);
9329}
9330
9331/*
9332 * Return TRUE if option "p" has its default value.
9333 */
9334 static int
9335optval_default(p, varp)
9336 struct vimoption *p;
9337 char_u *varp;
9338{
9339 int dvi;
9340
9341 if (varp == NULL)
9342 return TRUE; /* hidden option is always at default */
9343 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9344 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009345 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009346 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009347 /* the cast to long is required for Manx C, long_i is
9348 * needed for MSVC */
9349 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009350 /* P_STRING */
9351 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9352}
9353
9354/*
9355 * showoneopt: show the value of one option
9356 * must not be called with a hidden option!
9357 */
9358 static void
9359showoneopt(p, opt_flags)
9360 struct vimoption *p;
9361 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9362{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009363 char_u *varp;
9364 int save_silent = silent_mode;
9365
9366 silent_mode = FALSE;
9367 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368
9369 varp = get_varp_scope(p, opt_flags);
9370
9371 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9372 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9373 ? !curbufIsChanged() : !*(int *)varp))
9374 MSG_PUTS("no");
9375 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9376 MSG_PUTS("--");
9377 else
9378 MSG_PUTS(" ");
9379 MSG_PUTS(p->fullname);
9380 if (!(p->flags & P_BOOL))
9381 {
9382 msg_putchar('=');
9383 /* put value string in NameBuff */
9384 option_value2string(p, opt_flags);
9385 msg_outtrans(NameBuff);
9386 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009387
9388 silent_mode = save_silent;
9389 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009390}
9391
9392/*
9393 * Write modified options as ":set" commands to a file.
9394 *
9395 * There are three values for "opt_flags":
9396 * OPT_GLOBAL: Write global option values and fresh values of
9397 * buffer-local options (used for start of a session
9398 * file).
9399 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9400 * curwin (used for a vimrc file).
9401 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9402 * and local values for window-local options of
9403 * curwin. Local values are also written when at the
9404 * default value, because a modeline or autocommand
9405 * may have set them when doing ":edit file" and the
9406 * user has set them back at the default or fresh
9407 * value.
9408 * When "local_only" is TRUE, don't write fresh
9409 * values, only local values (for ":mkview").
9410 * (fresh value = value used for a new buffer or window for a local option).
9411 *
9412 * Return FAIL on error, OK otherwise.
9413 */
9414 int
9415makeset(fd, opt_flags, local_only)
9416 FILE *fd;
9417 int opt_flags;
9418 int local_only;
9419{
9420 struct vimoption *p;
9421 char_u *varp; /* currently used value */
9422 char_u *varp_fresh; /* local value */
9423 char_u *varp_local = NULL; /* fresh value */
9424 char *cmd;
9425 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009426 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009427
9428 /*
9429 * The options that don't have a default (terminal name, columns, lines)
9430 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009431 * Do the loop over "options[]" twice: once for options with the
9432 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009434 for (pri = 1; pri >= 0; --pri)
9435 {
9436 for (p = &options[0]; !istermoption(p); p++)
9437 if (!(p->flags & P_NO_MKRC)
9438 && !istermoption(p)
9439 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009440 {
9441 /* skip global option when only doing locals */
9442 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9443 continue;
9444
9445 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9446 * file, they are always buffer-specific. */
9447 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9448 continue;
9449
9450 /* Global values are only written when not at the default value. */
9451 varp = get_varp_scope(p, opt_flags);
9452 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9453 continue;
9454
9455 round = 2;
9456 if (p->indir != PV_NONE)
9457 {
9458 if (p->var == VAR_WIN)
9459 {
9460 /* skip window-local option when only doing globals */
9461 if (!(opt_flags & OPT_LOCAL))
9462 continue;
9463 /* When fresh value of window-local option is not at the
9464 * default, need to write it too. */
9465 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9466 {
9467 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9468 if (!optval_default(p, varp_fresh))
9469 {
9470 round = 1;
9471 varp_local = varp;
9472 varp = varp_fresh;
9473 }
9474 }
9475 }
9476 }
9477
9478 /* Round 1: fresh value for window-local options.
9479 * Round 2: other values */
9480 for ( ; round <= 2; varp = varp_local, ++round)
9481 {
9482 if (round == 1 || (opt_flags & OPT_GLOBAL))
9483 cmd = "set";
9484 else
9485 cmd = "setlocal";
9486
9487 if (p->flags & P_BOOL)
9488 {
9489 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9490 return FAIL;
9491 }
9492 else if (p->flags & P_NUM)
9493 {
9494 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9495 return FAIL;
9496 }
9497 else /* P_STRING */
9498 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009499#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9500 int do_endif = FALSE;
9501
Bram Moolenaar071d4272004-06-13 20:20:40 +00009502 /* Don't set 'syntax' and 'filetype' again if the value is
9503 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009504 if (
9505# if defined(FEAT_SYN_HL)
9506 p->indir == PV_SYN
9507# if defined(FEAT_AUTOCMD)
9508 ||
9509# endif
9510# endif
9511# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009512 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009513# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009514 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009515 {
9516 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9517 *(char_u **)(varp)) < 0
9518 || put_eol(fd) < 0)
9519 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009520 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009521 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009522#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009523 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9524 (p->flags & P_EXPAND) != 0) == FAIL)
9525 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009526#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9527 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009528 {
9529 if (put_line(fd, "endif") == FAIL)
9530 return FAIL;
9531 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009532#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009533 }
9534 }
9535 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009536 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537 return OK;
9538}
9539
9540#if defined(FEAT_FOLDING) || defined(PROTO)
9541/*
9542 * Generate set commands for the local fold options only. Used when
9543 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9544 */
9545 int
9546makefoldset(fd)
9547 FILE *fd;
9548{
9549 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9550# ifdef FEAT_EVAL
9551 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9552 == FAIL
9553# endif
9554 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9555 == FAIL
9556 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9557 == FAIL
9558 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9559 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9560 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9561 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9562 )
9563 return FAIL;
9564
9565 return OK;
9566}
9567#endif
9568
9569 static int
9570put_setstring(fd, cmd, name, valuep, expand)
9571 FILE *fd;
9572 char *cmd;
9573 char *name;
9574 char_u **valuep;
9575 int expand;
9576{
9577 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009578 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009579
9580 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9581 return FAIL;
9582 if (*valuep != NULL)
9583 {
9584 /* Output 'pastetoggle' as key names. For other
9585 * options some characters have to be escaped with
9586 * CTRL-V or backslash */
9587 if (valuep == &p_pt)
9588 {
9589 s = *valuep;
9590 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009591 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592 return FAIL;
9593 }
9594 else if (expand)
9595 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009596 buf = alloc(MAXPATHL);
9597 if (buf == NULL)
9598 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009599 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9600 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009601 {
9602 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009603 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009604 }
9605 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009606 }
9607 else if (put_escstr(fd, *valuep, 2) == FAIL)
9608 return FAIL;
9609 }
9610 if (put_eol(fd) < 0)
9611 return FAIL;
9612 return OK;
9613}
9614
9615 static int
9616put_setnum(fd, cmd, name, valuep)
9617 FILE *fd;
9618 char *cmd;
9619 char *name;
9620 long *valuep;
9621{
9622 long wc;
9623
9624 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9625 return FAIL;
9626 if (wc_use_keyname((char_u *)valuep, &wc))
9627 {
9628 /* print 'wildchar' and 'wildcharm' as a key name */
9629 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9630 return FAIL;
9631 }
9632 else if (fprintf(fd, "%ld", *valuep) < 0)
9633 return FAIL;
9634 if (put_eol(fd) < 0)
9635 return FAIL;
9636 return OK;
9637}
9638
9639 static int
9640put_setbool(fd, cmd, name, value)
9641 FILE *fd;
9642 char *cmd;
9643 char *name;
9644 int value;
9645{
Bram Moolenaar893de922007-10-02 18:40:57 +00009646 if (value < 0) /* global/local option using global value */
9647 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009648 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9649 || put_eol(fd) < 0)
9650 return FAIL;
9651 return OK;
9652}
9653
9654/*
9655 * Clear all the terminal options.
9656 * If the option has been allocated, free the memory.
9657 * Terminal options are never hidden or indirect.
9658 */
9659 void
9660clear_termoptions()
9661{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009662 /*
9663 * Reset a few things before clearing the old options. This may cause
9664 * outputting a few things that the terminal doesn't understand, but the
9665 * screen will be cleared later, so this is OK.
9666 */
9667#ifdef FEAT_MOUSE_TTY
9668 mch_setmouse(FALSE); /* switch mouse off */
9669#endif
9670#ifdef FEAT_TITLE
9671 mch_restore_title(3); /* restore window titles */
9672#endif
9673#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9674 /* When starting the GUI close the display opened for the clipboard.
9675 * After restoring the title, because that will need the display. */
9676 if (gui.starting)
9677 clear_xterm_clip();
9678#endif
9679#ifdef WIN3264
9680 /*
9681 * Check if this is allowed now.
9682 */
9683 if (can_end_termcap_mode(FALSE) == TRUE)
9684#endif
9685 stoptermcap(); /* stop termcap mode */
9686
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009687 free_termoptions();
9688}
9689
9690 void
9691free_termoptions()
9692{
9693 struct vimoption *p;
9694
Bram Moolenaar071d4272004-06-13 20:20:40 +00009695 for (p = &options[0]; p->fullname != NULL; p++)
9696 if (istermoption(p))
9697 {
9698 if (p->flags & P_ALLOCED)
9699 free_string_option(*(char_u **)(p->var));
9700 if (p->flags & P_DEF_ALLOCED)
9701 free_string_option(p->def_val[VI_DEFAULT]);
9702 *(char_u **)(p->var) = empty_option;
9703 p->def_val[VI_DEFAULT] = empty_option;
9704 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9705 }
9706 clear_termcodes();
9707}
9708
9709/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009710 * Free the string for one term option, if it was allocated.
9711 * Set the string to empty_option and clear allocated flag.
9712 * "var" points to the option value.
9713 */
9714 void
9715free_one_termoption(var)
9716 char_u *var;
9717{
9718 struct vimoption *p;
9719
9720 for (p = &options[0]; p->fullname != NULL; p++)
9721 if (p->var == var)
9722 {
9723 if (p->flags & P_ALLOCED)
9724 free_string_option(*(char_u **)(p->var));
9725 *(char_u **)(p->var) = empty_option;
9726 p->flags &= ~P_ALLOCED;
9727 break;
9728 }
9729}
9730
9731/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009732 * Set the terminal option defaults to the current value.
9733 * Used after setting the terminal name.
9734 */
9735 void
9736set_term_defaults()
9737{
9738 struct vimoption *p;
9739
9740 for (p = &options[0]; p->fullname != NULL; p++)
9741 {
9742 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9743 {
9744 if (p->flags & P_DEF_ALLOCED)
9745 {
9746 free_string_option(p->def_val[VI_DEFAULT]);
9747 p->flags &= ~P_DEF_ALLOCED;
9748 }
9749 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9750 if (p->flags & P_ALLOCED)
9751 {
9752 p->flags |= P_DEF_ALLOCED;
9753 p->flags &= ~P_ALLOCED; /* don't free the value now */
9754 }
9755 }
9756 }
9757}
9758
9759/*
9760 * return TRUE if 'p' starts with 't_'
9761 */
9762 static int
9763istermoption(p)
9764 struct vimoption *p;
9765{
9766 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9767}
9768
9769/*
9770 * Compute columns for ruler and shown command. 'sc_col' is also used to
9771 * decide what the maximum length of a message on the status line can be.
9772 * If there is a status line for the last window, 'sc_col' is independent
9773 * of 'ru_col'.
9774 */
9775
9776#define COL_RULER 17 /* columns needed by standard ruler */
9777
9778 void
9779comp_col()
9780{
9781#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9782 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9783
9784 sc_col = 0;
9785 ru_col = 0;
9786 if (p_ru)
9787 {
9788#ifdef FEAT_STL_OPT
9789 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9790#else
9791 ru_col = COL_RULER + 1;
9792#endif
9793 /* no last status line, adjust sc_col */
9794 if (!last_has_status)
9795 sc_col = ru_col;
9796 }
9797 if (p_sc)
9798 {
9799 sc_col += SHOWCMD_COLS;
9800 if (!p_ru || last_has_status) /* no need for separating space */
9801 ++sc_col;
9802 }
9803 sc_col = Columns - sc_col;
9804 ru_col = Columns - ru_col;
9805 if (sc_col <= 0) /* screen too narrow, will become a mess */
9806 sc_col = 1;
9807 if (ru_col <= 0)
9808 ru_col = 1;
9809#else
9810 sc_col = Columns;
9811 ru_col = Columns;
9812#endif
9813}
9814
9815/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009816 * Unset local option value, similar to ":set opt<".
9817 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009818 void
9819unset_global_local_option(name, from)
9820 char_u *name;
9821 void *from;
9822{
9823 struct vimoption *p;
9824 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009825 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009826
9827 opt_idx = findoption(name);
9828 p = &(options[opt_idx]);
9829
9830 switch ((int)p->indir)
9831 {
9832 /* global option with local value: use local value if it's been set */
9833 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009834 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009835 break;
9836 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009837 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009838 break;
9839 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009840 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009841 break;
9842 case PV_AR:
9843 buf->b_p_ar = -1;
9844 break;
9845 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009846 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009847 break;
9848#ifdef FEAT_FIND_ID
9849 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009850 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009851 break;
9852 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009853 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009854 break;
9855#endif
9856#ifdef FEAT_INS_EXPAND
9857 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009858 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009859 break;
9860 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009861 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009862 break;
9863#endif
9864#ifdef FEAT_QUICKFIX
9865 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009866 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009867 break;
9868 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009869 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009870 break;
9871 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009872 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009873 break;
9874#endif
9875#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9876 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009877 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009878 break;
9879#endif
9880#if defined(FEAT_CRYPT)
9881 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009882 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009883 break;
9884#endif
9885#ifdef FEAT_STL_OPT
9886 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009887 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009888 break;
9889#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009890 case PV_UL:
9891 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9892 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009893#ifdef FEAT_LISP
9894 case PV_LW:
9895 clear_string_option(&buf->b_p_lw);
9896 break;
9897#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009898 }
9899}
9900
9901/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009902 * Get pointer to option variable, depending on local or global scope.
9903 */
9904 static char_u *
9905get_varp_scope(p, opt_flags)
9906 struct vimoption *p;
9907 int opt_flags;
9908{
9909 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9910 {
9911 if (p->var == VAR_WIN)
9912 return (char_u *)GLOBAL_WO(get_varp(p));
9913 return p->var;
9914 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009915 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009916 {
9917 switch ((int)p->indir)
9918 {
9919#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009920 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9921 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9922 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009923#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009924 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9925 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9926 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009927 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009928 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009929#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009930 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9931 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009932#endif
9933#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009934 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9935 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009936#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009937#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9938 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9939#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009940#if defined(FEAT_CRYPT)
9941 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9942#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009943#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009944 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009945#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009946 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009947#ifdef FEAT_LISP
9948 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9949#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950 }
9951 return NULL; /* "cannot happen" */
9952 }
9953 return get_varp(p);
9954}
9955
9956/*
9957 * Get pointer to option variable.
9958 */
9959 static char_u *
9960get_varp(p)
9961 struct vimoption *p;
9962{
9963 /* hidden option, always return NULL */
9964 if (p->var == NULL)
9965 return NULL;
9966
9967 switch ((int)p->indir)
9968 {
9969 case PV_NONE: return p->var;
9970
9971 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009972 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009974 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009975 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009976 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009978 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009979 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009980 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009981 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9982#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009983 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009985 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009986 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9987#endif
9988#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009989 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009990 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009991 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
9993#endif
9994#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009995 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009996 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009997 case PV_GP: return *curbuf->b_p_gp != NUL
9998 ? (char_u *)&(curbuf->b_p_gp) : p->var;
9999 case PV_MP: return *curbuf->b_p_mp != NUL
10000 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010001#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010002#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10003 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10004 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10005#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010006#if defined(FEAT_CRYPT)
10007 case PV_CM: return *curbuf->b_p_cm != NUL
10008 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10009#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010010#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010011 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010012 ? (char_u *)&(curwin->w_p_stl) : p->var;
10013#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010014 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10015 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010016#ifdef FEAT_LISP
10017 case PV_LW: return *curbuf->b_p_lw != NUL
10018 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010020
10021#ifdef FEAT_ARABIC
10022 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10023#endif
10024 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010025#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010026 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10027#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010028#ifdef FEAT_SYN_HL
10029 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10030 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010031 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010032#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010033#ifdef FEAT_DIFF
10034 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10035#endif
10036#ifdef FEAT_FOLDING
10037 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10038 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10039 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10040 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10041 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10042 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10043 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10044# ifdef FEAT_EVAL
10045 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10046 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10047# endif
10048 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10049#endif
10050 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010051 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010052#ifdef FEAT_LINEBREAK
10053 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10054#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010055#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10057#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010058#ifdef FEAT_VERTSPLIT
10059 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10060#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010061#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10062 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10063#endif
10064#ifdef FEAT_RIGHTLEFT
10065 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10066 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10067#endif
10068 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10069 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10070#ifdef FEAT_LINEBREAK
10071 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010072 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10073 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010074#endif
10075#ifdef FEAT_SCROLLBIND
10076 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10077#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010078#ifdef FEAT_CURSORBIND
10079 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10080#endif
10081#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010082 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10083 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010085
10086 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10087 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10088#ifdef FEAT_MBYTE
10089 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10090#endif
10091#if defined(FEAT_QUICKFIX)
10092 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10093 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10094#endif
10095 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10096 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10097#ifdef FEAT_CINDENT
10098 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10099 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10100 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10101#endif
10102#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10103 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10104#endif
10105#ifdef FEAT_COMMENTS
10106 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10107#endif
10108#ifdef FEAT_FOLDING
10109 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10110#endif
10111#ifdef FEAT_INS_EXPAND
10112 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10113#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010114#ifdef FEAT_COMPL_FUNC
10115 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010116 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010117#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010118 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10119 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10120#ifdef FEAT_MBYTE
10121 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10122#endif
10123 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10124#ifdef FEAT_AUTOCMD
10125 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10126#endif
10127 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010128 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10130 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10131 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10132 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10133#ifdef FEAT_FIND_ID
10134# ifdef FEAT_EVAL
10135 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10136# endif
10137#endif
10138#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10139 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10140 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10141#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010142#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010143 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145#ifdef FEAT_CRYPT
10146 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10147#endif
10148#ifdef FEAT_LISP
10149 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10150#endif
10151 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10152 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10153 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10154 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10155 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010156 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010157#ifdef FEAT_TEXTOBJ
10158 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10159#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10161#ifdef FEAT_SMARTINDENT
10162 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10163#endif
10164#ifndef SHORT_FNAME
10165 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10166#endif
10167 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10168#ifdef FEAT_SEARCHPATH
10169 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10170#endif
10171 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10172#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010173 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010174 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10175#endif
10176#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010177 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10178 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10179 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180#endif
10181 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10182 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10183 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10184 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010185#ifdef FEAT_PERSISTENT_UNDO
10186 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10187#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10189#ifdef FEAT_KEYMAP
10190 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10191#endif
10192 default: EMSG(_("E356: get_varp ERROR"));
10193 }
10194 /* always return a valid pointer to avoid a crash! */
10195 return (char_u *)&(curbuf->b_p_wm);
10196}
10197
10198/*
10199 * Get the value of 'equalprg', either the buffer-local one or the global one.
10200 */
10201 char_u *
10202get_equalprg()
10203{
10204 if (*curbuf->b_p_ep == NUL)
10205 return p_ep;
10206 return curbuf->b_p_ep;
10207}
10208
10209#if defined(FEAT_WINDOWS) || defined(PROTO)
10210/*
10211 * Copy options from one window to another.
10212 * Used when splitting a window.
10213 */
10214 void
10215win_copy_options(wp_from, wp_to)
10216 win_T *wp_from;
10217 win_T *wp_to;
10218{
10219 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10220 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10221# ifdef FEAT_RIGHTLEFT
10222# ifdef FEAT_FKMAP
10223 /* Is this right? */
10224 wp_to->w_farsi = wp_from->w_farsi;
10225# endif
10226# endif
10227}
10228#endif
10229
10230/*
10231 * Copy the options from one winopt_T to another.
10232 * Doesn't free the old option values in "to", use clear_winopt() for that.
10233 * The 'scroll' option is not copied, because it depends on the window height.
10234 * The 'previewwindow' option is reset, there can be only one preview window.
10235 */
10236 void
10237copy_winopt(from, to)
10238 winopt_T *from;
10239 winopt_T *to;
10240{
10241#ifdef FEAT_ARABIC
10242 to->wo_arab = from->wo_arab;
10243#endif
10244 to->wo_list = from->wo_list;
10245 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010246 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010247#ifdef FEAT_LINEBREAK
10248 to->wo_nuw = from->wo_nuw;
10249#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010250#ifdef FEAT_RIGHTLEFT
10251 to->wo_rl = from->wo_rl;
10252 to->wo_rlc = vim_strsave(from->wo_rlc);
10253#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010254#ifdef FEAT_STL_OPT
10255 to->wo_stl = vim_strsave(from->wo_stl);
10256#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010258#ifdef FEAT_DIFF
10259 to->wo_wrap_save = from->wo_wrap_save;
10260#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261#ifdef FEAT_LINEBREAK
10262 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010263 to->wo_bri = from->wo_bri;
10264 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010265#endif
10266#ifdef FEAT_SCROLLBIND
10267 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010268 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010270#ifdef FEAT_CURSORBIND
10271 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010272 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010273#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010274#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010275 to->wo_spell = from->wo_spell;
10276#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010277#ifdef FEAT_SYN_HL
10278 to->wo_cuc = from->wo_cuc;
10279 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010280 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010281#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010282#ifdef FEAT_DIFF
10283 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010284 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010285#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010286#ifdef FEAT_CONCEAL
10287 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010288 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290#ifdef FEAT_FOLDING
10291 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010292 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010293 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010294 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010295 to->wo_fdi = vim_strsave(from->wo_fdi);
10296 to->wo_fml = from->wo_fml;
10297 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010298 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010299 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010300 to->wo_fdm_save = from->wo_diff_saved
10301 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 to->wo_fdn = from->wo_fdn;
10303# ifdef FEAT_EVAL
10304 to->wo_fde = vim_strsave(from->wo_fde);
10305 to->wo_fdt = vim_strsave(from->wo_fdt);
10306# endif
10307 to->wo_fmr = vim_strsave(from->wo_fmr);
10308#endif
10309 check_winopt(to); /* don't want NULL pointers */
10310}
10311
10312/*
10313 * Check string options in a window for a NULL value.
10314 */
10315 void
10316check_win_options(win)
10317 win_T *win;
10318{
10319 check_winopt(&win->w_onebuf_opt);
10320 check_winopt(&win->w_allbuf_opt);
10321}
10322
10323/*
10324 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10325 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010326 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010327check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010328 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329{
10330#ifdef FEAT_FOLDING
10331 check_string_option(&wop->wo_fdi);
10332 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010333 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010334# ifdef FEAT_EVAL
10335 check_string_option(&wop->wo_fde);
10336 check_string_option(&wop->wo_fdt);
10337# endif
10338 check_string_option(&wop->wo_fmr);
10339#endif
10340#ifdef FEAT_RIGHTLEFT
10341 check_string_option(&wop->wo_rlc);
10342#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010343#ifdef FEAT_STL_OPT
10344 check_string_option(&wop->wo_stl);
10345#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010346#ifdef FEAT_SYN_HL
10347 check_string_option(&wop->wo_cc);
10348#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010349#ifdef FEAT_CONCEAL
10350 check_string_option(&wop->wo_cocu);
10351#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010352#ifdef FEAT_LINEBREAK
10353 check_string_option(&wop->wo_briopt);
10354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010355}
10356
10357/*
10358 * Free the allocated memory inside a winopt_T.
10359 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010360 void
10361clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010362 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363{
10364#ifdef FEAT_FOLDING
10365 clear_string_option(&wop->wo_fdi);
10366 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010367 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010368# ifdef FEAT_EVAL
10369 clear_string_option(&wop->wo_fde);
10370 clear_string_option(&wop->wo_fdt);
10371# endif
10372 clear_string_option(&wop->wo_fmr);
10373#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010374#ifdef FEAT_LINEBREAK
10375 clear_string_option(&wop->wo_briopt);
10376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010377#ifdef FEAT_RIGHTLEFT
10378 clear_string_option(&wop->wo_rlc);
10379#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010380#ifdef FEAT_STL_OPT
10381 clear_string_option(&wop->wo_stl);
10382#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010383#ifdef FEAT_SYN_HL
10384 clear_string_option(&wop->wo_cc);
10385#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010386#ifdef FEAT_CONCEAL
10387 clear_string_option(&wop->wo_cocu);
10388#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010389}
10390
10391/*
10392 * Copy global option values to local options for one buffer.
10393 * Used when creating a new buffer and sometimes when entering a buffer.
10394 * flags:
10395 * BCO_ENTER We will enter the buf buffer.
10396 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10397 * appropriate.
10398 * BCO_NOHELP Don't copy the values to a help buffer.
10399 */
10400 void
10401buf_copy_options(buf, flags)
10402 buf_T *buf;
10403 int flags;
10404{
10405 int should_copy = TRUE;
10406 char_u *save_p_isk = NULL; /* init for GCC */
10407 int dont_do_help;
10408 int did_isk = FALSE;
10409
10410 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010411 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010412 */
10413 if (buf == NULL || !buf_valid(buf))
10414 return;
10415
10416 /*
10417 * Skip this when the option defaults have not been set yet. Happens when
10418 * main() allocates the first buffer.
10419 */
10420 if (p_cpo != NULL)
10421 {
10422 /*
10423 * Always copy when entering and 'cpo' contains 'S'.
10424 * Don't copy when already initialized.
10425 * Don't copy when 'cpo' contains 's' and not entering.
10426 * 'S' BCO_ENTER initialized 's' should_copy
10427 * yes yes X X TRUE
10428 * yes no yes X FALSE
10429 * no X yes X FALSE
10430 * X no no yes FALSE
10431 * X no no no TRUE
10432 * no yes no X TRUE
10433 */
10434 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10435 && (buf->b_p_initialized
10436 || (!(flags & BCO_ENTER)
10437 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10438 should_copy = FALSE;
10439
10440 if (should_copy || (flags & BCO_ALWAYS))
10441 {
10442 /* Don't copy the options specific to a help buffer when
10443 * BCO_NOHELP is given or the options were initialized already
10444 * (jumping back to a help file with CTRL-T or CTRL-O) */
10445 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10446 || buf->b_p_initialized;
10447 if (dont_do_help) /* don't free b_p_isk */
10448 {
10449 save_p_isk = buf->b_p_isk;
10450 buf->b_p_isk = NULL;
10451 }
10452 /*
10453 * Always free the allocated strings.
10454 * If not already initialized, set 'readonly' and copy 'fileformat'.
10455 */
10456 if (!buf->b_p_initialized)
10457 {
10458 free_buf_options(buf, TRUE);
10459 buf->b_p_ro = FALSE; /* don't copy readonly */
10460 buf->b_p_tx = p_tx;
10461#ifdef FEAT_MBYTE
10462 buf->b_p_fenc = vim_strsave(p_fenc);
10463#endif
10464 buf->b_p_ff = vim_strsave(p_ff);
10465#if defined(FEAT_QUICKFIX)
10466 buf->b_p_bh = empty_option;
10467 buf->b_p_bt = empty_option;
10468#endif
10469 }
10470 else
10471 free_buf_options(buf, FALSE);
10472
10473 buf->b_p_ai = p_ai;
10474 buf->b_p_ai_nopaste = p_ai_nopaste;
10475 buf->b_p_sw = p_sw;
10476 buf->b_p_tw = p_tw;
10477 buf->b_p_tw_nopaste = p_tw_nopaste;
10478 buf->b_p_tw_nobin = p_tw_nobin;
10479 buf->b_p_wm = p_wm;
10480 buf->b_p_wm_nopaste = p_wm_nopaste;
10481 buf->b_p_wm_nobin = p_wm_nobin;
10482 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010483#ifdef FEAT_MBYTE
10484 buf->b_p_bomb = p_bomb;
10485#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486 buf->b_p_et = p_et;
10487 buf->b_p_et_nobin = p_et_nobin;
10488 buf->b_p_ml = p_ml;
10489 buf->b_p_ml_nobin = p_ml_nobin;
10490 buf->b_p_inf = p_inf;
10491 buf->b_p_swf = p_swf;
10492#ifdef FEAT_INS_EXPAND
10493 buf->b_p_cpt = vim_strsave(p_cpt);
10494#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010495#ifdef FEAT_COMPL_FUNC
10496 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010497 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499 buf->b_p_sts = p_sts;
10500 buf->b_p_sts_nopaste = p_sts_nopaste;
10501#ifndef SHORT_FNAME
10502 buf->b_p_sn = p_sn;
10503#endif
10504#ifdef FEAT_COMMENTS
10505 buf->b_p_com = vim_strsave(p_com);
10506#endif
10507#ifdef FEAT_FOLDING
10508 buf->b_p_cms = vim_strsave(p_cms);
10509#endif
10510 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010511 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512 buf->b_p_nf = vim_strsave(p_nf);
10513 buf->b_p_mps = vim_strsave(p_mps);
10514#ifdef FEAT_SMARTINDENT
10515 buf->b_p_si = p_si;
10516#endif
10517 buf->b_p_ci = p_ci;
10518#ifdef FEAT_CINDENT
10519 buf->b_p_cin = p_cin;
10520 buf->b_p_cink = vim_strsave(p_cink);
10521 buf->b_p_cino = vim_strsave(p_cino);
10522#endif
10523#ifdef FEAT_AUTOCMD
10524 /* Don't copy 'filetype', it must be detected */
10525 buf->b_p_ft = empty_option;
10526#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527 buf->b_p_pi = p_pi;
10528#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10529 buf->b_p_cinw = vim_strsave(p_cinw);
10530#endif
10531#ifdef FEAT_LISP
10532 buf->b_p_lisp = p_lisp;
10533#endif
10534#ifdef FEAT_SYN_HL
10535 /* Don't copy 'syntax', it must be set */
10536 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010537 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010538#endif
10539#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010540 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010541 (void)compile_cap_prog(&buf->b_s);
10542 buf->b_s.b_p_spf = vim_strsave(p_spf);
10543 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544#endif
10545#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10546 buf->b_p_inde = vim_strsave(p_inde);
10547 buf->b_p_indk = vim_strsave(p_indk);
10548#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010549#if defined(FEAT_EVAL)
10550 buf->b_p_fex = vim_strsave(p_fex);
10551#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552#ifdef FEAT_CRYPT
10553 buf->b_p_key = vim_strsave(p_key);
10554#endif
10555#ifdef FEAT_SEARCHPATH
10556 buf->b_p_sua = vim_strsave(p_sua);
10557#endif
10558#ifdef FEAT_KEYMAP
10559 buf->b_p_keymap = vim_strsave(p_keymap);
10560 buf->b_kmap_state |= KEYMAP_INIT;
10561#endif
10562 /* This isn't really an option, but copying the langmap and IME
10563 * state from the current buffer is better than resetting it. */
10564 buf->b_p_iminsert = p_iminsert;
10565 buf->b_p_imsearch = p_imsearch;
10566
10567 /* options that are normally global but also have a local value
10568 * are not copied, start using the global value */
10569 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010570 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010571#ifdef FEAT_QUICKFIX
10572 buf->b_p_gp = empty_option;
10573 buf->b_p_mp = empty_option;
10574 buf->b_p_efm = empty_option;
10575#endif
10576 buf->b_p_ep = empty_option;
10577 buf->b_p_kp = empty_option;
10578 buf->b_p_path = empty_option;
10579 buf->b_p_tags = empty_option;
10580#ifdef FEAT_FIND_ID
10581 buf->b_p_def = empty_option;
10582 buf->b_p_inc = empty_option;
10583# ifdef FEAT_EVAL
10584 buf->b_p_inex = vim_strsave(p_inex);
10585# endif
10586#endif
10587#ifdef FEAT_INS_EXPAND
10588 buf->b_p_dict = empty_option;
10589 buf->b_p_tsr = empty_option;
10590#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010591#ifdef FEAT_TEXTOBJ
10592 buf->b_p_qe = vim_strsave(p_qe);
10593#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010594#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10595 buf->b_p_bexpr = empty_option;
10596#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010597#if defined(FEAT_CRYPT)
10598 buf->b_p_cm = empty_option;
10599#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010600#ifdef FEAT_PERSISTENT_UNDO
10601 buf->b_p_udf = p_udf;
10602#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010603#ifdef FEAT_LISP
10604 buf->b_p_lw = empty_option;
10605#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606
10607 /*
10608 * Don't copy the options set by ex_help(), use the saved values,
10609 * when going from a help buffer to a non-help buffer.
10610 * Don't touch these at all when BCO_NOHELP is used and going from
10611 * or to a help buffer.
10612 */
10613 if (dont_do_help)
10614 buf->b_p_isk = save_p_isk;
10615 else
10616 {
10617 buf->b_p_isk = vim_strsave(p_isk);
10618 did_isk = TRUE;
10619 buf->b_p_ts = p_ts;
10620 buf->b_help = FALSE;
10621#ifdef FEAT_QUICKFIX
10622 if (buf->b_p_bt[0] == 'h')
10623 clear_string_option(&buf->b_p_bt);
10624#endif
10625 buf->b_p_ma = p_ma;
10626 }
10627 }
10628
10629 /*
10630 * When the options should be copied (ignoring BCO_ALWAYS), set the
10631 * flag that indicates that the options have been initialized.
10632 */
10633 if (should_copy)
10634 buf->b_p_initialized = TRUE;
10635 }
10636
10637 check_buf_options(buf); /* make sure we don't have NULLs */
10638 if (did_isk)
10639 (void)buf_init_chartab(buf, FALSE);
10640}
10641
10642/*
10643 * Reset the 'modifiable' option and its default value.
10644 */
10645 void
10646reset_modifiable()
10647{
10648 int opt_idx;
10649
10650 curbuf->b_p_ma = FALSE;
10651 p_ma = FALSE;
10652 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010653 if (opt_idx >= 0)
10654 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655}
10656
10657/*
10658 * Set the global value for 'iminsert' to the local value.
10659 */
10660 void
10661set_iminsert_global()
10662{
10663 p_iminsert = curbuf->b_p_iminsert;
10664}
10665
10666/*
10667 * Set the global value for 'imsearch' to the local value.
10668 */
10669 void
10670set_imsearch_global()
10671{
10672 p_imsearch = curbuf->b_p_imsearch;
10673}
10674
10675#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10676static int expand_option_idx = -1;
10677static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10678static int expand_option_flags = 0;
10679
10680 void
10681set_context_in_set_cmd(xp, arg, opt_flags)
10682 expand_T *xp;
10683 char_u *arg;
10684 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10685{
10686 int nextchar;
10687 long_u flags = 0; /* init for GCC */
10688 int opt_idx = 0; /* init for GCC */
10689 char_u *p;
10690 char_u *s;
10691 int is_term_option = FALSE;
10692 int key;
10693
10694 expand_option_flags = opt_flags;
10695
10696 xp->xp_context = EXPAND_SETTINGS;
10697 if (*arg == NUL)
10698 {
10699 xp->xp_pattern = arg;
10700 return;
10701 }
10702 p = arg + STRLEN(arg) - 1;
10703 if (*p == ' ' && *(p - 1) != '\\')
10704 {
10705 xp->xp_pattern = p + 1;
10706 return;
10707 }
10708 while (p > arg)
10709 {
10710 s = p;
10711 /* count number of backslashes before ' ' or ',' */
10712 if (*p == ' ' || *p == ',')
10713 {
10714 while (s > arg && *(s - 1) == '\\')
10715 --s;
10716 }
10717 /* break at a space with an even number of backslashes */
10718 if (*p == ' ' && ((p - s) & 1) == 0)
10719 {
10720 ++p;
10721 break;
10722 }
10723 --p;
10724 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010725 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010726 {
10727 xp->xp_context = EXPAND_BOOL_SETTINGS;
10728 p += 2;
10729 }
10730 if (STRNCMP(p, "inv", 3) == 0)
10731 {
10732 xp->xp_context = EXPAND_BOOL_SETTINGS;
10733 p += 3;
10734 }
10735 xp->xp_pattern = arg = p;
10736 if (*arg == '<')
10737 {
10738 while (*p != '>')
10739 if (*p++ == NUL) /* expand terminal option name */
10740 return;
10741 key = get_special_key_code(arg + 1);
10742 if (key == 0) /* unknown name */
10743 {
10744 xp->xp_context = EXPAND_NOTHING;
10745 return;
10746 }
10747 nextchar = *++p;
10748 is_term_option = TRUE;
10749 expand_option_name[2] = KEY2TERMCAP0(key);
10750 expand_option_name[3] = KEY2TERMCAP1(key);
10751 }
10752 else
10753 {
10754 if (p[0] == 't' && p[1] == '_')
10755 {
10756 p += 2;
10757 if (*p != NUL)
10758 ++p;
10759 if (*p == NUL)
10760 return; /* expand option name */
10761 nextchar = *++p;
10762 is_term_option = TRUE;
10763 expand_option_name[2] = p[-2];
10764 expand_option_name[3] = p[-1];
10765 }
10766 else
10767 {
10768 /* Allow * wildcard */
10769 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10770 p++;
10771 if (*p == NUL)
10772 return;
10773 nextchar = *p;
10774 *p = NUL;
10775 opt_idx = findoption(arg);
10776 *p = nextchar;
10777 if (opt_idx == -1 || options[opt_idx].var == NULL)
10778 {
10779 xp->xp_context = EXPAND_NOTHING;
10780 return;
10781 }
10782 flags = options[opt_idx].flags;
10783 if (flags & P_BOOL)
10784 {
10785 xp->xp_context = EXPAND_NOTHING;
10786 return;
10787 }
10788 }
10789 }
10790 /* handle "-=" and "+=" */
10791 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10792 {
10793 ++p;
10794 nextchar = '=';
10795 }
10796 if ((nextchar != '=' && nextchar != ':')
10797 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10798 {
10799 xp->xp_context = EXPAND_UNSUCCESSFUL;
10800 return;
10801 }
10802 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10803 {
10804 xp->xp_context = EXPAND_OLD_SETTING;
10805 if (is_term_option)
10806 expand_option_idx = -1;
10807 else
10808 expand_option_idx = opt_idx;
10809 xp->xp_pattern = p + 1;
10810 return;
10811 }
10812 xp->xp_context = EXPAND_NOTHING;
10813 if (is_term_option || (flags & P_NUM))
10814 return;
10815
10816 xp->xp_pattern = p + 1;
10817
10818 if (flags & P_EXPAND)
10819 {
10820 p = options[opt_idx].var;
10821 if (p == (char_u *)&p_bdir
10822 || p == (char_u *)&p_dir
10823 || p == (char_u *)&p_path
10824 || p == (char_u *)&p_rtp
10825#ifdef FEAT_SEARCHPATH
10826 || p == (char_u *)&p_cdpath
10827#endif
10828#ifdef FEAT_SESSION
10829 || p == (char_u *)&p_vdir
10830#endif
10831 )
10832 {
10833 xp->xp_context = EXPAND_DIRECTORIES;
10834 if (p == (char_u *)&p_path
10835#ifdef FEAT_SEARCHPATH
10836 || p == (char_u *)&p_cdpath
10837#endif
10838 )
10839 xp->xp_backslash = XP_BS_THREE;
10840 else
10841 xp->xp_backslash = XP_BS_ONE;
10842 }
10843 else
10844 {
10845 xp->xp_context = EXPAND_FILES;
10846 /* for 'tags' need three backslashes for a space */
10847 if (p == (char_u *)&p_tags)
10848 xp->xp_backslash = XP_BS_THREE;
10849 else
10850 xp->xp_backslash = XP_BS_ONE;
10851 }
10852 }
10853
10854 /* For an option that is a list of file names, find the start of the
10855 * last file name. */
10856 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10857 {
10858 /* count number of backslashes before ' ' or ',' */
10859 if (*p == ' ' || *p == ',')
10860 {
10861 s = p;
10862 while (s > xp->xp_pattern && *(s - 1) == '\\')
10863 --s;
10864 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10865 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10866 {
10867 xp->xp_pattern = p + 1;
10868 break;
10869 }
10870 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010871
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010872#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010873 /* for 'spellsuggest' start at "file:" */
10874 if (options[opt_idx].var == (char_u *)&p_sps
10875 && STRNCMP(p, "file:", 5) == 0)
10876 {
10877 xp->xp_pattern = p + 5;
10878 break;
10879 }
10880#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010881 }
10882
10883 return;
10884}
10885
10886 int
10887ExpandSettings(xp, regmatch, num_file, file)
10888 expand_T *xp;
10889 regmatch_T *regmatch;
10890 int *num_file;
10891 char_u ***file;
10892{
10893 int num_normal = 0; /* Nr of matching non-term-code settings */
10894 int num_term = 0; /* Nr of matching terminal code settings */
10895 int opt_idx;
10896 int match;
10897 int count = 0;
10898 char_u *str;
10899 int loop;
10900 int is_term_opt;
10901 char_u name_buf[MAX_KEY_NAME_LEN];
10902 static char *(names[]) = {"all", "termcap"};
10903 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10904
10905 /* do this loop twice:
10906 * loop == 0: count the number of matching options
10907 * loop == 1: copy the matching options into allocated memory
10908 */
10909 for (loop = 0; loop <= 1; ++loop)
10910 {
10911 regmatch->rm_ic = ic;
10912 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10913 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010914 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10915 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10917 {
10918 if (loop == 0)
10919 num_normal++;
10920 else
10921 (*file)[count++] = vim_strsave((char_u *)names[match]);
10922 }
10923 }
10924 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10925 opt_idx++)
10926 {
10927 if (options[opt_idx].var == NULL)
10928 continue;
10929 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10930 && !(options[opt_idx].flags & P_BOOL))
10931 continue;
10932 is_term_opt = istermoption(&options[opt_idx]);
10933 if (is_term_opt && num_normal > 0)
10934 continue;
10935 match = FALSE;
10936 if (vim_regexec(regmatch, str, (colnr_T)0)
10937 || (options[opt_idx].shortname != NULL
10938 && vim_regexec(regmatch,
10939 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10940 match = TRUE;
10941 else if (is_term_opt)
10942 {
10943 name_buf[0] = '<';
10944 name_buf[1] = 't';
10945 name_buf[2] = '_';
10946 name_buf[3] = str[2];
10947 name_buf[4] = str[3];
10948 name_buf[5] = '>';
10949 name_buf[6] = NUL;
10950 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10951 {
10952 match = TRUE;
10953 str = name_buf;
10954 }
10955 }
10956 if (match)
10957 {
10958 if (loop == 0)
10959 {
10960 if (is_term_opt)
10961 num_term++;
10962 else
10963 num_normal++;
10964 }
10965 else
10966 (*file)[count++] = vim_strsave(str);
10967 }
10968 }
10969 /*
10970 * Check terminal key codes, these are not in the option table
10971 */
10972 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10973 {
10974 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10975 {
10976 if (!isprint(str[0]) || !isprint(str[1]))
10977 continue;
10978
10979 name_buf[0] = 't';
10980 name_buf[1] = '_';
10981 name_buf[2] = str[0];
10982 name_buf[3] = str[1];
10983 name_buf[4] = NUL;
10984
10985 match = FALSE;
10986 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10987 match = TRUE;
10988 else
10989 {
10990 name_buf[0] = '<';
10991 name_buf[1] = 't';
10992 name_buf[2] = '_';
10993 name_buf[3] = str[0];
10994 name_buf[4] = str[1];
10995 name_buf[5] = '>';
10996 name_buf[6] = NUL;
10997
10998 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10999 match = TRUE;
11000 }
11001 if (match)
11002 {
11003 if (loop == 0)
11004 num_term++;
11005 else
11006 (*file)[count++] = vim_strsave(name_buf);
11007 }
11008 }
11009
11010 /*
11011 * Check special key names.
11012 */
11013 regmatch->rm_ic = TRUE; /* ignore case here */
11014 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11015 {
11016 name_buf[0] = '<';
11017 STRCPY(name_buf + 1, str);
11018 STRCAT(name_buf, ">");
11019
11020 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11021 {
11022 if (loop == 0)
11023 num_term++;
11024 else
11025 (*file)[count++] = vim_strsave(name_buf);
11026 }
11027 }
11028 }
11029 if (loop == 0)
11030 {
11031 if (num_normal > 0)
11032 *num_file = num_normal;
11033 else if (num_term > 0)
11034 *num_file = num_term;
11035 else
11036 return OK;
11037 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11038 if (*file == NULL)
11039 {
11040 *file = (char_u **)"";
11041 return FAIL;
11042 }
11043 }
11044 }
11045 return OK;
11046}
11047
11048 int
11049ExpandOldSetting(num_file, file)
11050 int *num_file;
11051 char_u ***file;
11052{
11053 char_u *var = NULL; /* init for GCC */
11054 char_u *buf;
11055
11056 *num_file = 0;
11057 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11058 if (*file == NULL)
11059 return FAIL;
11060
11061 /*
11062 * For a terminal key code expand_option_idx is < 0.
11063 */
11064 if (expand_option_idx < 0)
11065 {
11066 var = find_termcode(expand_option_name + 2);
11067 if (var == NULL)
11068 expand_option_idx = findoption(expand_option_name);
11069 }
11070
11071 if (expand_option_idx >= 0)
11072 {
11073 /* put string of option value in NameBuff */
11074 option_value2string(&options[expand_option_idx], expand_option_flags);
11075 var = NameBuff;
11076 }
11077 else if (var == NULL)
11078 var = (char_u *)"";
11079
11080 /* A backslash is required before some characters. This is the reverse of
11081 * what happens in do_set(). */
11082 buf = vim_strsave_escaped(var, escape_chars);
11083
11084 if (buf == NULL)
11085 {
11086 vim_free(*file);
11087 *file = NULL;
11088 return FAIL;
11089 }
11090
11091#ifdef BACKSLASH_IN_FILENAME
11092 /* For MS-Windows et al. we don't double backslashes at the start and
11093 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011094 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095 if (var[0] == '\\' && var[1] == '\\'
11096 && expand_option_idx >= 0
11097 && (options[expand_option_idx].flags & P_EXPAND)
11098 && vim_isfilec(var[2])
11099 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011100 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011101#endif
11102
11103 *file[0] = buf;
11104 *num_file = 1;
11105 return OK;
11106}
11107#endif
11108
11109/*
11110 * Get the value for the numeric or string option *opp in a nice format into
11111 * NameBuff[]. Must not be called with a hidden option!
11112 */
11113 static void
11114option_value2string(opp, opt_flags)
11115 struct vimoption *opp;
11116 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11117{
11118 char_u *varp;
11119
11120 varp = get_varp_scope(opp, opt_flags);
11121
11122 if (opp->flags & P_NUM)
11123 {
11124 long wc = 0;
11125
11126 if (wc_use_keyname(varp, &wc))
11127 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11128 else if (wc != 0)
11129 STRCPY(NameBuff, transchar((int)wc));
11130 else
11131 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11132 }
11133 else /* P_STRING */
11134 {
11135 varp = *(char_u **)(varp);
11136 if (varp == NULL) /* just in case */
11137 NameBuff[0] = NUL;
11138#ifdef FEAT_CRYPT
11139 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011140 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011141 STRCPY(NameBuff, "*****");
11142#endif
11143 else if (opp->flags & P_EXPAND)
11144 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11145 /* Translate 'pastetoggle' into special key names */
11146 else if ((char_u **)opp->var == &p_pt)
11147 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11148 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011149 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011150 }
11151}
11152
11153/*
11154 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11155 * printed as a keyname.
11156 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11157 */
11158 static int
11159wc_use_keyname(varp, wcp)
11160 char_u *varp;
11161 long *wcp;
11162{
11163 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11164 {
11165 *wcp = *(long *)varp;
11166 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11167 return TRUE;
11168 }
11169 return FALSE;
11170}
11171
11172#ifdef FEAT_LANGMAP
11173/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011174 * Any character has an equivalent 'langmap' character. This is used for
11175 * keyboards that have a special language mode that sends characters above
11176 * 128 (although other characters can be translated too). The "to" field is a
11177 * Vim command character. This avoids having to switch the keyboard back to
11178 * ASCII mode when leaving Insert mode.
11179 *
11180 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11181 * commands.
11182 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11183 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11184 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011186# ifdef FEAT_MBYTE
11187/*
11188 * With multi-byte support use growarray for 'langmap' chars >= 256
11189 */
11190typedef struct
11191{
11192 int from;
11193 int to;
11194} langmap_entry_T;
11195
11196static garray_T langmap_mapga;
11197static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011198
11199/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011200 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11201 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011203 static void
11204langmap_set_entry(from, to)
11205 int from;
11206 int to;
11207{
11208 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011209 int a = 0;
11210 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011211
11212 /* Do a binary search for an existing entry. */
11213 while (a != b)
11214 {
11215 int i = (a + b) / 2;
11216 int d = entries[i].from - from;
11217
11218 if (d == 0)
11219 {
11220 entries[i].to = to;
11221 return;
11222 }
11223 if (d < 0)
11224 a = i + 1;
11225 else
11226 b = i;
11227 }
11228
11229 if (ga_grow(&langmap_mapga, 1) != OK)
11230 return; /* out of memory */
11231
11232 /* insert new entry at position "a" */
11233 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11234 mch_memmove(entries + 1, entries,
11235 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11236 ++langmap_mapga.ga_len;
11237 entries[0].from = from;
11238 entries[0].to = to;
11239}
11240
11241/*
11242 * Apply 'langmap' to multi-byte character "c" and return the result.
11243 */
11244 int
11245langmap_adjust_mb(c)
11246 int c;
11247{
11248 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11249 int a = 0;
11250 int b = langmap_mapga.ga_len;
11251
11252 while (a != b)
11253 {
11254 int i = (a + b) / 2;
11255 int d = entries[i].from - c;
11256
11257 if (d == 0)
11258 return entries[i].to; /* found matching entry */
11259 if (d < 0)
11260 a = i + 1;
11261 else
11262 b = i;
11263 }
11264 return c; /* no entry found, return "c" unmodified */
11265}
11266# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267
11268 static void
11269langmap_init()
11270{
11271 int i;
11272
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011273 for (i = 0; i < 256; i++)
11274 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11275# ifdef FEAT_MBYTE
11276 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11277# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278}
11279
11280/*
11281 * Called when langmap option is set; the language map can be
11282 * changed at any time!
11283 */
11284 static void
11285langmap_set()
11286{
11287 char_u *p;
11288 char_u *p2;
11289 int from, to;
11290
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011291#ifdef FEAT_MBYTE
11292 ga_clear(&langmap_mapga); /* clear the previous map first */
11293#endif
11294 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011295
11296 for (p = p_langmap; p[0] != NUL; )
11297 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011298 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11299 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011300 {
11301 if (p2[0] == '\\' && p2[1] != NUL)
11302 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011303 }
11304 if (p2[0] == ';')
11305 ++p2; /* abcd;ABCD form, p2 points to A */
11306 else
11307 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11308 while (p[0])
11309 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011310 if (p[0] == ',')
11311 {
11312 ++p;
11313 break;
11314 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315 if (p[0] == '\\' && p[1] != NUL)
11316 ++p;
11317#ifdef FEAT_MBYTE
11318 from = (*mb_ptr2char)(p);
11319#else
11320 from = p[0];
11321#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011322 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323 if (p2 == NULL)
11324 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011325 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011326 if (p[0] != ',')
11327 {
11328 if (p[0] == '\\')
11329 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011331 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011333 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011334#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011335 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011336 }
11337 else
11338 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011339 if (p2[0] != ',')
11340 {
11341 if (p2[0] == '\\')
11342 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011343#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011344 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011345#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011346 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011347#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011348 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349 }
11350 if (to == NUL)
11351 {
11352 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11353 transchar(from));
11354 return;
11355 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011356
11357#ifdef FEAT_MBYTE
11358 if (from >= 256)
11359 langmap_set_entry(from, to);
11360 else
11361#endif
11362 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011363
11364 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011365 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011366 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011367 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011368 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011369 if (*p == ';')
11370 {
11371 p = p2;
11372 if (p[0] != NUL)
11373 {
11374 if (p[0] != ',')
11375 {
11376 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11377 return;
11378 }
11379 ++p;
11380 }
11381 break;
11382 }
11383 }
11384 }
11385 }
11386}
11387#endif
11388
11389/*
11390 * Return TRUE if format option 'x' is in effect.
11391 * Take care of no formatting when 'paste' is set.
11392 */
11393 int
11394has_format_option(x)
11395 int x;
11396{
11397 if (p_paste)
11398 return FALSE;
11399 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11400}
11401
11402/*
11403 * Return TRUE if "x" is present in 'shortmess' option, or
11404 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11405 */
11406 int
11407shortmess(x)
11408 int x;
11409{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011410 return p_shm != NULL &&
11411 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011412 || (vim_strchr(p_shm, 'a') != NULL
11413 && vim_strchr((char_u *)SHM_A, x) != NULL));
11414}
11415
11416/*
11417 * paste_option_changed() - Called after p_paste was set or reset.
11418 */
11419 static void
11420paste_option_changed()
11421{
11422 static int old_p_paste = FALSE;
11423 static int save_sm = 0;
11424#ifdef FEAT_CMDL_INFO
11425 static int save_ru = 0;
11426#endif
11427#ifdef FEAT_RIGHTLEFT
11428 static int save_ri = 0;
11429 static int save_hkmap = 0;
11430#endif
11431 buf_T *buf;
11432
11433 if (p_paste)
11434 {
11435 /*
11436 * Paste switched from off to on.
11437 * Save the current values, so they can be restored later.
11438 */
11439 if (!old_p_paste)
11440 {
11441 /* save options for each buffer */
11442 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11443 {
11444 buf->b_p_tw_nopaste = buf->b_p_tw;
11445 buf->b_p_wm_nopaste = buf->b_p_wm;
11446 buf->b_p_sts_nopaste = buf->b_p_sts;
11447 buf->b_p_ai_nopaste = buf->b_p_ai;
11448 }
11449
11450 /* save global options */
11451 save_sm = p_sm;
11452#ifdef FEAT_CMDL_INFO
11453 save_ru = p_ru;
11454#endif
11455#ifdef FEAT_RIGHTLEFT
11456 save_ri = p_ri;
11457 save_hkmap = p_hkmap;
11458#endif
11459 /* save global values for local buffer options */
11460 p_tw_nopaste = p_tw;
11461 p_wm_nopaste = p_wm;
11462 p_sts_nopaste = p_sts;
11463 p_ai_nopaste = p_ai;
11464 }
11465
11466 /*
11467 * Always set the option values, also when 'paste' is set when it is
11468 * already on.
11469 */
11470 /* set options for each buffer */
11471 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11472 {
11473 buf->b_p_tw = 0; /* textwidth is 0 */
11474 buf->b_p_wm = 0; /* wrapmargin is 0 */
11475 buf->b_p_sts = 0; /* softtabstop is 0 */
11476 buf->b_p_ai = 0; /* no auto-indent */
11477 }
11478
11479 /* set global options */
11480 p_sm = 0; /* no showmatch */
11481#ifdef FEAT_CMDL_INFO
11482# ifdef FEAT_WINDOWS
11483 if (p_ru)
11484 status_redraw_all(); /* redraw to remove the ruler */
11485# endif
11486 p_ru = 0; /* no ruler */
11487#endif
11488#ifdef FEAT_RIGHTLEFT
11489 p_ri = 0; /* no reverse insert */
11490 p_hkmap = 0; /* no Hebrew keyboard */
11491#endif
11492 /* set global values for local buffer options */
11493 p_tw = 0;
11494 p_wm = 0;
11495 p_sts = 0;
11496 p_ai = 0;
11497 }
11498
11499 /*
11500 * Paste switched from on to off: Restore saved values.
11501 */
11502 else if (old_p_paste)
11503 {
11504 /* restore options for each buffer */
11505 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11506 {
11507 buf->b_p_tw = buf->b_p_tw_nopaste;
11508 buf->b_p_wm = buf->b_p_wm_nopaste;
11509 buf->b_p_sts = buf->b_p_sts_nopaste;
11510 buf->b_p_ai = buf->b_p_ai_nopaste;
11511 }
11512
11513 /* restore global options */
11514 p_sm = save_sm;
11515#ifdef FEAT_CMDL_INFO
11516# ifdef FEAT_WINDOWS
11517 if (p_ru != save_ru)
11518 status_redraw_all(); /* redraw to draw the ruler */
11519# endif
11520 p_ru = save_ru;
11521#endif
11522#ifdef FEAT_RIGHTLEFT
11523 p_ri = save_ri;
11524 p_hkmap = save_hkmap;
11525#endif
11526 /* set global values for local buffer options */
11527 p_tw = p_tw_nopaste;
11528 p_wm = p_wm_nopaste;
11529 p_sts = p_sts_nopaste;
11530 p_ai = p_ai_nopaste;
11531 }
11532
11533 old_p_paste = p_paste;
11534}
11535
11536/*
11537 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11538 *
11539 * Reset 'compatible' and set the values for options that didn't get set yet
11540 * to the Vim defaults.
11541 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011542 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011543 */
11544 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011545vimrc_found(fname, envname)
11546 char_u *fname;
11547 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011548{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011549 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011550 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011551 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011552
11553 if (!option_was_set((char_u *)"cp"))
11554 {
11555 p_cp = FALSE;
11556 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11557 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11558 set_option_default(opt_idx, OPT_FREE, FALSE);
11559 didset_options();
11560 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011561
11562 if (fname != NULL)
11563 {
11564 p = vim_getenv(envname, &dofree);
11565 if (p == NULL)
11566 {
11567 /* Set $MYVIMRC to the first vimrc file found. */
11568 p = FullName_save(fname, FALSE);
11569 if (p != NULL)
11570 {
11571 vim_setenv(envname, p);
11572 vim_free(p);
11573 }
11574 }
11575 else if (dofree)
11576 vim_free(p);
11577 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011578}
11579
11580/*
11581 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11582 */
11583 void
11584change_compatible(on)
11585 int on;
11586{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011587 int opt_idx;
11588
Bram Moolenaar071d4272004-06-13 20:20:40 +000011589 if (p_cp != on)
11590 {
11591 p_cp = on;
11592 compatible_set();
11593 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011594 opt_idx = findoption((char_u *)"cp");
11595 if (opt_idx >= 0)
11596 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011597}
11598
11599/*
11600 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011601 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011602 */
11603 int
11604option_was_set(name)
11605 char_u *name;
11606{
11607 int idx;
11608
11609 idx = findoption(name);
11610 if (idx < 0) /* unknown option */
11611 return FALSE;
11612 if (options[idx].flags & P_WAS_SET)
11613 return TRUE;
11614 return FALSE;
11615}
11616
11617/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011618 * Reset the flag indicating option "name" was set.
11619 */
11620 void
11621reset_option_was_set(name)
11622 char_u *name;
11623{
11624 int idx = findoption(name);
11625
11626 if (idx >= 0)
11627 options[idx].flags &= ~P_WAS_SET;
11628}
11629
11630/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011631 * compatible_set() - Called when 'compatible' has been set or unset.
11632 *
11633 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11634 * flag) to a Vi compatible value.
11635 * When 'compatible' is unset: Set all options that have a different default
11636 * for Vim (without the P_VI_DEF flag) to that default.
11637 */
11638 static void
11639compatible_set()
11640{
11641 int opt_idx;
11642
11643 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11644 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11645 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11646 set_option_default(opt_idx, OPT_FREE, p_cp);
11647 didset_options();
11648}
11649
11650#ifdef FEAT_LINEBREAK
11651
11652# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11653 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011654 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011655# endif
11656
11657/*
11658 * fill_breakat_flags() -- called when 'breakat' changes value.
11659 */
11660 static void
11661fill_breakat_flags()
11662{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011663 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011664 int i;
11665
11666 for (i = 0; i < 256; i++)
11667 breakat_flags[i] = FALSE;
11668
11669 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011670 for (p = p_breakat; *p; p++)
11671 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011672}
11673
11674# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011675 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011676# endif
11677
11678#endif
11679
11680/*
11681 * Check an option that can be a range of string values.
11682 *
11683 * Return OK for correct value, FAIL otherwise.
11684 * Empty is always OK.
11685 */
11686 static int
11687check_opt_strings(val, values, list)
11688 char_u *val;
11689 char **values;
11690 int list; /* when TRUE: accept a list of values */
11691{
11692 return opt_strings_flags(val, values, NULL, list);
11693}
11694
11695/*
11696 * Handle an option that can be a range of string values.
11697 * Set a flag in "*flagp" for each string present.
11698 *
11699 * Return OK for correct value, FAIL otherwise.
11700 * Empty is always OK.
11701 */
11702 static int
11703opt_strings_flags(val, values, flagp, list)
11704 char_u *val; /* new value */
11705 char **values; /* array of valid string values */
11706 unsigned *flagp;
11707 int list; /* when TRUE: accept a list of values */
11708{
11709 int i;
11710 int len;
11711 unsigned new_flags = 0;
11712
11713 while (*val)
11714 {
11715 for (i = 0; ; ++i)
11716 {
11717 if (values[i] == NULL) /* val not found in values[] */
11718 return FAIL;
11719
11720 len = (int)STRLEN(values[i]);
11721 if (STRNCMP(values[i], val, len) == 0
11722 && ((list && val[len] == ',') || val[len] == NUL))
11723 {
11724 val += len + (val[len] == ',');
11725 new_flags |= (1 << i);
11726 break; /* check next item in val list */
11727 }
11728 }
11729 }
11730 if (flagp != NULL)
11731 *flagp = new_flags;
11732
11733 return OK;
11734}
11735
11736/*
11737 * Read the 'wildmode' option, fill wim_flags[].
11738 */
11739 static int
11740check_opt_wim()
11741{
11742 char_u new_wim_flags[4];
11743 char_u *p;
11744 int i;
11745 int idx = 0;
11746
11747 for (i = 0; i < 4; ++i)
11748 new_wim_flags[i] = 0;
11749
11750 for (p = p_wim; *p; ++p)
11751 {
11752 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11753 ;
11754 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11755 return FAIL;
11756 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11757 new_wim_flags[idx] |= WIM_LONGEST;
11758 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11759 new_wim_flags[idx] |= WIM_FULL;
11760 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11761 new_wim_flags[idx] |= WIM_LIST;
11762 else
11763 return FAIL;
11764 p += i;
11765 if (*p == NUL)
11766 break;
11767 if (*p == ',')
11768 {
11769 if (idx == 3)
11770 return FAIL;
11771 ++idx;
11772 }
11773 }
11774
11775 /* fill remaining entries with last flag */
11776 while (idx < 3)
11777 {
11778 new_wim_flags[idx + 1] = new_wim_flags[idx];
11779 ++idx;
11780 }
11781
11782 /* only when there are no errors, wim_flags[] is changed */
11783 for (i = 0; i < 4; ++i)
11784 wim_flags[i] = new_wim_flags[i];
11785 return OK;
11786}
11787
11788/*
11789 * Check if backspacing over something is allowed.
11790 */
11791 int
11792can_bs(what)
11793 int what; /* BS_INDENT, BS_EOL or BS_START */
11794{
11795 switch (*p_bs)
11796 {
11797 case '2': return TRUE;
11798 case '1': return (what != BS_START);
11799 case '0': return FALSE;
11800 }
11801 return vim_strchr(p_bs, what) != NULL;
11802}
11803
11804/*
11805 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11806 * the file must be considered changed when the value is different.
11807 */
11808 void
11809save_file_ff(buf)
11810 buf_T *buf;
11811{
11812 buf->b_start_ffc = *buf->b_p_ff;
11813 buf->b_start_eol = buf->b_p_eol;
11814#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011815 buf->b_start_bomb = buf->b_p_bomb;
11816
Bram Moolenaar071d4272004-06-13 20:20:40 +000011817 /* Only use free/alloc when necessary, they take time. */
11818 if (buf->b_start_fenc == NULL
11819 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11820 {
11821 vim_free(buf->b_start_fenc);
11822 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11823 }
11824#endif
11825}
11826
11827/*
11828 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11829 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011830 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11831 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011832 * When "ignore_empty" is true don't consider a new, empty buffer to be
11833 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011834 */
11835 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011836file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011837 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011838 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011839{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011840 /* In a buffer that was never loaded the options are not valid. */
11841 if (buf->b_flags & BF_NEVERLOADED)
11842 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011843 if (ignore_empty
11844 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845 && buf->b_ml.ml_line_count == 1
11846 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11847 return FALSE;
11848 if (buf->b_start_ffc != *buf->b_p_ff)
11849 return TRUE;
11850 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11851 return TRUE;
11852#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011853 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11854 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855 if (buf->b_start_fenc == NULL)
11856 return (*buf->b_p_fenc != NUL);
11857 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11858#else
11859 return FALSE;
11860#endif
11861}
11862
11863/*
11864 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11865 */
11866 int
11867check_ff_value(p)
11868 char_u *p;
11869{
11870 return check_opt_strings(p, p_ff_values, FALSE);
11871}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011872
11873/*
11874 * Return the effective shiftwidth value for current buffer, using the
11875 * 'tabstop' value when 'shiftwidth' is zero.
11876 */
11877 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011878get_sw_value(buf)
11879 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011880{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011881 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011882}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011883
11884/*
11885 * Return the effective softtabstop value for the current buffer, using the
11886 * 'tabstop' value when 'softtabstop' is negative.
11887 */
11888 long
11889get_sts_value()
11890{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011891 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011892}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011893
11894/*
11895 * Check matchpairs option for "*initc".
11896 * If there is a match set "*initc" to the matching character and "*findc" to
11897 * the opposite character. Set "*backwards" to the direction.
11898 * When "switchit" is TRUE swap the direction.
11899 */
11900 void
11901find_mps_values(initc, findc, backwards, switchit)
11902 int *initc;
11903 int *findc;
11904 int *backwards;
11905 int switchit;
11906{
11907 char_u *ptr;
11908
11909 ptr = curbuf->b_p_mps;
11910 while (*ptr != NUL)
11911 {
11912#ifdef FEAT_MBYTE
11913 if (has_mbyte)
11914 {
11915 char_u *prev;
11916
11917 if (mb_ptr2char(ptr) == *initc)
11918 {
11919 if (switchit)
11920 {
11921 *findc = *initc;
11922 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11923 *backwards = TRUE;
11924 }
11925 else
11926 {
11927 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11928 *backwards = FALSE;
11929 }
11930 return;
11931 }
11932 prev = ptr;
11933 ptr += mb_ptr2len(ptr) + 1;
11934 if (mb_ptr2char(ptr) == *initc)
11935 {
11936 if (switchit)
11937 {
11938 *findc = *initc;
11939 *initc = mb_ptr2char(prev);
11940 *backwards = FALSE;
11941 }
11942 else
11943 {
11944 *findc = mb_ptr2char(prev);
11945 *backwards = TRUE;
11946 }
11947 return;
11948 }
11949 ptr += mb_ptr2len(ptr);
11950 }
11951 else
11952#endif
11953 {
11954 if (*ptr == *initc)
11955 {
11956 if (switchit)
11957 {
11958 *backwards = TRUE;
11959 *findc = *initc;
11960 *initc = ptr[2];
11961 }
11962 else
11963 {
11964 *backwards = FALSE;
11965 *findc = ptr[2];
11966 }
11967 return;
11968 }
11969 ptr += 2;
11970 if (*ptr == *initc)
11971 {
11972 if (switchit)
11973 {
11974 *backwards = FALSE;
11975 *findc = *initc;
11976 *initc = ptr[-2];
11977 }
11978 else
11979 {
11980 *backwards = TRUE;
11981 *findc = ptr[-2];
11982 }
11983 return;
11984 }
11985 ++ptr;
11986 }
11987 if (*ptr == ',')
11988 ++ptr;
11989 }
11990}
Bram Moolenaar597a4222014-06-25 14:39:50 +020011991
11992#if defined(FEAT_LINEBREAK) || defined(PROTO)
11993/*
11994 * This is called when 'breakindentopt' is changed and when a window is
11995 * initialized.
11996 */
11997 int
11998briopt_check()
11999{
12000 char_u *p;
12001 int bri_shift = 0;
12002 long bri_min = 20;
12003 int bri_sbr = FALSE;
12004
12005 p = curwin->w_p_briopt;
12006 while (*p != NUL)
12007 {
12008 if (STRNCMP(p, "shift:", 6) == 0
12009 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12010 {
12011 p += 6;
12012 bri_shift = getdigits(&p);
12013 }
12014 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12015 {
12016 p += 4;
12017 bri_min = getdigits(&p);
12018 }
12019 else if (STRNCMP(p, "sbr", 3) == 0)
12020 {
12021 p += 3;
12022 bri_sbr = TRUE;
12023 }
12024 if (*p != ',' && *p != NUL)
12025 return FAIL;
12026 if (*p == ',')
12027 ++p;
12028 }
12029
12030 curwin->w_p_brishift = bri_shift;
12031 curwin->w_p_brimin = bri_min;
12032 curwin->w_p_brisbr = bri_sbr;
12033
12034 return OK;
12035}
12036#endif