blob: f928b3ba941dd5b112c249c58fef05a240359150 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000059#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000060# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000061# define PV_BT OPT_BUF(BV_BT)
62# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
63# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
64# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000065#endif
66#define PV_BIN OPT_BUF(BV_BIN)
67#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000068#ifdef FEAT_MBYTE
69# define PV_BOMB OPT_BUF(BV_BOMB)
70#endif
71#define PV_CI OPT_BUF(BV_CI)
72#ifdef FEAT_CINDENT
73# define PV_CIN OPT_BUF(BV_CIN)
74# define PV_CINK OPT_BUF(BV_CINK)
75# define PV_CINO OPT_BUF(BV_CINO)
76#endif
77#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
78# define PV_CINW OPT_BUF(BV_CINW)
79#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020080#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000081#ifdef FEAT_FOLDING
82# define PV_CMS OPT_BUF(BV_CMS)
83#endif
84#ifdef FEAT_COMMENTS
85# define PV_COM OPT_BUF(BV_COM)
86#endif
87#ifdef FEAT_INS_EXPAND
88# define PV_CPT OPT_BUF(BV_CPT)
89# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
90# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
91#endif
92#ifdef FEAT_COMPL_FUNC
93# define PV_CFU OPT_BUF(BV_CFU)
94#endif
95#ifdef FEAT_FIND_ID
96# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
97# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
98#endif
99#define PV_EOL OPT_BUF(BV_EOL)
100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
102#ifdef FEAT_MBYTE
103# define PV_FENC OPT_BUF(BV_FENC)
104#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000105#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
106# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
107#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000108#ifdef FEAT_EVAL
109# define PV_FEX OPT_BUF(BV_FEX)
110#endif
111#define PV_FF OPT_BUF(BV_FF)
112#define PV_FLP OPT_BUF(BV_FLP)
113#define PV_FO OPT_BUF(BV_FO)
114#ifdef FEAT_AUTOCMD
115# define PV_FT OPT_BUF(BV_FT)
116#endif
117#define PV_IMI OPT_BUF(BV_IMI)
118#define PV_IMS OPT_BUF(BV_IMS)
119#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
120# define PV_INDE OPT_BUF(BV_INDE)
121# define PV_INDK OPT_BUF(BV_INDK)
122#endif
123#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
124# define PV_INEX OPT_BUF(BV_INEX)
125#endif
126#define PV_INF OPT_BUF(BV_INF)
127#define PV_ISK OPT_BUF(BV_ISK)
128#ifdef FEAT_CRYPT
129# define PV_KEY OPT_BUF(BV_KEY)
130#endif
131#ifdef FEAT_KEYMAP
132# define PV_KMAP OPT_BUF(BV_KMAP)
133#endif
134#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
135#ifdef FEAT_LISP
136# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100137# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000138#endif
139#define PV_MA OPT_BUF(BV_MA)
140#define PV_ML OPT_BUF(BV_ML)
141#define PV_MOD OPT_BUF(BV_MOD)
142#define PV_MPS OPT_BUF(BV_MPS)
143#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000144#ifdef FEAT_COMPL_FUNC
145# define PV_OFU OPT_BUF(BV_OFU)
146#endif
147#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
148#define PV_PI OPT_BUF(BV_PI)
149#ifdef FEAT_TEXTOBJ
150# define PV_QE OPT_BUF(BV_QE)
151#endif
152#define PV_RO OPT_BUF(BV_RO)
153#ifdef FEAT_SMARTINDENT
154# define PV_SI OPT_BUF(BV_SI)
155#endif
156#ifndef SHORT_FNAME
157# define PV_SN OPT_BUF(BV_SN)
158#endif
159#ifdef FEAT_SYN_HL
160# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000161# define PV_SYN OPT_BUF(BV_SYN)
162#endif
163#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000164# define PV_SPC OPT_BUF(BV_SPC)
165# define PV_SPF OPT_BUF(BV_SPF)
166# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000167#endif
168#define PV_STS OPT_BUF(BV_STS)
169#ifdef FEAT_SEARCHPATH
170# define PV_SUA OPT_BUF(BV_SUA)
171#endif
172#define PV_SW OPT_BUF(BV_SW)
173#define PV_SWF OPT_BUF(BV_SWF)
174#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
175#define PV_TS OPT_BUF(BV_TS)
176#define PV_TW OPT_BUF(BV_TW)
177#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200178#ifdef FEAT_PERSISTENT_UNDO
179# define PV_UDF OPT_BUF(BV_UDF)
180#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000181#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000182
183/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184 * Definition of the PV_ values for window-local options.
185 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187#define PV_LIST OPT_WIN(WV_LIST)
188#ifdef FEAT_ARABIC
189# define PV_ARAB OPT_WIN(WV_ARAB)
190#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200191#ifdef FEAT_LINEBREAK
192# define PV_BRI OPT_WIN(WV_BRI)
193# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
194#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000195#ifdef FEAT_DIFF
196# define PV_DIFF OPT_WIN(WV_DIFF)
197#endif
198#ifdef FEAT_FOLDING
199# define PV_FDC OPT_WIN(WV_FDC)
200# define PV_FEN OPT_WIN(WV_FEN)
201# define PV_FDI OPT_WIN(WV_FDI)
202# define PV_FDL OPT_WIN(WV_FDL)
203# define PV_FDM OPT_WIN(WV_FDM)
204# define PV_FML OPT_WIN(WV_FML)
205# define PV_FDN OPT_WIN(WV_FDN)
206# ifdef FEAT_EVAL
207# define PV_FDE OPT_WIN(WV_FDE)
208# define PV_FDT OPT_WIN(WV_FDT)
209# endif
210# define PV_FMR OPT_WIN(WV_FMR)
211#endif
212#ifdef FEAT_LINEBREAK
213# define PV_LBR OPT_WIN(WV_LBR)
214#endif
215#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200216#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000217#ifdef FEAT_LINEBREAK
218# define PV_NUW OPT_WIN(WV_NUW)
219#endif
220#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
221# define PV_PVW OPT_WIN(WV_PVW)
222#endif
223#ifdef FEAT_RIGHTLEFT
224# define PV_RL OPT_WIN(WV_RL)
225# define PV_RLC OPT_WIN(WV_RLC)
226#endif
227#ifdef FEAT_SCROLLBIND
228# define PV_SCBIND OPT_WIN(WV_SCBIND)
229#endif
230#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000231#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000232# define PV_SPELL OPT_WIN(WV_SPELL)
233#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000234#ifdef FEAT_SYN_HL
235# define PV_CUC OPT_WIN(WV_CUC)
236# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200237# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000238#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000239#ifdef FEAT_STL_OPT
240# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
241#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100242#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000243#ifdef FEAT_WINDOWS
244# define PV_WFH OPT_WIN(WV_WFH)
245#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000246#ifdef FEAT_VERTSPLIT
247# define PV_WFW OPT_WIN(WV_WFW)
248#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000249#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200250#ifdef FEAT_CURSORBIND
251# define PV_CRBIND OPT_WIN(WV_CRBIND)
252#endif
253#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200254# define PV_COCU OPT_WIN(WV_COCU)
255# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200256#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000257
258/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259typedef enum
260{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000261 PV_NONE = 0,
262 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000263} idopt_T;
264
265/*
266 * Options local to a window have a value local to a buffer and global to all
267 * buffers. Indicate this by setting "var" to VAR_WIN.
268 */
269#define VAR_WIN ((char_u *)-1)
270
271/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000272 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273 * Only to be used in option.c!
274 */
275static int p_ai;
276static int p_bin;
277#ifdef FEAT_MBYTE
278static int p_bomb;
279#endif
280#if defined(FEAT_QUICKFIX)
281static char_u *p_bh;
282static char_u *p_bt;
283#endif
284static int p_bl;
285static int p_ci;
286#ifdef FEAT_CINDENT
287static int p_cin;
288static char_u *p_cink;
289static char_u *p_cino;
290#endif
291#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
292static char_u *p_cinw;
293#endif
294#ifdef FEAT_COMMENTS
295static char_u *p_com;
296#endif
297#ifdef FEAT_FOLDING
298static char_u *p_cms;
299#endif
300#ifdef FEAT_INS_EXPAND
301static char_u *p_cpt;
302#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000303#ifdef FEAT_COMPL_FUNC
304static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000305static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307static int p_eol;
308static int p_et;
309#ifdef FEAT_MBYTE
310static char_u *p_fenc;
311#endif
312static char_u *p_ff;
313static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000314static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315#ifdef FEAT_AUTOCMD
316static char_u *p_ft;
317#endif
318static long p_iminsert;
319static long p_imsearch;
320#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
321static char_u *p_inex;
322#endif
323#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
324static char_u *p_inde;
325static char_u *p_indk;
326#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000327#if defined(FEAT_EVAL)
328static char_u *p_fex;
329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330static int p_inf;
331static char_u *p_isk;
332#ifdef FEAT_CRYPT
333static char_u *p_key;
334#endif
335#ifdef FEAT_LISP
336static int p_lisp;
337#endif
338static int p_ml;
339static int p_ma;
340static int p_mod;
341static char_u *p_mps;
342static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344#ifdef FEAT_TEXTOBJ
345static char_u *p_qe;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_ro;
348#ifdef FEAT_SMARTINDENT
349static int p_si;
350#endif
351#ifndef SHORT_FNAME
352static int p_sn;
353#endif
354static long p_sts;
355#if defined(FEAT_SEARCHPATH)
356static char_u *p_sua;
357#endif
358static long p_sw;
359static int p_swf;
360#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000361static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000363#endif
364#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000365static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000366static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000367static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368#endif
369static long p_ts;
370static long p_tw;
371static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200372#ifdef FEAT_PERSISTENT_UNDO
373static int p_udf;
374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375static long p_wm;
376#ifdef FEAT_KEYMAP
377static char_u *p_keymap;
378#endif
379
380/* Saved values for when 'bin' is set. */
381static int p_et_nobin;
382static int p_ml_nobin;
383static long p_tw_nobin;
384static long p_wm_nobin;
385
386/* Saved values for when 'paste' is set */
387static long p_tw_nopaste;
388static long p_wm_nopaste;
389static long p_sts_nopaste;
390static int p_ai_nopaste;
391
392struct vimoption
393{
394 char *fullname; /* full option name */
395 char *shortname; /* permissible abbreviation */
396 long_u flags; /* see below */
397 char_u *var; /* global option: pointer to variable;
398 * window-local option: VAR_WIN;
399 * buffer-local option: global value */
400 idopt_T indir; /* global option: PV_NONE;
401 * local option: indirect option index */
402 char_u *def_val[2]; /* default values for variable (vi and vim) */
403#ifdef FEAT_EVAL
404 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000405# define SCRIPTID_INIT , 0
406#else
407# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408#endif
409};
410
411#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
412#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
413
414/*
415 * Flags
416 */
417#define P_BOOL 0x01 /* the option is boolean */
418#define P_NUM 0x02 /* the option is numeric */
419#define P_STRING 0x04 /* the option is a string */
420#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000421 must use free_string_option() when
422 assigning new value. Not set if default is
423 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000424#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
425 never be used for local or hidden options! */
426#define P_NODEFAULT 0x40 /* don't set to default value */
427#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
428 use vim_free() when assigning new value */
429#define P_WAS_SET 0x100 /* option has been set/reset */
430#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
431#define P_VI_DEF 0x400 /* Use Vi default for Vim */
432#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
433
434 /* when option changed, what to display: */
435#define P_RSTAT 0x1000 /* redraw status lines */
436#define P_RWIN 0x2000 /* redraw current window */
437#define P_RBUF 0x4000 /* redraw current buffer */
438#define P_RALL 0x6000 /* redraw all windows */
439#define P_RCLR 0x7000 /* clear and redraw all */
440
441#define P_COMMA 0x8000 /* comma separated list */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200442#define P_NODUP 0x10000L /* don't allow duplicate strings */
443#define P_FLAGLIST 0x20000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444
Bram Moolenaar913077c2012-03-28 19:59:04 +0200445#define P_SECURE 0x40000L /* cannot change in modeline or secure mode */
446#define P_GETTEXT 0x80000L /* expand default value with _() */
447#define P_NOGLOB 0x100000L /* do not use local value for global vimrc */
448#define P_NFNAME 0x200000L /* only normal file name chars allowed */
449#define P_INSECURE 0x400000L /* option was set from a modeline */
450#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000451 side effects) */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200452#define P_NO_ML 0x1000000L /* not allowed in modeline */
453#define P_CURSWANT 0x2000000L /* update curswant required; not needed when
454 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000455
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000456#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
457
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000458/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
459 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000460#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000461# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000462#else
463# define ISP_LATIN1 (char_u *)"@,161-255"
464#endif
465
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000466/* The 16 bit MS-DOS version is low on space, make the string as short as
467 * possible when compiling with few features. */
468#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
469 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200470 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100471# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000472#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100473# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000474#endif
475
Bram Moolenaar071d4272004-06-13 20:20:40 +0000476/*
477 * options[] is initialized here.
478 * The order of the options MUST be alphabetic for ":set all" and findoption().
479 * All option names MUST start with a lowercase letter (for findoption()).
480 * Exception: "t_" options are at the end.
481 * The options with a NULL variable are 'hidden': a set command for them is
482 * ignored and they are not printed.
483 */
484static struct vimoption
485#ifdef FEAT_GUI_W16
486 _far
487#endif
488 options[] =
489{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200490 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000491#ifdef FEAT_RIGHTLEFT
492 (char_u *)&p_aleph, PV_NONE,
493#else
494 (char_u *)NULL, PV_NONE,
495#endif
496 {
497#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
498 (char_u *)128L,
499#else
500 (char_u *)224L,
501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000502 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
504#if defined(FEAT_GUI) && defined(MACOS_X)
505 (char_u *)&p_antialias, PV_NONE,
506 {(char_u *)FALSE, (char_u *)FALSE}
507#else
508 (char_u *)NULL, PV_NONE,
509 {(char_u *)FALSE, (char_u *)FALSE}
510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000511 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200512 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000513#ifdef FEAT_ARABIC
514 (char_u *)VAR_WIN, PV_ARAB,
515#else
516 (char_u *)NULL, PV_NONE,
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
520#ifdef FEAT_ARABIC
521 (char_u *)&p_arshape, PV_NONE,
522#else
523 (char_u *)NULL, PV_NONE,
524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000525 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
527#ifdef FEAT_RIGHTLEFT
528 (char_u *)&p_ari, PV_NONE,
529#else
530 (char_u *)NULL, PV_NONE,
531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000532 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
534#ifdef FEAT_FKMAP
535 (char_u *)&p_altkeymap, PV_NONE,
536#else
537 (char_u *)NULL, PV_NONE,
538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000540 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
541#if defined(FEAT_MBYTE)
542 (char_u *)&p_ambw, PV_NONE,
543 {(char_u *)"single", (char_u *)0L}
544#else
545 (char_u *)NULL, PV_NONE,
546 {(char_u *)0L, (char_u *)0L}
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000549#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"autochdir", "acd", P_BOOL|P_VI_DEF,
551 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553#endif
554 {"autoindent", "ai", P_BOOL|P_VI_DEF,
555 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autoprint", "ap", P_BOOL|P_VI_DEF,
558 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000561 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autowrite", "aw", P_BOOL|P_VI_DEF,
564 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autowriteall","awa", P_BOOL|P_VI_DEF,
567 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
570 (char_u *)&p_bg, PV_NONE,
571 {
572#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
573 (char_u *)"dark",
574#else
575 (char_u *)"light",
576#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000577 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
579 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
582 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
585 (char_u *)&p_bkc, PV_NONE,
586#ifdef UNIX
587 {(char_u *)"yes", (char_u *)"auto"}
588#else
589 {(char_u *)"auto", (char_u *)"auto"}
590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
593 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000594 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000595 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 (char_u *)&p_bex, PV_NONE,
597 {
598#ifdef VMS
599 (char_u *)"_",
600#else
601 (char_u *)"~",
602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
605#ifdef FEAT_WILDIGN
606 (char_u *)&p_bsk, PV_NONE,
607 {(char_u *)"", (char_u *)0L}
608#else
609 (char_u *)NULL, PV_NONE,
610 {(char_u *)0L, (char_u *)0L}
611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613#ifdef FEAT_BEVAL
614 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
615 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
618 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000620# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000621 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000622 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000624# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625#endif
626 {"beautify", "bf", P_BOOL|P_VI_DEF,
627 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
630 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
633#ifdef MSDOS
634 (char_u *)&p_biosk, PV_NONE,
635#else
636 (char_u *)NULL, PV_NONE,
637#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000638 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
640#ifdef FEAT_MBYTE
641 (char_u *)&p_bomb, PV_BOMB,
642#else
643 (char_u *)NULL, PV_NONE,
644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000645 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
647#ifdef FEAT_LINEBREAK
648 (char_u *)&p_breakat, PV_NONE,
649 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
650#else
651 (char_u *)NULL, PV_NONE,
652 {(char_u *)0L, (char_u *)0L}
653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000654 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200655 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
656#ifdef FEAT_LINEBREAK
657 (char_u *)VAR_WIN, PV_BRI,
658 {(char_u *)FALSE, (char_u *)0L}
659#else
660 (char_u *)NULL, PV_NONE,
661 {(char_u *)0L, (char_u *)0L}
662#endif
663 SCRIPTID_INIT},
664 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_COMMA|P_NODUP,
665#ifdef FEAT_LINEBREAK
666 (char_u *)VAR_WIN, PV_BRIOPT,
667 {(char_u *)"", (char_u *)NULL}
668#else
669 (char_u *)NULL, PV_NONE,
670 {(char_u *)"", (char_u *)NULL}
671#endif
672 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
674#ifdef FEAT_BROWSE
675 (char_u *)&p_bsdir, PV_NONE,
676 {(char_u *)"last", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000682 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
683#if defined(FEAT_QUICKFIX)
684 (char_u *)&p_bh, PV_BH,
685 {(char_u *)"", (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000690 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
692 (char_u *)&p_bl, PV_BL,
693 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000694 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
696#if defined(FEAT_QUICKFIX)
697 (char_u *)&p_bt, PV_BT,
698 {(char_u *)"", (char_u *)0L}
699#else
700 (char_u *)NULL, PV_NONE,
701 {(char_u *)0L, (char_u *)0L}
702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000703 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000705#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 (char_u *)&p_cmp, PV_NONE,
707 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000708#else
709 (char_u *)NULL, PV_NONE,
710 {(char_u *)0L, (char_u *)0L}
711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000712 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
714#ifdef FEAT_SEARCHPATH
715 (char_u *)&p_cdpath, PV_NONE,
716 {(char_u *)",,", (char_u *)0L}
717#else
718 (char_u *)NULL, PV_NONE,
719 {(char_u *)0L, (char_u *)0L}
720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000721 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 {"cedit", NULL, P_STRING,
723#ifdef FEAT_CMDWIN
724 (char_u *)&p_cedit, PV_NONE,
725 {(char_u *)"", (char_u *)CTRL_F_STR}
726#else
727 (char_u *)NULL, PV_NONE,
728 {(char_u *)0L, (char_u *)0L}
729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
732#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
733 (char_u *)&p_ccv, PV_NONE,
734 {(char_u *)"", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
741#ifdef FEAT_CINDENT
742 (char_u *)&p_cin, PV_CIN,
743#else
744 (char_u *)NULL, PV_NONE,
745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000746 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
748#ifdef FEAT_CINDENT
749 (char_u *)&p_cink, PV_CINK,
750 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
751#else
752 (char_u *)NULL, PV_NONE,
753 {(char_u *)0L, (char_u *)0L}
754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000755 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
757#ifdef FEAT_CINDENT
758 (char_u *)&p_cino, PV_CINO,
759#else
760 (char_u *)NULL, PV_NONE,
761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000762 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000763 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
764#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
765 (char_u *)&p_cinw, PV_CINW,
766 {(char_u *)"if,else,while,do,for,switch",
767 (char_u *)0L}
768#else
769 (char_u *)NULL, PV_NONE,
770 {(char_u *)0L, (char_u *)0L}
771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000772 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000773 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
774#ifdef FEAT_CLIPBOARD
775 (char_u *)&p_cb, PV_NONE,
776# ifdef FEAT_XCLIPBOARD
777 {(char_u *)"autoselect,exclude:cons\\|linux",
778 (char_u *)0L}
779# else
780 {(char_u *)"", (char_u *)0L}
781# endif
782#else
783 (char_u *)NULL, PV_NONE,
784 {(char_u *)"", (char_u *)0L}
785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000787 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
788 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
791#ifdef FEAT_CMDWIN
792 (char_u *)&p_cwh, PV_NONE,
793#else
794 (char_u *)NULL, PV_NONE,
795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000796 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200797 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
798#ifdef FEAT_SYN_HL
799 (char_u *)VAR_WIN, PV_CC,
800#else
801 (char_u *)NULL, PV_NONE,
802#endif
803 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
805 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000806 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200807 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808#ifdef FEAT_COMMENTS
809 (char_u *)&p_com, PV_COM,
810 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
811 (char_u *)0L}
812#else
813 (char_u *)NULL, PV_NONE,
814 {(char_u *)0L, (char_u *)0L}
815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000816 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200817 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818#ifdef FEAT_FOLDING
819 (char_u *)&p_cms, PV_CMS,
820 {(char_u *)"/*%s*/", (char_u *)0L}
821#else
822 (char_u *)NULL, PV_NONE,
823 {(char_u *)0L, (char_u *)0L}
824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000826 /* P_PRI_MKRC isn't needed here, optval_default()
827 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000828 {"compatible", "cp", P_BOOL|P_RALL,
829 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000830 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
832#ifdef FEAT_INS_EXPAND
833 (char_u *)&p_cpt, PV_CPT,
834 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
835#else
836 (char_u *)NULL, PV_NONE,
837 {(char_u *)0L, (char_u *)0L}
838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000839 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200840 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200841#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200842 (char_u *)VAR_WIN, PV_COCU,
843 {(char_u *)"", (char_u *)NULL}
844#else
845 (char_u *)NULL, PV_NONE,
846 {(char_u *)NULL, (char_u *)0L}
847#endif
848 SCRIPTID_INIT},
849 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
850#ifdef FEAT_CONCEAL
851 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200852#else
853 (char_u *)NULL, PV_NONE,
854#endif
855 {(char_u *)0L, (char_u *)0L}
856 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000857 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
858#ifdef FEAT_COMPL_FUNC
859 (char_u *)&p_cfu, PV_CFU,
860 {(char_u *)"", (char_u *)0L}
861#else
862 (char_u *)NULL, PV_NONE,
863 {(char_u *)0L, (char_u *)0L}
864#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000865 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000866 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
867#ifdef FEAT_INS_EXPAND
868 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000869 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000870#else
871 (char_u *)NULL, PV_NONE,
872 {(char_u *)0L, (char_u *)0L}
873#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000874 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000875 {"confirm", "cf", P_BOOL|P_VI_DEF,
876#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
877 (char_u *)&p_confirm, PV_NONE,
878#else
879 (char_u *)NULL, PV_NONE,
880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000881 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000882 {"conskey", "consk",P_BOOL|P_VI_DEF,
883#ifdef MSDOS
884 (char_u *)&p_consk, PV_NONE,
885#else
886 (char_u *)NULL, PV_NONE,
887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
890 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
893 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
895 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200896 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200897#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200898 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200899 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200900#else
901 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200902 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200903#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200904 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
906#ifdef FEAT_CSCOPE
907 (char_u *)&p_cspc, PV_NONE,
908#else
909 (char_u *)NULL, PV_NONE,
910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
913#ifdef FEAT_CSCOPE
914 (char_u *)&p_csprg, PV_NONE,
915 {(char_u *)"cscope", (char_u *)0L}
916#else
917 (char_u *)NULL, PV_NONE,
918 {(char_u *)0L, (char_u *)0L}
919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
922#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
923 (char_u *)&p_csqf, PV_NONE,
924 {(char_u *)"", (char_u *)0L}
925#else
926 (char_u *)NULL, PV_NONE,
927 {(char_u *)0L, (char_u *)0L}
928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000929 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200930 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
931#ifdef FEAT_CSCOPE
932 (char_u *)&p_csre, PV_NONE,
933#else
934 (char_u *)NULL, PV_NONE,
935#endif
936 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
938#ifdef FEAT_CSCOPE
939 (char_u *)&p_cst, PV_NONE,
940#else
941 (char_u *)NULL, PV_NONE,
942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000943 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
945#ifdef FEAT_CSCOPE
946 (char_u *)&p_csto, PV_NONE,
947#else
948 (char_u *)NULL, PV_NONE,
949#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000950 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000951 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
952#ifdef FEAT_CSCOPE
953 (char_u *)&p_csverbose, PV_NONE,
954#else
955 (char_u *)NULL, PV_NONE,
956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000957 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200958 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
959#ifdef FEAT_CURSORBIND
960 (char_u *)VAR_WIN, PV_CRBIND,
961#else
962 (char_u *)NULL, PV_NONE,
963#endif
964 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000965 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
966#ifdef FEAT_SYN_HL
967 (char_u *)VAR_WIN, PV_CUC,
968#else
969 (char_u *)NULL, PV_NONE,
970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000971 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000972 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
973#ifdef FEAT_SYN_HL
974 (char_u *)VAR_WIN, PV_CUL,
975#else
976 (char_u *)NULL, PV_NONE,
977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979 {"debug", NULL, P_STRING|P_VI_DEF,
980 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000981 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200982 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000984 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000985 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000986#else
987 (char_u *)NULL, PV_NONE,
988 {(char_u *)NULL, (char_u *)0L}
989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
992#ifdef FEAT_MBYTE
993 (char_u *)&p_deco, PV_NONE,
994#else
995 (char_u *)NULL, PV_NONE,
996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
999#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001000 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001#else
1002 (char_u *)NULL, PV_NONE,
1003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1006#ifdef FEAT_DIFF
1007 (char_u *)VAR_WIN, PV_DIFF,
1008#else
1009 (char_u *)NULL, PV_NONE,
1010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001011 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001012 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1014 (char_u *)&p_dex, PV_NONE,
1015 {(char_u *)"", (char_u *)0L}
1016#else
1017 (char_u *)NULL, PV_NONE,
1018 {(char_u *)0L, (char_u *)0L}
1019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001020 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
1022#ifdef FEAT_DIFF
1023 (char_u *)&p_dip, PV_NONE,
1024 {(char_u *)"filler", (char_u *)NULL}
1025#else
1026 (char_u *)NULL, PV_NONE,
1027 {(char_u *)"", (char_u *)NULL}
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1031#ifdef FEAT_DIGRAPHS
1032 (char_u *)&p_dg, PV_NONE,
1033#else
1034 (char_u *)NULL, PV_NONE,
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1038 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001039 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1041 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001042 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 {"eadirection", "ead", P_STRING|P_VI_DEF,
1044#ifdef FEAT_VERTSPLIT
1045 (char_u *)&p_ead, PV_NONE,
1046 {(char_u *)"both", (char_u *)0L}
1047#else
1048 (char_u *)NULL, PV_NONE,
1049 {(char_u *)NULL, (char_u *)0L}
1050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1053 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001055 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056#ifdef FEAT_MBYTE
1057 (char_u *)&p_enc, PV_NONE,
1058 {(char_u *)ENC_DFLT, (char_u *)0L}
1059#else
1060 (char_u *)NULL, PV_NONE,
1061 {(char_u *)0L, (char_u *)0L}
1062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1065 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1068 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001071 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001072 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1074 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001075 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1077#ifdef FEAT_QUICKFIX
1078 (char_u *)&p_ef, PV_NONE,
1079 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1080#else
1081 (char_u *)NULL, PV_NONE,
1082 {(char_u *)NULL, (char_u *)0L}
1083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1086#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001087 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089#else
1090 (char_u *)NULL, PV_NONE,
1091 {(char_u *)NULL, (char_u *)0L}
1092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094 {"esckeys", "ek", P_BOOL|P_VIM,
1095 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1098#ifdef FEAT_AUTOCMD
1099 (char_u *)&p_ei, PV_NONE,
1100#else
1101 (char_u *)NULL, PV_NONE,
1102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1105 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1108 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1111#ifdef FEAT_MBYTE
1112 (char_u *)&p_fenc, PV_FENC,
1113 {(char_u *)"", (char_u *)0L}
1114#else
1115 (char_u *)NULL, PV_NONE,
1116 {(char_u *)0L, (char_u *)0L}
1117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1120#ifdef FEAT_MBYTE
1121 (char_u *)&p_fencs, PV_NONE,
1122 {(char_u *)"ucs-bom", (char_u *)0L}
1123#else
1124 (char_u *)NULL, PV_NONE,
1125 {(char_u *)0L, (char_u *)0L}
1126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001128 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1132 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1134 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001135 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1136 (char_u *)&p_fic, PV_NONE,
1137 {
1138#ifdef CASE_INSENSITIVE_FILENAME
1139 (char_u *)TRUE,
1140#else
1141 (char_u *)FALSE,
1142#endif
1143 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001144 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145#ifdef FEAT_AUTOCMD
1146 (char_u *)&p_ft, PV_FT,
1147 {(char_u *)"", (char_u *)0L}
1148#else
1149 (char_u *)NULL, PV_NONE,
1150 {(char_u *)0L, (char_u *)0L}
1151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001152 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1154#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1155 (char_u *)&p_fcs, PV_NONE,
1156 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1157#else
1158 (char_u *)NULL, PV_NONE,
1159 {(char_u *)"", (char_u *)0L}
1160#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001161 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1163#ifdef FEAT_FKMAP
1164 (char_u *)&p_fkmap, PV_NONE,
1165#else
1166 (char_u *)NULL, PV_NONE,
1167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169 {"flash", "fl", P_BOOL|P_VI_DEF,
1170 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172#ifdef FEAT_FOLDING
1173 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1174 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001176 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1177 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1180 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1183# ifdef FEAT_EVAL
1184 (char_u *)VAR_WIN, PV_FDE,
1185 {(char_u *)"0", (char_u *)NULL}
1186# else
1187 (char_u *)NULL, PV_NONE,
1188 {(char_u *)NULL, (char_u *)0L}
1189# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001190 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1192 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001193 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1195 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001196 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001197 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001199 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001200 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1201 P_RWIN|P_COMMA|P_NODUP,
1202 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 {(char_u *)"{{{,}}}", (char_u *)NULL}
1204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001205 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1206 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001207 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001208 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1209 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1212 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001214 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 (char_u *)&p_fdo, PV_NONE,
1216 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1219# ifdef FEAT_EVAL
1220 (char_u *)VAR_WIN, PV_FDT,
1221 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001222# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 (char_u *)NULL, PV_NONE,
1224 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001225# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001228 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001229#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001230 (char_u *)&p_fex, PV_FEX,
1231 {(char_u *)"", (char_u *)0L}
1232#else
1233 (char_u *)NULL, PV_NONE,
1234 {(char_u *)0L, (char_u *)0L}
1235#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1238 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001239 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1240 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001241 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1242 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001243 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1244 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1246 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001247 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001248 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1249#ifdef HAVE_FSYNC
1250 (char_u *)&p_fs, PV_NONE,
1251 {(char_u *)TRUE, (char_u *)0L}
1252#else
1253 (char_u *)NULL, PV_NONE,
1254 {(char_u *)FALSE, (char_u *)0L}
1255#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001257 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1258 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001259 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001260 {"graphic", "gr", P_BOOL|P_VI_DEF,
1261 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001262 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001263 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1264#ifdef FEAT_QUICKFIX
1265 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)NULL, (char_u *)0L}
1270#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001271 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001272 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1273#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001274 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001275 {
1276# ifdef WIN3264
1277 /* may be changed to "grep -n" in os_win32.c */
1278 (char_u *)"findstr /n",
1279# else
1280# ifdef UNIX
1281 /* Add an extra file name so that grep will always
1282 * insert a file name in the match line. */
1283 (char_u *)"grep -n $* /dev/null",
1284# else
1285# ifdef VMS
1286 (char_u *)"SEARCH/NUMBERS ",
1287# else
1288 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001289# endif
1290# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001292 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001293#else
1294 (char_u *)NULL, PV_NONE,
1295 {(char_u *)NULL, (char_u *)0L}
1296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001297 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1299#ifdef CURSOR_SHAPE
1300 (char_u *)&p_guicursor, PV_NONE,
1301 {
1302# ifdef FEAT_GUI
1303 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
1304# else /* MSDOS or Win32 console */
1305 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1306# endif
1307 (char_u *)0L}
1308#else
1309 (char_u *)NULL, PV_NONE,
1310 {(char_u *)NULL, (char_u *)0L}
1311#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1314#ifdef FEAT_GUI
1315 (char_u *)&p_guifont, PV_NONE,
1316 {(char_u *)"", (char_u *)0L}
1317#else
1318 (char_u *)NULL, PV_NONE,
1319 {(char_u *)NULL, (char_u *)0L}
1320#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001321 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001322 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1323#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1324 (char_u *)&p_guifontset, PV_NONE,
1325 {(char_u *)"", (char_u *)0L}
1326#else
1327 (char_u *)NULL, PV_NONE,
1328 {(char_u *)NULL, (char_u *)0L}
1329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001330 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001331 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1332#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1333 (char_u *)&p_guifontwide, PV_NONE,
1334 {(char_u *)"", (char_u *)0L}
1335#else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)NULL, (char_u *)0L}
1338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001339 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001341#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 (char_u *)&p_ghr, PV_NONE,
1343#else
1344 (char_u *)NULL, PV_NONE,
1345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001348#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 (char_u *)&p_go, PV_NONE,
1350# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001351 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001353 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001354# endif
1355#else
1356 (char_u *)NULL, PV_NONE,
1357 {(char_u *)NULL, (char_u *)0L}
1358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 {"guipty", NULL, P_BOOL|P_VI_DEF,
1361#if defined(FEAT_GUI)
1362 (char_u *)&p_guipty, PV_NONE,
1363#else
1364 (char_u *)NULL, PV_NONE,
1365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001366 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001367 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001368#if defined(FEAT_GUI_TABLINE)
1369 (char_u *)&p_gtl, PV_NONE,
1370 {(char_u *)"", (char_u *)0L}
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001375 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001376 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001377#if defined(FEAT_GUI_TABLINE)
1378 (char_u *)&p_gtt, PV_NONE,
1379 {(char_u *)"", (char_u *)0L}
1380#else
1381 (char_u *)NULL, PV_NONE,
1382 {(char_u *)NULL, (char_u *)0L}
1383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001384 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1386 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001387 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001388 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1389 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001390 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1391 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392 {"helpheight", "hh", P_NUM|P_VI_DEF,
1393#ifdef FEAT_WINDOWS
1394 (char_u *)&p_hh, PV_NONE,
1395#else
1396 (char_u *)NULL, PV_NONE,
1397#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001398 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1400#ifdef FEAT_MULTI_LANG
1401 (char_u *)&p_hlg, PV_NONE,
1402 {(char_u *)"", (char_u *)0L}
1403#else
1404 (char_u *)NULL, PV_NONE,
1405 {(char_u *)0L, (char_u *)0L}
1406#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001407 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"hidden", "hid", P_BOOL|P_VI_DEF,
1409 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001410 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001411 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1412 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001413 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1414 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415 {"history", "hi", P_NUM|P_VIM,
1416 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001417 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1419#ifdef FEAT_RIGHTLEFT
1420 (char_u *)&p_hkmap, PV_NONE,
1421#else
1422 (char_u *)NULL, PV_NONE,
1423#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001424 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1426#ifdef FEAT_RIGHTLEFT
1427 (char_u *)&p_hkmapp, PV_NONE,
1428#else
1429 (char_u *)NULL, PV_NONE,
1430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1433 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"icon", NULL, P_BOOL|P_VI_DEF,
1436#ifdef FEAT_TITLE
1437 (char_u *)&p_icon, PV_NONE,
1438#else
1439 (char_u *)NULL, PV_NONE,
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"iconstring", NULL, P_STRING|P_VI_DEF,
1443#ifdef FEAT_TITLE
1444 (char_u *)&p_iconstring, PV_NONE,
1445#else
1446 (char_u *)NULL, PV_NONE,
1447#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001448 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1450 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001452 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1453# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1454 (char_u *)&p_imaf, PV_NONE,
1455 {(char_u *)"", (char_u *)NULL}
1456# else
1457 (char_u *)NULL, PV_NONE,
1458 {(char_u *)NULL, (char_u *)0L}
1459# endif
1460 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001462#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463 (char_u *)&p_imak, PV_NONE,
1464#else
1465 (char_u *)NULL, PV_NONE,
1466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001467 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1469#ifdef USE_IM_CONTROL
1470 (char_u *)&p_imcmdline, PV_NONE,
1471#else
1472 (char_u *)NULL, PV_NONE,
1473#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001474 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001475 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1476#ifdef USE_IM_CONTROL
1477 (char_u *)&p_imdisable, PV_NONE,
1478#else
1479 (char_u *)NULL, PV_NONE,
1480#endif
1481#ifdef __sgi
1482 {(char_u *)TRUE, (char_u *)0L}
1483#else
1484 {(char_u *)FALSE, (char_u *)0L}
1485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001486 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 {"iminsert", "imi", P_NUM|P_VI_DEF,
1488 (char_u *)&p_iminsert, PV_IMI,
1489#ifdef B_IMODE_IM
1490 {(char_u *)B_IMODE_IM, (char_u *)0L}
1491#else
1492 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001494 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"imsearch", "ims", P_NUM|P_VI_DEF,
1496 (char_u *)&p_imsearch, PV_IMS,
1497#ifdef B_IMODE_IM
1498 {(char_u *)B_IMODE_IM, (char_u *)0L}
1499#else
1500 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001503 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001504# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1505 (char_u *)&p_imsf, PV_NONE,
1506 {(char_u *)"", (char_u *)NULL}
1507# else
1508 (char_u *)NULL, PV_NONE,
1509 {(char_u *)NULL, (char_u *)0L}
1510# endif
1511 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1513#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001514 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1516#else
1517 (char_u *)NULL, PV_NONE,
1518 {(char_u *)0L, (char_u *)0L}
1519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001520 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1522#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1523 (char_u *)&p_inex, PV_INEX,
1524 {(char_u *)"", (char_u *)0L}
1525#else
1526 (char_u *)NULL, PV_NONE,
1527 {(char_u *)0L, (char_u *)0L}
1528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001529 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1531 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001532 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001533 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1534#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1535 (char_u *)&p_inde, PV_INDE,
1536 {(char_u *)"", (char_u *)0L}
1537#else
1538 (char_u *)NULL, PV_NONE,
1539 {(char_u *)0L, (char_u *)0L}
1540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001541 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1543#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1544 (char_u *)&p_indk, PV_INDK,
1545 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1546#else
1547 (char_u *)NULL, PV_NONE,
1548 {(char_u *)0L, (char_u *)0L}
1549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001550 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001551 {"infercase", "inf", P_BOOL|P_VI_DEF,
1552 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1555 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1558 (char_u *)&p_isf, PV_NONE,
1559 {
1560#ifdef BACKSLASH_IN_FILENAME
1561 /* Excluded are: & and ^ are special in cmd.exe
1562 * ( and ) are used in text separating fnames */
1563 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1564#else
1565# ifdef AMIGA
1566 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1567# else
1568# ifdef VMS
1569 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1570# else /* UNIX et al. */
1571# ifdef EBCDIC
1572 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1573# else
1574 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1575# endif
1576# endif
1577# endif
1578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1581 (char_u *)&p_isi, PV_NONE,
1582 {
1583#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1584 (char_u *)"@,48-57,_,128-167,224-235",
1585#else
1586# ifdef EBCDIC
1587 /* TODO: EBCDIC Check this! @ == isalpha()*/
1588 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1589 "112-120,128,140-142,156,158,172,"
1590 "174,186,191,203-207,219-225,235-239,"
1591 "251-254",
1592# else
1593 (char_u *)"@,48-57,_,192-255",
1594# endif
1595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001596 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001597 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1598 (char_u *)&p_isk, PV_ISK,
1599 {
1600#ifdef EBCDIC
1601 (char_u *)"@,240-249,_",
1602 /* TODO: EBCDIC Check this! @ == isalpha()*/
1603 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1604 "112-120,128,140-142,156,158,172,"
1605 "174,186,191,203-207,219-225,235-239,"
1606 "251-254",
1607#else
1608 (char_u *)"@,48-57,_",
1609# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1610 (char_u *)"@,48-57,_,128-167,224-235"
1611# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001612 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613# endif
1614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001615 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001616 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1617 (char_u *)&p_isp, PV_NONE,
1618 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001619#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1620 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001621 || defined(VMS)
1622 (char_u *)"@,~-255",
1623#else
1624# ifdef EBCDIC
1625 /* all chars above 63 are printable */
1626 (char_u *)"63-255",
1627# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001628 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629# endif
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1633 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1636#ifdef FEAT_CRYPT
1637 (char_u *)&p_key, PV_KEY,
1638 {(char_u *)"", (char_u *)0L}
1639#else
1640 (char_u *)NULL, PV_NONE,
1641 {(char_u *)0L, (char_u *)0L}
1642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001644 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645#ifdef FEAT_KEYMAP
1646 (char_u *)&p_keymap, PV_KMAP,
1647 {(char_u *)"", (char_u *)0L}
1648#else
1649 (char_u *)NULL, PV_NONE,
1650 {(char_u *)"", (char_u *)0L}
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001656 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001657 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658 {
1659#if defined(MSDOS) || defined(MSWIN)
1660 (char_u *)":help",
1661#else
1662#ifdef VMS
1663 (char_u *)"help",
1664#else
1665# if defined(OS2)
1666 (char_u *)"view /",
1667# else
1668# ifdef USEMAN_S
1669 (char_u *)"man -s",
1670# else
1671 (char_u *)"man",
1672# endif
1673# endif
1674#endif
1675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001676 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaared7547d2014-05-13 12:17:15 +02001677 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678#ifdef FEAT_LANGMAP
1679 (char_u *)&p_langmap, PV_NONE,
1680 {(char_u *)"", /* unmatched } */
1681#else
1682 (char_u *)NULL, PV_NONE,
1683 {(char_u *)NULL,
1684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001685 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001686 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1688 (char_u *)&p_lm, PV_NONE,
1689#else
1690 (char_u *)NULL, PV_NONE,
1691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1694#ifdef FEAT_WINDOWS
1695 (char_u *)&p_ls, PV_NONE,
1696#else
1697 (char_u *)NULL, PV_NONE,
1698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001699 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1701 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001702 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1704#ifdef FEAT_LINEBREAK
1705 (char_u *)VAR_WIN, PV_LBR,
1706#else
1707 (char_u *)NULL, PV_NONE,
1708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001709 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1711 (char_u *)&Rows, PV_NONE,
1712 {
1713#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1714 (char_u *)25L,
1715#else
1716 (char_u *)24L,
1717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001718 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1720#ifdef FEAT_GUI
1721 (char_u *)&p_linespace, PV_NONE,
1722#else
1723 (char_u *)NULL, PV_NONE,
1724#endif
1725#ifdef FEAT_GUI_W32
1726 {(char_u *)1L, (char_u *)0L}
1727#else
1728 {(char_u *)0L, (char_u *)0L}
1729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001730 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 {"lisp", NULL, P_BOOL|P_VI_DEF,
1732#ifdef FEAT_LISP
1733 (char_u *)&p_lisp, PV_LISP,
1734#else
1735 (char_u *)NULL, PV_NONE,
1736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001737 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1739#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001740 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1742#else
1743 (char_u *)NULL, PV_NONE,
1744 {(char_u *)"", (char_u *)0L}
1745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001746 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1748 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1751 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1754 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001755 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001756#ifdef FEAT_GUI_MAC
1757 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1758 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"magic", NULL, P_BOOL|P_VI_DEF,
1762 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001764 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765#ifdef FEAT_QUICKFIX
1766 (char_u *)&p_mef, PV_NONE,
1767 {(char_u *)"", (char_u *)0L}
1768#else
1769 (char_u *)NULL, PV_NONE,
1770 {(char_u *)NULL, (char_u *)0L}
1771#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1774#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001775 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776# ifdef VMS
1777 {(char_u *)"MMS", (char_u *)0L}
1778# else
1779 {(char_u *)"make", (char_u *)0L}
1780# endif
1781#else
1782 (char_u *)NULL, PV_NONE,
1783 {(char_u *)NULL, (char_u *)0L}
1784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1787 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1789 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"matchtime", "mat", P_NUM|P_VI_DEF,
1791 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001793 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001794#ifdef FEAT_MBYTE
1795 (char_u *)&p_mco, PV_NONE,
1796#else
1797 (char_u *)NULL, PV_NONE,
1798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001799 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001800 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1801#ifdef FEAT_EVAL
1802 (char_u *)&p_mfd, PV_NONE,
1803#else
1804 (char_u *)NULL, PV_NONE,
1805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001806 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1808 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001809 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810 {"maxmem", "mm", P_NUM|P_VI_DEF,
1811 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001812 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1813 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001814 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1815 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1818 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1820 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"menuitems", "mis", P_NUM|P_VI_DEF,
1822#ifdef FEAT_MENU
1823 (char_u *)&p_mis, PV_NONE,
1824#else
1825 (char_u *)NULL, PV_NONE,
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"mesg", NULL, P_BOOL|P_VI_DEF,
1829 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001831 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001832#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001833 (char_u *)&p_msm, PV_NONE,
1834 {(char_u *)"460000,2000,500", (char_u *)0L}
1835#else
1836 (char_u *)NULL, PV_NONE,
1837 {(char_u *)0L, (char_u *)0L}
1838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001839 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001840 {"modeline", "ml", P_BOOL|P_VIM,
1841 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001842 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001843 {"modelines", "mls", P_NUM|P_VI_DEF,
1844 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1847 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1850 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"more", NULL, P_BOOL|P_VIM,
1853 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001854 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1856 (char_u *)&p_mouse, PV_NONE,
1857 {
1858#if defined(MSDOS) || defined(WIN3264)
1859 (char_u *)"a",
1860#else
1861 (char_u *)"",
1862#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1865#ifdef FEAT_GUI
1866 (char_u *)&p_mousef, PV_NONE,
1867#else
1868 (char_u *)NULL, PV_NONE,
1869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1872#ifdef FEAT_GUI
1873 (char_u *)&p_mh, PV_NONE,
1874#else
1875 (char_u *)NULL, PV_NONE,
1876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1879 (char_u *)&p_mousem, PV_NONE,
1880 {
1881#if defined(MSDOS) || defined(MSWIN)
1882 (char_u *)"popup",
1883#else
1884# if defined(MACOS)
1885 (char_u *)"popup_setpos",
1886# else
1887 (char_u *)"extend",
1888# endif
1889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001890 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1892#ifdef FEAT_MOUSESHAPE
1893 (char_u *)&p_mouseshape, PV_NONE,
1894 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1895#else
1896 (char_u *)NULL, PV_NONE,
1897 {(char_u *)NULL, (char_u *)0L}
1898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1901 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001903 {"mzquantum", "mzq", P_NUM,
1904#ifdef FEAT_MZSCHEME
1905 (char_u *)&p_mzq, PV_NONE,
1906#else
1907 (char_u *)NULL, PV_NONE,
1908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001909 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 {"novice", NULL, P_BOOL|P_VI_DEF,
1911 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1914 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 {(char_u *)"octal,hex", (char_u *)0L}
1916 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1918 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001920 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1921#ifdef FEAT_LINEBREAK
1922 (char_u *)VAR_WIN, PV_NUW,
1923#else
1924 (char_u *)NULL, PV_NONE,
1925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001927 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001928#ifdef FEAT_COMPL_FUNC
1929 (char_u *)&p_ofu, PV_OFU,
1930 {(char_u *)"", (char_u *)0L}
1931#else
1932 (char_u *)NULL, PV_NONE,
1933 {(char_u *)0L, (char_u *)0L}
1934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001935 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 {"open", NULL, P_BOOL|P_VI_DEF,
1937 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001939 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1940#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1941 (char_u *)&p_odev, PV_NONE,
1942#else
1943 (char_u *)NULL, PV_NONE,
1944#endif
1945 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001947 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1948 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001950 {"optimize", "opt", P_BOOL|P_VI_DEF,
1951 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001955 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"paragraphs", "para", P_STRING|P_VI_DEF,
1957 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001958 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001959 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001960 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1964 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001965 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1967#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1968 (char_u *)&p_pex, PV_NONE,
1969 {(char_u *)"", (char_u *)0L}
1970#else
1971 (char_u *)NULL, PV_NONE,
1972 {(char_u *)0L, (char_u *)0L}
1973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001975 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001979 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {
1981#if defined AMIGA || defined MSDOS || defined MSWIN
1982 (char_u *)".,,",
1983#else
1984# if defined(__EMX__)
1985 (char_u *)".,/emx/include,,",
1986# else /* Unix, probably */
1987 (char_u *)".,/usr/include,,",
1988# endif
1989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1992 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001994 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1996 (char_u *)&p_pvh, PV_NONE,
1997#else
1998 (char_u *)NULL, PV_NONE,
1999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2002#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2003 (char_u *)VAR_WIN, PV_PVW,
2004#else
2005 (char_u *)NULL, PV_NONE,
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002008 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009#ifdef FEAT_PRINTER
2010 (char_u *)&p_pdev, PV_NONE,
2011 {(char_u *)"", (char_u *)0L}
2012#else
2013 (char_u *)NULL, PV_NONE,
2014 {(char_u *)NULL, (char_u *)0L}
2015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 {"printencoding", "penc", P_STRING|P_VI_DEF,
2018#ifdef FEAT_POSTSCRIPT
2019 (char_u *)&p_penc, PV_NONE,
2020 {(char_u *)"", (char_u *)0L}
2021#else
2022 (char_u *)NULL, PV_NONE,
2023 {(char_u *)NULL, (char_u *)0L}
2024#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2027#ifdef FEAT_POSTSCRIPT
2028 (char_u *)&p_pexpr, PV_NONE,
2029 {(char_u *)"", (char_u *)0L}
2030#else
2031 (char_u *)NULL, PV_NONE,
2032 {(char_u *)NULL, (char_u *)0L}
2033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002034 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 {"printfont", "pfn", P_STRING|P_VI_DEF,
2036#ifdef FEAT_PRINTER
2037 (char_u *)&p_pfn, PV_NONE,
2038 {
2039# ifdef MSWIN
2040 (char_u *)"Courier_New:h10",
2041# else
2042 (char_u *)"courier",
2043# endif
2044 (char_u *)0L}
2045#else
2046 (char_u *)NULL, PV_NONE,
2047 {(char_u *)NULL, (char_u *)0L}
2048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002049 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2051#ifdef FEAT_PRINTER
2052 (char_u *)&p_header, PV_NONE,
2053 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2054#else
2055 (char_u *)NULL, PV_NONE,
2056 {(char_u *)NULL, (char_u *)0L}
2057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002058 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002059 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2060#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2061 (char_u *)&p_pmcs, PV_NONE,
2062 {(char_u *)"", (char_u *)0L}
2063#else
2064 (char_u *)NULL, PV_NONE,
2065 {(char_u *)NULL, (char_u *)0L}
2066#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002067 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002068 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2069#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2070 (char_u *)&p_pmfn, PV_NONE,
2071 {(char_u *)"", (char_u *)0L}
2072#else
2073 (char_u *)NULL, PV_NONE,
2074 {(char_u *)NULL, (char_u *)0L}
2075#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002076 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2078#ifdef FEAT_PRINTER
2079 (char_u *)&p_popt, PV_NONE,
2080 {(char_u *)"", (char_u *)0L}
2081#else
2082 (char_u *)NULL, PV_NONE,
2083 {(char_u *)NULL, (char_u *)0L}
2084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002087 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002089 {"pumheight", "ph", P_NUM|P_VI_DEF,
2090#ifdef FEAT_INS_EXPAND
2091 (char_u *)&p_ph, PV_NONE,
2092#else
2093 (char_u *)NULL, PV_NONE,
2094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002096 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2097#ifdef FEAT_TEXTOBJ
2098 (char_u *)&p_qe, PV_QE,
2099 {(char_u *)"\\", (char_u *)0L}
2100#else
2101 (char_u *)NULL, PV_NONE,
2102 {(char_u *)NULL, (char_u *)0L}
2103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002105 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2106 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"redraw", NULL, P_BOOL|P_VI_DEF,
2109 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002110 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002111 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2112#ifdef FEAT_RELTIME
2113 (char_u *)&p_rdt, PV_NONE,
2114#else
2115 (char_u *)NULL, PV_NONE,
2116#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002118 {"regexpengine", "re", P_NUM|P_VI_DEF,
2119 (char_u *)&p_re, PV_NONE,
2120 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002121 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2122 (char_u *)VAR_WIN, PV_RNU,
2123 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 {"remap", NULL, P_BOOL|P_VI_DEF,
2125 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002126 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002127 {"renderoptions", "rop", P_STRING|P_COMMA|P_RCLR|P_VI_DEF,
2128#ifdef FEAT_RENDER_OPTIONS
2129 (char_u *)&p_rop, PV_NONE,
2130 {(char_u *)"", (char_u *)0L}
2131#else
2132 (char_u *)NULL, PV_NONE,
2133 {(char_u *)NULL, (char_u *)0L}
2134#endif
2135 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 {"report", NULL, P_NUM|P_VI_DEF,
2137 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002138 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002139 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2140#ifdef WIN3264
2141 (char_u *)&p_rs, PV_NONE,
2142#else
2143 (char_u *)NULL, PV_NONE,
2144#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2147#ifdef FEAT_RIGHTLEFT
2148 (char_u *)&p_ri, PV_NONE,
2149#else
2150 (char_u *)NULL, PV_NONE,
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2154#ifdef FEAT_RIGHTLEFT
2155 (char_u *)VAR_WIN, PV_RL,
2156#else
2157 (char_u *)NULL, PV_NONE,
2158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002159 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2161#ifdef FEAT_RIGHTLEFT
2162 (char_u *)VAR_WIN, PV_RLC,
2163 {(char_u *)"search", (char_u *)NULL}
2164#else
2165 (char_u *)NULL, PV_NONE,
2166 {(char_u *)NULL, (char_u *)0L}
2167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002168 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2170#ifdef FEAT_CMDL_INFO
2171 (char_u *)&p_ru, PV_NONE,
2172#else
2173 (char_u *)NULL, PV_NONE,
2174#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002175 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2177#ifdef FEAT_STL_OPT
2178 (char_u *)&p_ruf, PV_NONE,
2179#else
2180 (char_u *)NULL, PV_NONE,
2181#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002182 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2184 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2186 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2188 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002189 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2191#ifdef FEAT_SCROLLBIND
2192 (char_u *)VAR_WIN, PV_SCBIND,
2193#else
2194 (char_u *)NULL, PV_NONE,
2195#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002196 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002197 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2198 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002199 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2201 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002202 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2204#ifdef FEAT_SCROLLBIND
2205 (char_u *)&p_sbo, PV_NONE,
2206 {(char_u *)"ver,jump", (char_u *)0L}
2207#else
2208 (char_u *)NULL, PV_NONE,
2209 {(char_u *)0L, (char_u *)0L}
2210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002211 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002212 {"sections", "sect", P_STRING|P_VI_DEF,
2213 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2215 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002216 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2217 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002218 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002219 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002220 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 {(char_u *)"inclusive", (char_u *)0L}
2222 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2227#ifdef FEAT_SESSION
2228 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002229 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230 (char_u *)0L}
2231#else
2232 (char_u *)NULL, PV_NONE,
2233 {(char_u *)0L, (char_u *)0L}
2234#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002235 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002236 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2237 (char_u *)&p_sh, PV_NONE,
2238 {
2239#ifdef VMS
2240 (char_u *)"-",
2241#else
2242# if defined(MSDOS)
2243 (char_u *)"command",
2244# else
2245# if defined(WIN16)
2246 (char_u *)"command.com",
2247# else
2248# if defined(WIN3264)
2249 (char_u *)"", /* set in set_init_1() */
2250# else
2251# if defined(OS2)
2252 (char_u *)"cmd.exe",
2253# else
2254# if defined(ARCHIE)
2255 (char_u *)"gos",
2256# else
2257 (char_u *)"sh",
2258# endif
2259# endif
2260# endif
2261# endif
2262# endif
2263#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002264 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2266 (char_u *)&p_shcf, PV_NONE,
2267 {
2268#if defined(MSDOS) || defined(MSWIN)
2269 (char_u *)"/c",
2270#else
2271# if defined(OS2)
2272 (char_u *)"/c",
2273# else
2274 (char_u *)"-c",
2275# endif
2276#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002277 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2279#ifdef FEAT_QUICKFIX
2280 (char_u *)&p_sp, PV_NONE,
2281 {
2282#if defined(UNIX) || defined(OS2)
2283# ifdef ARCHIE
2284 (char_u *)"2>",
2285# else
2286 (char_u *)"| tee",
2287# endif
2288#else
2289 (char_u *)">",
2290#endif
2291 (char_u *)0L}
2292#else
2293 (char_u *)NULL, PV_NONE,
2294 {(char_u *)0L, (char_u *)0L}
2295#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002296 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2298 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002299 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2301 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002302 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2304#ifdef BACKSLASH_IN_FILENAME
2305 (char_u *)&p_ssl, PV_NONE,
2306#else
2307 (char_u *)NULL, PV_NONE,
2308#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002310 {"shelltemp", "stmp", P_BOOL,
2311 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002312 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 {"shelltype", "st", P_NUM|P_VI_DEF,
2314#ifdef AMIGA
2315 (char_u *)&p_st, PV_NONE,
2316#else
2317 (char_u *)NULL, PV_NONE,
2318#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002319 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2321 (char_u *)&p_sxq, PV_NONE,
2322 {
2323#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2324 (char_u *)"\"",
2325#else
2326 (char_u *)"",
2327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002329 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2330 (char_u *)&p_sxe, PV_NONE,
2331 {
2332#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2333 (char_u *)"\"&|<>()@^",
2334#else
2335 (char_u *)"",
2336#endif
2337 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2339 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2342 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2345 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)"", (char_u *)"filnxtToO"}
2347 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 {"shortname", "sn", P_BOOL|P_VI_DEF,
2349#ifdef SHORT_FNAME
2350 (char_u *)NULL, PV_NONE,
2351#else
2352 (char_u *)&p_sn, PV_SN,
2353#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2356#ifdef FEAT_LINEBREAK
2357 (char_u *)&p_sbr, PV_NONE,
2358#else
2359 (char_u *)NULL, PV_NONE,
2360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"showcmd", "sc", P_BOOL|P_VIM,
2363#ifdef FEAT_CMDL_INFO
2364 (char_u *)&p_sc, PV_NONE,
2365#else
2366 (char_u *)NULL, PV_NONE,
2367#endif
2368 {(char_u *)FALSE,
2369#ifdef UNIX
2370 (char_u *)FALSE
2371#else
2372 (char_u *)TRUE
2373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2376 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2379 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"showmode", "smd", P_BOOL|P_VIM,
2382 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002383 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002384 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2385#ifdef FEAT_WINDOWS
2386 (char_u *)&p_stal, PV_NONE,
2387#else
2388 (char_u *)NULL, PV_NONE,
2389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2392 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2395 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2398 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2401 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2404#ifdef FEAT_SMARTINDENT
2405 (char_u *)&p_si, PV_SI,
2406#else
2407 (char_u *)NULL, PV_NONE,
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2411 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2414 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2417 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002419 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002420#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002421 (char_u *)VAR_WIN, PV_SPELL,
2422#else
2423 (char_u *)NULL, PV_NONE,
2424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002426 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002427#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002428 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002429 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002430#else
2431 (char_u *)NULL, PV_NONE,
2432 {(char_u *)0L, (char_u *)0L}
2433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002435 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002436#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002437 (char_u *)&p_spf, PV_SPF,
2438 {(char_u *)"", (char_u *)0L}
2439#else
2440 (char_u *)NULL, PV_NONE,
2441 {(char_u *)0L, (char_u *)0L}
2442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002443 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002444 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002445#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002446 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002447 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002448#else
2449 (char_u *)NULL, PV_NONE,
2450 {(char_u *)0L, (char_u *)0L}
2451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002453 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002454#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002455 (char_u *)&p_sps, PV_NONE,
2456 {(char_u *)"best", (char_u *)0L}
2457#else
2458 (char_u *)NULL, PV_NONE,
2459 {(char_u *)0L, (char_u *)0L}
2460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2463#ifdef FEAT_WINDOWS
2464 (char_u *)&p_sb, PV_NONE,
2465#else
2466 (char_u *)NULL, PV_NONE,
2467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"splitright", "spr", P_BOOL|P_VI_DEF,
2470#ifdef FEAT_VERTSPLIT
2471 (char_u *)&p_spr, PV_NONE,
2472#else
2473 (char_u *)NULL, PV_NONE,
2474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2477 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2480#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002481 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482#else
2483 (char_u *)NULL, PV_NONE,
2484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2487 (char_u *)&p_su, PV_NONE,
2488 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002491#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 (char_u *)&p_sua, PV_SUA,
2493 {(char_u *)"", (char_u *)0L}
2494#else
2495 (char_u *)NULL, PV_NONE,
2496 {(char_u *)0L, (char_u *)0L}
2497#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2500 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"swapsync", "sws", P_STRING|P_VI_DEF,
2503 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2506 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002508 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2509#ifdef FEAT_SYN_HL
2510 (char_u *)&p_smc, PV_SMC,
2511 {(char_u *)3000L, (char_u *)0L}
2512#else
2513 (char_u *)NULL, PV_NONE,
2514 {(char_u *)0L, (char_u *)0L}
2515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002516 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002517 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518#ifdef FEAT_SYN_HL
2519 (char_u *)&p_syn, PV_SYN,
2520 {(char_u *)"", (char_u *)0L}
2521#else
2522 (char_u *)NULL, PV_NONE,
2523 {(char_u *)0L, (char_u *)0L}
2524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002526 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2527#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002528 (char_u *)&p_tal, PV_NONE,
2529#else
2530 (char_u *)NULL, PV_NONE,
2531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002533 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2534#ifdef FEAT_WINDOWS
2535 (char_u *)&p_tpm, PV_NONE,
2536#else
2537 (char_u *)NULL, PV_NONE,
2538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2541 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002542 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2544 (char_u *)&p_tbs, PV_NONE,
2545#ifdef VMS /* binary searching doesn't appear to work on VMS */
2546 {(char_u *)0L, (char_u *)0L}
2547#else
2548 {(char_u *)TRUE, (char_u *)0L}
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"taglength", "tl", P_NUM|P_VI_DEF,
2552 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"tagrelative", "tr", P_BOOL|P_VIM,
2555 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002558 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {
2560#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2561 (char_u *)"./tags,./TAGS,tags,TAGS",
2562#else
2563 (char_u *)"./tags,tags",
2564#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2567 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2570 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2573#ifdef FEAT_ARABIC
2574 (char_u *)&p_tbidi, PV_NONE,
2575#else
2576 (char_u *)NULL, PV_NONE,
2577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2580#ifdef FEAT_MBYTE
2581 (char_u *)&p_tenc, PV_NONE,
2582 {(char_u *)"", (char_u *)0L}
2583#else
2584 (char_u *)NULL, PV_NONE,
2585 {(char_u *)0L, (char_u *)0L}
2586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588 {"terse", NULL, P_BOOL|P_VI_DEF,
2589 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {"textauto", "ta", P_BOOL|P_VIM,
2592 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2594 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2596 (char_u *)&p_tx, PV_TX,
2597 {
2598#ifdef USE_CRNL
2599 (char_u *)TRUE,
2600#else
2601 (char_u *)FALSE,
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002604 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002606 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2608#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002609 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610#else
2611 (char_u *)NULL, PV_NONE,
2612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2615 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"timeout", "to", P_BOOL|P_VI_DEF,
2618 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2621 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002622 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 {"title", NULL, P_BOOL|P_VI_DEF,
2624#ifdef FEAT_TITLE
2625 (char_u *)&p_title, PV_NONE,
2626#else
2627 (char_u *)NULL, PV_NONE,
2628#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 {"titlelen", NULL, P_NUM|P_VI_DEF,
2631#ifdef FEAT_TITLE
2632 (char_u *)&p_titlelen, PV_NONE,
2633#else
2634 (char_u *)NULL, PV_NONE,
2635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002637 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638#ifdef FEAT_TITLE
2639 (char_u *)&p_titleold, PV_NONE,
2640 {(char_u *)N_("Thanks for flying Vim"),
2641 (char_u *)0L}
2642#else
2643 (char_u *)NULL, PV_NONE,
2644 {(char_u *)0L, (char_u *)0L}
2645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"titlestring", NULL, P_STRING|P_VI_DEF,
2648#ifdef FEAT_TITLE
2649 (char_u *)&p_titlestring, PV_NONE,
2650#else
2651 (char_u *)NULL, PV_NONE,
2652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2655 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2656 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)"icons,tooltips", (char_u *)0L}
2658 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002660#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2662 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664#endif
2665 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2666 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2669 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2672 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002673 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2675 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002676 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2678#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2679 (char_u *)&p_ttym, PV_NONE,
2680#else
2681 (char_u *)NULL, PV_NONE,
2682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2685 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002686 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2688 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002689 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002690 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2691#ifdef FEAT_PERSISTENT_UNDO
2692 (char_u *)&p_udir, PV_NONE,
2693 {(char_u *)".", (char_u *)0L}
2694#else
2695 (char_u *)NULL, PV_NONE,
2696 {(char_u *)0L, (char_u *)0L}
2697#endif
2698 SCRIPTID_INIT},
2699 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2700#ifdef FEAT_PERSISTENT_UNDO
2701 (char_u *)&p_udf, PV_UDF,
2702#else
2703 (char_u *)NULL, PV_NONE,
2704#endif
2705 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002707 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {
2709#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2710 (char_u *)1000L,
2711#else
2712 (char_u *)100L,
2713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002715 {"undoreload", "ur", P_NUM|P_VI_DEF,
2716 (char_u *)&p_ur, PV_NONE,
2717 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"updatecount", "uc", P_NUM|P_VI_DEF,
2719 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"updatetime", "ut", P_NUM|P_VI_DEF,
2722 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"verbose", "vbs", P_NUM|P_VI_DEF,
2725 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002727 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2728 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2731#ifdef FEAT_SESSION
2732 (char_u *)&p_vdir, PV_NONE,
2733 {(char_u *)DFLT_VDIR, (char_u *)0L}
2734#else
2735 (char_u *)NULL, PV_NONE,
2736 {(char_u *)0L, (char_u *)0L}
2737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002738 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2740#ifdef FEAT_SESSION
2741 (char_u *)&p_vop, PV_NONE,
2742 {(char_u *)"folds,options,cursor", (char_u *)0L}
2743#else
2744 (char_u *)NULL, PV_NONE,
2745 {(char_u *)0L, (char_u *)0L}
2746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2749#ifdef FEAT_VIMINFO
2750 (char_u *)&p_viminfo, PV_NONE,
2751#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002752 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753#else
2754# ifdef AMIGA
2755 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002756 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002758 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759# endif
2760#endif
2761#else
2762 (char_u *)NULL, PV_NONE,
2763 {(char_u *)0L, (char_u *)0L}
2764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002765 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002766 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767#ifdef FEAT_VIRTUALEDIT
2768 (char_u *)&p_ve, PV_NONE,
2769 {(char_u *)"", (char_u *)""}
2770#else
2771 (char_u *)NULL, PV_NONE,
2772 {(char_u *)0L, (char_u *)0L}
2773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002774 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2776 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"w300", NULL, P_NUM|P_VI_DEF,
2779 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002780 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 {"w1200", NULL, P_NUM|P_VI_DEF,
2782 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"w9600", NULL, P_NUM|P_VI_DEF,
2785 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"warn", NULL, P_BOOL|P_VI_DEF,
2788 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002789 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2791 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002792 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2794 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 {"wildchar", "wc", P_NUM|P_VIM,
2797 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2799 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002800 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2804#ifdef FEAT_WILDIGN
2805 (char_u *)&p_wig, PV_NONE,
2806#else
2807 (char_u *)NULL, PV_NONE,
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002810 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2811 (char_u *)&p_wic, PV_NONE,
2812 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2814#ifdef FEAT_WILDMENU
2815 (char_u *)&p_wmnu, PV_NONE,
2816#else
2817 (char_u *)NULL, PV_NONE,
2818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2821 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002823 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2824#ifdef FEAT_CMDL_COMPL
2825 (char_u *)&p_wop, PV_NONE,
2826 {(char_u *)"", (char_u *)0L}
2827#else
2828 (char_u *)NULL, PV_NONE,
2829 {(char_u *)NULL, (char_u *)0L}
2830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2833#ifdef FEAT_WAK
2834 (char_u *)&p_wak, PV_NONE,
2835 {(char_u *)"menu", (char_u *)0L}
2836#else
2837 (char_u *)NULL, PV_NONE,
2838 {(char_u *)NULL, (char_u *)0L}
2839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002842 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"winheight", "wh", P_NUM|P_VI_DEF,
2845#ifdef FEAT_WINDOWS
2846 (char_u *)&p_wh, PV_NONE,
2847#else
2848 (char_u *)NULL, PV_NONE,
2849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002852#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 (char_u *)VAR_WIN, PV_WFH,
2854#else
2855 (char_u *)NULL, PV_NONE,
2856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002858 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2859#ifdef FEAT_VERTSPLIT
2860 (char_u *)VAR_WIN, PV_WFW,
2861#else
2862 (char_u *)NULL, PV_NONE,
2863#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002864 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002865 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2866#ifdef FEAT_WINDOWS
2867 (char_u *)&p_wmh, PV_NONE,
2868#else
2869 (char_u *)NULL, PV_NONE,
2870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002871 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2873#ifdef FEAT_VERTSPLIT
2874 (char_u *)&p_wmw, PV_NONE,
2875#else
2876 (char_u *)NULL, PV_NONE,
2877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2880#ifdef FEAT_VERTSPLIT
2881 (char_u *)&p_wiw, PV_NONE,
2882#else
2883 (char_u *)NULL, PV_NONE,
2884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002885 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2887 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2890 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2893 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002894 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895 {"write", NULL, P_BOOL|P_VI_DEF,
2896 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"writeany", "wa", P_BOOL|P_VI_DEF,
2899 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2902 (char_u *)&p_wb, PV_NONE,
2903 {
2904#ifdef FEAT_WRITEBACKUP
2905 (char_u *)TRUE,
2906#else
2907 (char_u *)FALSE,
2908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002909 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 {"writedelay", "wd", P_NUM|P_VI_DEF,
2911 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002912 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913
2914/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002915#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002916 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918
2919 p_term("t_AB", T_CAB)
2920 p_term("t_AF", T_CAF)
2921 p_term("t_AL", T_CAL)
2922 p_term("t_al", T_AL)
2923 p_term("t_bc", T_BC)
2924 p_term("t_cd", T_CD)
2925 p_term("t_ce", T_CE)
2926 p_term("t_cl", T_CL)
2927 p_term("t_cm", T_CM)
2928 p_term("t_Co", T_CCO)
2929 p_term("t_CS", T_CCS)
2930 p_term("t_cs", T_CS)
2931#ifdef FEAT_VERTSPLIT
2932 p_term("t_CV", T_CSV)
2933#endif
2934 p_term("t_ut", T_UT)
2935 p_term("t_da", T_DA)
2936 p_term("t_db", T_DB)
2937 p_term("t_DL", T_CDL)
2938 p_term("t_dl", T_DL)
2939 p_term("t_fs", T_FS)
2940 p_term("t_IE", T_CIE)
2941 p_term("t_IS", T_CIS)
2942 p_term("t_ke", T_KE)
2943 p_term("t_ks", T_KS)
2944 p_term("t_le", T_LE)
2945 p_term("t_mb", T_MB)
2946 p_term("t_md", T_MD)
2947 p_term("t_me", T_ME)
2948 p_term("t_mr", T_MR)
2949 p_term("t_ms", T_MS)
2950 p_term("t_nd", T_ND)
2951 p_term("t_op", T_OP)
2952 p_term("t_RI", T_CRI)
2953 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002954 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 p_term("t_Sb", T_CSB)
2956 p_term("t_Sf", T_CSF)
2957 p_term("t_se", T_SE)
2958 p_term("t_so", T_SO)
2959 p_term("t_sr", T_SR)
2960 p_term("t_ts", T_TS)
2961 p_term("t_te", T_TE)
2962 p_term("t_ti", T_TI)
2963 p_term("t_ue", T_UE)
2964 p_term("t_us", T_US)
2965 p_term("t_vb", T_VB)
2966 p_term("t_ve", T_VE)
2967 p_term("t_vi", T_VI)
2968 p_term("t_vs", T_VS)
2969 p_term("t_WP", T_CWP)
2970 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002971 p_term("t_SI", T_CSI)
2972 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973 p_term("t_xs", T_XS)
2974 p_term("t_ZH", T_CZH)
2975 p_term("t_ZR", T_CZR)
2976
2977/* terminal key codes are not in here */
2978
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002979 /* end marker */
2980 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981};
2982
2983#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2984
2985#ifdef FEAT_MBYTE
2986static char *(p_ambw_values[]) = {"single", "double", NULL};
2987#endif
2988static char *(p_bg_values[]) = {"light", "dark", NULL};
2989static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2990static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002991#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02002992static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002993#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002994#ifdef FEAT_CMDL_COMPL
2995static char *(p_wop_values[]) = {"tagfile", NULL};
2996#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997#ifdef FEAT_WAK
2998static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
2999#endif
3000static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3002static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004#ifdef FEAT_BROWSE
3005static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3006#endif
3007#ifdef FEAT_SCROLLBIND
3008static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3009#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003010static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011#ifdef FEAT_VERTSPLIT
3012static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3013#endif
3014#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003015# ifdef FEAT_AUTOCMD
3016static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3017# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003019# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3021#endif
3022static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3023#ifdef FEAT_FOLDING
3024static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003025# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003027# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 NULL};
3029static char *(p_fcl_values[]) = {"all", NULL};
3030#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003031#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003032static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003033#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034
3035static void set_option_default __ARGS((int, int opt_flags, int compatible));
3036static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003037static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003038static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039static char_u *illegal_char __ARGS((char_u *, int));
3040static int string_to_key __ARGS((char_u *arg));
3041#ifdef FEAT_CMDWIN
3042static char_u *check_cedit __ARGS((void));
3043#endif
3044#ifdef FEAT_TITLE
3045static void did_set_title __ARGS((int icon));
3046#endif
3047static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3048static void didset_options __ARGS((void));
3049static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003050#if defined(FEAT_EVAL) || defined(PROTO)
3051static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3052#else
3053# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3054#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003056static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
3058static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003059#ifdef FEAT_SYN_HL
3060static int int_cmp __ARGS((const void *a, const void *b));
3061#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062#ifdef FEAT_CLIPBOARD
3063static char_u *check_clipboard_option __ARGS((void));
3064#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003065#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003066static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003067#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003068#ifdef FEAT_EVAL
3069static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3070#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003072static char_u *set_num_option __ARGS((int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073static void check_redraw __ARGS((long_u flags));
3074static int findoption __ARGS((char_u *));
3075static int find_key_option __ARGS((char_u *));
3076static void showoptions __ARGS((int all, int opt_flags));
3077static int optval_default __ARGS((struct vimoption *, char_u *varp));
3078static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3079static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3080static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3081static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3082static int istermoption __ARGS((struct vimoption *));
3083static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3084static char_u *get_varp __ARGS((struct vimoption *));
3085static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003086static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3088#ifdef FEAT_LANGMAP
3089static void langmap_init __ARGS((void));
3090static void langmap_set __ARGS((void));
3091#endif
3092static void paste_option_changed __ARGS((void));
3093static void compatible_set __ARGS((void));
3094#ifdef FEAT_LINEBREAK
3095static void fill_breakat_flags __ARGS((void));
3096#endif
3097static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3098static int check_opt_strings __ARGS((char_u *val, char **values, int));
3099static int check_opt_wim __ARGS((void));
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 Moolenaar8f4ac012014-08-10 13:38:34 +02006143 ml_set_crypt_key(curbuf, oldval, crypt_get_method_nr(curbuf));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006144 }
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;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006154 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006155 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 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006166 /* When using ":set cm=name" the local value is going to be empty.
6167 * Do that here, otherwise the crypt functions will still use the
6168 * local value. */
6169 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6170 {
6171 free_string_option(curbuf->b_p_cm);
6172 curbuf->b_p_cm = empty_option;
6173 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006174
6175 /* Need to update the swapfile when the effective method changed.
6176 * Set "s" to the effective old value, "p" to the effective new
6177 * method and compare. */
6178 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6179 s = p_cm; /* was previously using the global value */
6180 else
6181 s = oldval;
6182 if (*curbuf->b_p_cm == NUL)
6183 p = p_cm; /* is now using the global value */
6184 else
6185 p = curbuf->b_p_cm;
6186 if (STRCMP(s, p) != 0)
6187 ml_set_crypt_key(curbuf, curbuf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006188 crypt_method_nr_from_name(s));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006189
6190 /* If the global value changes need to update the swapfile for all
6191 * buffers using that value. */
6192 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6193 {
6194 buf_T *buf;
6195
6196 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6197 if (buf != curbuf && *buf->b_p_cm == NUL)
6198 ml_set_crypt_key(buf, buf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006199 crypt_method_nr_from_name(oldval));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006200 }
6201 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006202 }
6203#endif
6204
6205 /* 'matchpairs' */
6206 else if (gvarp == &p_mps)
6207 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006208#ifdef FEAT_MBYTE
6209 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006210 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006211 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006212 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006213 int x2 = -1;
6214 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006215
6216 if (*p != NUL)
6217 p += mb_ptr2len(p);
6218 if (*p != NUL)
6219 x2 = *p++;
6220 if (*p != NUL)
6221 {
6222 x3 = mb_ptr2char(p);
6223 p += mb_ptr2len(p);
6224 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006225 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006226 {
6227 errmsg = e_invarg;
6228 break;
6229 }
6230 if (*p == NUL)
6231 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006232 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006233 }
6234 else
6235#endif
6236 {
6237 /* Check for "x:y,x:y" */
6238 for (p = *varp; *p != NUL; p += 4)
6239 {
6240 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6241 {
6242 errmsg = e_invarg;
6243 break;
6244 }
6245 if (p[3] == NUL)
6246 break;
6247 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006248 }
6249 }
6250
6251#ifdef FEAT_COMMENTS
6252 /* 'comments' */
6253 else if (gvarp == &p_com)
6254 {
6255 for (s = *varp; *s; )
6256 {
6257 while (*s && *s != ':')
6258 {
6259 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6260 && !VIM_ISDIGIT(*s) && *s != '-')
6261 {
6262 errmsg = illegal_char(errbuf, *s);
6263 break;
6264 }
6265 ++s;
6266 }
6267 if (*s++ == NUL)
6268 errmsg = (char_u *)N_("E524: Missing colon");
6269 else if (*s == ',' || *s == NUL)
6270 errmsg = (char_u *)N_("E525: Zero length string");
6271 if (errmsg != NULL)
6272 break;
6273 while (*s && *s != ',')
6274 {
6275 if (*s == '\\' && s[1] != NUL)
6276 ++s;
6277 ++s;
6278 }
6279 s = skip_to_option_part(s);
6280 }
6281 }
6282#endif
6283
6284 /* 'listchars' */
6285 else if (varp == &p_lcs)
6286 {
6287 errmsg = set_chars_option(varp);
6288 }
6289
6290#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6291 /* 'fillchars' */
6292 else if (varp == &p_fcs)
6293 {
6294 errmsg = set_chars_option(varp);
6295 }
6296#endif
6297
6298#ifdef FEAT_CMDWIN
6299 /* 'cedit' */
6300 else if (varp == &p_cedit)
6301 {
6302 errmsg = check_cedit();
6303 }
6304#endif
6305
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006306 /* 'verbosefile' */
6307 else if (varp == &p_vfile)
6308 {
6309 verbose_stop();
6310 if (*p_vfile != NUL && verbose_open() == FAIL)
6311 errmsg = e_invarg;
6312 }
6313
Bram Moolenaar071d4272004-06-13 20:20:40 +00006314#ifdef FEAT_VIMINFO
6315 /* 'viminfo' */
6316 else if (varp == &p_viminfo)
6317 {
6318 for (s = p_viminfo; *s;)
6319 {
6320 /* Check it's a valid character */
6321 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6322 {
6323 errmsg = illegal_char(errbuf, *s);
6324 break;
6325 }
6326 if (*s == 'n') /* name is always last one */
6327 {
6328 break;
6329 }
6330 else if (*s == 'r') /* skip until next ',' */
6331 {
6332 while (*++s && *s != ',')
6333 ;
6334 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006335 else if (*s == '%')
6336 {
6337 /* optional number */
6338 while (vim_isdigit(*++s))
6339 ;
6340 }
6341 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342 ++s; /* no extra chars */
6343 else /* must have a number */
6344 {
6345 while (vim_isdigit(*++s))
6346 ;
6347
6348 if (!VIM_ISDIGIT(*(s - 1)))
6349 {
6350 if (errbuf != NULL)
6351 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006352 sprintf((char *)errbuf,
6353 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 transchar_byte(*(s - 1)));
6355 errmsg = errbuf;
6356 }
6357 else
6358 errmsg = (char_u *)"";
6359 break;
6360 }
6361 }
6362 if (*s == ',')
6363 ++s;
6364 else if (*s)
6365 {
6366 if (errbuf != NULL)
6367 errmsg = (char_u *)N_("E527: Missing comma");
6368 else
6369 errmsg = (char_u *)"";
6370 break;
6371 }
6372 }
6373 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6374 errmsg = (char_u *)N_("E528: Must specify a ' value");
6375 }
6376#endif /* FEAT_VIMINFO */
6377
6378 /* terminal options */
6379 else if (istermoption(&options[opt_idx]) && full_screen)
6380 {
6381 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6382 if (varp == &T_CCO)
6383 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006384 int colors = atoi((char *)T_CCO);
6385
6386 /* Only reinitialize colors if t_Co value has really changed to
6387 * avoid expensive reload of colorscheme if t_Co is set to the
6388 * same value multiple times. */
6389 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006390 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006391 t_colors = colors;
6392 if (t_colors <= 1)
6393 {
6394 if (new_value_alloced)
6395 vim_free(T_CCO);
6396 T_CCO = empty_option;
6397 }
6398 /* We now have a different color setup, initialize it again. */
6399 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006400 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006401 }
6402 ttest(FALSE);
6403 if (varp == &T_ME)
6404 {
6405 out_str(T_ME);
6406 redraw_later(CLEAR);
6407#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6408 /* Since t_me has been set, this probably means that the user
6409 * wants to use this as default colors. Need to reset default
6410 * background/foreground colors. */
6411 mch_set_normal_colors();
6412#endif
6413 }
6414 }
6415
6416#ifdef FEAT_LINEBREAK
6417 /* 'showbreak' */
6418 else if (varp == &p_sbr)
6419 {
6420 for (s = p_sbr; *s; )
6421 {
6422 if (ptr2cells(s) != 1)
6423 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006424 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006425 }
6426 }
6427#endif
6428
6429#ifdef FEAT_GUI
6430 /* 'guifont' */
6431 else if (varp == &p_guifont)
6432 {
6433 if (gui.in_use)
6434 {
6435 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006436# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006437 /*
6438 * Put up a font dialog and let the user select a new value.
6439 * If this is cancelled go back to the old value but don't
6440 * give an error message.
6441 */
6442 if (STRCMP(p, "*") == 0)
6443 {
6444 p = gui_mch_font_dialog(oldval);
6445
6446 if (new_value_alloced)
6447 free_string_option(p_guifont);
6448
6449 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6450 new_value_alloced = TRUE;
6451 }
6452# endif
6453 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6454 {
6455# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6456 if (STRCMP(p_guifont, "*") == 0)
6457 {
6458 /* Dialog was cancelled: Keep the old value without giving
6459 * an error message. */
6460 if (new_value_alloced)
6461 free_string_option(p_guifont);
6462 p_guifont = vim_strsave(oldval);
6463 new_value_alloced = TRUE;
6464 }
6465 else
6466# endif
6467 errmsg = (char_u *)N_("E596: Invalid font(s)");
6468 }
6469 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006470 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006471 }
6472# ifdef FEAT_XFONTSET
6473 else if (varp == &p_guifontset)
6474 {
6475 if (STRCMP(p_guifontset, "*") == 0)
6476 errmsg = (char_u *)N_("E597: can't select fontset");
6477 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6478 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006479 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480 }
6481# endif
6482# ifdef FEAT_MBYTE
6483 else if (varp == &p_guifontwide)
6484 {
6485 if (STRCMP(p_guifontwide, "*") == 0)
6486 errmsg = (char_u *)N_("E533: can't select wide font");
6487 else if (gui_get_wide_font() == FAIL)
6488 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006489 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006490 }
6491# endif
6492#endif
6493
6494#ifdef CURSOR_SHAPE
6495 /* 'guicursor' */
6496 else if (varp == &p_guicursor)
6497 errmsg = parse_shape_opt(SHAPE_CURSOR);
6498#endif
6499
6500#ifdef FEAT_MOUSESHAPE
6501 /* 'mouseshape' */
6502 else if (varp == &p_mouseshape)
6503 {
6504 errmsg = parse_shape_opt(SHAPE_MOUSE);
6505 update_mouseshape(-1);
6506 }
6507#endif
6508
6509#ifdef FEAT_PRINTER
6510 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006511 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006512# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006513 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006514 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006515# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006516#endif
6517
6518#ifdef FEAT_LANGMAP
6519 /* 'langmap' */
6520 else if (varp == &p_langmap)
6521 langmap_set();
6522#endif
6523
6524#ifdef FEAT_LINEBREAK
6525 /* 'breakat' */
6526 else if (varp == &p_breakat)
6527 fill_breakat_flags();
6528#endif
6529
6530#ifdef FEAT_TITLE
6531 /* 'titlestring' and 'iconstring' */
6532 else if (varp == &p_titlestring || varp == &p_iconstring)
6533 {
6534# ifdef FEAT_STL_OPT
6535 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6536
6537 /* NULL => statusline syntax */
6538 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6539 stl_syntax |= flagval;
6540 else
6541 stl_syntax &= ~flagval;
6542# endif
6543 did_set_title(varp == &p_iconstring);
6544
6545 }
6546#endif
6547
6548#ifdef FEAT_GUI
6549 /* 'guioptions' */
6550 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006551 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006552 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006553 redraw_gui_only = TRUE;
6554 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555#endif
6556
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006557#if defined(FEAT_GUI_TABLINE)
6558 /* 'guitablabel' */
6559 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006560 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006561 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006562 redraw_gui_only = TRUE;
6563 }
6564 /* 'guitabtooltip' */
6565 else if (varp == &p_gtt)
6566 {
6567 redraw_gui_only = TRUE;
6568 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006569#endif
6570
Bram Moolenaar071d4272004-06-13 20:20:40 +00006571#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6572 /* 'ttymouse' */
6573 else if (varp == &p_ttym)
6574 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006575 /* Switch the mouse off before changing the escape sequences used for
6576 * that. */
6577 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6579 errmsg = e_invarg;
6580 else
6581 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006582 if (termcap_active)
6583 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006584 }
6585#endif
6586
Bram Moolenaar071d4272004-06-13 20:20:40 +00006587 /* 'selection' */
6588 else if (varp == &p_sel)
6589 {
6590 if (*p_sel == NUL
6591 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6592 errmsg = e_invarg;
6593 }
6594
6595 /* 'selectmode' */
6596 else if (varp == &p_slm)
6597 {
6598 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6599 errmsg = e_invarg;
6600 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006601
6602#ifdef FEAT_BROWSE
6603 /* 'browsedir' */
6604 else if (varp == &p_bsdir)
6605 {
6606 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6607 && !mch_isdir(p_bsdir))
6608 errmsg = e_invarg;
6609 }
6610#endif
6611
Bram Moolenaar071d4272004-06-13 20:20:40 +00006612 /* 'keymodel' */
6613 else if (varp == &p_km)
6614 {
6615 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6616 errmsg = e_invarg;
6617 else
6618 {
6619 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6620 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6621 }
6622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006623
6624 /* 'mousemodel' */
6625 else if (varp == &p_mousem)
6626 {
6627 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6628 errmsg = e_invarg;
6629#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6630 else if (*p_mousem != *oldval)
6631 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6632 * to create or delete the popup menus. */
6633 gui_motif_update_mousemodel(root_menu);
6634#endif
6635 }
6636
6637 /* 'switchbuf' */
6638 else if (varp == &p_swb)
6639 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006640 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006641 errmsg = e_invarg;
6642 }
6643
6644 /* 'debug' */
6645 else if (varp == &p_debug)
6646 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006647 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006648 errmsg = e_invarg;
6649 }
6650
6651 /* 'display' */
6652 else if (varp == &p_dy)
6653 {
6654 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6655 errmsg = e_invarg;
6656 else
6657 (void)init_chartab();
6658
6659 }
6660
6661#ifdef FEAT_VERTSPLIT
6662 /* 'eadirection' */
6663 else if (varp == &p_ead)
6664 {
6665 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6666 errmsg = e_invarg;
6667 }
6668#endif
6669
6670#ifdef FEAT_CLIPBOARD
6671 /* 'clipboard' */
6672 else if (varp == &p_cb)
6673 errmsg = check_clipboard_option();
6674#endif
6675
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006676#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006677 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6678 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006679 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006680 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006681 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006682 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006683
Bram Moolenaar860cae12010-06-05 23:22:07 +02006684 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006685 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006686 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6687 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006688 ".add") != 0))
6689 errmsg = e_invarg;
6690 }
6691
6692 if (errmsg == NULL)
6693 {
6694 FOR_ALL_WINDOWS(wp)
6695 if (wp->w_buffer == curbuf && wp->w_p_spell)
6696 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006697 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006698# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006699 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006700# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006701 }
6702 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006703 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006704 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006705 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006706 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006707 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006708 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006709 /* 'spellsuggest' */
6710 else if (varp == &p_sps)
6711 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006712 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006713 errmsg = e_invarg;
6714 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006715 /* 'mkspellmem' */
6716 else if (varp == &p_msm)
6717 {
6718 if (spell_check_msm() != OK)
6719 errmsg = e_invarg;
6720 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006721#endif
6722
Bram Moolenaar071d4272004-06-13 20:20:40 +00006723#ifdef FEAT_QUICKFIX
6724 /* When 'bufhidden' is set, check for valid value. */
6725 else if (gvarp == &p_bh)
6726 {
6727 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6728 errmsg = e_invarg;
6729 }
6730
6731 /* When 'buftype' is set, check for valid value. */
6732 else if (gvarp == &p_bt)
6733 {
6734 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6735 errmsg = e_invarg;
6736 else
6737 {
6738# ifdef FEAT_WINDOWS
6739 if (curwin->w_status_height)
6740 {
6741 curwin->w_redr_status = TRUE;
6742 redraw_later(VALID);
6743 }
6744# endif
6745 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006746# ifdef FEAT_TITLE
6747 redraw_titles();
6748# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749 }
6750 }
6751#endif
6752
6753#ifdef FEAT_STL_OPT
6754 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006755 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 {
6757 int wid;
6758
6759 if (varp == &p_ruf) /* reset ru_wid first */
6760 ru_wid = 0;
6761 s = *varp;
6762 if (varp == &p_ruf && *s == '%')
6763 {
6764 /* set ru_wid if 'ruf' starts with "%99(" */
6765 if (*++s == '-') /* ignore a '-' */
6766 s++;
6767 wid = getdigits(&s);
6768 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6769 ru_wid = wid;
6770 else
6771 errmsg = check_stl_option(p_ruf);
6772 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006773 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006774 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006775 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006776 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777 comp_col();
6778 }
6779#endif
6780
6781#ifdef FEAT_INS_EXPAND
6782 /* check if it is a valid value for 'complete' -- Acevedo */
6783 else if (gvarp == &p_cpt)
6784 {
6785 for (s = *varp; *s;)
6786 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006787 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006788 s++;
6789 if (!*s)
6790 break;
6791 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6792 {
6793 errmsg = illegal_char(errbuf, *s);
6794 break;
6795 }
6796 if (*++s != NUL && *s != ',' && *s != ' ')
6797 {
6798 if (s[-1] == 'k' || s[-1] == 's')
6799 {
6800 /* skip optional filename after 'k' and 's' */
6801 while (*s && *s != ',' && *s != ' ')
6802 {
6803 if (*s == '\\')
6804 ++s;
6805 ++s;
6806 }
6807 }
6808 else
6809 {
6810 if (errbuf != NULL)
6811 {
6812 sprintf((char *)errbuf,
6813 _("E535: Illegal character after <%c>"),
6814 *--s);
6815 errmsg = errbuf;
6816 }
6817 else
6818 errmsg = (char_u *)"";
6819 break;
6820 }
6821 }
6822 }
6823 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006824
6825 /* 'completeopt' */
6826 else if (varp == &p_cot)
6827 {
6828 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6829 errmsg = e_invarg;
6830 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006831#endif /* FEAT_INS_EXPAND */
6832
6833
6834#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6835 else if (varp == &p_toolbar)
6836 {
6837 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6838 &toolbar_flags, TRUE) != OK)
6839 errmsg = e_invarg;
6840 else
6841 {
6842 out_flush();
6843 gui_mch_show_toolbar((toolbar_flags &
6844 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6845 }
6846 }
6847#endif
6848
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006849#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006850 /* 'toolbariconsize': GTK+ 2 only */
6851 else if (varp == &p_tbis)
6852 {
6853 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6854 errmsg = e_invarg;
6855 else
6856 {
6857 out_flush();
6858 gui_mch_show_toolbar((toolbar_flags &
6859 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6860 }
6861 }
6862#endif
6863
6864 /* 'pastetoggle': translate key codes like in a mapping */
6865 else if (varp == &p_pt)
6866 {
6867 if (*p_pt)
6868 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006869 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006870 if (p != NULL)
6871 {
6872 if (new_value_alloced)
6873 free_string_option(p_pt);
6874 p_pt = p;
6875 new_value_alloced = TRUE;
6876 }
6877 }
6878 }
6879
6880 /* 'backspace' */
6881 else if (varp == &p_bs)
6882 {
6883 if (VIM_ISDIGIT(*p_bs))
6884 {
6885 if (*p_bs >'2' || p_bs[1] != NUL)
6886 errmsg = e_invarg;
6887 }
6888 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6889 errmsg = e_invarg;
6890 }
6891
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006892#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006893 /* 'casemap' */
6894 else if (varp == &p_cmp)
6895 {
6896 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6897 errmsg = e_invarg;
6898 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006899#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006900
6901#ifdef FEAT_DIFF
6902 /* 'diffopt' */
6903 else if (varp == &p_dip)
6904 {
6905 if (diffopt_changed() == FAIL)
6906 errmsg = e_invarg;
6907 }
6908#endif
6909
6910#ifdef FEAT_FOLDING
6911 /* 'foldmethod' */
6912 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6913 {
6914 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6915 || *curwin->w_p_fdm == NUL)
6916 errmsg = e_invarg;
6917 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006918 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006919 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006920 if (foldmethodIsDiff(curwin))
6921 newFoldLevel();
6922 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006923 }
6924# ifdef FEAT_EVAL
6925 /* 'foldexpr' */
6926 else if (varp == &curwin->w_p_fde)
6927 {
6928 if (foldmethodIsExpr(curwin))
6929 foldUpdateAll(curwin);
6930 }
6931# endif
6932 /* 'foldmarker' */
6933 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6934 {
6935 p = vim_strchr(*varp, ',');
6936 if (p == NULL)
6937 errmsg = (char_u *)N_("E536: comma required");
6938 else if (p == *varp || p[1] == NUL)
6939 errmsg = e_invarg;
6940 else if (foldmethodIsMarker(curwin))
6941 foldUpdateAll(curwin);
6942 }
6943 /* 'commentstring' */
6944 else if (gvarp == &p_cms)
6945 {
6946 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6947 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6948 }
6949 /* 'foldopen' */
6950 else if (varp == &p_fdo)
6951 {
6952 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6953 errmsg = e_invarg;
6954 }
6955 /* 'foldclose' */
6956 else if (varp == &p_fcl)
6957 {
6958 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6959 errmsg = e_invarg;
6960 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006961 /* 'foldignore' */
6962 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6963 {
6964 if (foldmethodIsIndent(curwin))
6965 foldUpdateAll(curwin);
6966 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006967#endif
6968
6969#ifdef FEAT_VIRTUALEDIT
6970 /* 'virtualedit' */
6971 else if (varp == &p_ve)
6972 {
6973 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6974 errmsg = e_invarg;
6975 else if (STRCMP(p_ve, oldval) != 0)
6976 {
6977 /* Recompute cursor position in case the new 've' setting
6978 * changes something. */
6979 validate_virtcol();
6980 coladvance(curwin->w_virtcol);
6981 }
6982 }
6983#endif
6984
6985#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
6986 else if (varp == &p_csqf)
6987 {
6988 if (p_csqf != NULL)
6989 {
6990 p = p_csqf;
6991 while (*p != NUL)
6992 {
6993 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
6994 || p[1] == NUL
6995 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
6996 || (p[2] != NUL && p[2] != ','))
6997 {
6998 errmsg = e_invarg;
6999 break;
7000 }
7001 else if (p[2] == NUL)
7002 break;
7003 else
7004 p += 3;
7005 }
7006 }
7007 }
7008#endif
7009
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007010#ifdef FEAT_CINDENT
7011 /* 'cinoptions' */
7012 else if (gvarp == &p_cino)
7013 {
7014 /* TODO: recognize errors */
7015 parse_cino(curbuf);
7016 }
7017#endif
7018
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007019#if defined(FEAT_RENDER_OPTIONS)
7020 else if (varp == &p_rop && gui.in_use)
7021 {
7022 if (!gui_mch_set_rendering_options(p_rop))
7023 errmsg = e_invarg;
7024 }
7025#endif
7026
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027 /* Options that are a list of flags. */
7028 else
7029 {
7030 p = NULL;
7031 if (varp == &p_ww)
7032 p = (char_u *)WW_ALL;
7033 if (varp == &p_shm)
7034 p = (char_u *)SHM_ALL;
7035 else if (varp == &(p_cpo))
7036 p = (char_u *)CPO_ALL;
7037 else if (varp == &(curbuf->b_p_fo))
7038 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007039#ifdef FEAT_CONCEAL
7040 else if (varp == &curwin->w_p_cocu)
7041 p = (char_u *)COCU_ALL;
7042#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007043 else if (varp == &p_mouse)
7044 {
7045#ifdef FEAT_MOUSE
7046 p = (char_u *)MOUSE_ALL;
7047#else
7048 if (*p_mouse != NUL)
7049 errmsg = (char_u *)N_("E538: No mouse support");
7050#endif
7051 }
7052#if defined(FEAT_GUI)
7053 else if (varp == &p_go)
7054 p = (char_u *)GO_ALL;
7055#endif
7056 if (p != NULL)
7057 {
7058 for (s = *varp; *s; ++s)
7059 if (vim_strchr(p, *s) == NULL)
7060 {
7061 errmsg = illegal_char(errbuf, *s);
7062 break;
7063 }
7064 }
7065 }
7066
7067 /*
7068 * If error detected, restore the previous value.
7069 */
7070 if (errmsg != NULL)
7071 {
7072 if (new_value_alloced)
7073 free_string_option(*varp);
7074 *varp = oldval;
7075 /*
7076 * When resetting some values, need to act on it.
7077 */
7078 if (did_chartab)
7079 (void)init_chartab();
7080 if (varp == &p_hl)
7081 (void)highlight_changed();
7082 }
7083 else
7084 {
7085#ifdef FEAT_EVAL
7086 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007087 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007088#endif
7089 /*
7090 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007091 * Use "free_oldval", because recursiveness may change the flags under
7092 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007093 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007094 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007095 free_string_option(oldval);
7096 if (new_value_alloced)
7097 options[opt_idx].flags |= P_ALLOCED;
7098 else
7099 options[opt_idx].flags &= ~P_ALLOCED;
7100
7101 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007102 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007103 {
7104 /* global option with local value set to use global value; free
7105 * the local value and make it empty */
7106 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7107 free_string_option(*(char_u **)p);
7108 *(char_u **)p = empty_option;
7109 }
7110
7111 /* May set global value for local option. */
7112 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7113 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007114
7115#ifdef FEAT_AUTOCMD
7116 /*
7117 * Trigger the autocommand only after setting the flags.
7118 */
7119# ifdef FEAT_SYN_HL
7120 /* When 'syntax' is set, load the syntax of that name */
7121 if (varp == &(curbuf->b_p_syn))
7122 {
7123 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7124 curbuf->b_fname, TRUE, curbuf);
7125 }
7126# endif
7127 else if (varp == &(curbuf->b_p_ft))
7128 {
7129 /* 'filetype' is set, trigger the FileType autocommand */
7130 did_filetype = TRUE;
7131 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7132 curbuf->b_fname, TRUE, curbuf);
7133 }
7134#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007135#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007136 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007137 {
7138 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007139 char_u *q = curwin->w_s->b_p_spl;
7140
7141 /* Skip the first name if it is "cjk". */
7142 if (STRNCMP(q, "cjk,", 4) == 0)
7143 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007144
7145 /*
7146 * Source the spell/LANG.vim in 'runtimepath'.
7147 * They could set 'spellcapcheck' depending on the language.
7148 * Use the first name in 'spelllang' up to '_region' or
7149 * '.encoding'.
7150 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007151 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007152 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7153 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007154 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007155 source_runtime(fname, TRUE);
7156 }
7157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158 }
7159
7160#ifdef FEAT_MOUSE
7161 if (varp == &p_mouse)
7162 {
7163# ifdef FEAT_MOUSE_TTY
7164 if (*p_mouse == NUL)
7165 mch_setmouse(FALSE); /* switch mouse off */
7166 else
7167# endif
7168 setmouse(); /* in case 'mouse' changed */
7169 }
7170#endif
7171
Bram Moolenaar913077c2012-03-28 19:59:04 +02007172 if (curwin->w_curswant != MAXCOL
7173 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7174 curwin->w_set_curswant = TRUE;
7175
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007176#ifdef FEAT_GUI
7177 /* check redraw when it's not a GUI option or the GUI is active. */
7178 if (!redraw_gui_only || gui.in_use)
7179#endif
7180 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181
7182 return errmsg;
7183}
7184
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007185#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007186/*
7187 * Simple int comparison function for use with qsort()
7188 */
7189 static int
7190int_cmp(a, b)
7191 const void *a;
7192 const void *b;
7193{
7194 return *(const int *)a - *(const int *)b;
7195}
7196
7197/*
7198 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7199 * Returns error message, NULL if it's OK.
7200 */
7201 char_u *
7202check_colorcolumn(wp)
7203 win_T *wp;
7204{
7205 char_u *s;
7206 int col;
7207 int count = 0;
7208 int color_cols[256];
7209 int i;
7210 int j = 0;
7211
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007212 if (wp->w_buffer == NULL)
7213 return NULL; /* buffer was closed */
7214
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007215 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007216 {
7217 if (*s == '-' || *s == '+')
7218 {
7219 /* -N and +N: add to 'textwidth' */
7220 col = (*s == '-') ? -1 : 1;
7221 ++s;
7222 if (!VIM_ISDIGIT(*s))
7223 return e_invarg;
7224 col = col * getdigits(&s);
7225 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007226 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007227 col += wp->w_buffer->b_p_tw;
7228 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007229 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007230 }
7231 else if (VIM_ISDIGIT(*s))
7232 col = getdigits(&s);
7233 else
7234 return e_invarg;
7235 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007236skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007237 if (*s == NUL)
7238 break;
7239 if (*s != ',')
7240 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007241 if (*++s == NUL)
7242 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007243 }
7244
7245 vim_free(wp->w_p_cc_cols);
7246 if (count == 0)
7247 wp->w_p_cc_cols = NULL;
7248 else
7249 {
7250 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7251 if (wp->w_p_cc_cols != NULL)
7252 {
7253 /* sort the columns for faster usage on screen redraw inside
7254 * win_line() */
7255 qsort(color_cols, count, sizeof(int), int_cmp);
7256
7257 for (i = 0; i < count; ++i)
7258 /* skip duplicates */
7259 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7260 wp->w_p_cc_cols[j++] = color_cols[i];
7261 wp->w_p_cc_cols[j] = -1; /* end marker */
7262 }
7263 }
7264
7265 return NULL; /* no error */
7266}
7267#endif
7268
Bram Moolenaar071d4272004-06-13 20:20:40 +00007269/*
7270 * Handle setting 'listchars' or 'fillchars'.
7271 * Returns error message, NULL if it's OK.
7272 */
7273 static char_u *
7274set_chars_option(varp)
7275 char_u **varp;
7276{
7277 int round, i, len, entries;
7278 char_u *p, *s;
7279 int c1, c2 = 0;
7280 struct charstab
7281 {
7282 int *cp;
7283 char *name;
7284 };
7285#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7286 static struct charstab filltab[] =
7287 {
7288 {&fill_stl, "stl"},
7289 {&fill_stlnc, "stlnc"},
7290 {&fill_vert, "vert"},
7291 {&fill_fold, "fold"},
7292 {&fill_diff, "diff"},
7293 };
7294#endif
7295 static struct charstab lcstab[] =
7296 {
7297 {&lcs_eol, "eol"},
7298 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007299 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007300 {&lcs_prec, "precedes"},
7301 {&lcs_tab2, "tab"},
7302 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007303#ifdef FEAT_CONCEAL
7304 {&lcs_conceal, "conceal"},
7305#else
7306 {NULL, "conceal"},
7307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007308 };
7309 struct charstab *tab;
7310
7311#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7312 if (varp == &p_lcs)
7313#endif
7314 {
7315 tab = lcstab;
7316 entries = sizeof(lcstab) / sizeof(struct charstab);
7317 }
7318#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7319 else
7320 {
7321 tab = filltab;
7322 entries = sizeof(filltab) / sizeof(struct charstab);
7323 }
7324#endif
7325
7326 /* first round: check for valid value, second round: assign values */
7327 for (round = 0; round <= 1; ++round)
7328 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007329 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007330 {
7331 /* After checking that the value is valid: set defaults: space for
7332 * 'fillchars', NUL for 'listchars' */
7333 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007334 if (tab[i].cp != NULL)
7335 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336 if (varp == &p_lcs)
7337 lcs_tab1 = NUL;
7338#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7339 else
7340 fill_diff = '-';
7341#endif
7342 }
7343 p = *varp;
7344 while (*p)
7345 {
7346 for (i = 0; i < entries; ++i)
7347 {
7348 len = (int)STRLEN(tab[i].name);
7349 if (STRNCMP(p, tab[i].name, len) == 0
7350 && p[len] == ':'
7351 && p[len + 1] != NUL)
7352 {
7353 s = p + len + 1;
7354#ifdef FEAT_MBYTE
7355 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007356 if (mb_char2cells(c1) > 1)
7357 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007358#else
7359 c1 = *s++;
7360#endif
7361 if (tab[i].cp == &lcs_tab2)
7362 {
7363 if (*s == NUL)
7364 continue;
7365#ifdef FEAT_MBYTE
7366 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007367 if (mb_char2cells(c2) > 1)
7368 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007369#else
7370 c2 = *s++;
7371#endif
7372 }
7373 if (*s == ',' || *s == NUL)
7374 {
7375 if (round)
7376 {
7377 if (tab[i].cp == &lcs_tab2)
7378 {
7379 lcs_tab1 = c1;
7380 lcs_tab2 = c2;
7381 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007382 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007383 *(tab[i].cp) = c1;
7384
7385 }
7386 p = s;
7387 break;
7388 }
7389 }
7390 }
7391
7392 if (i == entries)
7393 return e_invarg;
7394 if (*p == ',')
7395 ++p;
7396 }
7397 }
7398
7399 return NULL; /* no error */
7400}
7401
7402#ifdef FEAT_STL_OPT
7403/*
7404 * Check validity of options with the 'statusline' format.
7405 * Return error message or NULL.
7406 */
7407 char_u *
7408check_stl_option(s)
7409 char_u *s;
7410{
7411 int itemcnt = 0;
7412 int groupdepth = 0;
7413 static char_u errbuf[80];
7414
7415 while (*s && itemcnt < STL_MAX_ITEM)
7416 {
7417 /* Check for valid keys after % sequences */
7418 while (*s && *s != '%')
7419 s++;
7420 if (!*s)
7421 break;
7422 s++;
7423 if (*s != '%' && *s != ')')
7424 ++itemcnt;
7425 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7426 {
7427 s++;
7428 continue;
7429 }
7430 if (*s == ')')
7431 {
7432 s++;
7433 if (--groupdepth < 0)
7434 break;
7435 continue;
7436 }
7437 if (*s == '-')
7438 s++;
7439 while (VIM_ISDIGIT(*s))
7440 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007441 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007442 continue;
7443 if (*s == '.')
7444 {
7445 s++;
7446 while (*s && VIM_ISDIGIT(*s))
7447 s++;
7448 }
7449 if (*s == '(')
7450 {
7451 groupdepth++;
7452 continue;
7453 }
7454 if (vim_strchr(STL_ALL, *s) == NULL)
7455 {
7456 return illegal_char(errbuf, *s);
7457 }
7458 if (*s == '{')
7459 {
7460 s++;
7461 while (*s != '}' && *s)
7462 s++;
7463 if (*s != '}')
7464 return (char_u *)N_("E540: Unclosed expression sequence");
7465 }
7466 }
7467 if (itemcnt >= STL_MAX_ITEM)
7468 return (char_u *)N_("E541: too many items");
7469 if (groupdepth != 0)
7470 return (char_u *)N_("E542: unbalanced groups");
7471 return NULL;
7472}
7473#endif
7474
7475#ifdef FEAT_CLIPBOARD
7476/*
7477 * Extract the items in the 'clipboard' option and set global values.
7478 */
7479 static char_u *
7480check_clipboard_option()
7481{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007482 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007483 int new_autoselect_star = FALSE;
7484 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007485 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007486 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007487 regprog_T *new_exclude_prog = NULL;
7488 char_u *errmsg = NULL;
7489 char_u *p;
7490
7491 for (p = p_cb; *p != NUL; )
7492 {
7493 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7494 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007495 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007496 p += 7;
7497 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007498 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007499 && (p[11] == ',' || p[11] == NUL))
7500 {
7501 new_unnamed |= CLIP_UNNAMED_PLUS;
7502 p += 11;
7503 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007505 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007506 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007507 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007508 p += 10;
7509 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007510 else if (STRNCMP(p, "autoselectplus", 14) == 0
7511 && (p[14] == ',' || p[14] == NUL))
7512 {
7513 new_autoselect_plus = TRUE;
7514 p += 14;
7515 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007516 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007517 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518 {
7519 new_autoselectml = TRUE;
7520 p += 12;
7521 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007522 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7523 {
7524 new_html = TRUE;
7525 p += 4;
7526 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7528 {
7529 p += 8;
7530 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7531 if (new_exclude_prog == NULL)
7532 errmsg = e_invarg;
7533 break;
7534 }
7535 else
7536 {
7537 errmsg = e_invarg;
7538 break;
7539 }
7540 if (*p == ',')
7541 ++p;
7542 }
7543 if (errmsg == NULL)
7544 {
7545 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007546 clip_autoselect_star = new_autoselect_star;
7547 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007549 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007550 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007551 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007552#ifdef FEAT_GUI_GTK
7553 if (gui.in_use)
7554 {
7555 gui_gtk_set_selection_targets();
7556 gui_gtk_set_dnd_targets();
7557 }
7558#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007559 }
7560 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007561 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007562
7563 return errmsg;
7564}
7565#endif
7566
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007567#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007568/*
7569 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7570 * Return error message when failed, NULL when OK.
7571 */
7572 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007573compile_cap_prog(synblock)
7574 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007575{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007576 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007577 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007578
Bram Moolenaar860cae12010-06-05 23:22:07 +02007579 if (*synblock->b_p_spc == NUL)
7580 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007581 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007582 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007583 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007584 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007585 if (re != NULL)
7586 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007587 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007588 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007589 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007590 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007591 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007592 return e_invarg;
7593 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007594 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007595 }
7596
Bram Moolenaar473de612013-06-08 18:19:48 +02007597 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007598 return NULL;
7599}
7600#endif
7601
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007602#if defined(FEAT_EVAL) || defined(PROTO)
7603/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007604 * Set the scriptID for an option, taking care of setting the buffer- or
7605 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007606 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007607 static void
7608set_option_scriptID_idx(opt_idx, opt_flags, id)
7609 int opt_idx;
7610 int opt_flags;
7611 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007612{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007613 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7614 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007615
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007616 /* Remember where the option was set. For local options need to do that
7617 * in the buffer or window structure. */
7618 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007619 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007620 if (both || (opt_flags & OPT_LOCAL))
7621 {
7622 if (indir & PV_BUF)
7623 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7624 else if (indir & PV_WIN)
7625 curwin->w_p_scriptID[indir & PV_MASK] = id;
7626 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007627}
7628#endif
7629
Bram Moolenaar071d4272004-06-13 20:20:40 +00007630/*
7631 * Set the value of a boolean option, and take care of side effects.
7632 * Returns NULL for success, or an error message for an error.
7633 */
7634 static char_u *
7635set_bool_option(opt_idx, varp, value, opt_flags)
7636 int opt_idx; /* index in options[] table */
7637 char_u *varp; /* pointer to the option variable */
7638 int value; /* new value */
7639 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7640{
7641 int old_value = *(int *)varp;
7642
Bram Moolenaar071d4272004-06-13 20:20:40 +00007643 /* Disallow changing some options from secure mode */
7644 if ((secure
7645#ifdef HAVE_SANDBOX
7646 || sandbox != 0
7647#endif
7648 ) && (options[opt_idx].flags & P_SECURE))
7649 return e_secure;
7650
7651 *(int *)varp = value; /* set the new value */
7652#ifdef FEAT_EVAL
7653 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007654 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007655#endif
7656
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007657#ifdef FEAT_GUI
7658 need_mouse_correct = TRUE;
7659#endif
7660
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 /* May set global value for local option. */
7662 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7663 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7664
7665 /*
7666 * Handle side effects of changing a bool option.
7667 */
7668
7669 /* 'compatible' */
7670 if ((int *)varp == &p_cp)
7671 {
7672 compatible_set();
7673 }
7674
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007675#ifdef FEAT_PERSISTENT_UNDO
7676 /* 'undofile' */
7677 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7678 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007679 /* Only take action when the option was set. When reset we do not
7680 * delete the undo file, the option may be set again without making
7681 * any changes in between. */
7682 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007683 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007684 char_u hash[UNDO_HASH_SIZE];
7685 buf_T *save_curbuf = curbuf;
7686
7687 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007688 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007689 /* When 'undofile' is set globally: for every buffer, otherwise
7690 * only for the current buffer: Try to read in the undofile,
7691 * if one exists, the buffer wasn't changed and the buffer was
7692 * loaded */
7693 if ((curbuf == save_curbuf
7694 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7695 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7696 {
7697 u_compute_hash(hash);
7698 u_read_undo(NULL, hash, curbuf->b_fname);
7699 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007700 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007701 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007702 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007703 }
7704#endif
7705
Bram Moolenaar071d4272004-06-13 20:20:40 +00007706 else if ((int *)varp == &curbuf->b_p_ro)
7707 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007708 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007709 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7710 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007711
7712 /* when 'readonly' is set may give W10 again */
7713 if (curbuf->b_p_ro)
7714 curbuf->b_did_warn = FALSE;
7715
Bram Moolenaar071d4272004-06-13 20:20:40 +00007716#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007717 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007718#endif
7719 }
7720
Bram Moolenaar9c449722010-07-20 18:44:27 +02007721#ifdef FEAT_GUI
7722 else if ((int *)varp == &p_mh)
7723 {
7724 if (!p_mh)
7725 gui_mch_mousehide(FALSE);
7726 }
7727#endif
7728
Bram Moolenaara539df02010-08-01 14:35:05 +02007729#ifdef FEAT_TITLE
7730 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007731 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007732 {
7733 redraw_titles();
7734 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735 /* when 'endofline' is changed, redraw the window title */
7736 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007737 {
7738 redraw_titles();
7739 }
7740# ifdef FEAT_MBYTE
7741 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007742 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007743 {
7744 redraw_titles();
7745 }
7746# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007747#endif
7748
7749 /* when 'bin' is set also set some other options */
7750 else if ((int *)varp == &curbuf->b_p_bin)
7751 {
7752 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7753#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007754 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755#endif
7756 }
7757
7758#ifdef FEAT_AUTOCMD
7759 /* when 'buflisted' changes, trigger autocommands */
7760 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7761 {
7762 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7763 NULL, NULL, TRUE, curbuf);
7764 }
7765#endif
7766
7767 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7768 else if ((int *)varp == &curbuf->b_p_swf)
7769 {
7770 if (curbuf->b_p_swf && p_uc)
7771 ml_open_file(curbuf); /* create the swap file */
7772 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007773 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7774 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007775 mf_close_file(curbuf, TRUE); /* remove the swap file */
7776 }
7777
7778 /* when 'terse' is set change 'shortmess' */
7779 else if ((int *)varp == &p_terse)
7780 {
7781 char_u *p;
7782
7783 p = vim_strchr(p_shm, SHM_SEARCH);
7784
7785 /* insert 's' in p_shm */
7786 if (p_terse && p == NULL)
7787 {
7788 STRCPY(IObuff, p_shm);
7789 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007790 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 }
7792 /* remove 's' from p_shm */
7793 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007794 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007795 }
7796
7797 /* when 'paste' is set or reset also change other options */
7798 else if ((int *)varp == &p_paste)
7799 {
7800 paste_option_changed();
7801 }
7802
7803 /* when 'insertmode' is set from an autocommand need to do work here */
7804 else if ((int *)varp == &p_im)
7805 {
7806 if (p_im)
7807 {
7808 if ((State & INSERT) == 0)
7809 need_start_insertmode = TRUE;
7810 stop_insert_mode = FALSE;
7811 }
7812 else
7813 {
7814 need_start_insertmode = FALSE;
7815 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007816 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007817 clear_cmdline = TRUE; /* remove "(insert)" */
7818 restart_edit = 0;
7819 }
7820 }
7821
7822 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7823 else if ((int *)varp == &p_ic && p_hls)
7824 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007825 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007826 }
7827
7828#ifdef FEAT_SEARCH_EXTRA
7829 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7830 else if ((int *)varp == &p_hls)
7831 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007832 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007833 }
7834#endif
7835
7836#ifdef FEAT_SCROLLBIND
7837 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7838 * at the end of normal_cmd() */
7839 else if ((int *)varp == &curwin->w_p_scb)
7840 {
7841 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007842 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007843 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007844 curwin->w_scbind_pos = curwin->w_topline;
7845 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007846 }
7847#endif
7848
7849#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7850 /* There can be only one window with 'previewwindow' set. */
7851 else if ((int *)varp == &curwin->w_p_pvw)
7852 {
7853 if (curwin->w_p_pvw)
7854 {
7855 win_T *win;
7856
7857 for (win = firstwin; win != NULL; win = win->w_next)
7858 if (win->w_p_pvw && win != curwin)
7859 {
7860 curwin->w_p_pvw = FALSE;
7861 return (char_u *)N_("E590: A preview window already exists");
7862 }
7863 }
7864 }
7865#endif
7866
7867 /* when 'textmode' is set or reset also change 'fileformat' */
7868 else if ((int *)varp == &curbuf->b_p_tx)
7869 {
7870 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7871 }
7872
7873 /* when 'textauto' is set or reset also change 'fileformats' */
7874 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007875 set_string_option_direct((char_u *)"ffs", -1,
7876 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007877 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007878
7879 /*
7880 * When 'lisp' option changes include/exclude '-' in
7881 * keyword characters.
7882 */
7883#ifdef FEAT_LISP
7884 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7885 {
7886 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7887 }
7888#endif
7889
7890#ifdef FEAT_TITLE
7891 /* when 'title' changed, may need to change the title; same for 'icon' */
7892 else if ((int *)varp == &p_title)
7893 {
7894 did_set_title(FALSE);
7895 }
7896
7897 else if ((int *)varp == &p_icon)
7898 {
7899 did_set_title(TRUE);
7900 }
7901#endif
7902
7903 else if ((int *)varp == &curbuf->b_changed)
7904 {
7905 if (!value)
7906 save_file_ff(curbuf); /* Buffer is unchanged */
7907#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007908 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909#endif
7910#ifdef FEAT_AUTOCMD
7911 modified_was_set = value;
7912#endif
7913 }
7914
7915#ifdef BACKSLASH_IN_FILENAME
7916 else if ((int *)varp == &p_ssl)
7917 {
7918 if (p_ssl)
7919 {
7920 psepc = '/';
7921 psepcN = '\\';
7922 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007923 }
7924 else
7925 {
7926 psepc = '\\';
7927 psepcN = '/';
7928 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007929 }
7930
7931 /* need to adjust the file name arguments and buffer names. */
7932 buflist_slash_adjust();
7933 alist_slash_adjust();
7934# ifdef FEAT_EVAL
7935 scriptnames_slash_adjust();
7936# endif
7937 }
7938#endif
7939
7940 /* If 'wrap' is set, set w_leftcol to zero. */
7941 else if ((int *)varp == &curwin->w_p_wrap)
7942 {
7943 if (curwin->w_p_wrap)
7944 curwin->w_leftcol = 0;
7945 }
7946
7947#ifdef FEAT_WINDOWS
7948 else if ((int *)varp == &p_ea)
7949 {
7950 if (p_ea && !old_value)
7951 win_equal(curwin, FALSE, 0);
7952 }
7953#endif
7954
7955 else if ((int *)varp == &p_wiv)
7956 {
7957 /*
7958 * When 'weirdinvert' changed, set/reset 't_xs'.
7959 * Then set 'weirdinvert' according to value of 't_xs'.
7960 */
7961 if (p_wiv && !old_value)
7962 T_XS = (char_u *)"y";
7963 else if (!p_wiv && old_value)
7964 T_XS = empty_option;
7965 p_wiv = (*T_XS != NUL);
7966 }
7967
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007968#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007969 else if ((int *)varp == &p_beval)
7970 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007971 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007973 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007974 gui_mch_disable_beval_area(balloonEval);
7975 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007976#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007977
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007978#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007979 else if ((int *)varp == &p_acd)
7980 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007981 /* Change directories when the 'acd' option is set now. */
7982 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 }
7984#endif
7985
7986#ifdef FEAT_DIFF
7987 /* 'diff' */
7988 else if ((int *)varp == &curwin->w_p_diff)
7989 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007990 /* May add or remove the buffer from the list of diff buffers. */
7991 diff_buf_adjust(curwin);
7992# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00007993 if (foldmethodIsDiff(curwin))
7994 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00007995# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996 }
7997#endif
7998
7999#ifdef USE_IM_CONTROL
8000 /* 'imdisable' */
8001 else if ((int *)varp == &p_imdisable)
8002 {
8003 /* Only de-activate it here, it will be enabled when changing mode. */
8004 if (p_imdisable)
8005 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008006 else if (State & INSERT)
8007 /* When the option is set from an autocommand, it may need to take
8008 * effect right away. */
8009 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 }
8011#endif
8012
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008013#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008014 /* 'spell' */
8015 else if ((int *)varp == &curwin->w_p_spell)
8016 {
8017 if (curwin->w_p_spell)
8018 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008019 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008020 if (errmsg != NULL)
8021 EMSG(_(errmsg));
8022 }
8023 }
8024#endif
8025
Bram Moolenaar071d4272004-06-13 20:20:40 +00008026#ifdef FEAT_FKMAP
8027 else if ((int *)varp == &p_altkeymap)
8028 {
8029 if (old_value != p_altkeymap)
8030 {
8031 if (!p_altkeymap)
8032 {
8033 p_hkmap = p_fkmap;
8034 p_fkmap = 0;
8035 }
8036 else
8037 {
8038 p_fkmap = p_hkmap;
8039 p_hkmap = 0;
8040 }
8041 (void)init_chartab();
8042 }
8043 }
8044
8045 /*
8046 * In case some second language keymapping options have changed, check
8047 * and correct the setting in a consistent way.
8048 */
8049
8050 /*
8051 * If hkmap or fkmap are set, reset Arabic keymapping.
8052 */
8053 if ((p_hkmap || p_fkmap) && p_altkeymap)
8054 {
8055 p_altkeymap = p_fkmap;
8056# ifdef FEAT_ARABIC
8057 curwin->w_p_arab = FALSE;
8058# endif
8059 (void)init_chartab();
8060 }
8061
8062 /*
8063 * If hkmap set, reset Farsi keymapping.
8064 */
8065 if (p_hkmap && p_altkeymap)
8066 {
8067 p_altkeymap = 0;
8068 p_fkmap = 0;
8069# ifdef FEAT_ARABIC
8070 curwin->w_p_arab = FALSE;
8071# endif
8072 (void)init_chartab();
8073 }
8074
8075 /*
8076 * If fkmap set, reset Hebrew keymapping.
8077 */
8078 if (p_fkmap && !p_altkeymap)
8079 {
8080 p_altkeymap = 1;
8081 p_hkmap = 0;
8082# ifdef FEAT_ARABIC
8083 curwin->w_p_arab = FALSE;
8084# endif
8085 (void)init_chartab();
8086 }
8087#endif
8088
8089#ifdef FEAT_ARABIC
8090 if ((int *)varp == &curwin->w_p_arab)
8091 {
8092 if (curwin->w_p_arab)
8093 {
8094 /*
8095 * 'arabic' is set, handle various sub-settings.
8096 */
8097 if (!p_tbidi)
8098 {
8099 /* set rightleft mode */
8100 if (!curwin->w_p_rl)
8101 {
8102 curwin->w_p_rl = TRUE;
8103 changed_window_setting();
8104 }
8105
8106 /* Enable Arabic shaping (major part of what Arabic requires) */
8107 if (!p_arshape)
8108 {
8109 p_arshape = TRUE;
8110 redraw_later_clear();
8111 }
8112 }
8113
8114 /* Arabic requires a utf-8 encoding, inform the user if its not
8115 * set. */
8116 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008117 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008118 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8119
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008120 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008121 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8122#ifdef FEAT_EVAL
8123 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8124#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126
8127# ifdef FEAT_MBYTE
8128 /* set 'delcombine' */
8129 p_deco = TRUE;
8130# endif
8131
8132# ifdef FEAT_KEYMAP
8133 /* Force-set the necessary keymap for arabic */
8134 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8135 OPT_LOCAL);
8136# endif
8137# ifdef FEAT_FKMAP
8138 p_altkeymap = 0;
8139 p_hkmap = 0;
8140 p_fkmap = 0;
8141 (void)init_chartab();
8142# endif
8143 }
8144 else
8145 {
8146 /*
8147 * 'arabic' is reset, handle various sub-settings.
8148 */
8149 if (!p_tbidi)
8150 {
8151 /* reset rightleft mode */
8152 if (curwin->w_p_rl)
8153 {
8154 curwin->w_p_rl = FALSE;
8155 changed_window_setting();
8156 }
8157
8158 /* 'arabicshape' isn't reset, it is a global option and
8159 * another window may still need it "on". */
8160 }
8161
8162 /* 'delcombine' isn't reset, it is a global option and another
8163 * window may still want it "on". */
8164
8165# ifdef FEAT_KEYMAP
8166 /* Revert to the default keymap */
8167 curbuf->b_p_iminsert = B_IMODE_NONE;
8168 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8169# endif
8170 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008171 }
8172
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008173#endif
8174
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175 /*
8176 * End of handling side effects for bool options.
8177 */
8178
8179 options[opt_idx].flags |= P_WAS_SET;
8180
8181 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008182 if (curwin->w_curswant != MAXCOL
8183 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8184 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008185 check_redraw(options[opt_idx].flags);
8186
8187 return NULL;
8188}
8189
8190/*
8191 * Set the value of a number option, and take care of side effects.
8192 * Returns NULL for success, or an error message for an error.
8193 */
8194 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008195set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196 int opt_idx; /* index in options[] table */
8197 char_u *varp; /* pointer to the option variable */
8198 long value; /* new value */
8199 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008200 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008201 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8202 OPT_MODELINE */
8203{
8204 char_u *errmsg = NULL;
8205 long old_value = *(long *)varp;
8206 long old_Rows = Rows; /* remember old Rows */
8207 long old_Columns = Columns; /* remember old Columns */
8208 long *pp = (long *)varp;
8209
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008210 /* Disallow changing some options from secure mode. */
8211 if ((secure
8212#ifdef HAVE_SANDBOX
8213 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008214#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008215 ) && (options[opt_idx].flags & P_SECURE))
8216 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008217
8218 *pp = value;
8219#ifdef FEAT_EVAL
8220 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008221 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008223#ifdef FEAT_GUI
8224 need_mouse_correct = TRUE;
8225#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008226
Bram Moolenaar14f24742012-08-08 18:01:05 +02008227 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008228 {
8229 errmsg = e_positive;
8230 curbuf->b_p_sw = curbuf->b_p_ts;
8231 }
8232
8233 /*
8234 * Number options that need some action when changed
8235 */
8236#ifdef FEAT_WINDOWS
8237 if (pp == &p_wh || pp == &p_hh)
8238 {
8239 if (p_wh < 1)
8240 {
8241 errmsg = e_positive;
8242 p_wh = 1;
8243 }
8244 if (p_wmh > p_wh)
8245 {
8246 errmsg = e_winheight;
8247 p_wh = p_wmh;
8248 }
8249 if (p_hh < 0)
8250 {
8251 errmsg = e_positive;
8252 p_hh = 0;
8253 }
8254
8255 /* Change window height NOW */
8256 if (lastwin != firstwin)
8257 {
8258 if (pp == &p_wh && curwin->w_height < p_wh)
8259 win_setheight((int)p_wh);
8260 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8261 win_setheight((int)p_hh);
8262 }
8263 }
8264
8265 /* 'winminheight' */
8266 else if (pp == &p_wmh)
8267 {
8268 if (p_wmh < 0)
8269 {
8270 errmsg = e_positive;
8271 p_wmh = 0;
8272 }
8273 if (p_wmh > p_wh)
8274 {
8275 errmsg = e_winheight;
8276 p_wmh = p_wh;
8277 }
8278 win_setminheight();
8279 }
8280
8281# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008282 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008283 {
8284 if (p_wiw < 1)
8285 {
8286 errmsg = e_positive;
8287 p_wiw = 1;
8288 }
8289 if (p_wmw > p_wiw)
8290 {
8291 errmsg = e_winwidth;
8292 p_wiw = p_wmw;
8293 }
8294
8295 /* Change window width NOW */
8296 if (lastwin != firstwin && curwin->w_width < p_wiw)
8297 win_setwidth((int)p_wiw);
8298 }
8299
8300 /* 'winminwidth' */
8301 else if (pp == &p_wmw)
8302 {
8303 if (p_wmw < 0)
8304 {
8305 errmsg = e_positive;
8306 p_wmw = 0;
8307 }
8308 if (p_wmw > p_wiw)
8309 {
8310 errmsg = e_winwidth;
8311 p_wmw = p_wiw;
8312 }
8313 win_setminheight();
8314 }
8315# endif
8316
8317#endif
8318
8319#ifdef FEAT_WINDOWS
8320 /* (re)set last window status line */
8321 else if (pp == &p_ls)
8322 {
8323 last_status(FALSE);
8324 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008325
8326 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008327 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008328 {
8329 shell_new_rows(); /* recompute window positions and heights */
8330 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008331#endif
8332
8333#ifdef FEAT_GUI
8334 else if (pp == &p_linespace)
8335 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008336 /* Recompute gui.char_height and resize the Vim window to keep the
8337 * same number of lines. */
8338 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008339 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008340 }
8341#endif
8342
8343#ifdef FEAT_FOLDING
8344 /* 'foldlevel' */
8345 else if (pp == &curwin->w_p_fdl)
8346 {
8347 if (curwin->w_p_fdl < 0)
8348 curwin->w_p_fdl = 0;
8349 newFoldLevel();
8350 }
8351
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008352 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353 else if (pp == &curwin->w_p_fml)
8354 {
8355 foldUpdateAll(curwin);
8356 }
8357
8358 /* 'foldnestmax' */
8359 else if (pp == &curwin->w_p_fdn)
8360 {
8361 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8362 foldUpdateAll(curwin);
8363 }
8364
8365 /* 'foldcolumn' */
8366 else if (pp == &curwin->w_p_fdc)
8367 {
8368 if (curwin->w_p_fdc < 0)
8369 {
8370 errmsg = e_positive;
8371 curwin->w_p_fdc = 0;
8372 }
8373 else if (curwin->w_p_fdc > 12)
8374 {
8375 errmsg = e_invarg;
8376 curwin->w_p_fdc = 12;
8377 }
8378 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008379#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008381#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008382 /* 'shiftwidth' or 'tabstop' */
8383 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8384 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008385# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386 if (foldmethodIsIndent(curwin))
8387 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008388# endif
8389# ifdef FEAT_CINDENT
8390 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8391 * parse 'cinoptions'. */
8392 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8393 parse_cino(curbuf);
8394# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008395 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008397
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008398#ifdef FEAT_MBYTE
8399 /* 'maxcombine' */
8400 else if (pp == &p_mco)
8401 {
8402 if (p_mco > MAX_MCO)
8403 p_mco = MAX_MCO;
8404 else if (p_mco < 0)
8405 p_mco = 0;
8406 screenclear(); /* will re-allocate the screen */
8407 }
8408#endif
8409
Bram Moolenaar071d4272004-06-13 20:20:40 +00008410 else if (pp == &curbuf->b_p_iminsert)
8411 {
8412 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8413 {
8414 errmsg = e_invarg;
8415 curbuf->b_p_iminsert = B_IMODE_NONE;
8416 }
8417 p_iminsert = curbuf->b_p_iminsert;
8418 if (termcap_active) /* don't do this in the alternate screen */
8419 showmode();
8420#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8421 /* Show/unshow value of 'keymap' in status lines. */
8422 status_redraw_curbuf();
8423#endif
8424 }
8425
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008426 else if (pp == &p_window)
8427 {
8428 if (p_window < 1)
8429 p_window = 1;
8430 else if (p_window >= Rows)
8431 p_window = Rows - 1;
8432 }
8433
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 else if (pp == &curbuf->b_p_imsearch)
8435 {
8436 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8437 {
8438 errmsg = e_invarg;
8439 curbuf->b_p_imsearch = B_IMODE_NONE;
8440 }
8441 p_imsearch = curbuf->b_p_imsearch;
8442 }
8443
8444#ifdef FEAT_TITLE
8445 /* if 'titlelen' has changed, redraw the title */
8446 else if (pp == &p_titlelen)
8447 {
8448 if (p_titlelen < 0)
8449 {
8450 errmsg = e_positive;
8451 p_titlelen = 85;
8452 }
8453 if (starting != NO_SCREEN && old_value != p_titlelen)
8454 need_maketitle = TRUE;
8455 }
8456#endif
8457
8458 /* if p_ch changed value, change the command line height */
8459 else if (pp == &p_ch)
8460 {
8461 if (p_ch < 1)
8462 {
8463 errmsg = e_positive;
8464 p_ch = 1;
8465 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008466 if (p_ch > Rows - min_rows() + 1)
8467 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008468
8469 /* Only compute the new window layout when startup has been
8470 * completed. Otherwise the frame sizes may be wrong. */
8471 if (p_ch != old_value && full_screen
8472#ifdef FEAT_GUI
8473 && !gui.starting
8474#endif
8475 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008476 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477 }
8478
8479 /* when 'updatecount' changes from zero to non-zero, open swap files */
8480 else if (pp == &p_uc)
8481 {
8482 if (p_uc < 0)
8483 {
8484 errmsg = e_positive;
8485 p_uc = 100;
8486 }
8487 if (p_uc && !old_value)
8488 ml_open_files();
8489 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008490#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008491 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008492 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008493 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008494 {
8495 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008496 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008497 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008498 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008499 {
8500 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008501 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008502 }
8503 }
8504#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008505#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008506 else if (pp == &p_mzq)
8507 mzvim_reset_timer();
8508#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008509
8510 /* sync undo before 'undolevels' changes */
8511 else if (pp == &p_ul)
8512 {
8513 /* use the old value, otherwise u_sync() may not work properly */
8514 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008515 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008516 p_ul = value;
8517 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008518 else if (pp == &curbuf->b_p_ul)
8519 {
8520 /* use the old value, otherwise u_sync() may not work properly */
8521 curbuf->b_p_ul = old_value;
8522 u_sync(TRUE);
8523 curbuf->b_p_ul = value;
8524 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008525
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008526#ifdef FEAT_LINEBREAK
8527 /* 'numberwidth' must be positive */
8528 else if (pp == &curwin->w_p_nuw)
8529 {
8530 if (curwin->w_p_nuw < 1)
8531 {
8532 errmsg = e_positive;
8533 curwin->w_p_nuw = 1;
8534 }
8535 if (curwin->w_p_nuw > 10)
8536 {
8537 errmsg = e_invarg;
8538 curwin->w_p_nuw = 10;
8539 }
8540 curwin->w_nrwidth_line_count = 0;
8541 }
8542#endif
8543
Bram Moolenaar1a384422010-07-14 19:53:30 +02008544 else if (pp == &curbuf->b_p_tw)
8545 {
8546 if (curbuf->b_p_tw < 0)
8547 {
8548 errmsg = e_positive;
8549 curbuf->b_p_tw = 0;
8550 }
8551#ifdef FEAT_SYN_HL
8552# ifdef FEAT_WINDOWS
8553 {
8554 win_T *wp;
8555 tabpage_T *tp;
8556
8557 FOR_ALL_TAB_WINDOWS(tp, wp)
8558 check_colorcolumn(wp);
8559 }
8560# else
8561 check_colorcolumn(curwin);
8562# endif
8563#endif
8564 }
8565
Bram Moolenaar071d4272004-06-13 20:20:40 +00008566 /*
8567 * Check the bounds for numeric options here
8568 */
8569 if (Rows < min_rows() && full_screen)
8570 {
8571 if (errbuf != NULL)
8572 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008573 vim_snprintf((char *)errbuf, errbuflen,
8574 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008575 errmsg = errbuf;
8576 }
8577 Rows = min_rows();
8578 }
8579 if (Columns < MIN_COLUMNS && full_screen)
8580 {
8581 if (errbuf != NULL)
8582 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008583 vim_snprintf((char *)errbuf, errbuflen,
8584 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008585 errmsg = errbuf;
8586 }
8587 Columns = MIN_COLUMNS;
8588 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008589 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590
8591#ifdef DJGPP
8592 /* avoid a crash by checking for a too large value of 'columns' */
8593 if (old_Columns != Columns && full_screen && term_console)
8594 mch_check_columns();
8595#endif
8596
8597 /*
8598 * If the screen (shell) height has been changed, assume it is the
8599 * physical screenheight.
8600 */
8601 if (old_Rows != Rows || old_Columns != Columns)
8602 {
8603 /* Changing the screen size is not allowed while updating the screen. */
8604 if (updating_screen)
8605 *pp = old_value;
8606 else if (full_screen
8607#ifdef FEAT_GUI
8608 && !gui.starting
8609#endif
8610 )
8611 set_shellsize((int)Columns, (int)Rows, TRUE);
8612 else
8613 {
8614 /* Postpone the resizing; check the size and cmdline position for
8615 * messages. */
8616 check_shellsize();
8617 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8618 cmdline_row = Rows - p_ch;
8619 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008620 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008621 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622 }
8623
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624 if (curbuf->b_p_ts <= 0)
8625 {
8626 errmsg = e_positive;
8627 curbuf->b_p_ts = 8;
8628 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008629 if (p_tm < 0)
8630 {
8631 errmsg = e_positive;
8632 p_tm = 0;
8633 }
8634 if ((curwin->w_p_scr <= 0
8635 || (curwin->w_p_scr > curwin->w_height
8636 && curwin->w_height > 0))
8637 && full_screen)
8638 {
8639 if (pp == &(curwin->w_p_scr))
8640 {
8641 if (curwin->w_p_scr != 0)
8642 errmsg = e_scroll;
8643 win_comp_scroll(curwin);
8644 }
8645 /* If 'scroll' became invalid because of a side effect silently adjust
8646 * it. */
8647 else if (curwin->w_p_scr <= 0)
8648 curwin->w_p_scr = 1;
8649 else /* curwin->w_p_scr > curwin->w_height */
8650 curwin->w_p_scr = curwin->w_height;
8651 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008652 if (p_hi < 0)
8653 {
8654 errmsg = e_positive;
8655 p_hi = 0;
8656 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008657 else if (p_hi > 10000)
8658 {
8659 errmsg = e_invarg;
8660 p_hi = 10000;
8661 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008662 if (p_re < 0 || p_re > 2)
8663 {
8664 errmsg = e_invarg;
8665 p_re = 0;
8666 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008667 if (p_report < 0)
8668 {
8669 errmsg = e_positive;
8670 p_report = 1;
8671 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008672 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673 {
8674 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8675 p_sj = Rows / 2;
8676 else
8677 {
8678 errmsg = e_scroll;
8679 p_sj = 1;
8680 }
8681 }
8682 if (p_so < 0 && full_screen)
8683 {
8684 errmsg = e_scroll;
8685 p_so = 0;
8686 }
8687 if (p_siso < 0 && full_screen)
8688 {
8689 errmsg = e_positive;
8690 p_siso = 0;
8691 }
8692#ifdef FEAT_CMDWIN
8693 if (p_cwh < 1)
8694 {
8695 errmsg = e_positive;
8696 p_cwh = 1;
8697 }
8698#endif
8699 if (p_ut < 0)
8700 {
8701 errmsg = e_positive;
8702 p_ut = 2000;
8703 }
8704 if (p_ss < 0)
8705 {
8706 errmsg = e_positive;
8707 p_ss = 0;
8708 }
8709
8710 /* May set global value for local option. */
8711 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8712 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8713
8714 options[opt_idx].flags |= P_WAS_SET;
8715
8716 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008717 if (curwin->w_curswant != MAXCOL
8718 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8719 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720 check_redraw(options[opt_idx].flags);
8721
8722 return errmsg;
8723}
8724
8725/*
8726 * Called after an option changed: check if something needs to be redrawn.
8727 */
8728 static void
8729check_redraw(flags)
8730 long_u flags;
8731{
8732 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008733 int doclear = (flags & P_RCLR) == P_RCLR;
8734 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008735
8736#ifdef FEAT_WINDOWS
8737 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8738 status_redraw_all();
8739#endif
8740
8741 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8742 changed_window_setting();
8743 if (flags & P_RBUF)
8744 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008745 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008746 redraw_all_later(CLEAR);
8747 else if (all)
8748 redraw_all_later(NOT_VALID);
8749}
8750
8751/*
8752 * Find index for option 'arg'.
8753 * Return -1 if not found.
8754 */
8755 static int
8756findoption(arg)
8757 char_u *arg;
8758{
8759 int opt_idx;
8760 char *s, *p;
8761 static short quick_tab[27] = {0, 0}; /* quick access table */
8762 int is_term_opt;
8763
8764 /*
8765 * For first call: Initialize the quick-access table.
8766 * It contains the index for the first option that starts with a certain
8767 * letter. There are 26 letters, plus the first "t_" option.
8768 */
8769 if (quick_tab[1] == 0)
8770 {
8771 p = options[0].fullname;
8772 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8773 {
8774 if (s[0] != p[0])
8775 {
8776 if (s[0] == 't' && s[1] == '_')
8777 quick_tab[26] = opt_idx;
8778 else
8779 quick_tab[CharOrdLow(s[0])] = opt_idx;
8780 }
8781 p = s;
8782 }
8783 }
8784
8785 /*
8786 * Check for name starting with an illegal character.
8787 */
8788#ifdef EBCDIC
8789 if (!islower(arg[0]))
8790#else
8791 if (arg[0] < 'a' || arg[0] > 'z')
8792#endif
8793 return -1;
8794
8795 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8796 if (is_term_opt)
8797 opt_idx = quick_tab[26];
8798 else
8799 opt_idx = quick_tab[CharOrdLow(arg[0])];
8800 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8801 {
8802 if (STRCMP(arg, s) == 0) /* match full name */
8803 break;
8804 }
8805 if (s == NULL && !is_term_opt)
8806 {
8807 opt_idx = quick_tab[CharOrdLow(arg[0])];
8808 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8809 {
8810 s = options[opt_idx].shortname;
8811 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8812 break;
8813 s = NULL;
8814 }
8815 }
8816 if (s == NULL)
8817 opt_idx = -1;
8818 return opt_idx;
8819}
8820
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008821#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008822/*
8823 * Get the value for an option.
8824 *
8825 * Returns:
8826 * Number or Toggle option: 1, *numval gets value.
8827 * String option: 0, *stringval gets allocated string.
8828 * Hidden Number or Toggle option: -1.
8829 * hidden String option: -2.
8830 * unknown option: -3.
8831 */
8832 int
8833get_option_value(name, numval, stringval, opt_flags)
8834 char_u *name;
8835 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008836 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837 int opt_flags;
8838{
8839 int opt_idx;
8840 char_u *varp;
8841
8842 opt_idx = findoption(name);
8843 if (opt_idx < 0) /* unknown option */
8844 return -3;
8845
8846 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8847
8848 if (options[opt_idx].flags & P_STRING)
8849 {
8850 if (varp == NULL) /* hidden option */
8851 return -2;
8852 if (stringval != NULL)
8853 {
8854#ifdef FEAT_CRYPT
8855 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008856 if ((char_u **)varp == &curbuf->b_p_key
8857 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858 *stringval = vim_strsave((char_u *)"*****");
8859 else
8860#endif
8861 *stringval = vim_strsave(*(char_u **)(varp));
8862 }
8863 return 0;
8864 }
8865
8866 if (varp == NULL) /* hidden option */
8867 return -1;
8868 if (options[opt_idx].flags & P_NUM)
8869 *numval = *(long *)varp;
8870 else
8871 {
8872 /* Special case: 'modified' is b_changed, but we also want to consider
8873 * it set when 'ff' or 'fenc' changed. */
8874 if ((int *)varp == &curbuf->b_changed)
8875 *numval = curbufIsChanged();
8876 else
8877 *numval = *(int *)varp;
8878 }
8879 return 1;
8880}
8881#endif
8882
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008883#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008884/*
8885 * Returns the option attributes and its value. Unlike the above function it
8886 * will return either global value or local value of the option depending on
8887 * what was requested, but it will never return global value if it was
8888 * requested to return local one and vice versa. Neither it will return
8889 * buffer-local value if it was requested to return window-local one.
8890 *
8891 * Pretends that option is absent if it is not present in the requested scope
8892 * (i.e. has no global, window-local or buffer-local value depending on
8893 * opt_type). Uses
8894 *
8895 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008896 * 0 hidden or unknown option, also option that does not have requested
8897 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008898 * see SOPT_* in vim.h for other flags
8899 *
8900 * Possible opt_type values: see SREQ_* in vim.h
8901 */
8902 int
8903get_option_value_strict(name, numval, stringval, opt_type, from)
8904 char_u *name;
8905 long *numval;
8906 char_u **stringval; /* NULL when only obtaining attributes */
8907 int opt_type;
8908 void *from;
8909{
8910 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008911 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008912 struct vimoption *p;
8913 int r = 0;
8914
8915 opt_idx = findoption(name);
8916 if (opt_idx < 0)
8917 return 0;
8918
8919 p = &(options[opt_idx]);
8920
8921 /* Hidden option */
8922 if (p->var == NULL)
8923 return 0;
8924
8925 if (p->flags & P_BOOL)
8926 r |= SOPT_BOOL;
8927 else if (p->flags & P_NUM)
8928 r |= SOPT_NUM;
8929 else if (p->flags & P_STRING)
8930 r |= SOPT_STRING;
8931
8932 if (p->indir == PV_NONE)
8933 {
8934 if (opt_type == SREQ_GLOBAL)
8935 r |= SOPT_GLOBAL;
8936 else
8937 return 0; /* Did not request global-only option */
8938 }
8939 else
8940 {
8941 if (p->indir & PV_BOTH)
8942 r |= SOPT_GLOBAL;
8943 else if (opt_type == SREQ_GLOBAL)
8944 return 0; /* Requested global option */
8945
8946 if (p->indir & PV_WIN)
8947 {
8948 if (opt_type == SREQ_BUF)
8949 return 0; /* Did not request window-local option */
8950 else
8951 r |= SOPT_WIN;
8952 }
8953 else if (p->indir & PV_BUF)
8954 {
8955 if (opt_type == SREQ_WIN)
8956 return 0; /* Did not request buffer-local option */
8957 else
8958 r |= SOPT_BUF;
8959 }
8960 }
8961
8962 if (stringval == NULL)
8963 return r;
8964
8965 if (opt_type == SREQ_GLOBAL)
8966 varp = p->var;
8967 else
8968 {
8969 if (opt_type == SREQ_BUF)
8970 {
8971 /* Special case: 'modified' is b_changed, but we also want to
8972 * consider it set when 'ff' or 'fenc' changed. */
8973 if (p->indir == PV_MOD)
8974 {
8975 *numval = bufIsChanged((buf_T *) from);
8976 varp = NULL;
8977 }
8978#ifdef FEAT_CRYPT
8979 else if (p->indir == PV_KEY)
8980 {
8981 /* never return the value of the crypt key */
8982 *stringval = NULL;
8983 varp = NULL;
8984 }
8985#endif
8986 else
8987 {
8988 aco_save_T aco;
8989 aucmd_prepbuf(&aco, (buf_T *) from);
8990 varp = get_varp(p);
8991 aucmd_restbuf(&aco);
8992 }
8993 }
8994 else if (opt_type == SREQ_WIN)
8995 {
8996 win_T *save_curwin;
8997 save_curwin = curwin;
8998 curwin = (win_T *) from;
8999 curbuf = curwin->w_buffer;
9000 varp = get_varp(p);
9001 curwin = save_curwin;
9002 curbuf = curwin->w_buffer;
9003 }
9004 if (varp == p->var)
9005 return (r | SOPT_UNSET);
9006 }
9007
9008 if (varp != NULL)
9009 {
9010 if (p->flags & P_STRING)
9011 *stringval = vim_strsave(*(char_u **)(varp));
9012 else if (p->flags & P_NUM)
9013 *numval = *(long *) varp;
9014 else
9015 *numval = *(int *)varp;
9016 }
9017
9018 return r;
9019}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009020
9021/*
9022 * Iterate over options. First argument is a pointer to a pointer to a structure
9023 * inside options[] array, second is option type like in the above function.
9024 *
9025 * If first argument points to NULL it is assumed that iteration just started
9026 * and caller needs the very first value.
9027 * If first argument points to the end marker function returns NULL and sets
9028 * first argument to NULL.
9029 *
9030 * Returns full option name for current option on each call.
9031 */
9032 char_u *
9033option_iter_next(option, opt_type)
9034 void **option;
9035 int opt_type;
9036{
9037 struct vimoption *ret = NULL;
9038 do
9039 {
9040 if (*option == NULL)
9041 *option = (void *) options;
9042 else if (((struct vimoption *) (*option))->fullname == NULL)
9043 {
9044 *option = NULL;
9045 return NULL;
9046 }
9047 else
9048 *option = (void *) (((struct vimoption *) (*option)) + 1);
9049
9050 ret = ((struct vimoption *) (*option));
9051
9052 /* Hidden option */
9053 if (ret->var == NULL)
9054 {
9055 ret = NULL;
9056 continue;
9057 }
9058
9059 switch (opt_type)
9060 {
9061 case SREQ_GLOBAL:
9062 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9063 ret = NULL;
9064 break;
9065 case SREQ_BUF:
9066 if (!(ret->indir & PV_BUF))
9067 ret = NULL;
9068 break;
9069 case SREQ_WIN:
9070 if (!(ret->indir & PV_WIN))
9071 ret = NULL;
9072 break;
9073 default:
9074 EMSG2(_(e_intern2), "option_iter_next()");
9075 return NULL;
9076 }
9077 }
9078 while (ret == NULL);
9079
9080 return (char_u *)ret->fullname;
9081}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009082#endif
9083
Bram Moolenaar071d4272004-06-13 20:20:40 +00009084/*
9085 * Set the value of option "name".
9086 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009087 *
9088 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009089 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009090 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009091set_option_value(name, number, string, opt_flags)
9092 char_u *name;
9093 long number;
9094 char_u *string;
9095 int opt_flags; /* OPT_LOCAL or 0 (both) */
9096{
9097 int opt_idx;
9098 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009099 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009100
9101 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009102 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103 EMSG2(_("E355: Unknown option: %s"), name);
9104 else
9105 {
9106 flags = options[opt_idx].flags;
9107#ifdef HAVE_SANDBOX
9108 /* Disallow changing some options in the sandbox */
9109 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009110 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009112 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009113 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009114#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009115 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009116 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117 else
9118 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009119 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009120 if (varp != NULL) /* hidden option is not changed */
9121 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009122 if (number == 0 && string != NULL)
9123 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009124 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009125
9126 /* Either we are given a string or we are setting option
9127 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009128 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009129 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009130 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009131 {
9132 /* There's another character after zeros or the string
9133 * is empty. In both cases, we are trying to set a
9134 * num option using a string. */
9135 EMSG3(_("E521: Number required: &%s = '%s'"),
9136 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009137 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009138
9139 }
9140 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009141 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009142 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009143 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009144 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009145 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009146 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009147 }
9148 }
9149 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009150 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009151}
9152
9153/*
9154 * Get the terminal code for a terminal option.
9155 * Returns NULL when not found.
9156 */
9157 char_u *
9158get_term_code(tname)
9159 char_u *tname;
9160{
9161 int opt_idx;
9162 char_u *varp;
9163
9164 if (tname[0] != 't' || tname[1] != '_' ||
9165 tname[2] == NUL || tname[3] == NUL)
9166 return NULL;
9167 if ((opt_idx = findoption(tname)) >= 0)
9168 {
9169 varp = get_varp(&(options[opt_idx]));
9170 if (varp != NULL)
9171 varp = *(char_u **)(varp);
9172 return varp;
9173 }
9174 return find_termcode(tname + 2);
9175}
9176
9177 char_u *
9178get_highlight_default()
9179{
9180 int i;
9181
9182 i = findoption((char_u *)"hl");
9183 if (i >= 0)
9184 return options[i].def_val[VI_DEFAULT];
9185 return (char_u *)NULL;
9186}
9187
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009188#if defined(FEAT_MBYTE) || defined(PROTO)
9189 char_u *
9190get_encoding_default()
9191{
9192 int i;
9193
9194 i = findoption((char_u *)"enc");
9195 if (i >= 0)
9196 return options[i].def_val[VI_DEFAULT];
9197 return (char_u *)NULL;
9198}
9199#endif
9200
Bram Moolenaar071d4272004-06-13 20:20:40 +00009201/*
9202 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9203 */
9204 static int
9205find_key_option(arg)
9206 char_u *arg;
9207{
9208 int key;
9209 int modifiers;
9210
9211 /*
9212 * Don't use get_special_key_code() for t_xx, we don't want it to call
9213 * add_termcap_entry().
9214 */
9215 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9216 key = TERMCAP2KEY(arg[2], arg[3]);
9217 else
9218 {
9219 --arg; /* put arg at the '<' */
9220 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009221 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009222 if (modifiers) /* can't handle modifiers here */
9223 key = 0;
9224 }
9225 return key;
9226}
9227
9228/*
9229 * if 'all' == 0: show changed options
9230 * if 'all' == 1: show all normal options
9231 * if 'all' == 2: show all terminal options
9232 */
9233 static void
9234showoptions(all, opt_flags)
9235 int all;
9236 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9237{
9238 struct vimoption *p;
9239 int col;
9240 int isterm;
9241 char_u *varp;
9242 struct vimoption **items;
9243 int item_count;
9244 int run;
9245 int row, rows;
9246 int cols;
9247 int i;
9248 int len;
9249
9250#define INC 20
9251#define GAP 3
9252
9253 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9254 PARAM_COUNT));
9255 if (items == NULL)
9256 return;
9257
9258 /* Highlight title */
9259 if (all == 2)
9260 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9261 else if (opt_flags & OPT_GLOBAL)
9262 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9263 else if (opt_flags & OPT_LOCAL)
9264 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9265 else
9266 MSG_PUTS_TITLE(_("\n--- Options ---"));
9267
9268 /*
9269 * do the loop two times:
9270 * 1. display the short items
9271 * 2. display the long items (only strings and numbers)
9272 */
9273 for (run = 1; run <= 2 && !got_int; ++run)
9274 {
9275 /*
9276 * collect the items in items[]
9277 */
9278 item_count = 0;
9279 for (p = &options[0]; p->fullname != NULL; p++)
9280 {
9281 varp = NULL;
9282 isterm = istermoption(p);
9283 if (opt_flags != 0)
9284 {
9285 if (p->indir != PV_NONE && !isterm)
9286 varp = get_varp_scope(p, opt_flags);
9287 }
9288 else
9289 varp = get_varp(p);
9290 if (varp != NULL
9291 && ((all == 2 && isterm)
9292 || (all == 1 && !isterm)
9293 || (all == 0 && !optval_default(p, varp))))
9294 {
9295 if (p->flags & P_BOOL)
9296 len = 1; /* a toggle option fits always */
9297 else
9298 {
9299 option_value2string(p, opt_flags);
9300 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9301 }
9302 if ((len <= INC - GAP && run == 1) ||
9303 (len > INC - GAP && run == 2))
9304 items[item_count++] = p;
9305 }
9306 }
9307
9308 /*
9309 * display the items
9310 */
9311 if (run == 1)
9312 {
9313 cols = (Columns + GAP - 3) / INC;
9314 if (cols == 0)
9315 cols = 1;
9316 rows = (item_count + cols - 1) / cols;
9317 }
9318 else /* run == 2 */
9319 rows = item_count;
9320 for (row = 0; row < rows && !got_int; ++row)
9321 {
9322 msg_putchar('\n'); /* go to next line */
9323 if (got_int) /* 'q' typed in more */
9324 break;
9325 col = 0;
9326 for (i = row; i < item_count; i += rows)
9327 {
9328 msg_col = col; /* make columns */
9329 showoneopt(items[i], opt_flags);
9330 col += INC;
9331 }
9332 out_flush();
9333 ui_breakcheck();
9334 }
9335 }
9336 vim_free(items);
9337}
9338
9339/*
9340 * Return TRUE if option "p" has its default value.
9341 */
9342 static int
9343optval_default(p, varp)
9344 struct vimoption *p;
9345 char_u *varp;
9346{
9347 int dvi;
9348
9349 if (varp == NULL)
9350 return TRUE; /* hidden option is always at default */
9351 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9352 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009353 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009354 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009355 /* the cast to long is required for Manx C, long_i is
9356 * needed for MSVC */
9357 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009358 /* P_STRING */
9359 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9360}
9361
9362/*
9363 * showoneopt: show the value of one option
9364 * must not be called with a hidden option!
9365 */
9366 static void
9367showoneopt(p, opt_flags)
9368 struct vimoption *p;
9369 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9370{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009371 char_u *varp;
9372 int save_silent = silent_mode;
9373
9374 silent_mode = FALSE;
9375 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009376
9377 varp = get_varp_scope(p, opt_flags);
9378
9379 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9380 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9381 ? !curbufIsChanged() : !*(int *)varp))
9382 MSG_PUTS("no");
9383 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9384 MSG_PUTS("--");
9385 else
9386 MSG_PUTS(" ");
9387 MSG_PUTS(p->fullname);
9388 if (!(p->flags & P_BOOL))
9389 {
9390 msg_putchar('=');
9391 /* put value string in NameBuff */
9392 option_value2string(p, opt_flags);
9393 msg_outtrans(NameBuff);
9394 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009395
9396 silent_mode = save_silent;
9397 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009398}
9399
9400/*
9401 * Write modified options as ":set" commands to a file.
9402 *
9403 * There are three values for "opt_flags":
9404 * OPT_GLOBAL: Write global option values and fresh values of
9405 * buffer-local options (used for start of a session
9406 * file).
9407 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9408 * curwin (used for a vimrc file).
9409 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9410 * and local values for window-local options of
9411 * curwin. Local values are also written when at the
9412 * default value, because a modeline or autocommand
9413 * may have set them when doing ":edit file" and the
9414 * user has set them back at the default or fresh
9415 * value.
9416 * When "local_only" is TRUE, don't write fresh
9417 * values, only local values (for ":mkview").
9418 * (fresh value = value used for a new buffer or window for a local option).
9419 *
9420 * Return FAIL on error, OK otherwise.
9421 */
9422 int
9423makeset(fd, opt_flags, local_only)
9424 FILE *fd;
9425 int opt_flags;
9426 int local_only;
9427{
9428 struct vimoption *p;
9429 char_u *varp; /* currently used value */
9430 char_u *varp_fresh; /* local value */
9431 char_u *varp_local = NULL; /* fresh value */
9432 char *cmd;
9433 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009434 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009435
9436 /*
9437 * The options that don't have a default (terminal name, columns, lines)
9438 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009439 * Do the loop over "options[]" twice: once for options with the
9440 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009441 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009442 for (pri = 1; pri >= 0; --pri)
9443 {
9444 for (p = &options[0]; !istermoption(p); p++)
9445 if (!(p->flags & P_NO_MKRC)
9446 && !istermoption(p)
9447 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009448 {
9449 /* skip global option when only doing locals */
9450 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9451 continue;
9452
9453 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9454 * file, they are always buffer-specific. */
9455 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9456 continue;
9457
9458 /* Global values are only written when not at the default value. */
9459 varp = get_varp_scope(p, opt_flags);
9460 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9461 continue;
9462
9463 round = 2;
9464 if (p->indir != PV_NONE)
9465 {
9466 if (p->var == VAR_WIN)
9467 {
9468 /* skip window-local option when only doing globals */
9469 if (!(opt_flags & OPT_LOCAL))
9470 continue;
9471 /* When fresh value of window-local option is not at the
9472 * default, need to write it too. */
9473 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9474 {
9475 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9476 if (!optval_default(p, varp_fresh))
9477 {
9478 round = 1;
9479 varp_local = varp;
9480 varp = varp_fresh;
9481 }
9482 }
9483 }
9484 }
9485
9486 /* Round 1: fresh value for window-local options.
9487 * Round 2: other values */
9488 for ( ; round <= 2; varp = varp_local, ++round)
9489 {
9490 if (round == 1 || (opt_flags & OPT_GLOBAL))
9491 cmd = "set";
9492 else
9493 cmd = "setlocal";
9494
9495 if (p->flags & P_BOOL)
9496 {
9497 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9498 return FAIL;
9499 }
9500 else if (p->flags & P_NUM)
9501 {
9502 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9503 return FAIL;
9504 }
9505 else /* P_STRING */
9506 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009507#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9508 int do_endif = FALSE;
9509
Bram Moolenaar071d4272004-06-13 20:20:40 +00009510 /* Don't set 'syntax' and 'filetype' again if the value is
9511 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009512 if (
9513# if defined(FEAT_SYN_HL)
9514 p->indir == PV_SYN
9515# if defined(FEAT_AUTOCMD)
9516 ||
9517# endif
9518# endif
9519# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009520 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009521# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009522 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009523 {
9524 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9525 *(char_u **)(varp)) < 0
9526 || put_eol(fd) < 0)
9527 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009528 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009529 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009530#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009531 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9532 (p->flags & P_EXPAND) != 0) == FAIL)
9533 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009534#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9535 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009536 {
9537 if (put_line(fd, "endif") == FAIL)
9538 return FAIL;
9539 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009540#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009541 }
9542 }
9543 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009544 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009545 return OK;
9546}
9547
9548#if defined(FEAT_FOLDING) || defined(PROTO)
9549/*
9550 * Generate set commands for the local fold options only. Used when
9551 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9552 */
9553 int
9554makefoldset(fd)
9555 FILE *fd;
9556{
9557 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9558# ifdef FEAT_EVAL
9559 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9560 == FAIL
9561# endif
9562 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9563 == FAIL
9564 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9565 == FAIL
9566 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9567 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9568 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9569 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9570 )
9571 return FAIL;
9572
9573 return OK;
9574}
9575#endif
9576
9577 static int
9578put_setstring(fd, cmd, name, valuep, expand)
9579 FILE *fd;
9580 char *cmd;
9581 char *name;
9582 char_u **valuep;
9583 int expand;
9584{
9585 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009586 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009587
9588 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9589 return FAIL;
9590 if (*valuep != NULL)
9591 {
9592 /* Output 'pastetoggle' as key names. For other
9593 * options some characters have to be escaped with
9594 * CTRL-V or backslash */
9595 if (valuep == &p_pt)
9596 {
9597 s = *valuep;
9598 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009599 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009600 return FAIL;
9601 }
9602 else if (expand)
9603 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009604 buf = alloc(MAXPATHL);
9605 if (buf == NULL)
9606 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009607 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9608 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009609 {
9610 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009611 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009612 }
9613 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009614 }
9615 else if (put_escstr(fd, *valuep, 2) == FAIL)
9616 return FAIL;
9617 }
9618 if (put_eol(fd) < 0)
9619 return FAIL;
9620 return OK;
9621}
9622
9623 static int
9624put_setnum(fd, cmd, name, valuep)
9625 FILE *fd;
9626 char *cmd;
9627 char *name;
9628 long *valuep;
9629{
9630 long wc;
9631
9632 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9633 return FAIL;
9634 if (wc_use_keyname((char_u *)valuep, &wc))
9635 {
9636 /* print 'wildchar' and 'wildcharm' as a key name */
9637 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9638 return FAIL;
9639 }
9640 else if (fprintf(fd, "%ld", *valuep) < 0)
9641 return FAIL;
9642 if (put_eol(fd) < 0)
9643 return FAIL;
9644 return OK;
9645}
9646
9647 static int
9648put_setbool(fd, cmd, name, value)
9649 FILE *fd;
9650 char *cmd;
9651 char *name;
9652 int value;
9653{
Bram Moolenaar893de922007-10-02 18:40:57 +00009654 if (value < 0) /* global/local option using global value */
9655 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009656 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9657 || put_eol(fd) < 0)
9658 return FAIL;
9659 return OK;
9660}
9661
9662/*
9663 * Clear all the terminal options.
9664 * If the option has been allocated, free the memory.
9665 * Terminal options are never hidden or indirect.
9666 */
9667 void
9668clear_termoptions()
9669{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009670 /*
9671 * Reset a few things before clearing the old options. This may cause
9672 * outputting a few things that the terminal doesn't understand, but the
9673 * screen will be cleared later, so this is OK.
9674 */
9675#ifdef FEAT_MOUSE_TTY
9676 mch_setmouse(FALSE); /* switch mouse off */
9677#endif
9678#ifdef FEAT_TITLE
9679 mch_restore_title(3); /* restore window titles */
9680#endif
9681#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9682 /* When starting the GUI close the display opened for the clipboard.
9683 * After restoring the title, because that will need the display. */
9684 if (gui.starting)
9685 clear_xterm_clip();
9686#endif
9687#ifdef WIN3264
9688 /*
9689 * Check if this is allowed now.
9690 */
9691 if (can_end_termcap_mode(FALSE) == TRUE)
9692#endif
9693 stoptermcap(); /* stop termcap mode */
9694
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009695 free_termoptions();
9696}
9697
9698 void
9699free_termoptions()
9700{
9701 struct vimoption *p;
9702
Bram Moolenaar071d4272004-06-13 20:20:40 +00009703 for (p = &options[0]; p->fullname != NULL; p++)
9704 if (istermoption(p))
9705 {
9706 if (p->flags & P_ALLOCED)
9707 free_string_option(*(char_u **)(p->var));
9708 if (p->flags & P_DEF_ALLOCED)
9709 free_string_option(p->def_val[VI_DEFAULT]);
9710 *(char_u **)(p->var) = empty_option;
9711 p->def_val[VI_DEFAULT] = empty_option;
9712 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9713 }
9714 clear_termcodes();
9715}
9716
9717/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009718 * Free the string for one term option, if it was allocated.
9719 * Set the string to empty_option and clear allocated flag.
9720 * "var" points to the option value.
9721 */
9722 void
9723free_one_termoption(var)
9724 char_u *var;
9725{
9726 struct vimoption *p;
9727
9728 for (p = &options[0]; p->fullname != NULL; p++)
9729 if (p->var == var)
9730 {
9731 if (p->flags & P_ALLOCED)
9732 free_string_option(*(char_u **)(p->var));
9733 *(char_u **)(p->var) = empty_option;
9734 p->flags &= ~P_ALLOCED;
9735 break;
9736 }
9737}
9738
9739/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740 * Set the terminal option defaults to the current value.
9741 * Used after setting the terminal name.
9742 */
9743 void
9744set_term_defaults()
9745{
9746 struct vimoption *p;
9747
9748 for (p = &options[0]; p->fullname != NULL; p++)
9749 {
9750 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9751 {
9752 if (p->flags & P_DEF_ALLOCED)
9753 {
9754 free_string_option(p->def_val[VI_DEFAULT]);
9755 p->flags &= ~P_DEF_ALLOCED;
9756 }
9757 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9758 if (p->flags & P_ALLOCED)
9759 {
9760 p->flags |= P_DEF_ALLOCED;
9761 p->flags &= ~P_ALLOCED; /* don't free the value now */
9762 }
9763 }
9764 }
9765}
9766
9767/*
9768 * return TRUE if 'p' starts with 't_'
9769 */
9770 static int
9771istermoption(p)
9772 struct vimoption *p;
9773{
9774 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9775}
9776
9777/*
9778 * Compute columns for ruler and shown command. 'sc_col' is also used to
9779 * decide what the maximum length of a message on the status line can be.
9780 * If there is a status line for the last window, 'sc_col' is independent
9781 * of 'ru_col'.
9782 */
9783
9784#define COL_RULER 17 /* columns needed by standard ruler */
9785
9786 void
9787comp_col()
9788{
9789#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9790 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9791
9792 sc_col = 0;
9793 ru_col = 0;
9794 if (p_ru)
9795 {
9796#ifdef FEAT_STL_OPT
9797 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9798#else
9799 ru_col = COL_RULER + 1;
9800#endif
9801 /* no last status line, adjust sc_col */
9802 if (!last_has_status)
9803 sc_col = ru_col;
9804 }
9805 if (p_sc)
9806 {
9807 sc_col += SHOWCMD_COLS;
9808 if (!p_ru || last_has_status) /* no need for separating space */
9809 ++sc_col;
9810 }
9811 sc_col = Columns - sc_col;
9812 ru_col = Columns - ru_col;
9813 if (sc_col <= 0) /* screen too narrow, will become a mess */
9814 sc_col = 1;
9815 if (ru_col <= 0)
9816 ru_col = 1;
9817#else
9818 sc_col = Columns;
9819 ru_col = Columns;
9820#endif
9821}
9822
9823/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009824 * Unset local option value, similar to ":set opt<".
9825 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009826 void
9827unset_global_local_option(name, from)
9828 char_u *name;
9829 void *from;
9830{
9831 struct vimoption *p;
9832 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009833 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009834
9835 opt_idx = findoption(name);
9836 p = &(options[opt_idx]);
9837
9838 switch ((int)p->indir)
9839 {
9840 /* global option with local value: use local value if it's been set */
9841 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009842 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009843 break;
9844 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009845 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009846 break;
9847 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009848 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009849 break;
9850 case PV_AR:
9851 buf->b_p_ar = -1;
9852 break;
9853 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009854 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009855 break;
9856#ifdef FEAT_FIND_ID
9857 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009858 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009859 break;
9860 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009861 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009862 break;
9863#endif
9864#ifdef FEAT_INS_EXPAND
9865 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009866 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009867 break;
9868 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009869 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009870 break;
9871#endif
9872#ifdef FEAT_QUICKFIX
9873 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009874 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009875 break;
9876 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009877 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009878 break;
9879 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009880 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009881 break;
9882#endif
9883#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9884 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009885 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009886 break;
9887#endif
9888#if defined(FEAT_CRYPT)
9889 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009890 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009891 break;
9892#endif
9893#ifdef FEAT_STL_OPT
9894 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009895 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009896 break;
9897#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009898 case PV_UL:
9899 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9900 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009901#ifdef FEAT_LISP
9902 case PV_LW:
9903 clear_string_option(&buf->b_p_lw);
9904 break;
9905#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009906 }
9907}
9908
9909/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009910 * Get pointer to option variable, depending on local or global scope.
9911 */
9912 static char_u *
9913get_varp_scope(p, opt_flags)
9914 struct vimoption *p;
9915 int opt_flags;
9916{
9917 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9918 {
9919 if (p->var == VAR_WIN)
9920 return (char_u *)GLOBAL_WO(get_varp(p));
9921 return p->var;
9922 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009923 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009924 {
9925 switch ((int)p->indir)
9926 {
9927#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009928 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9929 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9930 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009931#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009932 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9933 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9934 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009935 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009936 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009937#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009938 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9939 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940#endif
9941#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009942 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9943 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009944#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009945#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9946 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9947#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009948#if defined(FEAT_CRYPT)
9949 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9950#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009951#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009952 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009953#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009954 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009955#ifdef FEAT_LISP
9956 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9957#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958 }
9959 return NULL; /* "cannot happen" */
9960 }
9961 return get_varp(p);
9962}
9963
9964/*
9965 * Get pointer to option variable.
9966 */
9967 static char_u *
9968get_varp(p)
9969 struct vimoption *p;
9970{
9971 /* hidden option, always return NULL */
9972 if (p->var == NULL)
9973 return NULL;
9974
9975 switch ((int)p->indir)
9976 {
9977 case PV_NONE: return p->var;
9978
9979 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009980 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009981 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009982 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009983 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009984 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009985 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009986 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009987 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009988 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989 ? (char_u *)&(curbuf->b_p_tags) : p->var;
9990#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009991 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009993 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009994 ? (char_u *)&(curbuf->b_p_inc) : p->var;
9995#endif
9996#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009997 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +00009998 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009999 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010000 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10001#endif
10002#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010003 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010004 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010005 case PV_GP: return *curbuf->b_p_gp != NUL
10006 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10007 case PV_MP: return *curbuf->b_p_mp != NUL
10008 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010009#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010010#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10011 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10012 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10013#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010014#if defined(FEAT_CRYPT)
10015 case PV_CM: return *curbuf->b_p_cm != NUL
10016 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10017#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010018#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010019 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010020 ? (char_u *)&(curwin->w_p_stl) : p->var;
10021#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010022 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10023 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010024#ifdef FEAT_LISP
10025 case PV_LW: return *curbuf->b_p_lw != NUL
10026 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10027#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010028
10029#ifdef FEAT_ARABIC
10030 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10031#endif
10032 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010033#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010034 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10035#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010036#ifdef FEAT_SYN_HL
10037 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10038 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010039 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010040#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010041#ifdef FEAT_DIFF
10042 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10043#endif
10044#ifdef FEAT_FOLDING
10045 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10046 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10047 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10048 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10049 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10050 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10051 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10052# ifdef FEAT_EVAL
10053 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10054 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10055# endif
10056 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10057#endif
10058 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010059 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010060#ifdef FEAT_LINEBREAK
10061 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10062#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010063#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010064 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10065#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010066#ifdef FEAT_VERTSPLIT
10067 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10068#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010069#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10070 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10071#endif
10072#ifdef FEAT_RIGHTLEFT
10073 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10074 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10075#endif
10076 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10077 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10078#ifdef FEAT_LINEBREAK
10079 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010080 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10081 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010082#endif
10083#ifdef FEAT_SCROLLBIND
10084 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10085#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010086#ifdef FEAT_CURSORBIND
10087 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10088#endif
10089#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010090 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10091 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010092#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010093
10094 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10095 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10096#ifdef FEAT_MBYTE
10097 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10098#endif
10099#if defined(FEAT_QUICKFIX)
10100 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10101 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10102#endif
10103 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10104 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10105#ifdef FEAT_CINDENT
10106 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10107 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10108 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10109#endif
10110#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10111 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10112#endif
10113#ifdef FEAT_COMMENTS
10114 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10115#endif
10116#ifdef FEAT_FOLDING
10117 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10118#endif
10119#ifdef FEAT_INS_EXPAND
10120 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10121#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010122#ifdef FEAT_COMPL_FUNC
10123 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010124 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010125#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010126 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10127 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10128#ifdef FEAT_MBYTE
10129 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10130#endif
10131 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10132#ifdef FEAT_AUTOCMD
10133 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10134#endif
10135 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010136 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010137 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10138 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10139 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10140 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10141#ifdef FEAT_FIND_ID
10142# ifdef FEAT_EVAL
10143 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10144# endif
10145#endif
10146#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10147 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10148 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10149#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010150#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010151 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10152#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153#ifdef FEAT_CRYPT
10154 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10155#endif
10156#ifdef FEAT_LISP
10157 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10158#endif
10159 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10160 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10161 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10162 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10163 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010164 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010165#ifdef FEAT_TEXTOBJ
10166 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10167#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010168 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10169#ifdef FEAT_SMARTINDENT
10170 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10171#endif
10172#ifndef SHORT_FNAME
10173 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10174#endif
10175 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10176#ifdef FEAT_SEARCHPATH
10177 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10178#endif
10179 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10180#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010181 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010182 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10183#endif
10184#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010185 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10186 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10187 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188#endif
10189 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10190 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10191 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10192 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010193#ifdef FEAT_PERSISTENT_UNDO
10194 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10195#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10197#ifdef FEAT_KEYMAP
10198 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10199#endif
10200 default: EMSG(_("E356: get_varp ERROR"));
10201 }
10202 /* always return a valid pointer to avoid a crash! */
10203 return (char_u *)&(curbuf->b_p_wm);
10204}
10205
10206/*
10207 * Get the value of 'equalprg', either the buffer-local one or the global one.
10208 */
10209 char_u *
10210get_equalprg()
10211{
10212 if (*curbuf->b_p_ep == NUL)
10213 return p_ep;
10214 return curbuf->b_p_ep;
10215}
10216
10217#if defined(FEAT_WINDOWS) || defined(PROTO)
10218/*
10219 * Copy options from one window to another.
10220 * Used when splitting a window.
10221 */
10222 void
10223win_copy_options(wp_from, wp_to)
10224 win_T *wp_from;
10225 win_T *wp_to;
10226{
10227 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10228 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10229# ifdef FEAT_RIGHTLEFT
10230# ifdef FEAT_FKMAP
10231 /* Is this right? */
10232 wp_to->w_farsi = wp_from->w_farsi;
10233# endif
10234# endif
10235}
10236#endif
10237
10238/*
10239 * Copy the options from one winopt_T to another.
10240 * Doesn't free the old option values in "to", use clear_winopt() for that.
10241 * The 'scroll' option is not copied, because it depends on the window height.
10242 * The 'previewwindow' option is reset, there can be only one preview window.
10243 */
10244 void
10245copy_winopt(from, to)
10246 winopt_T *from;
10247 winopt_T *to;
10248{
10249#ifdef FEAT_ARABIC
10250 to->wo_arab = from->wo_arab;
10251#endif
10252 to->wo_list = from->wo_list;
10253 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010254 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010255#ifdef FEAT_LINEBREAK
10256 to->wo_nuw = from->wo_nuw;
10257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010258#ifdef FEAT_RIGHTLEFT
10259 to->wo_rl = from->wo_rl;
10260 to->wo_rlc = vim_strsave(from->wo_rlc);
10261#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010262#ifdef FEAT_STL_OPT
10263 to->wo_stl = vim_strsave(from->wo_stl);
10264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010265 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010266#ifdef FEAT_DIFF
10267 to->wo_wrap_save = from->wo_wrap_save;
10268#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269#ifdef FEAT_LINEBREAK
10270 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010271 to->wo_bri = from->wo_bri;
10272 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273#endif
10274#ifdef FEAT_SCROLLBIND
10275 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010276 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010277#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010278#ifdef FEAT_CURSORBIND
10279 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010280 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010281#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010282#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010283 to->wo_spell = from->wo_spell;
10284#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010285#ifdef FEAT_SYN_HL
10286 to->wo_cuc = from->wo_cuc;
10287 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010288 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290#ifdef FEAT_DIFF
10291 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010292 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010293#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010294#ifdef FEAT_CONCEAL
10295 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010296 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010297#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010298#ifdef FEAT_FOLDING
10299 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010300 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010302 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303 to->wo_fdi = vim_strsave(from->wo_fdi);
10304 to->wo_fml = from->wo_fml;
10305 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010306 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010308 to->wo_fdm_save = from->wo_diff_saved
10309 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010310 to->wo_fdn = from->wo_fdn;
10311# ifdef FEAT_EVAL
10312 to->wo_fde = vim_strsave(from->wo_fde);
10313 to->wo_fdt = vim_strsave(from->wo_fdt);
10314# endif
10315 to->wo_fmr = vim_strsave(from->wo_fmr);
10316#endif
10317 check_winopt(to); /* don't want NULL pointers */
10318}
10319
10320/*
10321 * Check string options in a window for a NULL value.
10322 */
10323 void
10324check_win_options(win)
10325 win_T *win;
10326{
10327 check_winopt(&win->w_onebuf_opt);
10328 check_winopt(&win->w_allbuf_opt);
10329}
10330
10331/*
10332 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10333 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010334 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010335check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010336 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337{
10338#ifdef FEAT_FOLDING
10339 check_string_option(&wop->wo_fdi);
10340 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010341 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342# ifdef FEAT_EVAL
10343 check_string_option(&wop->wo_fde);
10344 check_string_option(&wop->wo_fdt);
10345# endif
10346 check_string_option(&wop->wo_fmr);
10347#endif
10348#ifdef FEAT_RIGHTLEFT
10349 check_string_option(&wop->wo_rlc);
10350#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010351#ifdef FEAT_STL_OPT
10352 check_string_option(&wop->wo_stl);
10353#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010354#ifdef FEAT_SYN_HL
10355 check_string_option(&wop->wo_cc);
10356#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010357#ifdef FEAT_CONCEAL
10358 check_string_option(&wop->wo_cocu);
10359#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010360#ifdef FEAT_LINEBREAK
10361 check_string_option(&wop->wo_briopt);
10362#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363}
10364
10365/*
10366 * Free the allocated memory inside a winopt_T.
10367 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010368 void
10369clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010370 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010371{
10372#ifdef FEAT_FOLDING
10373 clear_string_option(&wop->wo_fdi);
10374 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010375 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010376# ifdef FEAT_EVAL
10377 clear_string_option(&wop->wo_fde);
10378 clear_string_option(&wop->wo_fdt);
10379# endif
10380 clear_string_option(&wop->wo_fmr);
10381#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010382#ifdef FEAT_LINEBREAK
10383 clear_string_option(&wop->wo_briopt);
10384#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010385#ifdef FEAT_RIGHTLEFT
10386 clear_string_option(&wop->wo_rlc);
10387#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010388#ifdef FEAT_STL_OPT
10389 clear_string_option(&wop->wo_stl);
10390#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010391#ifdef FEAT_SYN_HL
10392 clear_string_option(&wop->wo_cc);
10393#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010394#ifdef FEAT_CONCEAL
10395 clear_string_option(&wop->wo_cocu);
10396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010397}
10398
10399/*
10400 * Copy global option values to local options for one buffer.
10401 * Used when creating a new buffer and sometimes when entering a buffer.
10402 * flags:
10403 * BCO_ENTER We will enter the buf buffer.
10404 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10405 * appropriate.
10406 * BCO_NOHELP Don't copy the values to a help buffer.
10407 */
10408 void
10409buf_copy_options(buf, flags)
10410 buf_T *buf;
10411 int flags;
10412{
10413 int should_copy = TRUE;
10414 char_u *save_p_isk = NULL; /* init for GCC */
10415 int dont_do_help;
10416 int did_isk = FALSE;
10417
10418 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010419 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420 */
10421 if (buf == NULL || !buf_valid(buf))
10422 return;
10423
10424 /*
10425 * Skip this when the option defaults have not been set yet. Happens when
10426 * main() allocates the first buffer.
10427 */
10428 if (p_cpo != NULL)
10429 {
10430 /*
10431 * Always copy when entering and 'cpo' contains 'S'.
10432 * Don't copy when already initialized.
10433 * Don't copy when 'cpo' contains 's' and not entering.
10434 * 'S' BCO_ENTER initialized 's' should_copy
10435 * yes yes X X TRUE
10436 * yes no yes X FALSE
10437 * no X yes X FALSE
10438 * X no no yes FALSE
10439 * X no no no TRUE
10440 * no yes no X TRUE
10441 */
10442 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10443 && (buf->b_p_initialized
10444 || (!(flags & BCO_ENTER)
10445 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10446 should_copy = FALSE;
10447
10448 if (should_copy || (flags & BCO_ALWAYS))
10449 {
10450 /* Don't copy the options specific to a help buffer when
10451 * BCO_NOHELP is given or the options were initialized already
10452 * (jumping back to a help file with CTRL-T or CTRL-O) */
10453 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10454 || buf->b_p_initialized;
10455 if (dont_do_help) /* don't free b_p_isk */
10456 {
10457 save_p_isk = buf->b_p_isk;
10458 buf->b_p_isk = NULL;
10459 }
10460 /*
10461 * Always free the allocated strings.
10462 * If not already initialized, set 'readonly' and copy 'fileformat'.
10463 */
10464 if (!buf->b_p_initialized)
10465 {
10466 free_buf_options(buf, TRUE);
10467 buf->b_p_ro = FALSE; /* don't copy readonly */
10468 buf->b_p_tx = p_tx;
10469#ifdef FEAT_MBYTE
10470 buf->b_p_fenc = vim_strsave(p_fenc);
10471#endif
10472 buf->b_p_ff = vim_strsave(p_ff);
10473#if defined(FEAT_QUICKFIX)
10474 buf->b_p_bh = empty_option;
10475 buf->b_p_bt = empty_option;
10476#endif
10477 }
10478 else
10479 free_buf_options(buf, FALSE);
10480
10481 buf->b_p_ai = p_ai;
10482 buf->b_p_ai_nopaste = p_ai_nopaste;
10483 buf->b_p_sw = p_sw;
10484 buf->b_p_tw = p_tw;
10485 buf->b_p_tw_nopaste = p_tw_nopaste;
10486 buf->b_p_tw_nobin = p_tw_nobin;
10487 buf->b_p_wm = p_wm;
10488 buf->b_p_wm_nopaste = p_wm_nopaste;
10489 buf->b_p_wm_nobin = p_wm_nobin;
10490 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010491#ifdef FEAT_MBYTE
10492 buf->b_p_bomb = p_bomb;
10493#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494 buf->b_p_et = p_et;
10495 buf->b_p_et_nobin = p_et_nobin;
10496 buf->b_p_ml = p_ml;
10497 buf->b_p_ml_nobin = p_ml_nobin;
10498 buf->b_p_inf = p_inf;
10499 buf->b_p_swf = p_swf;
10500#ifdef FEAT_INS_EXPAND
10501 buf->b_p_cpt = vim_strsave(p_cpt);
10502#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010503#ifdef FEAT_COMPL_FUNC
10504 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010505 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010506#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507 buf->b_p_sts = p_sts;
10508 buf->b_p_sts_nopaste = p_sts_nopaste;
10509#ifndef SHORT_FNAME
10510 buf->b_p_sn = p_sn;
10511#endif
10512#ifdef FEAT_COMMENTS
10513 buf->b_p_com = vim_strsave(p_com);
10514#endif
10515#ifdef FEAT_FOLDING
10516 buf->b_p_cms = vim_strsave(p_cms);
10517#endif
10518 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010519 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520 buf->b_p_nf = vim_strsave(p_nf);
10521 buf->b_p_mps = vim_strsave(p_mps);
10522#ifdef FEAT_SMARTINDENT
10523 buf->b_p_si = p_si;
10524#endif
10525 buf->b_p_ci = p_ci;
10526#ifdef FEAT_CINDENT
10527 buf->b_p_cin = p_cin;
10528 buf->b_p_cink = vim_strsave(p_cink);
10529 buf->b_p_cino = vim_strsave(p_cino);
10530#endif
10531#ifdef FEAT_AUTOCMD
10532 /* Don't copy 'filetype', it must be detected */
10533 buf->b_p_ft = empty_option;
10534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 buf->b_p_pi = p_pi;
10536#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10537 buf->b_p_cinw = vim_strsave(p_cinw);
10538#endif
10539#ifdef FEAT_LISP
10540 buf->b_p_lisp = p_lisp;
10541#endif
10542#ifdef FEAT_SYN_HL
10543 /* Don't copy 'syntax', it must be set */
10544 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010545 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010546#endif
10547#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010548 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010549 (void)compile_cap_prog(&buf->b_s);
10550 buf->b_s.b_p_spf = vim_strsave(p_spf);
10551 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552#endif
10553#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10554 buf->b_p_inde = vim_strsave(p_inde);
10555 buf->b_p_indk = vim_strsave(p_indk);
10556#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010557#if defined(FEAT_EVAL)
10558 buf->b_p_fex = vim_strsave(p_fex);
10559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560#ifdef FEAT_CRYPT
10561 buf->b_p_key = vim_strsave(p_key);
10562#endif
10563#ifdef FEAT_SEARCHPATH
10564 buf->b_p_sua = vim_strsave(p_sua);
10565#endif
10566#ifdef FEAT_KEYMAP
10567 buf->b_p_keymap = vim_strsave(p_keymap);
10568 buf->b_kmap_state |= KEYMAP_INIT;
10569#endif
10570 /* This isn't really an option, but copying the langmap and IME
10571 * state from the current buffer is better than resetting it. */
10572 buf->b_p_iminsert = p_iminsert;
10573 buf->b_p_imsearch = p_imsearch;
10574
10575 /* options that are normally global but also have a local value
10576 * are not copied, start using the global value */
10577 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010578 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579#ifdef FEAT_QUICKFIX
10580 buf->b_p_gp = empty_option;
10581 buf->b_p_mp = empty_option;
10582 buf->b_p_efm = empty_option;
10583#endif
10584 buf->b_p_ep = empty_option;
10585 buf->b_p_kp = empty_option;
10586 buf->b_p_path = empty_option;
10587 buf->b_p_tags = empty_option;
10588#ifdef FEAT_FIND_ID
10589 buf->b_p_def = empty_option;
10590 buf->b_p_inc = empty_option;
10591# ifdef FEAT_EVAL
10592 buf->b_p_inex = vim_strsave(p_inex);
10593# endif
10594#endif
10595#ifdef FEAT_INS_EXPAND
10596 buf->b_p_dict = empty_option;
10597 buf->b_p_tsr = empty_option;
10598#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010599#ifdef FEAT_TEXTOBJ
10600 buf->b_p_qe = vim_strsave(p_qe);
10601#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010602#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10603 buf->b_p_bexpr = empty_option;
10604#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010605#if defined(FEAT_CRYPT)
10606 buf->b_p_cm = empty_option;
10607#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010608#ifdef FEAT_PERSISTENT_UNDO
10609 buf->b_p_udf = p_udf;
10610#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010611#ifdef FEAT_LISP
10612 buf->b_p_lw = empty_option;
10613#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010614
10615 /*
10616 * Don't copy the options set by ex_help(), use the saved values,
10617 * when going from a help buffer to a non-help buffer.
10618 * Don't touch these at all when BCO_NOHELP is used and going from
10619 * or to a help buffer.
10620 */
10621 if (dont_do_help)
10622 buf->b_p_isk = save_p_isk;
10623 else
10624 {
10625 buf->b_p_isk = vim_strsave(p_isk);
10626 did_isk = TRUE;
10627 buf->b_p_ts = p_ts;
10628 buf->b_help = FALSE;
10629#ifdef FEAT_QUICKFIX
10630 if (buf->b_p_bt[0] == 'h')
10631 clear_string_option(&buf->b_p_bt);
10632#endif
10633 buf->b_p_ma = p_ma;
10634 }
10635 }
10636
10637 /*
10638 * When the options should be copied (ignoring BCO_ALWAYS), set the
10639 * flag that indicates that the options have been initialized.
10640 */
10641 if (should_copy)
10642 buf->b_p_initialized = TRUE;
10643 }
10644
10645 check_buf_options(buf); /* make sure we don't have NULLs */
10646 if (did_isk)
10647 (void)buf_init_chartab(buf, FALSE);
10648}
10649
10650/*
10651 * Reset the 'modifiable' option and its default value.
10652 */
10653 void
10654reset_modifiable()
10655{
10656 int opt_idx;
10657
10658 curbuf->b_p_ma = FALSE;
10659 p_ma = FALSE;
10660 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010661 if (opt_idx >= 0)
10662 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010663}
10664
10665/*
10666 * Set the global value for 'iminsert' to the local value.
10667 */
10668 void
10669set_iminsert_global()
10670{
10671 p_iminsert = curbuf->b_p_iminsert;
10672}
10673
10674/*
10675 * Set the global value for 'imsearch' to the local value.
10676 */
10677 void
10678set_imsearch_global()
10679{
10680 p_imsearch = curbuf->b_p_imsearch;
10681}
10682
10683#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10684static int expand_option_idx = -1;
10685static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10686static int expand_option_flags = 0;
10687
10688 void
10689set_context_in_set_cmd(xp, arg, opt_flags)
10690 expand_T *xp;
10691 char_u *arg;
10692 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10693{
10694 int nextchar;
10695 long_u flags = 0; /* init for GCC */
10696 int opt_idx = 0; /* init for GCC */
10697 char_u *p;
10698 char_u *s;
10699 int is_term_option = FALSE;
10700 int key;
10701
10702 expand_option_flags = opt_flags;
10703
10704 xp->xp_context = EXPAND_SETTINGS;
10705 if (*arg == NUL)
10706 {
10707 xp->xp_pattern = arg;
10708 return;
10709 }
10710 p = arg + STRLEN(arg) - 1;
10711 if (*p == ' ' && *(p - 1) != '\\')
10712 {
10713 xp->xp_pattern = p + 1;
10714 return;
10715 }
10716 while (p > arg)
10717 {
10718 s = p;
10719 /* count number of backslashes before ' ' or ',' */
10720 if (*p == ' ' || *p == ',')
10721 {
10722 while (s > arg && *(s - 1) == '\\')
10723 --s;
10724 }
10725 /* break at a space with an even number of backslashes */
10726 if (*p == ' ' && ((p - s) & 1) == 0)
10727 {
10728 ++p;
10729 break;
10730 }
10731 --p;
10732 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010733 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734 {
10735 xp->xp_context = EXPAND_BOOL_SETTINGS;
10736 p += 2;
10737 }
10738 if (STRNCMP(p, "inv", 3) == 0)
10739 {
10740 xp->xp_context = EXPAND_BOOL_SETTINGS;
10741 p += 3;
10742 }
10743 xp->xp_pattern = arg = p;
10744 if (*arg == '<')
10745 {
10746 while (*p != '>')
10747 if (*p++ == NUL) /* expand terminal option name */
10748 return;
10749 key = get_special_key_code(arg + 1);
10750 if (key == 0) /* unknown name */
10751 {
10752 xp->xp_context = EXPAND_NOTHING;
10753 return;
10754 }
10755 nextchar = *++p;
10756 is_term_option = TRUE;
10757 expand_option_name[2] = KEY2TERMCAP0(key);
10758 expand_option_name[3] = KEY2TERMCAP1(key);
10759 }
10760 else
10761 {
10762 if (p[0] == 't' && p[1] == '_')
10763 {
10764 p += 2;
10765 if (*p != NUL)
10766 ++p;
10767 if (*p == NUL)
10768 return; /* expand option name */
10769 nextchar = *++p;
10770 is_term_option = TRUE;
10771 expand_option_name[2] = p[-2];
10772 expand_option_name[3] = p[-1];
10773 }
10774 else
10775 {
10776 /* Allow * wildcard */
10777 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10778 p++;
10779 if (*p == NUL)
10780 return;
10781 nextchar = *p;
10782 *p = NUL;
10783 opt_idx = findoption(arg);
10784 *p = nextchar;
10785 if (opt_idx == -1 || options[opt_idx].var == NULL)
10786 {
10787 xp->xp_context = EXPAND_NOTHING;
10788 return;
10789 }
10790 flags = options[opt_idx].flags;
10791 if (flags & P_BOOL)
10792 {
10793 xp->xp_context = EXPAND_NOTHING;
10794 return;
10795 }
10796 }
10797 }
10798 /* handle "-=" and "+=" */
10799 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10800 {
10801 ++p;
10802 nextchar = '=';
10803 }
10804 if ((nextchar != '=' && nextchar != ':')
10805 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10806 {
10807 xp->xp_context = EXPAND_UNSUCCESSFUL;
10808 return;
10809 }
10810 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10811 {
10812 xp->xp_context = EXPAND_OLD_SETTING;
10813 if (is_term_option)
10814 expand_option_idx = -1;
10815 else
10816 expand_option_idx = opt_idx;
10817 xp->xp_pattern = p + 1;
10818 return;
10819 }
10820 xp->xp_context = EXPAND_NOTHING;
10821 if (is_term_option || (flags & P_NUM))
10822 return;
10823
10824 xp->xp_pattern = p + 1;
10825
10826 if (flags & P_EXPAND)
10827 {
10828 p = options[opt_idx].var;
10829 if (p == (char_u *)&p_bdir
10830 || p == (char_u *)&p_dir
10831 || p == (char_u *)&p_path
10832 || p == (char_u *)&p_rtp
10833#ifdef FEAT_SEARCHPATH
10834 || p == (char_u *)&p_cdpath
10835#endif
10836#ifdef FEAT_SESSION
10837 || p == (char_u *)&p_vdir
10838#endif
10839 )
10840 {
10841 xp->xp_context = EXPAND_DIRECTORIES;
10842 if (p == (char_u *)&p_path
10843#ifdef FEAT_SEARCHPATH
10844 || p == (char_u *)&p_cdpath
10845#endif
10846 )
10847 xp->xp_backslash = XP_BS_THREE;
10848 else
10849 xp->xp_backslash = XP_BS_ONE;
10850 }
10851 else
10852 {
10853 xp->xp_context = EXPAND_FILES;
10854 /* for 'tags' need three backslashes for a space */
10855 if (p == (char_u *)&p_tags)
10856 xp->xp_backslash = XP_BS_THREE;
10857 else
10858 xp->xp_backslash = XP_BS_ONE;
10859 }
10860 }
10861
10862 /* For an option that is a list of file names, find the start of the
10863 * last file name. */
10864 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10865 {
10866 /* count number of backslashes before ' ' or ',' */
10867 if (*p == ' ' || *p == ',')
10868 {
10869 s = p;
10870 while (s > xp->xp_pattern && *(s - 1) == '\\')
10871 --s;
10872 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10873 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10874 {
10875 xp->xp_pattern = p + 1;
10876 break;
10877 }
10878 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010879
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010880#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010881 /* for 'spellsuggest' start at "file:" */
10882 if (options[opt_idx].var == (char_u *)&p_sps
10883 && STRNCMP(p, "file:", 5) == 0)
10884 {
10885 xp->xp_pattern = p + 5;
10886 break;
10887 }
10888#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010889 }
10890
10891 return;
10892}
10893
10894 int
10895ExpandSettings(xp, regmatch, num_file, file)
10896 expand_T *xp;
10897 regmatch_T *regmatch;
10898 int *num_file;
10899 char_u ***file;
10900{
10901 int num_normal = 0; /* Nr of matching non-term-code settings */
10902 int num_term = 0; /* Nr of matching terminal code settings */
10903 int opt_idx;
10904 int match;
10905 int count = 0;
10906 char_u *str;
10907 int loop;
10908 int is_term_opt;
10909 char_u name_buf[MAX_KEY_NAME_LEN];
10910 static char *(names[]) = {"all", "termcap"};
10911 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10912
10913 /* do this loop twice:
10914 * loop == 0: count the number of matching options
10915 * loop == 1: copy the matching options into allocated memory
10916 */
10917 for (loop = 0; loop <= 1; ++loop)
10918 {
10919 regmatch->rm_ic = ic;
10920 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10921 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010922 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10923 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10925 {
10926 if (loop == 0)
10927 num_normal++;
10928 else
10929 (*file)[count++] = vim_strsave((char_u *)names[match]);
10930 }
10931 }
10932 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10933 opt_idx++)
10934 {
10935 if (options[opt_idx].var == NULL)
10936 continue;
10937 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10938 && !(options[opt_idx].flags & P_BOOL))
10939 continue;
10940 is_term_opt = istermoption(&options[opt_idx]);
10941 if (is_term_opt && num_normal > 0)
10942 continue;
10943 match = FALSE;
10944 if (vim_regexec(regmatch, str, (colnr_T)0)
10945 || (options[opt_idx].shortname != NULL
10946 && vim_regexec(regmatch,
10947 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10948 match = TRUE;
10949 else if (is_term_opt)
10950 {
10951 name_buf[0] = '<';
10952 name_buf[1] = 't';
10953 name_buf[2] = '_';
10954 name_buf[3] = str[2];
10955 name_buf[4] = str[3];
10956 name_buf[5] = '>';
10957 name_buf[6] = NUL;
10958 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10959 {
10960 match = TRUE;
10961 str = name_buf;
10962 }
10963 }
10964 if (match)
10965 {
10966 if (loop == 0)
10967 {
10968 if (is_term_opt)
10969 num_term++;
10970 else
10971 num_normal++;
10972 }
10973 else
10974 (*file)[count++] = vim_strsave(str);
10975 }
10976 }
10977 /*
10978 * Check terminal key codes, these are not in the option table
10979 */
10980 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
10981 {
10982 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
10983 {
10984 if (!isprint(str[0]) || !isprint(str[1]))
10985 continue;
10986
10987 name_buf[0] = 't';
10988 name_buf[1] = '_';
10989 name_buf[2] = str[0];
10990 name_buf[3] = str[1];
10991 name_buf[4] = NUL;
10992
10993 match = FALSE;
10994 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10995 match = TRUE;
10996 else
10997 {
10998 name_buf[0] = '<';
10999 name_buf[1] = 't';
11000 name_buf[2] = '_';
11001 name_buf[3] = str[0];
11002 name_buf[4] = str[1];
11003 name_buf[5] = '>';
11004 name_buf[6] = NUL;
11005
11006 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11007 match = TRUE;
11008 }
11009 if (match)
11010 {
11011 if (loop == 0)
11012 num_term++;
11013 else
11014 (*file)[count++] = vim_strsave(name_buf);
11015 }
11016 }
11017
11018 /*
11019 * Check special key names.
11020 */
11021 regmatch->rm_ic = TRUE; /* ignore case here */
11022 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11023 {
11024 name_buf[0] = '<';
11025 STRCPY(name_buf + 1, str);
11026 STRCAT(name_buf, ">");
11027
11028 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11029 {
11030 if (loop == 0)
11031 num_term++;
11032 else
11033 (*file)[count++] = vim_strsave(name_buf);
11034 }
11035 }
11036 }
11037 if (loop == 0)
11038 {
11039 if (num_normal > 0)
11040 *num_file = num_normal;
11041 else if (num_term > 0)
11042 *num_file = num_term;
11043 else
11044 return OK;
11045 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11046 if (*file == NULL)
11047 {
11048 *file = (char_u **)"";
11049 return FAIL;
11050 }
11051 }
11052 }
11053 return OK;
11054}
11055
11056 int
11057ExpandOldSetting(num_file, file)
11058 int *num_file;
11059 char_u ***file;
11060{
11061 char_u *var = NULL; /* init for GCC */
11062 char_u *buf;
11063
11064 *num_file = 0;
11065 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11066 if (*file == NULL)
11067 return FAIL;
11068
11069 /*
11070 * For a terminal key code expand_option_idx is < 0.
11071 */
11072 if (expand_option_idx < 0)
11073 {
11074 var = find_termcode(expand_option_name + 2);
11075 if (var == NULL)
11076 expand_option_idx = findoption(expand_option_name);
11077 }
11078
11079 if (expand_option_idx >= 0)
11080 {
11081 /* put string of option value in NameBuff */
11082 option_value2string(&options[expand_option_idx], expand_option_flags);
11083 var = NameBuff;
11084 }
11085 else if (var == NULL)
11086 var = (char_u *)"";
11087
11088 /* A backslash is required before some characters. This is the reverse of
11089 * what happens in do_set(). */
11090 buf = vim_strsave_escaped(var, escape_chars);
11091
11092 if (buf == NULL)
11093 {
11094 vim_free(*file);
11095 *file = NULL;
11096 return FAIL;
11097 }
11098
11099#ifdef BACKSLASH_IN_FILENAME
11100 /* For MS-Windows et al. we don't double backslashes at the start and
11101 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011102 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103 if (var[0] == '\\' && var[1] == '\\'
11104 && expand_option_idx >= 0
11105 && (options[expand_option_idx].flags & P_EXPAND)
11106 && vim_isfilec(var[2])
11107 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011108 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109#endif
11110
11111 *file[0] = buf;
11112 *num_file = 1;
11113 return OK;
11114}
11115#endif
11116
11117/*
11118 * Get the value for the numeric or string option *opp in a nice format into
11119 * NameBuff[]. Must not be called with a hidden option!
11120 */
11121 static void
11122option_value2string(opp, opt_flags)
11123 struct vimoption *opp;
11124 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11125{
11126 char_u *varp;
11127
11128 varp = get_varp_scope(opp, opt_flags);
11129
11130 if (opp->flags & P_NUM)
11131 {
11132 long wc = 0;
11133
11134 if (wc_use_keyname(varp, &wc))
11135 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11136 else if (wc != 0)
11137 STRCPY(NameBuff, transchar((int)wc));
11138 else
11139 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11140 }
11141 else /* P_STRING */
11142 {
11143 varp = *(char_u **)(varp);
11144 if (varp == NULL) /* just in case */
11145 NameBuff[0] = NUL;
11146#ifdef FEAT_CRYPT
11147 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011148 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011149 STRCPY(NameBuff, "*****");
11150#endif
11151 else if (opp->flags & P_EXPAND)
11152 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11153 /* Translate 'pastetoggle' into special key names */
11154 else if ((char_u **)opp->var == &p_pt)
11155 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11156 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011157 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011158 }
11159}
11160
11161/*
11162 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11163 * printed as a keyname.
11164 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11165 */
11166 static int
11167wc_use_keyname(varp, wcp)
11168 char_u *varp;
11169 long *wcp;
11170{
11171 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11172 {
11173 *wcp = *(long *)varp;
11174 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11175 return TRUE;
11176 }
11177 return FALSE;
11178}
11179
11180#ifdef FEAT_LANGMAP
11181/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011182 * Any character has an equivalent 'langmap' character. This is used for
11183 * keyboards that have a special language mode that sends characters above
11184 * 128 (although other characters can be translated too). The "to" field is a
11185 * Vim command character. This avoids having to switch the keyboard back to
11186 * ASCII mode when leaving Insert mode.
11187 *
11188 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11189 * commands.
11190 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11191 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11192 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011193 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011194# ifdef FEAT_MBYTE
11195/*
11196 * With multi-byte support use growarray for 'langmap' chars >= 256
11197 */
11198typedef struct
11199{
11200 int from;
11201 int to;
11202} langmap_entry_T;
11203
11204static garray_T langmap_mapga;
11205static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206
11207/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011208 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11209 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011210 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011211 static void
11212langmap_set_entry(from, to)
11213 int from;
11214 int to;
11215{
11216 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011217 int a = 0;
11218 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011219
11220 /* Do a binary search for an existing entry. */
11221 while (a != b)
11222 {
11223 int i = (a + b) / 2;
11224 int d = entries[i].from - from;
11225
11226 if (d == 0)
11227 {
11228 entries[i].to = to;
11229 return;
11230 }
11231 if (d < 0)
11232 a = i + 1;
11233 else
11234 b = i;
11235 }
11236
11237 if (ga_grow(&langmap_mapga, 1) != OK)
11238 return; /* out of memory */
11239
11240 /* insert new entry at position "a" */
11241 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11242 mch_memmove(entries + 1, entries,
11243 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11244 ++langmap_mapga.ga_len;
11245 entries[0].from = from;
11246 entries[0].to = to;
11247}
11248
11249/*
11250 * Apply 'langmap' to multi-byte character "c" and return the result.
11251 */
11252 int
11253langmap_adjust_mb(c)
11254 int c;
11255{
11256 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11257 int a = 0;
11258 int b = langmap_mapga.ga_len;
11259
11260 while (a != b)
11261 {
11262 int i = (a + b) / 2;
11263 int d = entries[i].from - c;
11264
11265 if (d == 0)
11266 return entries[i].to; /* found matching entry */
11267 if (d < 0)
11268 a = i + 1;
11269 else
11270 b = i;
11271 }
11272 return c; /* no entry found, return "c" unmodified */
11273}
11274# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011275
11276 static void
11277langmap_init()
11278{
11279 int i;
11280
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011281 for (i = 0; i < 256; i++)
11282 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11283# ifdef FEAT_MBYTE
11284 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11285# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286}
11287
11288/*
11289 * Called when langmap option is set; the language map can be
11290 * changed at any time!
11291 */
11292 static void
11293langmap_set()
11294{
11295 char_u *p;
11296 char_u *p2;
11297 int from, to;
11298
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011299#ifdef FEAT_MBYTE
11300 ga_clear(&langmap_mapga); /* clear the previous map first */
11301#endif
11302 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011303
11304 for (p = p_langmap; p[0] != NUL; )
11305 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011306 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11307 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011308 {
11309 if (p2[0] == '\\' && p2[1] != NUL)
11310 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011311 }
11312 if (p2[0] == ';')
11313 ++p2; /* abcd;ABCD form, p2 points to A */
11314 else
11315 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11316 while (p[0])
11317 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011318 if (p[0] == ',')
11319 {
11320 ++p;
11321 break;
11322 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323 if (p[0] == '\\' && p[1] != NUL)
11324 ++p;
11325#ifdef FEAT_MBYTE
11326 from = (*mb_ptr2char)(p);
11327#else
11328 from = p[0];
11329#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011330 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331 if (p2 == NULL)
11332 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011333 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011334 if (p[0] != ',')
11335 {
11336 if (p[0] == '\\')
11337 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011338#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011339 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011340#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011341 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011343 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011344 }
11345 else
11346 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011347 if (p2[0] != ',')
11348 {
11349 if (p2[0] == '\\')
11350 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011351#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011352 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011353#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011354 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011355#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011356 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011357 }
11358 if (to == NUL)
11359 {
11360 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11361 transchar(from));
11362 return;
11363 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011364
11365#ifdef FEAT_MBYTE
11366 if (from >= 256)
11367 langmap_set_entry(from, to);
11368 else
11369#endif
11370 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011371
11372 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011373 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011374 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011375 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011376 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011377 if (*p == ';')
11378 {
11379 p = p2;
11380 if (p[0] != NUL)
11381 {
11382 if (p[0] != ',')
11383 {
11384 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11385 return;
11386 }
11387 ++p;
11388 }
11389 break;
11390 }
11391 }
11392 }
11393 }
11394}
11395#endif
11396
11397/*
11398 * Return TRUE if format option 'x' is in effect.
11399 * Take care of no formatting when 'paste' is set.
11400 */
11401 int
11402has_format_option(x)
11403 int x;
11404{
11405 if (p_paste)
11406 return FALSE;
11407 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11408}
11409
11410/*
11411 * Return TRUE if "x" is present in 'shortmess' option, or
11412 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11413 */
11414 int
11415shortmess(x)
11416 int x;
11417{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011418 return p_shm != NULL &&
11419 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011420 || (vim_strchr(p_shm, 'a') != NULL
11421 && vim_strchr((char_u *)SHM_A, x) != NULL));
11422}
11423
11424/*
11425 * paste_option_changed() - Called after p_paste was set or reset.
11426 */
11427 static void
11428paste_option_changed()
11429{
11430 static int old_p_paste = FALSE;
11431 static int save_sm = 0;
11432#ifdef FEAT_CMDL_INFO
11433 static int save_ru = 0;
11434#endif
11435#ifdef FEAT_RIGHTLEFT
11436 static int save_ri = 0;
11437 static int save_hkmap = 0;
11438#endif
11439 buf_T *buf;
11440
11441 if (p_paste)
11442 {
11443 /*
11444 * Paste switched from off to on.
11445 * Save the current values, so they can be restored later.
11446 */
11447 if (!old_p_paste)
11448 {
11449 /* save options for each buffer */
11450 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11451 {
11452 buf->b_p_tw_nopaste = buf->b_p_tw;
11453 buf->b_p_wm_nopaste = buf->b_p_wm;
11454 buf->b_p_sts_nopaste = buf->b_p_sts;
11455 buf->b_p_ai_nopaste = buf->b_p_ai;
11456 }
11457
11458 /* save global options */
11459 save_sm = p_sm;
11460#ifdef FEAT_CMDL_INFO
11461 save_ru = p_ru;
11462#endif
11463#ifdef FEAT_RIGHTLEFT
11464 save_ri = p_ri;
11465 save_hkmap = p_hkmap;
11466#endif
11467 /* save global values for local buffer options */
11468 p_tw_nopaste = p_tw;
11469 p_wm_nopaste = p_wm;
11470 p_sts_nopaste = p_sts;
11471 p_ai_nopaste = p_ai;
11472 }
11473
11474 /*
11475 * Always set the option values, also when 'paste' is set when it is
11476 * already on.
11477 */
11478 /* set options for each buffer */
11479 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11480 {
11481 buf->b_p_tw = 0; /* textwidth is 0 */
11482 buf->b_p_wm = 0; /* wrapmargin is 0 */
11483 buf->b_p_sts = 0; /* softtabstop is 0 */
11484 buf->b_p_ai = 0; /* no auto-indent */
11485 }
11486
11487 /* set global options */
11488 p_sm = 0; /* no showmatch */
11489#ifdef FEAT_CMDL_INFO
11490# ifdef FEAT_WINDOWS
11491 if (p_ru)
11492 status_redraw_all(); /* redraw to remove the ruler */
11493# endif
11494 p_ru = 0; /* no ruler */
11495#endif
11496#ifdef FEAT_RIGHTLEFT
11497 p_ri = 0; /* no reverse insert */
11498 p_hkmap = 0; /* no Hebrew keyboard */
11499#endif
11500 /* set global values for local buffer options */
11501 p_tw = 0;
11502 p_wm = 0;
11503 p_sts = 0;
11504 p_ai = 0;
11505 }
11506
11507 /*
11508 * Paste switched from on to off: Restore saved values.
11509 */
11510 else if (old_p_paste)
11511 {
11512 /* restore options for each buffer */
11513 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11514 {
11515 buf->b_p_tw = buf->b_p_tw_nopaste;
11516 buf->b_p_wm = buf->b_p_wm_nopaste;
11517 buf->b_p_sts = buf->b_p_sts_nopaste;
11518 buf->b_p_ai = buf->b_p_ai_nopaste;
11519 }
11520
11521 /* restore global options */
11522 p_sm = save_sm;
11523#ifdef FEAT_CMDL_INFO
11524# ifdef FEAT_WINDOWS
11525 if (p_ru != save_ru)
11526 status_redraw_all(); /* redraw to draw the ruler */
11527# endif
11528 p_ru = save_ru;
11529#endif
11530#ifdef FEAT_RIGHTLEFT
11531 p_ri = save_ri;
11532 p_hkmap = save_hkmap;
11533#endif
11534 /* set global values for local buffer options */
11535 p_tw = p_tw_nopaste;
11536 p_wm = p_wm_nopaste;
11537 p_sts = p_sts_nopaste;
11538 p_ai = p_ai_nopaste;
11539 }
11540
11541 old_p_paste = p_paste;
11542}
11543
11544/*
11545 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11546 *
11547 * Reset 'compatible' and set the values for options that didn't get set yet
11548 * to the Vim defaults.
11549 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011550 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011551 */
11552 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011553vimrc_found(fname, envname)
11554 char_u *fname;
11555 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011556{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011557 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011558 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011559 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011560
11561 if (!option_was_set((char_u *)"cp"))
11562 {
11563 p_cp = FALSE;
11564 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11565 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11566 set_option_default(opt_idx, OPT_FREE, FALSE);
11567 didset_options();
11568 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011569
11570 if (fname != NULL)
11571 {
11572 p = vim_getenv(envname, &dofree);
11573 if (p == NULL)
11574 {
11575 /* Set $MYVIMRC to the first vimrc file found. */
11576 p = FullName_save(fname, FALSE);
11577 if (p != NULL)
11578 {
11579 vim_setenv(envname, p);
11580 vim_free(p);
11581 }
11582 }
11583 else if (dofree)
11584 vim_free(p);
11585 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011586}
11587
11588/*
11589 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11590 */
11591 void
11592change_compatible(on)
11593 int on;
11594{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011595 int opt_idx;
11596
Bram Moolenaar071d4272004-06-13 20:20:40 +000011597 if (p_cp != on)
11598 {
11599 p_cp = on;
11600 compatible_set();
11601 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011602 opt_idx = findoption((char_u *)"cp");
11603 if (opt_idx >= 0)
11604 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011605}
11606
11607/*
11608 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011609 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610 */
11611 int
11612option_was_set(name)
11613 char_u *name;
11614{
11615 int idx;
11616
11617 idx = findoption(name);
11618 if (idx < 0) /* unknown option */
11619 return FALSE;
11620 if (options[idx].flags & P_WAS_SET)
11621 return TRUE;
11622 return FALSE;
11623}
11624
11625/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011626 * Reset the flag indicating option "name" was set.
11627 */
11628 void
11629reset_option_was_set(name)
11630 char_u *name;
11631{
11632 int idx = findoption(name);
11633
11634 if (idx >= 0)
11635 options[idx].flags &= ~P_WAS_SET;
11636}
11637
11638/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011639 * compatible_set() - Called when 'compatible' has been set or unset.
11640 *
11641 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11642 * flag) to a Vi compatible value.
11643 * When 'compatible' is unset: Set all options that have a different default
11644 * for Vim (without the P_VI_DEF flag) to that default.
11645 */
11646 static void
11647compatible_set()
11648{
11649 int opt_idx;
11650
11651 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11652 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11653 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11654 set_option_default(opt_idx, OPT_FREE, p_cp);
11655 didset_options();
11656}
11657
11658#ifdef FEAT_LINEBREAK
11659
11660# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11661 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011662 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011663# endif
11664
11665/*
11666 * fill_breakat_flags() -- called when 'breakat' changes value.
11667 */
11668 static void
11669fill_breakat_flags()
11670{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011671 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011672 int i;
11673
11674 for (i = 0; i < 256; i++)
11675 breakat_flags[i] = FALSE;
11676
11677 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011678 for (p = p_breakat; *p; p++)
11679 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011680}
11681
11682# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011683 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011684# endif
11685
11686#endif
11687
11688/*
11689 * Check an option that can be a range of string values.
11690 *
11691 * Return OK for correct value, FAIL otherwise.
11692 * Empty is always OK.
11693 */
11694 static int
11695check_opt_strings(val, values, list)
11696 char_u *val;
11697 char **values;
11698 int list; /* when TRUE: accept a list of values */
11699{
11700 return opt_strings_flags(val, values, NULL, list);
11701}
11702
11703/*
11704 * Handle an option that can be a range of string values.
11705 * Set a flag in "*flagp" for each string present.
11706 *
11707 * Return OK for correct value, FAIL otherwise.
11708 * Empty is always OK.
11709 */
11710 static int
11711opt_strings_flags(val, values, flagp, list)
11712 char_u *val; /* new value */
11713 char **values; /* array of valid string values */
11714 unsigned *flagp;
11715 int list; /* when TRUE: accept a list of values */
11716{
11717 int i;
11718 int len;
11719 unsigned new_flags = 0;
11720
11721 while (*val)
11722 {
11723 for (i = 0; ; ++i)
11724 {
11725 if (values[i] == NULL) /* val not found in values[] */
11726 return FAIL;
11727
11728 len = (int)STRLEN(values[i]);
11729 if (STRNCMP(values[i], val, len) == 0
11730 && ((list && val[len] == ',') || val[len] == NUL))
11731 {
11732 val += len + (val[len] == ',');
11733 new_flags |= (1 << i);
11734 break; /* check next item in val list */
11735 }
11736 }
11737 }
11738 if (flagp != NULL)
11739 *flagp = new_flags;
11740
11741 return OK;
11742}
11743
11744/*
11745 * Read the 'wildmode' option, fill wim_flags[].
11746 */
11747 static int
11748check_opt_wim()
11749{
11750 char_u new_wim_flags[4];
11751 char_u *p;
11752 int i;
11753 int idx = 0;
11754
11755 for (i = 0; i < 4; ++i)
11756 new_wim_flags[i] = 0;
11757
11758 for (p = p_wim; *p; ++p)
11759 {
11760 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11761 ;
11762 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11763 return FAIL;
11764 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11765 new_wim_flags[idx] |= WIM_LONGEST;
11766 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11767 new_wim_flags[idx] |= WIM_FULL;
11768 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11769 new_wim_flags[idx] |= WIM_LIST;
11770 else
11771 return FAIL;
11772 p += i;
11773 if (*p == NUL)
11774 break;
11775 if (*p == ',')
11776 {
11777 if (idx == 3)
11778 return FAIL;
11779 ++idx;
11780 }
11781 }
11782
11783 /* fill remaining entries with last flag */
11784 while (idx < 3)
11785 {
11786 new_wim_flags[idx + 1] = new_wim_flags[idx];
11787 ++idx;
11788 }
11789
11790 /* only when there are no errors, wim_flags[] is changed */
11791 for (i = 0; i < 4; ++i)
11792 wim_flags[i] = new_wim_flags[i];
11793 return OK;
11794}
11795
11796/*
11797 * Check if backspacing over something is allowed.
11798 */
11799 int
11800can_bs(what)
11801 int what; /* BS_INDENT, BS_EOL or BS_START */
11802{
11803 switch (*p_bs)
11804 {
11805 case '2': return TRUE;
11806 case '1': return (what != BS_START);
11807 case '0': return FALSE;
11808 }
11809 return vim_strchr(p_bs, what) != NULL;
11810}
11811
11812/*
11813 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11814 * the file must be considered changed when the value is different.
11815 */
11816 void
11817save_file_ff(buf)
11818 buf_T *buf;
11819{
11820 buf->b_start_ffc = *buf->b_p_ff;
11821 buf->b_start_eol = buf->b_p_eol;
11822#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011823 buf->b_start_bomb = buf->b_p_bomb;
11824
Bram Moolenaar071d4272004-06-13 20:20:40 +000011825 /* Only use free/alloc when necessary, they take time. */
11826 if (buf->b_start_fenc == NULL
11827 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11828 {
11829 vim_free(buf->b_start_fenc);
11830 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11831 }
11832#endif
11833}
11834
11835/*
11836 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11837 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011838 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11839 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011840 * When "ignore_empty" is true don't consider a new, empty buffer to be
11841 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011842 */
11843 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011844file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011846 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011847{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011848 /* In a buffer that was never loaded the options are not valid. */
11849 if (buf->b_flags & BF_NEVERLOADED)
11850 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011851 if (ignore_empty
11852 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011853 && buf->b_ml.ml_line_count == 1
11854 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11855 return FALSE;
11856 if (buf->b_start_ffc != *buf->b_p_ff)
11857 return TRUE;
11858 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11859 return TRUE;
11860#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011861 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11862 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011863 if (buf->b_start_fenc == NULL)
11864 return (*buf->b_p_fenc != NUL);
11865 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11866#else
11867 return FALSE;
11868#endif
11869}
11870
11871/*
11872 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11873 */
11874 int
11875check_ff_value(p)
11876 char_u *p;
11877{
11878 return check_opt_strings(p, p_ff_values, FALSE);
11879}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011880
11881/*
11882 * Return the effective shiftwidth value for current buffer, using the
11883 * 'tabstop' value when 'shiftwidth' is zero.
11884 */
11885 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011886get_sw_value(buf)
11887 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011888{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011889 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011890}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011891
11892/*
11893 * Return the effective softtabstop value for the current buffer, using the
11894 * 'tabstop' value when 'softtabstop' is negative.
11895 */
11896 long
11897get_sts_value()
11898{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011899 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011900}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011901
11902/*
11903 * Check matchpairs option for "*initc".
11904 * If there is a match set "*initc" to the matching character and "*findc" to
11905 * the opposite character. Set "*backwards" to the direction.
11906 * When "switchit" is TRUE swap the direction.
11907 */
11908 void
11909find_mps_values(initc, findc, backwards, switchit)
11910 int *initc;
11911 int *findc;
11912 int *backwards;
11913 int switchit;
11914{
11915 char_u *ptr;
11916
11917 ptr = curbuf->b_p_mps;
11918 while (*ptr != NUL)
11919 {
11920#ifdef FEAT_MBYTE
11921 if (has_mbyte)
11922 {
11923 char_u *prev;
11924
11925 if (mb_ptr2char(ptr) == *initc)
11926 {
11927 if (switchit)
11928 {
11929 *findc = *initc;
11930 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11931 *backwards = TRUE;
11932 }
11933 else
11934 {
11935 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11936 *backwards = FALSE;
11937 }
11938 return;
11939 }
11940 prev = ptr;
11941 ptr += mb_ptr2len(ptr) + 1;
11942 if (mb_ptr2char(ptr) == *initc)
11943 {
11944 if (switchit)
11945 {
11946 *findc = *initc;
11947 *initc = mb_ptr2char(prev);
11948 *backwards = FALSE;
11949 }
11950 else
11951 {
11952 *findc = mb_ptr2char(prev);
11953 *backwards = TRUE;
11954 }
11955 return;
11956 }
11957 ptr += mb_ptr2len(ptr);
11958 }
11959 else
11960#endif
11961 {
11962 if (*ptr == *initc)
11963 {
11964 if (switchit)
11965 {
11966 *backwards = TRUE;
11967 *findc = *initc;
11968 *initc = ptr[2];
11969 }
11970 else
11971 {
11972 *backwards = FALSE;
11973 *findc = ptr[2];
11974 }
11975 return;
11976 }
11977 ptr += 2;
11978 if (*ptr == *initc)
11979 {
11980 if (switchit)
11981 {
11982 *backwards = FALSE;
11983 *findc = *initc;
11984 *initc = ptr[-2];
11985 }
11986 else
11987 {
11988 *backwards = TRUE;
11989 *findc = ptr[-2];
11990 }
11991 return;
11992 }
11993 ++ptr;
11994 }
11995 if (*ptr == ',')
11996 ++ptr;
11997 }
11998}
Bram Moolenaar597a4222014-06-25 14:39:50 +020011999
12000#if defined(FEAT_LINEBREAK) || defined(PROTO)
12001/*
12002 * This is called when 'breakindentopt' is changed and when a window is
12003 * initialized.
12004 */
12005 int
12006briopt_check()
12007{
12008 char_u *p;
12009 int bri_shift = 0;
12010 long bri_min = 20;
12011 int bri_sbr = FALSE;
12012
12013 p = curwin->w_p_briopt;
12014 while (*p != NUL)
12015 {
12016 if (STRNCMP(p, "shift:", 6) == 0
12017 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12018 {
12019 p += 6;
12020 bri_shift = getdigits(&p);
12021 }
12022 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12023 {
12024 p += 4;
12025 bri_min = getdigits(&p);
12026 }
12027 else if (STRNCMP(p, "sbr", 3) == 0)
12028 {
12029 p += 3;
12030 bri_sbr = TRUE;
12031 }
12032 if (*p != ',' && *p != NUL)
12033 return FAIL;
12034 if (*p == ',')
12035 ++p;
12036 }
12037
12038 curwin->w_p_brishift = bri_shift;
12039 curwin->w_p_brimin = bri_min;
12040 curwin->w_p_brisbr = bri_sbr;
12041
12042 return OK;
12043}
12044#endif