blob: af9fb506fc7bcf98aafa5b602d1a9dc926f3aca9 [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 Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
101#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
102#define PV_ET OPT_BUF(BV_ET)
103#ifdef FEAT_MBYTE
104# define PV_FENC OPT_BUF(BV_FENC)
105#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000106#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
107# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
108#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000109#ifdef FEAT_EVAL
110# define PV_FEX OPT_BUF(BV_FEX)
111#endif
112#define PV_FF OPT_BUF(BV_FF)
113#define PV_FLP OPT_BUF(BV_FLP)
114#define PV_FO OPT_BUF(BV_FO)
115#ifdef FEAT_AUTOCMD
116# define PV_FT OPT_BUF(BV_FT)
117#endif
118#define PV_IMI OPT_BUF(BV_IMI)
119#define PV_IMS OPT_BUF(BV_IMS)
120#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
121# define PV_INDE OPT_BUF(BV_INDE)
122# define PV_INDK OPT_BUF(BV_INDK)
123#endif
124#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
125# define PV_INEX OPT_BUF(BV_INEX)
126#endif
127#define PV_INF OPT_BUF(BV_INF)
128#define PV_ISK OPT_BUF(BV_ISK)
129#ifdef FEAT_CRYPT
130# define PV_KEY OPT_BUF(BV_KEY)
131#endif
132#ifdef FEAT_KEYMAP
133# define PV_KMAP OPT_BUF(BV_KMAP)
134#endif
135#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
136#ifdef FEAT_LISP
137# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100138# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000139#endif
140#define PV_MA OPT_BUF(BV_MA)
141#define PV_ML OPT_BUF(BV_ML)
142#define PV_MOD OPT_BUF(BV_MOD)
143#define PV_MPS OPT_BUF(BV_MPS)
144#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#ifdef FEAT_COMPL_FUNC
146# define PV_OFU OPT_BUF(BV_OFU)
147#endif
148#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
149#define PV_PI OPT_BUF(BV_PI)
150#ifdef FEAT_TEXTOBJ
151# define PV_QE OPT_BUF(BV_QE)
152#endif
153#define PV_RO OPT_BUF(BV_RO)
154#ifdef FEAT_SMARTINDENT
155# define PV_SI OPT_BUF(BV_SI)
156#endif
157#ifndef SHORT_FNAME
158# define PV_SN OPT_BUF(BV_SN)
159#endif
160#ifdef FEAT_SYN_HL
161# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000162# define PV_SYN OPT_BUF(BV_SYN)
163#endif
164#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000165# define PV_SPC OPT_BUF(BV_SPC)
166# define PV_SPF OPT_BUF(BV_SPF)
167# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168#endif
169#define PV_STS OPT_BUF(BV_STS)
170#ifdef FEAT_SEARCHPATH
171# define PV_SUA OPT_BUF(BV_SUA)
172#endif
173#define PV_SW OPT_BUF(BV_SW)
174#define PV_SWF OPT_BUF(BV_SWF)
175#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
176#define PV_TS OPT_BUF(BV_TS)
177#define PV_TW OPT_BUF(BV_TW)
178#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200179#ifdef FEAT_PERSISTENT_UNDO
180# define PV_UDF OPT_BUF(BV_UDF)
181#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000182#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000183
184/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000185 * Definition of the PV_ values for window-local options.
186 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188#define PV_LIST OPT_WIN(WV_LIST)
189#ifdef FEAT_ARABIC
190# define PV_ARAB OPT_WIN(WV_ARAB)
191#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200192#ifdef FEAT_LINEBREAK
193# define PV_BRI OPT_WIN(WV_BRI)
194# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000196#ifdef FEAT_DIFF
197# define PV_DIFF OPT_WIN(WV_DIFF)
198#endif
199#ifdef FEAT_FOLDING
200# define PV_FDC OPT_WIN(WV_FDC)
201# define PV_FEN OPT_WIN(WV_FEN)
202# define PV_FDI OPT_WIN(WV_FDI)
203# define PV_FDL OPT_WIN(WV_FDL)
204# define PV_FDM OPT_WIN(WV_FDM)
205# define PV_FML OPT_WIN(WV_FML)
206# define PV_FDN OPT_WIN(WV_FDN)
207# ifdef FEAT_EVAL
208# define PV_FDE OPT_WIN(WV_FDE)
209# define PV_FDT OPT_WIN(WV_FDT)
210# endif
211# define PV_FMR OPT_WIN(WV_FMR)
212#endif
213#ifdef FEAT_LINEBREAK
214# define PV_LBR OPT_WIN(WV_LBR)
215#endif
216#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200217#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000218#ifdef FEAT_LINEBREAK
219# define PV_NUW OPT_WIN(WV_NUW)
220#endif
221#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
222# define PV_PVW OPT_WIN(WV_PVW)
223#endif
224#ifdef FEAT_RIGHTLEFT
225# define PV_RL OPT_WIN(WV_RL)
226# define PV_RLC OPT_WIN(WV_RLC)
227#endif
228#ifdef FEAT_SCROLLBIND
229# define PV_SCBIND OPT_WIN(WV_SCBIND)
230#endif
231#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_WINDOWS
245# define PV_WFH OPT_WIN(WV_WFH)
246#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000247#ifdef FEAT_VERTSPLIT
248# define PV_WFW OPT_WIN(WV_WFW)
249#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#ifdef FEAT_CURSORBIND
252# define PV_CRBIND OPT_WIN(WV_CRBIND)
253#endif
254#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200255# define PV_COCU OPT_WIN(WV_COCU)
256# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200257#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000258
259/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260typedef enum
261{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000262 PV_NONE = 0,
263 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264} idopt_T;
265
266/*
267 * Options local to a window have a value local to a buffer and global to all
268 * buffers. Indicate this by setting "var" to VAR_WIN.
269 */
270#define VAR_WIN ((char_u *)-1)
271
272/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000273 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000274 * Only to be used in option.c!
275 */
276static int p_ai;
277static int p_bin;
278#ifdef FEAT_MBYTE
279static int p_bomb;
280#endif
281#if defined(FEAT_QUICKFIX)
282static char_u *p_bh;
283static char_u *p_bt;
284#endif
285static int p_bl;
286static int p_ci;
287#ifdef FEAT_CINDENT
288static int p_cin;
289static char_u *p_cink;
290static char_u *p_cino;
291#endif
292#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
293static char_u *p_cinw;
294#endif
295#ifdef FEAT_COMMENTS
296static char_u *p_com;
297#endif
298#ifdef FEAT_FOLDING
299static char_u *p_cms;
300#endif
301#ifdef FEAT_INS_EXPAND
302static char_u *p_cpt;
303#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000304#ifdef FEAT_COMPL_FUNC
305static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000306static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static int p_eol;
309static int p_et;
310#ifdef FEAT_MBYTE
311static char_u *p_fenc;
312#endif
313static char_u *p_ff;
314static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000315static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316#ifdef FEAT_AUTOCMD
317static char_u *p_ft;
318#endif
319static long p_iminsert;
320static long p_imsearch;
321#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
322static char_u *p_inex;
323#endif
324#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
325static char_u *p_inde;
326static char_u *p_indk;
327#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000328#if defined(FEAT_EVAL)
329static char_u *p_fex;
330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000331static int p_inf;
332static char_u *p_isk;
333#ifdef FEAT_CRYPT
334static char_u *p_key;
335#endif
336#ifdef FEAT_LISP
337static int p_lisp;
338#endif
339static int p_ml;
340static int p_ma;
341static int p_mod;
342static char_u *p_mps;
343static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000344static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000345#ifdef FEAT_TEXTOBJ
346static char_u *p_qe;
347#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348static int p_ro;
349#ifdef FEAT_SMARTINDENT
350static int p_si;
351#endif
352#ifndef SHORT_FNAME
353static int p_sn;
354#endif
355static long p_sts;
356#if defined(FEAT_SEARCHPATH)
357static char_u *p_sua;
358#endif
359static long p_sw;
360static int p_swf;
361#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000362static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000364#endif
365#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000366static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000367static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000368static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369#endif
370static long p_ts;
371static long p_tw;
372static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200373#ifdef FEAT_PERSISTENT_UNDO
374static int p_udf;
375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376static long p_wm;
377#ifdef FEAT_KEYMAP
378static char_u *p_keymap;
379#endif
380
381/* Saved values for when 'bin' is set. */
382static int p_et_nobin;
383static int p_ml_nobin;
384static long p_tw_nobin;
385static long p_wm_nobin;
386
387/* Saved values for when 'paste' is set */
388static long p_tw_nopaste;
389static long p_wm_nopaste;
390static long p_sts_nopaste;
391static int p_ai_nopaste;
392
393struct vimoption
394{
395 char *fullname; /* full option name */
396 char *shortname; /* permissible abbreviation */
397 long_u flags; /* see below */
398 char_u *var; /* global option: pointer to variable;
399 * window-local option: VAR_WIN;
400 * buffer-local option: global value */
401 idopt_T indir; /* global option: PV_NONE;
402 * local option: indirect option index */
403 char_u *def_val[2]; /* default values for variable (vi and vim) */
404#ifdef FEAT_EVAL
405 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000406# define SCRIPTID_INIT , 0
407#else
408# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409#endif
410};
411
412#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
413#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
414
415/*
416 * Flags
417 */
418#define P_BOOL 0x01 /* the option is boolean */
419#define P_NUM 0x02 /* the option is numeric */
420#define P_STRING 0x04 /* the option is a string */
421#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000422 must use free_string_option() when
423 assigning new value. Not set if default is
424 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000425#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
426 never be used for local or hidden options! */
427#define P_NODEFAULT 0x40 /* don't set to default value */
428#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
429 use vim_free() when assigning new value */
430#define P_WAS_SET 0x100 /* option has been set/reset */
431#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
432#define P_VI_DEF 0x400 /* Use Vi default for Vim */
433#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
434
435 /* when option changed, what to display: */
436#define P_RSTAT 0x1000 /* redraw status lines */
437#define P_RWIN 0x2000 /* redraw current window */
438#define P_RBUF 0x4000 /* redraw current buffer */
439#define P_RALL 0x6000 /* redraw all windows */
440#define P_RCLR 0x7000 /* clear and redraw all */
441
442#define P_COMMA 0x8000 /* comma separated list */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200443#define P_NODUP 0x10000L /* don't allow duplicate strings */
444#define P_FLAGLIST 0x20000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445
Bram Moolenaar913077c2012-03-28 19:59:04 +0200446#define P_SECURE 0x40000L /* cannot change in modeline or secure mode */
447#define P_GETTEXT 0x80000L /* expand default value with _() */
448#define P_NOGLOB 0x100000L /* do not use local value for global vimrc */
449#define P_NFNAME 0x200000L /* only normal file name chars allowed */
450#define P_INSECURE 0x400000L /* option was set from a modeline */
451#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000452 side effects) */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200453#define P_NO_ML 0x1000000L /* not allowed in modeline */
454#define P_CURSWANT 0x2000000L /* update curswant required; not needed when
455 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000457#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
458
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000459/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
460 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000461#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000462# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000463#else
464# define ISP_LATIN1 (char_u *)"@,161-255"
465#endif
466
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000467/* The 16 bit MS-DOS version is low on space, make the string as short as
468 * possible when compiling with few features. */
469#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
470 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200471 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100472# 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 +0000473#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100474# 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 +0000475#endif
476
Bram Moolenaar071d4272004-06-13 20:20:40 +0000477/*
478 * options[] is initialized here.
479 * The order of the options MUST be alphabetic for ":set all" and findoption().
480 * All option names MUST start with a lowercase letter (for findoption()).
481 * Exception: "t_" options are at the end.
482 * The options with a NULL variable are 'hidden': a set command for them is
483 * ignored and they are not printed.
484 */
485static struct vimoption
486#ifdef FEAT_GUI_W16
487 _far
488#endif
489 options[] =
490{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200491 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492#ifdef FEAT_RIGHTLEFT
493 (char_u *)&p_aleph, PV_NONE,
494#else
495 (char_u *)NULL, PV_NONE,
496#endif
497 {
498#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
499 (char_u *)128L,
500#else
501 (char_u *)224L,
502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000503 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
505#if defined(FEAT_GUI) && defined(MACOS_X)
506 (char_u *)&p_antialias, PV_NONE,
507 {(char_u *)FALSE, (char_u *)FALSE}
508#else
509 (char_u *)NULL, PV_NONE,
510 {(char_u *)FALSE, (char_u *)FALSE}
511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000512 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200513 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514#ifdef FEAT_ARABIC
515 (char_u *)VAR_WIN, PV_ARAB,
516#else
517 (char_u *)NULL, PV_NONE,
518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000519 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
521#ifdef FEAT_ARABIC
522 (char_u *)&p_arshape, PV_NONE,
523#else
524 (char_u *)NULL, PV_NONE,
525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000526 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000527 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
528#ifdef FEAT_RIGHTLEFT
529 (char_u *)&p_ari, PV_NONE,
530#else
531 (char_u *)NULL, PV_NONE,
532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000534 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
535#ifdef FEAT_FKMAP
536 (char_u *)&p_altkeymap, PV_NONE,
537#else
538 (char_u *)NULL, PV_NONE,
539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000541 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
542#if defined(FEAT_MBYTE)
543 (char_u *)&p_ambw, PV_NONE,
544 {(char_u *)"single", (char_u *)0L}
545#else
546 (char_u *)NULL, PV_NONE,
547 {(char_u *)0L, (char_u *)0L}
548#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000549 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000550#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 {"autochdir", "acd", P_BOOL|P_VI_DEF,
552 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554#endif
555 {"autoindent", "ai", P_BOOL|P_VI_DEF,
556 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autoprint", "ap", P_BOOL|P_VI_DEF,
559 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000562 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564 {"autowrite", "aw", P_BOOL|P_VI_DEF,
565 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autowriteall","awa", P_BOOL|P_VI_DEF,
568 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
571 (char_u *)&p_bg, PV_NONE,
572 {
573#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
574 (char_u *)"dark",
575#else
576 (char_u *)"light",
577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
580 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
583 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000584 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200586 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587#ifdef UNIX
588 {(char_u *)"yes", (char_u *)"auto"}
589#else
590 {(char_u *)"auto", (char_u *)"auto"}
591#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000592 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
594 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000595 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000596 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 (char_u *)&p_bex, PV_NONE,
598 {
599#ifdef VMS
600 (char_u *)"_",
601#else
602 (char_u *)"~",
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
606#ifdef FEAT_WILDIGN
607 (char_u *)&p_bsk, PV_NONE,
608 {(char_u *)"", (char_u *)0L}
609#else
610 (char_u *)NULL, PV_NONE,
611 {(char_u *)0L, (char_u *)0L}
612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000613 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614#ifdef FEAT_BEVAL
615 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
616 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
619 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000621# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000622 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000623 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000625# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626#endif
627 {"beautify", "bf", P_BOOL|P_VI_DEF,
628 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000629 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
631 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000632 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
634#ifdef MSDOS
635 (char_u *)&p_biosk, PV_NONE,
636#else
637 (char_u *)NULL, PV_NONE,
638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000639 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
641#ifdef FEAT_MBYTE
642 (char_u *)&p_bomb, PV_BOMB,
643#else
644 (char_u *)NULL, PV_NONE,
645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
648#ifdef FEAT_LINEBREAK
649 (char_u *)&p_breakat, PV_NONE,
650 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000655 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200656 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
657#ifdef FEAT_LINEBREAK
658 (char_u *)VAR_WIN, PV_BRI,
659 {(char_u *)FALSE, (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
664 SCRIPTID_INIT},
665 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_COMMA|P_NODUP,
666#ifdef FEAT_LINEBREAK
667 (char_u *)VAR_WIN, PV_BRIOPT,
668 {(char_u *)"", (char_u *)NULL}
669#else
670 (char_u *)NULL, PV_NONE,
671 {(char_u *)"", (char_u *)NULL}
672#endif
673 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
675#ifdef FEAT_BROWSE
676 (char_u *)&p_bsdir, PV_NONE,
677 {(char_u *)"last", (char_u *)0L}
678#else
679 (char_u *)NULL, PV_NONE,
680 {(char_u *)0L, (char_u *)0L}
681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000682 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
684#if defined(FEAT_QUICKFIX)
685 (char_u *)&p_bh, PV_BH,
686 {(char_u *)"", (char_u *)0L}
687#else
688 (char_u *)NULL, PV_NONE,
689 {(char_u *)0L, (char_u *)0L}
690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000691 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
693 (char_u *)&p_bl, PV_BL,
694 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
697#if defined(FEAT_QUICKFIX)
698 (char_u *)&p_bt, PV_BT,
699 {(char_u *)"", (char_u *)0L}
700#else
701 (char_u *)NULL, PV_NONE,
702 {(char_u *)0L, (char_u *)0L}
703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000706#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 (char_u *)&p_cmp, PV_NONE,
708 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000709#else
710 (char_u *)NULL, PV_NONE,
711 {(char_u *)0L, (char_u *)0L}
712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
715#ifdef FEAT_SEARCHPATH
716 (char_u *)&p_cdpath, PV_NONE,
717 {(char_u *)",,", (char_u *)0L}
718#else
719 (char_u *)NULL, PV_NONE,
720 {(char_u *)0L, (char_u *)0L}
721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"cedit", NULL, P_STRING,
724#ifdef FEAT_CMDWIN
725 (char_u *)&p_cedit, PV_NONE,
726 {(char_u *)"", (char_u *)CTRL_F_STR}
727#else
728 (char_u *)NULL, PV_NONE,
729 {(char_u *)0L, (char_u *)0L}
730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000731 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
733#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
734 (char_u *)&p_ccv, PV_NONE,
735 {(char_u *)"", (char_u *)0L}
736#else
737 (char_u *)NULL, PV_NONE,
738 {(char_u *)0L, (char_u *)0L}
739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000740 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
742#ifdef FEAT_CINDENT
743 (char_u *)&p_cin, PV_CIN,
744#else
745 (char_u *)NULL, PV_NONE,
746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000747 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
749#ifdef FEAT_CINDENT
750 (char_u *)&p_cink, PV_CINK,
751 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
752#else
753 (char_u *)NULL, PV_NONE,
754 {(char_u *)0L, (char_u *)0L}
755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000756 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
758#ifdef FEAT_CINDENT
759 (char_u *)&p_cino, PV_CINO,
760#else
761 (char_u *)NULL, PV_NONE,
762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000763 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
765#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
766 (char_u *)&p_cinw, PV_CINW,
767 {(char_u *)"if,else,while,do,for,switch",
768 (char_u *)0L}
769#else
770 (char_u *)NULL, PV_NONE,
771 {(char_u *)0L, (char_u *)0L}
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
775#ifdef FEAT_CLIPBOARD
776 (char_u *)&p_cb, PV_NONE,
777# ifdef FEAT_XCLIPBOARD
778 {(char_u *)"autoselect,exclude:cons\\|linux",
779 (char_u *)0L}
780# else
781 {(char_u *)"", (char_u *)0L}
782# endif
783#else
784 (char_u *)NULL, PV_NONE,
785 {(char_u *)"", (char_u *)0L}
786#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000787 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000788 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
789 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
792#ifdef FEAT_CMDWIN
793 (char_u *)&p_cwh, PV_NONE,
794#else
795 (char_u *)NULL, PV_NONE,
796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000797 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200798 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
799#ifdef FEAT_SYN_HL
800 (char_u *)VAR_WIN, PV_CC,
801#else
802 (char_u *)NULL, PV_NONE,
803#endif
804 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
806 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200808 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809#ifdef FEAT_COMMENTS
810 (char_u *)&p_com, PV_COM,
811 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
812 (char_u *)0L}
813#else
814 (char_u *)NULL, PV_NONE,
815 {(char_u *)0L, (char_u *)0L}
816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000817 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200818 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819#ifdef FEAT_FOLDING
820 (char_u *)&p_cms, PV_CMS,
821 {(char_u *)"/*%s*/", (char_u *)0L}
822#else
823 (char_u *)NULL, PV_NONE,
824 {(char_u *)0L, (char_u *)0L}
825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000826 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000827 /* P_PRI_MKRC isn't needed here, optval_default()
828 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000829 {"compatible", "cp", P_BOOL|P_RALL,
830 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000832 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
833#ifdef FEAT_INS_EXPAND
834 (char_u *)&p_cpt, PV_CPT,
835 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
836#else
837 (char_u *)NULL, PV_NONE,
838 {(char_u *)0L, (char_u *)0L}
839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000840 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200841 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200842#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200843 (char_u *)VAR_WIN, PV_COCU,
844 {(char_u *)"", (char_u *)NULL}
845#else
846 (char_u *)NULL, PV_NONE,
847 {(char_u *)NULL, (char_u *)0L}
848#endif
849 SCRIPTID_INIT},
850 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
851#ifdef FEAT_CONCEAL
852 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200853#else
854 (char_u *)NULL, PV_NONE,
855#endif
856 {(char_u *)0L, (char_u *)0L}
857 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000858 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
859#ifdef FEAT_COMPL_FUNC
860 (char_u *)&p_cfu, PV_CFU,
861 {(char_u *)"", (char_u *)0L}
862#else
863 (char_u *)NULL, PV_NONE,
864 {(char_u *)0L, (char_u *)0L}
865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000867 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
868#ifdef FEAT_INS_EXPAND
869 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000870 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000871#else
872 (char_u *)NULL, PV_NONE,
873 {(char_u *)0L, (char_u *)0L}
874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000875 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000876 {"confirm", "cf", P_BOOL|P_VI_DEF,
877#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
878 (char_u *)&p_confirm, PV_NONE,
879#else
880 (char_u *)NULL, PV_NONE,
881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"conskey", "consk",P_BOOL|P_VI_DEF,
884#ifdef MSDOS
885 (char_u *)&p_consk, PV_NONE,
886#else
887 (char_u *)NULL, PV_NONE,
888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000889 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
891 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000892 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
894 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000895 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
896 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200897 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200898#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200899 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200900 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200901#else
902 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200903 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200904#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200905 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
907#ifdef FEAT_CSCOPE
908 (char_u *)&p_cspc, PV_NONE,
909#else
910 (char_u *)NULL, PV_NONE,
911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000912 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
914#ifdef FEAT_CSCOPE
915 (char_u *)&p_csprg, PV_NONE,
916 {(char_u *)"cscope", (char_u *)0L}
917#else
918 (char_u *)NULL, PV_NONE,
919 {(char_u *)0L, (char_u *)0L}
920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000921 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
923#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
924 (char_u *)&p_csqf, PV_NONE,
925 {(char_u *)"", (char_u *)0L}
926#else
927 (char_u *)NULL, PV_NONE,
928 {(char_u *)0L, (char_u *)0L}
929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000930 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200931 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
932#ifdef FEAT_CSCOPE
933 (char_u *)&p_csre, PV_NONE,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_cst, PV_NONE,
941#else
942 (char_u *)NULL, PV_NONE,
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csto, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
953#ifdef FEAT_CSCOPE
954 (char_u *)&p_csverbose, PV_NONE,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000958 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200959 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
960#ifdef FEAT_CURSORBIND
961 (char_u *)VAR_WIN, PV_CRBIND,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
965 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000966 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
967#ifdef FEAT_SYN_HL
968 (char_u *)VAR_WIN, PV_CUC,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000973 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
974#ifdef FEAT_SYN_HL
975 (char_u *)VAR_WIN, PV_CUL,
976#else
977 (char_u *)NULL, PV_NONE,
978#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980 {"debug", NULL, P_STRING|P_VI_DEF,
981 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200983 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000984#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000985 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000986 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000987#else
988 (char_u *)NULL, PV_NONE,
989 {(char_u *)NULL, (char_u *)0L}
990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000991 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
993#ifdef FEAT_MBYTE
994 (char_u *)&p_deco, PV_NONE,
995#else
996 (char_u *)NULL, PV_NONE,
997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
1000#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001001 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002#else
1003 (char_u *)NULL, PV_NONE,
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1007#ifdef FEAT_DIFF
1008 (char_u *)VAR_WIN, PV_DIFF,
1009#else
1010 (char_u *)NULL, PV_NONE,
1011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001012 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001013 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1015 (char_u *)&p_dex, PV_NONE,
1016 {(char_u *)"", (char_u *)0L}
1017#else
1018 (char_u *)NULL, PV_NONE,
1019 {(char_u *)0L, (char_u *)0L}
1020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001021 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
1023#ifdef FEAT_DIFF
1024 (char_u *)&p_dip, PV_NONE,
1025 {(char_u *)"filler", (char_u *)NULL}
1026#else
1027 (char_u *)NULL, PV_NONE,
1028 {(char_u *)"", (char_u *)NULL}
1029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1032#ifdef FEAT_DIGRAPHS
1033 (char_u *)&p_dg, PV_NONE,
1034#else
1035 (char_u *)NULL, PV_NONE,
1036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1039 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001040 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1042 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 {"eadirection", "ead", P_STRING|P_VI_DEF,
1045#ifdef FEAT_VERTSPLIT
1046 (char_u *)&p_ead, PV_NONE,
1047 {(char_u *)"both", (char_u *)0L}
1048#else
1049 (char_u *)NULL, PV_NONE,
1050 {(char_u *)NULL, (char_u *)0L}
1051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1054 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001055 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001056 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057#ifdef FEAT_MBYTE
1058 (char_u *)&p_enc, PV_NONE,
1059 {(char_u *)ENC_DFLT, (char_u *)0L}
1060#else
1061 (char_u *)NULL, PV_NONE,
1062 {(char_u *)0L, (char_u *)0L}
1063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1066 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1069 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001072 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001073 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1075 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001076 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1078#ifdef FEAT_QUICKFIX
1079 (char_u *)&p_ef, PV_NONE,
1080 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)NULL, (char_u *)0L}
1084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1087#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001088 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001089 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090#else
1091 (char_u *)NULL, PV_NONE,
1092 {(char_u *)NULL, (char_u *)0L}
1093#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"esckeys", "ek", P_BOOL|P_VIM,
1096 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001097 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1099#ifdef FEAT_AUTOCMD
1100 (char_u *)&p_ei, PV_NONE,
1101#else
1102 (char_u *)NULL, PV_NONE,
1103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1106 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1109 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1112#ifdef FEAT_MBYTE
1113 (char_u *)&p_fenc, PV_FENC,
1114 {(char_u *)"", (char_u *)0L}
1115#else
1116 (char_u *)NULL, PV_NONE,
1117 {(char_u *)0L, (char_u *)0L}
1118#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1121#ifdef FEAT_MBYTE
1122 (char_u *)&p_fencs, PV_NONE,
1123 {(char_u *)"ucs-bom", (char_u *)0L}
1124#else
1125 (char_u *)NULL, PV_NONE,
1126 {(char_u *)0L, (char_u *)0L}
1127#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001128 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001129 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001131 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1133 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001134 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1135 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001136 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1137 (char_u *)&p_fic, PV_NONE,
1138 {
1139#ifdef CASE_INSENSITIVE_FILENAME
1140 (char_u *)TRUE,
1141#else
1142 (char_u *)FALSE,
1143#endif
1144 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001145 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146#ifdef FEAT_AUTOCMD
1147 (char_u *)&p_ft, PV_FT,
1148 {(char_u *)"", (char_u *)0L}
1149#else
1150 (char_u *)NULL, PV_NONE,
1151 {(char_u *)0L, (char_u *)0L}
1152#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1155#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1156 (char_u *)&p_fcs, PV_NONE,
1157 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)"", (char_u *)0L}
1161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001163 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1164#ifdef FEAT_FKMAP
1165 (char_u *)&p_fkmap, PV_NONE,
1166#else
1167 (char_u *)NULL, PV_NONE,
1168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001170 {"flash", "fl", P_BOOL|P_VI_DEF,
1171 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001173#ifdef FEAT_FOLDING
1174 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1175 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001176 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1178 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001179 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001180 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1181 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001182 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1184# ifdef FEAT_EVAL
1185 (char_u *)VAR_WIN, PV_FDE,
1186 {(char_u *)"0", (char_u *)NULL}
1187# else
1188 (char_u *)NULL, PV_NONE,
1189 {(char_u *)NULL, (char_u *)0L}
1190# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1193 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1196 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001198 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1202 P_RWIN|P_COMMA|P_NODUP,
1203 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001204 {(char_u *)"{{{,}}}", (char_u *)NULL}
1205 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001206 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1207 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001208 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1210 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001211 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1213 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001214 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001215 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 (char_u *)&p_fdo, PV_NONE,
1217 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001218 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1220# ifdef FEAT_EVAL
1221 (char_u *)VAR_WIN, PV_FDT,
1222 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001223# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224 (char_u *)NULL, PV_NONE,
1225 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001226# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001227 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001229 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001230#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001231 (char_u *)&p_fex, PV_FEX,
1232 {(char_u *)"", (char_u *)0L}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)0L, (char_u *)0L}
1236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1239 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001240 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1241 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001242 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1243 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001244 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1245 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001246 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1247 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001248 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001249 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1250#ifdef HAVE_FSYNC
1251 (char_u *)&p_fs, PV_NONE,
1252 {(char_u *)TRUE, (char_u *)0L}
1253#else
1254 (char_u *)NULL, PV_NONE,
1255 {(char_u *)FALSE, (char_u *)0L}
1256#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001257 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1259 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 {"graphic", "gr", P_BOOL|P_VI_DEF,
1262 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1265#ifdef FEAT_QUICKFIX
1266 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001267 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268#else
1269 (char_u *)NULL, PV_NONE,
1270 {(char_u *)NULL, (char_u *)0L}
1271#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1274#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001275 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {
1277# ifdef WIN3264
1278 /* may be changed to "grep -n" in os_win32.c */
1279 (char_u *)"findstr /n",
1280# else
1281# ifdef UNIX
1282 /* Add an extra file name so that grep will always
1283 * insert a file name in the match line. */
1284 (char_u *)"grep -n $* /dev/null",
1285# else
1286# ifdef VMS
1287 (char_u *)"SEARCH/NUMBERS ",
1288# else
1289 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001290# endif
1291# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001292# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001293 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294#else
1295 (char_u *)NULL, PV_NONE,
1296 {(char_u *)NULL, (char_u *)0L}
1297#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001298 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1300#ifdef CURSOR_SHAPE
1301 (char_u *)&p_guicursor, PV_NONE,
1302 {
1303# ifdef FEAT_GUI
1304 (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",
1305# else /* MSDOS or Win32 console */
1306 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1307# endif
1308 (char_u *)0L}
1309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001313 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1315#ifdef FEAT_GUI
1316 (char_u *)&p_guifont, PV_NONE,
1317 {(char_u *)"", (char_u *)0L}
1318#else
1319 (char_u *)NULL, PV_NONE,
1320 {(char_u *)NULL, (char_u *)0L}
1321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001322 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001323 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1324#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1325 (char_u *)&p_guifontset, PV_NONE,
1326 {(char_u *)"", (char_u *)0L}
1327#else
1328 (char_u *)NULL, PV_NONE,
1329 {(char_u *)NULL, (char_u *)0L}
1330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1333#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1334 (char_u *)&p_guifontwide, PV_NONE,
1335 {(char_u *)"", (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)NULL, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001342#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343 (char_u *)&p_ghr, PV_NONE,
1344#else
1345 (char_u *)NULL, PV_NONE,
1346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001347 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001349#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 (char_u *)&p_go, PV_NONE,
1351# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001352 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001354 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001355# endif
1356#else
1357 (char_u *)NULL, PV_NONE,
1358 {(char_u *)NULL, (char_u *)0L}
1359#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001360 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 {"guipty", NULL, P_BOOL|P_VI_DEF,
1362#if defined(FEAT_GUI)
1363 (char_u *)&p_guipty, PV_NONE,
1364#else
1365 (char_u *)NULL, PV_NONE,
1366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001368 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001369#if defined(FEAT_GUI_TABLINE)
1370 (char_u *)&p_gtl, PV_NONE,
1371 {(char_u *)"", (char_u *)0L}
1372#else
1373 (char_u *)NULL, PV_NONE,
1374 {(char_u *)NULL, (char_u *)0L}
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001377 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001378#if defined(FEAT_GUI_TABLINE)
1379 (char_u *)&p_gtt, PV_NONE,
1380 {(char_u *)"", (char_u *)0L}
1381#else
1382 (char_u *)NULL, PV_NONE,
1383 {(char_u *)NULL, (char_u *)0L}
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1387 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1390 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001391 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1392 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 {"helpheight", "hh", P_NUM|P_VI_DEF,
1394#ifdef FEAT_WINDOWS
1395 (char_u *)&p_hh, PV_NONE,
1396#else
1397 (char_u *)NULL, PV_NONE,
1398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001399 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001400 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1401#ifdef FEAT_MULTI_LANG
1402 (char_u *)&p_hlg, PV_NONE,
1403 {(char_u *)"", (char_u *)0L}
1404#else
1405 (char_u *)NULL, PV_NONE,
1406 {(char_u *)0L, (char_u *)0L}
1407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001409 {"hidden", "hid", P_BOOL|P_VI_DEF,
1410 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1413 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1415 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416 {"history", "hi", P_NUM|P_VIM,
1417 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001418 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1420#ifdef FEAT_RIGHTLEFT
1421 (char_u *)&p_hkmap, PV_NONE,
1422#else
1423 (char_u *)NULL, PV_NONE,
1424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1427#ifdef FEAT_RIGHTLEFT
1428 (char_u *)&p_hkmapp, PV_NONE,
1429#else
1430 (char_u *)NULL, PV_NONE,
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1434 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 {"icon", NULL, P_BOOL|P_VI_DEF,
1437#ifdef FEAT_TITLE
1438 (char_u *)&p_icon, PV_NONE,
1439#else
1440 (char_u *)NULL, PV_NONE,
1441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001442 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001443 {"iconstring", NULL, P_STRING|P_VI_DEF,
1444#ifdef FEAT_TITLE
1445 (char_u *)&p_iconstring, PV_NONE,
1446#else
1447 (char_u *)NULL, PV_NONE,
1448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001449 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1451 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001453 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1454# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1455 (char_u *)&p_imaf, PV_NONE,
1456 {(char_u *)"", (char_u *)NULL}
1457# else
1458 (char_u *)NULL, PV_NONE,
1459 {(char_u *)NULL, (char_u *)0L}
1460# endif
1461 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001463#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 (char_u *)&p_imak, PV_NONE,
1465#else
1466 (char_u *)NULL, PV_NONE,
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1470#ifdef USE_IM_CONTROL
1471 (char_u *)&p_imcmdline, PV_NONE,
1472#else
1473 (char_u *)NULL, PV_NONE,
1474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001475 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1477#ifdef USE_IM_CONTROL
1478 (char_u *)&p_imdisable, PV_NONE,
1479#else
1480 (char_u *)NULL, PV_NONE,
1481#endif
1482#ifdef __sgi
1483 {(char_u *)TRUE, (char_u *)0L}
1484#else
1485 {(char_u *)FALSE, (char_u *)0L}
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"iminsert", "imi", P_NUM|P_VI_DEF,
1489 (char_u *)&p_iminsert, PV_IMI,
1490#ifdef B_IMODE_IM
1491 {(char_u *)B_IMODE_IM, (char_u *)0L}
1492#else
1493 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1494#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001495 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496 {"imsearch", "ims", P_NUM|P_VI_DEF,
1497 (char_u *)&p_imsearch, PV_IMS,
1498#ifdef B_IMODE_IM
1499 {(char_u *)B_IMODE_IM, (char_u *)0L}
1500#else
1501 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001503 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001504 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001505# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1506 (char_u *)&p_imsf, PV_NONE,
1507 {(char_u *)"", (char_u *)NULL}
1508# else
1509 (char_u *)NULL, PV_NONE,
1510 {(char_u *)NULL, (char_u *)0L}
1511# endif
1512 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1514#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001515 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1517#else
1518 (char_u *)NULL, PV_NONE,
1519 {(char_u *)0L, (char_u *)0L}
1520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1523#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1524 (char_u *)&p_inex, PV_INEX,
1525 {(char_u *)"", (char_u *)0L}
1526#else
1527 (char_u *)NULL, PV_NONE,
1528 {(char_u *)0L, (char_u *)0L}
1529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001530 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1532 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001534 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1535#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1536 (char_u *)&p_inde, PV_INDE,
1537 {(char_u *)"", (char_u *)0L}
1538#else
1539 (char_u *)NULL, PV_NONE,
1540 {(char_u *)0L, (char_u *)0L}
1541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1544#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1545 (char_u *)&p_indk, PV_INDK,
1546 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1547#else
1548 (char_u *)NULL, PV_NONE,
1549 {(char_u *)0L, (char_u *)0L}
1550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001551 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 {"infercase", "inf", P_BOOL|P_VI_DEF,
1553 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1556 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1559 (char_u *)&p_isf, PV_NONE,
1560 {
1561#ifdef BACKSLASH_IN_FILENAME
1562 /* Excluded are: & and ^ are special in cmd.exe
1563 * ( and ) are used in text separating fnames */
1564 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1565#else
1566# ifdef AMIGA
1567 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1568# else
1569# ifdef VMS
1570 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1571# else /* UNIX et al. */
1572# ifdef EBCDIC
1573 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1574# else
1575 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1576# endif
1577# endif
1578# endif
1579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001580 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1582 (char_u *)&p_isi, PV_NONE,
1583 {
1584#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1585 (char_u *)"@,48-57,_,128-167,224-235",
1586#else
1587# ifdef EBCDIC
1588 /* TODO: EBCDIC Check this! @ == isalpha()*/
1589 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1590 "112-120,128,140-142,156,158,172,"
1591 "174,186,191,203-207,219-225,235-239,"
1592 "251-254",
1593# else
1594 (char_u *)"@,48-57,_,192-255",
1595# endif
1596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001597 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1599 (char_u *)&p_isk, PV_ISK,
1600 {
1601#ifdef EBCDIC
1602 (char_u *)"@,240-249,_",
1603 /* TODO: EBCDIC Check this! @ == isalpha()*/
1604 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1605 "112-120,128,140-142,156,158,172,"
1606 "174,186,191,203-207,219-225,235-239,"
1607 "251-254",
1608#else
1609 (char_u *)"@,48-57,_",
1610# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1611 (char_u *)"@,48-57,_,128-167,224-235"
1612# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001613 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614# endif
1615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001616 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1618 (char_u *)&p_isp, PV_NONE,
1619 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001620#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1621 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001622 || defined(VMS)
1623 (char_u *)"@,~-255",
1624#else
1625# ifdef EBCDIC
1626 /* all chars above 63 are printable */
1627 (char_u *)"63-255",
1628# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001629 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630# endif
1631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001632 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1634 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001635 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1637#ifdef FEAT_CRYPT
1638 (char_u *)&p_key, PV_KEY,
1639 {(char_u *)"", (char_u *)0L}
1640#else
1641 (char_u *)NULL, PV_NONE,
1642 {(char_u *)0L, (char_u *)0L}
1643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001644 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001645 {"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 +00001646#ifdef FEAT_KEYMAP
1647 (char_u *)&p_keymap, PV_KMAP,
1648 {(char_u *)"", (char_u *)0L}
1649#else
1650 (char_u *)NULL, PV_NONE,
1651 {(char_u *)"", (char_u *)0L}
1652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001653 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001656 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001658 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {
1660#if defined(MSDOS) || defined(MSWIN)
1661 (char_u *)":help",
1662#else
1663#ifdef VMS
1664 (char_u *)"help",
1665#else
1666# if defined(OS2)
1667 (char_u *)"view /",
1668# else
1669# ifdef USEMAN_S
1670 (char_u *)"man -s",
1671# else
1672 (char_u *)"man",
1673# endif
1674# endif
1675#endif
1676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001677 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaared7547d2014-05-13 12:17:15 +02001678 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679#ifdef FEAT_LANGMAP
1680 (char_u *)&p_langmap, PV_NONE,
1681 {(char_u *)"", /* unmatched } */
1682#else
1683 (char_u *)NULL, PV_NONE,
1684 {(char_u *)NULL,
1685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001686 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001687 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1689 (char_u *)&p_lm, PV_NONE,
1690#else
1691 (char_u *)NULL, PV_NONE,
1692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001693 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1695#ifdef FEAT_WINDOWS
1696 (char_u *)&p_ls, PV_NONE,
1697#else
1698 (char_u *)NULL, PV_NONE,
1699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001700 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1702 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001703 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1705#ifdef FEAT_LINEBREAK
1706 (char_u *)VAR_WIN, PV_LBR,
1707#else
1708 (char_u *)NULL, PV_NONE,
1709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1712 (char_u *)&Rows, PV_NONE,
1713 {
1714#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1715 (char_u *)25L,
1716#else
1717 (char_u *)24L,
1718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1721#ifdef FEAT_GUI
1722 (char_u *)&p_linespace, PV_NONE,
1723#else
1724 (char_u *)NULL, PV_NONE,
1725#endif
1726#ifdef FEAT_GUI_W32
1727 {(char_u *)1L, (char_u *)0L}
1728#else
1729 {(char_u *)0L, (char_u *)0L}
1730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001731 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 {"lisp", NULL, P_BOOL|P_VI_DEF,
1733#ifdef FEAT_LISP
1734 (char_u *)&p_lisp, PV_LISP,
1735#else
1736 (char_u *)NULL, PV_NONE,
1737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001738 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1740#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001741 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1743#else
1744 (char_u *)NULL, PV_NONE,
1745 {(char_u *)"", (char_u *)0L}
1746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1749 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001750 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1752 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001753 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1755 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001757#ifdef FEAT_GUI_MAC
1758 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1759 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001761#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762 {"magic", NULL, P_BOOL|P_VI_DEF,
1763 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001764 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001765 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766#ifdef FEAT_QUICKFIX
1767 (char_u *)&p_mef, PV_NONE,
1768 {(char_u *)"", (char_u *)0L}
1769#else
1770 (char_u *)NULL, PV_NONE,
1771 {(char_u *)NULL, (char_u *)0L}
1772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001773 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1775#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001776 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777# ifdef VMS
1778 {(char_u *)"MMS", (char_u *)0L}
1779# else
1780 {(char_u *)"make", (char_u *)0L}
1781# endif
1782#else
1783 (char_u *)NULL, PV_NONE,
1784 {(char_u *)NULL, (char_u *)0L}
1785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001786 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1788 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001789 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1790 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"matchtime", "mat", P_NUM|P_VI_DEF,
1792 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001794 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001795#ifdef FEAT_MBYTE
1796 (char_u *)&p_mco, PV_NONE,
1797#else
1798 (char_u *)NULL, PV_NONE,
1799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001800 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001801 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1802#ifdef FEAT_EVAL
1803 (char_u *)&p_mfd, PV_NONE,
1804#else
1805 (char_u *)NULL, PV_NONE,
1806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001807 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1809 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 {"maxmem", "mm", P_NUM|P_VI_DEF,
1812 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1814 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001815 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1816 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1819 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1821 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 {"menuitems", "mis", P_NUM|P_VI_DEF,
1823#ifdef FEAT_MENU
1824 (char_u *)&p_mis, PV_NONE,
1825#else
1826 (char_u *)NULL, PV_NONE,
1827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001828 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {"mesg", NULL, P_BOOL|P_VI_DEF,
1830 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001832 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001833#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001834 (char_u *)&p_msm, PV_NONE,
1835 {(char_u *)"460000,2000,500", (char_u *)0L}
1836#else
1837 (char_u *)NULL, PV_NONE,
1838 {(char_u *)0L, (char_u *)0L}
1839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"modeline", "ml", P_BOOL|P_VIM,
1842 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001844 {"modelines", "mls", P_NUM|P_VI_DEF,
1845 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001846 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001847 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1848 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001849 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1851 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"more", NULL, P_BOOL|P_VIM,
1854 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1857 (char_u *)&p_mouse, PV_NONE,
1858 {
1859#if defined(MSDOS) || defined(WIN3264)
1860 (char_u *)"a",
1861#else
1862 (char_u *)"",
1863#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001864 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1866#ifdef FEAT_GUI
1867 (char_u *)&p_mousef, PV_NONE,
1868#else
1869 (char_u *)NULL, PV_NONE,
1870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1873#ifdef FEAT_GUI
1874 (char_u *)&p_mh, PV_NONE,
1875#else
1876 (char_u *)NULL, PV_NONE,
1877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001878 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1880 (char_u *)&p_mousem, PV_NONE,
1881 {
1882#if defined(MSDOS) || defined(MSWIN)
1883 (char_u *)"popup",
1884#else
1885# if defined(MACOS)
1886 (char_u *)"popup_setpos",
1887# else
1888 (char_u *)"extend",
1889# endif
1890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1893#ifdef FEAT_MOUSESHAPE
1894 (char_u *)&p_mouseshape, PV_NONE,
1895 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1896#else
1897 (char_u *)NULL, PV_NONE,
1898 {(char_u *)NULL, (char_u *)0L}
1899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001900 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1902 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001903 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001904 {"mzquantum", "mzq", P_NUM,
1905#ifdef FEAT_MZSCHEME
1906 (char_u *)&p_mzq, PV_NONE,
1907#else
1908 (char_u *)NULL, PV_NONE,
1909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001910 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001911 {"novice", NULL, P_BOOL|P_VI_DEF,
1912 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001913 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1915 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001916 {(char_u *)"octal,hex", (char_u *)0L}
1917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1919 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001921 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1922#ifdef FEAT_LINEBREAK
1923 (char_u *)VAR_WIN, PV_NUW,
1924#else
1925 (char_u *)NULL, PV_NONE,
1926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001928 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001929#ifdef FEAT_COMPL_FUNC
1930 (char_u *)&p_ofu, PV_OFU,
1931 {(char_u *)"", (char_u *)0L}
1932#else
1933 (char_u *)NULL, PV_NONE,
1934 {(char_u *)0L, (char_u *)0L}
1935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001936 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 {"open", NULL, P_BOOL|P_VI_DEF,
1938 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001939 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001940 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1941#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1942 (char_u *)&p_odev, PV_NONE,
1943#else
1944 (char_u *)NULL, PV_NONE,
1945#endif
1946 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001948 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1949 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001950 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951 {"optimize", "opt", P_BOOL|P_VI_DEF,
1952 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001953 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001956 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001957 {"paragraphs", "para", P_STRING|P_VI_DEF,
1958 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001959 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001960 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001961 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1965 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001966 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001967 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1968#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1969 (char_u *)&p_pex, PV_NONE,
1970 {(char_u *)"", (char_u *)0L}
1971#else
1972 (char_u *)NULL, PV_NONE,
1973 {(char_u *)0L, (char_u *)0L}
1974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001975 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001976 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001980 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {
1982#if defined AMIGA || defined MSDOS || defined MSWIN
1983 (char_u *)".,,",
1984#else
1985# if defined(__EMX__)
1986 (char_u *)".,/emx/include,,",
1987# else /* Unix, probably */
1988 (char_u *)".,/usr/include,,",
1989# endif
1990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
1993 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001995 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
1997 (char_u *)&p_pvh, PV_NONE,
1998#else
1999 (char_u *)NULL, PV_NONE,
2000#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002001 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2003#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2004 (char_u *)VAR_WIN, PV_PVW,
2005#else
2006 (char_u *)NULL, PV_NONE,
2007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002008 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002009 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010#ifdef FEAT_PRINTER
2011 (char_u *)&p_pdev, PV_NONE,
2012 {(char_u *)"", (char_u *)0L}
2013#else
2014 (char_u *)NULL, PV_NONE,
2015 {(char_u *)NULL, (char_u *)0L}
2016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002017 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018 {"printencoding", "penc", P_STRING|P_VI_DEF,
2019#ifdef FEAT_POSTSCRIPT
2020 (char_u *)&p_penc, PV_NONE,
2021 {(char_u *)"", (char_u *)0L}
2022#else
2023 (char_u *)NULL, PV_NONE,
2024 {(char_u *)NULL, (char_u *)0L}
2025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002026 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2028#ifdef FEAT_POSTSCRIPT
2029 (char_u *)&p_pexpr, PV_NONE,
2030 {(char_u *)"", (char_u *)0L}
2031#else
2032 (char_u *)NULL, PV_NONE,
2033 {(char_u *)NULL, (char_u *)0L}
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036 {"printfont", "pfn", P_STRING|P_VI_DEF,
2037#ifdef FEAT_PRINTER
2038 (char_u *)&p_pfn, PV_NONE,
2039 {
2040# ifdef MSWIN
2041 (char_u *)"Courier_New:h10",
2042# else
2043 (char_u *)"courier",
2044# endif
2045 (char_u *)0L}
2046#else
2047 (char_u *)NULL, PV_NONE,
2048 {(char_u *)NULL, (char_u *)0L}
2049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002050 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2052#ifdef FEAT_PRINTER
2053 (char_u *)&p_header, PV_NONE,
2054 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2055#else
2056 (char_u *)NULL, PV_NONE,
2057 {(char_u *)NULL, (char_u *)0L}
2058#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002059 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002060 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2061#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2062 (char_u *)&p_pmcs, PV_NONE,
2063 {(char_u *)"", (char_u *)0L}
2064#else
2065 (char_u *)NULL, PV_NONE,
2066 {(char_u *)NULL, (char_u *)0L}
2067#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002068 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002069 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2070#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2071 (char_u *)&p_pmfn, PV_NONE,
2072 {(char_u *)"", (char_u *)0L}
2073#else
2074 (char_u *)NULL, PV_NONE,
2075 {(char_u *)NULL, (char_u *)0L}
2076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2079#ifdef FEAT_PRINTER
2080 (char_u *)&p_popt, PV_NONE,
2081 {(char_u *)"", (char_u *)0L}
2082#else
2083 (char_u *)NULL, PV_NONE,
2084 {(char_u *)NULL, (char_u *)0L}
2085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002088 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002089 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002090 {"pumheight", "ph", P_NUM|P_VI_DEF,
2091#ifdef FEAT_INS_EXPAND
2092 (char_u *)&p_ph, PV_NONE,
2093#else
2094 (char_u *)NULL, PV_NONE,
2095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002097 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2098#ifdef FEAT_TEXTOBJ
2099 (char_u *)&p_qe, PV_QE,
2100 {(char_u *)"\\", (char_u *)0L}
2101#else
2102 (char_u *)NULL, PV_NONE,
2103 {(char_u *)NULL, (char_u *)0L}
2104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002105 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2107 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002108 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109 {"redraw", NULL, P_BOOL|P_VI_DEF,
2110 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002112 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2113#ifdef FEAT_RELTIME
2114 (char_u *)&p_rdt, PV_NONE,
2115#else
2116 (char_u *)NULL, PV_NONE,
2117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002118 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002119 {"regexpengine", "re", P_NUM|P_VI_DEF,
2120 (char_u *)&p_re, PV_NONE,
2121 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002122 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2123 (char_u *)VAR_WIN, PV_RNU,
2124 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125 {"remap", NULL, P_BOOL|P_VI_DEF,
2126 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002127 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002128 {"renderoptions", "rop", P_STRING|P_COMMA|P_RCLR|P_VI_DEF,
2129#ifdef FEAT_RENDER_OPTIONS
2130 (char_u *)&p_rop, PV_NONE,
2131 {(char_u *)"", (char_u *)0L}
2132#else
2133 (char_u *)NULL, PV_NONE,
2134 {(char_u *)NULL, (char_u *)0L}
2135#endif
2136 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002137 {"report", NULL, P_NUM|P_VI_DEF,
2138 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002139 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2141#ifdef WIN3264
2142 (char_u *)&p_rs, PV_NONE,
2143#else
2144 (char_u *)NULL, PV_NONE,
2145#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002146 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2148#ifdef FEAT_RIGHTLEFT
2149 (char_u *)&p_ri, PV_NONE,
2150#else
2151 (char_u *)NULL, PV_NONE,
2152#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002153 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2155#ifdef FEAT_RIGHTLEFT
2156 (char_u *)VAR_WIN, PV_RL,
2157#else
2158 (char_u *)NULL, PV_NONE,
2159#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2162#ifdef FEAT_RIGHTLEFT
2163 (char_u *)VAR_WIN, PV_RLC,
2164 {(char_u *)"search", (char_u *)NULL}
2165#else
2166 (char_u *)NULL, PV_NONE,
2167 {(char_u *)NULL, (char_u *)0L}
2168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2171#ifdef FEAT_CMDL_INFO
2172 (char_u *)&p_ru, PV_NONE,
2173#else
2174 (char_u *)NULL, PV_NONE,
2175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002176 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2178#ifdef FEAT_STL_OPT
2179 (char_u *)&p_ruf, PV_NONE,
2180#else
2181 (char_u *)NULL, PV_NONE,
2182#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002183 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002184 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2185 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002186 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2187 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2189 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002190 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2192#ifdef FEAT_SCROLLBIND
2193 (char_u *)VAR_WIN, PV_SCBIND,
2194#else
2195 (char_u *)NULL, PV_NONE,
2196#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002197 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002198 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2199 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002200 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002201 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2202 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002203 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002204 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2205#ifdef FEAT_SCROLLBIND
2206 (char_u *)&p_sbo, PV_NONE,
2207 {(char_u *)"ver,jump", (char_u *)0L}
2208#else
2209 (char_u *)NULL, PV_NONE,
2210 {(char_u *)0L, (char_u *)0L}
2211#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002212 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002213 {"sections", "sect", P_STRING|P_VI_DEF,
2214 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002215 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2216 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2218 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002219 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002220 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002221 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 {(char_u *)"inclusive", (char_u *)0L}
2223 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002225 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002226 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002227 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2228#ifdef FEAT_SESSION
2229 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002230 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 (char_u *)0L}
2232#else
2233 (char_u *)NULL, PV_NONE,
2234 {(char_u *)0L, (char_u *)0L}
2235#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2238 (char_u *)&p_sh, PV_NONE,
2239 {
2240#ifdef VMS
2241 (char_u *)"-",
2242#else
2243# if defined(MSDOS)
2244 (char_u *)"command",
2245# else
2246# if defined(WIN16)
2247 (char_u *)"command.com",
2248# else
2249# if defined(WIN3264)
2250 (char_u *)"", /* set in set_init_1() */
2251# else
2252# if defined(OS2)
2253 (char_u *)"cmd.exe",
2254# else
2255# if defined(ARCHIE)
2256 (char_u *)"gos",
2257# else
2258 (char_u *)"sh",
2259# endif
2260# endif
2261# endif
2262# endif
2263# endif
2264#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2267 (char_u *)&p_shcf, PV_NONE,
2268 {
2269#if defined(MSDOS) || defined(MSWIN)
2270 (char_u *)"/c",
2271#else
2272# if defined(OS2)
2273 (char_u *)"/c",
2274# else
2275 (char_u *)"-c",
2276# endif
2277#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002278 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2280#ifdef FEAT_QUICKFIX
2281 (char_u *)&p_sp, PV_NONE,
2282 {
2283#if defined(UNIX) || defined(OS2)
2284# ifdef ARCHIE
2285 (char_u *)"2>",
2286# else
2287 (char_u *)"| tee",
2288# endif
2289#else
2290 (char_u *)">",
2291#endif
2292 (char_u *)0L}
2293#else
2294 (char_u *)NULL, PV_NONE,
2295 {(char_u *)0L, (char_u *)0L}
2296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2299 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002300 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2302 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002303 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2305#ifdef BACKSLASH_IN_FILENAME
2306 (char_u *)&p_ssl, PV_NONE,
2307#else
2308 (char_u *)NULL, PV_NONE,
2309#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002311 {"shelltemp", "stmp", P_BOOL,
2312 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002313 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"shelltype", "st", P_NUM|P_VI_DEF,
2315#ifdef AMIGA
2316 (char_u *)&p_st, PV_NONE,
2317#else
2318 (char_u *)NULL, PV_NONE,
2319#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002320 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2322 (char_u *)&p_sxq, PV_NONE,
2323 {
2324#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2325 (char_u *)"\"",
2326#else
2327 (char_u *)"",
2328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002330 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2331 (char_u *)&p_sxe, PV_NONE,
2332 {
2333#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2334 (char_u *)"\"&|<>()@^",
2335#else
2336 (char_u *)"",
2337#endif
2338 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2340 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002341 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002342 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2343 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002344 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002345 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2346 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002347 {(char_u *)"", (char_u *)"filnxtToO"}
2348 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"shortname", "sn", P_BOOL|P_VI_DEF,
2350#ifdef SHORT_FNAME
2351 (char_u *)NULL, PV_NONE,
2352#else
2353 (char_u *)&p_sn, PV_SN,
2354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002355 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2357#ifdef FEAT_LINEBREAK
2358 (char_u *)&p_sbr, PV_NONE,
2359#else
2360 (char_u *)NULL, PV_NONE,
2361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"showcmd", "sc", P_BOOL|P_VIM,
2364#ifdef FEAT_CMDL_INFO
2365 (char_u *)&p_sc, PV_NONE,
2366#else
2367 (char_u *)NULL, PV_NONE,
2368#endif
2369 {(char_u *)FALSE,
2370#ifdef UNIX
2371 (char_u *)FALSE
2372#else
2373 (char_u *)TRUE
2374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2377 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2380 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"showmode", "smd", P_BOOL|P_VIM,
2383 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002385 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2386#ifdef FEAT_WINDOWS
2387 (char_u *)&p_stal, PV_NONE,
2388#else
2389 (char_u *)NULL, PV_NONE,
2390#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2393 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2396 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002397 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2399 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002400 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2402 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2405#ifdef FEAT_SMARTINDENT
2406 (char_u *)&p_si, PV_SI,
2407#else
2408 (char_u *)NULL, PV_NONE,
2409#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2412 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2415 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2418 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002419 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002420 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002421#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002422 (char_u *)VAR_WIN, PV_SPELL,
2423#else
2424 (char_u *)NULL, PV_NONE,
2425#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002426 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002427 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002428#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002429 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002430 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002431#else
2432 (char_u *)NULL, PV_NONE,
2433 {(char_u *)0L, (char_u *)0L}
2434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002436 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002437#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002438 (char_u *)&p_spf, PV_SPF,
2439 {(char_u *)"", (char_u *)0L}
2440#else
2441 (char_u *)NULL, PV_NONE,
2442 {(char_u *)0L, (char_u *)0L}
2443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002445 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002446#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002447 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002448 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002449#else
2450 (char_u *)NULL, PV_NONE,
2451 {(char_u *)0L, (char_u *)0L}
2452#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002454 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002455#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002456 (char_u *)&p_sps, PV_NONE,
2457 {(char_u *)"best", (char_u *)0L}
2458#else
2459 (char_u *)NULL, PV_NONE,
2460 {(char_u *)0L, (char_u *)0L}
2461#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002462 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002463 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2464#ifdef FEAT_WINDOWS
2465 (char_u *)&p_sb, PV_NONE,
2466#else
2467 (char_u *)NULL, PV_NONE,
2468#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"splitright", "spr", P_BOOL|P_VI_DEF,
2471#ifdef FEAT_VERTSPLIT
2472 (char_u *)&p_spr, PV_NONE,
2473#else
2474 (char_u *)NULL, PV_NONE,
2475#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2478 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002479 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2481#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002482 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483#else
2484 (char_u *)NULL, PV_NONE,
2485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2488 (char_u *)&p_su, PV_NONE,
2489 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002490 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002492#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 (char_u *)&p_sua, PV_SUA,
2494 {(char_u *)"", (char_u *)0L}
2495#else
2496 (char_u *)NULL, PV_NONE,
2497 {(char_u *)0L, (char_u *)0L}
2498#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002499 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2501 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002502 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 {"swapsync", "sws", P_STRING|P_VI_DEF,
2504 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2507 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002509 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2510#ifdef FEAT_SYN_HL
2511 (char_u *)&p_smc, PV_SMC,
2512 {(char_u *)3000L, (char_u *)0L}
2513#else
2514 (char_u *)NULL, PV_NONE,
2515 {(char_u *)0L, (char_u *)0L}
2516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002517 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002518 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519#ifdef FEAT_SYN_HL
2520 (char_u *)&p_syn, PV_SYN,
2521 {(char_u *)"", (char_u *)0L}
2522#else
2523 (char_u *)NULL, PV_NONE,
2524 {(char_u *)0L, (char_u *)0L}
2525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002527 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2528#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002529 (char_u *)&p_tal, PV_NONE,
2530#else
2531 (char_u *)NULL, PV_NONE,
2532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002534 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2535#ifdef FEAT_WINDOWS
2536 (char_u *)&p_tpm, PV_NONE,
2537#else
2538 (char_u *)NULL, PV_NONE,
2539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2542 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2545 (char_u *)&p_tbs, PV_NONE,
2546#ifdef VMS /* binary searching doesn't appear to work on VMS */
2547 {(char_u *)0L, (char_u *)0L}
2548#else
2549 {(char_u *)TRUE, (char_u *)0L}
2550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002551 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552 {"taglength", "tl", P_NUM|P_VI_DEF,
2553 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002554 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555 {"tagrelative", "tr", P_BOOL|P_VIM,
2556 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002559 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {
2561#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2562 (char_u *)"./tags,./TAGS,tags,TAGS",
2563#else
2564 (char_u *)"./tags,tags",
2565#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2568 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2571 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2574#ifdef FEAT_ARABIC
2575 (char_u *)&p_tbidi, PV_NONE,
2576#else
2577 (char_u *)NULL, PV_NONE,
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2581#ifdef FEAT_MBYTE
2582 (char_u *)&p_tenc, PV_NONE,
2583 {(char_u *)"", (char_u *)0L}
2584#else
2585 (char_u *)NULL, PV_NONE,
2586 {(char_u *)0L, (char_u *)0L}
2587#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589 {"terse", NULL, P_BOOL|P_VI_DEF,
2590 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 {"textauto", "ta", P_BOOL|P_VIM,
2593 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2595 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2597 (char_u *)&p_tx, PV_TX,
2598 {
2599#ifdef USE_CRNL
2600 (char_u *)TRUE,
2601#else
2602 (char_u *)FALSE,
2603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002604 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002605 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2609#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002610 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611#else
2612 (char_u *)NULL, PV_NONE,
2613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2616 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"timeout", "to", P_BOOL|P_VI_DEF,
2619 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2622 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"title", NULL, P_BOOL|P_VI_DEF,
2625#ifdef FEAT_TITLE
2626 (char_u *)&p_title, PV_NONE,
2627#else
2628 (char_u *)NULL, PV_NONE,
2629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002630 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"titlelen", NULL, P_NUM|P_VI_DEF,
2632#ifdef FEAT_TITLE
2633 (char_u *)&p_titlelen, PV_NONE,
2634#else
2635 (char_u *)NULL, PV_NONE,
2636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002638 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639#ifdef FEAT_TITLE
2640 (char_u *)&p_titleold, PV_NONE,
2641 {(char_u *)N_("Thanks for flying Vim"),
2642 (char_u *)0L}
2643#else
2644 (char_u *)NULL, PV_NONE,
2645 {(char_u *)0L, (char_u *)0L}
2646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"titlestring", NULL, P_STRING|P_VI_DEF,
2649#ifdef FEAT_TITLE
2650 (char_u *)&p_titlestring, PV_NONE,
2651#else
2652 (char_u *)NULL, PV_NONE,
2653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2656 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2657 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 {(char_u *)"icons,tooltips", (char_u *)0L}
2659 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002661#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2663 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665#endif
2666 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2667 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002668 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2670 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2673 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002674 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2676 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2679#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2680 (char_u *)&p_ttym, PV_NONE,
2681#else
2682 (char_u *)NULL, PV_NONE,
2683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2686 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2689 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002691 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2692#ifdef FEAT_PERSISTENT_UNDO
2693 (char_u *)&p_udir, PV_NONE,
2694 {(char_u *)".", (char_u *)0L}
2695#else
2696 (char_u *)NULL, PV_NONE,
2697 {(char_u *)0L, (char_u *)0L}
2698#endif
2699 SCRIPTID_INIT},
2700 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2701#ifdef FEAT_PERSISTENT_UNDO
2702 (char_u *)&p_udf, PV_UDF,
2703#else
2704 (char_u *)NULL, PV_NONE,
2705#endif
2706 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002708 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {
2710#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2711 (char_u *)1000L,
2712#else
2713 (char_u *)100L,
2714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002716 {"undoreload", "ur", P_NUM|P_VI_DEF,
2717 (char_u *)&p_ur, PV_NONE,
2718 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 {"updatecount", "uc", P_NUM|P_VI_DEF,
2720 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"updatetime", "ut", P_NUM|P_VI_DEF,
2723 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"verbose", "vbs", P_NUM|P_VI_DEF,
2726 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002728 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2729 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2732#ifdef FEAT_SESSION
2733 (char_u *)&p_vdir, PV_NONE,
2734 {(char_u *)DFLT_VDIR, (char_u *)0L}
2735#else
2736 (char_u *)NULL, PV_NONE,
2737 {(char_u *)0L, (char_u *)0L}
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2741#ifdef FEAT_SESSION
2742 (char_u *)&p_vop, PV_NONE,
2743 {(char_u *)"folds,options,cursor", (char_u *)0L}
2744#else
2745 (char_u *)NULL, PV_NONE,
2746 {(char_u *)0L, (char_u *)0L}
2747#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002748 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002749 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2750#ifdef FEAT_VIMINFO
2751 (char_u *)&p_viminfo, PV_NONE,
2752#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002753 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754#else
2755# ifdef AMIGA
2756 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002757 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002758# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002759 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760# endif
2761#endif
2762#else
2763 (char_u *)NULL, PV_NONE,
2764 {(char_u *)0L, (char_u *)0L}
2765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002767 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768#ifdef FEAT_VIRTUALEDIT
2769 (char_u *)&p_ve, PV_NONE,
2770 {(char_u *)"", (char_u *)""}
2771#else
2772 (char_u *)NULL, PV_NONE,
2773 {(char_u *)0L, (char_u *)0L}
2774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2777 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002778 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 {"w300", NULL, P_NUM|P_VI_DEF,
2780 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002781 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 {"w1200", NULL, P_NUM|P_VI_DEF,
2783 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785 {"w9600", NULL, P_NUM|P_VI_DEF,
2786 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002787 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 {"warn", NULL, P_BOOL|P_VI_DEF,
2789 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002790 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2792 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002793 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2795 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 {"wildchar", "wc", P_NUM|P_VIM,
2798 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2800 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002801 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002803 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2805#ifdef FEAT_WILDIGN
2806 (char_u *)&p_wig, PV_NONE,
2807#else
2808 (char_u *)NULL, PV_NONE,
2809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002811 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2812 (char_u *)&p_wic, PV_NONE,
2813 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2815#ifdef FEAT_WILDMENU
2816 (char_u *)&p_wmnu, PV_NONE,
2817#else
2818 (char_u *)NULL, PV_NONE,
2819#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002820 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2822 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002823 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002824 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2825#ifdef FEAT_CMDL_COMPL
2826 (char_u *)&p_wop, PV_NONE,
2827 {(char_u *)"", (char_u *)0L}
2828#else
2829 (char_u *)NULL, PV_NONE,
2830 {(char_u *)NULL, (char_u *)0L}
2831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2834#ifdef FEAT_WAK
2835 (char_u *)&p_wak, PV_NONE,
2836 {(char_u *)"menu", (char_u *)0L}
2837#else
2838 (char_u *)NULL, PV_NONE,
2839 {(char_u *)NULL, (char_u *)0L}
2840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002841 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002843 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002844 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 {"winheight", "wh", P_NUM|P_VI_DEF,
2846#ifdef FEAT_WINDOWS
2847 (char_u *)&p_wh, PV_NONE,
2848#else
2849 (char_u *)NULL, PV_NONE,
2850#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002851 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002853#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 (char_u *)VAR_WIN, PV_WFH,
2855#else
2856 (char_u *)NULL, PV_NONE,
2857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002859 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2860#ifdef FEAT_VERTSPLIT
2861 (char_u *)VAR_WIN, PV_WFW,
2862#else
2863 (char_u *)NULL, PV_NONE,
2864#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002865 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2867#ifdef FEAT_WINDOWS
2868 (char_u *)&p_wmh, PV_NONE,
2869#else
2870 (char_u *)NULL, PV_NONE,
2871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2874#ifdef FEAT_VERTSPLIT
2875 (char_u *)&p_wmw, PV_NONE,
2876#else
2877 (char_u *)NULL, PV_NONE,
2878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2881#ifdef FEAT_VERTSPLIT
2882 (char_u *)&p_wiw, PV_NONE,
2883#else
2884 (char_u *)NULL, PV_NONE,
2885#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2888 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002889 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2891 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002892 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2894 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002895 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896 {"write", NULL, P_BOOL|P_VI_DEF,
2897 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002898 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 {"writeany", "wa", P_BOOL|P_VI_DEF,
2900 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002902 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2903 (char_u *)&p_wb, PV_NONE,
2904 {
2905#ifdef FEAT_WRITEBACKUP
2906 (char_u *)TRUE,
2907#else
2908 (char_u *)FALSE,
2909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002910 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {"writedelay", "wd", P_NUM|P_VI_DEF,
2912 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002913 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914
2915/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002916#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002918 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919
2920 p_term("t_AB", T_CAB)
2921 p_term("t_AF", T_CAF)
2922 p_term("t_AL", T_CAL)
2923 p_term("t_al", T_AL)
2924 p_term("t_bc", T_BC)
2925 p_term("t_cd", T_CD)
2926 p_term("t_ce", T_CE)
2927 p_term("t_cl", T_CL)
2928 p_term("t_cm", T_CM)
2929 p_term("t_Co", T_CCO)
2930 p_term("t_CS", T_CCS)
2931 p_term("t_cs", T_CS)
2932#ifdef FEAT_VERTSPLIT
2933 p_term("t_CV", T_CSV)
2934#endif
2935 p_term("t_ut", T_UT)
2936 p_term("t_da", T_DA)
2937 p_term("t_db", T_DB)
2938 p_term("t_DL", T_CDL)
2939 p_term("t_dl", T_DL)
2940 p_term("t_fs", T_FS)
2941 p_term("t_IE", T_CIE)
2942 p_term("t_IS", T_CIS)
2943 p_term("t_ke", T_KE)
2944 p_term("t_ks", T_KS)
2945 p_term("t_le", T_LE)
2946 p_term("t_mb", T_MB)
2947 p_term("t_md", T_MD)
2948 p_term("t_me", T_ME)
2949 p_term("t_mr", T_MR)
2950 p_term("t_ms", T_MS)
2951 p_term("t_nd", T_ND)
2952 p_term("t_op", T_OP)
2953 p_term("t_RI", T_CRI)
2954 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002955 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 p_term("t_Sb", T_CSB)
2957 p_term("t_Sf", T_CSF)
2958 p_term("t_se", T_SE)
2959 p_term("t_so", T_SO)
2960 p_term("t_sr", T_SR)
2961 p_term("t_ts", T_TS)
2962 p_term("t_te", T_TE)
2963 p_term("t_ti", T_TI)
2964 p_term("t_ue", T_UE)
2965 p_term("t_us", T_US)
2966 p_term("t_vb", T_VB)
2967 p_term("t_ve", T_VE)
2968 p_term("t_vi", T_VI)
2969 p_term("t_vs", T_VS)
2970 p_term("t_WP", T_CWP)
2971 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002972 p_term("t_SI", T_CSI)
2973 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 p_term("t_xs", T_XS)
2975 p_term("t_ZH", T_CZH)
2976 p_term("t_ZR", T_CZR)
2977
2978/* terminal key codes are not in here */
2979
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002980 /* end marker */
2981 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982};
2983
2984#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2985
2986#ifdef FEAT_MBYTE
2987static char *(p_ambw_values[]) = {"single", "double", NULL};
2988#endif
2989static char *(p_bg_values[]) = {"light", "dark", NULL};
2990static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2991static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002992#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02002993static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002994#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002995#ifdef FEAT_CMDL_COMPL
2996static char *(p_wop_values[]) = {"tagfile", NULL};
2997#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998#ifdef FEAT_WAK
2999static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3000#endif
3001static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3003static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005#ifdef FEAT_BROWSE
3006static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3007#endif
3008#ifdef FEAT_SCROLLBIND
3009static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3010#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003011static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012#ifdef FEAT_VERTSPLIT
3013static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3014#endif
3015#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003016# ifdef FEAT_AUTOCMD
3017static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3018# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003020# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3022#endif
3023static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3024#ifdef FEAT_FOLDING
3025static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003026# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003028# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 NULL};
3030static char *(p_fcl_values[]) = {"all", NULL};
3031#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003032#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003033static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003034#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035
3036static void set_option_default __ARGS((int, int opt_flags, int compatible));
3037static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003038static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003039static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040static char_u *illegal_char __ARGS((char_u *, int));
3041static int string_to_key __ARGS((char_u *arg));
3042#ifdef FEAT_CMDWIN
3043static char_u *check_cedit __ARGS((void));
3044#endif
3045#ifdef FEAT_TITLE
3046static void did_set_title __ARGS((int icon));
3047#endif
3048static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3049static void didset_options __ARGS((void));
3050static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003051#if defined(FEAT_EVAL) || defined(PROTO)
3052static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3053#else
3054# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3055#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003057static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058static 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));
3059static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003060#ifdef FEAT_SYN_HL
3061static int int_cmp __ARGS((const void *a, const void *b));
3062#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063#ifdef FEAT_CLIPBOARD
3064static char_u *check_clipboard_option __ARGS((void));
3065#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003066#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003067static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003068#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003069#ifdef FEAT_EVAL
3070static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003073static 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 +00003074static void check_redraw __ARGS((long_u flags));
3075static int findoption __ARGS((char_u *));
3076static int find_key_option __ARGS((char_u *));
3077static void showoptions __ARGS((int all, int opt_flags));
3078static int optval_default __ARGS((struct vimoption *, char_u *varp));
3079static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3080static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3081static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3082static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3083static int istermoption __ARGS((struct vimoption *));
3084static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3085static char_u *get_varp __ARGS((struct vimoption *));
3086static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003087static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3089#ifdef FEAT_LANGMAP
3090static void langmap_init __ARGS((void));
3091static void langmap_set __ARGS((void));
3092#endif
3093static void paste_option_changed __ARGS((void));
3094static void compatible_set __ARGS((void));
3095#ifdef FEAT_LINEBREAK
3096static void fill_breakat_flags __ARGS((void));
3097#endif
3098static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3099static int check_opt_strings __ARGS((char_u *val, char **values, int));
3100static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003101#ifdef FEAT_LINEBREAK
3102static int briopt_check __ARGS((win_T *wp));
3103#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104
3105/*
3106 * Initialize the options, first part.
3107 *
3108 * Called only once from main(), just after creating the first buffer.
3109 */
3110 void
3111set_init_1()
3112{
3113 char_u *p;
3114 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003115 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116
3117#ifdef FEAT_LANGMAP
3118 langmap_init();
3119#endif
3120
3121 /* Be Vi compatible by default */
3122 p_cp = TRUE;
3123
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003124 /* Use POSIX compatibility when $VIM_POSIX is set. */
3125 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003126 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003127 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003128 set_string_default("shm", (char_u *)"A");
3129 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003130
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 /*
3132 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003133 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003135 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3137# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003138 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003140 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003142 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143# endif
3144#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003145 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 set_string_default("sh", p);
3147
3148#ifdef FEAT_WILDIGN
3149 /*
3150 * Set the default for 'backupskip' to include environment variables for
3151 * temp files.
3152 */
3153 {
3154# ifdef UNIX
3155 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3156# else
3157 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3158# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003159 int len;
3160 garray_T ga;
3161 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162
3163 ga_init2(&ga, 1, 100);
3164 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3165 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003166 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167# ifdef UNIX
3168 if (*names[n] == NUL)
3169 p = (char_u *)"/tmp";
3170 else
3171# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003172 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 if (p != NULL && *p != NUL)
3174 {
3175 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003176 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 if (ga_grow(&ga, len) == OK)
3178 {
3179 if (ga.ga_len > 0)
3180 STRCAT(ga.ga_data, ",");
3181 STRCAT(ga.ga_data, p);
3182 add_pathsep(ga.ga_data);
3183 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184 ga.ga_len += len;
3185 }
3186 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003187 if (mustfree)
3188 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 }
3190 if (ga.ga_data != NULL)
3191 {
3192 set_string_default("bsk", ga.ga_data);
3193 vim_free(ga.ga_data);
3194 }
3195 }
3196#endif
3197
3198 /*
3199 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3200 */
3201 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003202 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003204#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3205 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3206#endif
3207 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003209 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003210 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211#else
3212# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003213 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003214 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003216 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003217# endif
3218#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003220 opt_idx = findoption((char_u *)"maxmem");
3221 if (opt_idx >= 0)
3222 {
3223#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003224 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003225 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3226#endif
3227 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3228 }
3229 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230 }
3231
3232#ifdef FEAT_GUI_W32
3233 /* force 'shortname' for Win32s */
3234 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003235 {
3236 opt_idx = findoption((char_u *)"shortname");
3237 if (opt_idx >= 0)
3238 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3239 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240#endif
3241
3242#ifdef FEAT_SEARCHPATH
3243 {
3244 char_u *cdpath;
3245 char_u *buf;
3246 int i;
3247 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003248 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249
3250 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003251 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252 if (cdpath != NULL)
3253 {
3254 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3255 if (buf != NULL)
3256 {
3257 buf[0] = ','; /* start with ",", current dir first */
3258 j = 1;
3259 for (i = 0; cdpath[i] != NUL; ++i)
3260 {
3261 if (vim_ispathlistsep(cdpath[i]))
3262 buf[j++] = ',';
3263 else
3264 {
3265 if (cdpath[i] == ' ' || cdpath[i] == ',')
3266 buf[j++] = '\\';
3267 buf[j++] = cdpath[i];
3268 }
3269 }
3270 buf[j] = NUL;
3271 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003272 if (opt_idx >= 0)
3273 {
3274 options[opt_idx].def_val[VI_DEFAULT] = buf;
3275 options[opt_idx].flags |= P_DEF_ALLOCED;
3276 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003277 else
3278 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003280 if (mustfree)
3281 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282 }
3283 }
3284#endif
3285
3286#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3287 /* Set print encoding on platforms that don't default to latin1 */
3288 set_string_default("penc",
3289# if defined(MSWIN) || defined(OS2)
3290 (char_u *)"cp1252"
3291# else
3292# ifdef VMS
3293 (char_u *)"dec-mcs"
3294# else
3295# ifdef EBCDIC
3296 (char_u *)"ebcdic-uk"
3297# else
3298# ifdef MAC
3299 (char_u *)"mac-roman"
3300# else /* HPUX */
3301 (char_u *)"hp-roman8"
3302# endif
3303# endif
3304# endif
3305# endif
3306 );
3307#endif
3308
3309#ifdef FEAT_POSTSCRIPT
3310 /* 'printexpr' must be allocated to be able to evaluate it. */
3311 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003312# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3313 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314# else
3315# ifdef VMS
3316 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3317
3318# else
3319 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3320# endif
3321# endif
3322 );
3323#endif
3324
3325 /*
3326 * Set all the options (except the terminal options) to their default
3327 * value. Also set the global value for local options.
3328 */
3329 set_options_default(0);
3330
3331#ifdef FEAT_GUI
3332 if (found_reverse_arg)
3333 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3334#endif
3335
3336 curbuf->b_p_initialized = TRUE;
3337 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003338 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339 check_buf_options(curbuf);
3340 check_win_options(curwin);
3341 check_options();
3342
3343 /* Must be before option_expand(), because that one needs vim_isIDc() */
3344 didset_options();
3345
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003346#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003347 /* Use the current chartab for the generic chartab. */
3348 init_spell_chartab();
3349#endif
3350
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351#ifdef FEAT_LINEBREAK
3352 /*
3353 * initialize the table for 'breakat'.
3354 */
3355 fill_breakat_flags();
3356#endif
3357
3358 /*
3359 * Expand environment variables and things like "~" for the defaults.
3360 * If option_expand() returns non-NULL the variable is expanded. This can
3361 * only happen for non-indirect options.
3362 * Also set the default to the expanded value, so ":set" does not list
3363 * them.
3364 * Don't set the P_ALLOCED flag, because we don't want to free the
3365 * default.
3366 */
3367 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3368 {
3369 if ((options[opt_idx].flags & P_GETTEXT)
3370 && options[opt_idx].var != NULL)
3371 p = (char_u *)_(*(char **)options[opt_idx].var);
3372 else
3373 p = option_expand(opt_idx, NULL);
3374 if (p != NULL && (p = vim_strsave(p)) != NULL)
3375 {
3376 *(char_u **)options[opt_idx].var = p;
3377 /* VIMEXP
3378 * Defaults for all expanded options are currently the same for Vi
3379 * and Vim. When this changes, add some code here! Also need to
3380 * split P_DEF_ALLOCED in two.
3381 */
3382 if (options[opt_idx].flags & P_DEF_ALLOCED)
3383 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3384 options[opt_idx].def_val[VI_DEFAULT] = p;
3385 options[opt_idx].flags |= P_DEF_ALLOCED;
3386 }
3387 }
3388
3389 /* Initialize the highlight_attr[] table. */
3390 highlight_changed();
3391
3392 save_file_ff(curbuf); /* Buffer is unchanged */
3393
3394 /* Parse default for 'wildmode' */
3395 check_opt_wim();
3396
3397#if defined(FEAT_ARABIC)
3398 /* Detect use of mlterm.
3399 * Mlterm is a terminal emulator akin to xterm that has some special
3400 * abilities (bidi namely).
3401 * NOTE: mlterm's author is being asked to 'set' a variable
3402 * instead of an environment variable due to inheritance.
3403 */
3404 if (mch_getenv((char_u *)"MLTERM") != NULL)
3405 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3406#endif
3407
3408#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3409 /* Parse default for 'fillchars'. */
3410 (void)set_chars_option(&p_fcs);
3411#endif
3412
3413#ifdef FEAT_CLIPBOARD
3414 /* Parse default for 'clipboard' */
3415 (void)check_clipboard_option();
3416#endif
3417
3418#ifdef FEAT_MBYTE
3419# if defined(WIN3264) && defined(FEAT_GETTEXT)
3420 /*
3421 * If $LANG isn't set, try to get a good value for it. This makes the
3422 * right language be used automatically. Don't do this for English.
3423 */
3424 if (mch_getenv((char_u *)"LANG") == NULL)
3425 {
3426 char buf[20];
3427
3428 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3429 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3430 * only the first two. */
3431 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3432 (LPTSTR)buf, 20);
3433 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3434 {
3435 /* There are a few exceptions (probably more) */
3436 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3437 STRCPY(buf, "zh_TW");
3438 else if (STRNICMP(buf, "chs", 3) == 0
3439 || STRNICMP(buf, "zhc", 3) == 0)
3440 STRCPY(buf, "zh_CN");
3441 else if (STRNICMP(buf, "jp", 2) == 0)
3442 STRCPY(buf, "ja");
3443 else
3444 buf[2] = NUL; /* truncate to two-letter code */
3445 vim_setenv("LANG", buf);
3446 }
3447 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003448# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003449# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003450 /* Moved to os_mac_conv.c to avoid dependency problems. */
3451 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003452# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453# endif
3454
3455 /* enc_locale() will try to find the encoding of the current locale. */
3456 p = enc_locale();
3457 if (p != NULL)
3458 {
3459 char_u *save_enc;
3460
3461 /* Try setting 'encoding' and check if the value is valid.
3462 * If not, go back to the default "latin1". */
3463 save_enc = p_enc;
3464 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003465 if (STRCMP(p_enc, "gb18030") == 0)
3466 {
3467 /* We don't support "gb18030", but "cp936" is a good substitute
3468 * for practical purposes, thus use that. It's not an alias to
3469 * still support conversion between gb18030 and utf-8. */
3470 p_enc = vim_strsave((char_u *)"cp936");
3471 vim_free(p);
3472 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003473 if (mb_init() == NULL)
3474 {
3475 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003476 if (opt_idx >= 0)
3477 {
3478 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3479 options[opt_idx].flags |= P_DEF_ALLOCED;
3480 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003481
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003482#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3483 || defined(VMS)
3484 if (STRCMP(p_enc, "latin1") == 0
3485# ifdef FEAT_MBYTE
3486 || enc_utf8
3487# endif
3488 )
3489 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003490 /* Adjust the default for 'isprint' and 'iskeyword' to match
3491 * latin1. Also set the defaults for when 'nocompatible' is
3492 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003493 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003494 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003495 set_string_option_direct((char_u *)"isk", -1,
3496 ISK_LATIN1, OPT_FREE, SID_NONE);
3497 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003498 if (opt_idx >= 0)
3499 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003500 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003501 if (opt_idx >= 0)
3502 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003503 (void)init_chartab();
3504 }
3505#endif
3506
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507# if defined(WIN3264) && !defined(FEAT_GUI)
3508 /* Win32 console: When GetACP() returns a different value from
3509 * GetConsoleCP() set 'termencoding'. */
3510 if (GetACP() != GetConsoleCP())
3511 {
3512 char buf[50];
3513
3514 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3515 p_tenc = vim_strsave((char_u *)buf);
3516 if (p_tenc != NULL)
3517 {
3518 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003519 if (opt_idx >= 0)
3520 {
3521 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3522 options[opt_idx].flags |= P_DEF_ALLOCED;
3523 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524 convert_setup(&input_conv, p_tenc, p_enc);
3525 convert_setup(&output_conv, p_enc, p_tenc);
3526 }
3527 else
3528 p_tenc = empty_option;
3529 }
3530# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003531# if defined(WIN3264) && defined(FEAT_MBYTE)
3532 /* $HOME may have characters in active code page. */
3533 init_homedir();
3534# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003535 }
3536 else
3537 {
3538 vim_free(p_enc);
3539 p_enc = save_enc;
3540 }
3541 }
3542#endif
3543
3544#ifdef FEAT_MULTI_LANG
3545 /* Set the default for 'helplang'. */
3546 set_helplang_default(get_mess_lang());
3547#endif
3548}
3549
3550/*
3551 * Set an option to its default value.
3552 * This does not take care of side effects!
3553 */
3554 static void
3555set_option_default(opt_idx, opt_flags, compatible)
3556 int opt_idx;
3557 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3558 int compatible; /* use Vi default value */
3559{
3560 char_u *varp; /* pointer to variable for current option */
3561 int dvi; /* index in def_val[] */
3562 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003563 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3565
3566 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3567 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003568 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003569 {
3570 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3571 if (flags & P_STRING)
3572 {
3573 /* Use set_string_option_direct() for local options to handle
3574 * freeing and allocating the value. */
3575 if (options[opt_idx].indir != PV_NONE)
3576 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003577 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003578 else
3579 {
3580 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3581 free_string_option(*(char_u **)(varp));
3582 *(char_u **)varp = options[opt_idx].def_val[dvi];
3583 options[opt_idx].flags &= ~P_ALLOCED;
3584 }
3585 }
3586 else if (flags & P_NUM)
3587 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003588 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003589 win_comp_scroll(curwin);
3590 else
3591 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003592 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 /* May also set global value for local option. */
3594 if (both)
3595 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3596 *(long *)varp;
3597 }
3598 }
3599 else /* P_BOOL */
3600 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003601 /* the cast to long is required for Manx C, long_i is needed for
3602 * MSVC */
3603 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003604#ifdef UNIX
3605 /* 'modeline' defaults to off for root */
3606 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3607 *(int *)varp = FALSE;
3608#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003609 /* May also set global value for local option. */
3610 if (both)
3611 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3612 *(int *)varp;
3613 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003614
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003615 /* The default value is not insecure. */
3616 flagsp = insecure_flag(opt_idx, opt_flags);
3617 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 }
3619
3620#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003621 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622#endif
3623}
3624
3625/*
3626 * Set all options (except terminal options) to their default value.
3627 */
3628 static void
3629set_options_default(opt_flags)
3630 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3631{
3632 int i;
3633#ifdef FEAT_WINDOWS
3634 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003635 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636#endif
3637
3638 for (i = 0; !istermoption(&options[i]); i++)
3639 if (!(options[i].flags & P_NODEFAULT))
3640 set_option_default(i, opt_flags, p_cp);
3641
3642#ifdef FEAT_WINDOWS
3643 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003644 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003645 win_comp_scroll(wp);
3646#else
3647 win_comp_scroll(curwin);
3648#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003649#ifdef FEAT_CINDENT
3650 parse_cino(curbuf);
3651#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652}
3653
3654/*
3655 * Set the Vi-default value of a string option.
3656 * Used for 'sh', 'backupskip' and 'term'.
3657 */
3658 void
3659set_string_default(name, val)
3660 char *name;
3661 char_u *val;
3662{
3663 char_u *p;
3664 int opt_idx;
3665
3666 p = vim_strsave(val);
3667 if (p != NULL) /* we don't want a NULL */
3668 {
3669 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003670 if (opt_idx >= 0)
3671 {
3672 if (options[opt_idx].flags & P_DEF_ALLOCED)
3673 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3674 options[opt_idx].def_val[VI_DEFAULT] = p;
3675 options[opt_idx].flags |= P_DEF_ALLOCED;
3676 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677 }
3678}
3679
3680/*
3681 * Set the Vi-default value of a number option.
3682 * Used for 'lines' and 'columns'.
3683 */
3684 void
3685set_number_default(name, val)
3686 char *name;
3687 long val;
3688{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003689 int opt_idx;
3690
3691 opt_idx = findoption((char_u *)name);
3692 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003693 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694}
3695
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003696#if defined(EXITFREE) || defined(PROTO)
3697/*
3698 * Free all options.
3699 */
3700 void
3701free_all_options()
3702{
3703 int i;
3704
3705 for (i = 0; !istermoption(&options[i]); i++)
3706 {
3707 if (options[i].indir == PV_NONE)
3708 {
3709 /* global option: free value and default value. */
3710 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3711 free_string_option(*(char_u **)options[i].var);
3712 if (options[i].flags & P_DEF_ALLOCED)
3713 free_string_option(options[i].def_val[VI_DEFAULT]);
3714 }
3715 else if (options[i].var != VAR_WIN
3716 && (options[i].flags & P_STRING))
3717 /* buffer-local option: free global value */
3718 free_string_option(*(char_u **)options[i].var);
3719 }
3720}
3721#endif
3722
3723
Bram Moolenaar071d4272004-06-13 20:20:40 +00003724/*
3725 * Initialize the options, part two: After getting Rows and Columns and
3726 * setting 'term'.
3727 */
3728 void
3729set_init_2()
3730{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003731 int idx;
3732
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 /*
3734 * 'scroll' defaults to half the window height. Note that this default is
3735 * wrong when the window height changes.
3736 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003737 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003738 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003739 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003740 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003741 comp_col();
3742
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003743 /*
3744 * 'window' is only for backwards compatibility with Vi.
3745 * Default is Rows - 1.
3746 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003747 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003748 p_window = Rows - 1;
3749 set_number_default("window", Rows - 1);
3750
Bram Moolenaarf740b292006-02-16 22:11:02 +00003751 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003752#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003753 /*
3754 * If 'background' wasn't set by the user, try guessing the value,
3755 * depending on the terminal name. Only need to check for terminals
3756 * with a dark background, that can handle color.
3757 */
3758 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003759 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3760 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003762 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003763 /* don't mark it as set, when starting the GUI it may be
3764 * changed again */
3765 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 }
3767#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003768
3769#ifdef CURSOR_SHAPE
3770 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3771#endif
3772#ifdef FEAT_MOUSESHAPE
3773 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3774#endif
3775#ifdef FEAT_PRINTER
3776 (void)parse_printoptions(); /* parse 'printoptions' default value */
3777#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003778}
3779
3780/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003781 * Return "dark" or "light" depending on the kind of terminal.
3782 * This is just guessing! Recognized are:
3783 * "linux" Linux console
3784 * "screen.linux" Linux console with screen
3785 * "cygwin" Cygwin shell
3786 * "putty" Putty program
3787 * We also check the COLORFGBG environment variable, which is set by
3788 * rxvt and derivatives. This variable contains either two or three
3789 * values separated by semicolons; we want the last value in either
3790 * case. If this value is 0-6 or 8, our background is dark.
3791 */
3792 static char_u *
3793term_bg_default()
3794{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003795#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3796 /* DOS console nearly always black */
3797 return (char_u *)"dark";
3798#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003799 char_u *p;
3800
Bram Moolenaarf740b292006-02-16 22:11:02 +00003801 if (STRCMP(T_NAME, "linux") == 0
3802 || STRCMP(T_NAME, "screen.linux") == 0
3803 || STRCMP(T_NAME, "cygwin") == 0
3804 || STRCMP(T_NAME, "putty") == 0
3805 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3806 && (p = vim_strrchr(p, ';')) != NULL
3807 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3808 && p[2] == NUL))
3809 return (char_u *)"dark";
3810 return (char_u *)"light";
3811#endif
3812}
3813
3814/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 * Initialize the options, part three: After reading the .vimrc
3816 */
3817 void
3818set_init_3()
3819{
3820#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3821/*
3822 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3823 * This is done after other initializations, where 'shell' might have been
3824 * set, but only if they have not been set before.
3825 */
3826 char_u *p;
3827 int idx_srr;
3828 int do_srr;
3829#ifdef FEAT_QUICKFIX
3830 int idx_sp;
3831 int do_sp;
3832#endif
3833
3834 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003835 if (idx_srr < 0)
3836 do_srr = FALSE;
3837 else
3838 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839#ifdef FEAT_QUICKFIX
3840 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003841 if (idx_sp < 0)
3842 do_sp = FALSE;
3843 else
3844 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003845#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003846 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847 if (p != NULL)
3848 {
3849 /*
3850 * Default for p_sp is "| tee", for p_srr is ">".
3851 * For known shells it is changed here to include stderr.
3852 */
3853 if ( fnamecmp(p, "csh") == 0
3854 || fnamecmp(p, "tcsh") == 0
3855# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3856 || fnamecmp(p, "csh.exe") == 0
3857 || fnamecmp(p, "tcsh.exe") == 0
3858# endif
3859 )
3860 {
3861#if defined(FEAT_QUICKFIX)
3862 if (do_sp)
3863 {
3864# ifdef WIN3264
3865 p_sp = (char_u *)">&";
3866# else
3867 p_sp = (char_u *)"|& tee";
3868# endif
3869 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3870 }
3871#endif
3872 if (do_srr)
3873 {
3874 p_srr = (char_u *)">&";
3875 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3876 }
3877 }
3878 else
3879# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3880 if ( fnamecmp(p, "sh") == 0
3881 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003882 || fnamecmp(p, "mksh") == 0
3883 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003885 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003886 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003887 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888# ifdef WIN3264
3889 || fnamecmp(p, "cmd") == 0
3890 || fnamecmp(p, "sh.exe") == 0
3891 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003892 || fnamecmp(p, "mksh.exe") == 0
3893 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003895 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896 || fnamecmp(p, "bash.exe") == 0
3897 || fnamecmp(p, "cmd.exe") == 0
3898# endif
3899 )
3900# endif
3901 {
3902#if defined(FEAT_QUICKFIX)
3903 if (do_sp)
3904 {
3905# ifdef WIN3264
3906 p_sp = (char_u *)">%s 2>&1";
3907# else
3908 p_sp = (char_u *)"2>&1| tee";
3909# endif
3910 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3911 }
3912#endif
3913 if (do_srr)
3914 {
3915 p_srr = (char_u *)">%s 2>&1";
3916 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3917 }
3918 }
3919 vim_free(p);
3920 }
3921#endif
3922
3923#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3924 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003925 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3926 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003927 * This is done after other initializations, where 'shell' might have been
3928 * set, but only if they have not been set before. Default for p_shcf is
3929 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3930 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3931 * command.com. And for Win32 we need to set p_sxq instead.
3932 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003933 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 {
3935 int idx3;
3936
3937 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003938 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 {
3940 p_shcf = (char_u *)"-c";
3941 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3942 }
3943
3944# ifndef DJGPP
3945# ifdef WIN3264
3946 /* Somehow Win32 requires the quotes around the redirection too */
3947 idx3 = findoption((char_u *)"sxq");
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_sxq = (char_u *)"\"";
3951 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3952 }
3953# else
3954 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003955 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 {
3957 p_shq = (char_u *)"\"";
3958 options[idx3].def_val[VI_DEFAULT] = p_shq;
3959 }
3960# endif
3961# endif
3962 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003963 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3964 {
3965 int idx3;
3966
3967 /*
3968 * cmd.exe on Windows will strip the first and last double quote given
3969 * on the command line, e.g. most of the time things like:
3970 * cmd /c "my path/to/echo" "my args to echo"
3971 * become:
3972 * my path/to/echo" "my args to echo
3973 * when executed.
3974 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003975 * To avoid this, set shellxquote to surround the command in
3976 * parenthesis. This appears to make most commands work, without
3977 * breaking commands that worked previously, such as
3978 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003979 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003980 idx3 = findoption((char_u *)"sxq");
3981 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3982 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003983 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003984 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3985 }
3986
Bram Moolenaara64ba222012-02-12 23:23:31 +01003987 idx3 = findoption((char_u *)"shcf");
3988 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3989 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003990 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003991 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3992 }
3993 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994#endif
3995
3996#ifdef FEAT_TITLE
3997 set_title_defaults();
3998#endif
3999}
4000
4001#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4002/*
4003 * When 'helplang' is still at its default value, set it to "lang".
4004 * Only the first two characters of "lang" are used.
4005 */
4006 void
4007set_helplang_default(lang)
4008 char_u *lang;
4009{
4010 int idx;
4011
4012 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4013 return;
4014 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004015 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004016 {
4017 if (options[idx].flags & P_ALLOCED)
4018 free_string_option(p_hlg);
4019 p_hlg = vim_strsave(lang);
4020 if (p_hlg == NULL)
4021 p_hlg = empty_option;
4022 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004023 {
4024 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4025 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4026 {
4027 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4028 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4029 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004031 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004032 options[idx].flags |= P_ALLOCED;
4033 }
4034}
4035#endif
4036
4037#ifdef FEAT_GUI
4038static char_u *gui_bg_default __ARGS((void));
4039
4040 static char_u *
4041gui_bg_default()
4042{
4043 if (gui_get_lightness(gui.back_pixel) < 127)
4044 return (char_u *)"dark";
4045 return (char_u *)"light";
4046}
4047
4048/*
4049 * Option initializations that can only be done after opening the GUI window.
4050 */
4051 void
4052init_gui_options()
4053{
4054 /* Set the 'background' option according to the lightness of the
4055 * background color, unless the user has set it already. */
4056 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4057 {
4058 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4059 highlight_changed();
4060 }
4061}
4062#endif
4063
4064#ifdef FEAT_TITLE
4065/*
4066 * 'title' and 'icon' only default to true if they have not been set or reset
4067 * in .vimrc and we can read the old value.
4068 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4069 * they can be reset. This reduces startup time when using X on a remote
4070 * machine.
4071 */
4072 void
4073set_title_defaults()
4074{
4075 int idx1;
4076 long val;
4077
4078 /*
4079 * If GUI is (going to be) used, we can always set the window title and
4080 * icon name. Saves a bit of time, because the X11 display server does
4081 * not need to be contacted.
4082 */
4083 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004084 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 {
4086#ifdef FEAT_GUI
4087 if (gui.starting || gui.in_use)
4088 val = TRUE;
4089 else
4090#endif
4091 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004092 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 p_title = val;
4094 }
4095 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004096 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 {
4098#ifdef FEAT_GUI
4099 if (gui.starting || gui.in_use)
4100 val = TRUE;
4101 else
4102#endif
4103 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004104 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 p_icon = val;
4106 }
4107}
4108#endif
4109
4110/*
4111 * Parse 'arg' for option settings.
4112 *
4113 * 'arg' may be IObuff, but only when no errors can be present and option
4114 * does not need to be expanded with option_expand().
4115 * "opt_flags":
4116 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004117 * OPT_GLOBAL for ":setglobal"
4118 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004120 * OPT_WINONLY to only set window-local options
4121 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 *
4123 * returns FAIL if an error is detected, OK otherwise
4124 */
4125 int
4126do_set(arg, opt_flags)
4127 char_u *arg; /* option string (may be written to!) */
4128 int opt_flags;
4129{
4130 int opt_idx;
4131 char_u *errmsg;
4132 char_u errbuf[80];
4133 char_u *startarg;
4134 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4135 int nextchar; /* next non-white char after option name */
4136 int afterchar; /* character just after option name */
4137 int len;
4138 int i;
4139 long value;
4140 int key;
4141 long_u flags; /* flags for current option */
4142 char_u *varp = NULL; /* pointer to variable for current option */
4143 int did_show = FALSE; /* already showed one value */
4144 int adding; /* "opt+=arg" */
4145 int prepending; /* "opt^=arg" */
4146 int removing; /* "opt-=arg" */
4147 int cp_val = 0;
4148 char_u key_name[2];
4149
4150 if (*arg == NUL)
4151 {
4152 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004153 did_show = TRUE;
4154 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 }
4156
4157 while (*arg != NUL) /* loop to process all options */
4158 {
4159 errmsg = NULL;
4160 startarg = arg; /* remember for error message */
4161
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004162 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4163 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004164 {
4165 /*
4166 * ":set all" show all options.
4167 * ":set all&" set all options to their default value.
4168 */
4169 arg += 3;
4170 if (*arg == '&')
4171 {
4172 ++arg;
4173 /* Only for :set command set global value of local options. */
4174 set_options_default(OPT_FREE | opt_flags);
4175 }
4176 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004177 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004178 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004179 did_show = TRUE;
4180 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004181 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004182 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 {
4184 showoptions(2, opt_flags);
4185 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004186 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 arg += 7;
4188 }
4189 else
4190 {
4191 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004192 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 {
4194 prefix = 0;
4195 arg += 2;
4196 }
4197 else if (STRNCMP(arg, "inv", 3) == 0)
4198 {
4199 prefix = 2;
4200 arg += 3;
4201 }
4202
4203 /* find end of name */
4204 key = 0;
4205 if (*arg == '<')
4206 {
4207 nextchar = 0;
4208 opt_idx = -1;
4209 /* look out for <t_>;> */
4210 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4211 len = 5;
4212 else
4213 {
4214 len = 1;
4215 while (arg[len] != NUL && arg[len] != '>')
4216 ++len;
4217 }
4218 if (arg[len] != '>')
4219 {
4220 errmsg = e_invarg;
4221 goto skip;
4222 }
4223 arg[len] = NUL; /* put NUL after name */
4224 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4225 opt_idx = findoption(arg + 1);
4226 arg[len++] = '>'; /* restore '>' */
4227 if (opt_idx == -1)
4228 key = find_key_option(arg + 1);
4229 }
4230 else
4231 {
4232 len = 0;
4233 /*
4234 * The two characters after "t_" may not be alphanumeric.
4235 */
4236 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4237 len = 4;
4238 else
4239 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4240 ++len;
4241 nextchar = arg[len];
4242 arg[len] = NUL; /* put NUL after name */
4243 opt_idx = findoption(arg);
4244 arg[len] = nextchar; /* restore nextchar */
4245 if (opt_idx == -1)
4246 key = find_key_option(arg);
4247 }
4248
4249 /* remember character after option name */
4250 afterchar = arg[len];
4251
4252 /* skip white space, allow ":set ai ?" */
4253 while (vim_iswhite(arg[len]))
4254 ++len;
4255
4256 adding = FALSE;
4257 prepending = FALSE;
4258 removing = FALSE;
4259 if (arg[len] != NUL && arg[len + 1] == '=')
4260 {
4261 if (arg[len] == '+')
4262 {
4263 adding = TRUE; /* "+=" */
4264 ++len;
4265 }
4266 else if (arg[len] == '^')
4267 {
4268 prepending = TRUE; /* "^=" */
4269 ++len;
4270 }
4271 else if (arg[len] == '-')
4272 {
4273 removing = TRUE; /* "-=" */
4274 ++len;
4275 }
4276 }
4277 nextchar = arg[len];
4278
4279 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4280 {
4281 errmsg = (char_u *)N_("E518: Unknown option");
4282 goto skip;
4283 }
4284
4285 if (opt_idx >= 0)
4286 {
4287 if (options[opt_idx].var == NULL) /* hidden option: skip */
4288 {
4289 /* Only give an error message when requesting the value of
4290 * a hidden option, ignore setting it. */
4291 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4292 && (!(options[opt_idx].flags & P_BOOL)
4293 || nextchar == '?'))
4294 errmsg = (char_u *)N_("E519: Option not supported");
4295 goto skip;
4296 }
4297
4298 flags = options[opt_idx].flags;
4299 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4300 }
4301 else
4302 {
4303 flags = P_STRING;
4304 if (key < 0)
4305 {
4306 key_name[0] = KEY2TERMCAP0(key);
4307 key_name[1] = KEY2TERMCAP1(key);
4308 }
4309 else
4310 {
4311 key_name[0] = KS_KEY;
4312 key_name[1] = (key & 0xff);
4313 }
4314 }
4315
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004316 /* Skip all options that are not window-local (used when showing
4317 * an already loaded buffer in a window). */
4318 if ((opt_flags & OPT_WINONLY)
4319 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4320 goto skip;
4321
Bram Moolenaara3227e22006-03-08 21:32:40 +00004322 /* Skip all options that are window-local (used for :vimgrep). */
4323 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4324 && options[opt_idx].var == VAR_WIN)
4325 goto skip;
4326
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004327 /* Disallow changing some options from modelines. */
4328 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004329 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004330 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004331 {
4332 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4333 goto skip;
4334 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004335#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004336 /* In diff mode some options are overruled. This avoids that
4337 * 'foldmethod' becomes "marker" instead of "diff" and that
4338 * "wrap" gets set. */
4339 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004340 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004341 && (options[opt_idx].indir == PV_FDM
4342 || options[opt_idx].indir == PV_WRAP))
4343 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004345 }
4346
4347#ifdef HAVE_SANDBOX
4348 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004349 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004350 {
4351 errmsg = (char_u *)_(e_sandbox);
4352 goto skip;
4353 }
4354#endif
4355
4356 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4357 {
4358 arg += len;
4359 cp_val = p_cp;
4360 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4361 {
4362 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4363 {
4364 cp_val = FALSE;
4365 arg += 3;
4366 }
4367 else /* "opt&vi": set to Vi default */
4368 {
4369 cp_val = TRUE;
4370 arg += 2;
4371 }
4372 }
4373 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4374 && arg[1] != NUL && !vim_iswhite(arg[1]))
4375 {
4376 errmsg = e_trailing;
4377 goto skip;
4378 }
4379 }
4380
4381 /*
4382 * allow '=' and ':' as MSDOS command.com allows only one
4383 * '=' character per "set" command line. grrr. (jw)
4384 */
4385 if (nextchar == '?'
4386 || (prefix == 1
4387 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4388 && !(flags & P_BOOL)))
4389 {
4390 /*
4391 * print value
4392 */
4393 if (did_show)
4394 msg_putchar('\n'); /* cursor below last one */
4395 else
4396 {
4397 gotocmdline(TRUE); /* cursor at status line */
4398 did_show = TRUE; /* remember that we did a line */
4399 }
4400 if (opt_idx >= 0)
4401 {
4402 showoneopt(&options[opt_idx], opt_flags);
4403#ifdef FEAT_EVAL
4404 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004405 {
4406 /* Mention where the option was last set. */
4407 if (varp == options[opt_idx].var)
4408 last_set_msg(options[opt_idx].scriptID);
4409 else if ((int)options[opt_idx].indir & PV_WIN)
4410 last_set_msg(curwin->w_p_scriptID[
4411 (int)options[opt_idx].indir & PV_MASK]);
4412 else if ((int)options[opt_idx].indir & PV_BUF)
4413 last_set_msg(curbuf->b_p_scriptID[
4414 (int)options[opt_idx].indir & PV_MASK]);
4415 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004416#endif
4417 }
4418 else
4419 {
4420 char_u *p;
4421
4422 p = find_termcode(key_name);
4423 if (p == NULL)
4424 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004425 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004426 goto skip;
4427 }
4428 else
4429 (void)show_one_termcode(key_name, p, TRUE);
4430 }
4431 if (nextchar != '?'
4432 && nextchar != NUL && !vim_iswhite(afterchar))
4433 errmsg = e_trailing;
4434 }
4435 else
4436 {
4437 if (flags & P_BOOL) /* boolean */
4438 {
4439 if (nextchar == '=' || nextchar == ':')
4440 {
4441 errmsg = e_invarg;
4442 goto skip;
4443 }
4444
4445 /*
4446 * ":set opt!": invert
4447 * ":set opt&": reset to default value
4448 * ":set opt<": reset to global value
4449 */
4450 if (nextchar == '!')
4451 value = *(int *)(varp) ^ 1;
4452 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004453 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004454 ((flags & P_VI_DEF) || cp_val)
4455 ? VI_DEFAULT : VIM_DEFAULT];
4456 else if (nextchar == '<')
4457 {
4458 /* For 'autoread' -1 means to use global value. */
4459 if ((int *)varp == &curbuf->b_p_ar
4460 && opt_flags == OPT_LOCAL)
4461 value = -1;
4462 else
4463 value = *(int *)get_varp_scope(&(options[opt_idx]),
4464 OPT_GLOBAL);
4465 }
4466 else
4467 {
4468 /*
4469 * ":set invopt": invert
4470 * ":set opt" or ":set noopt": set or reset
4471 */
4472 if (nextchar != NUL && !vim_iswhite(afterchar))
4473 {
4474 errmsg = e_trailing;
4475 goto skip;
4476 }
4477 if (prefix == 2) /* inv */
4478 value = *(int *)(varp) ^ 1;
4479 else
4480 value = prefix;
4481 }
4482
4483 errmsg = set_bool_option(opt_idx, varp, (int)value,
4484 opt_flags);
4485 }
4486 else /* numeric or string */
4487 {
4488 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4489 || prefix != 1)
4490 {
4491 errmsg = e_invarg;
4492 goto skip;
4493 }
4494
4495 if (flags & P_NUM) /* numeric */
4496 {
4497 /*
4498 * Different ways to set a number option:
4499 * & set to default value
4500 * < set to global value
4501 * <xx> accept special key codes for 'wildchar'
4502 * c accept any non-digit for 'wildchar'
4503 * [-]0-9 set number
4504 * other error
4505 */
4506 ++arg;
4507 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004508 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004509 ((flags & P_VI_DEF) || cp_val)
4510 ? VI_DEFAULT : VIM_DEFAULT];
4511 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004512 {
4513 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4514 * use the global value. */
4515 if ((long *)varp == &curbuf->b_p_ul
4516 && opt_flags == OPT_LOCAL)
4517 value = NO_LOCAL_UNDOLEVEL;
4518 else
4519 value = *(long *)get_varp_scope(
4520 &(options[opt_idx]), OPT_GLOBAL);
4521 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004522 else if (((long *)varp == &p_wc
4523 || (long *)varp == &p_wcm)
4524 && (*arg == '<'
4525 || *arg == '^'
4526 || ((!arg[1] || vim_iswhite(arg[1]))
4527 && !VIM_ISDIGIT(*arg))))
4528 {
4529 value = string_to_key(arg);
4530 if (value == 0 && (long *)varp != &p_wcm)
4531 {
4532 errmsg = e_invarg;
4533 goto skip;
4534 }
4535 }
4536 /* allow negative numbers (for 'undolevels') */
4537 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4538 {
4539 i = 0;
4540 if (*arg == '-')
4541 i = 1;
4542#ifdef HAVE_STRTOL
4543 value = strtol((char *)arg, NULL, 0);
4544 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4545 i += 2;
4546#else
4547 value = atol((char *)arg);
4548#endif
4549 while (VIM_ISDIGIT(arg[i]))
4550 ++i;
4551 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4552 {
4553 errmsg = e_invarg;
4554 goto skip;
4555 }
4556 }
4557 else
4558 {
4559 errmsg = (char_u *)N_("E521: Number required after =");
4560 goto skip;
4561 }
4562
4563 if (adding)
4564 value = *(long *)varp + value;
4565 if (prepending)
4566 value = *(long *)varp * value;
4567 if (removing)
4568 value = *(long *)varp - value;
4569 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004570 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004571 }
4572 else if (opt_idx >= 0) /* string */
4573 {
4574 char_u *save_arg = NULL;
4575 char_u *s = NULL;
4576 char_u *oldval; /* previous value if *varp */
4577 char_u *newval;
4578 char_u *origval;
4579 unsigned newlen;
4580 int comma;
4581 int bs;
4582 int new_value_alloced; /* new string option
4583 was allocated */
4584
4585 /* When using ":set opt=val" for a global option
4586 * with a local value the local value will be
4587 * reset, use the global value here. */
4588 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004589 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004590 varp = options[opt_idx].var;
4591
4592 /* The old value is kept until we are sure that the
4593 * new value is valid. */
4594 oldval = *(char_u **)varp;
4595 if (nextchar == '&') /* set to default val */
4596 {
4597 newval = options[opt_idx].def_val[
4598 ((flags & P_VI_DEF) || cp_val)
4599 ? VI_DEFAULT : VIM_DEFAULT];
4600 if ((char_u **)varp == &p_bg)
4601 {
4602 /* guess the value of 'background' */
4603#ifdef FEAT_GUI
4604 if (gui.in_use)
4605 newval = gui_bg_default();
4606 else
4607#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004608 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004609 }
4610
4611 /* expand environment variables and ~ (since the
4612 * default value was already expanded, only
4613 * required when an environment variable was set
4614 * later */
4615 if (newval == NULL)
4616 newval = empty_option;
4617 else
4618 {
4619 s = option_expand(opt_idx, newval);
4620 if (s == NULL)
4621 s = newval;
4622 newval = vim_strsave(s);
4623 }
4624 new_value_alloced = TRUE;
4625 }
4626 else if (nextchar == '<') /* set to global val */
4627 {
4628 newval = vim_strsave(*(char_u **)get_varp_scope(
4629 &(options[opt_idx]), OPT_GLOBAL));
4630 new_value_alloced = TRUE;
4631 }
4632 else
4633 {
4634 ++arg; /* jump to after the '=' or ':' */
4635
4636 /*
4637 * Set 'keywordprg' to ":help" if an empty
4638 * value was passed to :set by the user.
4639 * Misuse errbuf[] for the resulting string.
4640 */
4641 if (varp == (char_u *)&p_kp
4642 && (*arg == NUL || *arg == ' '))
4643 {
4644 STRCPY(errbuf, ":help");
4645 save_arg = arg;
4646 arg = errbuf;
4647 }
4648 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004649 * Convert 'backspace' number to string, for
4650 * adding, prepending and removing string.
4651 */
4652 else if (varp == (char_u *)&p_bs
4653 && VIM_ISDIGIT(**(char_u **)varp))
4654 {
4655 i = getdigits((char_u **)varp);
4656 switch (i)
4657 {
4658 case 0:
4659 *(char_u **)varp = empty_option;
4660 break;
4661 case 1:
4662 *(char_u **)varp = vim_strsave(
4663 (char_u *)"indent,eol");
4664 break;
4665 case 2:
4666 *(char_u **)varp = vim_strsave(
4667 (char_u *)"indent,eol,start");
4668 break;
4669 }
4670 vim_free(oldval);
4671 oldval = *(char_u **)varp;
4672 }
4673 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004674 * Convert 'whichwrap' number to string, for
4675 * backwards compatibility with Vim 3.0.
4676 * Misuse errbuf[] for the resulting string.
4677 */
4678 else if (varp == (char_u *)&p_ww
4679 && VIM_ISDIGIT(*arg))
4680 {
4681 *errbuf = NUL;
4682 i = getdigits(&arg);
4683 if (i & 1)
4684 STRCAT(errbuf, "b,");
4685 if (i & 2)
4686 STRCAT(errbuf, "s,");
4687 if (i & 4)
4688 STRCAT(errbuf, "h,l,");
4689 if (i & 8)
4690 STRCAT(errbuf, "<,>,");
4691 if (i & 16)
4692 STRCAT(errbuf, "[,],");
4693 if (*errbuf != NUL) /* remove trailing , */
4694 errbuf[STRLEN(errbuf) - 1] = NUL;
4695 save_arg = arg;
4696 arg = errbuf;
4697 }
4698 /*
4699 * Remove '>' before 'dir' and 'bdir', for
4700 * backwards compatibility with version 3.0
4701 */
4702 else if ( *arg == '>'
4703 && (varp == (char_u *)&p_dir
4704 || varp == (char_u *)&p_bdir))
4705 {
4706 ++arg;
4707 }
4708
4709 /* When setting the local value of a global
4710 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004711 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004712 && (opt_flags & OPT_LOCAL))
4713 origval = *(char_u **)get_varp(
4714 &options[opt_idx]);
4715 else
4716 origval = oldval;
4717
4718 /*
4719 * Copy the new string into allocated memory.
4720 * Can't use set_string_option_direct(), because
4721 * we need to remove the backslashes.
4722 */
4723 /* get a bit too much */
4724 newlen = (unsigned)STRLEN(arg) + 1;
4725 if (adding || prepending || removing)
4726 newlen += (unsigned)STRLEN(origval) + 1;
4727 newval = alloc(newlen);
4728 if (newval == NULL) /* out of mem, don't change */
4729 break;
4730 s = newval;
4731
4732 /*
4733 * Copy the string, skip over escaped chars.
4734 * For MS-DOS and WIN32 backslashes before normal
4735 * file name characters are not removed, and keep
4736 * backslash at start, for "\\machine\path", but
4737 * do remove it for "\\\\machine\\path".
4738 * The reverse is found in ExpandOldSetting().
4739 */
4740 while (*arg && !vim_iswhite(*arg))
4741 {
4742 if (*arg == '\\' && arg[1] != NUL
4743#ifdef BACKSLASH_IN_FILENAME
4744 && !((flags & P_EXPAND)
4745 && vim_isfilec(arg[1])
4746 && (arg[1] != '\\'
4747 || (s == newval
4748 && arg[2] != '\\')))
4749#endif
4750 )
4751 ++arg; /* remove backslash */
4752#ifdef FEAT_MBYTE
4753 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004754 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004755 {
4756 /* copy multibyte char */
4757 mch_memmove(s, arg, (size_t)i);
4758 arg += i;
4759 s += i;
4760 }
4761 else
4762#endif
4763 *s++ = *arg++;
4764 }
4765 *s = NUL;
4766
4767 /*
4768 * Expand environment variables and ~.
4769 * Don't do it when adding without inserting a
4770 * comma.
4771 */
4772 if (!(adding || prepending || removing)
4773 || (flags & P_COMMA))
4774 {
4775 s = option_expand(opt_idx, newval);
4776 if (s != NULL)
4777 {
4778 vim_free(newval);
4779 newlen = (unsigned)STRLEN(s) + 1;
4780 if (adding || prepending || removing)
4781 newlen += (unsigned)STRLEN(origval) + 1;
4782 newval = alloc(newlen);
4783 if (newval == NULL)
4784 break;
4785 STRCPY(newval, s);
4786 }
4787 }
4788
4789 /* locate newval[] in origval[] when removing it
4790 * and when adding to avoid duplicates */
4791 i = 0; /* init for GCC */
4792 if (removing || (flags & P_NODUP))
4793 {
4794 i = (int)STRLEN(newval);
4795 bs = 0;
4796 for (s = origval; *s; ++s)
4797 {
4798 if ((!(flags & P_COMMA)
4799 || s == origval
4800 || (s[-1] == ',' && !(bs & 1)))
4801 && STRNCMP(s, newval, i) == 0
4802 && (!(flags & P_COMMA)
4803 || s[i] == ','
4804 || s[i] == NUL))
4805 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004806 /* Count backslashes. Only a comma with an
4807 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004808 * recognized as a separator */
4809 if (s > origval && s[-1] == '\\')
4810 ++bs;
4811 else
4812 bs = 0;
4813 }
4814
4815 /* do not add if already there */
4816 if ((adding || prepending) && *s)
4817 {
4818 prepending = FALSE;
4819 adding = FALSE;
4820 STRCPY(newval, origval);
4821 }
4822 }
4823
4824 /* concatenate the two strings; add a ',' if
4825 * needed */
4826 if (adding || prepending)
4827 {
4828 comma = ((flags & P_COMMA) && *origval != NUL
4829 && *newval != NUL);
4830 if (adding)
4831 {
4832 i = (int)STRLEN(origval);
4833 mch_memmove(newval + i + comma, newval,
4834 STRLEN(newval) + 1);
4835 mch_memmove(newval, origval, (size_t)i);
4836 }
4837 else
4838 {
4839 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004840 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004841 }
4842 if (comma)
4843 newval[i] = ',';
4844 }
4845
4846 /* Remove newval[] from origval[]. (Note: "i" has
4847 * been set above and is used here). */
4848 if (removing)
4849 {
4850 STRCPY(newval, origval);
4851 if (*s)
4852 {
4853 /* may need to remove a comma */
4854 if (flags & P_COMMA)
4855 {
4856 if (s == origval)
4857 {
4858 /* include comma after string */
4859 if (s[i] == ',')
4860 ++i;
4861 }
4862 else
4863 {
4864 /* include comma before string */
4865 --s;
4866 ++i;
4867 }
4868 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004869 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004870 }
4871 }
4872
4873 if (flags & P_FLAGLIST)
4874 {
4875 /* Remove flags that appear twice. */
4876 for (s = newval; *s; ++s)
4877 if ((!(flags & P_COMMA) || *s != ',')
4878 && vim_strchr(s + 1, *s) != NULL)
4879 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004880 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004881 --s;
4882 }
4883 }
4884
4885 if (save_arg != NULL) /* number for 'whichwrap' */
4886 arg = save_arg;
4887 new_value_alloced = TRUE;
4888 }
4889
4890 /* Set the new value. */
4891 *(char_u **)(varp) = newval;
4892
4893 /* Handle side effects, and set the global value for
4894 * ":set" on local options. */
4895 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4896 new_value_alloced, oldval, errbuf, opt_flags);
4897
4898 /* If error detected, print the error message. */
4899 if (errmsg != NULL)
4900 goto skip;
4901 }
4902 else /* key code option */
4903 {
4904 char_u *p;
4905
4906 if (nextchar == '&')
4907 {
4908 if (add_termcap_entry(key_name, TRUE) == FAIL)
4909 errmsg = (char_u *)N_("E522: Not found in termcap");
4910 }
4911 else
4912 {
4913 ++arg; /* jump to after the '=' or ':' */
4914 for (p = arg; *p && !vim_iswhite(*p); ++p)
4915 if (*p == '\\' && p[1] != NUL)
4916 ++p;
4917 nextchar = *p;
4918 *p = NUL;
4919 add_termcode(key_name, arg, FALSE);
4920 *p = nextchar;
4921 }
4922 if (full_screen)
4923 ttest(FALSE);
4924 redraw_all_later(CLEAR);
4925 }
4926 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004927
Bram Moolenaar071d4272004-06-13 20:20:40 +00004928 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004929 did_set_option(opt_idx, opt_flags,
4930 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004931 }
4932
4933skip:
4934 /*
4935 * Advance to next argument.
4936 * - skip until a blank found, taking care of backslashes
4937 * - skip blanks
4938 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4939 */
4940 for (i = 0; i < 2 ; ++i)
4941 {
4942 while (*arg != NUL && !vim_iswhite(*arg))
4943 if (*arg++ == '\\' && *arg != NUL)
4944 ++arg;
4945 arg = skipwhite(arg);
4946 if (*arg != '=')
4947 break;
4948 }
4949 }
4950
4951 if (errmsg != NULL)
4952 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004953 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004954 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004955 if (i + (arg - startarg) < IOSIZE)
4956 {
4957 /* append the argument with the error */
4958 STRCAT(IObuff, ": ");
4959 mch_memmove(IObuff + i, startarg, (arg - startarg));
4960 IObuff[i + (arg - startarg)] = NUL;
4961 }
4962 /* make sure all characters are printable */
4963 trans_characters(IObuff, IOSIZE);
4964
4965 ++no_wait_return; /* wait_return done later */
4966 emsg(IObuff); /* show error highlighted */
4967 --no_wait_return;
4968
4969 return FAIL;
4970 }
4971
4972 arg = skipwhite(arg);
4973 }
4974
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004975theend:
4976 if (silent_mode && did_show)
4977 {
4978 /* After displaying option values in silent mode. */
4979 silent_mode = FALSE;
4980 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4981 msg_putchar('\n');
4982 cursor_on(); /* msg_start() switches it off */
4983 out_flush();
4984 silent_mode = TRUE;
4985 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4986 }
4987
Bram Moolenaar071d4272004-06-13 20:20:40 +00004988 return OK;
4989}
4990
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004991/*
4992 * Call this when an option has been given a new value through a user command.
4993 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4994 */
4995 static void
4996did_set_option(opt_idx, opt_flags, new_value)
4997 int opt_idx;
4998 int opt_flags; /* possibly with OPT_MODELINE */
4999 int new_value; /* value was replaced completely */
5000{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005001 long_u *p;
5002
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005003 options[opt_idx].flags |= P_WAS_SET;
5004
5005 /* When an option is set in the sandbox, from a modeline or in secure mode
5006 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005007 * flag. */
5008 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005009 if (secure
5010#ifdef HAVE_SANDBOX
5011 || sandbox != 0
5012#endif
5013 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005014 *p = *p | P_INSECURE;
5015 else if (new_value)
5016 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005017}
5018
Bram Moolenaar071d4272004-06-13 20:20:40 +00005019 static char_u *
5020illegal_char(errbuf, c)
5021 char_u *errbuf;
5022 int c;
5023{
5024 if (errbuf == NULL)
5025 return (char_u *)"";
5026 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005027 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005028 return errbuf;
5029}
5030
5031/*
5032 * Convert a key name or string into a key value.
5033 * Used for 'wildchar' and 'cedit' options.
5034 */
5035 static int
5036string_to_key(arg)
5037 char_u *arg;
5038{
5039 if (*arg == '<')
5040 return find_key_option(arg + 1);
5041 if (*arg == '^')
5042 return Ctrl_chr(arg[1]);
5043 return *arg;
5044}
5045
5046#ifdef FEAT_CMDWIN
5047/*
5048 * Check value of 'cedit' and set cedit_key.
5049 * Returns NULL if value is OK, error message otherwise.
5050 */
5051 static char_u *
5052check_cedit()
5053{
5054 int n;
5055
5056 if (*p_cedit == NUL)
5057 cedit_key = -1;
5058 else
5059 {
5060 n = string_to_key(p_cedit);
5061 if (vim_isprintc(n))
5062 return e_invarg;
5063 cedit_key = n;
5064 }
5065 return NULL;
5066}
5067#endif
5068
5069#ifdef FEAT_TITLE
5070/*
5071 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5072 * maketitle() to create and display it.
5073 * When switching the title or icon off, call mch_restore_title() to get
5074 * the old value back.
5075 */
5076 static void
5077did_set_title(icon)
5078 int icon; /* Did set icon instead of title */
5079{
5080 if (starting != NO_SCREEN
5081#ifdef FEAT_GUI
5082 && !gui.starting
5083#endif
5084 )
5085 {
5086 maketitle();
5087 if (icon)
5088 {
5089 if (!p_icon)
5090 mch_restore_title(2);
5091 }
5092 else
5093 {
5094 if (!p_title)
5095 mch_restore_title(1);
5096 }
5097 }
5098}
5099#endif
5100
5101/*
5102 * set_options_bin - called when 'bin' changes value.
5103 */
5104 void
5105set_options_bin(oldval, newval, opt_flags)
5106 int oldval;
5107 int newval;
5108 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5109{
5110 /*
5111 * The option values that are changed when 'bin' changes are
5112 * copied when 'bin is set and restored when 'bin' is reset.
5113 */
5114 if (newval)
5115 {
5116 if (!oldval) /* switched on */
5117 {
5118 if (!(opt_flags & OPT_GLOBAL))
5119 {
5120 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5121 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5122 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5123 curbuf->b_p_et_nobin = curbuf->b_p_et;
5124 }
5125 if (!(opt_flags & OPT_LOCAL))
5126 {
5127 p_tw_nobin = p_tw;
5128 p_wm_nobin = p_wm;
5129 p_ml_nobin = p_ml;
5130 p_et_nobin = p_et;
5131 }
5132 }
5133
5134 if (!(opt_flags & OPT_GLOBAL))
5135 {
5136 curbuf->b_p_tw = 0; /* no automatic line wrap */
5137 curbuf->b_p_wm = 0; /* no automatic line wrap */
5138 curbuf->b_p_ml = 0; /* no modelines */
5139 curbuf->b_p_et = 0; /* no expandtab */
5140 }
5141 if (!(opt_flags & OPT_LOCAL))
5142 {
5143 p_tw = 0;
5144 p_wm = 0;
5145 p_ml = FALSE;
5146 p_et = FALSE;
5147 p_bin = TRUE; /* needed when called for the "-b" argument */
5148 }
5149 }
5150 else if (oldval) /* switched off */
5151 {
5152 if (!(opt_flags & OPT_GLOBAL))
5153 {
5154 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5155 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5156 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5157 curbuf->b_p_et = curbuf->b_p_et_nobin;
5158 }
5159 if (!(opt_flags & OPT_LOCAL))
5160 {
5161 p_tw = p_tw_nobin;
5162 p_wm = p_wm_nobin;
5163 p_ml = p_ml_nobin;
5164 p_et = p_et_nobin;
5165 }
5166 }
5167}
5168
5169#ifdef FEAT_VIMINFO
5170/*
5171 * Find the parameter represented by the given character (eg ', :, ", or /),
5172 * and return its associated value in the 'viminfo' string.
5173 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005174 * If the parameter is not specified in the string or there is no following
5175 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005176 */
5177 int
5178get_viminfo_parameter(type)
5179 int type;
5180{
5181 char_u *p;
5182
5183 p = find_viminfo_parameter(type);
5184 if (p != NULL && VIM_ISDIGIT(*p))
5185 return atoi((char *)p);
5186 return -1;
5187}
5188
5189/*
5190 * Find the parameter represented by the given character (eg ''', ':', '"', or
5191 * '/') in the 'viminfo' option and return a pointer to the string after it.
5192 * Return NULL if the parameter is not specified in the string.
5193 */
5194 char_u *
5195find_viminfo_parameter(type)
5196 int type;
5197{
5198 char_u *p;
5199
5200 for (p = p_viminfo; *p; ++p)
5201 {
5202 if (*p == type)
5203 return p + 1;
5204 if (*p == 'n') /* 'n' is always the last one */
5205 break;
5206 p = vim_strchr(p, ','); /* skip until next ',' */
5207 if (p == NULL) /* hit the end without finding parameter */
5208 break;
5209 }
5210 return NULL;
5211}
5212#endif
5213
5214/*
5215 * Expand environment variables for some string options.
5216 * These string options cannot be indirect!
5217 * If "val" is NULL expand the current value of the option.
5218 * Return pointer to NameBuff, or NULL when not expanded.
5219 */
5220 static char_u *
5221option_expand(opt_idx, val)
5222 int opt_idx;
5223 char_u *val;
5224{
5225 /* if option doesn't need expansion nothing to do */
5226 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5227 return NULL;
5228
5229 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5230 * expand_env() would truncate the string. */
5231 if (val != NULL && STRLEN(val) > MAXPATHL)
5232 return NULL;
5233
5234 if (val == NULL)
5235 val = *(char_u **)options[opt_idx].var;
5236
5237 /*
5238 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5239 * Escape spaces when expanding 'tags', they are used to separate file
5240 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005241 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 */
5243 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005244 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005245#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005246 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5247#endif
5248 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005249 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5250 return NULL;
5251
5252 return NameBuff;
5253}
5254
5255/*
5256 * After setting various option values: recompute variables that depend on
5257 * option values.
5258 */
5259 static void
5260didset_options()
5261{
5262 /* initialize the table for 'iskeyword' et.al. */
5263 (void)init_chartab();
5264
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005265#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005266 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005267#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005268 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5269#ifdef FEAT_SESSION
5270 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5271 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5272#endif
5273#ifdef FEAT_FOLDING
5274 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5275#endif
5276 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5277#ifdef FEAT_VIRTUALEDIT
5278 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5279#endif
5280#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5281 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5282#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005283#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005284 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005285 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005286 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005288#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5289 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5290#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005291#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005292 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5293#endif
5294#ifdef FEAT_CMDWIN
5295 /* set cedit_key */
5296 (void)check_cedit();
5297#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005298#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005299 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005300#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005301}
5302
5303/*
5304 * Check for string options that are NULL (normally only termcap options).
5305 */
5306 void
5307check_options()
5308{
5309 int opt_idx;
5310
5311 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5312 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5313 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5314}
5315
5316/*
5317 * Check string options in a buffer for NULL value.
5318 */
5319 void
5320check_buf_options(buf)
5321 buf_T *buf;
5322{
5323#if defined(FEAT_QUICKFIX)
5324 check_string_option(&buf->b_p_bh);
5325 check_string_option(&buf->b_p_bt);
5326#endif
5327#ifdef FEAT_MBYTE
5328 check_string_option(&buf->b_p_fenc);
5329#endif
5330 check_string_option(&buf->b_p_ff);
5331#ifdef FEAT_FIND_ID
5332 check_string_option(&buf->b_p_def);
5333 check_string_option(&buf->b_p_inc);
5334# ifdef FEAT_EVAL
5335 check_string_option(&buf->b_p_inex);
5336# endif
5337#endif
5338#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5339 check_string_option(&buf->b_p_inde);
5340 check_string_option(&buf->b_p_indk);
5341#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005342#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5343 check_string_option(&buf->b_p_bexpr);
5344#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005345#if defined(FEAT_CRYPT)
5346 check_string_option(&buf->b_p_cm);
5347#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005348#if defined(FEAT_EVAL)
5349 check_string_option(&buf->b_p_fex);
5350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351#ifdef FEAT_CRYPT
5352 check_string_option(&buf->b_p_key);
5353#endif
5354 check_string_option(&buf->b_p_kp);
5355 check_string_option(&buf->b_p_mps);
5356 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005357 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005358 check_string_option(&buf->b_p_isk);
5359#ifdef FEAT_COMMENTS
5360 check_string_option(&buf->b_p_com);
5361#endif
5362#ifdef FEAT_FOLDING
5363 check_string_option(&buf->b_p_cms);
5364#endif
5365 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005366#ifdef FEAT_TEXTOBJ
5367 check_string_option(&buf->b_p_qe);
5368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369#ifdef FEAT_SYN_HL
5370 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005371#endif
5372#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005373 check_string_option(&buf->b_s.b_p_spc);
5374 check_string_option(&buf->b_s.b_p_spf);
5375 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376#endif
5377#ifdef FEAT_SEARCHPATH
5378 check_string_option(&buf->b_p_sua);
5379#endif
5380#ifdef FEAT_CINDENT
5381 check_string_option(&buf->b_p_cink);
5382 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005383 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005384#endif
5385#ifdef FEAT_AUTOCMD
5386 check_string_option(&buf->b_p_ft);
5387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005388#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5389 check_string_option(&buf->b_p_cinw);
5390#endif
5391#ifdef FEAT_INS_EXPAND
5392 check_string_option(&buf->b_p_cpt);
5393#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005394#ifdef FEAT_COMPL_FUNC
5395 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005396 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005397#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005398#ifdef FEAT_KEYMAP
5399 check_string_option(&buf->b_p_keymap);
5400#endif
5401#ifdef FEAT_QUICKFIX
5402 check_string_option(&buf->b_p_gp);
5403 check_string_option(&buf->b_p_mp);
5404 check_string_option(&buf->b_p_efm);
5405#endif
5406 check_string_option(&buf->b_p_ep);
5407 check_string_option(&buf->b_p_path);
5408 check_string_option(&buf->b_p_tags);
5409#ifdef FEAT_INS_EXPAND
5410 check_string_option(&buf->b_p_dict);
5411 check_string_option(&buf->b_p_tsr);
5412#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005413#ifdef FEAT_LISP
5414 check_string_option(&buf->b_p_lw);
5415#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005416 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005417}
5418
5419/*
5420 * Free the string allocated for an option.
5421 * Checks for the string being empty_option. This may happen if we're out of
5422 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5423 * check_options().
5424 * Does NOT check for P_ALLOCED flag!
5425 */
5426 void
5427free_string_option(p)
5428 char_u *p;
5429{
5430 if (p != empty_option)
5431 vim_free(p);
5432}
5433
5434 void
5435clear_string_option(pp)
5436 char_u **pp;
5437{
5438 if (*pp != empty_option)
5439 vim_free(*pp);
5440 *pp = empty_option;
5441}
5442
5443 static void
5444check_string_option(pp)
5445 char_u **pp;
5446{
5447 if (*pp == NULL)
5448 *pp = empty_option;
5449}
5450
5451/*
5452 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5453 */
5454 void
5455set_term_option_alloced(p)
5456 char_u **p;
5457{
5458 int opt_idx;
5459
5460 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5461 if (options[opt_idx].var == (char_u *)p)
5462 {
5463 options[opt_idx].flags |= P_ALLOCED;
5464 return;
5465 }
5466 return; /* cannot happen: didn't find it! */
5467}
5468
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005469#if defined(FEAT_EVAL) || defined(PROTO)
5470/*
5471 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5472 * Return FALSE when it wasn't.
5473 * Return -1 for an unknown option.
5474 */
5475 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005476was_set_insecurely(opt, opt_flags)
5477 char_u *opt;
5478 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005479{
5480 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005481 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005482
5483 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005484 {
5485 flagp = insecure_flag(idx, opt_flags);
5486 return (*flagp & P_INSECURE) != 0;
5487 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005488 EMSG2(_(e_intern2), "was_set_insecurely()");
5489 return -1;
5490}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005491
5492/*
5493 * Get a pointer to the flags used for the P_INSECURE flag of option
5494 * "opt_idx". For some local options a local flags field is used.
5495 */
5496 static long_u *
5497insecure_flag(opt_idx, opt_flags)
5498 int opt_idx;
5499 int opt_flags;
5500{
5501 if (opt_flags & OPT_LOCAL)
5502 switch ((int)options[opt_idx].indir)
5503 {
5504#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005505 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005506#endif
5507#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005508# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005509 case PV_FDE: return &curwin->w_p_fde_flags;
5510 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005511# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005512# ifdef FEAT_BEVAL
5513 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5514# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005515# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005516 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005517# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005518 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005519# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005520 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005521# endif
5522#endif
5523 }
5524
5525 /* Nothing special, return global flags field. */
5526 return &options[opt_idx].flags;
5527}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005528#endif
5529
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005530#ifdef FEAT_TITLE
5531static void redraw_titles __ARGS((void));
5532
5533/*
5534 * Redraw the window title and/or tab page text later.
5535 */
5536static void redraw_titles()
5537{
5538 need_maketitle = TRUE;
5539# ifdef FEAT_WINDOWS
5540 redraw_tabline = TRUE;
5541# endif
5542}
5543#endif
5544
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545/*
5546 * Set a string option to a new value (without checking the effect).
5547 * The string is copied into allocated memory.
5548 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005549 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005550 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551 */
5552 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005553set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005554 char_u *name;
5555 int opt_idx;
5556 char_u *val;
5557 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005558 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559{
5560 char_u *s;
5561 char_u **varp;
5562 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005563 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564
Bram Moolenaar89d40322006-08-29 15:30:07 +00005565 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005567 idx = findoption(name);
5568 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005569 {
5570 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005572 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573 }
5574
Bram Moolenaar89d40322006-08-29 15:30:07 +00005575 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005576 return;
5577
5578 s = vim_strsave(val);
5579 if (s != NULL)
5580 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005581 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005583 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584 free_string_option(*varp);
5585 *varp = s;
5586
5587 /* For buffer/window local option may also set the global value. */
5588 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005589 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590
Bram Moolenaar89d40322006-08-29 15:30:07 +00005591 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005592
5593 /* When setting both values of a global option with a local value,
5594 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005595 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005596 {
5597 free_string_option(*varp);
5598 *varp = empty_option;
5599 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005600# ifdef FEAT_EVAL
5601 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005602 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005603 set_sid == 0 ? current_SID : set_sid);
5604# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005605 }
5606}
5607
5608/*
5609 * Set global value for string option when it's a local option.
5610 */
5611 static void
5612set_string_option_global(opt_idx, varp)
5613 int opt_idx; /* option index */
5614 char_u **varp; /* pointer to option variable */
5615{
5616 char_u **p, *s;
5617
5618 /* the global value is always allocated */
5619 if (options[opt_idx].var == VAR_WIN)
5620 p = (char_u **)GLOBAL_WO(varp);
5621 else
5622 p = (char_u **)options[opt_idx].var;
5623 if (options[opt_idx].indir != PV_NONE
5624 && p != varp
5625 && (s = vim_strsave(*varp)) != NULL)
5626 {
5627 free_string_option(*p);
5628 *p = s;
5629 }
5630}
5631
5632/*
5633 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005634 *
5635 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005637 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638set_string_option(opt_idx, value, opt_flags)
5639 int opt_idx;
5640 char_u *value;
5641 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5642{
5643 char_u *s;
5644 char_u **varp;
5645 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005646 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005647
5648 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005649 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650
5651 s = vim_strsave(value);
5652 if (s != NULL)
5653 {
5654 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5655 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005656 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657 ? OPT_GLOBAL : OPT_LOCAL)
5658 : opt_flags);
5659 oldval = *varp;
5660 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005661 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5662 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005663 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005665 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666}
5667
5668/*
5669 * Handle string options that need some action to perform when changed.
5670 * Returns NULL for success, or an error message for an error.
5671 */
5672 static char_u *
5673did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5674 opt_flags)
5675 int opt_idx; /* index in options[] table */
5676 char_u **varp; /* pointer to the option variable */
5677 int new_value_alloced; /* new value was allocated */
5678 char_u *oldval; /* previous value of the option */
5679 char_u *errbuf; /* buffer for errors, or NULL */
5680 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5681{
5682 char_u *errmsg = NULL;
5683 char_u *s, *p;
5684 int did_chartab = FALSE;
5685 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005686 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005687#ifdef FEAT_GUI
5688 /* set when changing an option that only requires a redraw in the GUI */
5689 int redraw_gui_only = FALSE;
5690#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691
5692 /* Get the global option to compare with, otherwise we would have to check
5693 * two values for all local options. */
5694 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5695
5696 /* Disallow changing some options from secure mode */
5697 if ((secure
5698#ifdef HAVE_SANDBOX
5699 || sandbox != 0
5700#endif
5701 ) && (options[opt_idx].flags & P_SECURE))
5702 {
5703 errmsg = e_secure;
5704 }
5705
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005706 /* Check for a "normal" file name in some options. Disallow a path
5707 * separator (slash and/or backslash), wildcards and characters that are
5708 * often illegal in a file name. */
5709 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005710 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005711 {
5712 errmsg = e_invarg;
5713 }
5714
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715 /* 'term' */
5716 else if (varp == &T_NAME)
5717 {
5718 if (T_NAME[0] == NUL)
5719 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5720#ifdef FEAT_GUI
5721 if (gui.in_use)
5722 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5723 else if (term_is_gui(T_NAME))
5724 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5725#endif
5726 else if (set_termname(T_NAME) == FAIL)
5727 errmsg = (char_u *)N_("E522: Not found in termcap");
5728 else
5729 /* Screen colors may have changed. */
5730 redraw_later_clear();
5731 }
5732
5733 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005734 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005736 char_u *bkc = p_bkc;
5737 unsigned int *flags = &bkc_flags;
5738
5739 if (opt_flags & OPT_LOCAL)
5740 {
5741 bkc = curbuf->b_p_bkc;
5742 flags = &curbuf->b_bkc_flags;
5743 }
5744
5745 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746 errmsg = e_invarg;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005747 if ((((int)*flags & BKC_AUTO) != 0)
5748 + (((int)*flags & BKC_YES) != 0)
5749 + (((int)*flags & BKC_NO) != 0) != 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005750 {
5751 /* Must have exactly one of "auto", "yes" and "no". */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005752 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753 errmsg = e_invarg;
5754 }
5755 }
5756
5757 /* 'backupext' and 'patchmode' */
5758 else if (varp == &p_bex || varp == &p_pm)
5759 {
5760 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5761 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5762 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5763 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005764#ifdef FEAT_LINEBREAK
5765 /* 'breakindentopt' */
5766 else if (varp == &curwin->w_p_briopt)
5767 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005768 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005769 errmsg = e_invarg;
5770 }
5771#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772
5773 /*
5774 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5775 * If the new option is invalid, use old value. 'lisp' option: refill
5776 * chartab[] for '-' char
5777 */
5778 else if ( varp == &p_isi
5779 || varp == &(curbuf->b_p_isk)
5780 || varp == &p_isp
5781 || varp == &p_isf)
5782 {
5783 if (init_chartab() == FAIL)
5784 {
5785 did_chartab = TRUE; /* need to restore it below */
5786 errmsg = e_invarg; /* error in value */
5787 }
5788 }
5789
5790 /* 'helpfile' */
5791 else if (varp == &p_hf)
5792 {
5793 /* May compute new values for $VIM and $VIMRUNTIME */
5794 if (didset_vim)
5795 {
5796 vim_setenv((char_u *)"VIM", (char_u *)"");
5797 didset_vim = FALSE;
5798 }
5799 if (didset_vimruntime)
5800 {
5801 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5802 didset_vimruntime = FALSE;
5803 }
5804 }
5805
Bram Moolenaar1a384422010-07-14 19:53:30 +02005806#ifdef FEAT_SYN_HL
5807 /* 'colorcolumn' */
5808 else if (varp == &curwin->w_p_cc)
5809 errmsg = check_colorcolumn(curwin);
5810#endif
5811
Bram Moolenaar071d4272004-06-13 20:20:40 +00005812#ifdef FEAT_MULTI_LANG
5813 /* 'helplang' */
5814 else if (varp == &p_hlg)
5815 {
5816 /* Check for "", "ab", "ab,cd", etc. */
5817 for (s = p_hlg; *s != NUL; s += 3)
5818 {
5819 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5820 {
5821 errmsg = e_invarg;
5822 break;
5823 }
5824 if (s[2] == NUL)
5825 break;
5826 }
5827 }
5828#endif
5829
5830 /* 'highlight' */
5831 else if (varp == &p_hl)
5832 {
5833 if (highlight_changed() == FAIL)
5834 errmsg = e_invarg; /* invalid flags */
5835 }
5836
5837 /* 'nrformats' */
5838 else if (gvarp == &p_nf)
5839 {
5840 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5841 errmsg = e_invarg;
5842 }
5843
5844#ifdef FEAT_SESSION
5845 /* 'sessionoptions' */
5846 else if (varp == &p_ssop)
5847 {
5848 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5849 errmsg = e_invarg;
5850 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5851 {
5852 /* Don't allow both "sesdir" and "curdir". */
5853 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5854 errmsg = e_invarg;
5855 }
5856 }
5857 /* 'viewoptions' */
5858 else if (varp == &p_vop)
5859 {
5860 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5861 errmsg = e_invarg;
5862 }
5863#endif
5864
5865 /* 'scrollopt' */
5866#ifdef FEAT_SCROLLBIND
5867 else if (varp == &p_sbo)
5868 {
5869 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5870 errmsg = e_invarg;
5871 }
5872#endif
5873
5874 /* 'ambiwidth' */
5875#ifdef FEAT_MBYTE
5876 else if (varp == &p_ambw)
5877 {
5878 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5879 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005880 else if (set_chars_option(&p_lcs) != NULL)
5881 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5882# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5883 else if (set_chars_option(&p_fcs) != NULL)
5884 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5885# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005886 }
5887#endif
5888
5889 /* 'background' */
5890 else if (varp == &p_bg)
5891 {
5892 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5893 {
5894#ifdef FEAT_EVAL
5895 int dark = (*p_bg == 'd');
5896#endif
5897
5898 init_highlight(FALSE, FALSE);
5899
5900#ifdef FEAT_EVAL
5901 if (dark != (*p_bg == 'd')
5902 && get_var_value((char_u *)"g:colors_name") != NULL)
5903 {
5904 /* The color scheme must have set 'background' back to another
5905 * value, that's not what we want here. Disable the color
5906 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005907 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005908 free_string_option(p_bg);
5909 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5910 check_string_option(&p_bg);
5911 init_highlight(FALSE, FALSE);
5912 }
5913#endif
5914 }
5915 else
5916 errmsg = e_invarg;
5917 }
5918
5919 /* 'wildmode' */
5920 else if (varp == &p_wim)
5921 {
5922 if (check_opt_wim() == FAIL)
5923 errmsg = e_invarg;
5924 }
5925
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005926#ifdef FEAT_CMDL_COMPL
5927 /* 'wildoptions' */
5928 else if (varp == &p_wop)
5929 {
5930 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5931 errmsg = e_invarg;
5932 }
5933#endif
5934
Bram Moolenaar071d4272004-06-13 20:20:40 +00005935#ifdef FEAT_WAK
5936 /* 'winaltkeys' */
5937 else if (varp == &p_wak)
5938 {
5939 if (*p_wak == NUL
5940 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5941 errmsg = e_invarg;
5942# ifdef FEAT_MENU
5943# ifdef FEAT_GUI_MOTIF
5944 else if (gui.in_use)
5945 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5946# else
5947# ifdef FEAT_GUI_GTK
5948 else if (gui.in_use)
5949 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5950# endif
5951# endif
5952# endif
5953 }
5954#endif
5955
5956#ifdef FEAT_AUTOCMD
5957 /* 'eventignore' */
5958 else if (varp == &p_ei)
5959 {
5960 if (check_ei() == FAIL)
5961 errmsg = e_invarg;
5962 }
5963#endif
5964
5965#ifdef FEAT_MBYTE
5966 /* 'encoding' and 'fileencoding' */
5967 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5968 {
5969 if (gvarp == &p_fenc)
5970 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005971 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005972 errmsg = e_modifiable;
5973 else if (vim_strchr(*varp, ',') != NULL)
5974 /* No comma allowed in 'fileencoding'; catches confusing it
5975 * with 'fileencodings'. */
5976 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005978 {
5979# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005980 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005981 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005982# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005983 /* Add 'fileencoding' to the swap file. */
5984 ml_setflags(curbuf);
5985 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005986 }
5987 if (errmsg == NULL)
5988 {
5989 /* canonize the value, so that STRCMP() can be used on it */
5990 p = enc_canonize(*varp);
5991 if (p != NULL)
5992 {
5993 vim_free(*varp);
5994 *varp = p;
5995 }
5996 if (varp == &p_enc)
5997 {
5998 errmsg = mb_init();
5999# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006000 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006001# endif
6002 }
6003 }
6004
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006005# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6007 {
6008 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6009 if (STRCMP(p_tenc, "utf-8") != 0)
6010 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6011 }
6012# endif
6013
6014 if (errmsg == NULL)
6015 {
6016# ifdef FEAT_KEYMAP
6017 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6018 * (with another encoding). */
6019 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6020 (void)keymap_init();
6021# endif
6022
6023 /* When 'termencoding' is not empty and 'encoding' changes or when
6024 * 'termencoding' changes, need to setup for keyboard input and
6025 * display output conversion. */
6026 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6027 {
6028 convert_setup(&input_conv, p_tenc, p_enc);
6029 convert_setup(&output_conv, p_enc, p_tenc);
6030 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006031
6032# if defined(WIN3264) && defined(FEAT_MBYTE)
6033 /* $HOME may have characters in active code page. */
6034 if (varp == &p_enc)
6035 init_homedir();
6036# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037 }
6038 }
6039#endif
6040
6041#if defined(FEAT_POSTSCRIPT)
6042 else if (varp == &p_penc)
6043 {
6044 /* Canonize printencoding if VIM standard one */
6045 p = enc_canonize(p_penc);
6046 if (p != NULL)
6047 {
6048 vim_free(p_penc);
6049 p_penc = p;
6050 }
6051 else
6052 {
6053 /* Ensure lower case and '-' for '_' */
6054 for (s = p_penc; *s != NUL; s++)
6055 {
6056 if (*s == '_')
6057 *s = '-';
6058 else
6059 *s = TOLOWER_ASC(*s);
6060 }
6061 }
6062 }
6063#endif
6064
Bram Moolenaar9372a112005-12-06 19:59:18 +00006065#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006066 else if (varp == &p_imak)
6067 {
6068 if (gui.in_use && !im_xim_isvalid_imactivate())
6069 errmsg = e_invarg;
6070 }
6071#endif
6072
6073#ifdef FEAT_KEYMAP
6074 else if (varp == &curbuf->b_p_keymap)
6075 {
6076 /* load or unload key mapping tables */
6077 errmsg = keymap_init();
6078
Bram Moolenaarfab06232009-03-04 03:13:35 +00006079 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006080 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006081 if (*curbuf->b_p_keymap != NUL)
6082 {
6083 /* Installed a new keymap, switch on using it. */
6084 curbuf->b_p_iminsert = B_IMODE_LMAP;
6085 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6086 curbuf->b_p_imsearch = B_IMODE_LMAP;
6087 }
6088 else
6089 {
6090 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6091 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6092 curbuf->b_p_iminsert = B_IMODE_NONE;
6093 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6094 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6095 }
6096 if ((opt_flags & OPT_LOCAL) == 0)
6097 {
6098 set_iminsert_global();
6099 set_imsearch_global();
6100 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101# ifdef FEAT_WINDOWS
6102 status_redraw_curbuf();
6103# endif
6104 }
6105 }
6106#endif
6107
6108 /* 'fileformat' */
6109 else if (gvarp == &p_ff)
6110 {
6111 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6112 errmsg = e_modifiable;
6113 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6114 errmsg = e_invarg;
6115 else
6116 {
6117 /* may also change 'textmode' */
6118 if (get_fileformat(curbuf) == EOL_DOS)
6119 curbuf->b_p_tx = TRUE;
6120 else
6121 curbuf->b_p_tx = FALSE;
6122#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006123 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006125 /* update flag in swap file */
6126 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006127 /* Redraw needed when switching to/from "mac": a CR in the text
6128 * will be displayed differently. */
6129 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6130 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006131 }
6132 }
6133
6134 /* 'fileformats' */
6135 else if (varp == &p_ffs)
6136 {
6137 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6138 errmsg = e_invarg;
6139 else
6140 {
6141 /* also change 'textauto' */
6142 if (*p_ffs == NUL)
6143 p_ta = FALSE;
6144 else
6145 p_ta = TRUE;
6146 }
6147 }
6148
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006149#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150 /* 'cryptkey' */
6151 else if (gvarp == &p_key)
6152 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006153# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006154 /* Make sure the ":set" command doesn't show the new value in the
6155 * history. */
6156 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006157# endif
6158 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6159 /* Need to update the swapfile. */
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006160 ml_set_crypt_key(curbuf, oldval, crypt_get_method_nr(curbuf));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006161 }
6162
6163 else if (gvarp == &p_cm)
6164 {
6165 if (opt_flags & OPT_LOCAL)
6166 p = curbuf->b_p_cm;
6167 else
6168 p = p_cm;
6169 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6170 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006171 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006172 errmsg = e_invarg;
6173 else
6174 {
6175 /* When setting the global value to empty, make it "zip". */
6176 if (*p_cm == NUL)
6177 {
6178 if (new_value_alloced)
6179 free_string_option(p_cm);
6180 p_cm = vim_strsave((char_u *)"zip");
6181 new_value_alloced = TRUE;
6182 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006183 /* When using ":set cm=name" the local value is going to be empty.
6184 * Do that here, otherwise the crypt functions will still use the
6185 * local value. */
6186 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6187 {
6188 free_string_option(curbuf->b_p_cm);
6189 curbuf->b_p_cm = empty_option;
6190 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006191
6192 /* Need to update the swapfile when the effective method changed.
6193 * Set "s" to the effective old value, "p" to the effective new
6194 * method and compare. */
6195 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6196 s = p_cm; /* was previously using the global value */
6197 else
6198 s = oldval;
6199 if (*curbuf->b_p_cm == NUL)
6200 p = p_cm; /* is now using the global value */
6201 else
6202 p = curbuf->b_p_cm;
6203 if (STRCMP(s, p) != 0)
6204 ml_set_crypt_key(curbuf, curbuf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006205 crypt_method_nr_from_name(s));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006206
6207 /* If the global value changes need to update the swapfile for all
6208 * buffers using that value. */
6209 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6210 {
6211 buf_T *buf;
6212
6213 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6214 if (buf != curbuf && *buf->b_p_cm == NUL)
6215 ml_set_crypt_key(buf, buf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006216 crypt_method_nr_from_name(oldval));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006217 }
6218 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006219 }
6220#endif
6221
6222 /* 'matchpairs' */
6223 else if (gvarp == &p_mps)
6224 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006225#ifdef FEAT_MBYTE
6226 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006227 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006228 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006229 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006230 int x2 = -1;
6231 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006232
6233 if (*p != NUL)
6234 p += mb_ptr2len(p);
6235 if (*p != NUL)
6236 x2 = *p++;
6237 if (*p != NUL)
6238 {
6239 x3 = mb_ptr2char(p);
6240 p += mb_ptr2len(p);
6241 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006242 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006243 {
6244 errmsg = e_invarg;
6245 break;
6246 }
6247 if (*p == NUL)
6248 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006249 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006250 }
6251 else
6252#endif
6253 {
6254 /* Check for "x:y,x:y" */
6255 for (p = *varp; *p != NUL; p += 4)
6256 {
6257 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6258 {
6259 errmsg = e_invarg;
6260 break;
6261 }
6262 if (p[3] == NUL)
6263 break;
6264 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265 }
6266 }
6267
6268#ifdef FEAT_COMMENTS
6269 /* 'comments' */
6270 else if (gvarp == &p_com)
6271 {
6272 for (s = *varp; *s; )
6273 {
6274 while (*s && *s != ':')
6275 {
6276 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6277 && !VIM_ISDIGIT(*s) && *s != '-')
6278 {
6279 errmsg = illegal_char(errbuf, *s);
6280 break;
6281 }
6282 ++s;
6283 }
6284 if (*s++ == NUL)
6285 errmsg = (char_u *)N_("E524: Missing colon");
6286 else if (*s == ',' || *s == NUL)
6287 errmsg = (char_u *)N_("E525: Zero length string");
6288 if (errmsg != NULL)
6289 break;
6290 while (*s && *s != ',')
6291 {
6292 if (*s == '\\' && s[1] != NUL)
6293 ++s;
6294 ++s;
6295 }
6296 s = skip_to_option_part(s);
6297 }
6298 }
6299#endif
6300
6301 /* 'listchars' */
6302 else if (varp == &p_lcs)
6303 {
6304 errmsg = set_chars_option(varp);
6305 }
6306
6307#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6308 /* 'fillchars' */
6309 else if (varp == &p_fcs)
6310 {
6311 errmsg = set_chars_option(varp);
6312 }
6313#endif
6314
6315#ifdef FEAT_CMDWIN
6316 /* 'cedit' */
6317 else if (varp == &p_cedit)
6318 {
6319 errmsg = check_cedit();
6320 }
6321#endif
6322
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006323 /* 'verbosefile' */
6324 else if (varp == &p_vfile)
6325 {
6326 verbose_stop();
6327 if (*p_vfile != NUL && verbose_open() == FAIL)
6328 errmsg = e_invarg;
6329 }
6330
Bram Moolenaar071d4272004-06-13 20:20:40 +00006331#ifdef FEAT_VIMINFO
6332 /* 'viminfo' */
6333 else if (varp == &p_viminfo)
6334 {
6335 for (s = p_viminfo; *s;)
6336 {
6337 /* Check it's a valid character */
6338 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6339 {
6340 errmsg = illegal_char(errbuf, *s);
6341 break;
6342 }
6343 if (*s == 'n') /* name is always last one */
6344 {
6345 break;
6346 }
6347 else if (*s == 'r') /* skip until next ',' */
6348 {
6349 while (*++s && *s != ',')
6350 ;
6351 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006352 else if (*s == '%')
6353 {
6354 /* optional number */
6355 while (vim_isdigit(*++s))
6356 ;
6357 }
6358 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006359 ++s; /* no extra chars */
6360 else /* must have a number */
6361 {
6362 while (vim_isdigit(*++s))
6363 ;
6364
6365 if (!VIM_ISDIGIT(*(s - 1)))
6366 {
6367 if (errbuf != NULL)
6368 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006369 sprintf((char *)errbuf,
6370 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006371 transchar_byte(*(s - 1)));
6372 errmsg = errbuf;
6373 }
6374 else
6375 errmsg = (char_u *)"";
6376 break;
6377 }
6378 }
6379 if (*s == ',')
6380 ++s;
6381 else if (*s)
6382 {
6383 if (errbuf != NULL)
6384 errmsg = (char_u *)N_("E527: Missing comma");
6385 else
6386 errmsg = (char_u *)"";
6387 break;
6388 }
6389 }
6390 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6391 errmsg = (char_u *)N_("E528: Must specify a ' value");
6392 }
6393#endif /* FEAT_VIMINFO */
6394
6395 /* terminal options */
6396 else if (istermoption(&options[opt_idx]) && full_screen)
6397 {
6398 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6399 if (varp == &T_CCO)
6400 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006401 int colors = atoi((char *)T_CCO);
6402
6403 /* Only reinitialize colors if t_Co value has really changed to
6404 * avoid expensive reload of colorscheme if t_Co is set to the
6405 * same value multiple times. */
6406 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006407 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006408 t_colors = colors;
6409 if (t_colors <= 1)
6410 {
6411 if (new_value_alloced)
6412 vim_free(T_CCO);
6413 T_CCO = empty_option;
6414 }
6415 /* We now have a different color setup, initialize it again. */
6416 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006417 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418 }
6419 ttest(FALSE);
6420 if (varp == &T_ME)
6421 {
6422 out_str(T_ME);
6423 redraw_later(CLEAR);
6424#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6425 /* Since t_me has been set, this probably means that the user
6426 * wants to use this as default colors. Need to reset default
6427 * background/foreground colors. */
6428 mch_set_normal_colors();
6429#endif
6430 }
6431 }
6432
6433#ifdef FEAT_LINEBREAK
6434 /* 'showbreak' */
6435 else if (varp == &p_sbr)
6436 {
6437 for (s = p_sbr; *s; )
6438 {
6439 if (ptr2cells(s) != 1)
6440 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006441 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006442 }
6443 }
6444#endif
6445
6446#ifdef FEAT_GUI
6447 /* 'guifont' */
6448 else if (varp == &p_guifont)
6449 {
6450 if (gui.in_use)
6451 {
6452 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006453# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454 /*
6455 * Put up a font dialog and let the user select a new value.
6456 * If this is cancelled go back to the old value but don't
6457 * give an error message.
6458 */
6459 if (STRCMP(p, "*") == 0)
6460 {
6461 p = gui_mch_font_dialog(oldval);
6462
6463 if (new_value_alloced)
6464 free_string_option(p_guifont);
6465
6466 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6467 new_value_alloced = TRUE;
6468 }
6469# endif
6470 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6471 {
6472# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6473 if (STRCMP(p_guifont, "*") == 0)
6474 {
6475 /* Dialog was cancelled: Keep the old value without giving
6476 * an error message. */
6477 if (new_value_alloced)
6478 free_string_option(p_guifont);
6479 p_guifont = vim_strsave(oldval);
6480 new_value_alloced = TRUE;
6481 }
6482 else
6483# endif
6484 errmsg = (char_u *)N_("E596: Invalid font(s)");
6485 }
6486 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006487 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006488 }
6489# ifdef FEAT_XFONTSET
6490 else if (varp == &p_guifontset)
6491 {
6492 if (STRCMP(p_guifontset, "*") == 0)
6493 errmsg = (char_u *)N_("E597: can't select fontset");
6494 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6495 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006496 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006497 }
6498# endif
6499# ifdef FEAT_MBYTE
6500 else if (varp == &p_guifontwide)
6501 {
6502 if (STRCMP(p_guifontwide, "*") == 0)
6503 errmsg = (char_u *)N_("E533: can't select wide font");
6504 else if (gui_get_wide_font() == FAIL)
6505 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006506 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006507 }
6508# endif
6509#endif
6510
6511#ifdef CURSOR_SHAPE
6512 /* 'guicursor' */
6513 else if (varp == &p_guicursor)
6514 errmsg = parse_shape_opt(SHAPE_CURSOR);
6515#endif
6516
6517#ifdef FEAT_MOUSESHAPE
6518 /* 'mouseshape' */
6519 else if (varp == &p_mouseshape)
6520 {
6521 errmsg = parse_shape_opt(SHAPE_MOUSE);
6522 update_mouseshape(-1);
6523 }
6524#endif
6525
6526#ifdef FEAT_PRINTER
6527 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006528 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006529# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006530 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006531 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006532# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006533#endif
6534
6535#ifdef FEAT_LANGMAP
6536 /* 'langmap' */
6537 else if (varp == &p_langmap)
6538 langmap_set();
6539#endif
6540
6541#ifdef FEAT_LINEBREAK
6542 /* 'breakat' */
6543 else if (varp == &p_breakat)
6544 fill_breakat_flags();
6545#endif
6546
6547#ifdef FEAT_TITLE
6548 /* 'titlestring' and 'iconstring' */
6549 else if (varp == &p_titlestring || varp == &p_iconstring)
6550 {
6551# ifdef FEAT_STL_OPT
6552 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6553
6554 /* NULL => statusline syntax */
6555 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6556 stl_syntax |= flagval;
6557 else
6558 stl_syntax &= ~flagval;
6559# endif
6560 did_set_title(varp == &p_iconstring);
6561
6562 }
6563#endif
6564
6565#ifdef FEAT_GUI
6566 /* 'guioptions' */
6567 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006568 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006569 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006570 redraw_gui_only = TRUE;
6571 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006572#endif
6573
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006574#if defined(FEAT_GUI_TABLINE)
6575 /* 'guitablabel' */
6576 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006577 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006578 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006579 redraw_gui_only = TRUE;
6580 }
6581 /* 'guitabtooltip' */
6582 else if (varp == &p_gtt)
6583 {
6584 redraw_gui_only = TRUE;
6585 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006586#endif
6587
Bram Moolenaar071d4272004-06-13 20:20:40 +00006588#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6589 /* 'ttymouse' */
6590 else if (varp == &p_ttym)
6591 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006592 /* Switch the mouse off before changing the escape sequences used for
6593 * that. */
6594 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006595 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6596 errmsg = e_invarg;
6597 else
6598 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006599 if (termcap_active)
6600 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006601 }
6602#endif
6603
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604 /* 'selection' */
6605 else if (varp == &p_sel)
6606 {
6607 if (*p_sel == NUL
6608 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6609 errmsg = e_invarg;
6610 }
6611
6612 /* 'selectmode' */
6613 else if (varp == &p_slm)
6614 {
6615 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6616 errmsg = e_invarg;
6617 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618
6619#ifdef FEAT_BROWSE
6620 /* 'browsedir' */
6621 else if (varp == &p_bsdir)
6622 {
6623 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6624 && !mch_isdir(p_bsdir))
6625 errmsg = e_invarg;
6626 }
6627#endif
6628
Bram Moolenaar071d4272004-06-13 20:20:40 +00006629 /* 'keymodel' */
6630 else if (varp == &p_km)
6631 {
6632 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6633 errmsg = e_invarg;
6634 else
6635 {
6636 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6637 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6638 }
6639 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006640
6641 /* 'mousemodel' */
6642 else if (varp == &p_mousem)
6643 {
6644 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6645 errmsg = e_invarg;
6646#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6647 else if (*p_mousem != *oldval)
6648 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6649 * to create or delete the popup menus. */
6650 gui_motif_update_mousemodel(root_menu);
6651#endif
6652 }
6653
6654 /* 'switchbuf' */
6655 else if (varp == &p_swb)
6656 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006657 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006658 errmsg = e_invarg;
6659 }
6660
6661 /* 'debug' */
6662 else if (varp == &p_debug)
6663 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006664 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665 errmsg = e_invarg;
6666 }
6667
6668 /* 'display' */
6669 else if (varp == &p_dy)
6670 {
6671 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6672 errmsg = e_invarg;
6673 else
6674 (void)init_chartab();
6675
6676 }
6677
6678#ifdef FEAT_VERTSPLIT
6679 /* 'eadirection' */
6680 else if (varp == &p_ead)
6681 {
6682 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6683 errmsg = e_invarg;
6684 }
6685#endif
6686
6687#ifdef FEAT_CLIPBOARD
6688 /* 'clipboard' */
6689 else if (varp == &p_cb)
6690 errmsg = check_clipboard_option();
6691#endif
6692
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006693#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006694 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6695 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006696 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006697 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006698 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006699 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006700
Bram Moolenaar860cae12010-06-05 23:22:07 +02006701 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006702 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006703 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6704 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006705 ".add") != 0))
6706 errmsg = e_invarg;
6707 }
6708
6709 if (errmsg == NULL)
6710 {
6711 FOR_ALL_WINDOWS(wp)
6712 if (wp->w_buffer == curbuf && wp->w_p_spell)
6713 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006714 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006715# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006716 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006717# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006718 }
6719 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006720 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006721 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006722 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006723 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006724 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006725 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006726 /* 'spellsuggest' */
6727 else if (varp == &p_sps)
6728 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006729 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006730 errmsg = e_invarg;
6731 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006732 /* 'mkspellmem' */
6733 else if (varp == &p_msm)
6734 {
6735 if (spell_check_msm() != OK)
6736 errmsg = e_invarg;
6737 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006738#endif
6739
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740#ifdef FEAT_QUICKFIX
6741 /* When 'bufhidden' is set, check for valid value. */
6742 else if (gvarp == &p_bh)
6743 {
6744 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6745 errmsg = e_invarg;
6746 }
6747
6748 /* When 'buftype' is set, check for valid value. */
6749 else if (gvarp == &p_bt)
6750 {
6751 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6752 errmsg = e_invarg;
6753 else
6754 {
6755# ifdef FEAT_WINDOWS
6756 if (curwin->w_status_height)
6757 {
6758 curwin->w_redr_status = TRUE;
6759 redraw_later(VALID);
6760 }
6761# endif
6762 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006763# ifdef FEAT_TITLE
6764 redraw_titles();
6765# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006766 }
6767 }
6768#endif
6769
6770#ifdef FEAT_STL_OPT
6771 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006772 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006773 {
6774 int wid;
6775
6776 if (varp == &p_ruf) /* reset ru_wid first */
6777 ru_wid = 0;
6778 s = *varp;
6779 if (varp == &p_ruf && *s == '%')
6780 {
6781 /* set ru_wid if 'ruf' starts with "%99(" */
6782 if (*++s == '-') /* ignore a '-' */
6783 s++;
6784 wid = getdigits(&s);
6785 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6786 ru_wid = wid;
6787 else
6788 errmsg = check_stl_option(p_ruf);
6789 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006790 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006791 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006793 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006794 comp_col();
6795 }
6796#endif
6797
6798#ifdef FEAT_INS_EXPAND
6799 /* check if it is a valid value for 'complete' -- Acevedo */
6800 else if (gvarp == &p_cpt)
6801 {
6802 for (s = *varp; *s;)
6803 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006804 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006805 s++;
6806 if (!*s)
6807 break;
6808 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6809 {
6810 errmsg = illegal_char(errbuf, *s);
6811 break;
6812 }
6813 if (*++s != NUL && *s != ',' && *s != ' ')
6814 {
6815 if (s[-1] == 'k' || s[-1] == 's')
6816 {
6817 /* skip optional filename after 'k' and 's' */
6818 while (*s && *s != ',' && *s != ' ')
6819 {
6820 if (*s == '\\')
6821 ++s;
6822 ++s;
6823 }
6824 }
6825 else
6826 {
6827 if (errbuf != NULL)
6828 {
6829 sprintf((char *)errbuf,
6830 _("E535: Illegal character after <%c>"),
6831 *--s);
6832 errmsg = errbuf;
6833 }
6834 else
6835 errmsg = (char_u *)"";
6836 break;
6837 }
6838 }
6839 }
6840 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006841
6842 /* 'completeopt' */
6843 else if (varp == &p_cot)
6844 {
6845 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6846 errmsg = e_invarg;
6847 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006848#endif /* FEAT_INS_EXPAND */
6849
6850
6851#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6852 else if (varp == &p_toolbar)
6853 {
6854 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6855 &toolbar_flags, TRUE) != OK)
6856 errmsg = e_invarg;
6857 else
6858 {
6859 out_flush();
6860 gui_mch_show_toolbar((toolbar_flags &
6861 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6862 }
6863 }
6864#endif
6865
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006866#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006867 /* 'toolbariconsize': GTK+ 2 only */
6868 else if (varp == &p_tbis)
6869 {
6870 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6871 errmsg = e_invarg;
6872 else
6873 {
6874 out_flush();
6875 gui_mch_show_toolbar((toolbar_flags &
6876 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6877 }
6878 }
6879#endif
6880
6881 /* 'pastetoggle': translate key codes like in a mapping */
6882 else if (varp == &p_pt)
6883 {
6884 if (*p_pt)
6885 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006886 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006887 if (p != NULL)
6888 {
6889 if (new_value_alloced)
6890 free_string_option(p_pt);
6891 p_pt = p;
6892 new_value_alloced = TRUE;
6893 }
6894 }
6895 }
6896
6897 /* 'backspace' */
6898 else if (varp == &p_bs)
6899 {
6900 if (VIM_ISDIGIT(*p_bs))
6901 {
6902 if (*p_bs >'2' || p_bs[1] != NUL)
6903 errmsg = e_invarg;
6904 }
6905 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6906 errmsg = e_invarg;
6907 }
6908
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006909#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 /* 'casemap' */
6911 else if (varp == &p_cmp)
6912 {
6913 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6914 errmsg = e_invarg;
6915 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006916#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917
6918#ifdef FEAT_DIFF
6919 /* 'diffopt' */
6920 else if (varp == &p_dip)
6921 {
6922 if (diffopt_changed() == FAIL)
6923 errmsg = e_invarg;
6924 }
6925#endif
6926
6927#ifdef FEAT_FOLDING
6928 /* 'foldmethod' */
6929 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6930 {
6931 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6932 || *curwin->w_p_fdm == NUL)
6933 errmsg = e_invarg;
6934 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006935 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006937 if (foldmethodIsDiff(curwin))
6938 newFoldLevel();
6939 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006940 }
6941# ifdef FEAT_EVAL
6942 /* 'foldexpr' */
6943 else if (varp == &curwin->w_p_fde)
6944 {
6945 if (foldmethodIsExpr(curwin))
6946 foldUpdateAll(curwin);
6947 }
6948# endif
6949 /* 'foldmarker' */
6950 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6951 {
6952 p = vim_strchr(*varp, ',');
6953 if (p == NULL)
6954 errmsg = (char_u *)N_("E536: comma required");
6955 else if (p == *varp || p[1] == NUL)
6956 errmsg = e_invarg;
6957 else if (foldmethodIsMarker(curwin))
6958 foldUpdateAll(curwin);
6959 }
6960 /* 'commentstring' */
6961 else if (gvarp == &p_cms)
6962 {
6963 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6964 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6965 }
6966 /* 'foldopen' */
6967 else if (varp == &p_fdo)
6968 {
6969 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6970 errmsg = e_invarg;
6971 }
6972 /* 'foldclose' */
6973 else if (varp == &p_fcl)
6974 {
6975 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6976 errmsg = e_invarg;
6977 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006978 /* 'foldignore' */
6979 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6980 {
6981 if (foldmethodIsIndent(curwin))
6982 foldUpdateAll(curwin);
6983 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006984#endif
6985
6986#ifdef FEAT_VIRTUALEDIT
6987 /* 'virtualedit' */
6988 else if (varp == &p_ve)
6989 {
6990 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6991 errmsg = e_invarg;
6992 else if (STRCMP(p_ve, oldval) != 0)
6993 {
6994 /* Recompute cursor position in case the new 've' setting
6995 * changes something. */
6996 validate_virtcol();
6997 coladvance(curwin->w_virtcol);
6998 }
6999 }
7000#endif
7001
7002#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7003 else if (varp == &p_csqf)
7004 {
7005 if (p_csqf != NULL)
7006 {
7007 p = p_csqf;
7008 while (*p != NUL)
7009 {
7010 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7011 || p[1] == NUL
7012 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7013 || (p[2] != NUL && p[2] != ','))
7014 {
7015 errmsg = e_invarg;
7016 break;
7017 }
7018 else if (p[2] == NUL)
7019 break;
7020 else
7021 p += 3;
7022 }
7023 }
7024 }
7025#endif
7026
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007027#ifdef FEAT_CINDENT
7028 /* 'cinoptions' */
7029 else if (gvarp == &p_cino)
7030 {
7031 /* TODO: recognize errors */
7032 parse_cino(curbuf);
7033 }
7034#endif
7035
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007036#if defined(FEAT_RENDER_OPTIONS)
7037 else if (varp == &p_rop && gui.in_use)
7038 {
7039 if (!gui_mch_set_rendering_options(p_rop))
7040 errmsg = e_invarg;
7041 }
7042#endif
7043
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044 /* Options that are a list of flags. */
7045 else
7046 {
7047 p = NULL;
7048 if (varp == &p_ww)
7049 p = (char_u *)WW_ALL;
7050 if (varp == &p_shm)
7051 p = (char_u *)SHM_ALL;
7052 else if (varp == &(p_cpo))
7053 p = (char_u *)CPO_ALL;
7054 else if (varp == &(curbuf->b_p_fo))
7055 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007056#ifdef FEAT_CONCEAL
7057 else if (varp == &curwin->w_p_cocu)
7058 p = (char_u *)COCU_ALL;
7059#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007060 else if (varp == &p_mouse)
7061 {
7062#ifdef FEAT_MOUSE
7063 p = (char_u *)MOUSE_ALL;
7064#else
7065 if (*p_mouse != NUL)
7066 errmsg = (char_u *)N_("E538: No mouse support");
7067#endif
7068 }
7069#if defined(FEAT_GUI)
7070 else if (varp == &p_go)
7071 p = (char_u *)GO_ALL;
7072#endif
7073 if (p != NULL)
7074 {
7075 for (s = *varp; *s; ++s)
7076 if (vim_strchr(p, *s) == NULL)
7077 {
7078 errmsg = illegal_char(errbuf, *s);
7079 break;
7080 }
7081 }
7082 }
7083
7084 /*
7085 * If error detected, restore the previous value.
7086 */
7087 if (errmsg != NULL)
7088 {
7089 if (new_value_alloced)
7090 free_string_option(*varp);
7091 *varp = oldval;
7092 /*
7093 * When resetting some values, need to act on it.
7094 */
7095 if (did_chartab)
7096 (void)init_chartab();
7097 if (varp == &p_hl)
7098 (void)highlight_changed();
7099 }
7100 else
7101 {
7102#ifdef FEAT_EVAL
7103 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007104 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007105#endif
7106 /*
7107 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007108 * Use "free_oldval", because recursiveness may change the flags under
7109 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007110 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007111 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007112 free_string_option(oldval);
7113 if (new_value_alloced)
7114 options[opt_idx].flags |= P_ALLOCED;
7115 else
7116 options[opt_idx].flags &= ~P_ALLOCED;
7117
7118 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007119 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120 {
7121 /* global option with local value set to use global value; free
7122 * the local value and make it empty */
7123 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7124 free_string_option(*(char_u **)p);
7125 *(char_u **)p = empty_option;
7126 }
7127
7128 /* May set global value for local option. */
7129 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7130 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007131
7132#ifdef FEAT_AUTOCMD
7133 /*
7134 * Trigger the autocommand only after setting the flags.
7135 */
7136# ifdef FEAT_SYN_HL
7137 /* When 'syntax' is set, load the syntax of that name */
7138 if (varp == &(curbuf->b_p_syn))
7139 {
7140 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7141 curbuf->b_fname, TRUE, curbuf);
7142 }
7143# endif
7144 else if (varp == &(curbuf->b_p_ft))
7145 {
7146 /* 'filetype' is set, trigger the FileType autocommand */
7147 did_filetype = TRUE;
7148 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7149 curbuf->b_fname, TRUE, curbuf);
7150 }
7151#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007152#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007153 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007154 {
7155 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007156 char_u *q = curwin->w_s->b_p_spl;
7157
7158 /* Skip the first name if it is "cjk". */
7159 if (STRNCMP(q, "cjk,", 4) == 0)
7160 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007161
7162 /*
7163 * Source the spell/LANG.vim in 'runtimepath'.
7164 * They could set 'spellcapcheck' depending on the language.
7165 * Use the first name in 'spelllang' up to '_region' or
7166 * '.encoding'.
7167 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007168 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007169 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7170 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007171 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007172 source_runtime(fname, TRUE);
7173 }
7174#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007175 }
7176
7177#ifdef FEAT_MOUSE
7178 if (varp == &p_mouse)
7179 {
7180# ifdef FEAT_MOUSE_TTY
7181 if (*p_mouse == NUL)
7182 mch_setmouse(FALSE); /* switch mouse off */
7183 else
7184# endif
7185 setmouse(); /* in case 'mouse' changed */
7186 }
7187#endif
7188
Bram Moolenaar913077c2012-03-28 19:59:04 +02007189 if (curwin->w_curswant != MAXCOL
7190 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7191 curwin->w_set_curswant = TRUE;
7192
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007193#ifdef FEAT_GUI
7194 /* check redraw when it's not a GUI option or the GUI is active. */
7195 if (!redraw_gui_only || gui.in_use)
7196#endif
7197 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007198
7199 return errmsg;
7200}
7201
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007202#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007203/*
7204 * Simple int comparison function for use with qsort()
7205 */
7206 static int
7207int_cmp(a, b)
7208 const void *a;
7209 const void *b;
7210{
7211 return *(const int *)a - *(const int *)b;
7212}
7213
7214/*
7215 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7216 * Returns error message, NULL if it's OK.
7217 */
7218 char_u *
7219check_colorcolumn(wp)
7220 win_T *wp;
7221{
7222 char_u *s;
7223 int col;
7224 int count = 0;
7225 int color_cols[256];
7226 int i;
7227 int j = 0;
7228
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007229 if (wp->w_buffer == NULL)
7230 return NULL; /* buffer was closed */
7231
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007232 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007233 {
7234 if (*s == '-' || *s == '+')
7235 {
7236 /* -N and +N: add to 'textwidth' */
7237 col = (*s == '-') ? -1 : 1;
7238 ++s;
7239 if (!VIM_ISDIGIT(*s))
7240 return e_invarg;
7241 col = col * getdigits(&s);
7242 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007243 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007244 col += wp->w_buffer->b_p_tw;
7245 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007246 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007247 }
7248 else if (VIM_ISDIGIT(*s))
7249 col = getdigits(&s);
7250 else
7251 return e_invarg;
7252 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007253skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007254 if (*s == NUL)
7255 break;
7256 if (*s != ',')
7257 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007258 if (*++s == NUL)
7259 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007260 }
7261
7262 vim_free(wp->w_p_cc_cols);
7263 if (count == 0)
7264 wp->w_p_cc_cols = NULL;
7265 else
7266 {
7267 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7268 if (wp->w_p_cc_cols != NULL)
7269 {
7270 /* sort the columns for faster usage on screen redraw inside
7271 * win_line() */
7272 qsort(color_cols, count, sizeof(int), int_cmp);
7273
7274 for (i = 0; i < count; ++i)
7275 /* skip duplicates */
7276 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7277 wp->w_p_cc_cols[j++] = color_cols[i];
7278 wp->w_p_cc_cols[j] = -1; /* end marker */
7279 }
7280 }
7281
7282 return NULL; /* no error */
7283}
7284#endif
7285
Bram Moolenaar071d4272004-06-13 20:20:40 +00007286/*
7287 * Handle setting 'listchars' or 'fillchars'.
7288 * Returns error message, NULL if it's OK.
7289 */
7290 static char_u *
7291set_chars_option(varp)
7292 char_u **varp;
7293{
7294 int round, i, len, entries;
7295 char_u *p, *s;
7296 int c1, c2 = 0;
7297 struct charstab
7298 {
7299 int *cp;
7300 char *name;
7301 };
7302#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7303 static struct charstab filltab[] =
7304 {
7305 {&fill_stl, "stl"},
7306 {&fill_stlnc, "stlnc"},
7307 {&fill_vert, "vert"},
7308 {&fill_fold, "fold"},
7309 {&fill_diff, "diff"},
7310 };
7311#endif
7312 static struct charstab lcstab[] =
7313 {
7314 {&lcs_eol, "eol"},
7315 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007316 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317 {&lcs_prec, "precedes"},
7318 {&lcs_tab2, "tab"},
7319 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007320#ifdef FEAT_CONCEAL
7321 {&lcs_conceal, "conceal"},
7322#else
7323 {NULL, "conceal"},
7324#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007325 };
7326 struct charstab *tab;
7327
7328#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7329 if (varp == &p_lcs)
7330#endif
7331 {
7332 tab = lcstab;
7333 entries = sizeof(lcstab) / sizeof(struct charstab);
7334 }
7335#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7336 else
7337 {
7338 tab = filltab;
7339 entries = sizeof(filltab) / sizeof(struct charstab);
7340 }
7341#endif
7342
7343 /* first round: check for valid value, second round: assign values */
7344 for (round = 0; round <= 1; ++round)
7345 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007346 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007347 {
7348 /* After checking that the value is valid: set defaults: space for
7349 * 'fillchars', NUL for 'listchars' */
7350 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007351 if (tab[i].cp != NULL)
7352 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007353 if (varp == &p_lcs)
7354 lcs_tab1 = NUL;
7355#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7356 else
7357 fill_diff = '-';
7358#endif
7359 }
7360 p = *varp;
7361 while (*p)
7362 {
7363 for (i = 0; i < entries; ++i)
7364 {
7365 len = (int)STRLEN(tab[i].name);
7366 if (STRNCMP(p, tab[i].name, len) == 0
7367 && p[len] == ':'
7368 && p[len + 1] != NUL)
7369 {
7370 s = p + len + 1;
7371#ifdef FEAT_MBYTE
7372 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007373 if (mb_char2cells(c1) > 1)
7374 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007375#else
7376 c1 = *s++;
7377#endif
7378 if (tab[i].cp == &lcs_tab2)
7379 {
7380 if (*s == NUL)
7381 continue;
7382#ifdef FEAT_MBYTE
7383 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007384 if (mb_char2cells(c2) > 1)
7385 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007386#else
7387 c2 = *s++;
7388#endif
7389 }
7390 if (*s == ',' || *s == NUL)
7391 {
7392 if (round)
7393 {
7394 if (tab[i].cp == &lcs_tab2)
7395 {
7396 lcs_tab1 = c1;
7397 lcs_tab2 = c2;
7398 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007399 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007400 *(tab[i].cp) = c1;
7401
7402 }
7403 p = s;
7404 break;
7405 }
7406 }
7407 }
7408
7409 if (i == entries)
7410 return e_invarg;
7411 if (*p == ',')
7412 ++p;
7413 }
7414 }
7415
7416 return NULL; /* no error */
7417}
7418
7419#ifdef FEAT_STL_OPT
7420/*
7421 * Check validity of options with the 'statusline' format.
7422 * Return error message or NULL.
7423 */
7424 char_u *
7425check_stl_option(s)
7426 char_u *s;
7427{
7428 int itemcnt = 0;
7429 int groupdepth = 0;
7430 static char_u errbuf[80];
7431
7432 while (*s && itemcnt < STL_MAX_ITEM)
7433 {
7434 /* Check for valid keys after % sequences */
7435 while (*s && *s != '%')
7436 s++;
7437 if (!*s)
7438 break;
7439 s++;
7440 if (*s != '%' && *s != ')')
7441 ++itemcnt;
7442 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7443 {
7444 s++;
7445 continue;
7446 }
7447 if (*s == ')')
7448 {
7449 s++;
7450 if (--groupdepth < 0)
7451 break;
7452 continue;
7453 }
7454 if (*s == '-')
7455 s++;
7456 while (VIM_ISDIGIT(*s))
7457 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007458 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007459 continue;
7460 if (*s == '.')
7461 {
7462 s++;
7463 while (*s && VIM_ISDIGIT(*s))
7464 s++;
7465 }
7466 if (*s == '(')
7467 {
7468 groupdepth++;
7469 continue;
7470 }
7471 if (vim_strchr(STL_ALL, *s) == NULL)
7472 {
7473 return illegal_char(errbuf, *s);
7474 }
7475 if (*s == '{')
7476 {
7477 s++;
7478 while (*s != '}' && *s)
7479 s++;
7480 if (*s != '}')
7481 return (char_u *)N_("E540: Unclosed expression sequence");
7482 }
7483 }
7484 if (itemcnt >= STL_MAX_ITEM)
7485 return (char_u *)N_("E541: too many items");
7486 if (groupdepth != 0)
7487 return (char_u *)N_("E542: unbalanced groups");
7488 return NULL;
7489}
7490#endif
7491
7492#ifdef FEAT_CLIPBOARD
7493/*
7494 * Extract the items in the 'clipboard' option and set global values.
7495 */
7496 static char_u *
7497check_clipboard_option()
7498{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007499 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007500 int new_autoselect_star = FALSE;
7501 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007502 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007503 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504 regprog_T *new_exclude_prog = NULL;
7505 char_u *errmsg = NULL;
7506 char_u *p;
7507
7508 for (p = p_cb; *p != NUL; )
7509 {
7510 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7511 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007512 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513 p += 7;
7514 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007515 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007516 && (p[11] == ',' || p[11] == NUL))
7517 {
7518 new_unnamed |= CLIP_UNNAMED_PLUS;
7519 p += 11;
7520 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007522 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007523 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007524 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007525 p += 10;
7526 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007527 else if (STRNCMP(p, "autoselectplus", 14) == 0
7528 && (p[14] == ',' || p[14] == NUL))
7529 {
7530 new_autoselect_plus = TRUE;
7531 p += 14;
7532 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007533 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007534 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007535 {
7536 new_autoselectml = TRUE;
7537 p += 12;
7538 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007539 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7540 {
7541 new_html = TRUE;
7542 p += 4;
7543 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007544 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7545 {
7546 p += 8;
7547 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7548 if (new_exclude_prog == NULL)
7549 errmsg = e_invarg;
7550 break;
7551 }
7552 else
7553 {
7554 errmsg = e_invarg;
7555 break;
7556 }
7557 if (*p == ',')
7558 ++p;
7559 }
7560 if (errmsg == NULL)
7561 {
7562 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007563 clip_autoselect_star = new_autoselect_star;
7564 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007565 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007566 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007567 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007568 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007569#ifdef FEAT_GUI_GTK
7570 if (gui.in_use)
7571 {
7572 gui_gtk_set_selection_targets();
7573 gui_gtk_set_dnd_targets();
7574 }
7575#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007576 }
7577 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007578 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007579
7580 return errmsg;
7581}
7582#endif
7583
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007584#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007585/*
7586 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7587 * Return error message when failed, NULL when OK.
7588 */
7589 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007590compile_cap_prog(synblock)
7591 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007592{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007593 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007594 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007595
Bram Moolenaar860cae12010-06-05 23:22:07 +02007596 if (*synblock->b_p_spc == NUL)
7597 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007598 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007599 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007600 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007601 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007602 if (re != NULL)
7603 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007604 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007605 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007606 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007607 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007608 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007609 return e_invarg;
7610 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007611 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007612 }
7613
Bram Moolenaar473de612013-06-08 18:19:48 +02007614 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007615 return NULL;
7616}
7617#endif
7618
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007619#if defined(FEAT_EVAL) || defined(PROTO)
7620/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007621 * Set the scriptID for an option, taking care of setting the buffer- or
7622 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007623 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007624 static void
7625set_option_scriptID_idx(opt_idx, opt_flags, id)
7626 int opt_idx;
7627 int opt_flags;
7628 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007629{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007630 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7631 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007632
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007633 /* Remember where the option was set. For local options need to do that
7634 * in the buffer or window structure. */
7635 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007636 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007637 if (both || (opt_flags & OPT_LOCAL))
7638 {
7639 if (indir & PV_BUF)
7640 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7641 else if (indir & PV_WIN)
7642 curwin->w_p_scriptID[indir & PV_MASK] = id;
7643 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007644}
7645#endif
7646
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647/*
7648 * Set the value of a boolean option, and take care of side effects.
7649 * Returns NULL for success, or an error message for an error.
7650 */
7651 static char_u *
7652set_bool_option(opt_idx, varp, value, opt_flags)
7653 int opt_idx; /* index in options[] table */
7654 char_u *varp; /* pointer to the option variable */
7655 int value; /* new value */
7656 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7657{
7658 int old_value = *(int *)varp;
7659
Bram Moolenaar071d4272004-06-13 20:20:40 +00007660 /* Disallow changing some options from secure mode */
7661 if ((secure
7662#ifdef HAVE_SANDBOX
7663 || sandbox != 0
7664#endif
7665 ) && (options[opt_idx].flags & P_SECURE))
7666 return e_secure;
7667
7668 *(int *)varp = value; /* set the new value */
7669#ifdef FEAT_EVAL
7670 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007671 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007672#endif
7673
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007674#ifdef FEAT_GUI
7675 need_mouse_correct = TRUE;
7676#endif
7677
Bram Moolenaar071d4272004-06-13 20:20:40 +00007678 /* May set global value for local option. */
7679 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7680 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7681
7682 /*
7683 * Handle side effects of changing a bool option.
7684 */
7685
7686 /* 'compatible' */
7687 if ((int *)varp == &p_cp)
7688 {
7689 compatible_set();
7690 }
7691
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007692#ifdef FEAT_PERSISTENT_UNDO
7693 /* 'undofile' */
7694 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7695 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007696 /* Only take action when the option was set. When reset we do not
7697 * delete the undo file, the option may be set again without making
7698 * any changes in between. */
7699 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007700 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007701 char_u hash[UNDO_HASH_SIZE];
7702 buf_T *save_curbuf = curbuf;
7703
7704 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007705 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007706 /* When 'undofile' is set globally: for every buffer, otherwise
7707 * only for the current buffer: Try to read in the undofile,
7708 * if one exists, the buffer wasn't changed and the buffer was
7709 * loaded */
7710 if ((curbuf == save_curbuf
7711 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7712 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7713 {
7714 u_compute_hash(hash);
7715 u_read_undo(NULL, hash, curbuf->b_fname);
7716 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007717 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007718 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007719 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007720 }
7721#endif
7722
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723 else if ((int *)varp == &curbuf->b_p_ro)
7724 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007725 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007726 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7727 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007728
7729 /* when 'readonly' is set may give W10 again */
7730 if (curbuf->b_p_ro)
7731 curbuf->b_did_warn = FALSE;
7732
Bram Moolenaar071d4272004-06-13 20:20:40 +00007733#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007734 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735#endif
7736 }
7737
Bram Moolenaar9c449722010-07-20 18:44:27 +02007738#ifdef FEAT_GUI
7739 else if ((int *)varp == &p_mh)
7740 {
7741 if (!p_mh)
7742 gui_mch_mousehide(FALSE);
7743 }
7744#endif
7745
Bram Moolenaara539df02010-08-01 14:35:05 +02007746#ifdef FEAT_TITLE
7747 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007749 {
7750 redraw_titles();
7751 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007752 /* when 'endofline' is changed, redraw the window title */
7753 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007754 {
7755 redraw_titles();
7756 }
7757# ifdef FEAT_MBYTE
7758 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007759 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007760 {
7761 redraw_titles();
7762 }
7763# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007764#endif
7765
7766 /* when 'bin' is set also set some other options */
7767 else if ((int *)varp == &curbuf->b_p_bin)
7768 {
7769 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7770#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007771 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007772#endif
7773 }
7774
7775#ifdef FEAT_AUTOCMD
7776 /* when 'buflisted' changes, trigger autocommands */
7777 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7778 {
7779 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7780 NULL, NULL, TRUE, curbuf);
7781 }
7782#endif
7783
7784 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7785 else if ((int *)varp == &curbuf->b_p_swf)
7786 {
7787 if (curbuf->b_p_swf && p_uc)
7788 ml_open_file(curbuf); /* create the swap file */
7789 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007790 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7791 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007792 mf_close_file(curbuf, TRUE); /* remove the swap file */
7793 }
7794
7795 /* when 'terse' is set change 'shortmess' */
7796 else if ((int *)varp == &p_terse)
7797 {
7798 char_u *p;
7799
7800 p = vim_strchr(p_shm, SHM_SEARCH);
7801
7802 /* insert 's' in p_shm */
7803 if (p_terse && p == NULL)
7804 {
7805 STRCPY(IObuff, p_shm);
7806 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007807 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007808 }
7809 /* remove 's' from p_shm */
7810 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007811 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007812 }
7813
7814 /* when 'paste' is set or reset also change other options */
7815 else if ((int *)varp == &p_paste)
7816 {
7817 paste_option_changed();
7818 }
7819
7820 /* when 'insertmode' is set from an autocommand need to do work here */
7821 else if ((int *)varp == &p_im)
7822 {
7823 if (p_im)
7824 {
7825 if ((State & INSERT) == 0)
7826 need_start_insertmode = TRUE;
7827 stop_insert_mode = FALSE;
7828 }
7829 else
7830 {
7831 need_start_insertmode = FALSE;
7832 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007833 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007834 clear_cmdline = TRUE; /* remove "(insert)" */
7835 restart_edit = 0;
7836 }
7837 }
7838
7839 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7840 else if ((int *)varp == &p_ic && p_hls)
7841 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007842 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007843 }
7844
7845#ifdef FEAT_SEARCH_EXTRA
7846 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7847 else if ((int *)varp == &p_hls)
7848 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007849 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850 }
7851#endif
7852
7853#ifdef FEAT_SCROLLBIND
7854 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7855 * at the end of normal_cmd() */
7856 else if ((int *)varp == &curwin->w_p_scb)
7857 {
7858 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007859 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007860 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007861 curwin->w_scbind_pos = curwin->w_topline;
7862 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007863 }
7864#endif
7865
7866#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7867 /* There can be only one window with 'previewwindow' set. */
7868 else if ((int *)varp == &curwin->w_p_pvw)
7869 {
7870 if (curwin->w_p_pvw)
7871 {
7872 win_T *win;
7873
7874 for (win = firstwin; win != NULL; win = win->w_next)
7875 if (win->w_p_pvw && win != curwin)
7876 {
7877 curwin->w_p_pvw = FALSE;
7878 return (char_u *)N_("E590: A preview window already exists");
7879 }
7880 }
7881 }
7882#endif
7883
7884 /* when 'textmode' is set or reset also change 'fileformat' */
7885 else if ((int *)varp == &curbuf->b_p_tx)
7886 {
7887 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7888 }
7889
7890 /* when 'textauto' is set or reset also change 'fileformats' */
7891 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 set_string_option_direct((char_u *)"ffs", -1,
7893 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007894 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895
7896 /*
7897 * When 'lisp' option changes include/exclude '-' in
7898 * keyword characters.
7899 */
7900#ifdef FEAT_LISP
7901 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7902 {
7903 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7904 }
7905#endif
7906
7907#ifdef FEAT_TITLE
7908 /* when 'title' changed, may need to change the title; same for 'icon' */
7909 else if ((int *)varp == &p_title)
7910 {
7911 did_set_title(FALSE);
7912 }
7913
7914 else if ((int *)varp == &p_icon)
7915 {
7916 did_set_title(TRUE);
7917 }
7918#endif
7919
7920 else if ((int *)varp == &curbuf->b_changed)
7921 {
7922 if (!value)
7923 save_file_ff(curbuf); /* Buffer is unchanged */
7924#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007925 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926#endif
7927#ifdef FEAT_AUTOCMD
7928 modified_was_set = value;
7929#endif
7930 }
7931
7932#ifdef BACKSLASH_IN_FILENAME
7933 else if ((int *)varp == &p_ssl)
7934 {
7935 if (p_ssl)
7936 {
7937 psepc = '/';
7938 psepcN = '\\';
7939 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007940 }
7941 else
7942 {
7943 psepc = '\\';
7944 psepcN = '/';
7945 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946 }
7947
7948 /* need to adjust the file name arguments and buffer names. */
7949 buflist_slash_adjust();
7950 alist_slash_adjust();
7951# ifdef FEAT_EVAL
7952 scriptnames_slash_adjust();
7953# endif
7954 }
7955#endif
7956
7957 /* If 'wrap' is set, set w_leftcol to zero. */
7958 else if ((int *)varp == &curwin->w_p_wrap)
7959 {
7960 if (curwin->w_p_wrap)
7961 curwin->w_leftcol = 0;
7962 }
7963
7964#ifdef FEAT_WINDOWS
7965 else if ((int *)varp == &p_ea)
7966 {
7967 if (p_ea && !old_value)
7968 win_equal(curwin, FALSE, 0);
7969 }
7970#endif
7971
7972 else if ((int *)varp == &p_wiv)
7973 {
7974 /*
7975 * When 'weirdinvert' changed, set/reset 't_xs'.
7976 * Then set 'weirdinvert' according to value of 't_xs'.
7977 */
7978 if (p_wiv && !old_value)
7979 T_XS = (char_u *)"y";
7980 else if (!p_wiv && old_value)
7981 T_XS = empty_option;
7982 p_wiv = (*T_XS != NUL);
7983 }
7984
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007985#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007986 else if ((int *)varp == &p_beval)
7987 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007988 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007989 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007990 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007991 gui_mch_disable_beval_area(balloonEval);
7992 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007993#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007994
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007995#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996 else if ((int *)varp == &p_acd)
7997 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00007998 /* Change directories when the 'acd' option is set now. */
7999 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008000 }
8001#endif
8002
8003#ifdef FEAT_DIFF
8004 /* 'diff' */
8005 else if ((int *)varp == &curwin->w_p_diff)
8006 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008007 /* May add or remove the buffer from the list of diff buffers. */
8008 diff_buf_adjust(curwin);
8009# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 if (foldmethodIsDiff(curwin))
8011 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008012# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013 }
8014#endif
8015
8016#ifdef USE_IM_CONTROL
8017 /* 'imdisable' */
8018 else if ((int *)varp == &p_imdisable)
8019 {
8020 /* Only de-activate it here, it will be enabled when changing mode. */
8021 if (p_imdisable)
8022 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008023 else if (State & INSERT)
8024 /* When the option is set from an autocommand, it may need to take
8025 * effect right away. */
8026 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008027 }
8028#endif
8029
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008030#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008031 /* 'spell' */
8032 else if ((int *)varp == &curwin->w_p_spell)
8033 {
8034 if (curwin->w_p_spell)
8035 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008036 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008037 if (errmsg != NULL)
8038 EMSG(_(errmsg));
8039 }
8040 }
8041#endif
8042
Bram Moolenaar071d4272004-06-13 20:20:40 +00008043#ifdef FEAT_FKMAP
8044 else if ((int *)varp == &p_altkeymap)
8045 {
8046 if (old_value != p_altkeymap)
8047 {
8048 if (!p_altkeymap)
8049 {
8050 p_hkmap = p_fkmap;
8051 p_fkmap = 0;
8052 }
8053 else
8054 {
8055 p_fkmap = p_hkmap;
8056 p_hkmap = 0;
8057 }
8058 (void)init_chartab();
8059 }
8060 }
8061
8062 /*
8063 * In case some second language keymapping options have changed, check
8064 * and correct the setting in a consistent way.
8065 */
8066
8067 /*
8068 * If hkmap or fkmap are set, reset Arabic keymapping.
8069 */
8070 if ((p_hkmap || p_fkmap) && p_altkeymap)
8071 {
8072 p_altkeymap = p_fkmap;
8073# ifdef FEAT_ARABIC
8074 curwin->w_p_arab = FALSE;
8075# endif
8076 (void)init_chartab();
8077 }
8078
8079 /*
8080 * If hkmap set, reset Farsi keymapping.
8081 */
8082 if (p_hkmap && p_altkeymap)
8083 {
8084 p_altkeymap = 0;
8085 p_fkmap = 0;
8086# ifdef FEAT_ARABIC
8087 curwin->w_p_arab = FALSE;
8088# endif
8089 (void)init_chartab();
8090 }
8091
8092 /*
8093 * If fkmap set, reset Hebrew keymapping.
8094 */
8095 if (p_fkmap && !p_altkeymap)
8096 {
8097 p_altkeymap = 1;
8098 p_hkmap = 0;
8099# ifdef FEAT_ARABIC
8100 curwin->w_p_arab = FALSE;
8101# endif
8102 (void)init_chartab();
8103 }
8104#endif
8105
8106#ifdef FEAT_ARABIC
8107 if ((int *)varp == &curwin->w_p_arab)
8108 {
8109 if (curwin->w_p_arab)
8110 {
8111 /*
8112 * 'arabic' is set, handle various sub-settings.
8113 */
8114 if (!p_tbidi)
8115 {
8116 /* set rightleft mode */
8117 if (!curwin->w_p_rl)
8118 {
8119 curwin->w_p_rl = TRUE;
8120 changed_window_setting();
8121 }
8122
8123 /* Enable Arabic shaping (major part of what Arabic requires) */
8124 if (!p_arshape)
8125 {
8126 p_arshape = TRUE;
8127 redraw_later_clear();
8128 }
8129 }
8130
8131 /* Arabic requires a utf-8 encoding, inform the user if its not
8132 * set. */
8133 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008134 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008135 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8136
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008137 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008138 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8139#ifdef FEAT_EVAL
8140 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8141#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008142 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143
8144# ifdef FEAT_MBYTE
8145 /* set 'delcombine' */
8146 p_deco = TRUE;
8147# endif
8148
8149# ifdef FEAT_KEYMAP
8150 /* Force-set the necessary keymap for arabic */
8151 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8152 OPT_LOCAL);
8153# endif
8154# ifdef FEAT_FKMAP
8155 p_altkeymap = 0;
8156 p_hkmap = 0;
8157 p_fkmap = 0;
8158 (void)init_chartab();
8159# endif
8160 }
8161 else
8162 {
8163 /*
8164 * 'arabic' is reset, handle various sub-settings.
8165 */
8166 if (!p_tbidi)
8167 {
8168 /* reset rightleft mode */
8169 if (curwin->w_p_rl)
8170 {
8171 curwin->w_p_rl = FALSE;
8172 changed_window_setting();
8173 }
8174
8175 /* 'arabicshape' isn't reset, it is a global option and
8176 * another window may still need it "on". */
8177 }
8178
8179 /* 'delcombine' isn't reset, it is a global option and another
8180 * window may still want it "on". */
8181
8182# ifdef FEAT_KEYMAP
8183 /* Revert to the default keymap */
8184 curbuf->b_p_iminsert = B_IMODE_NONE;
8185 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8186# endif
8187 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008188 }
8189
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008190#endif
8191
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192 /*
8193 * End of handling side effects for bool options.
8194 */
8195
8196 options[opt_idx].flags |= P_WAS_SET;
8197
8198 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008199 if (curwin->w_curswant != MAXCOL
8200 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8201 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 check_redraw(options[opt_idx].flags);
8203
8204 return NULL;
8205}
8206
8207/*
8208 * Set the value of a number option, and take care of side effects.
8209 * Returns NULL for success, or an error message for an error.
8210 */
8211 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008212set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008213 int opt_idx; /* index in options[] table */
8214 char_u *varp; /* pointer to the option variable */
8215 long value; /* new value */
8216 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008217 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8219 OPT_MODELINE */
8220{
8221 char_u *errmsg = NULL;
8222 long old_value = *(long *)varp;
8223 long old_Rows = Rows; /* remember old Rows */
8224 long old_Columns = Columns; /* remember old Columns */
8225 long *pp = (long *)varp;
8226
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008227 /* Disallow changing some options from secure mode. */
8228 if ((secure
8229#ifdef HAVE_SANDBOX
8230 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008231#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008232 ) && (options[opt_idx].flags & P_SECURE))
8233 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008234
8235 *pp = value;
8236#ifdef FEAT_EVAL
8237 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008238 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008240#ifdef FEAT_GUI
8241 need_mouse_correct = TRUE;
8242#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008243
Bram Moolenaar14f24742012-08-08 18:01:05 +02008244 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245 {
8246 errmsg = e_positive;
8247 curbuf->b_p_sw = curbuf->b_p_ts;
8248 }
8249
8250 /*
8251 * Number options that need some action when changed
8252 */
8253#ifdef FEAT_WINDOWS
8254 if (pp == &p_wh || pp == &p_hh)
8255 {
8256 if (p_wh < 1)
8257 {
8258 errmsg = e_positive;
8259 p_wh = 1;
8260 }
8261 if (p_wmh > p_wh)
8262 {
8263 errmsg = e_winheight;
8264 p_wh = p_wmh;
8265 }
8266 if (p_hh < 0)
8267 {
8268 errmsg = e_positive;
8269 p_hh = 0;
8270 }
8271
8272 /* Change window height NOW */
8273 if (lastwin != firstwin)
8274 {
8275 if (pp == &p_wh && curwin->w_height < p_wh)
8276 win_setheight((int)p_wh);
8277 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8278 win_setheight((int)p_hh);
8279 }
8280 }
8281
8282 /* 'winminheight' */
8283 else if (pp == &p_wmh)
8284 {
8285 if (p_wmh < 0)
8286 {
8287 errmsg = e_positive;
8288 p_wmh = 0;
8289 }
8290 if (p_wmh > p_wh)
8291 {
8292 errmsg = e_winheight;
8293 p_wmh = p_wh;
8294 }
8295 win_setminheight();
8296 }
8297
8298# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008299 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008300 {
8301 if (p_wiw < 1)
8302 {
8303 errmsg = e_positive;
8304 p_wiw = 1;
8305 }
8306 if (p_wmw > p_wiw)
8307 {
8308 errmsg = e_winwidth;
8309 p_wiw = p_wmw;
8310 }
8311
8312 /* Change window width NOW */
8313 if (lastwin != firstwin && curwin->w_width < p_wiw)
8314 win_setwidth((int)p_wiw);
8315 }
8316
8317 /* 'winminwidth' */
8318 else if (pp == &p_wmw)
8319 {
8320 if (p_wmw < 0)
8321 {
8322 errmsg = e_positive;
8323 p_wmw = 0;
8324 }
8325 if (p_wmw > p_wiw)
8326 {
8327 errmsg = e_winwidth;
8328 p_wmw = p_wiw;
8329 }
8330 win_setminheight();
8331 }
8332# endif
8333
8334#endif
8335
8336#ifdef FEAT_WINDOWS
8337 /* (re)set last window status line */
8338 else if (pp == &p_ls)
8339 {
8340 last_status(FALSE);
8341 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008342
8343 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008344 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008345 {
8346 shell_new_rows(); /* recompute window positions and heights */
8347 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008348#endif
8349
8350#ifdef FEAT_GUI
8351 else if (pp == &p_linespace)
8352 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008353 /* Recompute gui.char_height and resize the Vim window to keep the
8354 * same number of lines. */
8355 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008356 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008357 }
8358#endif
8359
8360#ifdef FEAT_FOLDING
8361 /* 'foldlevel' */
8362 else if (pp == &curwin->w_p_fdl)
8363 {
8364 if (curwin->w_p_fdl < 0)
8365 curwin->w_p_fdl = 0;
8366 newFoldLevel();
8367 }
8368
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008369 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370 else if (pp == &curwin->w_p_fml)
8371 {
8372 foldUpdateAll(curwin);
8373 }
8374
8375 /* 'foldnestmax' */
8376 else if (pp == &curwin->w_p_fdn)
8377 {
8378 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8379 foldUpdateAll(curwin);
8380 }
8381
8382 /* 'foldcolumn' */
8383 else if (pp == &curwin->w_p_fdc)
8384 {
8385 if (curwin->w_p_fdc < 0)
8386 {
8387 errmsg = e_positive;
8388 curwin->w_p_fdc = 0;
8389 }
8390 else if (curwin->w_p_fdc > 12)
8391 {
8392 errmsg = e_invarg;
8393 curwin->w_p_fdc = 12;
8394 }
8395 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008396#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008397
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008398#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008399 /* 'shiftwidth' or 'tabstop' */
8400 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8401 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008402# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403 if (foldmethodIsIndent(curwin))
8404 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008405# endif
8406# ifdef FEAT_CINDENT
8407 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8408 * parse 'cinoptions'. */
8409 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8410 parse_cino(curbuf);
8411# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008413#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008414
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008415#ifdef FEAT_MBYTE
8416 /* 'maxcombine' */
8417 else if (pp == &p_mco)
8418 {
8419 if (p_mco > MAX_MCO)
8420 p_mco = MAX_MCO;
8421 else if (p_mco < 0)
8422 p_mco = 0;
8423 screenclear(); /* will re-allocate the screen */
8424 }
8425#endif
8426
Bram Moolenaar071d4272004-06-13 20:20:40 +00008427 else if (pp == &curbuf->b_p_iminsert)
8428 {
8429 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8430 {
8431 errmsg = e_invarg;
8432 curbuf->b_p_iminsert = B_IMODE_NONE;
8433 }
8434 p_iminsert = curbuf->b_p_iminsert;
8435 if (termcap_active) /* don't do this in the alternate screen */
8436 showmode();
8437#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8438 /* Show/unshow value of 'keymap' in status lines. */
8439 status_redraw_curbuf();
8440#endif
8441 }
8442
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008443 else if (pp == &p_window)
8444 {
8445 if (p_window < 1)
8446 p_window = 1;
8447 else if (p_window >= Rows)
8448 p_window = Rows - 1;
8449 }
8450
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451 else if (pp == &curbuf->b_p_imsearch)
8452 {
8453 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8454 {
8455 errmsg = e_invarg;
8456 curbuf->b_p_imsearch = B_IMODE_NONE;
8457 }
8458 p_imsearch = curbuf->b_p_imsearch;
8459 }
8460
8461#ifdef FEAT_TITLE
8462 /* if 'titlelen' has changed, redraw the title */
8463 else if (pp == &p_titlelen)
8464 {
8465 if (p_titlelen < 0)
8466 {
8467 errmsg = e_positive;
8468 p_titlelen = 85;
8469 }
8470 if (starting != NO_SCREEN && old_value != p_titlelen)
8471 need_maketitle = TRUE;
8472 }
8473#endif
8474
8475 /* if p_ch changed value, change the command line height */
8476 else if (pp == &p_ch)
8477 {
8478 if (p_ch < 1)
8479 {
8480 errmsg = e_positive;
8481 p_ch = 1;
8482 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008483 if (p_ch > Rows - min_rows() + 1)
8484 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008485
8486 /* Only compute the new window layout when startup has been
8487 * completed. Otherwise the frame sizes may be wrong. */
8488 if (p_ch != old_value && full_screen
8489#ifdef FEAT_GUI
8490 && !gui.starting
8491#endif
8492 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008493 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008494 }
8495
8496 /* when 'updatecount' changes from zero to non-zero, open swap files */
8497 else if (pp == &p_uc)
8498 {
8499 if (p_uc < 0)
8500 {
8501 errmsg = e_positive;
8502 p_uc = 100;
8503 }
8504 if (p_uc && !old_value)
8505 ml_open_files();
8506 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008507#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008508 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008509 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008510 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008511 {
8512 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008513 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008514 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008515 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008516 {
8517 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008518 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008519 }
8520 }
8521#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008522#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008523 else if (pp == &p_mzq)
8524 mzvim_reset_timer();
8525#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008526
8527 /* sync undo before 'undolevels' changes */
8528 else if (pp == &p_ul)
8529 {
8530 /* use the old value, otherwise u_sync() may not work properly */
8531 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008532 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533 p_ul = value;
8534 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008535 else if (pp == &curbuf->b_p_ul)
8536 {
8537 /* use the old value, otherwise u_sync() may not work properly */
8538 curbuf->b_p_ul = old_value;
8539 u_sync(TRUE);
8540 curbuf->b_p_ul = value;
8541 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008542
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008543#ifdef FEAT_LINEBREAK
8544 /* 'numberwidth' must be positive */
8545 else if (pp == &curwin->w_p_nuw)
8546 {
8547 if (curwin->w_p_nuw < 1)
8548 {
8549 errmsg = e_positive;
8550 curwin->w_p_nuw = 1;
8551 }
8552 if (curwin->w_p_nuw > 10)
8553 {
8554 errmsg = e_invarg;
8555 curwin->w_p_nuw = 10;
8556 }
8557 curwin->w_nrwidth_line_count = 0;
8558 }
8559#endif
8560
Bram Moolenaar1a384422010-07-14 19:53:30 +02008561 else if (pp == &curbuf->b_p_tw)
8562 {
8563 if (curbuf->b_p_tw < 0)
8564 {
8565 errmsg = e_positive;
8566 curbuf->b_p_tw = 0;
8567 }
8568#ifdef FEAT_SYN_HL
8569# ifdef FEAT_WINDOWS
8570 {
8571 win_T *wp;
8572 tabpage_T *tp;
8573
8574 FOR_ALL_TAB_WINDOWS(tp, wp)
8575 check_colorcolumn(wp);
8576 }
8577# else
8578 check_colorcolumn(curwin);
8579# endif
8580#endif
8581 }
8582
Bram Moolenaar071d4272004-06-13 20:20:40 +00008583 /*
8584 * Check the bounds for numeric options here
8585 */
8586 if (Rows < min_rows() && full_screen)
8587 {
8588 if (errbuf != NULL)
8589 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008590 vim_snprintf((char *)errbuf, errbuflen,
8591 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008592 errmsg = errbuf;
8593 }
8594 Rows = min_rows();
8595 }
8596 if (Columns < MIN_COLUMNS && full_screen)
8597 {
8598 if (errbuf != NULL)
8599 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008600 vim_snprintf((char *)errbuf, errbuflen,
8601 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008602 errmsg = errbuf;
8603 }
8604 Columns = MIN_COLUMNS;
8605 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008606 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008607
8608#ifdef DJGPP
8609 /* avoid a crash by checking for a too large value of 'columns' */
8610 if (old_Columns != Columns && full_screen && term_console)
8611 mch_check_columns();
8612#endif
8613
8614 /*
8615 * If the screen (shell) height has been changed, assume it is the
8616 * physical screenheight.
8617 */
8618 if (old_Rows != Rows || old_Columns != Columns)
8619 {
8620 /* Changing the screen size is not allowed while updating the screen. */
8621 if (updating_screen)
8622 *pp = old_value;
8623 else if (full_screen
8624#ifdef FEAT_GUI
8625 && !gui.starting
8626#endif
8627 )
8628 set_shellsize((int)Columns, (int)Rows, TRUE);
8629 else
8630 {
8631 /* Postpone the resizing; check the size and cmdline position for
8632 * messages. */
8633 check_shellsize();
8634 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8635 cmdline_row = Rows - p_ch;
8636 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008637 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008638 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639 }
8640
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 if (curbuf->b_p_ts <= 0)
8642 {
8643 errmsg = e_positive;
8644 curbuf->b_p_ts = 8;
8645 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008646 if (p_tm < 0)
8647 {
8648 errmsg = e_positive;
8649 p_tm = 0;
8650 }
8651 if ((curwin->w_p_scr <= 0
8652 || (curwin->w_p_scr > curwin->w_height
8653 && curwin->w_height > 0))
8654 && full_screen)
8655 {
8656 if (pp == &(curwin->w_p_scr))
8657 {
8658 if (curwin->w_p_scr != 0)
8659 errmsg = e_scroll;
8660 win_comp_scroll(curwin);
8661 }
8662 /* If 'scroll' became invalid because of a side effect silently adjust
8663 * it. */
8664 else if (curwin->w_p_scr <= 0)
8665 curwin->w_p_scr = 1;
8666 else /* curwin->w_p_scr > curwin->w_height */
8667 curwin->w_p_scr = curwin->w_height;
8668 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008669 if (p_hi < 0)
8670 {
8671 errmsg = e_positive;
8672 p_hi = 0;
8673 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008674 else if (p_hi > 10000)
8675 {
8676 errmsg = e_invarg;
8677 p_hi = 10000;
8678 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008679 if (p_re < 0 || p_re > 2)
8680 {
8681 errmsg = e_invarg;
8682 p_re = 0;
8683 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008684 if (p_report < 0)
8685 {
8686 errmsg = e_positive;
8687 p_report = 1;
8688 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008689 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008690 {
8691 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8692 p_sj = Rows / 2;
8693 else
8694 {
8695 errmsg = e_scroll;
8696 p_sj = 1;
8697 }
8698 }
8699 if (p_so < 0 && full_screen)
8700 {
8701 errmsg = e_scroll;
8702 p_so = 0;
8703 }
8704 if (p_siso < 0 && full_screen)
8705 {
8706 errmsg = e_positive;
8707 p_siso = 0;
8708 }
8709#ifdef FEAT_CMDWIN
8710 if (p_cwh < 1)
8711 {
8712 errmsg = e_positive;
8713 p_cwh = 1;
8714 }
8715#endif
8716 if (p_ut < 0)
8717 {
8718 errmsg = e_positive;
8719 p_ut = 2000;
8720 }
8721 if (p_ss < 0)
8722 {
8723 errmsg = e_positive;
8724 p_ss = 0;
8725 }
8726
8727 /* May set global value for local option. */
8728 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8729 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8730
8731 options[opt_idx].flags |= P_WAS_SET;
8732
8733 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008734 if (curwin->w_curswant != MAXCOL
8735 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8736 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008737 check_redraw(options[opt_idx].flags);
8738
8739 return errmsg;
8740}
8741
8742/*
8743 * Called after an option changed: check if something needs to be redrawn.
8744 */
8745 static void
8746check_redraw(flags)
8747 long_u flags;
8748{
8749 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008750 int doclear = (flags & P_RCLR) == P_RCLR;
8751 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752
8753#ifdef FEAT_WINDOWS
8754 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8755 status_redraw_all();
8756#endif
8757
8758 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8759 changed_window_setting();
8760 if (flags & P_RBUF)
8761 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008762 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763 redraw_all_later(CLEAR);
8764 else if (all)
8765 redraw_all_later(NOT_VALID);
8766}
8767
8768/*
8769 * Find index for option 'arg'.
8770 * Return -1 if not found.
8771 */
8772 static int
8773findoption(arg)
8774 char_u *arg;
8775{
8776 int opt_idx;
8777 char *s, *p;
8778 static short quick_tab[27] = {0, 0}; /* quick access table */
8779 int is_term_opt;
8780
8781 /*
8782 * For first call: Initialize the quick-access table.
8783 * It contains the index for the first option that starts with a certain
8784 * letter. There are 26 letters, plus the first "t_" option.
8785 */
8786 if (quick_tab[1] == 0)
8787 {
8788 p = options[0].fullname;
8789 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8790 {
8791 if (s[0] != p[0])
8792 {
8793 if (s[0] == 't' && s[1] == '_')
8794 quick_tab[26] = opt_idx;
8795 else
8796 quick_tab[CharOrdLow(s[0])] = opt_idx;
8797 }
8798 p = s;
8799 }
8800 }
8801
8802 /*
8803 * Check for name starting with an illegal character.
8804 */
8805#ifdef EBCDIC
8806 if (!islower(arg[0]))
8807#else
8808 if (arg[0] < 'a' || arg[0] > 'z')
8809#endif
8810 return -1;
8811
8812 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8813 if (is_term_opt)
8814 opt_idx = quick_tab[26];
8815 else
8816 opt_idx = quick_tab[CharOrdLow(arg[0])];
8817 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8818 {
8819 if (STRCMP(arg, s) == 0) /* match full name */
8820 break;
8821 }
8822 if (s == NULL && !is_term_opt)
8823 {
8824 opt_idx = quick_tab[CharOrdLow(arg[0])];
8825 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8826 {
8827 s = options[opt_idx].shortname;
8828 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8829 break;
8830 s = NULL;
8831 }
8832 }
8833 if (s == NULL)
8834 opt_idx = -1;
8835 return opt_idx;
8836}
8837
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008838#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008839/*
8840 * Get the value for an option.
8841 *
8842 * Returns:
8843 * Number or Toggle option: 1, *numval gets value.
8844 * String option: 0, *stringval gets allocated string.
8845 * Hidden Number or Toggle option: -1.
8846 * hidden String option: -2.
8847 * unknown option: -3.
8848 */
8849 int
8850get_option_value(name, numval, stringval, opt_flags)
8851 char_u *name;
8852 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008853 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008854 int opt_flags;
8855{
8856 int opt_idx;
8857 char_u *varp;
8858
8859 opt_idx = findoption(name);
8860 if (opt_idx < 0) /* unknown option */
8861 return -3;
8862
8863 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8864
8865 if (options[opt_idx].flags & P_STRING)
8866 {
8867 if (varp == NULL) /* hidden option */
8868 return -2;
8869 if (stringval != NULL)
8870 {
8871#ifdef FEAT_CRYPT
8872 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008873 if ((char_u **)varp == &curbuf->b_p_key
8874 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008875 *stringval = vim_strsave((char_u *)"*****");
8876 else
8877#endif
8878 *stringval = vim_strsave(*(char_u **)(varp));
8879 }
8880 return 0;
8881 }
8882
8883 if (varp == NULL) /* hidden option */
8884 return -1;
8885 if (options[opt_idx].flags & P_NUM)
8886 *numval = *(long *)varp;
8887 else
8888 {
8889 /* Special case: 'modified' is b_changed, but we also want to consider
8890 * it set when 'ff' or 'fenc' changed. */
8891 if ((int *)varp == &curbuf->b_changed)
8892 *numval = curbufIsChanged();
8893 else
8894 *numval = *(int *)varp;
8895 }
8896 return 1;
8897}
8898#endif
8899
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008900#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008901/*
8902 * Returns the option attributes and its value. Unlike the above function it
8903 * will return either global value or local value of the option depending on
8904 * what was requested, but it will never return global value if it was
8905 * requested to return local one and vice versa. Neither it will return
8906 * buffer-local value if it was requested to return window-local one.
8907 *
8908 * Pretends that option is absent if it is not present in the requested scope
8909 * (i.e. has no global, window-local or buffer-local value depending on
8910 * opt_type). Uses
8911 *
8912 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008913 * 0 hidden or unknown option, also option that does not have requested
8914 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008915 * see SOPT_* in vim.h for other flags
8916 *
8917 * Possible opt_type values: see SREQ_* in vim.h
8918 */
8919 int
8920get_option_value_strict(name, numval, stringval, opt_type, from)
8921 char_u *name;
8922 long *numval;
8923 char_u **stringval; /* NULL when only obtaining attributes */
8924 int opt_type;
8925 void *from;
8926{
8927 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008928 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008929 struct vimoption *p;
8930 int r = 0;
8931
8932 opt_idx = findoption(name);
8933 if (opt_idx < 0)
8934 return 0;
8935
8936 p = &(options[opt_idx]);
8937
8938 /* Hidden option */
8939 if (p->var == NULL)
8940 return 0;
8941
8942 if (p->flags & P_BOOL)
8943 r |= SOPT_BOOL;
8944 else if (p->flags & P_NUM)
8945 r |= SOPT_NUM;
8946 else if (p->flags & P_STRING)
8947 r |= SOPT_STRING;
8948
8949 if (p->indir == PV_NONE)
8950 {
8951 if (opt_type == SREQ_GLOBAL)
8952 r |= SOPT_GLOBAL;
8953 else
8954 return 0; /* Did not request global-only option */
8955 }
8956 else
8957 {
8958 if (p->indir & PV_BOTH)
8959 r |= SOPT_GLOBAL;
8960 else if (opt_type == SREQ_GLOBAL)
8961 return 0; /* Requested global option */
8962
8963 if (p->indir & PV_WIN)
8964 {
8965 if (opt_type == SREQ_BUF)
8966 return 0; /* Did not request window-local option */
8967 else
8968 r |= SOPT_WIN;
8969 }
8970 else if (p->indir & PV_BUF)
8971 {
8972 if (opt_type == SREQ_WIN)
8973 return 0; /* Did not request buffer-local option */
8974 else
8975 r |= SOPT_BUF;
8976 }
8977 }
8978
8979 if (stringval == NULL)
8980 return r;
8981
8982 if (opt_type == SREQ_GLOBAL)
8983 varp = p->var;
8984 else
8985 {
8986 if (opt_type == SREQ_BUF)
8987 {
8988 /* Special case: 'modified' is b_changed, but we also want to
8989 * consider it set when 'ff' or 'fenc' changed. */
8990 if (p->indir == PV_MOD)
8991 {
8992 *numval = bufIsChanged((buf_T *) from);
8993 varp = NULL;
8994 }
8995#ifdef FEAT_CRYPT
8996 else if (p->indir == PV_KEY)
8997 {
8998 /* never return the value of the crypt key */
8999 *stringval = NULL;
9000 varp = NULL;
9001 }
9002#endif
9003 else
9004 {
9005 aco_save_T aco;
9006 aucmd_prepbuf(&aco, (buf_T *) from);
9007 varp = get_varp(p);
9008 aucmd_restbuf(&aco);
9009 }
9010 }
9011 else if (opt_type == SREQ_WIN)
9012 {
9013 win_T *save_curwin;
9014 save_curwin = curwin;
9015 curwin = (win_T *) from;
9016 curbuf = curwin->w_buffer;
9017 varp = get_varp(p);
9018 curwin = save_curwin;
9019 curbuf = curwin->w_buffer;
9020 }
9021 if (varp == p->var)
9022 return (r | SOPT_UNSET);
9023 }
9024
9025 if (varp != NULL)
9026 {
9027 if (p->flags & P_STRING)
9028 *stringval = vim_strsave(*(char_u **)(varp));
9029 else if (p->flags & P_NUM)
9030 *numval = *(long *) varp;
9031 else
9032 *numval = *(int *)varp;
9033 }
9034
9035 return r;
9036}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009037
9038/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009039 * Iterate over options. First argument is a pointer to a pointer to a
9040 * structure inside options[] array, second is option type like in the above
9041 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009042 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009043 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009044 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009045 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009046 * first argument to NULL.
9047 *
9048 * Returns full option name for current option on each call.
9049 */
9050 char_u *
9051option_iter_next(option, opt_type)
9052 void **option;
9053 int opt_type;
9054{
9055 struct vimoption *ret = NULL;
9056 do
9057 {
9058 if (*option == NULL)
9059 *option = (void *) options;
9060 else if (((struct vimoption *) (*option))->fullname == NULL)
9061 {
9062 *option = NULL;
9063 return NULL;
9064 }
9065 else
9066 *option = (void *) (((struct vimoption *) (*option)) + 1);
9067
9068 ret = ((struct vimoption *) (*option));
9069
9070 /* Hidden option */
9071 if (ret->var == NULL)
9072 {
9073 ret = NULL;
9074 continue;
9075 }
9076
9077 switch (opt_type)
9078 {
9079 case SREQ_GLOBAL:
9080 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9081 ret = NULL;
9082 break;
9083 case SREQ_BUF:
9084 if (!(ret->indir & PV_BUF))
9085 ret = NULL;
9086 break;
9087 case SREQ_WIN:
9088 if (!(ret->indir & PV_WIN))
9089 ret = NULL;
9090 break;
9091 default:
9092 EMSG2(_(e_intern2), "option_iter_next()");
9093 return NULL;
9094 }
9095 }
9096 while (ret == NULL);
9097
9098 return (char_u *)ret->fullname;
9099}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009100#endif
9101
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102/*
9103 * Set the value of option "name".
9104 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009105 *
9106 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009107 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009108 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009109set_option_value(name, number, string, opt_flags)
9110 char_u *name;
9111 long number;
9112 char_u *string;
9113 int opt_flags; /* OPT_LOCAL or 0 (both) */
9114{
9115 int opt_idx;
9116 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009117 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009118
9119 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009120 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121 EMSG2(_("E355: Unknown option: %s"), name);
9122 else
9123 {
9124 flags = options[opt_idx].flags;
9125#ifdef HAVE_SANDBOX
9126 /* Disallow changing some options in the sandbox */
9127 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009128 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009129 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009130 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009132#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009133 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009134 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009135 else
9136 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009137 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009138 if (varp != NULL) /* hidden option is not changed */
9139 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009140 if (number == 0 && string != NULL)
9141 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009142 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009143
9144 /* Either we are given a string or we are setting option
9145 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009146 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009147 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009148 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009149 {
9150 /* There's another character after zeros or the string
9151 * is empty. In both cases, we are trying to set a
9152 * num option using a string. */
9153 EMSG3(_("E521: Number required: &%s = '%s'"),
9154 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009155 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009156
9157 }
9158 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009159 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009160 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009161 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009162 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009163 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009164 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009165 }
9166 }
9167 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009168 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009169}
9170
9171/*
9172 * Get the terminal code for a terminal option.
9173 * Returns NULL when not found.
9174 */
9175 char_u *
9176get_term_code(tname)
9177 char_u *tname;
9178{
9179 int opt_idx;
9180 char_u *varp;
9181
9182 if (tname[0] != 't' || tname[1] != '_' ||
9183 tname[2] == NUL || tname[3] == NUL)
9184 return NULL;
9185 if ((opt_idx = findoption(tname)) >= 0)
9186 {
9187 varp = get_varp(&(options[opt_idx]));
9188 if (varp != NULL)
9189 varp = *(char_u **)(varp);
9190 return varp;
9191 }
9192 return find_termcode(tname + 2);
9193}
9194
9195 char_u *
9196get_highlight_default()
9197{
9198 int i;
9199
9200 i = findoption((char_u *)"hl");
9201 if (i >= 0)
9202 return options[i].def_val[VI_DEFAULT];
9203 return (char_u *)NULL;
9204}
9205
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009206#if defined(FEAT_MBYTE) || defined(PROTO)
9207 char_u *
9208get_encoding_default()
9209{
9210 int i;
9211
9212 i = findoption((char_u *)"enc");
9213 if (i >= 0)
9214 return options[i].def_val[VI_DEFAULT];
9215 return (char_u *)NULL;
9216}
9217#endif
9218
Bram Moolenaar071d4272004-06-13 20:20:40 +00009219/*
9220 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9221 */
9222 static int
9223find_key_option(arg)
9224 char_u *arg;
9225{
9226 int key;
9227 int modifiers;
9228
9229 /*
9230 * Don't use get_special_key_code() for t_xx, we don't want it to call
9231 * add_termcap_entry().
9232 */
9233 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9234 key = TERMCAP2KEY(arg[2], arg[3]);
9235 else
9236 {
9237 --arg; /* put arg at the '<' */
9238 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009239 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009240 if (modifiers) /* can't handle modifiers here */
9241 key = 0;
9242 }
9243 return key;
9244}
9245
9246/*
9247 * if 'all' == 0: show changed options
9248 * if 'all' == 1: show all normal options
9249 * if 'all' == 2: show all terminal options
9250 */
9251 static void
9252showoptions(all, opt_flags)
9253 int all;
9254 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9255{
9256 struct vimoption *p;
9257 int col;
9258 int isterm;
9259 char_u *varp;
9260 struct vimoption **items;
9261 int item_count;
9262 int run;
9263 int row, rows;
9264 int cols;
9265 int i;
9266 int len;
9267
9268#define INC 20
9269#define GAP 3
9270
9271 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9272 PARAM_COUNT));
9273 if (items == NULL)
9274 return;
9275
9276 /* Highlight title */
9277 if (all == 2)
9278 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9279 else if (opt_flags & OPT_GLOBAL)
9280 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9281 else if (opt_flags & OPT_LOCAL)
9282 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9283 else
9284 MSG_PUTS_TITLE(_("\n--- Options ---"));
9285
9286 /*
9287 * do the loop two times:
9288 * 1. display the short items
9289 * 2. display the long items (only strings and numbers)
9290 */
9291 for (run = 1; run <= 2 && !got_int; ++run)
9292 {
9293 /*
9294 * collect the items in items[]
9295 */
9296 item_count = 0;
9297 for (p = &options[0]; p->fullname != NULL; p++)
9298 {
9299 varp = NULL;
9300 isterm = istermoption(p);
9301 if (opt_flags != 0)
9302 {
9303 if (p->indir != PV_NONE && !isterm)
9304 varp = get_varp_scope(p, opt_flags);
9305 }
9306 else
9307 varp = get_varp(p);
9308 if (varp != NULL
9309 && ((all == 2 && isterm)
9310 || (all == 1 && !isterm)
9311 || (all == 0 && !optval_default(p, varp))))
9312 {
9313 if (p->flags & P_BOOL)
9314 len = 1; /* a toggle option fits always */
9315 else
9316 {
9317 option_value2string(p, opt_flags);
9318 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9319 }
9320 if ((len <= INC - GAP && run == 1) ||
9321 (len > INC - GAP && run == 2))
9322 items[item_count++] = p;
9323 }
9324 }
9325
9326 /*
9327 * display the items
9328 */
9329 if (run == 1)
9330 {
9331 cols = (Columns + GAP - 3) / INC;
9332 if (cols == 0)
9333 cols = 1;
9334 rows = (item_count + cols - 1) / cols;
9335 }
9336 else /* run == 2 */
9337 rows = item_count;
9338 for (row = 0; row < rows && !got_int; ++row)
9339 {
9340 msg_putchar('\n'); /* go to next line */
9341 if (got_int) /* 'q' typed in more */
9342 break;
9343 col = 0;
9344 for (i = row; i < item_count; i += rows)
9345 {
9346 msg_col = col; /* make columns */
9347 showoneopt(items[i], opt_flags);
9348 col += INC;
9349 }
9350 out_flush();
9351 ui_breakcheck();
9352 }
9353 }
9354 vim_free(items);
9355}
9356
9357/*
9358 * Return TRUE if option "p" has its default value.
9359 */
9360 static int
9361optval_default(p, varp)
9362 struct vimoption *p;
9363 char_u *varp;
9364{
9365 int dvi;
9366
9367 if (varp == NULL)
9368 return TRUE; /* hidden option is always at default */
9369 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9370 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009371 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009372 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009373 /* the cast to long is required for Manx C, long_i is
9374 * needed for MSVC */
9375 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009376 /* P_STRING */
9377 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9378}
9379
9380/*
9381 * showoneopt: show the value of one option
9382 * must not be called with a hidden option!
9383 */
9384 static void
9385showoneopt(p, opt_flags)
9386 struct vimoption *p;
9387 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9388{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009389 char_u *varp;
9390 int save_silent = silent_mode;
9391
9392 silent_mode = FALSE;
9393 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009394
9395 varp = get_varp_scope(p, opt_flags);
9396
9397 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9398 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9399 ? !curbufIsChanged() : !*(int *)varp))
9400 MSG_PUTS("no");
9401 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9402 MSG_PUTS("--");
9403 else
9404 MSG_PUTS(" ");
9405 MSG_PUTS(p->fullname);
9406 if (!(p->flags & P_BOOL))
9407 {
9408 msg_putchar('=');
9409 /* put value string in NameBuff */
9410 option_value2string(p, opt_flags);
9411 msg_outtrans(NameBuff);
9412 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009413
9414 silent_mode = save_silent;
9415 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416}
9417
9418/*
9419 * Write modified options as ":set" commands to a file.
9420 *
9421 * There are three values for "opt_flags":
9422 * OPT_GLOBAL: Write global option values and fresh values of
9423 * buffer-local options (used for start of a session
9424 * file).
9425 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9426 * curwin (used for a vimrc file).
9427 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9428 * and local values for window-local options of
9429 * curwin. Local values are also written when at the
9430 * default value, because a modeline or autocommand
9431 * may have set them when doing ":edit file" and the
9432 * user has set them back at the default or fresh
9433 * value.
9434 * When "local_only" is TRUE, don't write fresh
9435 * values, only local values (for ":mkview").
9436 * (fresh value = value used for a new buffer or window for a local option).
9437 *
9438 * Return FAIL on error, OK otherwise.
9439 */
9440 int
9441makeset(fd, opt_flags, local_only)
9442 FILE *fd;
9443 int opt_flags;
9444 int local_only;
9445{
9446 struct vimoption *p;
9447 char_u *varp; /* currently used value */
9448 char_u *varp_fresh; /* local value */
9449 char_u *varp_local = NULL; /* fresh value */
9450 char *cmd;
9451 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009452 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009453
9454 /*
9455 * The options that don't have a default (terminal name, columns, lines)
9456 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009457 * Do the loop over "options[]" twice: once for options with the
9458 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009459 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009460 for (pri = 1; pri >= 0; --pri)
9461 {
9462 for (p = &options[0]; !istermoption(p); p++)
9463 if (!(p->flags & P_NO_MKRC)
9464 && !istermoption(p)
9465 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009466 {
9467 /* skip global option when only doing locals */
9468 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9469 continue;
9470
9471 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9472 * file, they are always buffer-specific. */
9473 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9474 continue;
9475
9476 /* Global values are only written when not at the default value. */
9477 varp = get_varp_scope(p, opt_flags);
9478 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9479 continue;
9480
9481 round = 2;
9482 if (p->indir != PV_NONE)
9483 {
9484 if (p->var == VAR_WIN)
9485 {
9486 /* skip window-local option when only doing globals */
9487 if (!(opt_flags & OPT_LOCAL))
9488 continue;
9489 /* When fresh value of window-local option is not at the
9490 * default, need to write it too. */
9491 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9492 {
9493 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9494 if (!optval_default(p, varp_fresh))
9495 {
9496 round = 1;
9497 varp_local = varp;
9498 varp = varp_fresh;
9499 }
9500 }
9501 }
9502 }
9503
9504 /* Round 1: fresh value for window-local options.
9505 * Round 2: other values */
9506 for ( ; round <= 2; varp = varp_local, ++round)
9507 {
9508 if (round == 1 || (opt_flags & OPT_GLOBAL))
9509 cmd = "set";
9510 else
9511 cmd = "setlocal";
9512
9513 if (p->flags & P_BOOL)
9514 {
9515 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9516 return FAIL;
9517 }
9518 else if (p->flags & P_NUM)
9519 {
9520 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9521 return FAIL;
9522 }
9523 else /* P_STRING */
9524 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009525#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9526 int do_endif = FALSE;
9527
Bram Moolenaar071d4272004-06-13 20:20:40 +00009528 /* Don't set 'syntax' and 'filetype' again if the value is
9529 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009530 if (
9531# if defined(FEAT_SYN_HL)
9532 p->indir == PV_SYN
9533# if defined(FEAT_AUTOCMD)
9534 ||
9535# endif
9536# endif
9537# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009538 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009539# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009540 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009541 {
9542 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9543 *(char_u **)(varp)) < 0
9544 || put_eol(fd) < 0)
9545 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009546 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009548#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009549 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9550 (p->flags & P_EXPAND) != 0) == FAIL)
9551 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009552#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9553 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009554 {
9555 if (put_line(fd, "endif") == FAIL)
9556 return FAIL;
9557 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009558#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009559 }
9560 }
9561 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009562 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009563 return OK;
9564}
9565
9566#if defined(FEAT_FOLDING) || defined(PROTO)
9567/*
9568 * Generate set commands for the local fold options only. Used when
9569 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9570 */
9571 int
9572makefoldset(fd)
9573 FILE *fd;
9574{
9575 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9576# ifdef FEAT_EVAL
9577 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9578 == FAIL
9579# endif
9580 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9581 == FAIL
9582 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9583 == FAIL
9584 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9585 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9586 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9587 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9588 )
9589 return FAIL;
9590
9591 return OK;
9592}
9593#endif
9594
9595 static int
9596put_setstring(fd, cmd, name, valuep, expand)
9597 FILE *fd;
9598 char *cmd;
9599 char *name;
9600 char_u **valuep;
9601 int expand;
9602{
9603 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009604 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009605
9606 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9607 return FAIL;
9608 if (*valuep != NULL)
9609 {
9610 /* Output 'pastetoggle' as key names. For other
9611 * options some characters have to be escaped with
9612 * CTRL-V or backslash */
9613 if (valuep == &p_pt)
9614 {
9615 s = *valuep;
9616 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009617 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009618 return FAIL;
9619 }
9620 else if (expand)
9621 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009622 buf = alloc(MAXPATHL);
9623 if (buf == NULL)
9624 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009625 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9626 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009627 {
9628 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009629 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009630 }
9631 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009632 }
9633 else if (put_escstr(fd, *valuep, 2) == FAIL)
9634 return FAIL;
9635 }
9636 if (put_eol(fd) < 0)
9637 return FAIL;
9638 return OK;
9639}
9640
9641 static int
9642put_setnum(fd, cmd, name, valuep)
9643 FILE *fd;
9644 char *cmd;
9645 char *name;
9646 long *valuep;
9647{
9648 long wc;
9649
9650 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9651 return FAIL;
9652 if (wc_use_keyname((char_u *)valuep, &wc))
9653 {
9654 /* print 'wildchar' and 'wildcharm' as a key name */
9655 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9656 return FAIL;
9657 }
9658 else if (fprintf(fd, "%ld", *valuep) < 0)
9659 return FAIL;
9660 if (put_eol(fd) < 0)
9661 return FAIL;
9662 return OK;
9663}
9664
9665 static int
9666put_setbool(fd, cmd, name, value)
9667 FILE *fd;
9668 char *cmd;
9669 char *name;
9670 int value;
9671{
Bram Moolenaar893de922007-10-02 18:40:57 +00009672 if (value < 0) /* global/local option using global value */
9673 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009674 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9675 || put_eol(fd) < 0)
9676 return FAIL;
9677 return OK;
9678}
9679
9680/*
9681 * Clear all the terminal options.
9682 * If the option has been allocated, free the memory.
9683 * Terminal options are never hidden or indirect.
9684 */
9685 void
9686clear_termoptions()
9687{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009688 /*
9689 * Reset a few things before clearing the old options. This may cause
9690 * outputting a few things that the terminal doesn't understand, but the
9691 * screen will be cleared later, so this is OK.
9692 */
9693#ifdef FEAT_MOUSE_TTY
9694 mch_setmouse(FALSE); /* switch mouse off */
9695#endif
9696#ifdef FEAT_TITLE
9697 mch_restore_title(3); /* restore window titles */
9698#endif
9699#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9700 /* When starting the GUI close the display opened for the clipboard.
9701 * After restoring the title, because that will need the display. */
9702 if (gui.starting)
9703 clear_xterm_clip();
9704#endif
9705#ifdef WIN3264
9706 /*
9707 * Check if this is allowed now.
9708 */
9709 if (can_end_termcap_mode(FALSE) == TRUE)
9710#endif
9711 stoptermcap(); /* stop termcap mode */
9712
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009713 free_termoptions();
9714}
9715
9716 void
9717free_termoptions()
9718{
9719 struct vimoption *p;
9720
Bram Moolenaar071d4272004-06-13 20:20:40 +00009721 for (p = &options[0]; p->fullname != NULL; p++)
9722 if (istermoption(p))
9723 {
9724 if (p->flags & P_ALLOCED)
9725 free_string_option(*(char_u **)(p->var));
9726 if (p->flags & P_DEF_ALLOCED)
9727 free_string_option(p->def_val[VI_DEFAULT]);
9728 *(char_u **)(p->var) = empty_option;
9729 p->def_val[VI_DEFAULT] = empty_option;
9730 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9731 }
9732 clear_termcodes();
9733}
9734
9735/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009736 * Free the string for one term option, if it was allocated.
9737 * Set the string to empty_option and clear allocated flag.
9738 * "var" points to the option value.
9739 */
9740 void
9741free_one_termoption(var)
9742 char_u *var;
9743{
9744 struct vimoption *p;
9745
9746 for (p = &options[0]; p->fullname != NULL; p++)
9747 if (p->var == var)
9748 {
9749 if (p->flags & P_ALLOCED)
9750 free_string_option(*(char_u **)(p->var));
9751 *(char_u **)(p->var) = empty_option;
9752 p->flags &= ~P_ALLOCED;
9753 break;
9754 }
9755}
9756
9757/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758 * Set the terminal option defaults to the current value.
9759 * Used after setting the terminal name.
9760 */
9761 void
9762set_term_defaults()
9763{
9764 struct vimoption *p;
9765
9766 for (p = &options[0]; p->fullname != NULL; p++)
9767 {
9768 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9769 {
9770 if (p->flags & P_DEF_ALLOCED)
9771 {
9772 free_string_option(p->def_val[VI_DEFAULT]);
9773 p->flags &= ~P_DEF_ALLOCED;
9774 }
9775 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9776 if (p->flags & P_ALLOCED)
9777 {
9778 p->flags |= P_DEF_ALLOCED;
9779 p->flags &= ~P_ALLOCED; /* don't free the value now */
9780 }
9781 }
9782 }
9783}
9784
9785/*
9786 * return TRUE if 'p' starts with 't_'
9787 */
9788 static int
9789istermoption(p)
9790 struct vimoption *p;
9791{
9792 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9793}
9794
9795/*
9796 * Compute columns for ruler and shown command. 'sc_col' is also used to
9797 * decide what the maximum length of a message on the status line can be.
9798 * If there is a status line for the last window, 'sc_col' is independent
9799 * of 'ru_col'.
9800 */
9801
9802#define COL_RULER 17 /* columns needed by standard ruler */
9803
9804 void
9805comp_col()
9806{
9807#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9808 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9809
9810 sc_col = 0;
9811 ru_col = 0;
9812 if (p_ru)
9813 {
9814#ifdef FEAT_STL_OPT
9815 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9816#else
9817 ru_col = COL_RULER + 1;
9818#endif
9819 /* no last status line, adjust sc_col */
9820 if (!last_has_status)
9821 sc_col = ru_col;
9822 }
9823 if (p_sc)
9824 {
9825 sc_col += SHOWCMD_COLS;
9826 if (!p_ru || last_has_status) /* no need for separating space */
9827 ++sc_col;
9828 }
9829 sc_col = Columns - sc_col;
9830 ru_col = Columns - ru_col;
9831 if (sc_col <= 0) /* screen too narrow, will become a mess */
9832 sc_col = 1;
9833 if (ru_col <= 0)
9834 ru_col = 1;
9835#else
9836 sc_col = Columns;
9837 ru_col = Columns;
9838#endif
9839}
9840
9841/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009842 * Unset local option value, similar to ":set opt<".
9843 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009844 void
9845unset_global_local_option(name, from)
9846 char_u *name;
9847 void *from;
9848{
9849 struct vimoption *p;
9850 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009851 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009852
9853 opt_idx = findoption(name);
9854 p = &(options[opt_idx]);
9855
9856 switch ((int)p->indir)
9857 {
9858 /* global option with local value: use local value if it's been set */
9859 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009860 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009861 break;
9862 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009863 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009864 break;
9865 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009866 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009867 break;
9868 case PV_AR:
9869 buf->b_p_ar = -1;
9870 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009871 case PV_BKC:
9872 clear_string_option(&buf->b_p_bkc);
9873 buf->b_bkc_flags = 0;
9874 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009875 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009876 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009877 break;
9878#ifdef FEAT_FIND_ID
9879 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009880 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009881 break;
9882 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009883 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009884 break;
9885#endif
9886#ifdef FEAT_INS_EXPAND
9887 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009888 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009889 break;
9890 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009891 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009892 break;
9893#endif
9894#ifdef FEAT_QUICKFIX
9895 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009896 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009897 break;
9898 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009899 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009900 break;
9901 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009902 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009903 break;
9904#endif
9905#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9906 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009907 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009908 break;
9909#endif
9910#if defined(FEAT_CRYPT)
9911 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009912 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009913 break;
9914#endif
9915#ifdef FEAT_STL_OPT
9916 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009917 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009918 break;
9919#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009920 case PV_UL:
9921 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9922 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009923#ifdef FEAT_LISP
9924 case PV_LW:
9925 clear_string_option(&buf->b_p_lw);
9926 break;
9927#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009928 }
9929}
9930
9931/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009932 * Get pointer to option variable, depending on local or global scope.
9933 */
9934 static char_u *
9935get_varp_scope(p, opt_flags)
9936 struct vimoption *p;
9937 int opt_flags;
9938{
9939 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9940 {
9941 if (p->var == VAR_WIN)
9942 return (char_u *)GLOBAL_WO(get_varp(p));
9943 return p->var;
9944 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009945 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009946 {
9947 switch ((int)p->indir)
9948 {
9949#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009950 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9951 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9952 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009953#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009954 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9955 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9956 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009957 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009958 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009960 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9961 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009962#endif
9963#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009964 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9965 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009967#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9968 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9969#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009970#if defined(FEAT_CRYPT)
9971 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9972#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009973#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009974 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009975#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009976 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009977#ifdef FEAT_LISP
9978 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9979#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009980 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009981 }
9982 return NULL; /* "cannot happen" */
9983 }
9984 return get_varp(p);
9985}
9986
9987/*
9988 * Get pointer to option variable.
9989 */
9990 static char_u *
9991get_varp(p)
9992 struct vimoption *p;
9993{
9994 /* hidden option, always return NULL */
9995 if (p->var == NULL)
9996 return NULL;
9997
9998 switch ((int)p->indir)
9999 {
10000 case PV_NONE: return p->var;
10001
10002 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010003 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010004 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010005 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010007 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010009 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010010 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010011 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010012 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010013 case PV_BKC: return *curbuf->b_p_bkc != NUL
10014 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010015#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010016 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010017 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010018 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010019 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10020#endif
10021#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010022 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010023 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010024 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010025 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10026#endif
10027#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010028 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010029 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010030 case PV_GP: return *curbuf->b_p_gp != NUL
10031 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10032 case PV_MP: return *curbuf->b_p_mp != NUL
10033 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010035#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10036 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10037 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10038#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010039#if defined(FEAT_CRYPT)
10040 case PV_CM: return *curbuf->b_p_cm != NUL
10041 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10042#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010043#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010044 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010045 ? (char_u *)&(curwin->w_p_stl) : p->var;
10046#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010047 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10048 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010049#ifdef FEAT_LISP
10050 case PV_LW: return *curbuf->b_p_lw != NUL
10051 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10052#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010053
10054#ifdef FEAT_ARABIC
10055 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10056#endif
10057 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010058#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010059 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10060#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010061#ifdef FEAT_SYN_HL
10062 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10063 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010064 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010065#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066#ifdef FEAT_DIFF
10067 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10068#endif
10069#ifdef FEAT_FOLDING
10070 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10071 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10072 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10073 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10074 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10075 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10076 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10077# ifdef FEAT_EVAL
10078 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10079 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10080# endif
10081 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10082#endif
10083 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010084 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010085#ifdef FEAT_LINEBREAK
10086 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10087#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010088#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010089 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10090#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010091#ifdef FEAT_VERTSPLIT
10092 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10093#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010094#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10095 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10096#endif
10097#ifdef FEAT_RIGHTLEFT
10098 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10099 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10100#endif
10101 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10102 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10103#ifdef FEAT_LINEBREAK
10104 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010105 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10106 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010107#endif
10108#ifdef FEAT_SCROLLBIND
10109 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10110#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010111#ifdef FEAT_CURSORBIND
10112 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10113#endif
10114#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010115 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10116 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010117#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010118
10119 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10120 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10121#ifdef FEAT_MBYTE
10122 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10123#endif
10124#if defined(FEAT_QUICKFIX)
10125 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10126 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10127#endif
10128 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10129 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10130#ifdef FEAT_CINDENT
10131 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10132 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10133 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10134#endif
10135#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10136 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10137#endif
10138#ifdef FEAT_COMMENTS
10139 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10140#endif
10141#ifdef FEAT_FOLDING
10142 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10143#endif
10144#ifdef FEAT_INS_EXPAND
10145 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10146#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010147#ifdef FEAT_COMPL_FUNC
10148 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010149 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010150#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10152 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10153#ifdef FEAT_MBYTE
10154 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10155#endif
10156 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10157#ifdef FEAT_AUTOCMD
10158 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10159#endif
10160 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010161 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010162 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10163 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10164 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10165 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10166#ifdef FEAT_FIND_ID
10167# ifdef FEAT_EVAL
10168 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10169# endif
10170#endif
10171#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10172 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10173 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10174#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010175#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010176 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10177#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178#ifdef FEAT_CRYPT
10179 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10180#endif
10181#ifdef FEAT_LISP
10182 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10183#endif
10184 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10185 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10186 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10187 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10188 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010190#ifdef FEAT_TEXTOBJ
10191 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10192#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10194#ifdef FEAT_SMARTINDENT
10195 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10196#endif
10197#ifndef SHORT_FNAME
10198 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10199#endif
10200 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10201#ifdef FEAT_SEARCHPATH
10202 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10203#endif
10204 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10205#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010206 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010207 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10208#endif
10209#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010210 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10211 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10212 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010213#endif
10214 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10215 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10216 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10217 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010218#ifdef FEAT_PERSISTENT_UNDO
10219 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10220#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010221 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10222#ifdef FEAT_KEYMAP
10223 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10224#endif
10225 default: EMSG(_("E356: get_varp ERROR"));
10226 }
10227 /* always return a valid pointer to avoid a crash! */
10228 return (char_u *)&(curbuf->b_p_wm);
10229}
10230
10231/*
10232 * Get the value of 'equalprg', either the buffer-local one or the global one.
10233 */
10234 char_u *
10235get_equalprg()
10236{
10237 if (*curbuf->b_p_ep == NUL)
10238 return p_ep;
10239 return curbuf->b_p_ep;
10240}
10241
10242#if defined(FEAT_WINDOWS) || defined(PROTO)
10243/*
10244 * Copy options from one window to another.
10245 * Used when splitting a window.
10246 */
10247 void
10248win_copy_options(wp_from, wp_to)
10249 win_T *wp_from;
10250 win_T *wp_to;
10251{
10252 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10253 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10254# ifdef FEAT_RIGHTLEFT
10255# ifdef FEAT_FKMAP
10256 /* Is this right? */
10257 wp_to->w_farsi = wp_from->w_farsi;
10258# endif
10259# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010260#if defined(FEAT_LINEBREAK)
10261 briopt_check(wp_to);
10262#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010263}
10264#endif
10265
10266/*
10267 * Copy the options from one winopt_T to another.
10268 * Doesn't free the old option values in "to", use clear_winopt() for that.
10269 * The 'scroll' option is not copied, because it depends on the window height.
10270 * The 'previewwindow' option is reset, there can be only one preview window.
10271 */
10272 void
10273copy_winopt(from, to)
10274 winopt_T *from;
10275 winopt_T *to;
10276{
10277#ifdef FEAT_ARABIC
10278 to->wo_arab = from->wo_arab;
10279#endif
10280 to->wo_list = from->wo_list;
10281 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010282 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010283#ifdef FEAT_LINEBREAK
10284 to->wo_nuw = from->wo_nuw;
10285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010286#ifdef FEAT_RIGHTLEFT
10287 to->wo_rl = from->wo_rl;
10288 to->wo_rlc = vim_strsave(from->wo_rlc);
10289#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010290#ifdef FEAT_STL_OPT
10291 to->wo_stl = vim_strsave(from->wo_stl);
10292#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010293 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010294#ifdef FEAT_DIFF
10295 to->wo_wrap_save = from->wo_wrap_save;
10296#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297#ifdef FEAT_LINEBREAK
10298 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010299 to->wo_bri = from->wo_bri;
10300 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010301#endif
10302#ifdef FEAT_SCROLLBIND
10303 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010304 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010305#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010306#ifdef FEAT_CURSORBIND
10307 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010308 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010309#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010310#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010311 to->wo_spell = from->wo_spell;
10312#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010313#ifdef FEAT_SYN_HL
10314 to->wo_cuc = from->wo_cuc;
10315 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010316 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010317#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318#ifdef FEAT_DIFF
10319 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010320 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010322#ifdef FEAT_CONCEAL
10323 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010324 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326#ifdef FEAT_FOLDING
10327 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010328 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010330 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331 to->wo_fdi = vim_strsave(from->wo_fdi);
10332 to->wo_fml = from->wo_fml;
10333 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010334 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010335 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010336 to->wo_fdm_save = from->wo_diff_saved
10337 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010338 to->wo_fdn = from->wo_fdn;
10339# ifdef FEAT_EVAL
10340 to->wo_fde = vim_strsave(from->wo_fde);
10341 to->wo_fdt = vim_strsave(from->wo_fdt);
10342# endif
10343 to->wo_fmr = vim_strsave(from->wo_fmr);
10344#endif
10345 check_winopt(to); /* don't want NULL pointers */
10346}
10347
10348/*
10349 * Check string options in a window for a NULL value.
10350 */
10351 void
10352check_win_options(win)
10353 win_T *win;
10354{
10355 check_winopt(&win->w_onebuf_opt);
10356 check_winopt(&win->w_allbuf_opt);
10357}
10358
10359/*
10360 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10361 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010362 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010364 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365{
10366#ifdef FEAT_FOLDING
10367 check_string_option(&wop->wo_fdi);
10368 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010369 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370# ifdef FEAT_EVAL
10371 check_string_option(&wop->wo_fde);
10372 check_string_option(&wop->wo_fdt);
10373# endif
10374 check_string_option(&wop->wo_fmr);
10375#endif
10376#ifdef FEAT_RIGHTLEFT
10377 check_string_option(&wop->wo_rlc);
10378#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010379#ifdef FEAT_STL_OPT
10380 check_string_option(&wop->wo_stl);
10381#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010382#ifdef FEAT_SYN_HL
10383 check_string_option(&wop->wo_cc);
10384#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010385#ifdef FEAT_CONCEAL
10386 check_string_option(&wop->wo_cocu);
10387#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010388#ifdef FEAT_LINEBREAK
10389 check_string_option(&wop->wo_briopt);
10390#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010391}
10392
10393/*
10394 * Free the allocated memory inside a winopt_T.
10395 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010396 void
10397clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010398 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399{
10400#ifdef FEAT_FOLDING
10401 clear_string_option(&wop->wo_fdi);
10402 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010403 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010404# ifdef FEAT_EVAL
10405 clear_string_option(&wop->wo_fde);
10406 clear_string_option(&wop->wo_fdt);
10407# endif
10408 clear_string_option(&wop->wo_fmr);
10409#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010410#ifdef FEAT_LINEBREAK
10411 clear_string_option(&wop->wo_briopt);
10412#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413#ifdef FEAT_RIGHTLEFT
10414 clear_string_option(&wop->wo_rlc);
10415#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010416#ifdef FEAT_STL_OPT
10417 clear_string_option(&wop->wo_stl);
10418#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010419#ifdef FEAT_SYN_HL
10420 clear_string_option(&wop->wo_cc);
10421#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010422#ifdef FEAT_CONCEAL
10423 clear_string_option(&wop->wo_cocu);
10424#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010425}
10426
10427/*
10428 * Copy global option values to local options for one buffer.
10429 * Used when creating a new buffer and sometimes when entering a buffer.
10430 * flags:
10431 * BCO_ENTER We will enter the buf buffer.
10432 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10433 * appropriate.
10434 * BCO_NOHELP Don't copy the values to a help buffer.
10435 */
10436 void
10437buf_copy_options(buf, flags)
10438 buf_T *buf;
10439 int flags;
10440{
10441 int should_copy = TRUE;
10442 char_u *save_p_isk = NULL; /* init for GCC */
10443 int dont_do_help;
10444 int did_isk = FALSE;
10445
10446 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010447 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010448 */
10449 if (buf == NULL || !buf_valid(buf))
10450 return;
10451
10452 /*
10453 * Skip this when the option defaults have not been set yet. Happens when
10454 * main() allocates the first buffer.
10455 */
10456 if (p_cpo != NULL)
10457 {
10458 /*
10459 * Always copy when entering and 'cpo' contains 'S'.
10460 * Don't copy when already initialized.
10461 * Don't copy when 'cpo' contains 's' and not entering.
10462 * 'S' BCO_ENTER initialized 's' should_copy
10463 * yes yes X X TRUE
10464 * yes no yes X FALSE
10465 * no X yes X FALSE
10466 * X no no yes FALSE
10467 * X no no no TRUE
10468 * no yes no X TRUE
10469 */
10470 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10471 && (buf->b_p_initialized
10472 || (!(flags & BCO_ENTER)
10473 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10474 should_copy = FALSE;
10475
10476 if (should_copy || (flags & BCO_ALWAYS))
10477 {
10478 /* Don't copy the options specific to a help buffer when
10479 * BCO_NOHELP is given or the options were initialized already
10480 * (jumping back to a help file with CTRL-T or CTRL-O) */
10481 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10482 || buf->b_p_initialized;
10483 if (dont_do_help) /* don't free b_p_isk */
10484 {
10485 save_p_isk = buf->b_p_isk;
10486 buf->b_p_isk = NULL;
10487 }
10488 /*
10489 * Always free the allocated strings.
10490 * If not already initialized, set 'readonly' and copy 'fileformat'.
10491 */
10492 if (!buf->b_p_initialized)
10493 {
10494 free_buf_options(buf, TRUE);
10495 buf->b_p_ro = FALSE; /* don't copy readonly */
10496 buf->b_p_tx = p_tx;
10497#ifdef FEAT_MBYTE
10498 buf->b_p_fenc = vim_strsave(p_fenc);
10499#endif
10500 buf->b_p_ff = vim_strsave(p_ff);
10501#if defined(FEAT_QUICKFIX)
10502 buf->b_p_bh = empty_option;
10503 buf->b_p_bt = empty_option;
10504#endif
10505 }
10506 else
10507 free_buf_options(buf, FALSE);
10508
10509 buf->b_p_ai = p_ai;
10510 buf->b_p_ai_nopaste = p_ai_nopaste;
10511 buf->b_p_sw = p_sw;
10512 buf->b_p_tw = p_tw;
10513 buf->b_p_tw_nopaste = p_tw_nopaste;
10514 buf->b_p_tw_nobin = p_tw_nobin;
10515 buf->b_p_wm = p_wm;
10516 buf->b_p_wm_nopaste = p_wm_nopaste;
10517 buf->b_p_wm_nobin = p_wm_nobin;
10518 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010519#ifdef FEAT_MBYTE
10520 buf->b_p_bomb = p_bomb;
10521#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010522 buf->b_p_et = p_et;
10523 buf->b_p_et_nobin = p_et_nobin;
10524 buf->b_p_ml = p_ml;
10525 buf->b_p_ml_nobin = p_ml_nobin;
10526 buf->b_p_inf = p_inf;
10527 buf->b_p_swf = p_swf;
10528#ifdef FEAT_INS_EXPAND
10529 buf->b_p_cpt = vim_strsave(p_cpt);
10530#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010531#ifdef FEAT_COMPL_FUNC
10532 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010533 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 buf->b_p_sts = p_sts;
10536 buf->b_p_sts_nopaste = p_sts_nopaste;
10537#ifndef SHORT_FNAME
10538 buf->b_p_sn = p_sn;
10539#endif
10540#ifdef FEAT_COMMENTS
10541 buf->b_p_com = vim_strsave(p_com);
10542#endif
10543#ifdef FEAT_FOLDING
10544 buf->b_p_cms = vim_strsave(p_cms);
10545#endif
10546 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010547 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548 buf->b_p_nf = vim_strsave(p_nf);
10549 buf->b_p_mps = vim_strsave(p_mps);
10550#ifdef FEAT_SMARTINDENT
10551 buf->b_p_si = p_si;
10552#endif
10553 buf->b_p_ci = p_ci;
10554#ifdef FEAT_CINDENT
10555 buf->b_p_cin = p_cin;
10556 buf->b_p_cink = vim_strsave(p_cink);
10557 buf->b_p_cino = vim_strsave(p_cino);
10558#endif
10559#ifdef FEAT_AUTOCMD
10560 /* Don't copy 'filetype', it must be detected */
10561 buf->b_p_ft = empty_option;
10562#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563 buf->b_p_pi = p_pi;
10564#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10565 buf->b_p_cinw = vim_strsave(p_cinw);
10566#endif
10567#ifdef FEAT_LISP
10568 buf->b_p_lisp = p_lisp;
10569#endif
10570#ifdef FEAT_SYN_HL
10571 /* Don't copy 'syntax', it must be set */
10572 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010573 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010574#endif
10575#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010576 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010577 (void)compile_cap_prog(&buf->b_s);
10578 buf->b_s.b_p_spf = vim_strsave(p_spf);
10579 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580#endif
10581#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10582 buf->b_p_inde = vim_strsave(p_inde);
10583 buf->b_p_indk = vim_strsave(p_indk);
10584#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010585#if defined(FEAT_EVAL)
10586 buf->b_p_fex = vim_strsave(p_fex);
10587#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588#ifdef FEAT_CRYPT
10589 buf->b_p_key = vim_strsave(p_key);
10590#endif
10591#ifdef FEAT_SEARCHPATH
10592 buf->b_p_sua = vim_strsave(p_sua);
10593#endif
10594#ifdef FEAT_KEYMAP
10595 buf->b_p_keymap = vim_strsave(p_keymap);
10596 buf->b_kmap_state |= KEYMAP_INIT;
10597#endif
10598 /* This isn't really an option, but copying the langmap and IME
10599 * state from the current buffer is better than resetting it. */
10600 buf->b_p_iminsert = p_iminsert;
10601 buf->b_p_imsearch = p_imsearch;
10602
10603 /* options that are normally global but also have a local value
10604 * are not copied, start using the global value */
10605 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010606 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010607 buf->b_p_bkc = empty_option;
10608 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010609#ifdef FEAT_QUICKFIX
10610 buf->b_p_gp = empty_option;
10611 buf->b_p_mp = empty_option;
10612 buf->b_p_efm = empty_option;
10613#endif
10614 buf->b_p_ep = empty_option;
10615 buf->b_p_kp = empty_option;
10616 buf->b_p_path = empty_option;
10617 buf->b_p_tags = empty_option;
10618#ifdef FEAT_FIND_ID
10619 buf->b_p_def = empty_option;
10620 buf->b_p_inc = empty_option;
10621# ifdef FEAT_EVAL
10622 buf->b_p_inex = vim_strsave(p_inex);
10623# endif
10624#endif
10625#ifdef FEAT_INS_EXPAND
10626 buf->b_p_dict = empty_option;
10627 buf->b_p_tsr = empty_option;
10628#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010629#ifdef FEAT_TEXTOBJ
10630 buf->b_p_qe = vim_strsave(p_qe);
10631#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010632#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10633 buf->b_p_bexpr = empty_option;
10634#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010635#if defined(FEAT_CRYPT)
10636 buf->b_p_cm = empty_option;
10637#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010638#ifdef FEAT_PERSISTENT_UNDO
10639 buf->b_p_udf = p_udf;
10640#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010641#ifdef FEAT_LISP
10642 buf->b_p_lw = empty_option;
10643#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010644
10645 /*
10646 * Don't copy the options set by ex_help(), use the saved values,
10647 * when going from a help buffer to a non-help buffer.
10648 * Don't touch these at all when BCO_NOHELP is used and going from
10649 * or to a help buffer.
10650 */
10651 if (dont_do_help)
10652 buf->b_p_isk = save_p_isk;
10653 else
10654 {
10655 buf->b_p_isk = vim_strsave(p_isk);
10656 did_isk = TRUE;
10657 buf->b_p_ts = p_ts;
10658 buf->b_help = FALSE;
10659#ifdef FEAT_QUICKFIX
10660 if (buf->b_p_bt[0] == 'h')
10661 clear_string_option(&buf->b_p_bt);
10662#endif
10663 buf->b_p_ma = p_ma;
10664 }
10665 }
10666
10667 /*
10668 * When the options should be copied (ignoring BCO_ALWAYS), set the
10669 * flag that indicates that the options have been initialized.
10670 */
10671 if (should_copy)
10672 buf->b_p_initialized = TRUE;
10673 }
10674
10675 check_buf_options(buf); /* make sure we don't have NULLs */
10676 if (did_isk)
10677 (void)buf_init_chartab(buf, FALSE);
10678}
10679
10680/*
10681 * Reset the 'modifiable' option and its default value.
10682 */
10683 void
10684reset_modifiable()
10685{
10686 int opt_idx;
10687
10688 curbuf->b_p_ma = FALSE;
10689 p_ma = FALSE;
10690 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010691 if (opt_idx >= 0)
10692 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010693}
10694
10695/*
10696 * Set the global value for 'iminsert' to the local value.
10697 */
10698 void
10699set_iminsert_global()
10700{
10701 p_iminsert = curbuf->b_p_iminsert;
10702}
10703
10704/*
10705 * Set the global value for 'imsearch' to the local value.
10706 */
10707 void
10708set_imsearch_global()
10709{
10710 p_imsearch = curbuf->b_p_imsearch;
10711}
10712
10713#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10714static int expand_option_idx = -1;
10715static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10716static int expand_option_flags = 0;
10717
10718 void
10719set_context_in_set_cmd(xp, arg, opt_flags)
10720 expand_T *xp;
10721 char_u *arg;
10722 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10723{
10724 int nextchar;
10725 long_u flags = 0; /* init for GCC */
10726 int opt_idx = 0; /* init for GCC */
10727 char_u *p;
10728 char_u *s;
10729 int is_term_option = FALSE;
10730 int key;
10731
10732 expand_option_flags = opt_flags;
10733
10734 xp->xp_context = EXPAND_SETTINGS;
10735 if (*arg == NUL)
10736 {
10737 xp->xp_pattern = arg;
10738 return;
10739 }
10740 p = arg + STRLEN(arg) - 1;
10741 if (*p == ' ' && *(p - 1) != '\\')
10742 {
10743 xp->xp_pattern = p + 1;
10744 return;
10745 }
10746 while (p > arg)
10747 {
10748 s = p;
10749 /* count number of backslashes before ' ' or ',' */
10750 if (*p == ' ' || *p == ',')
10751 {
10752 while (s > arg && *(s - 1) == '\\')
10753 --s;
10754 }
10755 /* break at a space with an even number of backslashes */
10756 if (*p == ' ' && ((p - s) & 1) == 0)
10757 {
10758 ++p;
10759 break;
10760 }
10761 --p;
10762 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010763 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764 {
10765 xp->xp_context = EXPAND_BOOL_SETTINGS;
10766 p += 2;
10767 }
10768 if (STRNCMP(p, "inv", 3) == 0)
10769 {
10770 xp->xp_context = EXPAND_BOOL_SETTINGS;
10771 p += 3;
10772 }
10773 xp->xp_pattern = arg = p;
10774 if (*arg == '<')
10775 {
10776 while (*p != '>')
10777 if (*p++ == NUL) /* expand terminal option name */
10778 return;
10779 key = get_special_key_code(arg + 1);
10780 if (key == 0) /* unknown name */
10781 {
10782 xp->xp_context = EXPAND_NOTHING;
10783 return;
10784 }
10785 nextchar = *++p;
10786 is_term_option = TRUE;
10787 expand_option_name[2] = KEY2TERMCAP0(key);
10788 expand_option_name[3] = KEY2TERMCAP1(key);
10789 }
10790 else
10791 {
10792 if (p[0] == 't' && p[1] == '_')
10793 {
10794 p += 2;
10795 if (*p != NUL)
10796 ++p;
10797 if (*p == NUL)
10798 return; /* expand option name */
10799 nextchar = *++p;
10800 is_term_option = TRUE;
10801 expand_option_name[2] = p[-2];
10802 expand_option_name[3] = p[-1];
10803 }
10804 else
10805 {
10806 /* Allow * wildcard */
10807 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10808 p++;
10809 if (*p == NUL)
10810 return;
10811 nextchar = *p;
10812 *p = NUL;
10813 opt_idx = findoption(arg);
10814 *p = nextchar;
10815 if (opt_idx == -1 || options[opt_idx].var == NULL)
10816 {
10817 xp->xp_context = EXPAND_NOTHING;
10818 return;
10819 }
10820 flags = options[opt_idx].flags;
10821 if (flags & P_BOOL)
10822 {
10823 xp->xp_context = EXPAND_NOTHING;
10824 return;
10825 }
10826 }
10827 }
10828 /* handle "-=" and "+=" */
10829 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10830 {
10831 ++p;
10832 nextchar = '=';
10833 }
10834 if ((nextchar != '=' && nextchar != ':')
10835 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10836 {
10837 xp->xp_context = EXPAND_UNSUCCESSFUL;
10838 return;
10839 }
10840 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10841 {
10842 xp->xp_context = EXPAND_OLD_SETTING;
10843 if (is_term_option)
10844 expand_option_idx = -1;
10845 else
10846 expand_option_idx = opt_idx;
10847 xp->xp_pattern = p + 1;
10848 return;
10849 }
10850 xp->xp_context = EXPAND_NOTHING;
10851 if (is_term_option || (flags & P_NUM))
10852 return;
10853
10854 xp->xp_pattern = p + 1;
10855
10856 if (flags & P_EXPAND)
10857 {
10858 p = options[opt_idx].var;
10859 if (p == (char_u *)&p_bdir
10860 || p == (char_u *)&p_dir
10861 || p == (char_u *)&p_path
10862 || p == (char_u *)&p_rtp
10863#ifdef FEAT_SEARCHPATH
10864 || p == (char_u *)&p_cdpath
10865#endif
10866#ifdef FEAT_SESSION
10867 || p == (char_u *)&p_vdir
10868#endif
10869 )
10870 {
10871 xp->xp_context = EXPAND_DIRECTORIES;
10872 if (p == (char_u *)&p_path
10873#ifdef FEAT_SEARCHPATH
10874 || p == (char_u *)&p_cdpath
10875#endif
10876 )
10877 xp->xp_backslash = XP_BS_THREE;
10878 else
10879 xp->xp_backslash = XP_BS_ONE;
10880 }
10881 else
10882 {
10883 xp->xp_context = EXPAND_FILES;
10884 /* for 'tags' need three backslashes for a space */
10885 if (p == (char_u *)&p_tags)
10886 xp->xp_backslash = XP_BS_THREE;
10887 else
10888 xp->xp_backslash = XP_BS_ONE;
10889 }
10890 }
10891
10892 /* For an option that is a list of file names, find the start of the
10893 * last file name. */
10894 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10895 {
10896 /* count number of backslashes before ' ' or ',' */
10897 if (*p == ' ' || *p == ',')
10898 {
10899 s = p;
10900 while (s > xp->xp_pattern && *(s - 1) == '\\')
10901 --s;
10902 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10903 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10904 {
10905 xp->xp_pattern = p + 1;
10906 break;
10907 }
10908 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010909
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010910#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010911 /* for 'spellsuggest' start at "file:" */
10912 if (options[opt_idx].var == (char_u *)&p_sps
10913 && STRNCMP(p, "file:", 5) == 0)
10914 {
10915 xp->xp_pattern = p + 5;
10916 break;
10917 }
10918#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010919 }
10920
10921 return;
10922}
10923
10924 int
10925ExpandSettings(xp, regmatch, num_file, file)
10926 expand_T *xp;
10927 regmatch_T *regmatch;
10928 int *num_file;
10929 char_u ***file;
10930{
10931 int num_normal = 0; /* Nr of matching non-term-code settings */
10932 int num_term = 0; /* Nr of matching terminal code settings */
10933 int opt_idx;
10934 int match;
10935 int count = 0;
10936 char_u *str;
10937 int loop;
10938 int is_term_opt;
10939 char_u name_buf[MAX_KEY_NAME_LEN];
10940 static char *(names[]) = {"all", "termcap"};
10941 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10942
10943 /* do this loop twice:
10944 * loop == 0: count the number of matching options
10945 * loop == 1: copy the matching options into allocated memory
10946 */
10947 for (loop = 0; loop <= 1; ++loop)
10948 {
10949 regmatch->rm_ic = ic;
10950 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10951 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010952 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10953 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010954 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10955 {
10956 if (loop == 0)
10957 num_normal++;
10958 else
10959 (*file)[count++] = vim_strsave((char_u *)names[match]);
10960 }
10961 }
10962 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10963 opt_idx++)
10964 {
10965 if (options[opt_idx].var == NULL)
10966 continue;
10967 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10968 && !(options[opt_idx].flags & P_BOOL))
10969 continue;
10970 is_term_opt = istermoption(&options[opt_idx]);
10971 if (is_term_opt && num_normal > 0)
10972 continue;
10973 match = FALSE;
10974 if (vim_regexec(regmatch, str, (colnr_T)0)
10975 || (options[opt_idx].shortname != NULL
10976 && vim_regexec(regmatch,
10977 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10978 match = TRUE;
10979 else if (is_term_opt)
10980 {
10981 name_buf[0] = '<';
10982 name_buf[1] = 't';
10983 name_buf[2] = '_';
10984 name_buf[3] = str[2];
10985 name_buf[4] = str[3];
10986 name_buf[5] = '>';
10987 name_buf[6] = NUL;
10988 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10989 {
10990 match = TRUE;
10991 str = name_buf;
10992 }
10993 }
10994 if (match)
10995 {
10996 if (loop == 0)
10997 {
10998 if (is_term_opt)
10999 num_term++;
11000 else
11001 num_normal++;
11002 }
11003 else
11004 (*file)[count++] = vim_strsave(str);
11005 }
11006 }
11007 /*
11008 * Check terminal key codes, these are not in the option table
11009 */
11010 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11011 {
11012 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11013 {
11014 if (!isprint(str[0]) || !isprint(str[1]))
11015 continue;
11016
11017 name_buf[0] = 't';
11018 name_buf[1] = '_';
11019 name_buf[2] = str[0];
11020 name_buf[3] = str[1];
11021 name_buf[4] = NUL;
11022
11023 match = FALSE;
11024 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11025 match = TRUE;
11026 else
11027 {
11028 name_buf[0] = '<';
11029 name_buf[1] = 't';
11030 name_buf[2] = '_';
11031 name_buf[3] = str[0];
11032 name_buf[4] = str[1];
11033 name_buf[5] = '>';
11034 name_buf[6] = NUL;
11035
11036 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11037 match = TRUE;
11038 }
11039 if (match)
11040 {
11041 if (loop == 0)
11042 num_term++;
11043 else
11044 (*file)[count++] = vim_strsave(name_buf);
11045 }
11046 }
11047
11048 /*
11049 * Check special key names.
11050 */
11051 regmatch->rm_ic = TRUE; /* ignore case here */
11052 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11053 {
11054 name_buf[0] = '<';
11055 STRCPY(name_buf + 1, str);
11056 STRCAT(name_buf, ">");
11057
11058 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11059 {
11060 if (loop == 0)
11061 num_term++;
11062 else
11063 (*file)[count++] = vim_strsave(name_buf);
11064 }
11065 }
11066 }
11067 if (loop == 0)
11068 {
11069 if (num_normal > 0)
11070 *num_file = num_normal;
11071 else if (num_term > 0)
11072 *num_file = num_term;
11073 else
11074 return OK;
11075 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11076 if (*file == NULL)
11077 {
11078 *file = (char_u **)"";
11079 return FAIL;
11080 }
11081 }
11082 }
11083 return OK;
11084}
11085
11086 int
11087ExpandOldSetting(num_file, file)
11088 int *num_file;
11089 char_u ***file;
11090{
11091 char_u *var = NULL; /* init for GCC */
11092 char_u *buf;
11093
11094 *num_file = 0;
11095 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11096 if (*file == NULL)
11097 return FAIL;
11098
11099 /*
11100 * For a terminal key code expand_option_idx is < 0.
11101 */
11102 if (expand_option_idx < 0)
11103 {
11104 var = find_termcode(expand_option_name + 2);
11105 if (var == NULL)
11106 expand_option_idx = findoption(expand_option_name);
11107 }
11108
11109 if (expand_option_idx >= 0)
11110 {
11111 /* put string of option value in NameBuff */
11112 option_value2string(&options[expand_option_idx], expand_option_flags);
11113 var = NameBuff;
11114 }
11115 else if (var == NULL)
11116 var = (char_u *)"";
11117
11118 /* A backslash is required before some characters. This is the reverse of
11119 * what happens in do_set(). */
11120 buf = vim_strsave_escaped(var, escape_chars);
11121
11122 if (buf == NULL)
11123 {
11124 vim_free(*file);
11125 *file = NULL;
11126 return FAIL;
11127 }
11128
11129#ifdef BACKSLASH_IN_FILENAME
11130 /* For MS-Windows et al. we don't double backslashes at the start and
11131 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011132 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133 if (var[0] == '\\' && var[1] == '\\'
11134 && expand_option_idx >= 0
11135 && (options[expand_option_idx].flags & P_EXPAND)
11136 && vim_isfilec(var[2])
11137 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011138 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011139#endif
11140
11141 *file[0] = buf;
11142 *num_file = 1;
11143 return OK;
11144}
11145#endif
11146
11147/*
11148 * Get the value for the numeric or string option *opp in a nice format into
11149 * NameBuff[]. Must not be called with a hidden option!
11150 */
11151 static void
11152option_value2string(opp, opt_flags)
11153 struct vimoption *opp;
11154 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11155{
11156 char_u *varp;
11157
11158 varp = get_varp_scope(opp, opt_flags);
11159
11160 if (opp->flags & P_NUM)
11161 {
11162 long wc = 0;
11163
11164 if (wc_use_keyname(varp, &wc))
11165 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11166 else if (wc != 0)
11167 STRCPY(NameBuff, transchar((int)wc));
11168 else
11169 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11170 }
11171 else /* P_STRING */
11172 {
11173 varp = *(char_u **)(varp);
11174 if (varp == NULL) /* just in case */
11175 NameBuff[0] = NUL;
11176#ifdef FEAT_CRYPT
11177 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011178 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011179 STRCPY(NameBuff, "*****");
11180#endif
11181 else if (opp->flags & P_EXPAND)
11182 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11183 /* Translate 'pastetoggle' into special key names */
11184 else if ((char_u **)opp->var == &p_pt)
11185 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11186 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011187 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188 }
11189}
11190
11191/*
11192 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11193 * printed as a keyname.
11194 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11195 */
11196 static int
11197wc_use_keyname(varp, wcp)
11198 char_u *varp;
11199 long *wcp;
11200{
11201 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11202 {
11203 *wcp = *(long *)varp;
11204 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11205 return TRUE;
11206 }
11207 return FALSE;
11208}
11209
11210#ifdef FEAT_LANGMAP
11211/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011212 * Any character has an equivalent 'langmap' character. This is used for
11213 * keyboards that have a special language mode that sends characters above
11214 * 128 (although other characters can be translated too). The "to" field is a
11215 * Vim command character. This avoids having to switch the keyboard back to
11216 * ASCII mode when leaving Insert mode.
11217 *
11218 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11219 * commands.
11220 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11221 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11222 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011223 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011224# ifdef FEAT_MBYTE
11225/*
11226 * With multi-byte support use growarray for 'langmap' chars >= 256
11227 */
11228typedef struct
11229{
11230 int from;
11231 int to;
11232} langmap_entry_T;
11233
11234static garray_T langmap_mapga;
11235static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236
11237/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011238 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11239 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011240 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011241 static void
11242langmap_set_entry(from, to)
11243 int from;
11244 int to;
11245{
11246 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011247 int a = 0;
11248 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011249
11250 /* Do a binary search for an existing entry. */
11251 while (a != b)
11252 {
11253 int i = (a + b) / 2;
11254 int d = entries[i].from - from;
11255
11256 if (d == 0)
11257 {
11258 entries[i].to = to;
11259 return;
11260 }
11261 if (d < 0)
11262 a = i + 1;
11263 else
11264 b = i;
11265 }
11266
11267 if (ga_grow(&langmap_mapga, 1) != OK)
11268 return; /* out of memory */
11269
11270 /* insert new entry at position "a" */
11271 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11272 mch_memmove(entries + 1, entries,
11273 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11274 ++langmap_mapga.ga_len;
11275 entries[0].from = from;
11276 entries[0].to = to;
11277}
11278
11279/*
11280 * Apply 'langmap' to multi-byte character "c" and return the result.
11281 */
11282 int
11283langmap_adjust_mb(c)
11284 int c;
11285{
11286 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11287 int a = 0;
11288 int b = langmap_mapga.ga_len;
11289
11290 while (a != b)
11291 {
11292 int i = (a + b) / 2;
11293 int d = entries[i].from - c;
11294
11295 if (d == 0)
11296 return entries[i].to; /* found matching entry */
11297 if (d < 0)
11298 a = i + 1;
11299 else
11300 b = i;
11301 }
11302 return c; /* no entry found, return "c" unmodified */
11303}
11304# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011305
11306 static void
11307langmap_init()
11308{
11309 int i;
11310
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011311 for (i = 0; i < 256; i++)
11312 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11313# ifdef FEAT_MBYTE
11314 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11315# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316}
11317
11318/*
11319 * Called when langmap option is set; the language map can be
11320 * changed at any time!
11321 */
11322 static void
11323langmap_set()
11324{
11325 char_u *p;
11326 char_u *p2;
11327 int from, to;
11328
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011329#ifdef FEAT_MBYTE
11330 ga_clear(&langmap_mapga); /* clear the previous map first */
11331#endif
11332 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011333
11334 for (p = p_langmap; p[0] != NUL; )
11335 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011336 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11337 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011338 {
11339 if (p2[0] == '\\' && p2[1] != NUL)
11340 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011341 }
11342 if (p2[0] == ';')
11343 ++p2; /* abcd;ABCD form, p2 points to A */
11344 else
11345 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11346 while (p[0])
11347 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011348 if (p[0] == ',')
11349 {
11350 ++p;
11351 break;
11352 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011353 if (p[0] == '\\' && p[1] != NUL)
11354 ++p;
11355#ifdef FEAT_MBYTE
11356 from = (*mb_ptr2char)(p);
11357#else
11358 from = p[0];
11359#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011360 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011361 if (p2 == NULL)
11362 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011363 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011364 if (p[0] != ',')
11365 {
11366 if (p[0] == '\\')
11367 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011369 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011370#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011371 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011373 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011374 }
11375 else
11376 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011377 if (p2[0] != ',')
11378 {
11379 if (p2[0] == '\\')
11380 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011381#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011382 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011383#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011384 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011385#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011386 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387 }
11388 if (to == NUL)
11389 {
11390 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11391 transchar(from));
11392 return;
11393 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011394
11395#ifdef FEAT_MBYTE
11396 if (from >= 256)
11397 langmap_set_entry(from, to);
11398 else
11399#endif
11400 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011401
11402 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011403 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011404 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011405 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011406 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011407 if (*p == ';')
11408 {
11409 p = p2;
11410 if (p[0] != NUL)
11411 {
11412 if (p[0] != ',')
11413 {
11414 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11415 return;
11416 }
11417 ++p;
11418 }
11419 break;
11420 }
11421 }
11422 }
11423 }
11424}
11425#endif
11426
11427/*
11428 * Return TRUE if format option 'x' is in effect.
11429 * Take care of no formatting when 'paste' is set.
11430 */
11431 int
11432has_format_option(x)
11433 int x;
11434{
11435 if (p_paste)
11436 return FALSE;
11437 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11438}
11439
11440/*
11441 * Return TRUE if "x" is present in 'shortmess' option, or
11442 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11443 */
11444 int
11445shortmess(x)
11446 int x;
11447{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011448 return p_shm != NULL &&
11449 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011450 || (vim_strchr(p_shm, 'a') != NULL
11451 && vim_strchr((char_u *)SHM_A, x) != NULL));
11452}
11453
11454/*
11455 * paste_option_changed() - Called after p_paste was set or reset.
11456 */
11457 static void
11458paste_option_changed()
11459{
11460 static int old_p_paste = FALSE;
11461 static int save_sm = 0;
11462#ifdef FEAT_CMDL_INFO
11463 static int save_ru = 0;
11464#endif
11465#ifdef FEAT_RIGHTLEFT
11466 static int save_ri = 0;
11467 static int save_hkmap = 0;
11468#endif
11469 buf_T *buf;
11470
11471 if (p_paste)
11472 {
11473 /*
11474 * Paste switched from off to on.
11475 * Save the current values, so they can be restored later.
11476 */
11477 if (!old_p_paste)
11478 {
11479 /* save options for each buffer */
11480 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11481 {
11482 buf->b_p_tw_nopaste = buf->b_p_tw;
11483 buf->b_p_wm_nopaste = buf->b_p_wm;
11484 buf->b_p_sts_nopaste = buf->b_p_sts;
11485 buf->b_p_ai_nopaste = buf->b_p_ai;
11486 }
11487
11488 /* save global options */
11489 save_sm = p_sm;
11490#ifdef FEAT_CMDL_INFO
11491 save_ru = p_ru;
11492#endif
11493#ifdef FEAT_RIGHTLEFT
11494 save_ri = p_ri;
11495 save_hkmap = p_hkmap;
11496#endif
11497 /* save global values for local buffer options */
11498 p_tw_nopaste = p_tw;
11499 p_wm_nopaste = p_wm;
11500 p_sts_nopaste = p_sts;
11501 p_ai_nopaste = p_ai;
11502 }
11503
11504 /*
11505 * Always set the option values, also when 'paste' is set when it is
11506 * already on.
11507 */
11508 /* set options for each buffer */
11509 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11510 {
11511 buf->b_p_tw = 0; /* textwidth is 0 */
11512 buf->b_p_wm = 0; /* wrapmargin is 0 */
11513 buf->b_p_sts = 0; /* softtabstop is 0 */
11514 buf->b_p_ai = 0; /* no auto-indent */
11515 }
11516
11517 /* set global options */
11518 p_sm = 0; /* no showmatch */
11519#ifdef FEAT_CMDL_INFO
11520# ifdef FEAT_WINDOWS
11521 if (p_ru)
11522 status_redraw_all(); /* redraw to remove the ruler */
11523# endif
11524 p_ru = 0; /* no ruler */
11525#endif
11526#ifdef FEAT_RIGHTLEFT
11527 p_ri = 0; /* no reverse insert */
11528 p_hkmap = 0; /* no Hebrew keyboard */
11529#endif
11530 /* set global values for local buffer options */
11531 p_tw = 0;
11532 p_wm = 0;
11533 p_sts = 0;
11534 p_ai = 0;
11535 }
11536
11537 /*
11538 * Paste switched from on to off: Restore saved values.
11539 */
11540 else if (old_p_paste)
11541 {
11542 /* restore options for each buffer */
11543 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11544 {
11545 buf->b_p_tw = buf->b_p_tw_nopaste;
11546 buf->b_p_wm = buf->b_p_wm_nopaste;
11547 buf->b_p_sts = buf->b_p_sts_nopaste;
11548 buf->b_p_ai = buf->b_p_ai_nopaste;
11549 }
11550
11551 /* restore global options */
11552 p_sm = save_sm;
11553#ifdef FEAT_CMDL_INFO
11554# ifdef FEAT_WINDOWS
11555 if (p_ru != save_ru)
11556 status_redraw_all(); /* redraw to draw the ruler */
11557# endif
11558 p_ru = save_ru;
11559#endif
11560#ifdef FEAT_RIGHTLEFT
11561 p_ri = save_ri;
11562 p_hkmap = save_hkmap;
11563#endif
11564 /* set global values for local buffer options */
11565 p_tw = p_tw_nopaste;
11566 p_wm = p_wm_nopaste;
11567 p_sts = p_sts_nopaste;
11568 p_ai = p_ai_nopaste;
11569 }
11570
11571 old_p_paste = p_paste;
11572}
11573
11574/*
11575 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11576 *
11577 * Reset 'compatible' and set the values for options that didn't get set yet
11578 * to the Vim defaults.
11579 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011580 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011581 */
11582 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011583vimrc_found(fname, envname)
11584 char_u *fname;
11585 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011586{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011587 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011588 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011589 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011590
11591 if (!option_was_set((char_u *)"cp"))
11592 {
11593 p_cp = FALSE;
11594 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11595 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11596 set_option_default(opt_idx, OPT_FREE, FALSE);
11597 didset_options();
11598 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011599
11600 if (fname != NULL)
11601 {
11602 p = vim_getenv(envname, &dofree);
11603 if (p == NULL)
11604 {
11605 /* Set $MYVIMRC to the first vimrc file found. */
11606 p = FullName_save(fname, FALSE);
11607 if (p != NULL)
11608 {
11609 vim_setenv(envname, p);
11610 vim_free(p);
11611 }
11612 }
11613 else if (dofree)
11614 vim_free(p);
11615 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616}
11617
11618/*
11619 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11620 */
11621 void
11622change_compatible(on)
11623 int on;
11624{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011625 int opt_idx;
11626
Bram Moolenaar071d4272004-06-13 20:20:40 +000011627 if (p_cp != on)
11628 {
11629 p_cp = on;
11630 compatible_set();
11631 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011632 opt_idx = findoption((char_u *)"cp");
11633 if (opt_idx >= 0)
11634 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011635}
11636
11637/*
11638 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011639 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640 */
11641 int
11642option_was_set(name)
11643 char_u *name;
11644{
11645 int idx;
11646
11647 idx = findoption(name);
11648 if (idx < 0) /* unknown option */
11649 return FALSE;
11650 if (options[idx].flags & P_WAS_SET)
11651 return TRUE;
11652 return FALSE;
11653}
11654
11655/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011656 * Reset the flag indicating option "name" was set.
11657 */
11658 void
11659reset_option_was_set(name)
11660 char_u *name;
11661{
11662 int idx = findoption(name);
11663
11664 if (idx >= 0)
11665 options[idx].flags &= ~P_WAS_SET;
11666}
11667
11668/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011669 * compatible_set() - Called when 'compatible' has been set or unset.
11670 *
11671 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11672 * flag) to a Vi compatible value.
11673 * When 'compatible' is unset: Set all options that have a different default
11674 * for Vim (without the P_VI_DEF flag) to that default.
11675 */
11676 static void
11677compatible_set()
11678{
11679 int opt_idx;
11680
11681 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11682 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11683 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11684 set_option_default(opt_idx, OPT_FREE, p_cp);
11685 didset_options();
11686}
11687
11688#ifdef FEAT_LINEBREAK
11689
11690# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11691 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011692 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011693# endif
11694
11695/*
11696 * fill_breakat_flags() -- called when 'breakat' changes value.
11697 */
11698 static void
11699fill_breakat_flags()
11700{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011701 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011702 int i;
11703
11704 for (i = 0; i < 256; i++)
11705 breakat_flags[i] = FALSE;
11706
11707 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011708 for (p = p_breakat; *p; p++)
11709 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011710}
11711
11712# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011713 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011714# endif
11715
11716#endif
11717
11718/*
11719 * Check an option that can be a range of string values.
11720 *
11721 * Return OK for correct value, FAIL otherwise.
11722 * Empty is always OK.
11723 */
11724 static int
11725check_opt_strings(val, values, list)
11726 char_u *val;
11727 char **values;
11728 int list; /* when TRUE: accept a list of values */
11729{
11730 return opt_strings_flags(val, values, NULL, list);
11731}
11732
11733/*
11734 * Handle an option that can be a range of string values.
11735 * Set a flag in "*flagp" for each string present.
11736 *
11737 * Return OK for correct value, FAIL otherwise.
11738 * Empty is always OK.
11739 */
11740 static int
11741opt_strings_flags(val, values, flagp, list)
11742 char_u *val; /* new value */
11743 char **values; /* array of valid string values */
11744 unsigned *flagp;
11745 int list; /* when TRUE: accept a list of values */
11746{
11747 int i;
11748 int len;
11749 unsigned new_flags = 0;
11750
11751 while (*val)
11752 {
11753 for (i = 0; ; ++i)
11754 {
11755 if (values[i] == NULL) /* val not found in values[] */
11756 return FAIL;
11757
11758 len = (int)STRLEN(values[i]);
11759 if (STRNCMP(values[i], val, len) == 0
11760 && ((list && val[len] == ',') || val[len] == NUL))
11761 {
11762 val += len + (val[len] == ',');
11763 new_flags |= (1 << i);
11764 break; /* check next item in val list */
11765 }
11766 }
11767 }
11768 if (flagp != NULL)
11769 *flagp = new_flags;
11770
11771 return OK;
11772}
11773
11774/*
11775 * Read the 'wildmode' option, fill wim_flags[].
11776 */
11777 static int
11778check_opt_wim()
11779{
11780 char_u new_wim_flags[4];
11781 char_u *p;
11782 int i;
11783 int idx = 0;
11784
11785 for (i = 0; i < 4; ++i)
11786 new_wim_flags[i] = 0;
11787
11788 for (p = p_wim; *p; ++p)
11789 {
11790 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11791 ;
11792 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11793 return FAIL;
11794 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11795 new_wim_flags[idx] |= WIM_LONGEST;
11796 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11797 new_wim_flags[idx] |= WIM_FULL;
11798 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11799 new_wim_flags[idx] |= WIM_LIST;
11800 else
11801 return FAIL;
11802 p += i;
11803 if (*p == NUL)
11804 break;
11805 if (*p == ',')
11806 {
11807 if (idx == 3)
11808 return FAIL;
11809 ++idx;
11810 }
11811 }
11812
11813 /* fill remaining entries with last flag */
11814 while (idx < 3)
11815 {
11816 new_wim_flags[idx + 1] = new_wim_flags[idx];
11817 ++idx;
11818 }
11819
11820 /* only when there are no errors, wim_flags[] is changed */
11821 for (i = 0; i < 4; ++i)
11822 wim_flags[i] = new_wim_flags[i];
11823 return OK;
11824}
11825
11826/*
11827 * Check if backspacing over something is allowed.
11828 */
11829 int
11830can_bs(what)
11831 int what; /* BS_INDENT, BS_EOL or BS_START */
11832{
11833 switch (*p_bs)
11834 {
11835 case '2': return TRUE;
11836 case '1': return (what != BS_START);
11837 case '0': return FALSE;
11838 }
11839 return vim_strchr(p_bs, what) != NULL;
11840}
11841
11842/*
11843 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11844 * the file must be considered changed when the value is different.
11845 */
11846 void
11847save_file_ff(buf)
11848 buf_T *buf;
11849{
11850 buf->b_start_ffc = *buf->b_p_ff;
11851 buf->b_start_eol = buf->b_p_eol;
11852#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011853 buf->b_start_bomb = buf->b_p_bomb;
11854
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855 /* Only use free/alloc when necessary, they take time. */
11856 if (buf->b_start_fenc == NULL
11857 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11858 {
11859 vim_free(buf->b_start_fenc);
11860 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11861 }
11862#endif
11863}
11864
11865/*
11866 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11867 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011868 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11869 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011870 * When "ignore_empty" is true don't consider a new, empty buffer to be
11871 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011872 */
11873 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011874file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011875 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011876 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011877{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011878 /* In a buffer that was never loaded the options are not valid. */
11879 if (buf->b_flags & BF_NEVERLOADED)
11880 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011881 if (ignore_empty
11882 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883 && buf->b_ml.ml_line_count == 1
11884 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11885 return FALSE;
11886 if (buf->b_start_ffc != *buf->b_p_ff)
11887 return TRUE;
11888 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11889 return TRUE;
11890#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011891 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11892 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893 if (buf->b_start_fenc == NULL)
11894 return (*buf->b_p_fenc != NUL);
11895 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11896#else
11897 return FALSE;
11898#endif
11899}
11900
11901/*
11902 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11903 */
11904 int
11905check_ff_value(p)
11906 char_u *p;
11907{
11908 return check_opt_strings(p, p_ff_values, FALSE);
11909}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011910
11911/*
11912 * Return the effective shiftwidth value for current buffer, using the
11913 * 'tabstop' value when 'shiftwidth' is zero.
11914 */
11915 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011916get_sw_value(buf)
11917 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011918{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011919 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011920}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011921
11922/*
11923 * Return the effective softtabstop value for the current buffer, using the
11924 * 'tabstop' value when 'softtabstop' is negative.
11925 */
11926 long
11927get_sts_value()
11928{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011929 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011930}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011931
11932/*
11933 * Check matchpairs option for "*initc".
11934 * If there is a match set "*initc" to the matching character and "*findc" to
11935 * the opposite character. Set "*backwards" to the direction.
11936 * When "switchit" is TRUE swap the direction.
11937 */
11938 void
11939find_mps_values(initc, findc, backwards, switchit)
11940 int *initc;
11941 int *findc;
11942 int *backwards;
11943 int switchit;
11944{
11945 char_u *ptr;
11946
11947 ptr = curbuf->b_p_mps;
11948 while (*ptr != NUL)
11949 {
11950#ifdef FEAT_MBYTE
11951 if (has_mbyte)
11952 {
11953 char_u *prev;
11954
11955 if (mb_ptr2char(ptr) == *initc)
11956 {
11957 if (switchit)
11958 {
11959 *findc = *initc;
11960 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11961 *backwards = TRUE;
11962 }
11963 else
11964 {
11965 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11966 *backwards = FALSE;
11967 }
11968 return;
11969 }
11970 prev = ptr;
11971 ptr += mb_ptr2len(ptr) + 1;
11972 if (mb_ptr2char(ptr) == *initc)
11973 {
11974 if (switchit)
11975 {
11976 *findc = *initc;
11977 *initc = mb_ptr2char(prev);
11978 *backwards = FALSE;
11979 }
11980 else
11981 {
11982 *findc = mb_ptr2char(prev);
11983 *backwards = TRUE;
11984 }
11985 return;
11986 }
11987 ptr += mb_ptr2len(ptr);
11988 }
11989 else
11990#endif
11991 {
11992 if (*ptr == *initc)
11993 {
11994 if (switchit)
11995 {
11996 *backwards = TRUE;
11997 *findc = *initc;
11998 *initc = ptr[2];
11999 }
12000 else
12001 {
12002 *backwards = FALSE;
12003 *findc = ptr[2];
12004 }
12005 return;
12006 }
12007 ptr += 2;
12008 if (*ptr == *initc)
12009 {
12010 if (switchit)
12011 {
12012 *backwards = FALSE;
12013 *findc = *initc;
12014 *initc = ptr[-2];
12015 }
12016 else
12017 {
12018 *backwards = TRUE;
12019 *findc = ptr[-2];
12020 }
12021 return;
12022 }
12023 ++ptr;
12024 }
12025 if (*ptr == ',')
12026 ++ptr;
12027 }
12028}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012029
12030#if defined(FEAT_LINEBREAK) || defined(PROTO)
12031/*
12032 * This is called when 'breakindentopt' is changed and when a window is
12033 * initialized.
12034 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012035 static int
12036briopt_check(wp)
12037 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012038{
12039 char_u *p;
12040 int bri_shift = 0;
12041 long bri_min = 20;
12042 int bri_sbr = FALSE;
12043
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012044 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012045 while (*p != NUL)
12046 {
12047 if (STRNCMP(p, "shift:", 6) == 0
12048 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12049 {
12050 p += 6;
12051 bri_shift = getdigits(&p);
12052 }
12053 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12054 {
12055 p += 4;
12056 bri_min = getdigits(&p);
12057 }
12058 else if (STRNCMP(p, "sbr", 3) == 0)
12059 {
12060 p += 3;
12061 bri_sbr = TRUE;
12062 }
12063 if (*p != ',' && *p != NUL)
12064 return FAIL;
12065 if (*p == ',')
12066 ++p;
12067 }
12068
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012069 wp->w_p_brishift = bri_shift;
12070 wp->w_p_brimin = bri_min;
12071 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012072
12073 return OK;
12074}
12075#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012076
12077/*
12078 * Get the local or global value of 'backupcopy'.
12079 */
12080 unsigned int
12081get_bkc_value(buf)
12082 buf_T *buf;
12083{
12084 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12085}