blob: cf3a3176265db291e833769bef420bb4c4d09317 [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 Moolenaar4391cf92014-11-05 17:44:52 +01001694 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1695#ifdef FEAT_LANGMAP
1696 (char_u *)&p_lnr, PV_NONE,
1697#else
1698 (char_u *)NULL, PV_NONE,
1699#endif
1700 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1702#ifdef FEAT_WINDOWS
1703 (char_u *)&p_ls, PV_NONE,
1704#else
1705 (char_u *)NULL, PV_NONE,
1706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001707 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1709 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1712#ifdef FEAT_LINEBREAK
1713 (char_u *)VAR_WIN, PV_LBR,
1714#else
1715 (char_u *)NULL, PV_NONE,
1716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001717 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1719 (char_u *)&Rows, PV_NONE,
1720 {
1721#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1722 (char_u *)25L,
1723#else
1724 (char_u *)24L,
1725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001726 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1728#ifdef FEAT_GUI
1729 (char_u *)&p_linespace, PV_NONE,
1730#else
1731 (char_u *)NULL, PV_NONE,
1732#endif
1733#ifdef FEAT_GUI_W32
1734 {(char_u *)1L, (char_u *)0L}
1735#else
1736 {(char_u *)0L, (char_u *)0L}
1737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001738 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"lisp", NULL, P_BOOL|P_VI_DEF,
1740#ifdef FEAT_LISP
1741 (char_u *)&p_lisp, PV_LISP,
1742#else
1743 (char_u *)NULL, PV_NONE,
1744#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1747#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001748 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1750#else
1751 (char_u *)NULL, PV_NONE,
1752 {(char_u *)"", (char_u *)0L}
1753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1756 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001757 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1759 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1762 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001764#ifdef FEAT_GUI_MAC
1765 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1766 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001768#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"magic", NULL, P_BOOL|P_VI_DEF,
1770 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001772 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773#ifdef FEAT_QUICKFIX
1774 (char_u *)&p_mef, PV_NONE,
1775 {(char_u *)"", (char_u *)0L}
1776#else
1777 (char_u *)NULL, PV_NONE,
1778 {(char_u *)NULL, (char_u *)0L}
1779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1782#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001783 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784# ifdef VMS
1785 {(char_u *)"MMS", (char_u *)0L}
1786# else
1787 {(char_u *)"make", (char_u *)0L}
1788# endif
1789#else
1790 (char_u *)NULL, PV_NONE,
1791 {(char_u *)NULL, (char_u *)0L}
1792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1795 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001796 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1797 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001798 {"matchtime", "mat", P_NUM|P_VI_DEF,
1799 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001800 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001801 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001802#ifdef FEAT_MBYTE
1803 (char_u *)&p_mco, PV_NONE,
1804#else
1805 (char_u *)NULL, PV_NONE,
1806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001807 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1809#ifdef FEAT_EVAL
1810 (char_u *)&p_mfd, PV_NONE,
1811#else
1812 (char_u *)NULL, PV_NONE,
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1816 (char_u *)&p_mmd, 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 {"maxmem", "mm", P_NUM|P_VI_DEF,
1819 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1821 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001822 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1823 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1826 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1828 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {"menuitems", "mis", P_NUM|P_VI_DEF,
1830#ifdef FEAT_MENU
1831 (char_u *)&p_mis, PV_NONE,
1832#else
1833 (char_u *)NULL, PV_NONE,
1834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001835 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 {"mesg", NULL, P_BOOL|P_VI_DEF,
1837 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001839 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001840#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001841 (char_u *)&p_msm, PV_NONE,
1842 {(char_u *)"460000,2000,500", (char_u *)0L}
1843#else
1844 (char_u *)NULL, PV_NONE,
1845 {(char_u *)0L, (char_u *)0L}
1846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 {"modeline", "ml", P_BOOL|P_VIM,
1849 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"modelines", "mls", P_NUM|P_VI_DEF,
1852 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001853 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001854 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1855 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001856 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1858 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"more", NULL, P_BOOL|P_VIM,
1861 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1864 (char_u *)&p_mouse, PV_NONE,
1865 {
1866#if defined(MSDOS) || defined(WIN3264)
1867 (char_u *)"a",
1868#else
1869 (char_u *)"",
1870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1873#ifdef FEAT_GUI
1874 (char_u *)&p_mousef, PV_NONE,
1875#else
1876 (char_u *)NULL, PV_NONE,
1877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001878 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1880#ifdef FEAT_GUI
1881 (char_u *)&p_mh, PV_NONE,
1882#else
1883 (char_u *)NULL, PV_NONE,
1884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001885 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1887 (char_u *)&p_mousem, PV_NONE,
1888 {
1889#if defined(MSDOS) || defined(MSWIN)
1890 (char_u *)"popup",
1891#else
1892# if defined(MACOS)
1893 (char_u *)"popup_setpos",
1894# else
1895 (char_u *)"extend",
1896# endif
1897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1900#ifdef FEAT_MOUSESHAPE
1901 (char_u *)&p_mouseshape, PV_NONE,
1902 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1903#else
1904 (char_u *)NULL, PV_NONE,
1905 {(char_u *)NULL, (char_u *)0L}
1906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001907 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001908 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1909 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001910 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001911 {"mzquantum", "mzq", P_NUM,
1912#ifdef FEAT_MZSCHEME
1913 (char_u *)&p_mzq, PV_NONE,
1914#else
1915 (char_u *)NULL, PV_NONE,
1916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001917 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"novice", NULL, P_BOOL|P_VI_DEF,
1919 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1922 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001923 {(char_u *)"octal,hex", (char_u *)0L}
1924 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1926 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001928 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1929#ifdef FEAT_LINEBREAK
1930 (char_u *)VAR_WIN, PV_NUW,
1931#else
1932 (char_u *)NULL, PV_NONE,
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001935 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001936#ifdef FEAT_COMPL_FUNC
1937 (char_u *)&p_ofu, PV_OFU,
1938 {(char_u *)"", (char_u *)0L}
1939#else
1940 (char_u *)NULL, PV_NONE,
1941 {(char_u *)0L, (char_u *)0L}
1942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"open", NULL, P_BOOL|P_VI_DEF,
1945 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001947 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1948#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1949 (char_u *)&p_odev, PV_NONE,
1950#else
1951 (char_u *)NULL, PV_NONE,
1952#endif
1953 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001955 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1956 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001957 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 {"optimize", "opt", P_BOOL|P_VI_DEF,
1959 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001960 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001963 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 {"paragraphs", "para", P_STRING|P_VI_DEF,
1965 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001966 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001968 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001969 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1972 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001973 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1975#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1976 (char_u *)&p_pex, PV_NONE,
1977 {(char_u *)"", (char_u *)0L}
1978#else
1979 (char_u *)NULL, PV_NONE,
1980 {(char_u *)0L, (char_u *)0L}
1981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001983 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001987 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {
1989#if defined AMIGA || defined MSDOS || defined MSWIN
1990 (char_u *)".,,",
1991#else
1992# if defined(__EMX__)
1993 (char_u *)".,/emx/include,,",
1994# else /* Unix, probably */
1995 (char_u *)".,/usr/include,,",
1996# endif
1997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2000 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002001 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002002 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2004 (char_u *)&p_pvh, PV_NONE,
2005#else
2006 (char_u *)NULL, PV_NONE,
2007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002008 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2010#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2011 (char_u *)VAR_WIN, PV_PVW,
2012#else
2013 (char_u *)NULL, PV_NONE,
2014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002016 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017#ifdef FEAT_PRINTER
2018 (char_u *)&p_pdev, PV_NONE,
2019 {(char_u *)"", (char_u *)0L}
2020#else
2021 (char_u *)NULL, PV_NONE,
2022 {(char_u *)NULL, (char_u *)0L}
2023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002024 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 {"printencoding", "penc", P_STRING|P_VI_DEF,
2026#ifdef FEAT_POSTSCRIPT
2027 (char_u *)&p_penc, PV_NONE,
2028 {(char_u *)"", (char_u *)0L}
2029#else
2030 (char_u *)NULL, PV_NONE,
2031 {(char_u *)NULL, (char_u *)0L}
2032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2035#ifdef FEAT_POSTSCRIPT
2036 (char_u *)&p_pexpr, PV_NONE,
2037 {(char_u *)"", (char_u *)0L}
2038#else
2039 (char_u *)NULL, PV_NONE,
2040 {(char_u *)NULL, (char_u *)0L}
2041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 {"printfont", "pfn", P_STRING|P_VI_DEF,
2044#ifdef FEAT_PRINTER
2045 (char_u *)&p_pfn, PV_NONE,
2046 {
2047# ifdef MSWIN
2048 (char_u *)"Courier_New:h10",
2049# else
2050 (char_u *)"courier",
2051# endif
2052 (char_u *)0L}
2053#else
2054 (char_u *)NULL, PV_NONE,
2055 {(char_u *)NULL, (char_u *)0L}
2056#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002057 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2059#ifdef FEAT_PRINTER
2060 (char_u *)&p_header, PV_NONE,
2061 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2062#else
2063 (char_u *)NULL, PV_NONE,
2064 {(char_u *)NULL, (char_u *)0L}
2065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002067 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2068#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2069 (char_u *)&p_pmcs, PV_NONE,
2070 {(char_u *)"", (char_u *)0L}
2071#else
2072 (char_u *)NULL, PV_NONE,
2073 {(char_u *)NULL, (char_u *)0L}
2074#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002075 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002076 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2077#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2078 (char_u *)&p_pmfn, PV_NONE,
2079 {(char_u *)"", (char_u *)0L}
2080#else
2081 (char_u *)NULL, PV_NONE,
2082 {(char_u *)NULL, (char_u *)0L}
2083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2086#ifdef FEAT_PRINTER
2087 (char_u *)&p_popt, PV_NONE,
2088 {(char_u *)"", (char_u *)0L}
2089#else
2090 (char_u *)NULL, PV_NONE,
2091 {(char_u *)NULL, (char_u *)0L}
2092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002095 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002097 {"pumheight", "ph", P_NUM|P_VI_DEF,
2098#ifdef FEAT_INS_EXPAND
2099 (char_u *)&p_ph, PV_NONE,
2100#else
2101 (char_u *)NULL, PV_NONE,
2102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002103 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002104 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2105#ifdef FEAT_TEXTOBJ
2106 (char_u *)&p_qe, PV_QE,
2107 {(char_u *)"\\", (char_u *)0L}
2108#else
2109 (char_u *)NULL, PV_NONE,
2110 {(char_u *)NULL, (char_u *)0L}
2111#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2114 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002115 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 {"redraw", NULL, P_BOOL|P_VI_DEF,
2117 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002118 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002119 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2120#ifdef FEAT_RELTIME
2121 (char_u *)&p_rdt, PV_NONE,
2122#else
2123 (char_u *)NULL, PV_NONE,
2124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002126 {"regexpengine", "re", P_NUM|P_VI_DEF,
2127 (char_u *)&p_re, PV_NONE,
2128 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002129 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2130 (char_u *)VAR_WIN, PV_RNU,
2131 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 {"remap", NULL, P_BOOL|P_VI_DEF,
2133 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002135 {"renderoptions", "rop", P_STRING|P_COMMA|P_RCLR|P_VI_DEF,
2136#ifdef FEAT_RENDER_OPTIONS
2137 (char_u *)&p_rop, PV_NONE,
2138 {(char_u *)"", (char_u *)0L}
2139#else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)NULL, (char_u *)0L}
2142#endif
2143 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"report", NULL, P_NUM|P_VI_DEF,
2145 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002146 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2148#ifdef WIN3264
2149 (char_u *)&p_rs, PV_NONE,
2150#else
2151 (char_u *)NULL, PV_NONE,
2152#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002153 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2155#ifdef FEAT_RIGHTLEFT
2156 (char_u *)&p_ri, PV_NONE,
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 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2162#ifdef FEAT_RIGHTLEFT
2163 (char_u *)VAR_WIN, PV_RL,
2164#else
2165 (char_u *)NULL, PV_NONE,
2166#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002167 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002168 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2169#ifdef FEAT_RIGHTLEFT
2170 (char_u *)VAR_WIN, PV_RLC,
2171 {(char_u *)"search", (char_u *)NULL}
2172#else
2173 (char_u *)NULL, PV_NONE,
2174 {(char_u *)NULL, (char_u *)0L}
2175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002176 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2178#ifdef FEAT_CMDL_INFO
2179 (char_u *)&p_ru, PV_NONE,
2180#else
2181 (char_u *)NULL, PV_NONE,
2182#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002183 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002184 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2185#ifdef FEAT_STL_OPT
2186 (char_u *)&p_ruf, PV_NONE,
2187#else
2188 (char_u *)NULL, PV_NONE,
2189#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002190 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2192 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2194 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002195 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2196 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002197 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002198 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2199#ifdef FEAT_SCROLLBIND
2200 (char_u *)VAR_WIN, PV_SCBIND,
2201#else
2202 (char_u *)NULL, PV_NONE,
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2206 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2209 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002210 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2212#ifdef FEAT_SCROLLBIND
2213 (char_u *)&p_sbo, PV_NONE,
2214 {(char_u *)"ver,jump", (char_u *)0L}
2215#else
2216 (char_u *)NULL, PV_NONE,
2217 {(char_u *)0L, (char_u *)0L}
2218#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002219 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002220 {"sections", "sect", P_STRING|P_VI_DEF,
2221 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2223 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2225 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002226 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002227 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002228 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 {(char_u *)"inclusive", (char_u *)0L}
2230 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2235#ifdef FEAT_SESSION
2236 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002237 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 (char_u *)0L}
2239#else
2240 (char_u *)NULL, PV_NONE,
2241 {(char_u *)0L, (char_u *)0L}
2242#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2245 (char_u *)&p_sh, PV_NONE,
2246 {
2247#ifdef VMS
2248 (char_u *)"-",
2249#else
2250# if defined(MSDOS)
2251 (char_u *)"command",
2252# else
2253# if defined(WIN16)
2254 (char_u *)"command.com",
2255# else
2256# if defined(WIN3264)
2257 (char_u *)"", /* set in set_init_1() */
2258# else
2259# if defined(OS2)
2260 (char_u *)"cmd.exe",
2261# else
2262# if defined(ARCHIE)
2263 (char_u *)"gos",
2264# else
2265 (char_u *)"sh",
2266# endif
2267# endif
2268# endif
2269# endif
2270# endif
2271#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2274 (char_u *)&p_shcf, PV_NONE,
2275 {
2276#if defined(MSDOS) || defined(MSWIN)
2277 (char_u *)"/c",
2278#else
2279# if defined(OS2)
2280 (char_u *)"/c",
2281# else
2282 (char_u *)"-c",
2283# endif
2284#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002285 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2287#ifdef FEAT_QUICKFIX
2288 (char_u *)&p_sp, PV_NONE,
2289 {
2290#if defined(UNIX) || defined(OS2)
2291# ifdef ARCHIE
2292 (char_u *)"2>",
2293# else
2294 (char_u *)"| tee",
2295# endif
2296#else
2297 (char_u *)">",
2298#endif
2299 (char_u *)0L}
2300#else
2301 (char_u *)NULL, PV_NONE,
2302 {(char_u *)0L, (char_u *)0L}
2303#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2306 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002307 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2309 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2312#ifdef BACKSLASH_IN_FILENAME
2313 (char_u *)&p_ssl, PV_NONE,
2314#else
2315 (char_u *)NULL, PV_NONE,
2316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002318 {"shelltemp", "stmp", P_BOOL,
2319 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002320 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"shelltype", "st", P_NUM|P_VI_DEF,
2322#ifdef AMIGA
2323 (char_u *)&p_st, PV_NONE,
2324#else
2325 (char_u *)NULL, PV_NONE,
2326#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2329 (char_u *)&p_sxq, PV_NONE,
2330 {
2331#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2332 (char_u *)"\"",
2333#else
2334 (char_u *)"",
2335#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002337 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2338 (char_u *)&p_sxe, PV_NONE,
2339 {
2340#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2341 (char_u *)"\"&|<>()@^",
2342#else
2343 (char_u *)"",
2344#endif
2345 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2347 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2350 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002352 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2353 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)"", (char_u *)"filnxtToO"}
2355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"shortname", "sn", P_BOOL|P_VI_DEF,
2357#ifdef SHORT_FNAME
2358 (char_u *)NULL, PV_NONE,
2359#else
2360 (char_u *)&p_sn, PV_SN,
2361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2364#ifdef FEAT_LINEBREAK
2365 (char_u *)&p_sbr, PV_NONE,
2366#else
2367 (char_u *)NULL, PV_NONE,
2368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 {"showcmd", "sc", P_BOOL|P_VIM,
2371#ifdef FEAT_CMDL_INFO
2372 (char_u *)&p_sc, PV_NONE,
2373#else
2374 (char_u *)NULL, PV_NONE,
2375#endif
2376 {(char_u *)FALSE,
2377#ifdef UNIX
2378 (char_u *)FALSE
2379#else
2380 (char_u *)TRUE
2381#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002382 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2384 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002385 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2387 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"showmode", "smd", P_BOOL|P_VIM,
2390 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002392 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2393#ifdef FEAT_WINDOWS
2394 (char_u *)&p_stal, PV_NONE,
2395#else
2396 (char_u *)NULL, PV_NONE,
2397#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002398 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2400 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002401 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2403 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2406 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2409 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2412#ifdef FEAT_SMARTINDENT
2413 (char_u *)&p_si, PV_SI,
2414#else
2415 (char_u *)NULL, PV_NONE,
2416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002417 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2419 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002420 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2422 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2425 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002426 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002427 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002428#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002429 (char_u *)VAR_WIN, PV_SPELL,
2430#else
2431 (char_u *)NULL, PV_NONE,
2432#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002433 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002434 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002435#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002436 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002437 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002438#else
2439 (char_u *)NULL, PV_NONE,
2440 {(char_u *)0L, (char_u *)0L}
2441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002443 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002444#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002445 (char_u *)&p_spf, PV_SPF,
2446 {(char_u *)"", (char_u *)0L}
2447#else
2448 (char_u *)NULL, PV_NONE,
2449 {(char_u *)0L, (char_u *)0L}
2450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002452 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002453#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002454 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002455 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002456#else
2457 (char_u *)NULL, PV_NONE,
2458 {(char_u *)0L, (char_u *)0L}
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002461 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002462#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002463 (char_u *)&p_sps, PV_NONE,
2464 {(char_u *)"best", (char_u *)0L}
2465#else
2466 (char_u *)NULL, PV_NONE,
2467 {(char_u *)0L, (char_u *)0L}
2468#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2471#ifdef FEAT_WINDOWS
2472 (char_u *)&p_sb, 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 {"splitright", "spr", P_BOOL|P_VI_DEF,
2478#ifdef FEAT_VERTSPLIT
2479 (char_u *)&p_spr, PV_NONE,
2480#else
2481 (char_u *)NULL, PV_NONE,
2482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2485 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2488#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002489 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490#else
2491 (char_u *)NULL, PV_NONE,
2492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2495 (char_u *)&p_su, PV_NONE,
2496 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002499#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 (char_u *)&p_sua, PV_SUA,
2501 {(char_u *)"", (char_u *)0L}
2502#else
2503 (char_u *)NULL, PV_NONE,
2504 {(char_u *)0L, (char_u *)0L}
2505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002506 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2508 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002509 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"swapsync", "sws", P_STRING|P_VI_DEF,
2511 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2514 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002516 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2517#ifdef FEAT_SYN_HL
2518 (char_u *)&p_smc, PV_SMC,
2519 {(char_u *)3000L, (char_u *)0L}
2520#else
2521 (char_u *)NULL, PV_NONE,
2522 {(char_u *)0L, (char_u *)0L}
2523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002524 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002525 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526#ifdef FEAT_SYN_HL
2527 (char_u *)&p_syn, PV_SYN,
2528 {(char_u *)"", (char_u *)0L}
2529#else
2530 (char_u *)NULL, PV_NONE,
2531 {(char_u *)0L, (char_u *)0L}
2532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002534 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2535#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002536 (char_u *)&p_tal, PV_NONE,
2537#else
2538 (char_u *)NULL, PV_NONE,
2539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002541 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2542#ifdef FEAT_WINDOWS
2543 (char_u *)&p_tpm, PV_NONE,
2544#else
2545 (char_u *)NULL, PV_NONE,
2546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2549 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2552 (char_u *)&p_tbs, PV_NONE,
2553#ifdef VMS /* binary searching doesn't appear to work on VMS */
2554 {(char_u *)0L, (char_u *)0L}
2555#else
2556 {(char_u *)TRUE, (char_u *)0L}
2557#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {"taglength", "tl", P_NUM|P_VI_DEF,
2560 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 {"tagrelative", "tr", P_BOOL|P_VIM,
2563 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002566 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {
2568#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2569 (char_u *)"./tags,./TAGS,tags,TAGS",
2570#else
2571 (char_u *)"./tags,tags",
2572#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002573 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2575 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2578 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2581#ifdef FEAT_ARABIC
2582 (char_u *)&p_tbidi, PV_NONE,
2583#else
2584 (char_u *)NULL, PV_NONE,
2585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2588#ifdef FEAT_MBYTE
2589 (char_u *)&p_tenc, PV_NONE,
2590 {(char_u *)"", (char_u *)0L}
2591#else
2592 (char_u *)NULL, PV_NONE,
2593 {(char_u *)0L, (char_u *)0L}
2594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002595 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 {"terse", NULL, P_BOOL|P_VI_DEF,
2597 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"textauto", "ta", P_BOOL|P_VIM,
2600 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002601 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2602 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2604 (char_u *)&p_tx, PV_TX,
2605 {
2606#ifdef USE_CRNL
2607 (char_u *)TRUE,
2608#else
2609 (char_u *)FALSE,
2610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002611 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002612 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2616#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002617 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618#else
2619 (char_u *)NULL, PV_NONE,
2620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2623 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 {"timeout", "to", P_BOOL|P_VI_DEF,
2626 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2629 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002630 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"title", NULL, P_BOOL|P_VI_DEF,
2632#ifdef FEAT_TITLE
2633 (char_u *)&p_title, PV_NONE,
2634#else
2635 (char_u *)NULL, PV_NONE,
2636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 {"titlelen", NULL, P_NUM|P_VI_DEF,
2639#ifdef FEAT_TITLE
2640 (char_u *)&p_titlelen, PV_NONE,
2641#else
2642 (char_u *)NULL, PV_NONE,
2643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002645 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646#ifdef FEAT_TITLE
2647 (char_u *)&p_titleold, PV_NONE,
2648 {(char_u *)N_("Thanks for flying Vim"),
2649 (char_u *)0L}
2650#else
2651 (char_u *)NULL, PV_NONE,
2652 {(char_u *)0L, (char_u *)0L}
2653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"titlestring", NULL, P_STRING|P_VI_DEF,
2656#ifdef FEAT_TITLE
2657 (char_u *)&p_titlestring, PV_NONE,
2658#else
2659 (char_u *)NULL, PV_NONE,
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2663 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2664 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 {(char_u *)"icons,tooltips", (char_u *)0L}
2666 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002668#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2670 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672#endif
2673 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2674 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002676 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2677 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2680 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002681 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2683 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2686#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2687 (char_u *)&p_ttym, PV_NONE,
2688#else
2689 (char_u *)NULL, PV_NONE,
2690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2693 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2696 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002698 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2699#ifdef FEAT_PERSISTENT_UNDO
2700 (char_u *)&p_udir, PV_NONE,
2701 {(char_u *)".", (char_u *)0L}
2702#else
2703 (char_u *)NULL, PV_NONE,
2704 {(char_u *)0L, (char_u *)0L}
2705#endif
2706 SCRIPTID_INIT},
2707 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2708#ifdef FEAT_PERSISTENT_UNDO
2709 (char_u *)&p_udf, PV_UDF,
2710#else
2711 (char_u *)NULL, PV_NONE,
2712#endif
2713 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002715 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {
2717#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2718 (char_u *)1000L,
2719#else
2720 (char_u *)100L,
2721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002723 {"undoreload", "ur", P_NUM|P_VI_DEF,
2724 (char_u *)&p_ur, PV_NONE,
2725 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726 {"updatecount", "uc", P_NUM|P_VI_DEF,
2727 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {"updatetime", "ut", P_NUM|P_VI_DEF,
2730 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"verbose", "vbs", P_NUM|P_VI_DEF,
2733 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002735 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2736 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002737 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2739#ifdef FEAT_SESSION
2740 (char_u *)&p_vdir, PV_NONE,
2741 {(char_u *)DFLT_VDIR, (char_u *)0L}
2742#else
2743 (char_u *)NULL, PV_NONE,
2744 {(char_u *)0L, (char_u *)0L}
2745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2748#ifdef FEAT_SESSION
2749 (char_u *)&p_vop, PV_NONE,
2750 {(char_u *)"folds,options,cursor", (char_u *)0L}
2751#else
2752 (char_u *)NULL, PV_NONE,
2753 {(char_u *)0L, (char_u *)0L}
2754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2757#ifdef FEAT_VIMINFO
2758 (char_u *)&p_viminfo, PV_NONE,
2759#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002760 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761#else
2762# ifdef AMIGA
2763 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002764 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002766 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767# endif
2768#endif
2769#else
2770 (char_u *)NULL, PV_NONE,
2771 {(char_u *)0L, (char_u *)0L}
2772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002774 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775#ifdef FEAT_VIRTUALEDIT
2776 (char_u *)&p_ve, PV_NONE,
2777 {(char_u *)"", (char_u *)""}
2778#else
2779 (char_u *)NULL, PV_NONE,
2780 {(char_u *)0L, (char_u *)0L}
2781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2784 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {"w300", NULL, P_NUM|P_VI_DEF,
2787 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 {"w1200", NULL, P_NUM|P_VI_DEF,
2790 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 {"w9600", NULL, P_NUM|P_VI_DEF,
2793 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 {"warn", NULL, P_BOOL|P_VI_DEF,
2796 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2799 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2802 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002803 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804 {"wildchar", "wc", P_NUM|P_VIM,
2805 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2807 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002808 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2812#ifdef FEAT_WILDIGN
2813 (char_u *)&p_wig, PV_NONE,
2814#else
2815 (char_u *)NULL, PV_NONE,
2816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002817 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002818 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2819 (char_u *)&p_wic, PV_NONE,
2820 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2822#ifdef FEAT_WILDMENU
2823 (char_u *)&p_wmnu, PV_NONE,
2824#else
2825 (char_u *)NULL, PV_NONE,
2826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002827 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2829 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002830 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002831 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2832#ifdef FEAT_CMDL_COMPL
2833 (char_u *)&p_wop, PV_NONE,
2834 {(char_u *)"", (char_u *)0L}
2835#else
2836 (char_u *)NULL, PV_NONE,
2837 {(char_u *)NULL, (char_u *)0L}
2838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2841#ifdef FEAT_WAK
2842 (char_u *)&p_wak, PV_NONE,
2843 {(char_u *)"menu", (char_u *)0L}
2844#else
2845 (char_u *)NULL, PV_NONE,
2846 {(char_u *)NULL, (char_u *)0L}
2847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002848 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002850 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002851 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 {"winheight", "wh", P_NUM|P_VI_DEF,
2853#ifdef FEAT_WINDOWS
2854 (char_u *)&p_wh, PV_NONE,
2855#else
2856 (char_u *)NULL, PV_NONE,
2857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002860#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 (char_u *)VAR_WIN, PV_WFH,
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 Moolenaar97b2ad32006-03-18 21:40:56 +00002866 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2867#ifdef FEAT_VERTSPLIT
2868 (char_u *)VAR_WIN, PV_WFW,
2869#else
2870 (char_u *)NULL, PV_NONE,
2871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2874#ifdef FEAT_WINDOWS
2875 (char_u *)&p_wmh, 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 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2881#ifdef FEAT_VERTSPLIT
2882 (char_u *)&p_wmw, PV_NONE,
2883#else
2884 (char_u *)NULL, PV_NONE,
2885#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2888#ifdef FEAT_VERTSPLIT
2889 (char_u *)&p_wiw, PV_NONE,
2890#else
2891 (char_u *)NULL, PV_NONE,
2892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2895 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002896 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2898 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002899 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2901 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002902 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903 {"write", NULL, P_BOOL|P_VI_DEF,
2904 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"writeany", "wa", P_BOOL|P_VI_DEF,
2907 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002908 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2910 (char_u *)&p_wb, PV_NONE,
2911 {
2912#ifdef FEAT_WRITEBACKUP
2913 (char_u *)TRUE,
2914#else
2915 (char_u *)FALSE,
2916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 {"writedelay", "wd", P_NUM|P_VI_DEF,
2919 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921
2922/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002923#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926
2927 p_term("t_AB", T_CAB)
2928 p_term("t_AF", T_CAF)
2929 p_term("t_AL", T_CAL)
2930 p_term("t_al", T_AL)
2931 p_term("t_bc", T_BC)
2932 p_term("t_cd", T_CD)
2933 p_term("t_ce", T_CE)
2934 p_term("t_cl", T_CL)
2935 p_term("t_cm", T_CM)
2936 p_term("t_Co", T_CCO)
2937 p_term("t_CS", T_CCS)
2938 p_term("t_cs", T_CS)
2939#ifdef FEAT_VERTSPLIT
2940 p_term("t_CV", T_CSV)
2941#endif
2942 p_term("t_ut", T_UT)
2943 p_term("t_da", T_DA)
2944 p_term("t_db", T_DB)
2945 p_term("t_DL", T_CDL)
2946 p_term("t_dl", T_DL)
2947 p_term("t_fs", T_FS)
2948 p_term("t_IE", T_CIE)
2949 p_term("t_IS", T_CIS)
2950 p_term("t_ke", T_KE)
2951 p_term("t_ks", T_KS)
2952 p_term("t_le", T_LE)
2953 p_term("t_mb", T_MB)
2954 p_term("t_md", T_MD)
2955 p_term("t_me", T_ME)
2956 p_term("t_mr", T_MR)
2957 p_term("t_ms", T_MS)
2958 p_term("t_nd", T_ND)
2959 p_term("t_op", T_OP)
2960 p_term("t_RI", T_CRI)
2961 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002962 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963 p_term("t_Sb", T_CSB)
2964 p_term("t_Sf", T_CSF)
2965 p_term("t_se", T_SE)
2966 p_term("t_so", T_SO)
2967 p_term("t_sr", T_SR)
2968 p_term("t_ts", T_TS)
2969 p_term("t_te", T_TE)
2970 p_term("t_ti", T_TI)
2971 p_term("t_ue", T_UE)
2972 p_term("t_us", T_US)
2973 p_term("t_vb", T_VB)
2974 p_term("t_ve", T_VE)
2975 p_term("t_vi", T_VI)
2976 p_term("t_vs", T_VS)
2977 p_term("t_WP", T_CWP)
2978 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002979 p_term("t_SI", T_CSI)
2980 p_term("t_EI", T_CEI)
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02002981 p_term("t_SR", T_CSR)
Bram Moolenaar494838a2015-02-10 19:20:37 +01002982 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 p_term("t_xs", T_XS)
2984 p_term("t_ZH", T_CZH)
2985 p_term("t_ZR", T_CZR)
2986
2987/* terminal key codes are not in here */
2988
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002989 /* end marker */
2990 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991};
2992
2993#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2994
2995#ifdef FEAT_MBYTE
2996static char *(p_ambw_values[]) = {"single", "double", NULL};
2997#endif
2998static char *(p_bg_values[]) = {"light", "dark", NULL};
2999static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
3000static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003001#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003002static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003003#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003004#ifdef FEAT_CMDL_COMPL
3005static char *(p_wop_values[]) = {"tagfile", NULL};
3006#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007#ifdef FEAT_WAK
3008static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3009#endif
3010static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3012static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014#ifdef FEAT_BROWSE
3015static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3016#endif
3017#ifdef FEAT_SCROLLBIND
3018static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3019#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003020static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021#ifdef FEAT_VERTSPLIT
3022static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3023#endif
3024#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003025# ifdef FEAT_AUTOCMD
3026static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3027# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003029# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3031#endif
3032static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3033#ifdef FEAT_FOLDING
3034static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003035# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003037# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 NULL};
3039static char *(p_fcl_values[]) = {"all", NULL};
3040#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003041#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003042static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003043#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044
3045static void set_option_default __ARGS((int, int opt_flags, int compatible));
3046static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003047static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003048static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049static char_u *illegal_char __ARGS((char_u *, int));
3050static int string_to_key __ARGS((char_u *arg));
3051#ifdef FEAT_CMDWIN
3052static char_u *check_cedit __ARGS((void));
3053#endif
3054#ifdef FEAT_TITLE
3055static void did_set_title __ARGS((int icon));
3056#endif
3057static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3058static void didset_options __ARGS((void));
3059static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003060#if defined(FEAT_EVAL) || defined(PROTO)
3061static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3062#else
3063# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3064#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003066static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067static 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));
3068static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003069#ifdef FEAT_SYN_HL
3070static int int_cmp __ARGS((const void *a, const void *b));
3071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072#ifdef FEAT_CLIPBOARD
3073static char_u *check_clipboard_option __ARGS((void));
3074#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003075#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003076static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003077#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003078#ifdef FEAT_EVAL
3079static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3080#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003082static 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 +00003083static void check_redraw __ARGS((long_u flags));
3084static int findoption __ARGS((char_u *));
3085static int find_key_option __ARGS((char_u *));
3086static void showoptions __ARGS((int all, int opt_flags));
3087static int optval_default __ARGS((struct vimoption *, char_u *varp));
3088static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3089static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3090static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3091static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3092static int istermoption __ARGS((struct vimoption *));
3093static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3094static char_u *get_varp __ARGS((struct vimoption *));
3095static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003096static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3098#ifdef FEAT_LANGMAP
3099static void langmap_init __ARGS((void));
3100static void langmap_set __ARGS((void));
3101#endif
3102static void paste_option_changed __ARGS((void));
3103static void compatible_set __ARGS((void));
3104#ifdef FEAT_LINEBREAK
3105static void fill_breakat_flags __ARGS((void));
3106#endif
3107static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3108static int check_opt_strings __ARGS((char_u *val, char **values, int));
3109static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003110#ifdef FEAT_LINEBREAK
3111static int briopt_check __ARGS((win_T *wp));
3112#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113
3114/*
3115 * Initialize the options, first part.
3116 *
3117 * Called only once from main(), just after creating the first buffer.
3118 */
3119 void
3120set_init_1()
3121{
3122 char_u *p;
3123 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003124 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125
3126#ifdef FEAT_LANGMAP
3127 langmap_init();
3128#endif
3129
3130 /* Be Vi compatible by default */
3131 p_cp = TRUE;
3132
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003133 /* Use POSIX compatibility when $VIM_POSIX is set. */
3134 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003135 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003136 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003137 set_string_default("shm", (char_u *)"A");
3138 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003139
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140 /*
3141 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003142 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003144 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3146# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003147 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003149 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003151 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152# endif
3153#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003154 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 set_string_default("sh", p);
3156
3157#ifdef FEAT_WILDIGN
3158 /*
3159 * Set the default for 'backupskip' to include environment variables for
3160 * temp files.
3161 */
3162 {
3163# ifdef UNIX
3164 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3165# else
3166 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3167# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003168 int len;
3169 garray_T ga;
3170 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171
3172 ga_init2(&ga, 1, 100);
3173 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3174 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003175 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176# ifdef UNIX
3177 if (*names[n] == NUL)
3178 p = (char_u *)"/tmp";
3179 else
3180# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003181 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182 if (p != NULL && *p != NUL)
3183 {
3184 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003185 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186 if (ga_grow(&ga, len) == OK)
3187 {
3188 if (ga.ga_len > 0)
3189 STRCAT(ga.ga_data, ",");
3190 STRCAT(ga.ga_data, p);
3191 add_pathsep(ga.ga_data);
3192 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 ga.ga_len += len;
3194 }
3195 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003196 if (mustfree)
3197 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198 }
3199 if (ga.ga_data != NULL)
3200 {
3201 set_string_default("bsk", ga.ga_data);
3202 vim_free(ga.ga_data);
3203 }
3204 }
3205#endif
3206
3207 /*
3208 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3209 */
3210 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003211 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003213#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3214 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3215#endif
3216 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003217#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003218 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003219 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220#else
3221# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003222 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003223 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003225 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226# endif
3227#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003229 opt_idx = findoption((char_u *)"maxmem");
3230 if (opt_idx >= 0)
3231 {
3232#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003233 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003234 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3235#endif
3236 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3237 }
3238 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239 }
3240
3241#ifdef FEAT_GUI_W32
3242 /* force 'shortname' for Win32s */
3243 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003244 {
3245 opt_idx = findoption((char_u *)"shortname");
3246 if (opt_idx >= 0)
3247 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3248 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249#endif
3250
3251#ifdef FEAT_SEARCHPATH
3252 {
3253 char_u *cdpath;
3254 char_u *buf;
3255 int i;
3256 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003257 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258
3259 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003260 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261 if (cdpath != NULL)
3262 {
3263 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3264 if (buf != NULL)
3265 {
3266 buf[0] = ','; /* start with ",", current dir first */
3267 j = 1;
3268 for (i = 0; cdpath[i] != NUL; ++i)
3269 {
3270 if (vim_ispathlistsep(cdpath[i]))
3271 buf[j++] = ',';
3272 else
3273 {
3274 if (cdpath[i] == ' ' || cdpath[i] == ',')
3275 buf[j++] = '\\';
3276 buf[j++] = cdpath[i];
3277 }
3278 }
3279 buf[j] = NUL;
3280 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003281 if (opt_idx >= 0)
3282 {
3283 options[opt_idx].def_val[VI_DEFAULT] = buf;
3284 options[opt_idx].flags |= P_DEF_ALLOCED;
3285 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003286 else
3287 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003288 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003289 if (mustfree)
3290 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291 }
3292 }
3293#endif
3294
3295#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3296 /* Set print encoding on platforms that don't default to latin1 */
3297 set_string_default("penc",
3298# if defined(MSWIN) || defined(OS2)
3299 (char_u *)"cp1252"
3300# else
3301# ifdef VMS
3302 (char_u *)"dec-mcs"
3303# else
3304# ifdef EBCDIC
3305 (char_u *)"ebcdic-uk"
3306# else
3307# ifdef MAC
3308 (char_u *)"mac-roman"
3309# else /* HPUX */
3310 (char_u *)"hp-roman8"
3311# endif
3312# endif
3313# endif
3314# endif
3315 );
3316#endif
3317
3318#ifdef FEAT_POSTSCRIPT
3319 /* 'printexpr' must be allocated to be able to evaluate it. */
3320 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003321# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3322 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323# else
3324# ifdef VMS
3325 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3326
3327# else
3328 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3329# endif
3330# endif
3331 );
3332#endif
3333
3334 /*
3335 * Set all the options (except the terminal options) to their default
3336 * value. Also set the global value for local options.
3337 */
3338 set_options_default(0);
3339
3340#ifdef FEAT_GUI
3341 if (found_reverse_arg)
3342 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3343#endif
3344
3345 curbuf->b_p_initialized = TRUE;
3346 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003347 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 check_buf_options(curbuf);
3349 check_win_options(curwin);
3350 check_options();
3351
3352 /* Must be before option_expand(), because that one needs vim_isIDc() */
3353 didset_options();
3354
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003355#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003356 /* Use the current chartab for the generic chartab. */
3357 init_spell_chartab();
3358#endif
3359
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360#ifdef FEAT_LINEBREAK
3361 /*
3362 * initialize the table for 'breakat'.
3363 */
3364 fill_breakat_flags();
3365#endif
3366
3367 /*
3368 * Expand environment variables and things like "~" for the defaults.
3369 * If option_expand() returns non-NULL the variable is expanded. This can
3370 * only happen for non-indirect options.
3371 * Also set the default to the expanded value, so ":set" does not list
3372 * them.
3373 * Don't set the P_ALLOCED flag, because we don't want to free the
3374 * default.
3375 */
3376 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3377 {
3378 if ((options[opt_idx].flags & P_GETTEXT)
3379 && options[opt_idx].var != NULL)
3380 p = (char_u *)_(*(char **)options[opt_idx].var);
3381 else
3382 p = option_expand(opt_idx, NULL);
3383 if (p != NULL && (p = vim_strsave(p)) != NULL)
3384 {
3385 *(char_u **)options[opt_idx].var = p;
3386 /* VIMEXP
3387 * Defaults for all expanded options are currently the same for Vi
3388 * and Vim. When this changes, add some code here! Also need to
3389 * split P_DEF_ALLOCED in two.
3390 */
3391 if (options[opt_idx].flags & P_DEF_ALLOCED)
3392 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3393 options[opt_idx].def_val[VI_DEFAULT] = p;
3394 options[opt_idx].flags |= P_DEF_ALLOCED;
3395 }
3396 }
3397
3398 /* Initialize the highlight_attr[] table. */
3399 highlight_changed();
3400
3401 save_file_ff(curbuf); /* Buffer is unchanged */
3402
3403 /* Parse default for 'wildmode' */
3404 check_opt_wim();
3405
3406#if defined(FEAT_ARABIC)
3407 /* Detect use of mlterm.
3408 * Mlterm is a terminal emulator akin to xterm that has some special
3409 * abilities (bidi namely).
3410 * NOTE: mlterm's author is being asked to 'set' a variable
3411 * instead of an environment variable due to inheritance.
3412 */
3413 if (mch_getenv((char_u *)"MLTERM") != NULL)
3414 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3415#endif
3416
3417#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3418 /* Parse default for 'fillchars'. */
3419 (void)set_chars_option(&p_fcs);
3420#endif
3421
3422#ifdef FEAT_CLIPBOARD
3423 /* Parse default for 'clipboard' */
3424 (void)check_clipboard_option();
3425#endif
3426
3427#ifdef FEAT_MBYTE
3428# if defined(WIN3264) && defined(FEAT_GETTEXT)
3429 /*
3430 * If $LANG isn't set, try to get a good value for it. This makes the
3431 * right language be used automatically. Don't do this for English.
3432 */
3433 if (mch_getenv((char_u *)"LANG") == NULL)
3434 {
3435 char buf[20];
3436
3437 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3438 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3439 * only the first two. */
3440 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3441 (LPTSTR)buf, 20);
3442 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3443 {
3444 /* There are a few exceptions (probably more) */
3445 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3446 STRCPY(buf, "zh_TW");
3447 else if (STRNICMP(buf, "chs", 3) == 0
3448 || STRNICMP(buf, "zhc", 3) == 0)
3449 STRCPY(buf, "zh_CN");
3450 else if (STRNICMP(buf, "jp", 2) == 0)
3451 STRCPY(buf, "ja");
3452 else
3453 buf[2] = NUL; /* truncate to two-letter code */
3454 vim_setenv("LANG", buf);
3455 }
3456 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003457# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003458# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003459 /* Moved to os_mac_conv.c to avoid dependency problems. */
3460 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003461# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462# endif
3463
3464 /* enc_locale() will try to find the encoding of the current locale. */
3465 p = enc_locale();
3466 if (p != NULL)
3467 {
3468 char_u *save_enc;
3469
3470 /* Try setting 'encoding' and check if the value is valid.
3471 * If not, go back to the default "latin1". */
3472 save_enc = p_enc;
3473 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003474 if (STRCMP(p_enc, "gb18030") == 0)
3475 {
3476 /* We don't support "gb18030", but "cp936" is a good substitute
3477 * for practical purposes, thus use that. It's not an alias to
3478 * still support conversion between gb18030 and utf-8. */
3479 p_enc = vim_strsave((char_u *)"cp936");
3480 vim_free(p);
3481 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482 if (mb_init() == NULL)
3483 {
3484 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003485 if (opt_idx >= 0)
3486 {
3487 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3488 options[opt_idx].flags |= P_DEF_ALLOCED;
3489 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003491#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3492 || defined(VMS)
3493 if (STRCMP(p_enc, "latin1") == 0
3494# ifdef FEAT_MBYTE
3495 || enc_utf8
3496# endif
3497 )
3498 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003499 /* Adjust the default for 'isprint' and 'iskeyword' to match
3500 * latin1. Also set the defaults for when 'nocompatible' is
3501 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003502 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003503 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003504 set_string_option_direct((char_u *)"isk", -1,
3505 ISK_LATIN1, OPT_FREE, SID_NONE);
3506 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003507 if (opt_idx >= 0)
3508 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003509 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003510 if (opt_idx >= 0)
3511 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003512 (void)init_chartab();
3513 }
3514#endif
3515
Bram Moolenaar071d4272004-06-13 20:20:40 +00003516# if defined(WIN3264) && !defined(FEAT_GUI)
3517 /* Win32 console: When GetACP() returns a different value from
3518 * GetConsoleCP() set 'termencoding'. */
3519 if (GetACP() != GetConsoleCP())
3520 {
3521 char buf[50];
3522
3523 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3524 p_tenc = vim_strsave((char_u *)buf);
3525 if (p_tenc != NULL)
3526 {
3527 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003528 if (opt_idx >= 0)
3529 {
3530 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3531 options[opt_idx].flags |= P_DEF_ALLOCED;
3532 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533 convert_setup(&input_conv, p_tenc, p_enc);
3534 convert_setup(&output_conv, p_enc, p_tenc);
3535 }
3536 else
3537 p_tenc = empty_option;
3538 }
3539# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003540# if defined(WIN3264) && defined(FEAT_MBYTE)
3541 /* $HOME may have characters in active code page. */
3542 init_homedir();
3543# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003544 }
3545 else
3546 {
3547 vim_free(p_enc);
3548 p_enc = save_enc;
3549 }
3550 }
3551#endif
3552
3553#ifdef FEAT_MULTI_LANG
3554 /* Set the default for 'helplang'. */
3555 set_helplang_default(get_mess_lang());
3556#endif
3557}
3558
3559/*
3560 * Set an option to its default value.
3561 * This does not take care of side effects!
3562 */
3563 static void
3564set_option_default(opt_idx, opt_flags, compatible)
3565 int opt_idx;
3566 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3567 int compatible; /* use Vi default value */
3568{
3569 char_u *varp; /* pointer to variable for current option */
3570 int dvi; /* index in def_val[] */
3571 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003572 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3574
3575 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3576 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003577 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003578 {
3579 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3580 if (flags & P_STRING)
3581 {
3582 /* Use set_string_option_direct() for local options to handle
3583 * freeing and allocating the value. */
3584 if (options[opt_idx].indir != PV_NONE)
3585 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003586 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587 else
3588 {
3589 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3590 free_string_option(*(char_u **)(varp));
3591 *(char_u **)varp = options[opt_idx].def_val[dvi];
3592 options[opt_idx].flags &= ~P_ALLOCED;
3593 }
3594 }
3595 else if (flags & P_NUM)
3596 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003597 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 win_comp_scroll(curwin);
3599 else
3600 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003601 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003602 /* May also set global value for local option. */
3603 if (both)
3604 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3605 *(long *)varp;
3606 }
3607 }
3608 else /* P_BOOL */
3609 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003610 /* the cast to long is required for Manx C, long_i is needed for
3611 * MSVC */
3612 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003613#ifdef UNIX
3614 /* 'modeline' defaults to off for root */
3615 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3616 *(int *)varp = FALSE;
3617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 /* May also set global value for local option. */
3619 if (both)
3620 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3621 *(int *)varp;
3622 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003623
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003624 /* The default value is not insecure. */
3625 flagsp = insecure_flag(opt_idx, opt_flags);
3626 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 }
3628
3629#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003630 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003631#endif
3632}
3633
3634/*
3635 * Set all options (except terminal options) to their default value.
3636 */
3637 static void
3638set_options_default(opt_flags)
3639 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3640{
3641 int i;
3642#ifdef FEAT_WINDOWS
3643 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003644 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003645#endif
3646
3647 for (i = 0; !istermoption(&options[i]); i++)
3648 if (!(options[i].flags & P_NODEFAULT))
3649 set_option_default(i, opt_flags, p_cp);
3650
3651#ifdef FEAT_WINDOWS
3652 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003653 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 win_comp_scroll(wp);
3655#else
3656 win_comp_scroll(curwin);
3657#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003658#ifdef FEAT_CINDENT
3659 parse_cino(curbuf);
3660#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661}
3662
3663/*
3664 * Set the Vi-default value of a string option.
3665 * Used for 'sh', 'backupskip' and 'term'.
3666 */
3667 void
3668set_string_default(name, val)
3669 char *name;
3670 char_u *val;
3671{
3672 char_u *p;
3673 int opt_idx;
3674
3675 p = vim_strsave(val);
3676 if (p != NULL) /* we don't want a NULL */
3677 {
3678 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003679 if (opt_idx >= 0)
3680 {
3681 if (options[opt_idx].flags & P_DEF_ALLOCED)
3682 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3683 options[opt_idx].def_val[VI_DEFAULT] = p;
3684 options[opt_idx].flags |= P_DEF_ALLOCED;
3685 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686 }
3687}
3688
3689/*
3690 * Set the Vi-default value of a number option.
3691 * Used for 'lines' and 'columns'.
3692 */
3693 void
3694set_number_default(name, val)
3695 char *name;
3696 long val;
3697{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003698 int opt_idx;
3699
3700 opt_idx = findoption((char_u *)name);
3701 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003702 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703}
3704
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003705#if defined(EXITFREE) || defined(PROTO)
3706/*
3707 * Free all options.
3708 */
3709 void
3710free_all_options()
3711{
3712 int i;
3713
3714 for (i = 0; !istermoption(&options[i]); i++)
3715 {
3716 if (options[i].indir == PV_NONE)
3717 {
3718 /* global option: free value and default value. */
3719 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3720 free_string_option(*(char_u **)options[i].var);
3721 if (options[i].flags & P_DEF_ALLOCED)
3722 free_string_option(options[i].def_val[VI_DEFAULT]);
3723 }
3724 else if (options[i].var != VAR_WIN
3725 && (options[i].flags & P_STRING))
3726 /* buffer-local option: free global value */
3727 free_string_option(*(char_u **)options[i].var);
3728 }
3729}
3730#endif
3731
3732
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733/*
3734 * Initialize the options, part two: After getting Rows and Columns and
3735 * setting 'term'.
3736 */
3737 void
3738set_init_2()
3739{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003740 int idx;
3741
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742 /*
3743 * 'scroll' defaults to half the window height. Note that this default is
3744 * wrong when the window height changes.
3745 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003746 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003747 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003748 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003749 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750 comp_col();
3751
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003752 /*
3753 * 'window' is only for backwards compatibility with Vi.
3754 * Default is Rows - 1.
3755 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003756 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003757 p_window = Rows - 1;
3758 set_number_default("window", Rows - 1);
3759
Bram Moolenaarf740b292006-02-16 22:11:02 +00003760 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003762 /*
3763 * If 'background' wasn't set by the user, try guessing the value,
3764 * depending on the terminal name. Only need to check for terminals
3765 * with a dark background, that can handle color.
3766 */
3767 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003768 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3769 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003771 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003772 /* don't mark it as set, when starting the GUI it may be
3773 * changed again */
3774 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003775 }
3776#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003777
3778#ifdef CURSOR_SHAPE
3779 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3780#endif
3781#ifdef FEAT_MOUSESHAPE
3782 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3783#endif
3784#ifdef FEAT_PRINTER
3785 (void)parse_printoptions(); /* parse 'printoptions' default value */
3786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787}
3788
3789/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003790 * Return "dark" or "light" depending on the kind of terminal.
3791 * This is just guessing! Recognized are:
3792 * "linux" Linux console
3793 * "screen.linux" Linux console with screen
3794 * "cygwin" Cygwin shell
3795 * "putty" Putty program
3796 * We also check the COLORFGBG environment variable, which is set by
3797 * rxvt and derivatives. This variable contains either two or three
3798 * values separated by semicolons; we want the last value in either
3799 * case. If this value is 0-6 or 8, our background is dark.
3800 */
3801 static char_u *
3802term_bg_default()
3803{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003804#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3805 /* DOS console nearly always black */
3806 return (char_u *)"dark";
3807#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003808 char_u *p;
3809
Bram Moolenaarf740b292006-02-16 22:11:02 +00003810 if (STRCMP(T_NAME, "linux") == 0
3811 || STRCMP(T_NAME, "screen.linux") == 0
3812 || STRCMP(T_NAME, "cygwin") == 0
3813 || STRCMP(T_NAME, "putty") == 0
3814 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3815 && (p = vim_strrchr(p, ';')) != NULL
3816 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3817 && p[2] == NUL))
3818 return (char_u *)"dark";
3819 return (char_u *)"light";
3820#endif
3821}
3822
3823/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824 * Initialize the options, part three: After reading the .vimrc
3825 */
3826 void
3827set_init_3()
3828{
3829#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3830/*
3831 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3832 * This is done after other initializations, where 'shell' might have been
3833 * set, but only if they have not been set before.
3834 */
3835 char_u *p;
3836 int idx_srr;
3837 int do_srr;
3838#ifdef FEAT_QUICKFIX
3839 int idx_sp;
3840 int do_sp;
3841#endif
3842
3843 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003844 if (idx_srr < 0)
3845 do_srr = FALSE;
3846 else
3847 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848#ifdef FEAT_QUICKFIX
3849 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003850 if (idx_sp < 0)
3851 do_sp = FALSE;
3852 else
3853 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003855 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003856 if (p != NULL)
3857 {
3858 /*
3859 * Default for p_sp is "| tee", for p_srr is ">".
3860 * For known shells it is changed here to include stderr.
3861 */
3862 if ( fnamecmp(p, "csh") == 0
3863 || fnamecmp(p, "tcsh") == 0
3864# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3865 || fnamecmp(p, "csh.exe") == 0
3866 || fnamecmp(p, "tcsh.exe") == 0
3867# endif
3868 )
3869 {
3870#if defined(FEAT_QUICKFIX)
3871 if (do_sp)
3872 {
3873# ifdef WIN3264
3874 p_sp = (char_u *)">&";
3875# else
3876 p_sp = (char_u *)"|& tee";
3877# endif
3878 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3879 }
3880#endif
3881 if (do_srr)
3882 {
3883 p_srr = (char_u *)">&";
3884 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3885 }
3886 }
3887 else
3888# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3889 if ( fnamecmp(p, "sh") == 0
3890 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003891 || fnamecmp(p, "mksh") == 0
3892 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003894 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003896 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897# ifdef WIN3264
3898 || fnamecmp(p, "cmd") == 0
3899 || fnamecmp(p, "sh.exe") == 0
3900 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003901 || fnamecmp(p, "mksh.exe") == 0
3902 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003904 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003905 || fnamecmp(p, "bash.exe") == 0
3906 || fnamecmp(p, "cmd.exe") == 0
3907# endif
3908 )
3909# endif
3910 {
3911#if defined(FEAT_QUICKFIX)
3912 if (do_sp)
3913 {
3914# ifdef WIN3264
3915 p_sp = (char_u *)">%s 2>&1";
3916# else
3917 p_sp = (char_u *)"2>&1| tee";
3918# endif
3919 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3920 }
3921#endif
3922 if (do_srr)
3923 {
3924 p_srr = (char_u *)">%s 2>&1";
3925 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3926 }
3927 }
3928 vim_free(p);
3929 }
3930#endif
3931
3932#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3933 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003934 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3935 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003936 * This is done after other initializations, where 'shell' might have been
3937 * set, but only if they have not been set before. Default for p_shcf is
3938 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3939 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3940 * command.com. And for Win32 we need to set p_sxq instead.
3941 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003942 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 {
3944 int idx3;
3945
3946 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003947 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 {
3949 p_shcf = (char_u *)"-c";
3950 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3951 }
3952
3953# ifndef DJGPP
3954# ifdef WIN3264
3955 /* Somehow Win32 requires the quotes around the redirection too */
3956 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003957 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958 {
3959 p_sxq = (char_u *)"\"";
3960 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3961 }
3962# else
3963 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003964 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003965 {
3966 p_shq = (char_u *)"\"";
3967 options[idx3].def_val[VI_DEFAULT] = p_shq;
3968 }
3969# endif
3970# endif
3971 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003972 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3973 {
3974 int idx3;
3975
3976 /*
3977 * cmd.exe on Windows will strip the first and last double quote given
3978 * on the command line, e.g. most of the time things like:
3979 * cmd /c "my path/to/echo" "my args to echo"
3980 * become:
3981 * my path/to/echo" "my args to echo
3982 * when executed.
3983 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003984 * To avoid this, set shellxquote to surround the command in
3985 * parenthesis. This appears to make most commands work, without
3986 * breaking commands that worked previously, such as
3987 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003988 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003989 idx3 = findoption((char_u *)"sxq");
3990 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3991 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003992 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003993 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3994 }
3995
Bram Moolenaara64ba222012-02-12 23:23:31 +01003996 idx3 = findoption((char_u *)"shcf");
3997 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3998 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003999 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004000 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4001 }
4002 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003#endif
4004
4005#ifdef FEAT_TITLE
4006 set_title_defaults();
4007#endif
4008}
4009
4010#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4011/*
4012 * When 'helplang' is still at its default value, set it to "lang".
4013 * Only the first two characters of "lang" are used.
4014 */
4015 void
4016set_helplang_default(lang)
4017 char_u *lang;
4018{
4019 int idx;
4020
4021 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4022 return;
4023 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004024 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004025 {
4026 if (options[idx].flags & P_ALLOCED)
4027 free_string_option(p_hlg);
4028 p_hlg = vim_strsave(lang);
4029 if (p_hlg == NULL)
4030 p_hlg = empty_option;
4031 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004032 {
4033 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4034 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4035 {
4036 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4037 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4038 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004040 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041 options[idx].flags |= P_ALLOCED;
4042 }
4043}
4044#endif
4045
4046#ifdef FEAT_GUI
4047static char_u *gui_bg_default __ARGS((void));
4048
4049 static char_u *
4050gui_bg_default()
4051{
4052 if (gui_get_lightness(gui.back_pixel) < 127)
4053 return (char_u *)"dark";
4054 return (char_u *)"light";
4055}
4056
4057/*
4058 * Option initializations that can only be done after opening the GUI window.
4059 */
4060 void
4061init_gui_options()
4062{
4063 /* Set the 'background' option according to the lightness of the
4064 * background color, unless the user has set it already. */
4065 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4066 {
4067 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4068 highlight_changed();
4069 }
4070}
4071#endif
4072
4073#ifdef FEAT_TITLE
4074/*
4075 * 'title' and 'icon' only default to true if they have not been set or reset
4076 * in .vimrc and we can read the old value.
4077 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4078 * they can be reset. This reduces startup time when using X on a remote
4079 * machine.
4080 */
4081 void
4082set_title_defaults()
4083{
4084 int idx1;
4085 long val;
4086
4087 /*
4088 * If GUI is (going to be) used, we can always set the window title and
4089 * icon name. Saves a bit of time, because the X11 display server does
4090 * not need to be contacted.
4091 */
4092 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004093 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 {
4095#ifdef FEAT_GUI
4096 if (gui.starting || gui.in_use)
4097 val = TRUE;
4098 else
4099#endif
4100 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004101 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 p_title = val;
4103 }
4104 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004105 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 {
4107#ifdef FEAT_GUI
4108 if (gui.starting || gui.in_use)
4109 val = TRUE;
4110 else
4111#endif
4112 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004113 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 p_icon = val;
4115 }
4116}
4117#endif
4118
4119/*
4120 * Parse 'arg' for option settings.
4121 *
4122 * 'arg' may be IObuff, but only when no errors can be present and option
4123 * does not need to be expanded with option_expand().
4124 * "opt_flags":
4125 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004126 * OPT_GLOBAL for ":setglobal"
4127 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004129 * OPT_WINONLY to only set window-local options
4130 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 *
4132 * returns FAIL if an error is detected, OK otherwise
4133 */
4134 int
4135do_set(arg, opt_flags)
4136 char_u *arg; /* option string (may be written to!) */
4137 int opt_flags;
4138{
4139 int opt_idx;
4140 char_u *errmsg;
4141 char_u errbuf[80];
4142 char_u *startarg;
4143 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4144 int nextchar; /* next non-white char after option name */
4145 int afterchar; /* character just after option name */
4146 int len;
4147 int i;
4148 long value;
4149 int key;
4150 long_u flags; /* flags for current option */
4151 char_u *varp = NULL; /* pointer to variable for current option */
4152 int did_show = FALSE; /* already showed one value */
4153 int adding; /* "opt+=arg" */
4154 int prepending; /* "opt^=arg" */
4155 int removing; /* "opt-=arg" */
4156 int cp_val = 0;
4157 char_u key_name[2];
4158
4159 if (*arg == NUL)
4160 {
4161 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004162 did_show = TRUE;
4163 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004164 }
4165
4166 while (*arg != NUL) /* loop to process all options */
4167 {
4168 errmsg = NULL;
4169 startarg = arg; /* remember for error message */
4170
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004171 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4172 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004173 {
4174 /*
4175 * ":set all" show all options.
4176 * ":set all&" set all options to their default value.
4177 */
4178 arg += 3;
4179 if (*arg == '&')
4180 {
4181 ++arg;
4182 /* Only for :set command set global value of local options. */
4183 set_options_default(OPT_FREE | opt_flags);
4184 }
4185 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004186 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004188 did_show = TRUE;
4189 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004191 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004192 {
4193 showoptions(2, opt_flags);
4194 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004195 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004196 arg += 7;
4197 }
4198 else
4199 {
4200 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004201 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004202 {
4203 prefix = 0;
4204 arg += 2;
4205 }
4206 else if (STRNCMP(arg, "inv", 3) == 0)
4207 {
4208 prefix = 2;
4209 arg += 3;
4210 }
4211
4212 /* find end of name */
4213 key = 0;
4214 if (*arg == '<')
4215 {
4216 nextchar = 0;
4217 opt_idx = -1;
4218 /* look out for <t_>;> */
4219 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4220 len = 5;
4221 else
4222 {
4223 len = 1;
4224 while (arg[len] != NUL && arg[len] != '>')
4225 ++len;
4226 }
4227 if (arg[len] != '>')
4228 {
4229 errmsg = e_invarg;
4230 goto skip;
4231 }
4232 arg[len] = NUL; /* put NUL after name */
4233 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4234 opt_idx = findoption(arg + 1);
4235 arg[len++] = '>'; /* restore '>' */
4236 if (opt_idx == -1)
4237 key = find_key_option(arg + 1);
4238 }
4239 else
4240 {
4241 len = 0;
4242 /*
4243 * The two characters after "t_" may not be alphanumeric.
4244 */
4245 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4246 len = 4;
4247 else
4248 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4249 ++len;
4250 nextchar = arg[len];
4251 arg[len] = NUL; /* put NUL after name */
4252 opt_idx = findoption(arg);
4253 arg[len] = nextchar; /* restore nextchar */
4254 if (opt_idx == -1)
4255 key = find_key_option(arg);
4256 }
4257
4258 /* remember character after option name */
4259 afterchar = arg[len];
4260
4261 /* skip white space, allow ":set ai ?" */
4262 while (vim_iswhite(arg[len]))
4263 ++len;
4264
4265 adding = FALSE;
4266 prepending = FALSE;
4267 removing = FALSE;
4268 if (arg[len] != NUL && arg[len + 1] == '=')
4269 {
4270 if (arg[len] == '+')
4271 {
4272 adding = TRUE; /* "+=" */
4273 ++len;
4274 }
4275 else if (arg[len] == '^')
4276 {
4277 prepending = TRUE; /* "^=" */
4278 ++len;
4279 }
4280 else if (arg[len] == '-')
4281 {
4282 removing = TRUE; /* "-=" */
4283 ++len;
4284 }
4285 }
4286 nextchar = arg[len];
4287
4288 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4289 {
4290 errmsg = (char_u *)N_("E518: Unknown option");
4291 goto skip;
4292 }
4293
4294 if (opt_idx >= 0)
4295 {
4296 if (options[opt_idx].var == NULL) /* hidden option: skip */
4297 {
4298 /* Only give an error message when requesting the value of
4299 * a hidden option, ignore setting it. */
4300 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4301 && (!(options[opt_idx].flags & P_BOOL)
4302 || nextchar == '?'))
4303 errmsg = (char_u *)N_("E519: Option not supported");
4304 goto skip;
4305 }
4306
4307 flags = options[opt_idx].flags;
4308 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4309 }
4310 else
4311 {
4312 flags = P_STRING;
4313 if (key < 0)
4314 {
4315 key_name[0] = KEY2TERMCAP0(key);
4316 key_name[1] = KEY2TERMCAP1(key);
4317 }
4318 else
4319 {
4320 key_name[0] = KS_KEY;
4321 key_name[1] = (key & 0xff);
4322 }
4323 }
4324
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004325 /* Skip all options that are not window-local (used when showing
4326 * an already loaded buffer in a window). */
4327 if ((opt_flags & OPT_WINONLY)
4328 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4329 goto skip;
4330
Bram Moolenaara3227e22006-03-08 21:32:40 +00004331 /* Skip all options that are window-local (used for :vimgrep). */
4332 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4333 && options[opt_idx].var == VAR_WIN)
4334 goto skip;
4335
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004336 /* Disallow changing some options from modelines. */
4337 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004338 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004339 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004340 {
4341 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4342 goto skip;
4343 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004344#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004345 /* In diff mode some options are overruled. This avoids that
4346 * 'foldmethod' becomes "marker" instead of "diff" and that
4347 * "wrap" gets set. */
4348 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004349 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004350 && (options[opt_idx].indir == PV_FDM
4351 || options[opt_idx].indir == PV_WRAP))
4352 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004354 }
4355
4356#ifdef HAVE_SANDBOX
4357 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004358 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004359 {
4360 errmsg = (char_u *)_(e_sandbox);
4361 goto skip;
4362 }
4363#endif
4364
4365 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4366 {
4367 arg += len;
4368 cp_val = p_cp;
4369 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4370 {
4371 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4372 {
4373 cp_val = FALSE;
4374 arg += 3;
4375 }
4376 else /* "opt&vi": set to Vi default */
4377 {
4378 cp_val = TRUE;
4379 arg += 2;
4380 }
4381 }
4382 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4383 && arg[1] != NUL && !vim_iswhite(arg[1]))
4384 {
4385 errmsg = e_trailing;
4386 goto skip;
4387 }
4388 }
4389
4390 /*
4391 * allow '=' and ':' as MSDOS command.com allows only one
4392 * '=' character per "set" command line. grrr. (jw)
4393 */
4394 if (nextchar == '?'
4395 || (prefix == 1
4396 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4397 && !(flags & P_BOOL)))
4398 {
4399 /*
4400 * print value
4401 */
4402 if (did_show)
4403 msg_putchar('\n'); /* cursor below last one */
4404 else
4405 {
4406 gotocmdline(TRUE); /* cursor at status line */
4407 did_show = TRUE; /* remember that we did a line */
4408 }
4409 if (opt_idx >= 0)
4410 {
4411 showoneopt(&options[opt_idx], opt_flags);
4412#ifdef FEAT_EVAL
4413 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004414 {
4415 /* Mention where the option was last set. */
4416 if (varp == options[opt_idx].var)
4417 last_set_msg(options[opt_idx].scriptID);
4418 else if ((int)options[opt_idx].indir & PV_WIN)
4419 last_set_msg(curwin->w_p_scriptID[
4420 (int)options[opt_idx].indir & PV_MASK]);
4421 else if ((int)options[opt_idx].indir & PV_BUF)
4422 last_set_msg(curbuf->b_p_scriptID[
4423 (int)options[opt_idx].indir & PV_MASK]);
4424 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425#endif
4426 }
4427 else
4428 {
4429 char_u *p;
4430
4431 p = find_termcode(key_name);
4432 if (p == NULL)
4433 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004434 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004435 goto skip;
4436 }
4437 else
4438 (void)show_one_termcode(key_name, p, TRUE);
4439 }
4440 if (nextchar != '?'
4441 && nextchar != NUL && !vim_iswhite(afterchar))
4442 errmsg = e_trailing;
4443 }
4444 else
4445 {
4446 if (flags & P_BOOL) /* boolean */
4447 {
4448 if (nextchar == '=' || nextchar == ':')
4449 {
4450 errmsg = e_invarg;
4451 goto skip;
4452 }
4453
4454 /*
4455 * ":set opt!": invert
4456 * ":set opt&": reset to default value
4457 * ":set opt<": reset to global value
4458 */
4459 if (nextchar == '!')
4460 value = *(int *)(varp) ^ 1;
4461 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004462 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004463 ((flags & P_VI_DEF) || cp_val)
4464 ? VI_DEFAULT : VIM_DEFAULT];
4465 else if (nextchar == '<')
4466 {
4467 /* For 'autoread' -1 means to use global value. */
4468 if ((int *)varp == &curbuf->b_p_ar
4469 && opt_flags == OPT_LOCAL)
4470 value = -1;
4471 else
4472 value = *(int *)get_varp_scope(&(options[opt_idx]),
4473 OPT_GLOBAL);
4474 }
4475 else
4476 {
4477 /*
4478 * ":set invopt": invert
4479 * ":set opt" or ":set noopt": set or reset
4480 */
4481 if (nextchar != NUL && !vim_iswhite(afterchar))
4482 {
4483 errmsg = e_trailing;
4484 goto skip;
4485 }
4486 if (prefix == 2) /* inv */
4487 value = *(int *)(varp) ^ 1;
4488 else
4489 value = prefix;
4490 }
4491
4492 errmsg = set_bool_option(opt_idx, varp, (int)value,
4493 opt_flags);
4494 }
4495 else /* numeric or string */
4496 {
4497 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4498 || prefix != 1)
4499 {
4500 errmsg = e_invarg;
4501 goto skip;
4502 }
4503
4504 if (flags & P_NUM) /* numeric */
4505 {
4506 /*
4507 * Different ways to set a number option:
4508 * & set to default value
4509 * < set to global value
4510 * <xx> accept special key codes for 'wildchar'
4511 * c accept any non-digit for 'wildchar'
4512 * [-]0-9 set number
4513 * other error
4514 */
4515 ++arg;
4516 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004517 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004518 ((flags & P_VI_DEF) || cp_val)
4519 ? VI_DEFAULT : VIM_DEFAULT];
4520 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004521 {
4522 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4523 * use the global value. */
4524 if ((long *)varp == &curbuf->b_p_ul
4525 && opt_flags == OPT_LOCAL)
4526 value = NO_LOCAL_UNDOLEVEL;
4527 else
4528 value = *(long *)get_varp_scope(
4529 &(options[opt_idx]), OPT_GLOBAL);
4530 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004531 else if (((long *)varp == &p_wc
4532 || (long *)varp == &p_wcm)
4533 && (*arg == '<'
4534 || *arg == '^'
4535 || ((!arg[1] || vim_iswhite(arg[1]))
4536 && !VIM_ISDIGIT(*arg))))
4537 {
4538 value = string_to_key(arg);
4539 if (value == 0 && (long *)varp != &p_wcm)
4540 {
4541 errmsg = e_invarg;
4542 goto skip;
4543 }
4544 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004545 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4546 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004547 /* Allow negative (for 'undolevels'), octal and
4548 * hex numbers. */
4549 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004550 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4551 {
4552 errmsg = e_invarg;
4553 goto skip;
4554 }
4555 }
4556 else
4557 {
4558 errmsg = (char_u *)N_("E521: Number required after =");
4559 goto skip;
4560 }
4561
4562 if (adding)
4563 value = *(long *)varp + value;
4564 if (prepending)
4565 value = *(long *)varp * value;
4566 if (removing)
4567 value = *(long *)varp - value;
4568 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004569 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004570 }
4571 else if (opt_idx >= 0) /* string */
4572 {
4573 char_u *save_arg = NULL;
4574 char_u *s = NULL;
4575 char_u *oldval; /* previous value if *varp */
4576 char_u *newval;
4577 char_u *origval;
4578 unsigned newlen;
4579 int comma;
4580 int bs;
4581 int new_value_alloced; /* new string option
4582 was allocated */
4583
4584 /* When using ":set opt=val" for a global option
4585 * with a local value the local value will be
4586 * reset, use the global value here. */
4587 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004588 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004589 varp = options[opt_idx].var;
4590
4591 /* The old value is kept until we are sure that the
4592 * new value is valid. */
4593 oldval = *(char_u **)varp;
4594 if (nextchar == '&') /* set to default val */
4595 {
4596 newval = options[opt_idx].def_val[
4597 ((flags & P_VI_DEF) || cp_val)
4598 ? VI_DEFAULT : VIM_DEFAULT];
4599 if ((char_u **)varp == &p_bg)
4600 {
4601 /* guess the value of 'background' */
4602#ifdef FEAT_GUI
4603 if (gui.in_use)
4604 newval = gui_bg_default();
4605 else
4606#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004607 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004608 }
4609
4610 /* expand environment variables and ~ (since the
4611 * default value was already expanded, only
4612 * required when an environment variable was set
4613 * later */
4614 if (newval == NULL)
4615 newval = empty_option;
4616 else
4617 {
4618 s = option_expand(opt_idx, newval);
4619 if (s == NULL)
4620 s = newval;
4621 newval = vim_strsave(s);
4622 }
4623 new_value_alloced = TRUE;
4624 }
4625 else if (nextchar == '<') /* set to global val */
4626 {
4627 newval = vim_strsave(*(char_u **)get_varp_scope(
4628 &(options[opt_idx]), OPT_GLOBAL));
4629 new_value_alloced = TRUE;
4630 }
4631 else
4632 {
4633 ++arg; /* jump to after the '=' or ':' */
4634
4635 /*
4636 * Set 'keywordprg' to ":help" if an empty
4637 * value was passed to :set by the user.
4638 * Misuse errbuf[] for the resulting string.
4639 */
4640 if (varp == (char_u *)&p_kp
4641 && (*arg == NUL || *arg == ' '))
4642 {
4643 STRCPY(errbuf, ":help");
4644 save_arg = arg;
4645 arg = errbuf;
4646 }
4647 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004648 * Convert 'backspace' number to string, for
4649 * adding, prepending and removing string.
4650 */
4651 else if (varp == (char_u *)&p_bs
4652 && VIM_ISDIGIT(**(char_u **)varp))
4653 {
4654 i = getdigits((char_u **)varp);
4655 switch (i)
4656 {
4657 case 0:
4658 *(char_u **)varp = empty_option;
4659 break;
4660 case 1:
4661 *(char_u **)varp = vim_strsave(
4662 (char_u *)"indent,eol");
4663 break;
4664 case 2:
4665 *(char_u **)varp = vim_strsave(
4666 (char_u *)"indent,eol,start");
4667 break;
4668 }
4669 vim_free(oldval);
4670 oldval = *(char_u **)varp;
4671 }
4672 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004673 * Convert 'whichwrap' number to string, for
4674 * backwards compatibility with Vim 3.0.
4675 * Misuse errbuf[] for the resulting string.
4676 */
4677 else if (varp == (char_u *)&p_ww
4678 && VIM_ISDIGIT(*arg))
4679 {
4680 *errbuf = NUL;
4681 i = getdigits(&arg);
4682 if (i & 1)
4683 STRCAT(errbuf, "b,");
4684 if (i & 2)
4685 STRCAT(errbuf, "s,");
4686 if (i & 4)
4687 STRCAT(errbuf, "h,l,");
4688 if (i & 8)
4689 STRCAT(errbuf, "<,>,");
4690 if (i & 16)
4691 STRCAT(errbuf, "[,],");
4692 if (*errbuf != NUL) /* remove trailing , */
4693 errbuf[STRLEN(errbuf) - 1] = NUL;
4694 save_arg = arg;
4695 arg = errbuf;
4696 }
4697 /*
4698 * Remove '>' before 'dir' and 'bdir', for
4699 * backwards compatibility with version 3.0
4700 */
4701 else if ( *arg == '>'
4702 && (varp == (char_u *)&p_dir
4703 || varp == (char_u *)&p_bdir))
4704 {
4705 ++arg;
4706 }
4707
4708 /* When setting the local value of a global
4709 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004710 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004711 && (opt_flags & OPT_LOCAL))
4712 origval = *(char_u **)get_varp(
4713 &options[opt_idx]);
4714 else
4715 origval = oldval;
4716
4717 /*
4718 * Copy the new string into allocated memory.
4719 * Can't use set_string_option_direct(), because
4720 * we need to remove the backslashes.
4721 */
4722 /* get a bit too much */
4723 newlen = (unsigned)STRLEN(arg) + 1;
4724 if (adding || prepending || removing)
4725 newlen += (unsigned)STRLEN(origval) + 1;
4726 newval = alloc(newlen);
4727 if (newval == NULL) /* out of mem, don't change */
4728 break;
4729 s = newval;
4730
4731 /*
4732 * Copy the string, skip over escaped chars.
4733 * For MS-DOS and WIN32 backslashes before normal
4734 * file name characters are not removed, and keep
4735 * backslash at start, for "\\machine\path", but
4736 * do remove it for "\\\\machine\\path".
4737 * The reverse is found in ExpandOldSetting().
4738 */
4739 while (*arg && !vim_iswhite(*arg))
4740 {
4741 if (*arg == '\\' && arg[1] != NUL
4742#ifdef BACKSLASH_IN_FILENAME
4743 && !((flags & P_EXPAND)
4744 && vim_isfilec(arg[1])
4745 && (arg[1] != '\\'
4746 || (s == newval
4747 && arg[2] != '\\')))
4748#endif
4749 )
4750 ++arg; /* remove backslash */
4751#ifdef FEAT_MBYTE
4752 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004753 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004754 {
4755 /* copy multibyte char */
4756 mch_memmove(s, arg, (size_t)i);
4757 arg += i;
4758 s += i;
4759 }
4760 else
4761#endif
4762 *s++ = *arg++;
4763 }
4764 *s = NUL;
4765
4766 /*
4767 * Expand environment variables and ~.
4768 * Don't do it when adding without inserting a
4769 * comma.
4770 */
4771 if (!(adding || prepending || removing)
4772 || (flags & P_COMMA))
4773 {
4774 s = option_expand(opt_idx, newval);
4775 if (s != NULL)
4776 {
4777 vim_free(newval);
4778 newlen = (unsigned)STRLEN(s) + 1;
4779 if (adding || prepending || removing)
4780 newlen += (unsigned)STRLEN(origval) + 1;
4781 newval = alloc(newlen);
4782 if (newval == NULL)
4783 break;
4784 STRCPY(newval, s);
4785 }
4786 }
4787
4788 /* locate newval[] in origval[] when removing it
4789 * and when adding to avoid duplicates */
4790 i = 0; /* init for GCC */
4791 if (removing || (flags & P_NODUP))
4792 {
4793 i = (int)STRLEN(newval);
4794 bs = 0;
4795 for (s = origval; *s; ++s)
4796 {
4797 if ((!(flags & P_COMMA)
4798 || s == origval
4799 || (s[-1] == ',' && !(bs & 1)))
4800 && STRNCMP(s, newval, i) == 0
4801 && (!(flags & P_COMMA)
4802 || s[i] == ','
4803 || s[i] == NUL))
4804 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004805 /* Count backslashes. Only a comma with an
4806 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004807 * recognized as a separator */
4808 if (s > origval && s[-1] == '\\')
4809 ++bs;
4810 else
4811 bs = 0;
4812 }
4813
4814 /* do not add if already there */
4815 if ((adding || prepending) && *s)
4816 {
4817 prepending = FALSE;
4818 adding = FALSE;
4819 STRCPY(newval, origval);
4820 }
4821 }
4822
4823 /* concatenate the two strings; add a ',' if
4824 * needed */
4825 if (adding || prepending)
4826 {
4827 comma = ((flags & P_COMMA) && *origval != NUL
4828 && *newval != NUL);
4829 if (adding)
4830 {
4831 i = (int)STRLEN(origval);
4832 mch_memmove(newval + i + comma, newval,
4833 STRLEN(newval) + 1);
4834 mch_memmove(newval, origval, (size_t)i);
4835 }
4836 else
4837 {
4838 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004839 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004840 }
4841 if (comma)
4842 newval[i] = ',';
4843 }
4844
4845 /* Remove newval[] from origval[]. (Note: "i" has
4846 * been set above and is used here). */
4847 if (removing)
4848 {
4849 STRCPY(newval, origval);
4850 if (*s)
4851 {
4852 /* may need to remove a comma */
4853 if (flags & P_COMMA)
4854 {
4855 if (s == origval)
4856 {
4857 /* include comma after string */
4858 if (s[i] == ',')
4859 ++i;
4860 }
4861 else
4862 {
4863 /* include comma before string */
4864 --s;
4865 ++i;
4866 }
4867 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004868 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004869 }
4870 }
4871
4872 if (flags & P_FLAGLIST)
4873 {
4874 /* Remove flags that appear twice. */
4875 for (s = newval; *s; ++s)
4876 if ((!(flags & P_COMMA) || *s != ',')
4877 && vim_strchr(s + 1, *s) != NULL)
4878 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004879 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004880 --s;
4881 }
4882 }
4883
4884 if (save_arg != NULL) /* number for 'whichwrap' */
4885 arg = save_arg;
4886 new_value_alloced = TRUE;
4887 }
4888
4889 /* Set the new value. */
4890 *(char_u **)(varp) = newval;
4891
4892 /* Handle side effects, and set the global value for
4893 * ":set" on local options. */
4894 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4895 new_value_alloced, oldval, errbuf, opt_flags);
4896
4897 /* If error detected, print the error message. */
4898 if (errmsg != NULL)
4899 goto skip;
4900 }
4901 else /* key code option */
4902 {
4903 char_u *p;
4904
4905 if (nextchar == '&')
4906 {
4907 if (add_termcap_entry(key_name, TRUE) == FAIL)
4908 errmsg = (char_u *)N_("E522: Not found in termcap");
4909 }
4910 else
4911 {
4912 ++arg; /* jump to after the '=' or ':' */
4913 for (p = arg; *p && !vim_iswhite(*p); ++p)
4914 if (*p == '\\' && p[1] != NUL)
4915 ++p;
4916 nextchar = *p;
4917 *p = NUL;
4918 add_termcode(key_name, arg, FALSE);
4919 *p = nextchar;
4920 }
4921 if (full_screen)
4922 ttest(FALSE);
4923 redraw_all_later(CLEAR);
4924 }
4925 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004926
Bram Moolenaar071d4272004-06-13 20:20:40 +00004927 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004928 did_set_option(opt_idx, opt_flags,
4929 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004930 }
4931
4932skip:
4933 /*
4934 * Advance to next argument.
4935 * - skip until a blank found, taking care of backslashes
4936 * - skip blanks
4937 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4938 */
4939 for (i = 0; i < 2 ; ++i)
4940 {
4941 while (*arg != NUL && !vim_iswhite(*arg))
4942 if (*arg++ == '\\' && *arg != NUL)
4943 ++arg;
4944 arg = skipwhite(arg);
4945 if (*arg != '=')
4946 break;
4947 }
4948 }
4949
4950 if (errmsg != NULL)
4951 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004952 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004953 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004954 if (i + (arg - startarg) < IOSIZE)
4955 {
4956 /* append the argument with the error */
4957 STRCAT(IObuff, ": ");
4958 mch_memmove(IObuff + i, startarg, (arg - startarg));
4959 IObuff[i + (arg - startarg)] = NUL;
4960 }
4961 /* make sure all characters are printable */
4962 trans_characters(IObuff, IOSIZE);
4963
4964 ++no_wait_return; /* wait_return done later */
4965 emsg(IObuff); /* show error highlighted */
4966 --no_wait_return;
4967
4968 return FAIL;
4969 }
4970
4971 arg = skipwhite(arg);
4972 }
4973
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004974theend:
4975 if (silent_mode && did_show)
4976 {
4977 /* After displaying option values in silent mode. */
4978 silent_mode = FALSE;
4979 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4980 msg_putchar('\n');
4981 cursor_on(); /* msg_start() switches it off */
4982 out_flush();
4983 silent_mode = TRUE;
4984 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4985 }
4986
Bram Moolenaar071d4272004-06-13 20:20:40 +00004987 return OK;
4988}
4989
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004990/*
4991 * Call this when an option has been given a new value through a user command.
4992 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4993 */
4994 static void
4995did_set_option(opt_idx, opt_flags, new_value)
4996 int opt_idx;
4997 int opt_flags; /* possibly with OPT_MODELINE */
4998 int new_value; /* value was replaced completely */
4999{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005000 long_u *p;
5001
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005002 options[opt_idx].flags |= P_WAS_SET;
5003
5004 /* When an option is set in the sandbox, from a modeline or in secure mode
5005 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005006 * flag. */
5007 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005008 if (secure
5009#ifdef HAVE_SANDBOX
5010 || sandbox != 0
5011#endif
5012 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005013 *p = *p | P_INSECURE;
5014 else if (new_value)
5015 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005016}
5017
Bram Moolenaar071d4272004-06-13 20:20:40 +00005018 static char_u *
5019illegal_char(errbuf, c)
5020 char_u *errbuf;
5021 int c;
5022{
5023 if (errbuf == NULL)
5024 return (char_u *)"";
5025 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005026 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005027 return errbuf;
5028}
5029
5030/*
5031 * Convert a key name or string into a key value.
5032 * Used for 'wildchar' and 'cedit' options.
5033 */
5034 static int
5035string_to_key(arg)
5036 char_u *arg;
5037{
5038 if (*arg == '<')
5039 return find_key_option(arg + 1);
5040 if (*arg == '^')
5041 return Ctrl_chr(arg[1]);
5042 return *arg;
5043}
5044
5045#ifdef FEAT_CMDWIN
5046/*
5047 * Check value of 'cedit' and set cedit_key.
5048 * Returns NULL if value is OK, error message otherwise.
5049 */
5050 static char_u *
5051check_cedit()
5052{
5053 int n;
5054
5055 if (*p_cedit == NUL)
5056 cedit_key = -1;
5057 else
5058 {
5059 n = string_to_key(p_cedit);
5060 if (vim_isprintc(n))
5061 return e_invarg;
5062 cedit_key = n;
5063 }
5064 return NULL;
5065}
5066#endif
5067
5068#ifdef FEAT_TITLE
5069/*
5070 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5071 * maketitle() to create and display it.
5072 * When switching the title or icon off, call mch_restore_title() to get
5073 * the old value back.
5074 */
5075 static void
5076did_set_title(icon)
5077 int icon; /* Did set icon instead of title */
5078{
5079 if (starting != NO_SCREEN
5080#ifdef FEAT_GUI
5081 && !gui.starting
5082#endif
5083 )
5084 {
5085 maketitle();
5086 if (icon)
5087 {
5088 if (!p_icon)
5089 mch_restore_title(2);
5090 }
5091 else
5092 {
5093 if (!p_title)
5094 mch_restore_title(1);
5095 }
5096 }
5097}
5098#endif
5099
5100/*
5101 * set_options_bin - called when 'bin' changes value.
5102 */
5103 void
5104set_options_bin(oldval, newval, opt_flags)
5105 int oldval;
5106 int newval;
5107 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5108{
5109 /*
5110 * The option values that are changed when 'bin' changes are
5111 * copied when 'bin is set and restored when 'bin' is reset.
5112 */
5113 if (newval)
5114 {
5115 if (!oldval) /* switched on */
5116 {
5117 if (!(opt_flags & OPT_GLOBAL))
5118 {
5119 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5120 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5121 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5122 curbuf->b_p_et_nobin = curbuf->b_p_et;
5123 }
5124 if (!(opt_flags & OPT_LOCAL))
5125 {
5126 p_tw_nobin = p_tw;
5127 p_wm_nobin = p_wm;
5128 p_ml_nobin = p_ml;
5129 p_et_nobin = p_et;
5130 }
5131 }
5132
5133 if (!(opt_flags & OPT_GLOBAL))
5134 {
5135 curbuf->b_p_tw = 0; /* no automatic line wrap */
5136 curbuf->b_p_wm = 0; /* no automatic line wrap */
5137 curbuf->b_p_ml = 0; /* no modelines */
5138 curbuf->b_p_et = 0; /* no expandtab */
5139 }
5140 if (!(opt_flags & OPT_LOCAL))
5141 {
5142 p_tw = 0;
5143 p_wm = 0;
5144 p_ml = FALSE;
5145 p_et = FALSE;
5146 p_bin = TRUE; /* needed when called for the "-b" argument */
5147 }
5148 }
5149 else if (oldval) /* switched off */
5150 {
5151 if (!(opt_flags & OPT_GLOBAL))
5152 {
5153 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5154 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5155 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5156 curbuf->b_p_et = curbuf->b_p_et_nobin;
5157 }
5158 if (!(opt_flags & OPT_LOCAL))
5159 {
5160 p_tw = p_tw_nobin;
5161 p_wm = p_wm_nobin;
5162 p_ml = p_ml_nobin;
5163 p_et = p_et_nobin;
5164 }
5165 }
5166}
5167
5168#ifdef FEAT_VIMINFO
5169/*
5170 * Find the parameter represented by the given character (eg ', :, ", or /),
5171 * and return its associated value in the 'viminfo' string.
5172 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005173 * If the parameter is not specified in the string or there is no following
5174 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005175 */
5176 int
5177get_viminfo_parameter(type)
5178 int type;
5179{
5180 char_u *p;
5181
5182 p = find_viminfo_parameter(type);
5183 if (p != NULL && VIM_ISDIGIT(*p))
5184 return atoi((char *)p);
5185 return -1;
5186}
5187
5188/*
5189 * Find the parameter represented by the given character (eg ''', ':', '"', or
5190 * '/') in the 'viminfo' option and return a pointer to the string after it.
5191 * Return NULL if the parameter is not specified in the string.
5192 */
5193 char_u *
5194find_viminfo_parameter(type)
5195 int type;
5196{
5197 char_u *p;
5198
5199 for (p = p_viminfo; *p; ++p)
5200 {
5201 if (*p == type)
5202 return p + 1;
5203 if (*p == 'n') /* 'n' is always the last one */
5204 break;
5205 p = vim_strchr(p, ','); /* skip until next ',' */
5206 if (p == NULL) /* hit the end without finding parameter */
5207 break;
5208 }
5209 return NULL;
5210}
5211#endif
5212
5213/*
5214 * Expand environment variables for some string options.
5215 * These string options cannot be indirect!
5216 * If "val" is NULL expand the current value of the option.
5217 * Return pointer to NameBuff, or NULL when not expanded.
5218 */
5219 static char_u *
5220option_expand(opt_idx, val)
5221 int opt_idx;
5222 char_u *val;
5223{
5224 /* if option doesn't need expansion nothing to do */
5225 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5226 return NULL;
5227
5228 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5229 * expand_env() would truncate the string. */
5230 if (val != NULL && STRLEN(val) > MAXPATHL)
5231 return NULL;
5232
5233 if (val == NULL)
5234 val = *(char_u **)options[opt_idx].var;
5235
5236 /*
5237 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5238 * Escape spaces when expanding 'tags', they are used to separate file
5239 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005240 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005241 */
5242 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005243 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005244#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005245 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5246#endif
5247 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005248 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5249 return NULL;
5250
5251 return NameBuff;
5252}
5253
5254/*
5255 * After setting various option values: recompute variables that depend on
5256 * option values.
5257 */
5258 static void
5259didset_options()
5260{
5261 /* initialize the table for 'iskeyword' et.al. */
5262 (void)init_chartab();
5263
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005264#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005265 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005266#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005267 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5268#ifdef FEAT_SESSION
5269 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5270 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5271#endif
5272#ifdef FEAT_FOLDING
5273 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5274#endif
5275 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5276#ifdef FEAT_VIRTUALEDIT
5277 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5278#endif
5279#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5280 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5281#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005282#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005283 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005284 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005285 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005286#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005287#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5288 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5289#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005290#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005291 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5292#endif
5293#ifdef FEAT_CMDWIN
5294 /* set cedit_key */
5295 (void)check_cedit();
5296#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005297#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005298 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005299#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005300}
5301
5302/*
5303 * Check for string options that are NULL (normally only termcap options).
5304 */
5305 void
5306check_options()
5307{
5308 int opt_idx;
5309
5310 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5311 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5312 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5313}
5314
5315/*
5316 * Check string options in a buffer for NULL value.
5317 */
5318 void
5319check_buf_options(buf)
5320 buf_T *buf;
5321{
5322#if defined(FEAT_QUICKFIX)
5323 check_string_option(&buf->b_p_bh);
5324 check_string_option(&buf->b_p_bt);
5325#endif
5326#ifdef FEAT_MBYTE
5327 check_string_option(&buf->b_p_fenc);
5328#endif
5329 check_string_option(&buf->b_p_ff);
5330#ifdef FEAT_FIND_ID
5331 check_string_option(&buf->b_p_def);
5332 check_string_option(&buf->b_p_inc);
5333# ifdef FEAT_EVAL
5334 check_string_option(&buf->b_p_inex);
5335# endif
5336#endif
5337#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5338 check_string_option(&buf->b_p_inde);
5339 check_string_option(&buf->b_p_indk);
5340#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005341#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5342 check_string_option(&buf->b_p_bexpr);
5343#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005344#if defined(FEAT_CRYPT)
5345 check_string_option(&buf->b_p_cm);
5346#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005347#if defined(FEAT_EVAL)
5348 check_string_option(&buf->b_p_fex);
5349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005350#ifdef FEAT_CRYPT
5351 check_string_option(&buf->b_p_key);
5352#endif
5353 check_string_option(&buf->b_p_kp);
5354 check_string_option(&buf->b_p_mps);
5355 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005356 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357 check_string_option(&buf->b_p_isk);
5358#ifdef FEAT_COMMENTS
5359 check_string_option(&buf->b_p_com);
5360#endif
5361#ifdef FEAT_FOLDING
5362 check_string_option(&buf->b_p_cms);
5363#endif
5364 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005365#ifdef FEAT_TEXTOBJ
5366 check_string_option(&buf->b_p_qe);
5367#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005368#ifdef FEAT_SYN_HL
5369 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005370#endif
5371#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005372 check_string_option(&buf->b_s.b_p_spc);
5373 check_string_option(&buf->b_s.b_p_spf);
5374 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375#endif
5376#ifdef FEAT_SEARCHPATH
5377 check_string_option(&buf->b_p_sua);
5378#endif
5379#ifdef FEAT_CINDENT
5380 check_string_option(&buf->b_p_cink);
5381 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005382 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005383#endif
5384#ifdef FEAT_AUTOCMD
5385 check_string_option(&buf->b_p_ft);
5386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5388 check_string_option(&buf->b_p_cinw);
5389#endif
5390#ifdef FEAT_INS_EXPAND
5391 check_string_option(&buf->b_p_cpt);
5392#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005393#ifdef FEAT_COMPL_FUNC
5394 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005395 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005397#ifdef FEAT_KEYMAP
5398 check_string_option(&buf->b_p_keymap);
5399#endif
5400#ifdef FEAT_QUICKFIX
5401 check_string_option(&buf->b_p_gp);
5402 check_string_option(&buf->b_p_mp);
5403 check_string_option(&buf->b_p_efm);
5404#endif
5405 check_string_option(&buf->b_p_ep);
5406 check_string_option(&buf->b_p_path);
5407 check_string_option(&buf->b_p_tags);
5408#ifdef FEAT_INS_EXPAND
5409 check_string_option(&buf->b_p_dict);
5410 check_string_option(&buf->b_p_tsr);
5411#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005412#ifdef FEAT_LISP
5413 check_string_option(&buf->b_p_lw);
5414#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005415 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005416}
5417
5418/*
5419 * Free the string allocated for an option.
5420 * Checks for the string being empty_option. This may happen if we're out of
5421 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5422 * check_options().
5423 * Does NOT check for P_ALLOCED flag!
5424 */
5425 void
5426free_string_option(p)
5427 char_u *p;
5428{
5429 if (p != empty_option)
5430 vim_free(p);
5431}
5432
5433 void
5434clear_string_option(pp)
5435 char_u **pp;
5436{
5437 if (*pp != empty_option)
5438 vim_free(*pp);
5439 *pp = empty_option;
5440}
5441
5442 static void
5443check_string_option(pp)
5444 char_u **pp;
5445{
5446 if (*pp == NULL)
5447 *pp = empty_option;
5448}
5449
5450/*
5451 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5452 */
5453 void
5454set_term_option_alloced(p)
5455 char_u **p;
5456{
5457 int opt_idx;
5458
5459 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5460 if (options[opt_idx].var == (char_u *)p)
5461 {
5462 options[opt_idx].flags |= P_ALLOCED;
5463 return;
5464 }
5465 return; /* cannot happen: didn't find it! */
5466}
5467
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005468#if defined(FEAT_EVAL) || defined(PROTO)
5469/*
5470 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5471 * Return FALSE when it wasn't.
5472 * Return -1 for an unknown option.
5473 */
5474 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005475was_set_insecurely(opt, opt_flags)
5476 char_u *opt;
5477 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005478{
5479 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005480 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005481
5482 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005483 {
5484 flagp = insecure_flag(idx, opt_flags);
5485 return (*flagp & P_INSECURE) != 0;
5486 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005487 EMSG2(_(e_intern2), "was_set_insecurely()");
5488 return -1;
5489}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005490
5491/*
5492 * Get a pointer to the flags used for the P_INSECURE flag of option
5493 * "opt_idx". For some local options a local flags field is used.
5494 */
5495 static long_u *
5496insecure_flag(opt_idx, opt_flags)
5497 int opt_idx;
5498 int opt_flags;
5499{
5500 if (opt_flags & OPT_LOCAL)
5501 switch ((int)options[opt_idx].indir)
5502 {
5503#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005504 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005505#endif
5506#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005507# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005508 case PV_FDE: return &curwin->w_p_fde_flags;
5509 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005510# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005511# ifdef FEAT_BEVAL
5512 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5513# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005514# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005515 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005516# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005517 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005518# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005519 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005520# endif
5521#endif
5522 }
5523
5524 /* Nothing special, return global flags field. */
5525 return &options[opt_idx].flags;
5526}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005527#endif
5528
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005529#ifdef FEAT_TITLE
5530static void redraw_titles __ARGS((void));
5531
5532/*
5533 * Redraw the window title and/or tab page text later.
5534 */
5535static void redraw_titles()
5536{
5537 need_maketitle = TRUE;
5538# ifdef FEAT_WINDOWS
5539 redraw_tabline = TRUE;
5540# endif
5541}
5542#endif
5543
Bram Moolenaar071d4272004-06-13 20:20:40 +00005544/*
5545 * Set a string option to a new value (without checking the effect).
5546 * The string is copied into allocated memory.
5547 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005548 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005549 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550 */
5551 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005552set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005553 char_u *name;
5554 int opt_idx;
5555 char_u *val;
5556 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005557 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558{
5559 char_u *s;
5560 char_u **varp;
5561 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005562 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005563
Bram Moolenaar89d40322006-08-29 15:30:07 +00005564 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005565 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005566 idx = findoption(name);
5567 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005568 {
5569 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005570 EMSG2(_("For option %s"), name);
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
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005745 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5746 /* make the local value empty: use the global value */
5747 *flags = 0;
5748 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005749 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005750 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5751 errmsg = e_invarg;
5752 if ((((int)*flags & BKC_AUTO) != 0)
5753 + (((int)*flags & BKC_YES) != 0)
5754 + (((int)*flags & BKC_NO) != 0) != 1)
5755 {
5756 /* Must have exactly one of "auto", "yes" and "no". */
5757 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5758 errmsg = e_invarg;
5759 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005760 }
5761 }
5762
5763 /* 'backupext' and 'patchmode' */
5764 else if (varp == &p_bex || varp == &p_pm)
5765 {
5766 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5767 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5768 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5769 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005770#ifdef FEAT_LINEBREAK
5771 /* 'breakindentopt' */
5772 else if (varp == &curwin->w_p_briopt)
5773 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005774 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005775 errmsg = e_invarg;
5776 }
5777#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005778
5779 /*
5780 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5781 * If the new option is invalid, use old value. 'lisp' option: refill
5782 * chartab[] for '-' char
5783 */
5784 else if ( varp == &p_isi
5785 || varp == &(curbuf->b_p_isk)
5786 || varp == &p_isp
5787 || varp == &p_isf)
5788 {
5789 if (init_chartab() == FAIL)
5790 {
5791 did_chartab = TRUE; /* need to restore it below */
5792 errmsg = e_invarg; /* error in value */
5793 }
5794 }
5795
5796 /* 'helpfile' */
5797 else if (varp == &p_hf)
5798 {
5799 /* May compute new values for $VIM and $VIMRUNTIME */
5800 if (didset_vim)
5801 {
5802 vim_setenv((char_u *)"VIM", (char_u *)"");
5803 didset_vim = FALSE;
5804 }
5805 if (didset_vimruntime)
5806 {
5807 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5808 didset_vimruntime = FALSE;
5809 }
5810 }
5811
Bram Moolenaar1a384422010-07-14 19:53:30 +02005812#ifdef FEAT_SYN_HL
5813 /* 'colorcolumn' */
5814 else if (varp == &curwin->w_p_cc)
5815 errmsg = check_colorcolumn(curwin);
5816#endif
5817
Bram Moolenaar071d4272004-06-13 20:20:40 +00005818#ifdef FEAT_MULTI_LANG
5819 /* 'helplang' */
5820 else if (varp == &p_hlg)
5821 {
5822 /* Check for "", "ab", "ab,cd", etc. */
5823 for (s = p_hlg; *s != NUL; s += 3)
5824 {
5825 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5826 {
5827 errmsg = e_invarg;
5828 break;
5829 }
5830 if (s[2] == NUL)
5831 break;
5832 }
5833 }
5834#endif
5835
5836 /* 'highlight' */
5837 else if (varp == &p_hl)
5838 {
5839 if (highlight_changed() == FAIL)
5840 errmsg = e_invarg; /* invalid flags */
5841 }
5842
5843 /* 'nrformats' */
5844 else if (gvarp == &p_nf)
5845 {
5846 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5847 errmsg = e_invarg;
5848 }
5849
5850#ifdef FEAT_SESSION
5851 /* 'sessionoptions' */
5852 else if (varp == &p_ssop)
5853 {
5854 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5855 errmsg = e_invarg;
5856 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5857 {
5858 /* Don't allow both "sesdir" and "curdir". */
5859 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5860 errmsg = e_invarg;
5861 }
5862 }
5863 /* 'viewoptions' */
5864 else if (varp == &p_vop)
5865 {
5866 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5867 errmsg = e_invarg;
5868 }
5869#endif
5870
5871 /* 'scrollopt' */
5872#ifdef FEAT_SCROLLBIND
5873 else if (varp == &p_sbo)
5874 {
5875 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5876 errmsg = e_invarg;
5877 }
5878#endif
5879
5880 /* 'ambiwidth' */
5881#ifdef FEAT_MBYTE
5882 else if (varp == &p_ambw)
5883 {
5884 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5885 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005886 else if (set_chars_option(&p_lcs) != NULL)
5887 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5888# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5889 else if (set_chars_option(&p_fcs) != NULL)
5890 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5891# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892 }
5893#endif
5894
5895 /* 'background' */
5896 else if (varp == &p_bg)
5897 {
5898 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5899 {
5900#ifdef FEAT_EVAL
5901 int dark = (*p_bg == 'd');
5902#endif
5903
5904 init_highlight(FALSE, FALSE);
5905
5906#ifdef FEAT_EVAL
5907 if (dark != (*p_bg == 'd')
5908 && get_var_value((char_u *)"g:colors_name") != NULL)
5909 {
5910 /* The color scheme must have set 'background' back to another
5911 * value, that's not what we want here. Disable the color
5912 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005913 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005914 free_string_option(p_bg);
5915 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5916 check_string_option(&p_bg);
5917 init_highlight(FALSE, FALSE);
5918 }
5919#endif
5920 }
5921 else
5922 errmsg = e_invarg;
5923 }
5924
5925 /* 'wildmode' */
5926 else if (varp == &p_wim)
5927 {
5928 if (check_opt_wim() == FAIL)
5929 errmsg = e_invarg;
5930 }
5931
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005932#ifdef FEAT_CMDL_COMPL
5933 /* 'wildoptions' */
5934 else if (varp == &p_wop)
5935 {
5936 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5937 errmsg = e_invarg;
5938 }
5939#endif
5940
Bram Moolenaar071d4272004-06-13 20:20:40 +00005941#ifdef FEAT_WAK
5942 /* 'winaltkeys' */
5943 else if (varp == &p_wak)
5944 {
5945 if (*p_wak == NUL
5946 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5947 errmsg = e_invarg;
5948# ifdef FEAT_MENU
5949# ifdef FEAT_GUI_MOTIF
5950 else if (gui.in_use)
5951 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5952# else
5953# ifdef FEAT_GUI_GTK
5954 else if (gui.in_use)
5955 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5956# endif
5957# endif
5958# endif
5959 }
5960#endif
5961
5962#ifdef FEAT_AUTOCMD
5963 /* 'eventignore' */
5964 else if (varp == &p_ei)
5965 {
5966 if (check_ei() == FAIL)
5967 errmsg = e_invarg;
5968 }
5969#endif
5970
5971#ifdef FEAT_MBYTE
5972 /* 'encoding' and 'fileencoding' */
5973 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5974 {
5975 if (gvarp == &p_fenc)
5976 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005977 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005978 errmsg = e_modifiable;
5979 else if (vim_strchr(*varp, ',') != NULL)
5980 /* No comma allowed in 'fileencoding'; catches confusing it
5981 * with 'fileencodings'. */
5982 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005983 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005984 {
5985# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005986 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005987 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005988# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005989 /* Add 'fileencoding' to the swap file. */
5990 ml_setflags(curbuf);
5991 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005992 }
5993 if (errmsg == NULL)
5994 {
5995 /* canonize the value, so that STRCMP() can be used on it */
5996 p = enc_canonize(*varp);
5997 if (p != NULL)
5998 {
5999 vim_free(*varp);
6000 *varp = p;
6001 }
6002 if (varp == &p_enc)
6003 {
6004 errmsg = mb_init();
6005# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006006 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006007# endif
6008 }
6009 }
6010
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006011# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006012 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6013 {
6014 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6015 if (STRCMP(p_tenc, "utf-8") != 0)
6016 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6017 }
6018# endif
6019
6020 if (errmsg == NULL)
6021 {
6022# ifdef FEAT_KEYMAP
6023 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6024 * (with another encoding). */
6025 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6026 (void)keymap_init();
6027# endif
6028
6029 /* When 'termencoding' is not empty and 'encoding' changes or when
6030 * 'termencoding' changes, need to setup for keyboard input and
6031 * display output conversion. */
6032 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6033 {
6034 convert_setup(&input_conv, p_tenc, p_enc);
6035 convert_setup(&output_conv, p_enc, p_tenc);
6036 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006037
6038# if defined(WIN3264) && defined(FEAT_MBYTE)
6039 /* $HOME may have characters in active code page. */
6040 if (varp == &p_enc)
6041 init_homedir();
6042# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006043 }
6044 }
6045#endif
6046
6047#if defined(FEAT_POSTSCRIPT)
6048 else if (varp == &p_penc)
6049 {
6050 /* Canonize printencoding if VIM standard one */
6051 p = enc_canonize(p_penc);
6052 if (p != NULL)
6053 {
6054 vim_free(p_penc);
6055 p_penc = p;
6056 }
6057 else
6058 {
6059 /* Ensure lower case and '-' for '_' */
6060 for (s = p_penc; *s != NUL; s++)
6061 {
6062 if (*s == '_')
6063 *s = '-';
6064 else
6065 *s = TOLOWER_ASC(*s);
6066 }
6067 }
6068 }
6069#endif
6070
Bram Moolenaar9372a112005-12-06 19:59:18 +00006071#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006072 else if (varp == &p_imak)
6073 {
6074 if (gui.in_use && !im_xim_isvalid_imactivate())
6075 errmsg = e_invarg;
6076 }
6077#endif
6078
6079#ifdef FEAT_KEYMAP
6080 else if (varp == &curbuf->b_p_keymap)
6081 {
6082 /* load or unload key mapping tables */
6083 errmsg = keymap_init();
6084
Bram Moolenaarfab06232009-03-04 03:13:35 +00006085 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006087 if (*curbuf->b_p_keymap != NUL)
6088 {
6089 /* Installed a new keymap, switch on using it. */
6090 curbuf->b_p_iminsert = B_IMODE_LMAP;
6091 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6092 curbuf->b_p_imsearch = B_IMODE_LMAP;
6093 }
6094 else
6095 {
6096 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6097 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6098 curbuf->b_p_iminsert = B_IMODE_NONE;
6099 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6100 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6101 }
6102 if ((opt_flags & OPT_LOCAL) == 0)
6103 {
6104 set_iminsert_global();
6105 set_imsearch_global();
6106 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107# ifdef FEAT_WINDOWS
6108 status_redraw_curbuf();
6109# endif
6110 }
6111 }
6112#endif
6113
6114 /* 'fileformat' */
6115 else if (gvarp == &p_ff)
6116 {
6117 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6118 errmsg = e_modifiable;
6119 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6120 errmsg = e_invarg;
6121 else
6122 {
6123 /* may also change 'textmode' */
6124 if (get_fileformat(curbuf) == EOL_DOS)
6125 curbuf->b_p_tx = TRUE;
6126 else
6127 curbuf->b_p_tx = FALSE;
6128#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006129 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006130#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006131 /* update flag in swap file */
6132 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006133 /* Redraw needed when switching to/from "mac": a CR in the text
6134 * will be displayed differently. */
6135 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6136 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 }
6138 }
6139
6140 /* 'fileformats' */
6141 else if (varp == &p_ffs)
6142 {
6143 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6144 errmsg = e_invarg;
6145 else
6146 {
6147 /* also change 'textauto' */
6148 if (*p_ffs == NUL)
6149 p_ta = FALSE;
6150 else
6151 p_ta = TRUE;
6152 }
6153 }
6154
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006155#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006156 /* 'cryptkey' */
6157 else if (gvarp == &p_key)
6158 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006159# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006160 /* Make sure the ":set" command doesn't show the new value in the
6161 * history. */
6162 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006163# endif
6164 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6165 /* Need to update the swapfile. */
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006166 ml_set_crypt_key(curbuf, oldval, crypt_get_method_nr(curbuf));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006167 }
6168
6169 else if (gvarp == &p_cm)
6170 {
6171 if (opt_flags & OPT_LOCAL)
6172 p = curbuf->b_p_cm;
6173 else
6174 p = p_cm;
6175 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6176 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006177 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006178 errmsg = e_invarg;
6179 else
6180 {
6181 /* When setting the global value to empty, make it "zip". */
6182 if (*p_cm == NUL)
6183 {
6184 if (new_value_alloced)
6185 free_string_option(p_cm);
6186 p_cm = vim_strsave((char_u *)"zip");
6187 new_value_alloced = TRUE;
6188 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006189 /* When using ":set cm=name" the local value is going to be empty.
6190 * Do that here, otherwise the crypt functions will still use the
6191 * local value. */
6192 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6193 {
6194 free_string_option(curbuf->b_p_cm);
6195 curbuf->b_p_cm = empty_option;
6196 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006197
6198 /* Need to update the swapfile when the effective method changed.
6199 * Set "s" to the effective old value, "p" to the effective new
6200 * method and compare. */
6201 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6202 s = p_cm; /* was previously using the global value */
6203 else
6204 s = oldval;
6205 if (*curbuf->b_p_cm == NUL)
6206 p = p_cm; /* is now using the global value */
6207 else
6208 p = curbuf->b_p_cm;
6209 if (STRCMP(s, p) != 0)
6210 ml_set_crypt_key(curbuf, curbuf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006211 crypt_method_nr_from_name(s));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006212
6213 /* If the global value changes need to update the swapfile for all
6214 * buffers using that value. */
6215 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6216 {
6217 buf_T *buf;
6218
6219 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6220 if (buf != curbuf && *buf->b_p_cm == NUL)
6221 ml_set_crypt_key(buf, buf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006222 crypt_method_nr_from_name(oldval));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006223 }
6224 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006225 }
6226#endif
6227
6228 /* 'matchpairs' */
6229 else if (gvarp == &p_mps)
6230 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006231#ifdef FEAT_MBYTE
6232 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006233 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006234 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006235 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006236 int x2 = -1;
6237 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006238
6239 if (*p != NUL)
6240 p += mb_ptr2len(p);
6241 if (*p != NUL)
6242 x2 = *p++;
6243 if (*p != NUL)
6244 {
6245 x3 = mb_ptr2char(p);
6246 p += mb_ptr2len(p);
6247 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006248 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006249 {
6250 errmsg = e_invarg;
6251 break;
6252 }
6253 if (*p == NUL)
6254 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006255 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006256 }
6257 else
6258#endif
6259 {
6260 /* Check for "x:y,x:y" */
6261 for (p = *varp; *p != NUL; p += 4)
6262 {
6263 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6264 {
6265 errmsg = e_invarg;
6266 break;
6267 }
6268 if (p[3] == NUL)
6269 break;
6270 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006271 }
6272 }
6273
6274#ifdef FEAT_COMMENTS
6275 /* 'comments' */
6276 else if (gvarp == &p_com)
6277 {
6278 for (s = *varp; *s; )
6279 {
6280 while (*s && *s != ':')
6281 {
6282 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6283 && !VIM_ISDIGIT(*s) && *s != '-')
6284 {
6285 errmsg = illegal_char(errbuf, *s);
6286 break;
6287 }
6288 ++s;
6289 }
6290 if (*s++ == NUL)
6291 errmsg = (char_u *)N_("E524: Missing colon");
6292 else if (*s == ',' || *s == NUL)
6293 errmsg = (char_u *)N_("E525: Zero length string");
6294 if (errmsg != NULL)
6295 break;
6296 while (*s && *s != ',')
6297 {
6298 if (*s == '\\' && s[1] != NUL)
6299 ++s;
6300 ++s;
6301 }
6302 s = skip_to_option_part(s);
6303 }
6304 }
6305#endif
6306
6307 /* 'listchars' */
6308 else if (varp == &p_lcs)
6309 {
6310 errmsg = set_chars_option(varp);
6311 }
6312
6313#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6314 /* 'fillchars' */
6315 else if (varp == &p_fcs)
6316 {
6317 errmsg = set_chars_option(varp);
6318 }
6319#endif
6320
6321#ifdef FEAT_CMDWIN
6322 /* 'cedit' */
6323 else if (varp == &p_cedit)
6324 {
6325 errmsg = check_cedit();
6326 }
6327#endif
6328
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006329 /* 'verbosefile' */
6330 else if (varp == &p_vfile)
6331 {
6332 verbose_stop();
6333 if (*p_vfile != NUL && verbose_open() == FAIL)
6334 errmsg = e_invarg;
6335 }
6336
Bram Moolenaar071d4272004-06-13 20:20:40 +00006337#ifdef FEAT_VIMINFO
6338 /* 'viminfo' */
6339 else if (varp == &p_viminfo)
6340 {
6341 for (s = p_viminfo; *s;)
6342 {
6343 /* Check it's a valid character */
6344 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6345 {
6346 errmsg = illegal_char(errbuf, *s);
6347 break;
6348 }
6349 if (*s == 'n') /* name is always last one */
6350 {
6351 break;
6352 }
6353 else if (*s == 'r') /* skip until next ',' */
6354 {
6355 while (*++s && *s != ',')
6356 ;
6357 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006358 else if (*s == '%')
6359 {
6360 /* optional number */
6361 while (vim_isdigit(*++s))
6362 ;
6363 }
6364 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006365 ++s; /* no extra chars */
6366 else /* must have a number */
6367 {
6368 while (vim_isdigit(*++s))
6369 ;
6370
6371 if (!VIM_ISDIGIT(*(s - 1)))
6372 {
6373 if (errbuf != NULL)
6374 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006375 sprintf((char *)errbuf,
6376 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377 transchar_byte(*(s - 1)));
6378 errmsg = errbuf;
6379 }
6380 else
6381 errmsg = (char_u *)"";
6382 break;
6383 }
6384 }
6385 if (*s == ',')
6386 ++s;
6387 else if (*s)
6388 {
6389 if (errbuf != NULL)
6390 errmsg = (char_u *)N_("E527: Missing comma");
6391 else
6392 errmsg = (char_u *)"";
6393 break;
6394 }
6395 }
6396 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6397 errmsg = (char_u *)N_("E528: Must specify a ' value");
6398 }
6399#endif /* FEAT_VIMINFO */
6400
6401 /* terminal options */
6402 else if (istermoption(&options[opt_idx]) && full_screen)
6403 {
6404 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6405 if (varp == &T_CCO)
6406 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006407 int colors = atoi((char *)T_CCO);
6408
6409 /* Only reinitialize colors if t_Co value has really changed to
6410 * avoid expensive reload of colorscheme if t_Co is set to the
6411 * same value multiple times. */
6412 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006413 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006414 t_colors = colors;
6415 if (t_colors <= 1)
6416 {
6417 if (new_value_alloced)
6418 vim_free(T_CCO);
6419 T_CCO = empty_option;
6420 }
6421 /* We now have a different color setup, initialize it again. */
6422 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006423 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006424 }
6425 ttest(FALSE);
6426 if (varp == &T_ME)
6427 {
6428 out_str(T_ME);
6429 redraw_later(CLEAR);
6430#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6431 /* Since t_me has been set, this probably means that the user
6432 * wants to use this as default colors. Need to reset default
6433 * background/foreground colors. */
6434 mch_set_normal_colors();
6435#endif
6436 }
6437 }
6438
6439#ifdef FEAT_LINEBREAK
6440 /* 'showbreak' */
6441 else if (varp == &p_sbr)
6442 {
6443 for (s = p_sbr; *s; )
6444 {
6445 if (ptr2cells(s) != 1)
6446 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006447 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006448 }
6449 }
6450#endif
6451
6452#ifdef FEAT_GUI
6453 /* 'guifont' */
6454 else if (varp == &p_guifont)
6455 {
6456 if (gui.in_use)
6457 {
6458 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006459# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006460 /*
6461 * Put up a font dialog and let the user select a new value.
6462 * If this is cancelled go back to the old value but don't
6463 * give an error message.
6464 */
6465 if (STRCMP(p, "*") == 0)
6466 {
6467 p = gui_mch_font_dialog(oldval);
6468
6469 if (new_value_alloced)
6470 free_string_option(p_guifont);
6471
6472 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6473 new_value_alloced = TRUE;
6474 }
6475# endif
6476 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6477 {
6478# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6479 if (STRCMP(p_guifont, "*") == 0)
6480 {
6481 /* Dialog was cancelled: Keep the old value without giving
6482 * an error message. */
6483 if (new_value_alloced)
6484 free_string_option(p_guifont);
6485 p_guifont = vim_strsave(oldval);
6486 new_value_alloced = TRUE;
6487 }
6488 else
6489# endif
6490 errmsg = (char_u *)N_("E596: Invalid font(s)");
6491 }
6492 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006493 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006494 }
6495# ifdef FEAT_XFONTSET
6496 else if (varp == &p_guifontset)
6497 {
6498 if (STRCMP(p_guifontset, "*") == 0)
6499 errmsg = (char_u *)N_("E597: can't select fontset");
6500 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6501 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006502 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006503 }
6504# endif
6505# ifdef FEAT_MBYTE
6506 else if (varp == &p_guifontwide)
6507 {
6508 if (STRCMP(p_guifontwide, "*") == 0)
6509 errmsg = (char_u *)N_("E533: can't select wide font");
6510 else if (gui_get_wide_font() == FAIL)
6511 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006512 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006513 }
6514# endif
6515#endif
6516
6517#ifdef CURSOR_SHAPE
6518 /* 'guicursor' */
6519 else if (varp == &p_guicursor)
6520 errmsg = parse_shape_opt(SHAPE_CURSOR);
6521#endif
6522
6523#ifdef FEAT_MOUSESHAPE
6524 /* 'mouseshape' */
6525 else if (varp == &p_mouseshape)
6526 {
6527 errmsg = parse_shape_opt(SHAPE_MOUSE);
6528 update_mouseshape(-1);
6529 }
6530#endif
6531
6532#ifdef FEAT_PRINTER
6533 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006534 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006535# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006536 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006537 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006538# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006539#endif
6540
6541#ifdef FEAT_LANGMAP
6542 /* 'langmap' */
6543 else if (varp == &p_langmap)
6544 langmap_set();
6545#endif
6546
6547#ifdef FEAT_LINEBREAK
6548 /* 'breakat' */
6549 else if (varp == &p_breakat)
6550 fill_breakat_flags();
6551#endif
6552
6553#ifdef FEAT_TITLE
6554 /* 'titlestring' and 'iconstring' */
6555 else if (varp == &p_titlestring || varp == &p_iconstring)
6556 {
6557# ifdef FEAT_STL_OPT
6558 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6559
6560 /* NULL => statusline syntax */
6561 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6562 stl_syntax |= flagval;
6563 else
6564 stl_syntax &= ~flagval;
6565# endif
6566 did_set_title(varp == &p_iconstring);
6567
6568 }
6569#endif
6570
6571#ifdef FEAT_GUI
6572 /* 'guioptions' */
6573 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006574 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006575 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006576 redraw_gui_only = TRUE;
6577 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578#endif
6579
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006580#if defined(FEAT_GUI_TABLINE)
6581 /* 'guitablabel' */
6582 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006583 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006584 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006585 redraw_gui_only = TRUE;
6586 }
6587 /* 'guitabtooltip' */
6588 else if (varp == &p_gtt)
6589 {
6590 redraw_gui_only = TRUE;
6591 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006592#endif
6593
Bram Moolenaar071d4272004-06-13 20:20:40 +00006594#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6595 /* 'ttymouse' */
6596 else if (varp == &p_ttym)
6597 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006598 /* Switch the mouse off before changing the escape sequences used for
6599 * that. */
6600 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006601 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6602 errmsg = e_invarg;
6603 else
6604 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006605 if (termcap_active)
6606 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006607 }
6608#endif
6609
Bram Moolenaar071d4272004-06-13 20:20:40 +00006610 /* 'selection' */
6611 else if (varp == &p_sel)
6612 {
6613 if (*p_sel == NUL
6614 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6615 errmsg = e_invarg;
6616 }
6617
6618 /* 'selectmode' */
6619 else if (varp == &p_slm)
6620 {
6621 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6622 errmsg = e_invarg;
6623 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624
6625#ifdef FEAT_BROWSE
6626 /* 'browsedir' */
6627 else if (varp == &p_bsdir)
6628 {
6629 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6630 && !mch_isdir(p_bsdir))
6631 errmsg = e_invarg;
6632 }
6633#endif
6634
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635 /* 'keymodel' */
6636 else if (varp == &p_km)
6637 {
6638 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6639 errmsg = e_invarg;
6640 else
6641 {
6642 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6643 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6644 }
6645 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006646
6647 /* 'mousemodel' */
6648 else if (varp == &p_mousem)
6649 {
6650 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6651 errmsg = e_invarg;
6652#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6653 else if (*p_mousem != *oldval)
6654 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6655 * to create or delete the popup menus. */
6656 gui_motif_update_mousemodel(root_menu);
6657#endif
6658 }
6659
6660 /* 'switchbuf' */
6661 else if (varp == &p_swb)
6662 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006663 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006664 errmsg = e_invarg;
6665 }
6666
6667 /* 'debug' */
6668 else if (varp == &p_debug)
6669 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006670 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006671 errmsg = e_invarg;
6672 }
6673
6674 /* 'display' */
6675 else if (varp == &p_dy)
6676 {
6677 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6678 errmsg = e_invarg;
6679 else
6680 (void)init_chartab();
6681
6682 }
6683
6684#ifdef FEAT_VERTSPLIT
6685 /* 'eadirection' */
6686 else if (varp == &p_ead)
6687 {
6688 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6689 errmsg = e_invarg;
6690 }
6691#endif
6692
6693#ifdef FEAT_CLIPBOARD
6694 /* 'clipboard' */
6695 else if (varp == &p_cb)
6696 errmsg = check_clipboard_option();
6697#endif
6698
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006699#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006700 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6701 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006702 else if (varp == &(curwin->w_s->b_p_spl)
6703 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006704 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006705 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006706 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006707
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006708 if (varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006709 {
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006710 l = (int)STRLEN(curwin->w_s->b_p_spf);
6711 if (l > 0 && (l < 4 || STRCMP(curwin->w_s->b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006712 ".add") != 0))
6713 errmsg = e_invarg;
6714 }
6715
6716 if (errmsg == NULL)
6717 {
6718 FOR_ALL_WINDOWS(wp)
6719 if (wp->w_buffer == curbuf && wp->w_p_spell)
6720 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006721 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006722# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006723 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006724# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006725 }
6726 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006727 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006728 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006729 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006730 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006731 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006732 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006733 /* 'spellsuggest' */
6734 else if (varp == &p_sps)
6735 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006736 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006737 errmsg = e_invarg;
6738 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006739 /* 'mkspellmem' */
6740 else if (varp == &p_msm)
6741 {
6742 if (spell_check_msm() != OK)
6743 errmsg = e_invarg;
6744 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006745#endif
6746
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747#ifdef FEAT_QUICKFIX
6748 /* When 'bufhidden' is set, check for valid value. */
6749 else if (gvarp == &p_bh)
6750 {
6751 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6752 errmsg = e_invarg;
6753 }
6754
6755 /* When 'buftype' is set, check for valid value. */
6756 else if (gvarp == &p_bt)
6757 {
6758 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6759 errmsg = e_invarg;
6760 else
6761 {
6762# ifdef FEAT_WINDOWS
6763 if (curwin->w_status_height)
6764 {
6765 curwin->w_redr_status = TRUE;
6766 redraw_later(VALID);
6767 }
6768# endif
6769 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006770# ifdef FEAT_TITLE
6771 redraw_titles();
6772# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006773 }
6774 }
6775#endif
6776
6777#ifdef FEAT_STL_OPT
6778 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006779 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780 {
6781 int wid;
6782
6783 if (varp == &p_ruf) /* reset ru_wid first */
6784 ru_wid = 0;
6785 s = *varp;
6786 if (varp == &p_ruf && *s == '%')
6787 {
6788 /* set ru_wid if 'ruf' starts with "%99(" */
6789 if (*++s == '-') /* ignore a '-' */
6790 s++;
6791 wid = getdigits(&s);
6792 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6793 ru_wid = wid;
6794 else
6795 errmsg = check_stl_option(p_ruf);
6796 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006797 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006798 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006799 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006800 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006801 comp_col();
6802 }
6803#endif
6804
6805#ifdef FEAT_INS_EXPAND
6806 /* check if it is a valid value for 'complete' -- Acevedo */
6807 else if (gvarp == &p_cpt)
6808 {
6809 for (s = *varp; *s;)
6810 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006811 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006812 s++;
6813 if (!*s)
6814 break;
6815 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6816 {
6817 errmsg = illegal_char(errbuf, *s);
6818 break;
6819 }
6820 if (*++s != NUL && *s != ',' && *s != ' ')
6821 {
6822 if (s[-1] == 'k' || s[-1] == 's')
6823 {
6824 /* skip optional filename after 'k' and 's' */
6825 while (*s && *s != ',' && *s != ' ')
6826 {
6827 if (*s == '\\')
6828 ++s;
6829 ++s;
6830 }
6831 }
6832 else
6833 {
6834 if (errbuf != NULL)
6835 {
6836 sprintf((char *)errbuf,
6837 _("E535: Illegal character after <%c>"),
6838 *--s);
6839 errmsg = errbuf;
6840 }
6841 else
6842 errmsg = (char_u *)"";
6843 break;
6844 }
6845 }
6846 }
6847 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006848
6849 /* 'completeopt' */
6850 else if (varp == &p_cot)
6851 {
6852 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6853 errmsg = e_invarg;
6854 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006855#endif /* FEAT_INS_EXPAND */
6856
6857
6858#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6859 else if (varp == &p_toolbar)
6860 {
6861 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6862 &toolbar_flags, TRUE) != OK)
6863 errmsg = e_invarg;
6864 else
6865 {
6866 out_flush();
6867 gui_mch_show_toolbar((toolbar_flags &
6868 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6869 }
6870 }
6871#endif
6872
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006873#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006874 /* 'toolbariconsize': GTK+ 2 only */
6875 else if (varp == &p_tbis)
6876 {
6877 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6878 errmsg = e_invarg;
6879 else
6880 {
6881 out_flush();
6882 gui_mch_show_toolbar((toolbar_flags &
6883 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6884 }
6885 }
6886#endif
6887
6888 /* 'pastetoggle': translate key codes like in a mapping */
6889 else if (varp == &p_pt)
6890 {
6891 if (*p_pt)
6892 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006893 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006894 if (p != NULL)
6895 {
6896 if (new_value_alloced)
6897 free_string_option(p_pt);
6898 p_pt = p;
6899 new_value_alloced = TRUE;
6900 }
6901 }
6902 }
6903
6904 /* 'backspace' */
6905 else if (varp == &p_bs)
6906 {
6907 if (VIM_ISDIGIT(*p_bs))
6908 {
6909 if (*p_bs >'2' || p_bs[1] != NUL)
6910 errmsg = e_invarg;
6911 }
6912 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6913 errmsg = e_invarg;
6914 }
6915
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006916#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917 /* 'casemap' */
6918 else if (varp == &p_cmp)
6919 {
6920 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6921 errmsg = e_invarg;
6922 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006923#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006924
6925#ifdef FEAT_DIFF
6926 /* 'diffopt' */
6927 else if (varp == &p_dip)
6928 {
6929 if (diffopt_changed() == FAIL)
6930 errmsg = e_invarg;
6931 }
6932#endif
6933
6934#ifdef FEAT_FOLDING
6935 /* 'foldmethod' */
6936 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6937 {
6938 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6939 || *curwin->w_p_fdm == NUL)
6940 errmsg = e_invarg;
6941 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006942 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006944 if (foldmethodIsDiff(curwin))
6945 newFoldLevel();
6946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947 }
6948# ifdef FEAT_EVAL
6949 /* 'foldexpr' */
6950 else if (varp == &curwin->w_p_fde)
6951 {
6952 if (foldmethodIsExpr(curwin))
6953 foldUpdateAll(curwin);
6954 }
6955# endif
6956 /* 'foldmarker' */
6957 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6958 {
6959 p = vim_strchr(*varp, ',');
6960 if (p == NULL)
6961 errmsg = (char_u *)N_("E536: comma required");
6962 else if (p == *varp || p[1] == NUL)
6963 errmsg = e_invarg;
6964 else if (foldmethodIsMarker(curwin))
6965 foldUpdateAll(curwin);
6966 }
6967 /* 'commentstring' */
6968 else if (gvarp == &p_cms)
6969 {
6970 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6971 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6972 }
6973 /* 'foldopen' */
6974 else if (varp == &p_fdo)
6975 {
6976 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6977 errmsg = e_invarg;
6978 }
6979 /* 'foldclose' */
6980 else if (varp == &p_fcl)
6981 {
6982 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6983 errmsg = e_invarg;
6984 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006985 /* 'foldignore' */
6986 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6987 {
6988 if (foldmethodIsIndent(curwin))
6989 foldUpdateAll(curwin);
6990 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006991#endif
6992
6993#ifdef FEAT_VIRTUALEDIT
6994 /* 'virtualedit' */
6995 else if (varp == &p_ve)
6996 {
6997 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6998 errmsg = e_invarg;
6999 else if (STRCMP(p_ve, oldval) != 0)
7000 {
7001 /* Recompute cursor position in case the new 've' setting
7002 * changes something. */
7003 validate_virtcol();
7004 coladvance(curwin->w_virtcol);
7005 }
7006 }
7007#endif
7008
7009#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7010 else if (varp == &p_csqf)
7011 {
7012 if (p_csqf != NULL)
7013 {
7014 p = p_csqf;
7015 while (*p != NUL)
7016 {
7017 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7018 || p[1] == NUL
7019 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7020 || (p[2] != NUL && p[2] != ','))
7021 {
7022 errmsg = e_invarg;
7023 break;
7024 }
7025 else if (p[2] == NUL)
7026 break;
7027 else
7028 p += 3;
7029 }
7030 }
7031 }
7032#endif
7033
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007034#ifdef FEAT_CINDENT
7035 /* 'cinoptions' */
7036 else if (gvarp == &p_cino)
7037 {
7038 /* TODO: recognize errors */
7039 parse_cino(curbuf);
7040 }
7041#endif
7042
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007043#if defined(FEAT_RENDER_OPTIONS)
7044 else if (varp == &p_rop && gui.in_use)
7045 {
7046 if (!gui_mch_set_rendering_options(p_rop))
7047 errmsg = e_invarg;
7048 }
7049#endif
7050
Bram Moolenaar071d4272004-06-13 20:20:40 +00007051 /* Options that are a list of flags. */
7052 else
7053 {
7054 p = NULL;
7055 if (varp == &p_ww)
7056 p = (char_u *)WW_ALL;
7057 if (varp == &p_shm)
7058 p = (char_u *)SHM_ALL;
7059 else if (varp == &(p_cpo))
7060 p = (char_u *)CPO_ALL;
7061 else if (varp == &(curbuf->b_p_fo))
7062 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007063#ifdef FEAT_CONCEAL
7064 else if (varp == &curwin->w_p_cocu)
7065 p = (char_u *)COCU_ALL;
7066#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067 else if (varp == &p_mouse)
7068 {
7069#ifdef FEAT_MOUSE
7070 p = (char_u *)MOUSE_ALL;
7071#else
7072 if (*p_mouse != NUL)
7073 errmsg = (char_u *)N_("E538: No mouse support");
7074#endif
7075 }
7076#if defined(FEAT_GUI)
7077 else if (varp == &p_go)
7078 p = (char_u *)GO_ALL;
7079#endif
7080 if (p != NULL)
7081 {
7082 for (s = *varp; *s; ++s)
7083 if (vim_strchr(p, *s) == NULL)
7084 {
7085 errmsg = illegal_char(errbuf, *s);
7086 break;
7087 }
7088 }
7089 }
7090
7091 /*
7092 * If error detected, restore the previous value.
7093 */
7094 if (errmsg != NULL)
7095 {
7096 if (new_value_alloced)
7097 free_string_option(*varp);
7098 *varp = oldval;
7099 /*
7100 * When resetting some values, need to act on it.
7101 */
7102 if (did_chartab)
7103 (void)init_chartab();
7104 if (varp == &p_hl)
7105 (void)highlight_changed();
7106 }
7107 else
7108 {
7109#ifdef FEAT_EVAL
7110 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007111 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007112#endif
7113 /*
7114 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007115 * Use "free_oldval", because recursiveness may change the flags under
7116 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007117 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007118 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119 free_string_option(oldval);
7120 if (new_value_alloced)
7121 options[opt_idx].flags |= P_ALLOCED;
7122 else
7123 options[opt_idx].flags &= ~P_ALLOCED;
7124
7125 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007126 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007127 {
7128 /* global option with local value set to use global value; free
7129 * the local value and make it empty */
7130 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7131 free_string_option(*(char_u **)p);
7132 *(char_u **)p = empty_option;
7133 }
7134
7135 /* May set global value for local option. */
7136 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7137 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007138
7139#ifdef FEAT_AUTOCMD
7140 /*
7141 * Trigger the autocommand only after setting the flags.
7142 */
7143# ifdef FEAT_SYN_HL
7144 /* When 'syntax' is set, load the syntax of that name */
7145 if (varp == &(curbuf->b_p_syn))
7146 {
7147 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7148 curbuf->b_fname, TRUE, curbuf);
7149 }
7150# endif
7151 else if (varp == &(curbuf->b_p_ft))
7152 {
7153 /* 'filetype' is set, trigger the FileType autocommand */
7154 did_filetype = TRUE;
7155 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7156 curbuf->b_fname, TRUE, curbuf);
7157 }
7158#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007159#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007160 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007161 {
7162 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007163 char_u *q = curwin->w_s->b_p_spl;
7164
7165 /* Skip the first name if it is "cjk". */
7166 if (STRNCMP(q, "cjk,", 4) == 0)
7167 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007168
7169 /*
7170 * Source the spell/LANG.vim in 'runtimepath'.
7171 * They could set 'spellcapcheck' depending on the language.
7172 * Use the first name in 'spelllang' up to '_region' or
7173 * '.encoding'.
7174 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007175 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007176 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7177 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007178 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007179 source_runtime(fname, TRUE);
7180 }
7181#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007182 }
7183
7184#ifdef FEAT_MOUSE
7185 if (varp == &p_mouse)
7186 {
7187# ifdef FEAT_MOUSE_TTY
7188 if (*p_mouse == NUL)
7189 mch_setmouse(FALSE); /* switch mouse off */
7190 else
7191# endif
7192 setmouse(); /* in case 'mouse' changed */
7193 }
7194#endif
7195
Bram Moolenaar913077c2012-03-28 19:59:04 +02007196 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007197 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007198 curwin->w_set_curswant = TRUE;
7199
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007200#ifdef FEAT_GUI
7201 /* check redraw when it's not a GUI option or the GUI is active. */
7202 if (!redraw_gui_only || gui.in_use)
7203#endif
7204 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007205
7206 return errmsg;
7207}
7208
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007209#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007210/*
7211 * Simple int comparison function for use with qsort()
7212 */
7213 static int
7214int_cmp(a, b)
7215 const void *a;
7216 const void *b;
7217{
7218 return *(const int *)a - *(const int *)b;
7219}
7220
7221/*
7222 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7223 * Returns error message, NULL if it's OK.
7224 */
7225 char_u *
7226check_colorcolumn(wp)
7227 win_T *wp;
7228{
7229 char_u *s;
7230 int col;
7231 int count = 0;
7232 int color_cols[256];
7233 int i;
7234 int j = 0;
7235
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007236 if (wp->w_buffer == NULL)
7237 return NULL; /* buffer was closed */
7238
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007239 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007240 {
7241 if (*s == '-' || *s == '+')
7242 {
7243 /* -N and +N: add to 'textwidth' */
7244 col = (*s == '-') ? -1 : 1;
7245 ++s;
7246 if (!VIM_ISDIGIT(*s))
7247 return e_invarg;
7248 col = col * getdigits(&s);
7249 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007250 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007251 col += wp->w_buffer->b_p_tw;
7252 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007253 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007254 }
7255 else if (VIM_ISDIGIT(*s))
7256 col = getdigits(&s);
7257 else
7258 return e_invarg;
7259 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007260skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007261 if (*s == NUL)
7262 break;
7263 if (*s != ',')
7264 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007265 if (*++s == NUL)
7266 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007267 }
7268
7269 vim_free(wp->w_p_cc_cols);
7270 if (count == 0)
7271 wp->w_p_cc_cols = NULL;
7272 else
7273 {
7274 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7275 if (wp->w_p_cc_cols != NULL)
7276 {
7277 /* sort the columns for faster usage on screen redraw inside
7278 * win_line() */
7279 qsort(color_cols, count, sizeof(int), int_cmp);
7280
7281 for (i = 0; i < count; ++i)
7282 /* skip duplicates */
7283 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7284 wp->w_p_cc_cols[j++] = color_cols[i];
7285 wp->w_p_cc_cols[j] = -1; /* end marker */
7286 }
7287 }
7288
7289 return NULL; /* no error */
7290}
7291#endif
7292
Bram Moolenaar071d4272004-06-13 20:20:40 +00007293/*
7294 * Handle setting 'listchars' or 'fillchars'.
7295 * Returns error message, NULL if it's OK.
7296 */
7297 static char_u *
7298set_chars_option(varp)
7299 char_u **varp;
7300{
7301 int round, i, len, entries;
7302 char_u *p, *s;
7303 int c1, c2 = 0;
7304 struct charstab
7305 {
7306 int *cp;
7307 char *name;
7308 };
7309#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7310 static struct charstab filltab[] =
7311 {
7312 {&fill_stl, "stl"},
7313 {&fill_stlnc, "stlnc"},
7314 {&fill_vert, "vert"},
7315 {&fill_fold, "fold"},
7316 {&fill_diff, "diff"},
7317 };
7318#endif
7319 static struct charstab lcstab[] =
7320 {
7321 {&lcs_eol, "eol"},
7322 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007323 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007324 {&lcs_prec, "precedes"},
7325 {&lcs_tab2, "tab"},
7326 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007327#ifdef FEAT_CONCEAL
7328 {&lcs_conceal, "conceal"},
7329#else
7330 {NULL, "conceal"},
7331#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007332 };
7333 struct charstab *tab;
7334
7335#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7336 if (varp == &p_lcs)
7337#endif
7338 {
7339 tab = lcstab;
7340 entries = sizeof(lcstab) / sizeof(struct charstab);
7341 }
7342#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7343 else
7344 {
7345 tab = filltab;
7346 entries = sizeof(filltab) / sizeof(struct charstab);
7347 }
7348#endif
7349
7350 /* first round: check for valid value, second round: assign values */
7351 for (round = 0; round <= 1; ++round)
7352 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007353 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007354 {
7355 /* After checking that the value is valid: set defaults: space for
7356 * 'fillchars', NUL for 'listchars' */
7357 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007358 if (tab[i].cp != NULL)
7359 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007360 if (varp == &p_lcs)
7361 lcs_tab1 = NUL;
7362#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7363 else
7364 fill_diff = '-';
7365#endif
7366 }
7367 p = *varp;
7368 while (*p)
7369 {
7370 for (i = 0; i < entries; ++i)
7371 {
7372 len = (int)STRLEN(tab[i].name);
7373 if (STRNCMP(p, tab[i].name, len) == 0
7374 && p[len] == ':'
7375 && p[len + 1] != NUL)
7376 {
7377 s = p + len + 1;
7378#ifdef FEAT_MBYTE
7379 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007380 if (mb_char2cells(c1) > 1)
7381 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007382#else
7383 c1 = *s++;
7384#endif
7385 if (tab[i].cp == &lcs_tab2)
7386 {
7387 if (*s == NUL)
7388 continue;
7389#ifdef FEAT_MBYTE
7390 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007391 if (mb_char2cells(c2) > 1)
7392 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007393#else
7394 c2 = *s++;
7395#endif
7396 }
7397 if (*s == ',' || *s == NUL)
7398 {
7399 if (round)
7400 {
7401 if (tab[i].cp == &lcs_tab2)
7402 {
7403 lcs_tab1 = c1;
7404 lcs_tab2 = c2;
7405 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007406 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007407 *(tab[i].cp) = c1;
7408
7409 }
7410 p = s;
7411 break;
7412 }
7413 }
7414 }
7415
7416 if (i == entries)
7417 return e_invarg;
7418 if (*p == ',')
7419 ++p;
7420 }
7421 }
7422
7423 return NULL; /* no error */
7424}
7425
7426#ifdef FEAT_STL_OPT
7427/*
7428 * Check validity of options with the 'statusline' format.
7429 * Return error message or NULL.
7430 */
7431 char_u *
7432check_stl_option(s)
7433 char_u *s;
7434{
7435 int itemcnt = 0;
7436 int groupdepth = 0;
7437 static char_u errbuf[80];
7438
7439 while (*s && itemcnt < STL_MAX_ITEM)
7440 {
7441 /* Check for valid keys after % sequences */
7442 while (*s && *s != '%')
7443 s++;
7444 if (!*s)
7445 break;
7446 s++;
7447 if (*s != '%' && *s != ')')
7448 ++itemcnt;
7449 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7450 {
7451 s++;
7452 continue;
7453 }
7454 if (*s == ')')
7455 {
7456 s++;
7457 if (--groupdepth < 0)
7458 break;
7459 continue;
7460 }
7461 if (*s == '-')
7462 s++;
7463 while (VIM_ISDIGIT(*s))
7464 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007465 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007466 continue;
7467 if (*s == '.')
7468 {
7469 s++;
7470 while (*s && VIM_ISDIGIT(*s))
7471 s++;
7472 }
7473 if (*s == '(')
7474 {
7475 groupdepth++;
7476 continue;
7477 }
7478 if (vim_strchr(STL_ALL, *s) == NULL)
7479 {
7480 return illegal_char(errbuf, *s);
7481 }
7482 if (*s == '{')
7483 {
7484 s++;
7485 while (*s != '}' && *s)
7486 s++;
7487 if (*s != '}')
7488 return (char_u *)N_("E540: Unclosed expression sequence");
7489 }
7490 }
7491 if (itemcnt >= STL_MAX_ITEM)
7492 return (char_u *)N_("E541: too many items");
7493 if (groupdepth != 0)
7494 return (char_u *)N_("E542: unbalanced groups");
7495 return NULL;
7496}
7497#endif
7498
7499#ifdef FEAT_CLIPBOARD
7500/*
7501 * Extract the items in the 'clipboard' option and set global values.
7502 */
7503 static char_u *
7504check_clipboard_option()
7505{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007506 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007507 int new_autoselect_star = FALSE;
7508 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007509 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007510 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007511 regprog_T *new_exclude_prog = NULL;
7512 char_u *errmsg = NULL;
7513 char_u *p;
7514
7515 for (p = p_cb; *p != NUL; )
7516 {
7517 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7518 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007519 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007520 p += 7;
7521 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007522 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007523 && (p[11] == ',' || p[11] == NUL))
7524 {
7525 new_unnamed |= CLIP_UNNAMED_PLUS;
7526 p += 11;
7527 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007528 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007529 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007530 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007531 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007532 p += 10;
7533 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007534 else if (STRNCMP(p, "autoselectplus", 14) == 0
7535 && (p[14] == ',' || p[14] == NUL))
7536 {
7537 new_autoselect_plus = TRUE;
7538 p += 14;
7539 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007540 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007541 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007542 {
7543 new_autoselectml = TRUE;
7544 p += 12;
7545 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007546 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7547 {
7548 new_html = TRUE;
7549 p += 4;
7550 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007551 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7552 {
7553 p += 8;
7554 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7555 if (new_exclude_prog == NULL)
7556 errmsg = e_invarg;
7557 break;
7558 }
7559 else
7560 {
7561 errmsg = e_invarg;
7562 break;
7563 }
7564 if (*p == ',')
7565 ++p;
7566 }
7567 if (errmsg == NULL)
7568 {
7569 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007570 clip_autoselect_star = new_autoselect_star;
7571 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007572 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007573 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007574 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007575 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007576#ifdef FEAT_GUI_GTK
7577 if (gui.in_use)
7578 {
7579 gui_gtk_set_selection_targets();
7580 gui_gtk_set_dnd_targets();
7581 }
7582#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007583 }
7584 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007585 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007586
7587 return errmsg;
7588}
7589#endif
7590
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007591#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007592/*
7593 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7594 * Return error message when failed, NULL when OK.
7595 */
7596 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007597compile_cap_prog(synblock)
7598 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007599{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007600 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007601 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007602
Bram Moolenaar860cae12010-06-05 23:22:07 +02007603 if (*synblock->b_p_spc == NUL)
7604 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007605 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007606 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007607 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007608 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007609 if (re != NULL)
7610 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007611 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007612 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007613 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007614 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007615 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007616 return e_invarg;
7617 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007618 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007619 }
7620
Bram Moolenaar473de612013-06-08 18:19:48 +02007621 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007622 return NULL;
7623}
7624#endif
7625
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007626#if defined(FEAT_EVAL) || defined(PROTO)
7627/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007628 * Set the scriptID for an option, taking care of setting the buffer- or
7629 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007630 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007631 static void
7632set_option_scriptID_idx(opt_idx, opt_flags, id)
7633 int opt_idx;
7634 int opt_flags;
7635 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007636{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007637 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7638 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007639
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007640 /* Remember where the option was set. For local options need to do that
7641 * in the buffer or window structure. */
7642 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007643 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007644 if (both || (opt_flags & OPT_LOCAL))
7645 {
7646 if (indir & PV_BUF)
7647 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7648 else if (indir & PV_WIN)
7649 curwin->w_p_scriptID[indir & PV_MASK] = id;
7650 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007651}
7652#endif
7653
Bram Moolenaar071d4272004-06-13 20:20:40 +00007654/*
7655 * Set the value of a boolean option, and take care of side effects.
7656 * Returns NULL for success, or an error message for an error.
7657 */
7658 static char_u *
7659set_bool_option(opt_idx, varp, value, opt_flags)
7660 int opt_idx; /* index in options[] table */
7661 char_u *varp; /* pointer to the option variable */
7662 int value; /* new value */
7663 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7664{
7665 int old_value = *(int *)varp;
7666
Bram Moolenaar071d4272004-06-13 20:20:40 +00007667 /* Disallow changing some options from secure mode */
7668 if ((secure
7669#ifdef HAVE_SANDBOX
7670 || sandbox != 0
7671#endif
7672 ) && (options[opt_idx].flags & P_SECURE))
7673 return e_secure;
7674
7675 *(int *)varp = value; /* set the new value */
7676#ifdef FEAT_EVAL
7677 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007678 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007679#endif
7680
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007681#ifdef FEAT_GUI
7682 need_mouse_correct = TRUE;
7683#endif
7684
Bram Moolenaar071d4272004-06-13 20:20:40 +00007685 /* May set global value for local option. */
7686 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7687 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7688
7689 /*
7690 * Handle side effects of changing a bool option.
7691 */
7692
7693 /* 'compatible' */
7694 if ((int *)varp == &p_cp)
7695 {
7696 compatible_set();
7697 }
7698
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007699#ifdef FEAT_PERSISTENT_UNDO
7700 /* 'undofile' */
7701 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7702 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007703 /* Only take action when the option was set. When reset we do not
7704 * delete the undo file, the option may be set again without making
7705 * any changes in between. */
7706 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007707 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007708 char_u hash[UNDO_HASH_SIZE];
7709 buf_T *save_curbuf = curbuf;
7710
7711 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007712 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007713 /* When 'undofile' is set globally: for every buffer, otherwise
7714 * only for the current buffer: Try to read in the undofile,
7715 * if one exists, the buffer wasn't changed and the buffer was
7716 * loaded */
7717 if ((curbuf == save_curbuf
7718 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7719 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7720 {
7721 u_compute_hash(hash);
7722 u_read_undo(NULL, hash, curbuf->b_fname);
7723 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007724 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007725 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007726 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007727 }
7728#endif
7729
Bram Moolenaar071d4272004-06-13 20:20:40 +00007730 else if ((int *)varp == &curbuf->b_p_ro)
7731 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007732 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007733 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7734 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007735
7736 /* when 'readonly' is set may give W10 again */
7737 if (curbuf->b_p_ro)
7738 curbuf->b_did_warn = FALSE;
7739
Bram Moolenaar071d4272004-06-13 20:20:40 +00007740#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007741 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007742#endif
7743 }
7744
Bram Moolenaar9c449722010-07-20 18:44:27 +02007745#ifdef FEAT_GUI
7746 else if ((int *)varp == &p_mh)
7747 {
7748 if (!p_mh)
7749 gui_mch_mousehide(FALSE);
7750 }
7751#endif
7752
Bram Moolenaara539df02010-08-01 14:35:05 +02007753#ifdef FEAT_TITLE
7754 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007756 {
7757 redraw_titles();
7758 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759 /* when 'endofline' is changed, redraw the window title */
7760 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007761 {
7762 redraw_titles();
7763 }
7764# ifdef FEAT_MBYTE
7765 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007766 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007767 {
7768 redraw_titles();
7769 }
7770# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007771#endif
7772
7773 /* when 'bin' is set also set some other options */
7774 else if ((int *)varp == &curbuf->b_p_bin)
7775 {
7776 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7777#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007778 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779#endif
7780 }
7781
7782#ifdef FEAT_AUTOCMD
7783 /* when 'buflisted' changes, trigger autocommands */
7784 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7785 {
7786 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7787 NULL, NULL, TRUE, curbuf);
7788 }
7789#endif
7790
7791 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7792 else if ((int *)varp == &curbuf->b_p_swf)
7793 {
7794 if (curbuf->b_p_swf && p_uc)
7795 ml_open_file(curbuf); /* create the swap file */
7796 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007797 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7798 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799 mf_close_file(curbuf, TRUE); /* remove the swap file */
7800 }
7801
7802 /* when 'terse' is set change 'shortmess' */
7803 else if ((int *)varp == &p_terse)
7804 {
7805 char_u *p;
7806
7807 p = vim_strchr(p_shm, SHM_SEARCH);
7808
7809 /* insert 's' in p_shm */
7810 if (p_terse && p == NULL)
7811 {
7812 STRCPY(IObuff, p_shm);
7813 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007814 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007815 }
7816 /* remove 's' from p_shm */
7817 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007818 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819 }
7820
7821 /* when 'paste' is set or reset also change other options */
7822 else if ((int *)varp == &p_paste)
7823 {
7824 paste_option_changed();
7825 }
7826
7827 /* when 'insertmode' is set from an autocommand need to do work here */
7828 else if ((int *)varp == &p_im)
7829 {
7830 if (p_im)
7831 {
7832 if ((State & INSERT) == 0)
7833 need_start_insertmode = TRUE;
7834 stop_insert_mode = FALSE;
7835 }
7836 else
7837 {
7838 need_start_insertmode = FALSE;
7839 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007840 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841 clear_cmdline = TRUE; /* remove "(insert)" */
7842 restart_edit = 0;
7843 }
7844 }
7845
7846 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7847 else if ((int *)varp == &p_ic && p_hls)
7848 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007849 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850 }
7851
7852#ifdef FEAT_SEARCH_EXTRA
7853 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7854 else if ((int *)varp == &p_hls)
7855 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007856 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007857 }
7858#endif
7859
7860#ifdef FEAT_SCROLLBIND
7861 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7862 * at the end of normal_cmd() */
7863 else if ((int *)varp == &curwin->w_p_scb)
7864 {
7865 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007866 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007867 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007868 curwin->w_scbind_pos = curwin->w_topline;
7869 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007870 }
7871#endif
7872
7873#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7874 /* There can be only one window with 'previewwindow' set. */
7875 else if ((int *)varp == &curwin->w_p_pvw)
7876 {
7877 if (curwin->w_p_pvw)
7878 {
7879 win_T *win;
7880
7881 for (win = firstwin; win != NULL; win = win->w_next)
7882 if (win->w_p_pvw && win != curwin)
7883 {
7884 curwin->w_p_pvw = FALSE;
7885 return (char_u *)N_("E590: A preview window already exists");
7886 }
7887 }
7888 }
7889#endif
7890
7891 /* when 'textmode' is set or reset also change 'fileformat' */
7892 else if ((int *)varp == &curbuf->b_p_tx)
7893 {
7894 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7895 }
7896
7897 /* when 'textauto' is set or reset also change 'fileformats' */
7898 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007899 set_string_option_direct((char_u *)"ffs", -1,
7900 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007901 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902
7903 /*
7904 * When 'lisp' option changes include/exclude '-' in
7905 * keyword characters.
7906 */
7907#ifdef FEAT_LISP
7908 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7909 {
7910 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7911 }
7912#endif
7913
7914#ifdef FEAT_TITLE
7915 /* when 'title' changed, may need to change the title; same for 'icon' */
7916 else if ((int *)varp == &p_title)
7917 {
7918 did_set_title(FALSE);
7919 }
7920
7921 else if ((int *)varp == &p_icon)
7922 {
7923 did_set_title(TRUE);
7924 }
7925#endif
7926
7927 else if ((int *)varp == &curbuf->b_changed)
7928 {
7929 if (!value)
7930 save_file_ff(curbuf); /* Buffer is unchanged */
7931#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007932 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007933#endif
7934#ifdef FEAT_AUTOCMD
7935 modified_was_set = value;
7936#endif
7937 }
7938
7939#ifdef BACKSLASH_IN_FILENAME
7940 else if ((int *)varp == &p_ssl)
7941 {
7942 if (p_ssl)
7943 {
7944 psepc = '/';
7945 psepcN = '\\';
7946 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 }
7948 else
7949 {
7950 psepc = '\\';
7951 psepcN = '/';
7952 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953 }
7954
7955 /* need to adjust the file name arguments and buffer names. */
7956 buflist_slash_adjust();
7957 alist_slash_adjust();
7958# ifdef FEAT_EVAL
7959 scriptnames_slash_adjust();
7960# endif
7961 }
7962#endif
7963
7964 /* If 'wrap' is set, set w_leftcol to zero. */
7965 else if ((int *)varp == &curwin->w_p_wrap)
7966 {
7967 if (curwin->w_p_wrap)
7968 curwin->w_leftcol = 0;
7969 }
7970
7971#ifdef FEAT_WINDOWS
7972 else if ((int *)varp == &p_ea)
7973 {
7974 if (p_ea && !old_value)
7975 win_equal(curwin, FALSE, 0);
7976 }
7977#endif
7978
7979 else if ((int *)varp == &p_wiv)
7980 {
7981 /*
7982 * When 'weirdinvert' changed, set/reset 't_xs'.
7983 * Then set 'weirdinvert' according to value of 't_xs'.
7984 */
7985 if (p_wiv && !old_value)
7986 T_XS = (char_u *)"y";
7987 else if (!p_wiv && old_value)
7988 T_XS = empty_option;
7989 p_wiv = (*T_XS != NUL);
7990 }
7991
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007992#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007993 else if ((int *)varp == &p_beval)
7994 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007995 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007997 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007998 gui_mch_disable_beval_area(balloonEval);
7999 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008000#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008002#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003 else if ((int *)varp == &p_acd)
8004 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008005 /* Change directories when the 'acd' option is set now. */
8006 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 }
8008#endif
8009
8010#ifdef FEAT_DIFF
8011 /* 'diff' */
8012 else if ((int *)varp == &curwin->w_p_diff)
8013 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008014 /* May add or remove the buffer from the list of diff buffers. */
8015 diff_buf_adjust(curwin);
8016# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 if (foldmethodIsDiff(curwin))
8018 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008019# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008020 }
8021#endif
8022
8023#ifdef USE_IM_CONTROL
8024 /* 'imdisable' */
8025 else if ((int *)varp == &p_imdisable)
8026 {
8027 /* Only de-activate it here, it will be enabled when changing mode. */
8028 if (p_imdisable)
8029 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008030 else if (State & INSERT)
8031 /* When the option is set from an autocommand, it may need to take
8032 * effect right away. */
8033 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008034 }
8035#endif
8036
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008037#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008038 /* 'spell' */
8039 else if ((int *)varp == &curwin->w_p_spell)
8040 {
8041 if (curwin->w_p_spell)
8042 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008043 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008044 if (errmsg != NULL)
8045 EMSG(_(errmsg));
8046 }
8047 }
8048#endif
8049
Bram Moolenaar071d4272004-06-13 20:20:40 +00008050#ifdef FEAT_FKMAP
8051 else if ((int *)varp == &p_altkeymap)
8052 {
8053 if (old_value != p_altkeymap)
8054 {
8055 if (!p_altkeymap)
8056 {
8057 p_hkmap = p_fkmap;
8058 p_fkmap = 0;
8059 }
8060 else
8061 {
8062 p_fkmap = p_hkmap;
8063 p_hkmap = 0;
8064 }
8065 (void)init_chartab();
8066 }
8067 }
8068
8069 /*
8070 * In case some second language keymapping options have changed, check
8071 * and correct the setting in a consistent way.
8072 */
8073
8074 /*
8075 * If hkmap or fkmap are set, reset Arabic keymapping.
8076 */
8077 if ((p_hkmap || p_fkmap) && p_altkeymap)
8078 {
8079 p_altkeymap = p_fkmap;
8080# ifdef FEAT_ARABIC
8081 curwin->w_p_arab = FALSE;
8082# endif
8083 (void)init_chartab();
8084 }
8085
8086 /*
8087 * If hkmap set, reset Farsi keymapping.
8088 */
8089 if (p_hkmap && p_altkeymap)
8090 {
8091 p_altkeymap = 0;
8092 p_fkmap = 0;
8093# ifdef FEAT_ARABIC
8094 curwin->w_p_arab = FALSE;
8095# endif
8096 (void)init_chartab();
8097 }
8098
8099 /*
8100 * If fkmap set, reset Hebrew keymapping.
8101 */
8102 if (p_fkmap && !p_altkeymap)
8103 {
8104 p_altkeymap = 1;
8105 p_hkmap = 0;
8106# ifdef FEAT_ARABIC
8107 curwin->w_p_arab = FALSE;
8108# endif
8109 (void)init_chartab();
8110 }
8111#endif
8112
8113#ifdef FEAT_ARABIC
8114 if ((int *)varp == &curwin->w_p_arab)
8115 {
8116 if (curwin->w_p_arab)
8117 {
8118 /*
8119 * 'arabic' is set, handle various sub-settings.
8120 */
8121 if (!p_tbidi)
8122 {
8123 /* set rightleft mode */
8124 if (!curwin->w_p_rl)
8125 {
8126 curwin->w_p_rl = TRUE;
8127 changed_window_setting();
8128 }
8129
8130 /* Enable Arabic shaping (major part of what Arabic requires) */
8131 if (!p_arshape)
8132 {
8133 p_arshape = TRUE;
8134 redraw_later_clear();
8135 }
8136 }
8137
8138 /* Arabic requires a utf-8 encoding, inform the user if its not
8139 * set. */
8140 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008141 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008142 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8143
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008144 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008145 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8146#ifdef FEAT_EVAL
8147 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8148#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008149 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150
8151# ifdef FEAT_MBYTE
8152 /* set 'delcombine' */
8153 p_deco = TRUE;
8154# endif
8155
8156# ifdef FEAT_KEYMAP
8157 /* Force-set the necessary keymap for arabic */
8158 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8159 OPT_LOCAL);
8160# endif
8161# ifdef FEAT_FKMAP
8162 p_altkeymap = 0;
8163 p_hkmap = 0;
8164 p_fkmap = 0;
8165 (void)init_chartab();
8166# endif
8167 }
8168 else
8169 {
8170 /*
8171 * 'arabic' is reset, handle various sub-settings.
8172 */
8173 if (!p_tbidi)
8174 {
8175 /* reset rightleft mode */
8176 if (curwin->w_p_rl)
8177 {
8178 curwin->w_p_rl = FALSE;
8179 changed_window_setting();
8180 }
8181
8182 /* 'arabicshape' isn't reset, it is a global option and
8183 * another window may still need it "on". */
8184 }
8185
8186 /* 'delcombine' isn't reset, it is a global option and another
8187 * window may still want it "on". */
8188
8189# ifdef FEAT_KEYMAP
8190 /* Revert to the default keymap */
8191 curbuf->b_p_iminsert = B_IMODE_NONE;
8192 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8193# endif
8194 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008195 }
8196
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008197#endif
8198
Bram Moolenaar071d4272004-06-13 20:20:40 +00008199 /*
8200 * End of handling side effects for bool options.
8201 */
8202
8203 options[opt_idx].flags |= P_WAS_SET;
8204
8205 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008206 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008207 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008208 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209 check_redraw(options[opt_idx].flags);
8210
8211 return NULL;
8212}
8213
8214/*
8215 * Set the value of a number option, and take care of side effects.
8216 * Returns NULL for success, or an error message for an error.
8217 */
8218 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008219set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220 int opt_idx; /* index in options[] table */
8221 char_u *varp; /* pointer to the option variable */
8222 long value; /* new value */
8223 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008224 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8226 OPT_MODELINE */
8227{
8228 char_u *errmsg = NULL;
8229 long old_value = *(long *)varp;
8230 long old_Rows = Rows; /* remember old Rows */
8231 long old_Columns = Columns; /* remember old Columns */
8232 long *pp = (long *)varp;
8233
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008234 /* Disallow changing some options from secure mode. */
8235 if ((secure
8236#ifdef HAVE_SANDBOX
8237 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008238#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008239 ) && (options[opt_idx].flags & P_SECURE))
8240 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241
8242 *pp = value;
8243#ifdef FEAT_EVAL
8244 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008245 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008246#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008247#ifdef FEAT_GUI
8248 need_mouse_correct = TRUE;
8249#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008250
Bram Moolenaar14f24742012-08-08 18:01:05 +02008251 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008252 {
8253 errmsg = e_positive;
8254 curbuf->b_p_sw = curbuf->b_p_ts;
8255 }
8256
8257 /*
8258 * Number options that need some action when changed
8259 */
8260#ifdef FEAT_WINDOWS
8261 if (pp == &p_wh || pp == &p_hh)
8262 {
8263 if (p_wh < 1)
8264 {
8265 errmsg = e_positive;
8266 p_wh = 1;
8267 }
8268 if (p_wmh > p_wh)
8269 {
8270 errmsg = e_winheight;
8271 p_wh = p_wmh;
8272 }
8273 if (p_hh < 0)
8274 {
8275 errmsg = e_positive;
8276 p_hh = 0;
8277 }
8278
8279 /* Change window height NOW */
8280 if (lastwin != firstwin)
8281 {
8282 if (pp == &p_wh && curwin->w_height < p_wh)
8283 win_setheight((int)p_wh);
8284 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8285 win_setheight((int)p_hh);
8286 }
8287 }
8288
8289 /* 'winminheight' */
8290 else if (pp == &p_wmh)
8291 {
8292 if (p_wmh < 0)
8293 {
8294 errmsg = e_positive;
8295 p_wmh = 0;
8296 }
8297 if (p_wmh > p_wh)
8298 {
8299 errmsg = e_winheight;
8300 p_wmh = p_wh;
8301 }
8302 win_setminheight();
8303 }
8304
8305# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008306 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008307 {
8308 if (p_wiw < 1)
8309 {
8310 errmsg = e_positive;
8311 p_wiw = 1;
8312 }
8313 if (p_wmw > p_wiw)
8314 {
8315 errmsg = e_winwidth;
8316 p_wiw = p_wmw;
8317 }
8318
8319 /* Change window width NOW */
8320 if (lastwin != firstwin && curwin->w_width < p_wiw)
8321 win_setwidth((int)p_wiw);
8322 }
8323
8324 /* 'winminwidth' */
8325 else if (pp == &p_wmw)
8326 {
8327 if (p_wmw < 0)
8328 {
8329 errmsg = e_positive;
8330 p_wmw = 0;
8331 }
8332 if (p_wmw > p_wiw)
8333 {
8334 errmsg = e_winwidth;
8335 p_wmw = p_wiw;
8336 }
8337 win_setminheight();
8338 }
8339# endif
8340
8341#endif
8342
8343#ifdef FEAT_WINDOWS
8344 /* (re)set last window status line */
8345 else if (pp == &p_ls)
8346 {
8347 last_status(FALSE);
8348 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008349
8350 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008351 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008352 {
8353 shell_new_rows(); /* recompute window positions and heights */
8354 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008355#endif
8356
8357#ifdef FEAT_GUI
8358 else if (pp == &p_linespace)
8359 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008360 /* Recompute gui.char_height and resize the Vim window to keep the
8361 * same number of lines. */
8362 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008363 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 }
8365#endif
8366
8367#ifdef FEAT_FOLDING
8368 /* 'foldlevel' */
8369 else if (pp == &curwin->w_p_fdl)
8370 {
8371 if (curwin->w_p_fdl < 0)
8372 curwin->w_p_fdl = 0;
8373 newFoldLevel();
8374 }
8375
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008376 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008377 else if (pp == &curwin->w_p_fml)
8378 {
8379 foldUpdateAll(curwin);
8380 }
8381
8382 /* 'foldnestmax' */
8383 else if (pp == &curwin->w_p_fdn)
8384 {
8385 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8386 foldUpdateAll(curwin);
8387 }
8388
8389 /* 'foldcolumn' */
8390 else if (pp == &curwin->w_p_fdc)
8391 {
8392 if (curwin->w_p_fdc < 0)
8393 {
8394 errmsg = e_positive;
8395 curwin->w_p_fdc = 0;
8396 }
8397 else if (curwin->w_p_fdc > 12)
8398 {
8399 errmsg = e_invarg;
8400 curwin->w_p_fdc = 12;
8401 }
8402 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008403#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008405#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406 /* 'shiftwidth' or 'tabstop' */
8407 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8408 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008409# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008410 if (foldmethodIsIndent(curwin))
8411 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008412# endif
8413# ifdef FEAT_CINDENT
8414 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8415 * parse 'cinoptions'. */
8416 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8417 parse_cino(curbuf);
8418# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008419 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008420#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008422#ifdef FEAT_MBYTE
8423 /* 'maxcombine' */
8424 else if (pp == &p_mco)
8425 {
8426 if (p_mco > MAX_MCO)
8427 p_mco = MAX_MCO;
8428 else if (p_mco < 0)
8429 p_mco = 0;
8430 screenclear(); /* will re-allocate the screen */
8431 }
8432#endif
8433
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 else if (pp == &curbuf->b_p_iminsert)
8435 {
8436 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8437 {
8438 errmsg = e_invarg;
8439 curbuf->b_p_iminsert = B_IMODE_NONE;
8440 }
8441 p_iminsert = curbuf->b_p_iminsert;
8442 if (termcap_active) /* don't do this in the alternate screen */
8443 showmode();
8444#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8445 /* Show/unshow value of 'keymap' in status lines. */
8446 status_redraw_curbuf();
8447#endif
8448 }
8449
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008450 else if (pp == &p_window)
8451 {
8452 if (p_window < 1)
8453 p_window = 1;
8454 else if (p_window >= Rows)
8455 p_window = Rows - 1;
8456 }
8457
Bram Moolenaar071d4272004-06-13 20:20:40 +00008458 else if (pp == &curbuf->b_p_imsearch)
8459 {
8460 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8461 {
8462 errmsg = e_invarg;
8463 curbuf->b_p_imsearch = B_IMODE_NONE;
8464 }
8465 p_imsearch = curbuf->b_p_imsearch;
8466 }
8467
8468#ifdef FEAT_TITLE
8469 /* if 'titlelen' has changed, redraw the title */
8470 else if (pp == &p_titlelen)
8471 {
8472 if (p_titlelen < 0)
8473 {
8474 errmsg = e_positive;
8475 p_titlelen = 85;
8476 }
8477 if (starting != NO_SCREEN && old_value != p_titlelen)
8478 need_maketitle = TRUE;
8479 }
8480#endif
8481
8482 /* if p_ch changed value, change the command line height */
8483 else if (pp == &p_ch)
8484 {
8485 if (p_ch < 1)
8486 {
8487 errmsg = e_positive;
8488 p_ch = 1;
8489 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008490 if (p_ch > Rows - min_rows() + 1)
8491 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492
8493 /* Only compute the new window layout when startup has been
8494 * completed. Otherwise the frame sizes may be wrong. */
8495 if (p_ch != old_value && full_screen
8496#ifdef FEAT_GUI
8497 && !gui.starting
8498#endif
8499 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008500 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008501 }
8502
8503 /* when 'updatecount' changes from zero to non-zero, open swap files */
8504 else if (pp == &p_uc)
8505 {
8506 if (p_uc < 0)
8507 {
8508 errmsg = e_positive;
8509 p_uc = 100;
8510 }
8511 if (p_uc && !old_value)
8512 ml_open_files();
8513 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008514#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008515 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008516 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008517 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008518 {
8519 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008520 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008521 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008522 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008523 {
8524 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008525 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008526 }
8527 }
8528#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008529#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008530 else if (pp == &p_mzq)
8531 mzvim_reset_timer();
8532#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533
8534 /* sync undo before 'undolevels' changes */
8535 else if (pp == &p_ul)
8536 {
8537 /* use the old value, otherwise u_sync() may not work properly */
8538 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008539 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008540 p_ul = value;
8541 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008542 else if (pp == &curbuf->b_p_ul)
8543 {
8544 /* use the old value, otherwise u_sync() may not work properly */
8545 curbuf->b_p_ul = old_value;
8546 u_sync(TRUE);
8547 curbuf->b_p_ul = value;
8548 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008549
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008550#ifdef FEAT_LINEBREAK
8551 /* 'numberwidth' must be positive */
8552 else if (pp == &curwin->w_p_nuw)
8553 {
8554 if (curwin->w_p_nuw < 1)
8555 {
8556 errmsg = e_positive;
8557 curwin->w_p_nuw = 1;
8558 }
8559 if (curwin->w_p_nuw > 10)
8560 {
8561 errmsg = e_invarg;
8562 curwin->w_p_nuw = 10;
8563 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008564 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008565 }
8566#endif
8567
Bram Moolenaar1a384422010-07-14 19:53:30 +02008568 else if (pp == &curbuf->b_p_tw)
8569 {
8570 if (curbuf->b_p_tw < 0)
8571 {
8572 errmsg = e_positive;
8573 curbuf->b_p_tw = 0;
8574 }
8575#ifdef FEAT_SYN_HL
8576# ifdef FEAT_WINDOWS
8577 {
8578 win_T *wp;
8579 tabpage_T *tp;
8580
8581 FOR_ALL_TAB_WINDOWS(tp, wp)
8582 check_colorcolumn(wp);
8583 }
8584# else
8585 check_colorcolumn(curwin);
8586# endif
8587#endif
8588 }
8589
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590 /*
8591 * Check the bounds for numeric options here
8592 */
8593 if (Rows < min_rows() && full_screen)
8594 {
8595 if (errbuf != NULL)
8596 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008597 vim_snprintf((char *)errbuf, errbuflen,
8598 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008599 errmsg = errbuf;
8600 }
8601 Rows = min_rows();
8602 }
8603 if (Columns < MIN_COLUMNS && full_screen)
8604 {
8605 if (errbuf != NULL)
8606 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008607 vim_snprintf((char *)errbuf, errbuflen,
8608 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008609 errmsg = errbuf;
8610 }
8611 Columns = MIN_COLUMNS;
8612 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008613 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008614
8615#ifdef DJGPP
8616 /* avoid a crash by checking for a too large value of 'columns' */
8617 if (old_Columns != Columns && full_screen && term_console)
8618 mch_check_columns();
8619#endif
8620
8621 /*
8622 * If the screen (shell) height has been changed, assume it is the
8623 * physical screenheight.
8624 */
8625 if (old_Rows != Rows || old_Columns != Columns)
8626 {
8627 /* Changing the screen size is not allowed while updating the screen. */
8628 if (updating_screen)
8629 *pp = old_value;
8630 else if (full_screen
8631#ifdef FEAT_GUI
8632 && !gui.starting
8633#endif
8634 )
8635 set_shellsize((int)Columns, (int)Rows, TRUE);
8636 else
8637 {
8638 /* Postpone the resizing; check the size and cmdline position for
8639 * messages. */
8640 check_shellsize();
8641 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8642 cmdline_row = Rows - p_ch;
8643 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008644 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008645 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008646 }
8647
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648 if (curbuf->b_p_ts <= 0)
8649 {
8650 errmsg = e_positive;
8651 curbuf->b_p_ts = 8;
8652 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008653 if (p_tm < 0)
8654 {
8655 errmsg = e_positive;
8656 p_tm = 0;
8657 }
8658 if ((curwin->w_p_scr <= 0
8659 || (curwin->w_p_scr > curwin->w_height
8660 && curwin->w_height > 0))
8661 && full_screen)
8662 {
8663 if (pp == &(curwin->w_p_scr))
8664 {
8665 if (curwin->w_p_scr != 0)
8666 errmsg = e_scroll;
8667 win_comp_scroll(curwin);
8668 }
8669 /* If 'scroll' became invalid because of a side effect silently adjust
8670 * it. */
8671 else if (curwin->w_p_scr <= 0)
8672 curwin->w_p_scr = 1;
8673 else /* curwin->w_p_scr > curwin->w_height */
8674 curwin->w_p_scr = curwin->w_height;
8675 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008676 if (p_hi < 0)
8677 {
8678 errmsg = e_positive;
8679 p_hi = 0;
8680 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008681 else if (p_hi > 10000)
8682 {
8683 errmsg = e_invarg;
8684 p_hi = 10000;
8685 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008686 if (p_re < 0 || p_re > 2)
8687 {
8688 errmsg = e_invarg;
8689 p_re = 0;
8690 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691 if (p_report < 0)
8692 {
8693 errmsg = e_positive;
8694 p_report = 1;
8695 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008696 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697 {
8698 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8699 p_sj = Rows / 2;
8700 else
8701 {
8702 errmsg = e_scroll;
8703 p_sj = 1;
8704 }
8705 }
8706 if (p_so < 0 && full_screen)
8707 {
8708 errmsg = e_scroll;
8709 p_so = 0;
8710 }
8711 if (p_siso < 0 && full_screen)
8712 {
8713 errmsg = e_positive;
8714 p_siso = 0;
8715 }
8716#ifdef FEAT_CMDWIN
8717 if (p_cwh < 1)
8718 {
8719 errmsg = e_positive;
8720 p_cwh = 1;
8721 }
8722#endif
8723 if (p_ut < 0)
8724 {
8725 errmsg = e_positive;
8726 p_ut = 2000;
8727 }
8728 if (p_ss < 0)
8729 {
8730 errmsg = e_positive;
8731 p_ss = 0;
8732 }
8733
8734 /* May set global value for local option. */
8735 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8736 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8737
8738 options[opt_idx].flags |= P_WAS_SET;
8739
8740 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008741 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008742 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008743 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008744 check_redraw(options[opt_idx].flags);
8745
8746 return errmsg;
8747}
8748
8749/*
8750 * Called after an option changed: check if something needs to be redrawn.
8751 */
8752 static void
8753check_redraw(flags)
8754 long_u flags;
8755{
8756 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008757 int doclear = (flags & P_RCLR) == P_RCLR;
8758 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008759
8760#ifdef FEAT_WINDOWS
8761 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8762 status_redraw_all();
8763#endif
8764
8765 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8766 changed_window_setting();
8767 if (flags & P_RBUF)
8768 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008769 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008770 redraw_all_later(CLEAR);
8771 else if (all)
8772 redraw_all_later(NOT_VALID);
8773}
8774
8775/*
8776 * Find index for option 'arg'.
8777 * Return -1 if not found.
8778 */
8779 static int
8780findoption(arg)
8781 char_u *arg;
8782{
8783 int opt_idx;
8784 char *s, *p;
8785 static short quick_tab[27] = {0, 0}; /* quick access table */
8786 int is_term_opt;
8787
8788 /*
8789 * For first call: Initialize the quick-access table.
8790 * It contains the index for the first option that starts with a certain
8791 * letter. There are 26 letters, plus the first "t_" option.
8792 */
8793 if (quick_tab[1] == 0)
8794 {
8795 p = options[0].fullname;
8796 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8797 {
8798 if (s[0] != p[0])
8799 {
8800 if (s[0] == 't' && s[1] == '_')
8801 quick_tab[26] = opt_idx;
8802 else
8803 quick_tab[CharOrdLow(s[0])] = opt_idx;
8804 }
8805 p = s;
8806 }
8807 }
8808
8809 /*
8810 * Check for name starting with an illegal character.
8811 */
8812#ifdef EBCDIC
8813 if (!islower(arg[0]))
8814#else
8815 if (arg[0] < 'a' || arg[0] > 'z')
8816#endif
8817 return -1;
8818
8819 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8820 if (is_term_opt)
8821 opt_idx = quick_tab[26];
8822 else
8823 opt_idx = quick_tab[CharOrdLow(arg[0])];
8824 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8825 {
8826 if (STRCMP(arg, s) == 0) /* match full name */
8827 break;
8828 }
8829 if (s == NULL && !is_term_opt)
8830 {
8831 opt_idx = quick_tab[CharOrdLow(arg[0])];
8832 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8833 {
8834 s = options[opt_idx].shortname;
8835 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8836 break;
8837 s = NULL;
8838 }
8839 }
8840 if (s == NULL)
8841 opt_idx = -1;
8842 return opt_idx;
8843}
8844
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008845#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008846/*
8847 * Get the value for an option.
8848 *
8849 * Returns:
8850 * Number or Toggle option: 1, *numval gets value.
8851 * String option: 0, *stringval gets allocated string.
8852 * Hidden Number or Toggle option: -1.
8853 * hidden String option: -2.
8854 * unknown option: -3.
8855 */
8856 int
8857get_option_value(name, numval, stringval, opt_flags)
8858 char_u *name;
8859 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008860 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 int opt_flags;
8862{
8863 int opt_idx;
8864 char_u *varp;
8865
8866 opt_idx = findoption(name);
8867 if (opt_idx < 0) /* unknown option */
8868 return -3;
8869
8870 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8871
8872 if (options[opt_idx].flags & P_STRING)
8873 {
8874 if (varp == NULL) /* hidden option */
8875 return -2;
8876 if (stringval != NULL)
8877 {
8878#ifdef FEAT_CRYPT
8879 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008880 if ((char_u **)varp == &curbuf->b_p_key
8881 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008882 *stringval = vim_strsave((char_u *)"*****");
8883 else
8884#endif
8885 *stringval = vim_strsave(*(char_u **)(varp));
8886 }
8887 return 0;
8888 }
8889
8890 if (varp == NULL) /* hidden option */
8891 return -1;
8892 if (options[opt_idx].flags & P_NUM)
8893 *numval = *(long *)varp;
8894 else
8895 {
8896 /* Special case: 'modified' is b_changed, but we also want to consider
8897 * it set when 'ff' or 'fenc' changed. */
8898 if ((int *)varp == &curbuf->b_changed)
8899 *numval = curbufIsChanged();
8900 else
8901 *numval = *(int *)varp;
8902 }
8903 return 1;
8904}
8905#endif
8906
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008907#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008908/*
8909 * Returns the option attributes and its value. Unlike the above function it
8910 * will return either global value or local value of the option depending on
8911 * what was requested, but it will never return global value if it was
8912 * requested to return local one and vice versa. Neither it will return
8913 * buffer-local value if it was requested to return window-local one.
8914 *
8915 * Pretends that option is absent if it is not present in the requested scope
8916 * (i.e. has no global, window-local or buffer-local value depending on
8917 * opt_type). Uses
8918 *
8919 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008920 * 0 hidden or unknown option, also option that does not have requested
8921 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008922 * see SOPT_* in vim.h for other flags
8923 *
8924 * Possible opt_type values: see SREQ_* in vim.h
8925 */
8926 int
8927get_option_value_strict(name, numval, stringval, opt_type, from)
8928 char_u *name;
8929 long *numval;
8930 char_u **stringval; /* NULL when only obtaining attributes */
8931 int opt_type;
8932 void *from;
8933{
8934 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008935 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008936 struct vimoption *p;
8937 int r = 0;
8938
8939 opt_idx = findoption(name);
8940 if (opt_idx < 0)
8941 return 0;
8942
8943 p = &(options[opt_idx]);
8944
8945 /* Hidden option */
8946 if (p->var == NULL)
8947 return 0;
8948
8949 if (p->flags & P_BOOL)
8950 r |= SOPT_BOOL;
8951 else if (p->flags & P_NUM)
8952 r |= SOPT_NUM;
8953 else if (p->flags & P_STRING)
8954 r |= SOPT_STRING;
8955
8956 if (p->indir == PV_NONE)
8957 {
8958 if (opt_type == SREQ_GLOBAL)
8959 r |= SOPT_GLOBAL;
8960 else
8961 return 0; /* Did not request global-only option */
8962 }
8963 else
8964 {
8965 if (p->indir & PV_BOTH)
8966 r |= SOPT_GLOBAL;
8967 else if (opt_type == SREQ_GLOBAL)
8968 return 0; /* Requested global option */
8969
8970 if (p->indir & PV_WIN)
8971 {
8972 if (opt_type == SREQ_BUF)
8973 return 0; /* Did not request window-local option */
8974 else
8975 r |= SOPT_WIN;
8976 }
8977 else if (p->indir & PV_BUF)
8978 {
8979 if (opt_type == SREQ_WIN)
8980 return 0; /* Did not request buffer-local option */
8981 else
8982 r |= SOPT_BUF;
8983 }
8984 }
8985
8986 if (stringval == NULL)
8987 return r;
8988
8989 if (opt_type == SREQ_GLOBAL)
8990 varp = p->var;
8991 else
8992 {
8993 if (opt_type == SREQ_BUF)
8994 {
8995 /* Special case: 'modified' is b_changed, but we also want to
8996 * consider it set when 'ff' or 'fenc' changed. */
8997 if (p->indir == PV_MOD)
8998 {
8999 *numval = bufIsChanged((buf_T *) from);
9000 varp = NULL;
9001 }
9002#ifdef FEAT_CRYPT
9003 else if (p->indir == PV_KEY)
9004 {
9005 /* never return the value of the crypt key */
9006 *stringval = NULL;
9007 varp = NULL;
9008 }
9009#endif
9010 else
9011 {
9012 aco_save_T aco;
9013 aucmd_prepbuf(&aco, (buf_T *) from);
9014 varp = get_varp(p);
9015 aucmd_restbuf(&aco);
9016 }
9017 }
9018 else if (opt_type == SREQ_WIN)
9019 {
9020 win_T *save_curwin;
9021 save_curwin = curwin;
9022 curwin = (win_T *) from;
9023 curbuf = curwin->w_buffer;
9024 varp = get_varp(p);
9025 curwin = save_curwin;
9026 curbuf = curwin->w_buffer;
9027 }
9028 if (varp == p->var)
9029 return (r | SOPT_UNSET);
9030 }
9031
9032 if (varp != NULL)
9033 {
9034 if (p->flags & P_STRING)
9035 *stringval = vim_strsave(*(char_u **)(varp));
9036 else if (p->flags & P_NUM)
9037 *numval = *(long *) varp;
9038 else
9039 *numval = *(int *)varp;
9040 }
9041
9042 return r;
9043}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009044
9045/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009046 * Iterate over options. First argument is a pointer to a pointer to a
9047 * structure inside options[] array, second is option type like in the above
9048 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009049 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009050 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009051 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009052 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009053 * first argument to NULL.
9054 *
9055 * Returns full option name for current option on each call.
9056 */
9057 char_u *
9058option_iter_next(option, opt_type)
9059 void **option;
9060 int opt_type;
9061{
9062 struct vimoption *ret = NULL;
9063 do
9064 {
9065 if (*option == NULL)
9066 *option = (void *) options;
9067 else if (((struct vimoption *) (*option))->fullname == NULL)
9068 {
9069 *option = NULL;
9070 return NULL;
9071 }
9072 else
9073 *option = (void *) (((struct vimoption *) (*option)) + 1);
9074
9075 ret = ((struct vimoption *) (*option));
9076
9077 /* Hidden option */
9078 if (ret->var == NULL)
9079 {
9080 ret = NULL;
9081 continue;
9082 }
9083
9084 switch (opt_type)
9085 {
9086 case SREQ_GLOBAL:
9087 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9088 ret = NULL;
9089 break;
9090 case SREQ_BUF:
9091 if (!(ret->indir & PV_BUF))
9092 ret = NULL;
9093 break;
9094 case SREQ_WIN:
9095 if (!(ret->indir & PV_WIN))
9096 ret = NULL;
9097 break;
9098 default:
9099 EMSG2(_(e_intern2), "option_iter_next()");
9100 return NULL;
9101 }
9102 }
9103 while (ret == NULL);
9104
9105 return (char_u *)ret->fullname;
9106}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009107#endif
9108
Bram Moolenaar071d4272004-06-13 20:20:40 +00009109/*
9110 * Set the value of option "name".
9111 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009112 *
9113 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009114 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009115 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116set_option_value(name, number, string, opt_flags)
9117 char_u *name;
9118 long number;
9119 char_u *string;
9120 int opt_flags; /* OPT_LOCAL or 0 (both) */
9121{
9122 int opt_idx;
9123 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009124 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009125
9126 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009127 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009128 EMSG2(_("E355: Unknown option: %s"), name);
9129 else
9130 {
9131 flags = options[opt_idx].flags;
9132#ifdef HAVE_SANDBOX
9133 /* Disallow changing some options in the sandbox */
9134 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009135 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009136 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009137 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009139#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009140 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009141 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142 else
9143 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009144 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009145 if (varp != NULL) /* hidden option is not changed */
9146 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009147 if (number == 0 && string != NULL)
9148 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009149 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009150
9151 /* Either we are given a string or we are setting option
9152 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009153 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009154 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009155 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009156 {
9157 /* There's another character after zeros or the string
9158 * is empty. In both cases, we are trying to set a
9159 * num option using a string. */
9160 EMSG3(_("E521: Number required: &%s = '%s'"),
9161 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009162 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009163
9164 }
9165 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009166 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009167 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009168 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009169 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009170 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009171 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172 }
9173 }
9174 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009175 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009176}
9177
9178/*
9179 * Get the terminal code for a terminal option.
9180 * Returns NULL when not found.
9181 */
9182 char_u *
9183get_term_code(tname)
9184 char_u *tname;
9185{
9186 int opt_idx;
9187 char_u *varp;
9188
9189 if (tname[0] != 't' || tname[1] != '_' ||
9190 tname[2] == NUL || tname[3] == NUL)
9191 return NULL;
9192 if ((opt_idx = findoption(tname)) >= 0)
9193 {
9194 varp = get_varp(&(options[opt_idx]));
9195 if (varp != NULL)
9196 varp = *(char_u **)(varp);
9197 return varp;
9198 }
9199 return find_termcode(tname + 2);
9200}
9201
9202 char_u *
9203get_highlight_default()
9204{
9205 int i;
9206
9207 i = findoption((char_u *)"hl");
9208 if (i >= 0)
9209 return options[i].def_val[VI_DEFAULT];
9210 return (char_u *)NULL;
9211}
9212
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009213#if defined(FEAT_MBYTE) || defined(PROTO)
9214 char_u *
9215get_encoding_default()
9216{
9217 int i;
9218
9219 i = findoption((char_u *)"enc");
9220 if (i >= 0)
9221 return options[i].def_val[VI_DEFAULT];
9222 return (char_u *)NULL;
9223}
9224#endif
9225
Bram Moolenaar071d4272004-06-13 20:20:40 +00009226/*
9227 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9228 */
9229 static int
9230find_key_option(arg)
9231 char_u *arg;
9232{
9233 int key;
9234 int modifiers;
9235
9236 /*
9237 * Don't use get_special_key_code() for t_xx, we don't want it to call
9238 * add_termcap_entry().
9239 */
9240 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9241 key = TERMCAP2KEY(arg[2], arg[3]);
9242 else
9243 {
9244 --arg; /* put arg at the '<' */
9245 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009246 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009247 if (modifiers) /* can't handle modifiers here */
9248 key = 0;
9249 }
9250 return key;
9251}
9252
9253/*
9254 * if 'all' == 0: show changed options
9255 * if 'all' == 1: show all normal options
9256 * if 'all' == 2: show all terminal options
9257 */
9258 static void
9259showoptions(all, opt_flags)
9260 int all;
9261 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9262{
9263 struct vimoption *p;
9264 int col;
9265 int isterm;
9266 char_u *varp;
9267 struct vimoption **items;
9268 int item_count;
9269 int run;
9270 int row, rows;
9271 int cols;
9272 int i;
9273 int len;
9274
9275#define INC 20
9276#define GAP 3
9277
9278 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9279 PARAM_COUNT));
9280 if (items == NULL)
9281 return;
9282
9283 /* Highlight title */
9284 if (all == 2)
9285 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9286 else if (opt_flags & OPT_GLOBAL)
9287 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9288 else if (opt_flags & OPT_LOCAL)
9289 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9290 else
9291 MSG_PUTS_TITLE(_("\n--- Options ---"));
9292
9293 /*
9294 * do the loop two times:
9295 * 1. display the short items
9296 * 2. display the long items (only strings and numbers)
9297 */
9298 for (run = 1; run <= 2 && !got_int; ++run)
9299 {
9300 /*
9301 * collect the items in items[]
9302 */
9303 item_count = 0;
9304 for (p = &options[0]; p->fullname != NULL; p++)
9305 {
9306 varp = NULL;
9307 isterm = istermoption(p);
9308 if (opt_flags != 0)
9309 {
9310 if (p->indir != PV_NONE && !isterm)
9311 varp = get_varp_scope(p, opt_flags);
9312 }
9313 else
9314 varp = get_varp(p);
9315 if (varp != NULL
9316 && ((all == 2 && isterm)
9317 || (all == 1 && !isterm)
9318 || (all == 0 && !optval_default(p, varp))))
9319 {
9320 if (p->flags & P_BOOL)
9321 len = 1; /* a toggle option fits always */
9322 else
9323 {
9324 option_value2string(p, opt_flags);
9325 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9326 }
9327 if ((len <= INC - GAP && run == 1) ||
9328 (len > INC - GAP && run == 2))
9329 items[item_count++] = p;
9330 }
9331 }
9332
9333 /*
9334 * display the items
9335 */
9336 if (run == 1)
9337 {
9338 cols = (Columns + GAP - 3) / INC;
9339 if (cols == 0)
9340 cols = 1;
9341 rows = (item_count + cols - 1) / cols;
9342 }
9343 else /* run == 2 */
9344 rows = item_count;
9345 for (row = 0; row < rows && !got_int; ++row)
9346 {
9347 msg_putchar('\n'); /* go to next line */
9348 if (got_int) /* 'q' typed in more */
9349 break;
9350 col = 0;
9351 for (i = row; i < item_count; i += rows)
9352 {
9353 msg_col = col; /* make columns */
9354 showoneopt(items[i], opt_flags);
9355 col += INC;
9356 }
9357 out_flush();
9358 ui_breakcheck();
9359 }
9360 }
9361 vim_free(items);
9362}
9363
9364/*
9365 * Return TRUE if option "p" has its default value.
9366 */
9367 static int
9368optval_default(p, varp)
9369 struct vimoption *p;
9370 char_u *varp;
9371{
9372 int dvi;
9373
9374 if (varp == NULL)
9375 return TRUE; /* hidden option is always at default */
9376 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9377 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009378 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009379 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009380 /* the cast to long is required for Manx C, long_i is
9381 * needed for MSVC */
9382 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009383 /* P_STRING */
9384 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9385}
9386
9387/*
9388 * showoneopt: show the value of one option
9389 * must not be called with a hidden option!
9390 */
9391 static void
9392showoneopt(p, opt_flags)
9393 struct vimoption *p;
9394 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9395{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009396 char_u *varp;
9397 int save_silent = silent_mode;
9398
9399 silent_mode = FALSE;
9400 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009401
9402 varp = get_varp_scope(p, opt_flags);
9403
9404 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9405 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9406 ? !curbufIsChanged() : !*(int *)varp))
9407 MSG_PUTS("no");
9408 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9409 MSG_PUTS("--");
9410 else
9411 MSG_PUTS(" ");
9412 MSG_PUTS(p->fullname);
9413 if (!(p->flags & P_BOOL))
9414 {
9415 msg_putchar('=');
9416 /* put value string in NameBuff */
9417 option_value2string(p, opt_flags);
9418 msg_outtrans(NameBuff);
9419 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009420
9421 silent_mode = save_silent;
9422 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423}
9424
9425/*
9426 * Write modified options as ":set" commands to a file.
9427 *
9428 * There are three values for "opt_flags":
9429 * OPT_GLOBAL: Write global option values and fresh values of
9430 * buffer-local options (used for start of a session
9431 * file).
9432 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9433 * curwin (used for a vimrc file).
9434 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9435 * and local values for window-local options of
9436 * curwin. Local values are also written when at the
9437 * default value, because a modeline or autocommand
9438 * may have set them when doing ":edit file" and the
9439 * user has set them back at the default or fresh
9440 * value.
9441 * When "local_only" is TRUE, don't write fresh
9442 * values, only local values (for ":mkview").
9443 * (fresh value = value used for a new buffer or window for a local option).
9444 *
9445 * Return FAIL on error, OK otherwise.
9446 */
9447 int
9448makeset(fd, opt_flags, local_only)
9449 FILE *fd;
9450 int opt_flags;
9451 int local_only;
9452{
9453 struct vimoption *p;
9454 char_u *varp; /* currently used value */
9455 char_u *varp_fresh; /* local value */
9456 char_u *varp_local = NULL; /* fresh value */
9457 char *cmd;
9458 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009459 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009460
9461 /*
9462 * The options that don't have a default (terminal name, columns, lines)
9463 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009464 * Do the loop over "options[]" twice: once for options with the
9465 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009466 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009467 for (pri = 1; pri >= 0; --pri)
9468 {
9469 for (p = &options[0]; !istermoption(p); p++)
9470 if (!(p->flags & P_NO_MKRC)
9471 && !istermoption(p)
9472 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009473 {
9474 /* skip global option when only doing locals */
9475 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9476 continue;
9477
9478 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9479 * file, they are always buffer-specific. */
9480 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9481 continue;
9482
9483 /* Global values are only written when not at the default value. */
9484 varp = get_varp_scope(p, opt_flags);
9485 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9486 continue;
9487
9488 round = 2;
9489 if (p->indir != PV_NONE)
9490 {
9491 if (p->var == VAR_WIN)
9492 {
9493 /* skip window-local option when only doing globals */
9494 if (!(opt_flags & OPT_LOCAL))
9495 continue;
9496 /* When fresh value of window-local option is not at the
9497 * default, need to write it too. */
9498 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9499 {
9500 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9501 if (!optval_default(p, varp_fresh))
9502 {
9503 round = 1;
9504 varp_local = varp;
9505 varp = varp_fresh;
9506 }
9507 }
9508 }
9509 }
9510
9511 /* Round 1: fresh value for window-local options.
9512 * Round 2: other values */
9513 for ( ; round <= 2; varp = varp_local, ++round)
9514 {
9515 if (round == 1 || (opt_flags & OPT_GLOBAL))
9516 cmd = "set";
9517 else
9518 cmd = "setlocal";
9519
9520 if (p->flags & P_BOOL)
9521 {
9522 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9523 return FAIL;
9524 }
9525 else if (p->flags & P_NUM)
9526 {
9527 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9528 return FAIL;
9529 }
9530 else /* P_STRING */
9531 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009532#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9533 int do_endif = FALSE;
9534
Bram Moolenaar071d4272004-06-13 20:20:40 +00009535 /* Don't set 'syntax' and 'filetype' again if the value is
9536 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009537 if (
9538# if defined(FEAT_SYN_HL)
9539 p->indir == PV_SYN
9540# if defined(FEAT_AUTOCMD)
9541 ||
9542# endif
9543# endif
9544# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009545 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009546# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009547 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009548 {
9549 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9550 *(char_u **)(varp)) < 0
9551 || put_eol(fd) < 0)
9552 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009553 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009554 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009555#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009556 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9557 (p->flags & P_EXPAND) != 0) == FAIL)
9558 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009559#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9560 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009561 {
9562 if (put_line(fd, "endif") == FAIL)
9563 return FAIL;
9564 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009565#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009566 }
9567 }
9568 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009569 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009570 return OK;
9571}
9572
9573#if defined(FEAT_FOLDING) || defined(PROTO)
9574/*
9575 * Generate set commands for the local fold options only. Used when
9576 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9577 */
9578 int
9579makefoldset(fd)
9580 FILE *fd;
9581{
9582 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9583# ifdef FEAT_EVAL
9584 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9585 == FAIL
9586# endif
9587 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9588 == FAIL
9589 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9590 == FAIL
9591 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9592 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9593 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9594 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9595 )
9596 return FAIL;
9597
9598 return OK;
9599}
9600#endif
9601
9602 static int
9603put_setstring(fd, cmd, name, valuep, expand)
9604 FILE *fd;
9605 char *cmd;
9606 char *name;
9607 char_u **valuep;
9608 int expand;
9609{
9610 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009611 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009612
9613 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9614 return FAIL;
9615 if (*valuep != NULL)
9616 {
9617 /* Output 'pastetoggle' as key names. For other
9618 * options some characters have to be escaped with
9619 * CTRL-V or backslash */
9620 if (valuep == &p_pt)
9621 {
9622 s = *valuep;
9623 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009624 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009625 return FAIL;
9626 }
9627 else if (expand)
9628 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009629 buf = alloc(MAXPATHL);
9630 if (buf == NULL)
9631 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009632 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9633 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009634 {
9635 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009636 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009637 }
9638 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009639 }
9640 else if (put_escstr(fd, *valuep, 2) == FAIL)
9641 return FAIL;
9642 }
9643 if (put_eol(fd) < 0)
9644 return FAIL;
9645 return OK;
9646}
9647
9648 static int
9649put_setnum(fd, cmd, name, valuep)
9650 FILE *fd;
9651 char *cmd;
9652 char *name;
9653 long *valuep;
9654{
9655 long wc;
9656
9657 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9658 return FAIL;
9659 if (wc_use_keyname((char_u *)valuep, &wc))
9660 {
9661 /* print 'wildchar' and 'wildcharm' as a key name */
9662 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9663 return FAIL;
9664 }
9665 else if (fprintf(fd, "%ld", *valuep) < 0)
9666 return FAIL;
9667 if (put_eol(fd) < 0)
9668 return FAIL;
9669 return OK;
9670}
9671
9672 static int
9673put_setbool(fd, cmd, name, value)
9674 FILE *fd;
9675 char *cmd;
9676 char *name;
9677 int value;
9678{
Bram Moolenaar893de922007-10-02 18:40:57 +00009679 if (value < 0) /* global/local option using global value */
9680 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009681 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9682 || put_eol(fd) < 0)
9683 return FAIL;
9684 return OK;
9685}
9686
9687/*
9688 * Clear all the terminal options.
9689 * If the option has been allocated, free the memory.
9690 * Terminal options are never hidden or indirect.
9691 */
9692 void
9693clear_termoptions()
9694{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009695 /*
9696 * Reset a few things before clearing the old options. This may cause
9697 * outputting a few things that the terminal doesn't understand, but the
9698 * screen will be cleared later, so this is OK.
9699 */
9700#ifdef FEAT_MOUSE_TTY
9701 mch_setmouse(FALSE); /* switch mouse off */
9702#endif
9703#ifdef FEAT_TITLE
9704 mch_restore_title(3); /* restore window titles */
9705#endif
9706#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9707 /* When starting the GUI close the display opened for the clipboard.
9708 * After restoring the title, because that will need the display. */
9709 if (gui.starting)
9710 clear_xterm_clip();
9711#endif
9712#ifdef WIN3264
9713 /*
9714 * Check if this is allowed now.
9715 */
9716 if (can_end_termcap_mode(FALSE) == TRUE)
9717#endif
9718 stoptermcap(); /* stop termcap mode */
9719
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009720 free_termoptions();
9721}
9722
9723 void
9724free_termoptions()
9725{
9726 struct vimoption *p;
9727
Bram Moolenaar071d4272004-06-13 20:20:40 +00009728 for (p = &options[0]; p->fullname != NULL; p++)
9729 if (istermoption(p))
9730 {
9731 if (p->flags & P_ALLOCED)
9732 free_string_option(*(char_u **)(p->var));
9733 if (p->flags & P_DEF_ALLOCED)
9734 free_string_option(p->def_val[VI_DEFAULT]);
9735 *(char_u **)(p->var) = empty_option;
9736 p->def_val[VI_DEFAULT] = empty_option;
9737 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9738 }
9739 clear_termcodes();
9740}
9741
9742/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009743 * Free the string for one term option, if it was allocated.
9744 * Set the string to empty_option and clear allocated flag.
9745 * "var" points to the option value.
9746 */
9747 void
9748free_one_termoption(var)
9749 char_u *var;
9750{
9751 struct vimoption *p;
9752
9753 for (p = &options[0]; p->fullname != NULL; p++)
9754 if (p->var == var)
9755 {
9756 if (p->flags & P_ALLOCED)
9757 free_string_option(*(char_u **)(p->var));
9758 *(char_u **)(p->var) = empty_option;
9759 p->flags &= ~P_ALLOCED;
9760 break;
9761 }
9762}
9763
9764/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009765 * Set the terminal option defaults to the current value.
9766 * Used after setting the terminal name.
9767 */
9768 void
9769set_term_defaults()
9770{
9771 struct vimoption *p;
9772
9773 for (p = &options[0]; p->fullname != NULL; p++)
9774 {
9775 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9776 {
9777 if (p->flags & P_DEF_ALLOCED)
9778 {
9779 free_string_option(p->def_val[VI_DEFAULT]);
9780 p->flags &= ~P_DEF_ALLOCED;
9781 }
9782 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9783 if (p->flags & P_ALLOCED)
9784 {
9785 p->flags |= P_DEF_ALLOCED;
9786 p->flags &= ~P_ALLOCED; /* don't free the value now */
9787 }
9788 }
9789 }
9790}
9791
9792/*
9793 * return TRUE if 'p' starts with 't_'
9794 */
9795 static int
9796istermoption(p)
9797 struct vimoption *p;
9798{
9799 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9800}
9801
9802/*
9803 * Compute columns for ruler and shown command. 'sc_col' is also used to
9804 * decide what the maximum length of a message on the status line can be.
9805 * If there is a status line for the last window, 'sc_col' is independent
9806 * of 'ru_col'.
9807 */
9808
9809#define COL_RULER 17 /* columns needed by standard ruler */
9810
9811 void
9812comp_col()
9813{
9814#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9815 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9816
9817 sc_col = 0;
9818 ru_col = 0;
9819 if (p_ru)
9820 {
9821#ifdef FEAT_STL_OPT
9822 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9823#else
9824 ru_col = COL_RULER + 1;
9825#endif
9826 /* no last status line, adjust sc_col */
9827 if (!last_has_status)
9828 sc_col = ru_col;
9829 }
9830 if (p_sc)
9831 {
9832 sc_col += SHOWCMD_COLS;
9833 if (!p_ru || last_has_status) /* no need for separating space */
9834 ++sc_col;
9835 }
9836 sc_col = Columns - sc_col;
9837 ru_col = Columns - ru_col;
9838 if (sc_col <= 0) /* screen too narrow, will become a mess */
9839 sc_col = 1;
9840 if (ru_col <= 0)
9841 ru_col = 1;
9842#else
9843 sc_col = Columns;
9844 ru_col = Columns;
9845#endif
9846}
9847
9848/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009849 * Unset local option value, similar to ":set opt<".
9850 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009851 void
9852unset_global_local_option(name, from)
9853 char_u *name;
9854 void *from;
9855{
9856 struct vimoption *p;
9857 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009858 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009859
9860 opt_idx = findoption(name);
9861 p = &(options[opt_idx]);
9862
9863 switch ((int)p->indir)
9864 {
9865 /* global option with local value: use local value if it's been set */
9866 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009867 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009868 break;
9869 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009870 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009871 break;
9872 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009873 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009874 break;
9875 case PV_AR:
9876 buf->b_p_ar = -1;
9877 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009878 case PV_BKC:
9879 clear_string_option(&buf->b_p_bkc);
9880 buf->b_bkc_flags = 0;
9881 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009882 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009883 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009884 break;
9885#ifdef FEAT_FIND_ID
9886 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009887 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009888 break;
9889 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009890 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009891 break;
9892#endif
9893#ifdef FEAT_INS_EXPAND
9894 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009895 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009896 break;
9897 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009898 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009899 break;
9900#endif
9901#ifdef FEAT_QUICKFIX
9902 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009903 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009904 break;
9905 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009906 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009907 break;
9908 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009909 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009910 break;
9911#endif
9912#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9913 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009914 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009915 break;
9916#endif
9917#if defined(FEAT_CRYPT)
9918 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009919 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009920 break;
9921#endif
9922#ifdef FEAT_STL_OPT
9923 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009924 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009925 break;
9926#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009927 case PV_UL:
9928 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9929 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009930#ifdef FEAT_LISP
9931 case PV_LW:
9932 clear_string_option(&buf->b_p_lw);
9933 break;
9934#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009935 }
9936}
9937
9938/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009939 * Get pointer to option variable, depending on local or global scope.
9940 */
9941 static char_u *
9942get_varp_scope(p, opt_flags)
9943 struct vimoption *p;
9944 int opt_flags;
9945{
9946 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9947 {
9948 if (p->var == VAR_WIN)
9949 return (char_u *)GLOBAL_WO(get_varp(p));
9950 return p->var;
9951 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009952 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009953 {
9954 switch ((int)p->indir)
9955 {
9956#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009957 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9958 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9959 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009960#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009961 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9962 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9963 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009964 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009965 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009967 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9968 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009969#endif
9970#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009971 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9972 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009974#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9975 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9976#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009977#if defined(FEAT_CRYPT)
9978 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9979#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009980#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009981 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009982#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009983 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009984#ifdef FEAT_LISP
9985 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9986#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009987 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009988 }
9989 return NULL; /* "cannot happen" */
9990 }
9991 return get_varp(p);
9992}
9993
9994/*
9995 * Get pointer to option variable.
9996 */
9997 static char_u *
9998get_varp(p)
9999 struct vimoption *p;
10000{
10001 /* hidden option, always return NULL */
10002 if (p->var == NULL)
10003 return NULL;
10004
10005 switch ((int)p->indir)
10006 {
10007 case PV_NONE: return p->var;
10008
10009 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010010 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010011 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010012 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010013 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010014 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010015 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010016 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010017 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010018 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010019 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010020 case PV_BKC: return *curbuf->b_p_bkc != NUL
10021 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010022#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010023 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010024 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010025 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010026 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10027#endif
10028#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010029 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010030 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010031 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010032 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10033#endif
10034#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010035 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010036 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010037 case PV_GP: return *curbuf->b_p_gp != NUL
10038 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10039 case PV_MP: return *curbuf->b_p_mp != NUL
10040 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010041#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010042#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10043 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10044 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10045#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010046#if defined(FEAT_CRYPT)
10047 case PV_CM: return *curbuf->b_p_cm != NUL
10048 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10049#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010050#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010051 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010052 ? (char_u *)&(curwin->w_p_stl) : p->var;
10053#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010054 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10055 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010056#ifdef FEAT_LISP
10057 case PV_LW: return *curbuf->b_p_lw != NUL
10058 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10059#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010060
10061#ifdef FEAT_ARABIC
10062 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10063#endif
10064 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010065#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010066 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10067#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010068#ifdef FEAT_SYN_HL
10069 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10070 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010071 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010072#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010073#ifdef FEAT_DIFF
10074 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10075#endif
10076#ifdef FEAT_FOLDING
10077 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10078 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10079 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10080 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10081 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10082 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10083 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10084# ifdef FEAT_EVAL
10085 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10086 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10087# endif
10088 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10089#endif
10090 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010091 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010092#ifdef FEAT_LINEBREAK
10093 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10094#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010095#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010096 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10097#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010098#ifdef FEAT_VERTSPLIT
10099 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010101#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10102 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10103#endif
10104#ifdef FEAT_RIGHTLEFT
10105 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10106 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10107#endif
10108 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10109 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10110#ifdef FEAT_LINEBREAK
10111 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010112 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10113 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010114#endif
10115#ifdef FEAT_SCROLLBIND
10116 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10117#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010118#ifdef FEAT_CURSORBIND
10119 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10120#endif
10121#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010122 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10123 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125
10126 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10127 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10128#ifdef FEAT_MBYTE
10129 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10130#endif
10131#if defined(FEAT_QUICKFIX)
10132 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10133 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10134#endif
10135 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10136 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10137#ifdef FEAT_CINDENT
10138 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10139 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10140 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10141#endif
10142#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10143 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10144#endif
10145#ifdef FEAT_COMMENTS
10146 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10147#endif
10148#ifdef FEAT_FOLDING
10149 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10150#endif
10151#ifdef FEAT_INS_EXPAND
10152 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10153#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010154#ifdef FEAT_COMPL_FUNC
10155 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010156 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010158 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10159 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10160#ifdef FEAT_MBYTE
10161 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10162#endif
10163 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10164#ifdef FEAT_AUTOCMD
10165 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10166#endif
10167 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010168 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10170 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10171 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10172 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10173#ifdef FEAT_FIND_ID
10174# ifdef FEAT_EVAL
10175 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10176# endif
10177#endif
10178#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10179 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10180 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10181#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010182#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010183 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10184#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185#ifdef FEAT_CRYPT
10186 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10187#endif
10188#ifdef FEAT_LISP
10189 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10190#endif
10191 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10192 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10193 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10194 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10195 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010197#ifdef FEAT_TEXTOBJ
10198 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10199#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10201#ifdef FEAT_SMARTINDENT
10202 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10203#endif
10204#ifndef SHORT_FNAME
10205 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10206#endif
10207 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10208#ifdef FEAT_SEARCHPATH
10209 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10210#endif
10211 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10212#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010213 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010214 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10215#endif
10216#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010217 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10218 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10219 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220#endif
10221 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10222 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10223 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10224 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010225#ifdef FEAT_PERSISTENT_UNDO
10226 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10227#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10229#ifdef FEAT_KEYMAP
10230 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10231#endif
10232 default: EMSG(_("E356: get_varp ERROR"));
10233 }
10234 /* always return a valid pointer to avoid a crash! */
10235 return (char_u *)&(curbuf->b_p_wm);
10236}
10237
10238/*
10239 * Get the value of 'equalprg', either the buffer-local one or the global one.
10240 */
10241 char_u *
10242get_equalprg()
10243{
10244 if (*curbuf->b_p_ep == NUL)
10245 return p_ep;
10246 return curbuf->b_p_ep;
10247}
10248
10249#if defined(FEAT_WINDOWS) || defined(PROTO)
10250/*
10251 * Copy options from one window to another.
10252 * Used when splitting a window.
10253 */
10254 void
10255win_copy_options(wp_from, wp_to)
10256 win_T *wp_from;
10257 win_T *wp_to;
10258{
10259 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10260 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10261# ifdef FEAT_RIGHTLEFT
10262# ifdef FEAT_FKMAP
10263 /* Is this right? */
10264 wp_to->w_farsi = wp_from->w_farsi;
10265# endif
10266# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010267#if defined(FEAT_LINEBREAK)
10268 briopt_check(wp_to);
10269#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270}
10271#endif
10272
10273/*
10274 * Copy the options from one winopt_T to another.
10275 * Doesn't free the old option values in "to", use clear_winopt() for that.
10276 * The 'scroll' option is not copied, because it depends on the window height.
10277 * The 'previewwindow' option is reset, there can be only one preview window.
10278 */
10279 void
10280copy_winopt(from, to)
10281 winopt_T *from;
10282 winopt_T *to;
10283{
10284#ifdef FEAT_ARABIC
10285 to->wo_arab = from->wo_arab;
10286#endif
10287 to->wo_list = from->wo_list;
10288 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010289 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010290#ifdef FEAT_LINEBREAK
10291 to->wo_nuw = from->wo_nuw;
10292#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010293#ifdef FEAT_RIGHTLEFT
10294 to->wo_rl = from->wo_rl;
10295 to->wo_rlc = vim_strsave(from->wo_rlc);
10296#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010297#ifdef FEAT_STL_OPT
10298 to->wo_stl = vim_strsave(from->wo_stl);
10299#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010301#ifdef FEAT_DIFF
10302 to->wo_wrap_save = from->wo_wrap_save;
10303#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010304#ifdef FEAT_LINEBREAK
10305 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010306 to->wo_bri = from->wo_bri;
10307 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010308#endif
10309#ifdef FEAT_SCROLLBIND
10310 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010311 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010313#ifdef FEAT_CURSORBIND
10314 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010315 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010316#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010317#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010318 to->wo_spell = from->wo_spell;
10319#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010320#ifdef FEAT_SYN_HL
10321 to->wo_cuc = from->wo_cuc;
10322 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010323 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010324#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010325#ifdef FEAT_DIFF
10326 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010327 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010328#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010329#ifdef FEAT_CONCEAL
10330 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010331 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010332#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010333#ifdef FEAT_FOLDING
10334 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010335 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010336 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010337 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010338 to->wo_fdi = vim_strsave(from->wo_fdi);
10339 to->wo_fml = from->wo_fml;
10340 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010341 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010343 to->wo_fdm_save = from->wo_diff_saved
10344 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345 to->wo_fdn = from->wo_fdn;
10346# ifdef FEAT_EVAL
10347 to->wo_fde = vim_strsave(from->wo_fde);
10348 to->wo_fdt = vim_strsave(from->wo_fdt);
10349# endif
10350 to->wo_fmr = vim_strsave(from->wo_fmr);
10351#endif
10352 check_winopt(to); /* don't want NULL pointers */
10353}
10354
10355/*
10356 * Check string options in a window for a NULL value.
10357 */
10358 void
10359check_win_options(win)
10360 win_T *win;
10361{
10362 check_winopt(&win->w_onebuf_opt);
10363 check_winopt(&win->w_allbuf_opt);
10364}
10365
10366/*
10367 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10368 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010369 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010371 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010372{
10373#ifdef FEAT_FOLDING
10374 check_string_option(&wop->wo_fdi);
10375 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010376 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010377# ifdef FEAT_EVAL
10378 check_string_option(&wop->wo_fde);
10379 check_string_option(&wop->wo_fdt);
10380# endif
10381 check_string_option(&wop->wo_fmr);
10382#endif
10383#ifdef FEAT_RIGHTLEFT
10384 check_string_option(&wop->wo_rlc);
10385#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010386#ifdef FEAT_STL_OPT
10387 check_string_option(&wop->wo_stl);
10388#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010389#ifdef FEAT_SYN_HL
10390 check_string_option(&wop->wo_cc);
10391#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010392#ifdef FEAT_CONCEAL
10393 check_string_option(&wop->wo_cocu);
10394#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010395#ifdef FEAT_LINEBREAK
10396 check_string_option(&wop->wo_briopt);
10397#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398}
10399
10400/*
10401 * Free the allocated memory inside a winopt_T.
10402 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403 void
10404clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010405 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406{
10407#ifdef FEAT_FOLDING
10408 clear_string_option(&wop->wo_fdi);
10409 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010410 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010411# ifdef FEAT_EVAL
10412 clear_string_option(&wop->wo_fde);
10413 clear_string_option(&wop->wo_fdt);
10414# endif
10415 clear_string_option(&wop->wo_fmr);
10416#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010417#ifdef FEAT_LINEBREAK
10418 clear_string_option(&wop->wo_briopt);
10419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420#ifdef FEAT_RIGHTLEFT
10421 clear_string_option(&wop->wo_rlc);
10422#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010423#ifdef FEAT_STL_OPT
10424 clear_string_option(&wop->wo_stl);
10425#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010426#ifdef FEAT_SYN_HL
10427 clear_string_option(&wop->wo_cc);
10428#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010429#ifdef FEAT_CONCEAL
10430 clear_string_option(&wop->wo_cocu);
10431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432}
10433
10434/*
10435 * Copy global option values to local options for one buffer.
10436 * Used when creating a new buffer and sometimes when entering a buffer.
10437 * flags:
10438 * BCO_ENTER We will enter the buf buffer.
10439 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10440 * appropriate.
10441 * BCO_NOHELP Don't copy the values to a help buffer.
10442 */
10443 void
10444buf_copy_options(buf, flags)
10445 buf_T *buf;
10446 int flags;
10447{
10448 int should_copy = TRUE;
10449 char_u *save_p_isk = NULL; /* init for GCC */
10450 int dont_do_help;
10451 int did_isk = FALSE;
10452
10453 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010454 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010455 */
10456 if (buf == NULL || !buf_valid(buf))
10457 return;
10458
10459 /*
10460 * Skip this when the option defaults have not been set yet. Happens when
10461 * main() allocates the first buffer.
10462 */
10463 if (p_cpo != NULL)
10464 {
10465 /*
10466 * Always copy when entering and 'cpo' contains 'S'.
10467 * Don't copy when already initialized.
10468 * Don't copy when 'cpo' contains 's' and not entering.
10469 * 'S' BCO_ENTER initialized 's' should_copy
10470 * yes yes X X TRUE
10471 * yes no yes X FALSE
10472 * no X yes X FALSE
10473 * X no no yes FALSE
10474 * X no no no TRUE
10475 * no yes no X TRUE
10476 */
10477 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10478 && (buf->b_p_initialized
10479 || (!(flags & BCO_ENTER)
10480 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10481 should_copy = FALSE;
10482
10483 if (should_copy || (flags & BCO_ALWAYS))
10484 {
10485 /* Don't copy the options specific to a help buffer when
10486 * BCO_NOHELP is given or the options were initialized already
10487 * (jumping back to a help file with CTRL-T or CTRL-O) */
10488 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10489 || buf->b_p_initialized;
10490 if (dont_do_help) /* don't free b_p_isk */
10491 {
10492 save_p_isk = buf->b_p_isk;
10493 buf->b_p_isk = NULL;
10494 }
10495 /*
10496 * Always free the allocated strings.
10497 * If not already initialized, set 'readonly' and copy 'fileformat'.
10498 */
10499 if (!buf->b_p_initialized)
10500 {
10501 free_buf_options(buf, TRUE);
10502 buf->b_p_ro = FALSE; /* don't copy readonly */
10503 buf->b_p_tx = p_tx;
10504#ifdef FEAT_MBYTE
10505 buf->b_p_fenc = vim_strsave(p_fenc);
10506#endif
10507 buf->b_p_ff = vim_strsave(p_ff);
10508#if defined(FEAT_QUICKFIX)
10509 buf->b_p_bh = empty_option;
10510 buf->b_p_bt = empty_option;
10511#endif
10512 }
10513 else
10514 free_buf_options(buf, FALSE);
10515
10516 buf->b_p_ai = p_ai;
10517 buf->b_p_ai_nopaste = p_ai_nopaste;
10518 buf->b_p_sw = p_sw;
10519 buf->b_p_tw = p_tw;
10520 buf->b_p_tw_nopaste = p_tw_nopaste;
10521 buf->b_p_tw_nobin = p_tw_nobin;
10522 buf->b_p_wm = p_wm;
10523 buf->b_p_wm_nopaste = p_wm_nopaste;
10524 buf->b_p_wm_nobin = p_wm_nobin;
10525 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010526#ifdef FEAT_MBYTE
10527 buf->b_p_bomb = p_bomb;
10528#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529 buf->b_p_et = p_et;
10530 buf->b_p_et_nobin = p_et_nobin;
10531 buf->b_p_ml = p_ml;
10532 buf->b_p_ml_nobin = p_ml_nobin;
10533 buf->b_p_inf = p_inf;
10534 buf->b_p_swf = p_swf;
10535#ifdef FEAT_INS_EXPAND
10536 buf->b_p_cpt = vim_strsave(p_cpt);
10537#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010538#ifdef FEAT_COMPL_FUNC
10539 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010540 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010541#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 buf->b_p_sts = p_sts;
10543 buf->b_p_sts_nopaste = p_sts_nopaste;
10544#ifndef SHORT_FNAME
10545 buf->b_p_sn = p_sn;
10546#endif
10547#ifdef FEAT_COMMENTS
10548 buf->b_p_com = vim_strsave(p_com);
10549#endif
10550#ifdef FEAT_FOLDING
10551 buf->b_p_cms = vim_strsave(p_cms);
10552#endif
10553 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010554 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555 buf->b_p_nf = vim_strsave(p_nf);
10556 buf->b_p_mps = vim_strsave(p_mps);
10557#ifdef FEAT_SMARTINDENT
10558 buf->b_p_si = p_si;
10559#endif
10560 buf->b_p_ci = p_ci;
10561#ifdef FEAT_CINDENT
10562 buf->b_p_cin = p_cin;
10563 buf->b_p_cink = vim_strsave(p_cink);
10564 buf->b_p_cino = vim_strsave(p_cino);
10565#endif
10566#ifdef FEAT_AUTOCMD
10567 /* Don't copy 'filetype', it must be detected */
10568 buf->b_p_ft = empty_option;
10569#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010570 buf->b_p_pi = p_pi;
10571#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10572 buf->b_p_cinw = vim_strsave(p_cinw);
10573#endif
10574#ifdef FEAT_LISP
10575 buf->b_p_lisp = p_lisp;
10576#endif
10577#ifdef FEAT_SYN_HL
10578 /* Don't copy 'syntax', it must be set */
10579 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010580 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010581#endif
10582#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010583 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010584 (void)compile_cap_prog(&buf->b_s);
10585 buf->b_s.b_p_spf = vim_strsave(p_spf);
10586 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587#endif
10588#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10589 buf->b_p_inde = vim_strsave(p_inde);
10590 buf->b_p_indk = vim_strsave(p_indk);
10591#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010592#if defined(FEAT_EVAL)
10593 buf->b_p_fex = vim_strsave(p_fex);
10594#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595#ifdef FEAT_CRYPT
10596 buf->b_p_key = vim_strsave(p_key);
10597#endif
10598#ifdef FEAT_SEARCHPATH
10599 buf->b_p_sua = vim_strsave(p_sua);
10600#endif
10601#ifdef FEAT_KEYMAP
10602 buf->b_p_keymap = vim_strsave(p_keymap);
10603 buf->b_kmap_state |= KEYMAP_INIT;
10604#endif
10605 /* This isn't really an option, but copying the langmap and IME
10606 * state from the current buffer is better than resetting it. */
10607 buf->b_p_iminsert = p_iminsert;
10608 buf->b_p_imsearch = p_imsearch;
10609
10610 /* options that are normally global but also have a local value
10611 * are not copied, start using the global value */
10612 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010613 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010614 buf->b_p_bkc = empty_option;
10615 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616#ifdef FEAT_QUICKFIX
10617 buf->b_p_gp = empty_option;
10618 buf->b_p_mp = empty_option;
10619 buf->b_p_efm = empty_option;
10620#endif
10621 buf->b_p_ep = empty_option;
10622 buf->b_p_kp = empty_option;
10623 buf->b_p_path = empty_option;
10624 buf->b_p_tags = empty_option;
10625#ifdef FEAT_FIND_ID
10626 buf->b_p_def = empty_option;
10627 buf->b_p_inc = empty_option;
10628# ifdef FEAT_EVAL
10629 buf->b_p_inex = vim_strsave(p_inex);
10630# endif
10631#endif
10632#ifdef FEAT_INS_EXPAND
10633 buf->b_p_dict = empty_option;
10634 buf->b_p_tsr = empty_option;
10635#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010636#ifdef FEAT_TEXTOBJ
10637 buf->b_p_qe = vim_strsave(p_qe);
10638#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010639#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10640 buf->b_p_bexpr = empty_option;
10641#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010642#if defined(FEAT_CRYPT)
10643 buf->b_p_cm = empty_option;
10644#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010645#ifdef FEAT_PERSISTENT_UNDO
10646 buf->b_p_udf = p_udf;
10647#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010648#ifdef FEAT_LISP
10649 buf->b_p_lw = empty_option;
10650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010651
10652 /*
10653 * Don't copy the options set by ex_help(), use the saved values,
10654 * when going from a help buffer to a non-help buffer.
10655 * Don't touch these at all when BCO_NOHELP is used and going from
10656 * or to a help buffer.
10657 */
10658 if (dont_do_help)
10659 buf->b_p_isk = save_p_isk;
10660 else
10661 {
10662 buf->b_p_isk = vim_strsave(p_isk);
10663 did_isk = TRUE;
10664 buf->b_p_ts = p_ts;
10665 buf->b_help = FALSE;
10666#ifdef FEAT_QUICKFIX
10667 if (buf->b_p_bt[0] == 'h')
10668 clear_string_option(&buf->b_p_bt);
10669#endif
10670 buf->b_p_ma = p_ma;
10671 }
10672 }
10673
10674 /*
10675 * When the options should be copied (ignoring BCO_ALWAYS), set the
10676 * flag that indicates that the options have been initialized.
10677 */
10678 if (should_copy)
10679 buf->b_p_initialized = TRUE;
10680 }
10681
10682 check_buf_options(buf); /* make sure we don't have NULLs */
10683 if (did_isk)
10684 (void)buf_init_chartab(buf, FALSE);
10685}
10686
10687/*
10688 * Reset the 'modifiable' option and its default value.
10689 */
10690 void
10691reset_modifiable()
10692{
10693 int opt_idx;
10694
10695 curbuf->b_p_ma = FALSE;
10696 p_ma = FALSE;
10697 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010698 if (opt_idx >= 0)
10699 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010700}
10701
10702/*
10703 * Set the global value for 'iminsert' to the local value.
10704 */
10705 void
10706set_iminsert_global()
10707{
10708 p_iminsert = curbuf->b_p_iminsert;
10709}
10710
10711/*
10712 * Set the global value for 'imsearch' to the local value.
10713 */
10714 void
10715set_imsearch_global()
10716{
10717 p_imsearch = curbuf->b_p_imsearch;
10718}
10719
10720#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10721static int expand_option_idx = -1;
10722static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10723static int expand_option_flags = 0;
10724
10725 void
10726set_context_in_set_cmd(xp, arg, opt_flags)
10727 expand_T *xp;
10728 char_u *arg;
10729 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10730{
10731 int nextchar;
10732 long_u flags = 0; /* init for GCC */
10733 int opt_idx = 0; /* init for GCC */
10734 char_u *p;
10735 char_u *s;
10736 int is_term_option = FALSE;
10737 int key;
10738
10739 expand_option_flags = opt_flags;
10740
10741 xp->xp_context = EXPAND_SETTINGS;
10742 if (*arg == NUL)
10743 {
10744 xp->xp_pattern = arg;
10745 return;
10746 }
10747 p = arg + STRLEN(arg) - 1;
10748 if (*p == ' ' && *(p - 1) != '\\')
10749 {
10750 xp->xp_pattern = p + 1;
10751 return;
10752 }
10753 while (p > arg)
10754 {
10755 s = p;
10756 /* count number of backslashes before ' ' or ',' */
10757 if (*p == ' ' || *p == ',')
10758 {
10759 while (s > arg && *(s - 1) == '\\')
10760 --s;
10761 }
10762 /* break at a space with an even number of backslashes */
10763 if (*p == ' ' && ((p - s) & 1) == 0)
10764 {
10765 ++p;
10766 break;
10767 }
10768 --p;
10769 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010770 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771 {
10772 xp->xp_context = EXPAND_BOOL_SETTINGS;
10773 p += 2;
10774 }
10775 if (STRNCMP(p, "inv", 3) == 0)
10776 {
10777 xp->xp_context = EXPAND_BOOL_SETTINGS;
10778 p += 3;
10779 }
10780 xp->xp_pattern = arg = p;
10781 if (*arg == '<')
10782 {
10783 while (*p != '>')
10784 if (*p++ == NUL) /* expand terminal option name */
10785 return;
10786 key = get_special_key_code(arg + 1);
10787 if (key == 0) /* unknown name */
10788 {
10789 xp->xp_context = EXPAND_NOTHING;
10790 return;
10791 }
10792 nextchar = *++p;
10793 is_term_option = TRUE;
10794 expand_option_name[2] = KEY2TERMCAP0(key);
10795 expand_option_name[3] = KEY2TERMCAP1(key);
10796 }
10797 else
10798 {
10799 if (p[0] == 't' && p[1] == '_')
10800 {
10801 p += 2;
10802 if (*p != NUL)
10803 ++p;
10804 if (*p == NUL)
10805 return; /* expand option name */
10806 nextchar = *++p;
10807 is_term_option = TRUE;
10808 expand_option_name[2] = p[-2];
10809 expand_option_name[3] = p[-1];
10810 }
10811 else
10812 {
10813 /* Allow * wildcard */
10814 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10815 p++;
10816 if (*p == NUL)
10817 return;
10818 nextchar = *p;
10819 *p = NUL;
10820 opt_idx = findoption(arg);
10821 *p = nextchar;
10822 if (opt_idx == -1 || options[opt_idx].var == NULL)
10823 {
10824 xp->xp_context = EXPAND_NOTHING;
10825 return;
10826 }
10827 flags = options[opt_idx].flags;
10828 if (flags & P_BOOL)
10829 {
10830 xp->xp_context = EXPAND_NOTHING;
10831 return;
10832 }
10833 }
10834 }
10835 /* handle "-=" and "+=" */
10836 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10837 {
10838 ++p;
10839 nextchar = '=';
10840 }
10841 if ((nextchar != '=' && nextchar != ':')
10842 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10843 {
10844 xp->xp_context = EXPAND_UNSUCCESSFUL;
10845 return;
10846 }
10847 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10848 {
10849 xp->xp_context = EXPAND_OLD_SETTING;
10850 if (is_term_option)
10851 expand_option_idx = -1;
10852 else
10853 expand_option_idx = opt_idx;
10854 xp->xp_pattern = p + 1;
10855 return;
10856 }
10857 xp->xp_context = EXPAND_NOTHING;
10858 if (is_term_option || (flags & P_NUM))
10859 return;
10860
10861 xp->xp_pattern = p + 1;
10862
10863 if (flags & P_EXPAND)
10864 {
10865 p = options[opt_idx].var;
10866 if (p == (char_u *)&p_bdir
10867 || p == (char_u *)&p_dir
10868 || p == (char_u *)&p_path
10869 || p == (char_u *)&p_rtp
10870#ifdef FEAT_SEARCHPATH
10871 || p == (char_u *)&p_cdpath
10872#endif
10873#ifdef FEAT_SESSION
10874 || p == (char_u *)&p_vdir
10875#endif
10876 )
10877 {
10878 xp->xp_context = EXPAND_DIRECTORIES;
10879 if (p == (char_u *)&p_path
10880#ifdef FEAT_SEARCHPATH
10881 || p == (char_u *)&p_cdpath
10882#endif
10883 )
10884 xp->xp_backslash = XP_BS_THREE;
10885 else
10886 xp->xp_backslash = XP_BS_ONE;
10887 }
10888 else
10889 {
10890 xp->xp_context = EXPAND_FILES;
10891 /* for 'tags' need three backslashes for a space */
10892 if (p == (char_u *)&p_tags)
10893 xp->xp_backslash = XP_BS_THREE;
10894 else
10895 xp->xp_backslash = XP_BS_ONE;
10896 }
10897 }
10898
10899 /* For an option that is a list of file names, find the start of the
10900 * last file name. */
10901 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10902 {
10903 /* count number of backslashes before ' ' or ',' */
10904 if (*p == ' ' || *p == ',')
10905 {
10906 s = p;
10907 while (s > xp->xp_pattern && *(s - 1) == '\\')
10908 --s;
10909 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10910 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10911 {
10912 xp->xp_pattern = p + 1;
10913 break;
10914 }
10915 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010916
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010917#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010918 /* for 'spellsuggest' start at "file:" */
10919 if (options[opt_idx].var == (char_u *)&p_sps
10920 && STRNCMP(p, "file:", 5) == 0)
10921 {
10922 xp->xp_pattern = p + 5;
10923 break;
10924 }
10925#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010926 }
10927
10928 return;
10929}
10930
10931 int
10932ExpandSettings(xp, regmatch, num_file, file)
10933 expand_T *xp;
10934 regmatch_T *regmatch;
10935 int *num_file;
10936 char_u ***file;
10937{
10938 int num_normal = 0; /* Nr of matching non-term-code settings */
10939 int num_term = 0; /* Nr of matching terminal code settings */
10940 int opt_idx;
10941 int match;
10942 int count = 0;
10943 char_u *str;
10944 int loop;
10945 int is_term_opt;
10946 char_u name_buf[MAX_KEY_NAME_LEN];
10947 static char *(names[]) = {"all", "termcap"};
10948 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10949
10950 /* do this loop twice:
10951 * loop == 0: count the number of matching options
10952 * loop == 1: copy the matching options into allocated memory
10953 */
10954 for (loop = 0; loop <= 1; ++loop)
10955 {
10956 regmatch->rm_ic = ic;
10957 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10958 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010959 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10960 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010961 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10962 {
10963 if (loop == 0)
10964 num_normal++;
10965 else
10966 (*file)[count++] = vim_strsave((char_u *)names[match]);
10967 }
10968 }
10969 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10970 opt_idx++)
10971 {
10972 if (options[opt_idx].var == NULL)
10973 continue;
10974 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10975 && !(options[opt_idx].flags & P_BOOL))
10976 continue;
10977 is_term_opt = istermoption(&options[opt_idx]);
10978 if (is_term_opt && num_normal > 0)
10979 continue;
10980 match = FALSE;
10981 if (vim_regexec(regmatch, str, (colnr_T)0)
10982 || (options[opt_idx].shortname != NULL
10983 && vim_regexec(regmatch,
10984 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10985 match = TRUE;
10986 else if (is_term_opt)
10987 {
10988 name_buf[0] = '<';
10989 name_buf[1] = 't';
10990 name_buf[2] = '_';
10991 name_buf[3] = str[2];
10992 name_buf[4] = str[3];
10993 name_buf[5] = '>';
10994 name_buf[6] = NUL;
10995 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10996 {
10997 match = TRUE;
10998 str = name_buf;
10999 }
11000 }
11001 if (match)
11002 {
11003 if (loop == 0)
11004 {
11005 if (is_term_opt)
11006 num_term++;
11007 else
11008 num_normal++;
11009 }
11010 else
11011 (*file)[count++] = vim_strsave(str);
11012 }
11013 }
11014 /*
11015 * Check terminal key codes, these are not in the option table
11016 */
11017 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11018 {
11019 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11020 {
11021 if (!isprint(str[0]) || !isprint(str[1]))
11022 continue;
11023
11024 name_buf[0] = 't';
11025 name_buf[1] = '_';
11026 name_buf[2] = str[0];
11027 name_buf[3] = str[1];
11028 name_buf[4] = NUL;
11029
11030 match = FALSE;
11031 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11032 match = TRUE;
11033 else
11034 {
11035 name_buf[0] = '<';
11036 name_buf[1] = 't';
11037 name_buf[2] = '_';
11038 name_buf[3] = str[0];
11039 name_buf[4] = str[1];
11040 name_buf[5] = '>';
11041 name_buf[6] = NUL;
11042
11043 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11044 match = TRUE;
11045 }
11046 if (match)
11047 {
11048 if (loop == 0)
11049 num_term++;
11050 else
11051 (*file)[count++] = vim_strsave(name_buf);
11052 }
11053 }
11054
11055 /*
11056 * Check special key names.
11057 */
11058 regmatch->rm_ic = TRUE; /* ignore case here */
11059 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11060 {
11061 name_buf[0] = '<';
11062 STRCPY(name_buf + 1, str);
11063 STRCAT(name_buf, ">");
11064
11065 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11066 {
11067 if (loop == 0)
11068 num_term++;
11069 else
11070 (*file)[count++] = vim_strsave(name_buf);
11071 }
11072 }
11073 }
11074 if (loop == 0)
11075 {
11076 if (num_normal > 0)
11077 *num_file = num_normal;
11078 else if (num_term > 0)
11079 *num_file = num_term;
11080 else
11081 return OK;
11082 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11083 if (*file == NULL)
11084 {
11085 *file = (char_u **)"";
11086 return FAIL;
11087 }
11088 }
11089 }
11090 return OK;
11091}
11092
11093 int
11094ExpandOldSetting(num_file, file)
11095 int *num_file;
11096 char_u ***file;
11097{
11098 char_u *var = NULL; /* init for GCC */
11099 char_u *buf;
11100
11101 *num_file = 0;
11102 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11103 if (*file == NULL)
11104 return FAIL;
11105
11106 /*
11107 * For a terminal key code expand_option_idx is < 0.
11108 */
11109 if (expand_option_idx < 0)
11110 {
11111 var = find_termcode(expand_option_name + 2);
11112 if (var == NULL)
11113 expand_option_idx = findoption(expand_option_name);
11114 }
11115
11116 if (expand_option_idx >= 0)
11117 {
11118 /* put string of option value in NameBuff */
11119 option_value2string(&options[expand_option_idx], expand_option_flags);
11120 var = NameBuff;
11121 }
11122 else if (var == NULL)
11123 var = (char_u *)"";
11124
11125 /* A backslash is required before some characters. This is the reverse of
11126 * what happens in do_set(). */
11127 buf = vim_strsave_escaped(var, escape_chars);
11128
11129 if (buf == NULL)
11130 {
11131 vim_free(*file);
11132 *file = NULL;
11133 return FAIL;
11134 }
11135
11136#ifdef BACKSLASH_IN_FILENAME
11137 /* For MS-Windows et al. we don't double backslashes at the start and
11138 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011139 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011140 if (var[0] == '\\' && var[1] == '\\'
11141 && expand_option_idx >= 0
11142 && (options[expand_option_idx].flags & P_EXPAND)
11143 && vim_isfilec(var[2])
11144 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011145 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011146#endif
11147
11148 *file[0] = buf;
11149 *num_file = 1;
11150 return OK;
11151}
11152#endif
11153
11154/*
11155 * Get the value for the numeric or string option *opp in a nice format into
11156 * NameBuff[]. Must not be called with a hidden option!
11157 */
11158 static void
11159option_value2string(opp, opt_flags)
11160 struct vimoption *opp;
11161 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11162{
11163 char_u *varp;
11164
11165 varp = get_varp_scope(opp, opt_flags);
11166
11167 if (opp->flags & P_NUM)
11168 {
11169 long wc = 0;
11170
11171 if (wc_use_keyname(varp, &wc))
11172 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11173 else if (wc != 0)
11174 STRCPY(NameBuff, transchar((int)wc));
11175 else
11176 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11177 }
11178 else /* P_STRING */
11179 {
11180 varp = *(char_u **)(varp);
11181 if (varp == NULL) /* just in case */
11182 NameBuff[0] = NUL;
11183#ifdef FEAT_CRYPT
11184 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011185 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011186 STRCPY(NameBuff, "*****");
11187#endif
11188 else if (opp->flags & P_EXPAND)
11189 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11190 /* Translate 'pastetoggle' into special key names */
11191 else if ((char_u **)opp->var == &p_pt)
11192 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11193 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011194 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011195 }
11196}
11197
11198/*
11199 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11200 * printed as a keyname.
11201 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11202 */
11203 static int
11204wc_use_keyname(varp, wcp)
11205 char_u *varp;
11206 long *wcp;
11207{
11208 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11209 {
11210 *wcp = *(long *)varp;
11211 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11212 return TRUE;
11213 }
11214 return FALSE;
11215}
11216
Bram Moolenaar01615492015-02-03 13:00:38 +010011217#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011218/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011219 * Any character has an equivalent 'langmap' character. This is used for
11220 * keyboards that have a special language mode that sends characters above
11221 * 128 (although other characters can be translated too). The "to" field is a
11222 * Vim command character. This avoids having to switch the keyboard back to
11223 * ASCII mode when leaving Insert mode.
11224 *
11225 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11226 * commands.
11227 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11228 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11229 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011230 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011231# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011232/*
11233 * With multi-byte support use growarray for 'langmap' chars >= 256
11234 */
11235typedef struct
11236{
11237 int from;
11238 int to;
11239} langmap_entry_T;
11240
11241static garray_T langmap_mapga;
11242static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011243
11244/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011245 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11246 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011248 static void
11249langmap_set_entry(from, to)
11250 int from;
11251 int to;
11252{
11253 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011254 int a = 0;
11255 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011256
11257 /* Do a binary search for an existing entry. */
11258 while (a != b)
11259 {
11260 int i = (a + b) / 2;
11261 int d = entries[i].from - from;
11262
11263 if (d == 0)
11264 {
11265 entries[i].to = to;
11266 return;
11267 }
11268 if (d < 0)
11269 a = i + 1;
11270 else
11271 b = i;
11272 }
11273
11274 if (ga_grow(&langmap_mapga, 1) != OK)
11275 return; /* out of memory */
11276
11277 /* insert new entry at position "a" */
11278 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11279 mch_memmove(entries + 1, entries,
11280 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11281 ++langmap_mapga.ga_len;
11282 entries[0].from = from;
11283 entries[0].to = to;
11284}
11285
11286/*
11287 * Apply 'langmap' to multi-byte character "c" and return the result.
11288 */
11289 int
11290langmap_adjust_mb(c)
11291 int c;
11292{
11293 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11294 int a = 0;
11295 int b = langmap_mapga.ga_len;
11296
11297 while (a != b)
11298 {
11299 int i = (a + b) / 2;
11300 int d = entries[i].from - c;
11301
11302 if (d == 0)
11303 return entries[i].to; /* found matching entry */
11304 if (d < 0)
11305 a = i + 1;
11306 else
11307 b = i;
11308 }
11309 return c; /* no entry found, return "c" unmodified */
11310}
11311# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011312
11313 static void
11314langmap_init()
11315{
11316 int i;
11317
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011318 for (i = 0; i < 256; i++)
11319 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11320# ifdef FEAT_MBYTE
11321 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11322# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323}
11324
11325/*
11326 * Called when langmap option is set; the language map can be
11327 * changed at any time!
11328 */
11329 static void
11330langmap_set()
11331{
11332 char_u *p;
11333 char_u *p2;
11334 int from, to;
11335
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011336#ifdef FEAT_MBYTE
11337 ga_clear(&langmap_mapga); /* clear the previous map first */
11338#endif
11339 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011340
11341 for (p = p_langmap; p[0] != NUL; )
11342 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011343 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11344 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011345 {
11346 if (p2[0] == '\\' && p2[1] != NUL)
11347 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011348 }
11349 if (p2[0] == ';')
11350 ++p2; /* abcd;ABCD form, p2 points to A */
11351 else
11352 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11353 while (p[0])
11354 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011355 if (p[0] == ',')
11356 {
11357 ++p;
11358 break;
11359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011360 if (p[0] == '\\' && p[1] != NUL)
11361 ++p;
11362#ifdef FEAT_MBYTE
11363 from = (*mb_ptr2char)(p);
11364#else
11365 from = p[0];
11366#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011367 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368 if (p2 == NULL)
11369 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011370 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011371 if (p[0] != ',')
11372 {
11373 if (p[0] == '\\')
11374 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011375#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011376 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011377#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011378 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011379#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011380 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011381 }
11382 else
11383 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011384 if (p2[0] != ',')
11385 {
11386 if (p2[0] == '\\')
11387 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011389 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011390#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011391 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011392#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011393 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011394 }
11395 if (to == NUL)
11396 {
11397 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11398 transchar(from));
11399 return;
11400 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011401
11402#ifdef FEAT_MBYTE
11403 if (from >= 256)
11404 langmap_set_entry(from, to);
11405 else
11406#endif
11407 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408
11409 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011410 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011411 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011412 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011413 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011414 if (*p == ';')
11415 {
11416 p = p2;
11417 if (p[0] != NUL)
11418 {
11419 if (p[0] != ',')
11420 {
11421 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11422 return;
11423 }
11424 ++p;
11425 }
11426 break;
11427 }
11428 }
11429 }
11430 }
11431}
11432#endif
11433
11434/*
11435 * Return TRUE if format option 'x' is in effect.
11436 * Take care of no formatting when 'paste' is set.
11437 */
11438 int
11439has_format_option(x)
11440 int x;
11441{
11442 if (p_paste)
11443 return FALSE;
11444 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11445}
11446
11447/*
11448 * Return TRUE if "x" is present in 'shortmess' option, or
11449 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11450 */
11451 int
11452shortmess(x)
11453 int x;
11454{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011455 return p_shm != NULL &&
11456 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011457 || (vim_strchr(p_shm, 'a') != NULL
11458 && vim_strchr((char_u *)SHM_A, x) != NULL));
11459}
11460
11461/*
11462 * paste_option_changed() - Called after p_paste was set or reset.
11463 */
11464 static void
11465paste_option_changed()
11466{
11467 static int old_p_paste = FALSE;
11468 static int save_sm = 0;
11469#ifdef FEAT_CMDL_INFO
11470 static int save_ru = 0;
11471#endif
11472#ifdef FEAT_RIGHTLEFT
11473 static int save_ri = 0;
11474 static int save_hkmap = 0;
11475#endif
11476 buf_T *buf;
11477
11478 if (p_paste)
11479 {
11480 /*
11481 * Paste switched from off to on.
11482 * Save the current values, so they can be restored later.
11483 */
11484 if (!old_p_paste)
11485 {
11486 /* save options for each buffer */
11487 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11488 {
11489 buf->b_p_tw_nopaste = buf->b_p_tw;
11490 buf->b_p_wm_nopaste = buf->b_p_wm;
11491 buf->b_p_sts_nopaste = buf->b_p_sts;
11492 buf->b_p_ai_nopaste = buf->b_p_ai;
11493 }
11494
11495 /* save global options */
11496 save_sm = p_sm;
11497#ifdef FEAT_CMDL_INFO
11498 save_ru = p_ru;
11499#endif
11500#ifdef FEAT_RIGHTLEFT
11501 save_ri = p_ri;
11502 save_hkmap = p_hkmap;
11503#endif
11504 /* save global values for local buffer options */
11505 p_tw_nopaste = p_tw;
11506 p_wm_nopaste = p_wm;
11507 p_sts_nopaste = p_sts;
11508 p_ai_nopaste = p_ai;
11509 }
11510
11511 /*
11512 * Always set the option values, also when 'paste' is set when it is
11513 * already on.
11514 */
11515 /* set options for each buffer */
11516 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11517 {
11518 buf->b_p_tw = 0; /* textwidth is 0 */
11519 buf->b_p_wm = 0; /* wrapmargin is 0 */
11520 buf->b_p_sts = 0; /* softtabstop is 0 */
11521 buf->b_p_ai = 0; /* no auto-indent */
11522 }
11523
11524 /* set global options */
11525 p_sm = 0; /* no showmatch */
11526#ifdef FEAT_CMDL_INFO
11527# ifdef FEAT_WINDOWS
11528 if (p_ru)
11529 status_redraw_all(); /* redraw to remove the ruler */
11530# endif
11531 p_ru = 0; /* no ruler */
11532#endif
11533#ifdef FEAT_RIGHTLEFT
11534 p_ri = 0; /* no reverse insert */
11535 p_hkmap = 0; /* no Hebrew keyboard */
11536#endif
11537 /* set global values for local buffer options */
11538 p_tw = 0;
11539 p_wm = 0;
11540 p_sts = 0;
11541 p_ai = 0;
11542 }
11543
11544 /*
11545 * Paste switched from on to off: Restore saved values.
11546 */
11547 else if (old_p_paste)
11548 {
11549 /* restore options for each buffer */
11550 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11551 {
11552 buf->b_p_tw = buf->b_p_tw_nopaste;
11553 buf->b_p_wm = buf->b_p_wm_nopaste;
11554 buf->b_p_sts = buf->b_p_sts_nopaste;
11555 buf->b_p_ai = buf->b_p_ai_nopaste;
11556 }
11557
11558 /* restore global options */
11559 p_sm = save_sm;
11560#ifdef FEAT_CMDL_INFO
11561# ifdef FEAT_WINDOWS
11562 if (p_ru != save_ru)
11563 status_redraw_all(); /* redraw to draw the ruler */
11564# endif
11565 p_ru = save_ru;
11566#endif
11567#ifdef FEAT_RIGHTLEFT
11568 p_ri = save_ri;
11569 p_hkmap = save_hkmap;
11570#endif
11571 /* set global values for local buffer options */
11572 p_tw = p_tw_nopaste;
11573 p_wm = p_wm_nopaste;
11574 p_sts = p_sts_nopaste;
11575 p_ai = p_ai_nopaste;
11576 }
11577
11578 old_p_paste = p_paste;
11579}
11580
11581/*
11582 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11583 *
11584 * Reset 'compatible' and set the values for options that didn't get set yet
11585 * to the Vim defaults.
11586 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011587 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011588 */
11589 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011590vimrc_found(fname, envname)
11591 char_u *fname;
11592 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011593{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011594 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011595 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011596 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011597
11598 if (!option_was_set((char_u *)"cp"))
11599 {
11600 p_cp = FALSE;
11601 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11602 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11603 set_option_default(opt_idx, OPT_FREE, FALSE);
11604 didset_options();
11605 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011606
11607 if (fname != NULL)
11608 {
11609 p = vim_getenv(envname, &dofree);
11610 if (p == NULL)
11611 {
11612 /* Set $MYVIMRC to the first vimrc file found. */
11613 p = FullName_save(fname, FALSE);
11614 if (p != NULL)
11615 {
11616 vim_setenv(envname, p);
11617 vim_free(p);
11618 }
11619 }
11620 else if (dofree)
11621 vim_free(p);
11622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623}
11624
11625/*
11626 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11627 */
11628 void
11629change_compatible(on)
11630 int on;
11631{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011632 int opt_idx;
11633
Bram Moolenaar071d4272004-06-13 20:20:40 +000011634 if (p_cp != on)
11635 {
11636 p_cp = on;
11637 compatible_set();
11638 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011639 opt_idx = findoption((char_u *)"cp");
11640 if (opt_idx >= 0)
11641 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011642}
11643
11644/*
11645 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011646 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011647 */
11648 int
11649option_was_set(name)
11650 char_u *name;
11651{
11652 int idx;
11653
11654 idx = findoption(name);
11655 if (idx < 0) /* unknown option */
11656 return FALSE;
11657 if (options[idx].flags & P_WAS_SET)
11658 return TRUE;
11659 return FALSE;
11660}
11661
11662/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011663 * Reset the flag indicating option "name" was set.
11664 */
11665 void
11666reset_option_was_set(name)
11667 char_u *name;
11668{
11669 int idx = findoption(name);
11670
11671 if (idx >= 0)
11672 options[idx].flags &= ~P_WAS_SET;
11673}
11674
11675/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011676 * compatible_set() - Called when 'compatible' has been set or unset.
11677 *
11678 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11679 * flag) to a Vi compatible value.
11680 * When 'compatible' is unset: Set all options that have a different default
11681 * for Vim (without the P_VI_DEF flag) to that default.
11682 */
11683 static void
11684compatible_set()
11685{
11686 int opt_idx;
11687
11688 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11689 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11690 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11691 set_option_default(opt_idx, OPT_FREE, p_cp);
11692 didset_options();
11693}
11694
11695#ifdef FEAT_LINEBREAK
11696
11697# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11698 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011699 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011700# endif
11701
11702/*
11703 * fill_breakat_flags() -- called when 'breakat' changes value.
11704 */
11705 static void
11706fill_breakat_flags()
11707{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011708 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011709 int i;
11710
11711 for (i = 0; i < 256; i++)
11712 breakat_flags[i] = FALSE;
11713
11714 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011715 for (p = p_breakat; *p; p++)
11716 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011717}
11718
11719# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011720 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011721# endif
11722
11723#endif
11724
11725/*
11726 * Check an option that can be a range of string values.
11727 *
11728 * Return OK for correct value, FAIL otherwise.
11729 * Empty is always OK.
11730 */
11731 static int
11732check_opt_strings(val, values, list)
11733 char_u *val;
11734 char **values;
11735 int list; /* when TRUE: accept a list of values */
11736{
11737 return opt_strings_flags(val, values, NULL, list);
11738}
11739
11740/*
11741 * Handle an option that can be a range of string values.
11742 * Set a flag in "*flagp" for each string present.
11743 *
11744 * Return OK for correct value, FAIL otherwise.
11745 * Empty is always OK.
11746 */
11747 static int
11748opt_strings_flags(val, values, flagp, list)
11749 char_u *val; /* new value */
11750 char **values; /* array of valid string values */
11751 unsigned *flagp;
11752 int list; /* when TRUE: accept a list of values */
11753{
11754 int i;
11755 int len;
11756 unsigned new_flags = 0;
11757
11758 while (*val)
11759 {
11760 for (i = 0; ; ++i)
11761 {
11762 if (values[i] == NULL) /* val not found in values[] */
11763 return FAIL;
11764
11765 len = (int)STRLEN(values[i]);
11766 if (STRNCMP(values[i], val, len) == 0
11767 && ((list && val[len] == ',') || val[len] == NUL))
11768 {
11769 val += len + (val[len] == ',');
11770 new_flags |= (1 << i);
11771 break; /* check next item in val list */
11772 }
11773 }
11774 }
11775 if (flagp != NULL)
11776 *flagp = new_flags;
11777
11778 return OK;
11779}
11780
11781/*
11782 * Read the 'wildmode' option, fill wim_flags[].
11783 */
11784 static int
11785check_opt_wim()
11786{
11787 char_u new_wim_flags[4];
11788 char_u *p;
11789 int i;
11790 int idx = 0;
11791
11792 for (i = 0; i < 4; ++i)
11793 new_wim_flags[i] = 0;
11794
11795 for (p = p_wim; *p; ++p)
11796 {
11797 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11798 ;
11799 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11800 return FAIL;
11801 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11802 new_wim_flags[idx] |= WIM_LONGEST;
11803 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11804 new_wim_flags[idx] |= WIM_FULL;
11805 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11806 new_wim_flags[idx] |= WIM_LIST;
11807 else
11808 return FAIL;
11809 p += i;
11810 if (*p == NUL)
11811 break;
11812 if (*p == ',')
11813 {
11814 if (idx == 3)
11815 return FAIL;
11816 ++idx;
11817 }
11818 }
11819
11820 /* fill remaining entries with last flag */
11821 while (idx < 3)
11822 {
11823 new_wim_flags[idx + 1] = new_wim_flags[idx];
11824 ++idx;
11825 }
11826
11827 /* only when there are no errors, wim_flags[] is changed */
11828 for (i = 0; i < 4; ++i)
11829 wim_flags[i] = new_wim_flags[i];
11830 return OK;
11831}
11832
11833/*
11834 * Check if backspacing over something is allowed.
11835 */
11836 int
11837can_bs(what)
11838 int what; /* BS_INDENT, BS_EOL or BS_START */
11839{
11840 switch (*p_bs)
11841 {
11842 case '2': return TRUE;
11843 case '1': return (what != BS_START);
11844 case '0': return FALSE;
11845 }
11846 return vim_strchr(p_bs, what) != NULL;
11847}
11848
11849/*
11850 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11851 * the file must be considered changed when the value is different.
11852 */
11853 void
11854save_file_ff(buf)
11855 buf_T *buf;
11856{
11857 buf->b_start_ffc = *buf->b_p_ff;
11858 buf->b_start_eol = buf->b_p_eol;
11859#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011860 buf->b_start_bomb = buf->b_p_bomb;
11861
Bram Moolenaar071d4272004-06-13 20:20:40 +000011862 /* Only use free/alloc when necessary, they take time. */
11863 if (buf->b_start_fenc == NULL
11864 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11865 {
11866 vim_free(buf->b_start_fenc);
11867 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11868 }
11869#endif
11870}
11871
11872/*
11873 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11874 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011875 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11876 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011877 * When "ignore_empty" is true don't consider a new, empty buffer to be
11878 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011879 */
11880 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011881file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011882 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011883 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011884{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011885 /* In a buffer that was never loaded the options are not valid. */
11886 if (buf->b_flags & BF_NEVERLOADED)
11887 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011888 if (ignore_empty
11889 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011890 && buf->b_ml.ml_line_count == 1
11891 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11892 return FALSE;
11893 if (buf->b_start_ffc != *buf->b_p_ff)
11894 return TRUE;
11895 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11896 return TRUE;
11897#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011898 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11899 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900 if (buf->b_start_fenc == NULL)
11901 return (*buf->b_p_fenc != NUL);
11902 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11903#else
11904 return FALSE;
11905#endif
11906}
11907
11908/*
11909 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11910 */
11911 int
11912check_ff_value(p)
11913 char_u *p;
11914{
11915 return check_opt_strings(p, p_ff_values, FALSE);
11916}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011917
11918/*
11919 * Return the effective shiftwidth value for current buffer, using the
11920 * 'tabstop' value when 'shiftwidth' is zero.
11921 */
11922 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011923get_sw_value(buf)
11924 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011925{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011926 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011927}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011928
11929/*
11930 * Return the effective softtabstop value for the current buffer, using the
11931 * 'tabstop' value when 'softtabstop' is negative.
11932 */
11933 long
11934get_sts_value()
11935{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011936 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011937}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011938
11939/*
11940 * Check matchpairs option for "*initc".
11941 * If there is a match set "*initc" to the matching character and "*findc" to
11942 * the opposite character. Set "*backwards" to the direction.
11943 * When "switchit" is TRUE swap the direction.
11944 */
11945 void
11946find_mps_values(initc, findc, backwards, switchit)
11947 int *initc;
11948 int *findc;
11949 int *backwards;
11950 int switchit;
11951{
11952 char_u *ptr;
11953
11954 ptr = curbuf->b_p_mps;
11955 while (*ptr != NUL)
11956 {
11957#ifdef FEAT_MBYTE
11958 if (has_mbyte)
11959 {
11960 char_u *prev;
11961
11962 if (mb_ptr2char(ptr) == *initc)
11963 {
11964 if (switchit)
11965 {
11966 *findc = *initc;
11967 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11968 *backwards = TRUE;
11969 }
11970 else
11971 {
11972 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11973 *backwards = FALSE;
11974 }
11975 return;
11976 }
11977 prev = ptr;
11978 ptr += mb_ptr2len(ptr) + 1;
11979 if (mb_ptr2char(ptr) == *initc)
11980 {
11981 if (switchit)
11982 {
11983 *findc = *initc;
11984 *initc = mb_ptr2char(prev);
11985 *backwards = FALSE;
11986 }
11987 else
11988 {
11989 *findc = mb_ptr2char(prev);
11990 *backwards = TRUE;
11991 }
11992 return;
11993 }
11994 ptr += mb_ptr2len(ptr);
11995 }
11996 else
11997#endif
11998 {
11999 if (*ptr == *initc)
12000 {
12001 if (switchit)
12002 {
12003 *backwards = TRUE;
12004 *findc = *initc;
12005 *initc = ptr[2];
12006 }
12007 else
12008 {
12009 *backwards = FALSE;
12010 *findc = ptr[2];
12011 }
12012 return;
12013 }
12014 ptr += 2;
12015 if (*ptr == *initc)
12016 {
12017 if (switchit)
12018 {
12019 *backwards = FALSE;
12020 *findc = *initc;
12021 *initc = ptr[-2];
12022 }
12023 else
12024 {
12025 *backwards = TRUE;
12026 *findc = ptr[-2];
12027 }
12028 return;
12029 }
12030 ++ptr;
12031 }
12032 if (*ptr == ',')
12033 ++ptr;
12034 }
12035}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012036
12037#if defined(FEAT_LINEBREAK) || defined(PROTO)
12038/*
12039 * This is called when 'breakindentopt' is changed and when a window is
12040 * initialized.
12041 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012042 static int
12043briopt_check(wp)
12044 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012045{
12046 char_u *p;
12047 int bri_shift = 0;
12048 long bri_min = 20;
12049 int bri_sbr = FALSE;
12050
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012051 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012052 while (*p != NUL)
12053 {
12054 if (STRNCMP(p, "shift:", 6) == 0
12055 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12056 {
12057 p += 6;
12058 bri_shift = getdigits(&p);
12059 }
12060 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12061 {
12062 p += 4;
12063 bri_min = getdigits(&p);
12064 }
12065 else if (STRNCMP(p, "sbr", 3) == 0)
12066 {
12067 p += 3;
12068 bri_sbr = TRUE;
12069 }
12070 if (*p != ',' && *p != NUL)
12071 return FAIL;
12072 if (*p == ',')
12073 ++p;
12074 }
12075
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012076 wp->w_p_brishift = bri_shift;
12077 wp->w_p_brimin = bri_min;
12078 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012079
12080 return OK;
12081}
12082#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012083
12084/*
12085 * Get the local or global value of 'backupcopy'.
12086 */
12087 unsigned int
12088get_bkc_value(buf)
12089 buf_T *buf;
12090{
12091 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12092}