blob: 6841d42d6cfa92afdde42778c6746b0a7d8e7cb2 [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 Moolenaar071d4272004-06-13 20:20:40 +00002981 p_term("t_xs", T_XS)
2982 p_term("t_ZH", T_CZH)
2983 p_term("t_ZR", T_CZR)
2984
2985/* terminal key codes are not in here */
2986
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002987 /* end marker */
2988 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989};
2990
2991#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2992
2993#ifdef FEAT_MBYTE
2994static char *(p_ambw_values[]) = {"single", "double", NULL};
2995#endif
2996static char *(p_bg_values[]) = {"light", "dark", NULL};
2997static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2998static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02002999#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003000static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003001#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003002#ifdef FEAT_CMDL_COMPL
3003static char *(p_wop_values[]) = {"tagfile", NULL};
3004#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005#ifdef FEAT_WAK
3006static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3007#endif
3008static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3010static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012#ifdef FEAT_BROWSE
3013static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3014#endif
3015#ifdef FEAT_SCROLLBIND
3016static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3017#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003018static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019#ifdef FEAT_VERTSPLIT
3020static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3021#endif
3022#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003023# ifdef FEAT_AUTOCMD
3024static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3025# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003027# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3029#endif
3030static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3031#ifdef FEAT_FOLDING
3032static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003033# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003035# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036 NULL};
3037static char *(p_fcl_values[]) = {"all", NULL};
3038#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003039#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003040static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042
3043static void set_option_default __ARGS((int, int opt_flags, int compatible));
3044static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003045static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003046static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047static char_u *illegal_char __ARGS((char_u *, int));
3048static int string_to_key __ARGS((char_u *arg));
3049#ifdef FEAT_CMDWIN
3050static char_u *check_cedit __ARGS((void));
3051#endif
3052#ifdef FEAT_TITLE
3053static void did_set_title __ARGS((int icon));
3054#endif
3055static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3056static void didset_options __ARGS((void));
3057static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003058#if defined(FEAT_EVAL) || defined(PROTO)
3059static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3060#else
3061# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3062#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003064static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065static 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));
3066static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003067#ifdef FEAT_SYN_HL
3068static int int_cmp __ARGS((const void *a, const void *b));
3069#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070#ifdef FEAT_CLIPBOARD
3071static char_u *check_clipboard_option __ARGS((void));
3072#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003073#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003074static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003075#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003076#ifdef FEAT_EVAL
3077static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3078#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003080static 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 +00003081static void check_redraw __ARGS((long_u flags));
3082static int findoption __ARGS((char_u *));
3083static int find_key_option __ARGS((char_u *));
3084static void showoptions __ARGS((int all, int opt_flags));
3085static int optval_default __ARGS((struct vimoption *, char_u *varp));
3086static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3087static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3088static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3089static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3090static int istermoption __ARGS((struct vimoption *));
3091static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3092static char_u *get_varp __ARGS((struct vimoption *));
3093static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003094static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3096#ifdef FEAT_LANGMAP
3097static void langmap_init __ARGS((void));
3098static void langmap_set __ARGS((void));
3099#endif
3100static void paste_option_changed __ARGS((void));
3101static void compatible_set __ARGS((void));
3102#ifdef FEAT_LINEBREAK
3103static void fill_breakat_flags __ARGS((void));
3104#endif
3105static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3106static int check_opt_strings __ARGS((char_u *val, char **values, int));
3107static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003108#ifdef FEAT_LINEBREAK
3109static int briopt_check __ARGS((win_T *wp));
3110#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111
3112/*
3113 * Initialize the options, first part.
3114 *
3115 * Called only once from main(), just after creating the first buffer.
3116 */
3117 void
3118set_init_1()
3119{
3120 char_u *p;
3121 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003122 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123
3124#ifdef FEAT_LANGMAP
3125 langmap_init();
3126#endif
3127
3128 /* Be Vi compatible by default */
3129 p_cp = TRUE;
3130
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003131 /* Use POSIX compatibility when $VIM_POSIX is set. */
3132 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003133 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003134 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003135 set_string_default("shm", (char_u *)"A");
3136 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003137
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138 /*
3139 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003140 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003142 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3144# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003145 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003147 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003149 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150# endif
3151#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003152 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 set_string_default("sh", p);
3154
3155#ifdef FEAT_WILDIGN
3156 /*
3157 * Set the default for 'backupskip' to include environment variables for
3158 * temp files.
3159 */
3160 {
3161# ifdef UNIX
3162 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3163# else
3164 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3165# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003166 int len;
3167 garray_T ga;
3168 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169
3170 ga_init2(&ga, 1, 100);
3171 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3172 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003173 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174# ifdef UNIX
3175 if (*names[n] == NUL)
3176 p = (char_u *)"/tmp";
3177 else
3178# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003179 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 if (p != NULL && *p != NUL)
3181 {
3182 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003183 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184 if (ga_grow(&ga, len) == OK)
3185 {
3186 if (ga.ga_len > 0)
3187 STRCAT(ga.ga_data, ",");
3188 STRCAT(ga.ga_data, p);
3189 add_pathsep(ga.ga_data);
3190 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191 ga.ga_len += len;
3192 }
3193 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003194 if (mustfree)
3195 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196 }
3197 if (ga.ga_data != NULL)
3198 {
3199 set_string_default("bsk", ga.ga_data);
3200 vim_free(ga.ga_data);
3201 }
3202 }
3203#endif
3204
3205 /*
3206 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3207 */
3208 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003209 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003211#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3212 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3213#endif
3214 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003216 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003217 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218#else
3219# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003220 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003221 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003223 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224# endif
3225#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003227 opt_idx = findoption((char_u *)"maxmem");
3228 if (opt_idx >= 0)
3229 {
3230#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003231 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003232 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3233#endif
3234 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3235 }
3236 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237 }
3238
3239#ifdef FEAT_GUI_W32
3240 /* force 'shortname' for Win32s */
3241 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003242 {
3243 opt_idx = findoption((char_u *)"shortname");
3244 if (opt_idx >= 0)
3245 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3246 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247#endif
3248
3249#ifdef FEAT_SEARCHPATH
3250 {
3251 char_u *cdpath;
3252 char_u *buf;
3253 int i;
3254 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003255 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256
3257 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003258 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259 if (cdpath != NULL)
3260 {
3261 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3262 if (buf != NULL)
3263 {
3264 buf[0] = ','; /* start with ",", current dir first */
3265 j = 1;
3266 for (i = 0; cdpath[i] != NUL; ++i)
3267 {
3268 if (vim_ispathlistsep(cdpath[i]))
3269 buf[j++] = ',';
3270 else
3271 {
3272 if (cdpath[i] == ' ' || cdpath[i] == ',')
3273 buf[j++] = '\\';
3274 buf[j++] = cdpath[i];
3275 }
3276 }
3277 buf[j] = NUL;
3278 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003279 if (opt_idx >= 0)
3280 {
3281 options[opt_idx].def_val[VI_DEFAULT] = buf;
3282 options[opt_idx].flags |= P_DEF_ALLOCED;
3283 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003284 else
3285 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003287 if (mustfree)
3288 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289 }
3290 }
3291#endif
3292
3293#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3294 /* Set print encoding on platforms that don't default to latin1 */
3295 set_string_default("penc",
3296# if defined(MSWIN) || defined(OS2)
3297 (char_u *)"cp1252"
3298# else
3299# ifdef VMS
3300 (char_u *)"dec-mcs"
3301# else
3302# ifdef EBCDIC
3303 (char_u *)"ebcdic-uk"
3304# else
3305# ifdef MAC
3306 (char_u *)"mac-roman"
3307# else /* HPUX */
3308 (char_u *)"hp-roman8"
3309# endif
3310# endif
3311# endif
3312# endif
3313 );
3314#endif
3315
3316#ifdef FEAT_POSTSCRIPT
3317 /* 'printexpr' must be allocated to be able to evaluate it. */
3318 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003319# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3320 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321# else
3322# ifdef VMS
3323 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3324
3325# else
3326 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3327# endif
3328# endif
3329 );
3330#endif
3331
3332 /*
3333 * Set all the options (except the terminal options) to their default
3334 * value. Also set the global value for local options.
3335 */
3336 set_options_default(0);
3337
3338#ifdef FEAT_GUI
3339 if (found_reverse_arg)
3340 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3341#endif
3342
3343 curbuf->b_p_initialized = TRUE;
3344 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003345 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003346 check_buf_options(curbuf);
3347 check_win_options(curwin);
3348 check_options();
3349
3350 /* Must be before option_expand(), because that one needs vim_isIDc() */
3351 didset_options();
3352
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003353#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003354 /* Use the current chartab for the generic chartab. */
3355 init_spell_chartab();
3356#endif
3357
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358#ifdef FEAT_LINEBREAK
3359 /*
3360 * initialize the table for 'breakat'.
3361 */
3362 fill_breakat_flags();
3363#endif
3364
3365 /*
3366 * Expand environment variables and things like "~" for the defaults.
3367 * If option_expand() returns non-NULL the variable is expanded. This can
3368 * only happen for non-indirect options.
3369 * Also set the default to the expanded value, so ":set" does not list
3370 * them.
3371 * Don't set the P_ALLOCED flag, because we don't want to free the
3372 * default.
3373 */
3374 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3375 {
3376 if ((options[opt_idx].flags & P_GETTEXT)
3377 && options[opt_idx].var != NULL)
3378 p = (char_u *)_(*(char **)options[opt_idx].var);
3379 else
3380 p = option_expand(opt_idx, NULL);
3381 if (p != NULL && (p = vim_strsave(p)) != NULL)
3382 {
3383 *(char_u **)options[opt_idx].var = p;
3384 /* VIMEXP
3385 * Defaults for all expanded options are currently the same for Vi
3386 * and Vim. When this changes, add some code here! Also need to
3387 * split P_DEF_ALLOCED in two.
3388 */
3389 if (options[opt_idx].flags & P_DEF_ALLOCED)
3390 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3391 options[opt_idx].def_val[VI_DEFAULT] = p;
3392 options[opt_idx].flags |= P_DEF_ALLOCED;
3393 }
3394 }
3395
3396 /* Initialize the highlight_attr[] table. */
3397 highlight_changed();
3398
3399 save_file_ff(curbuf); /* Buffer is unchanged */
3400
3401 /* Parse default for 'wildmode' */
3402 check_opt_wim();
3403
3404#if defined(FEAT_ARABIC)
3405 /* Detect use of mlterm.
3406 * Mlterm is a terminal emulator akin to xterm that has some special
3407 * abilities (bidi namely).
3408 * NOTE: mlterm's author is being asked to 'set' a variable
3409 * instead of an environment variable due to inheritance.
3410 */
3411 if (mch_getenv((char_u *)"MLTERM") != NULL)
3412 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3413#endif
3414
3415#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3416 /* Parse default for 'fillchars'. */
3417 (void)set_chars_option(&p_fcs);
3418#endif
3419
3420#ifdef FEAT_CLIPBOARD
3421 /* Parse default for 'clipboard' */
3422 (void)check_clipboard_option();
3423#endif
3424
3425#ifdef FEAT_MBYTE
3426# if defined(WIN3264) && defined(FEAT_GETTEXT)
3427 /*
3428 * If $LANG isn't set, try to get a good value for it. This makes the
3429 * right language be used automatically. Don't do this for English.
3430 */
3431 if (mch_getenv((char_u *)"LANG") == NULL)
3432 {
3433 char buf[20];
3434
3435 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3436 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3437 * only the first two. */
3438 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3439 (LPTSTR)buf, 20);
3440 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3441 {
3442 /* There are a few exceptions (probably more) */
3443 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3444 STRCPY(buf, "zh_TW");
3445 else if (STRNICMP(buf, "chs", 3) == 0
3446 || STRNICMP(buf, "zhc", 3) == 0)
3447 STRCPY(buf, "zh_CN");
3448 else if (STRNICMP(buf, "jp", 2) == 0)
3449 STRCPY(buf, "ja");
3450 else
3451 buf[2] = NUL; /* truncate to two-letter code */
3452 vim_setenv("LANG", buf);
3453 }
3454 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003455# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003456# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003457 /* Moved to os_mac_conv.c to avoid dependency problems. */
3458 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003459# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003460# endif
3461
3462 /* enc_locale() will try to find the encoding of the current locale. */
3463 p = enc_locale();
3464 if (p != NULL)
3465 {
3466 char_u *save_enc;
3467
3468 /* Try setting 'encoding' and check if the value is valid.
3469 * If not, go back to the default "latin1". */
3470 save_enc = p_enc;
3471 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003472 if (STRCMP(p_enc, "gb18030") == 0)
3473 {
3474 /* We don't support "gb18030", but "cp936" is a good substitute
3475 * for practical purposes, thus use that. It's not an alias to
3476 * still support conversion between gb18030 and utf-8. */
3477 p_enc = vim_strsave((char_u *)"cp936");
3478 vim_free(p);
3479 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480 if (mb_init() == NULL)
3481 {
3482 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003483 if (opt_idx >= 0)
3484 {
3485 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3486 options[opt_idx].flags |= P_DEF_ALLOCED;
3487 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003489#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3490 || defined(VMS)
3491 if (STRCMP(p_enc, "latin1") == 0
3492# ifdef FEAT_MBYTE
3493 || enc_utf8
3494# endif
3495 )
3496 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003497 /* Adjust the default for 'isprint' and 'iskeyword' to match
3498 * latin1. Also set the defaults for when 'nocompatible' is
3499 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003500 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003501 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003502 set_string_option_direct((char_u *)"isk", -1,
3503 ISK_LATIN1, OPT_FREE, SID_NONE);
3504 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003505 if (opt_idx >= 0)
3506 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003507 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003508 if (opt_idx >= 0)
3509 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003510 (void)init_chartab();
3511 }
3512#endif
3513
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514# if defined(WIN3264) && !defined(FEAT_GUI)
3515 /* Win32 console: When GetACP() returns a different value from
3516 * GetConsoleCP() set 'termencoding'. */
3517 if (GetACP() != GetConsoleCP())
3518 {
3519 char buf[50];
3520
3521 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3522 p_tenc = vim_strsave((char_u *)buf);
3523 if (p_tenc != NULL)
3524 {
3525 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003526 if (opt_idx >= 0)
3527 {
3528 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3529 options[opt_idx].flags |= P_DEF_ALLOCED;
3530 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003531 convert_setup(&input_conv, p_tenc, p_enc);
3532 convert_setup(&output_conv, p_enc, p_tenc);
3533 }
3534 else
3535 p_tenc = empty_option;
3536 }
3537# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003538# if defined(WIN3264) && defined(FEAT_MBYTE)
3539 /* $HOME may have characters in active code page. */
3540 init_homedir();
3541# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542 }
3543 else
3544 {
3545 vim_free(p_enc);
3546 p_enc = save_enc;
3547 }
3548 }
3549#endif
3550
3551#ifdef FEAT_MULTI_LANG
3552 /* Set the default for 'helplang'. */
3553 set_helplang_default(get_mess_lang());
3554#endif
3555}
3556
3557/*
3558 * Set an option to its default value.
3559 * This does not take care of side effects!
3560 */
3561 static void
3562set_option_default(opt_idx, opt_flags, compatible)
3563 int opt_idx;
3564 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3565 int compatible; /* use Vi default value */
3566{
3567 char_u *varp; /* pointer to variable for current option */
3568 int dvi; /* index in def_val[] */
3569 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003570 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003571 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3572
3573 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3574 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003575 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576 {
3577 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3578 if (flags & P_STRING)
3579 {
3580 /* Use set_string_option_direct() for local options to handle
3581 * freeing and allocating the value. */
3582 if (options[opt_idx].indir != PV_NONE)
3583 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003584 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585 else
3586 {
3587 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3588 free_string_option(*(char_u **)(varp));
3589 *(char_u **)varp = options[opt_idx].def_val[dvi];
3590 options[opt_idx].flags &= ~P_ALLOCED;
3591 }
3592 }
3593 else if (flags & P_NUM)
3594 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003595 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 win_comp_scroll(curwin);
3597 else
3598 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003599 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003600 /* May also set global value for local option. */
3601 if (both)
3602 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3603 *(long *)varp;
3604 }
3605 }
3606 else /* P_BOOL */
3607 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003608 /* the cast to long is required for Manx C, long_i is needed for
3609 * MSVC */
3610 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003611#ifdef UNIX
3612 /* 'modeline' defaults to off for root */
3613 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3614 *(int *)varp = FALSE;
3615#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003616 /* May also set global value for local option. */
3617 if (both)
3618 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3619 *(int *)varp;
3620 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003621
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003622 /* The default value is not insecure. */
3623 flagsp = insecure_flag(opt_idx, opt_flags);
3624 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003625 }
3626
3627#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003628 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629#endif
3630}
3631
3632/*
3633 * Set all options (except terminal options) to their default value.
3634 */
3635 static void
3636set_options_default(opt_flags)
3637 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3638{
3639 int i;
3640#ifdef FEAT_WINDOWS
3641 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003642 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003643#endif
3644
3645 for (i = 0; !istermoption(&options[i]); i++)
3646 if (!(options[i].flags & P_NODEFAULT))
3647 set_option_default(i, opt_flags, p_cp);
3648
3649#ifdef FEAT_WINDOWS
3650 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003651 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652 win_comp_scroll(wp);
3653#else
3654 win_comp_scroll(curwin);
3655#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003656#ifdef FEAT_CINDENT
3657 parse_cino(curbuf);
3658#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003659}
3660
3661/*
3662 * Set the Vi-default value of a string option.
3663 * Used for 'sh', 'backupskip' and 'term'.
3664 */
3665 void
3666set_string_default(name, val)
3667 char *name;
3668 char_u *val;
3669{
3670 char_u *p;
3671 int opt_idx;
3672
3673 p = vim_strsave(val);
3674 if (p != NULL) /* we don't want a NULL */
3675 {
3676 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003677 if (opt_idx >= 0)
3678 {
3679 if (options[opt_idx].flags & P_DEF_ALLOCED)
3680 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3681 options[opt_idx].def_val[VI_DEFAULT] = p;
3682 options[opt_idx].flags |= P_DEF_ALLOCED;
3683 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003684 }
3685}
3686
3687/*
3688 * Set the Vi-default value of a number option.
3689 * Used for 'lines' and 'columns'.
3690 */
3691 void
3692set_number_default(name, val)
3693 char *name;
3694 long val;
3695{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003696 int opt_idx;
3697
3698 opt_idx = findoption((char_u *)name);
3699 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003700 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003701}
3702
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003703#if defined(EXITFREE) || defined(PROTO)
3704/*
3705 * Free all options.
3706 */
3707 void
3708free_all_options()
3709{
3710 int i;
3711
3712 for (i = 0; !istermoption(&options[i]); i++)
3713 {
3714 if (options[i].indir == PV_NONE)
3715 {
3716 /* global option: free value and default value. */
3717 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3718 free_string_option(*(char_u **)options[i].var);
3719 if (options[i].flags & P_DEF_ALLOCED)
3720 free_string_option(options[i].def_val[VI_DEFAULT]);
3721 }
3722 else if (options[i].var != VAR_WIN
3723 && (options[i].flags & P_STRING))
3724 /* buffer-local option: free global value */
3725 free_string_option(*(char_u **)options[i].var);
3726 }
3727}
3728#endif
3729
3730
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731/*
3732 * Initialize the options, part two: After getting Rows and Columns and
3733 * setting 'term'.
3734 */
3735 void
3736set_init_2()
3737{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003738 int idx;
3739
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740 /*
3741 * 'scroll' defaults to half the window height. Note that this default is
3742 * wrong when the window height changes.
3743 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003744 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003745 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003746 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003747 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 comp_col();
3749
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003750 /*
3751 * 'window' is only for backwards compatibility with Vi.
3752 * Default is Rows - 1.
3753 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003754 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003755 p_window = Rows - 1;
3756 set_number_default("window", Rows - 1);
3757
Bram Moolenaarf740b292006-02-16 22:11:02 +00003758 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003760 /*
3761 * If 'background' wasn't set by the user, try guessing the value,
3762 * depending on the terminal name. Only need to check for terminals
3763 * with a dark background, that can handle color.
3764 */
3765 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003766 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3767 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003769 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003770 /* don't mark it as set, when starting the GUI it may be
3771 * changed again */
3772 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 }
3774#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003775
3776#ifdef CURSOR_SHAPE
3777 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3778#endif
3779#ifdef FEAT_MOUSESHAPE
3780 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3781#endif
3782#ifdef FEAT_PRINTER
3783 (void)parse_printoptions(); /* parse 'printoptions' default value */
3784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785}
3786
3787/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003788 * Return "dark" or "light" depending on the kind of terminal.
3789 * This is just guessing! Recognized are:
3790 * "linux" Linux console
3791 * "screen.linux" Linux console with screen
3792 * "cygwin" Cygwin shell
3793 * "putty" Putty program
3794 * We also check the COLORFGBG environment variable, which is set by
3795 * rxvt and derivatives. This variable contains either two or three
3796 * values separated by semicolons; we want the last value in either
3797 * case. If this value is 0-6 or 8, our background is dark.
3798 */
3799 static char_u *
3800term_bg_default()
3801{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003802#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3803 /* DOS console nearly always black */
3804 return (char_u *)"dark";
3805#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003806 char_u *p;
3807
Bram Moolenaarf740b292006-02-16 22:11:02 +00003808 if (STRCMP(T_NAME, "linux") == 0
3809 || STRCMP(T_NAME, "screen.linux") == 0
3810 || STRCMP(T_NAME, "cygwin") == 0
3811 || STRCMP(T_NAME, "putty") == 0
3812 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3813 && (p = vim_strrchr(p, ';')) != NULL
3814 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3815 && p[2] == NUL))
3816 return (char_u *)"dark";
3817 return (char_u *)"light";
3818#endif
3819}
3820
3821/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822 * Initialize the options, part three: After reading the .vimrc
3823 */
3824 void
3825set_init_3()
3826{
3827#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3828/*
3829 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3830 * This is done after other initializations, where 'shell' might have been
3831 * set, but only if they have not been set before.
3832 */
3833 char_u *p;
3834 int idx_srr;
3835 int do_srr;
3836#ifdef FEAT_QUICKFIX
3837 int idx_sp;
3838 int do_sp;
3839#endif
3840
3841 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003842 if (idx_srr < 0)
3843 do_srr = FALSE;
3844 else
3845 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846#ifdef FEAT_QUICKFIX
3847 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003848 if (idx_sp < 0)
3849 do_sp = FALSE;
3850 else
3851 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003853 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 if (p != NULL)
3855 {
3856 /*
3857 * Default for p_sp is "| tee", for p_srr is ">".
3858 * For known shells it is changed here to include stderr.
3859 */
3860 if ( fnamecmp(p, "csh") == 0
3861 || fnamecmp(p, "tcsh") == 0
3862# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3863 || fnamecmp(p, "csh.exe") == 0
3864 || fnamecmp(p, "tcsh.exe") == 0
3865# endif
3866 )
3867 {
3868#if defined(FEAT_QUICKFIX)
3869 if (do_sp)
3870 {
3871# ifdef WIN3264
3872 p_sp = (char_u *)">&";
3873# else
3874 p_sp = (char_u *)"|& tee";
3875# endif
3876 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3877 }
3878#endif
3879 if (do_srr)
3880 {
3881 p_srr = (char_u *)">&";
3882 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3883 }
3884 }
3885 else
3886# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3887 if ( fnamecmp(p, "sh") == 0
3888 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003889 || fnamecmp(p, "mksh") == 0
3890 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003892 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003894 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895# ifdef WIN3264
3896 || fnamecmp(p, "cmd") == 0
3897 || fnamecmp(p, "sh.exe") == 0
3898 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003899 || fnamecmp(p, "mksh.exe") == 0
3900 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003902 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903 || fnamecmp(p, "bash.exe") == 0
3904 || fnamecmp(p, "cmd.exe") == 0
3905# endif
3906 )
3907# endif
3908 {
3909#if defined(FEAT_QUICKFIX)
3910 if (do_sp)
3911 {
3912# ifdef WIN3264
3913 p_sp = (char_u *)">%s 2>&1";
3914# else
3915 p_sp = (char_u *)"2>&1| tee";
3916# endif
3917 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3918 }
3919#endif
3920 if (do_srr)
3921 {
3922 p_srr = (char_u *)">%s 2>&1";
3923 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3924 }
3925 }
3926 vim_free(p);
3927 }
3928#endif
3929
3930#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3931 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003932 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3933 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 * This is done after other initializations, where 'shell' might have been
3935 * set, but only if they have not been set before. Default for p_shcf is
3936 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3937 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3938 * command.com. And for Win32 we need to set p_sxq instead.
3939 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003940 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 {
3942 int idx3;
3943
3944 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003945 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946 {
3947 p_shcf = (char_u *)"-c";
3948 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3949 }
3950
3951# ifndef DJGPP
3952# ifdef WIN3264
3953 /* Somehow Win32 requires the quotes around the redirection too */
3954 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003955 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 {
3957 p_sxq = (char_u *)"\"";
3958 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3959 }
3960# else
3961 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003962 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 {
3964 p_shq = (char_u *)"\"";
3965 options[idx3].def_val[VI_DEFAULT] = p_shq;
3966 }
3967# endif
3968# endif
3969 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003970 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3971 {
3972 int idx3;
3973
3974 /*
3975 * cmd.exe on Windows will strip the first and last double quote given
3976 * on the command line, e.g. most of the time things like:
3977 * cmd /c "my path/to/echo" "my args to echo"
3978 * become:
3979 * my path/to/echo" "my args to echo
3980 * when executed.
3981 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003982 * To avoid this, set shellxquote to surround the command in
3983 * parenthesis. This appears to make most commands work, without
3984 * breaking commands that worked previously, such as
3985 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003986 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003987 idx3 = findoption((char_u *)"sxq");
3988 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3989 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003990 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003991 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3992 }
3993
Bram Moolenaara64ba222012-02-12 23:23:31 +01003994 idx3 = findoption((char_u *)"shcf");
3995 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3996 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003997 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003998 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3999 }
4000 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004001#endif
4002
4003#ifdef FEAT_TITLE
4004 set_title_defaults();
4005#endif
4006}
4007
4008#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4009/*
4010 * When 'helplang' is still at its default value, set it to "lang".
4011 * Only the first two characters of "lang" are used.
4012 */
4013 void
4014set_helplang_default(lang)
4015 char_u *lang;
4016{
4017 int idx;
4018
4019 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4020 return;
4021 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004022 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023 {
4024 if (options[idx].flags & P_ALLOCED)
4025 free_string_option(p_hlg);
4026 p_hlg = vim_strsave(lang);
4027 if (p_hlg == NULL)
4028 p_hlg = empty_option;
4029 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004030 {
4031 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4032 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4033 {
4034 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4035 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004038 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 options[idx].flags |= P_ALLOCED;
4040 }
4041}
4042#endif
4043
4044#ifdef FEAT_GUI
4045static char_u *gui_bg_default __ARGS((void));
4046
4047 static char_u *
4048gui_bg_default()
4049{
4050 if (gui_get_lightness(gui.back_pixel) < 127)
4051 return (char_u *)"dark";
4052 return (char_u *)"light";
4053}
4054
4055/*
4056 * Option initializations that can only be done after opening the GUI window.
4057 */
4058 void
4059init_gui_options()
4060{
4061 /* Set the 'background' option according to the lightness of the
4062 * background color, unless the user has set it already. */
4063 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4064 {
4065 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4066 highlight_changed();
4067 }
4068}
4069#endif
4070
4071#ifdef FEAT_TITLE
4072/*
4073 * 'title' and 'icon' only default to true if they have not been set or reset
4074 * in .vimrc and we can read the old value.
4075 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4076 * they can be reset. This reduces startup time when using X on a remote
4077 * machine.
4078 */
4079 void
4080set_title_defaults()
4081{
4082 int idx1;
4083 long val;
4084
4085 /*
4086 * If GUI is (going to be) used, we can always set the window title and
4087 * icon name. Saves a bit of time, because the X11 display server does
4088 * not need to be contacted.
4089 */
4090 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004091 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 {
4093#ifdef FEAT_GUI
4094 if (gui.starting || gui.in_use)
4095 val = TRUE;
4096 else
4097#endif
4098 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004099 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 p_title = val;
4101 }
4102 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004103 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 {
4105#ifdef FEAT_GUI
4106 if (gui.starting || gui.in_use)
4107 val = TRUE;
4108 else
4109#endif
4110 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004111 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 p_icon = val;
4113 }
4114}
4115#endif
4116
4117/*
4118 * Parse 'arg' for option settings.
4119 *
4120 * 'arg' may be IObuff, but only when no errors can be present and option
4121 * does not need to be expanded with option_expand().
4122 * "opt_flags":
4123 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004124 * OPT_GLOBAL for ":setglobal"
4125 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004127 * OPT_WINONLY to only set window-local options
4128 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 *
4130 * returns FAIL if an error is detected, OK otherwise
4131 */
4132 int
4133do_set(arg, opt_flags)
4134 char_u *arg; /* option string (may be written to!) */
4135 int opt_flags;
4136{
4137 int opt_idx;
4138 char_u *errmsg;
4139 char_u errbuf[80];
4140 char_u *startarg;
4141 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4142 int nextchar; /* next non-white char after option name */
4143 int afterchar; /* character just after option name */
4144 int len;
4145 int i;
4146 long value;
4147 int key;
4148 long_u flags; /* flags for current option */
4149 char_u *varp = NULL; /* pointer to variable for current option */
4150 int did_show = FALSE; /* already showed one value */
4151 int adding; /* "opt+=arg" */
4152 int prepending; /* "opt^=arg" */
4153 int removing; /* "opt-=arg" */
4154 int cp_val = 0;
4155 char_u key_name[2];
4156
4157 if (*arg == NUL)
4158 {
4159 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004160 did_show = TRUE;
4161 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004162 }
4163
4164 while (*arg != NUL) /* loop to process all options */
4165 {
4166 errmsg = NULL;
4167 startarg = arg; /* remember for error message */
4168
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004169 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4170 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 {
4172 /*
4173 * ":set all" show all options.
4174 * ":set all&" set all options to their default value.
4175 */
4176 arg += 3;
4177 if (*arg == '&')
4178 {
4179 ++arg;
4180 /* Only for :set command set global value of local options. */
4181 set_options_default(OPT_FREE | opt_flags);
4182 }
4183 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004184 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004185 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004186 did_show = TRUE;
4187 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004188 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004189 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190 {
4191 showoptions(2, opt_flags);
4192 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004193 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194 arg += 7;
4195 }
4196 else
4197 {
4198 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004199 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004200 {
4201 prefix = 0;
4202 arg += 2;
4203 }
4204 else if (STRNCMP(arg, "inv", 3) == 0)
4205 {
4206 prefix = 2;
4207 arg += 3;
4208 }
4209
4210 /* find end of name */
4211 key = 0;
4212 if (*arg == '<')
4213 {
4214 nextchar = 0;
4215 opt_idx = -1;
4216 /* look out for <t_>;> */
4217 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4218 len = 5;
4219 else
4220 {
4221 len = 1;
4222 while (arg[len] != NUL && arg[len] != '>')
4223 ++len;
4224 }
4225 if (arg[len] != '>')
4226 {
4227 errmsg = e_invarg;
4228 goto skip;
4229 }
4230 arg[len] = NUL; /* put NUL after name */
4231 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4232 opt_idx = findoption(arg + 1);
4233 arg[len++] = '>'; /* restore '>' */
4234 if (opt_idx == -1)
4235 key = find_key_option(arg + 1);
4236 }
4237 else
4238 {
4239 len = 0;
4240 /*
4241 * The two characters after "t_" may not be alphanumeric.
4242 */
4243 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4244 len = 4;
4245 else
4246 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4247 ++len;
4248 nextchar = arg[len];
4249 arg[len] = NUL; /* put NUL after name */
4250 opt_idx = findoption(arg);
4251 arg[len] = nextchar; /* restore nextchar */
4252 if (opt_idx == -1)
4253 key = find_key_option(arg);
4254 }
4255
4256 /* remember character after option name */
4257 afterchar = arg[len];
4258
4259 /* skip white space, allow ":set ai ?" */
4260 while (vim_iswhite(arg[len]))
4261 ++len;
4262
4263 adding = FALSE;
4264 prepending = FALSE;
4265 removing = FALSE;
4266 if (arg[len] != NUL && arg[len + 1] == '=')
4267 {
4268 if (arg[len] == '+')
4269 {
4270 adding = TRUE; /* "+=" */
4271 ++len;
4272 }
4273 else if (arg[len] == '^')
4274 {
4275 prepending = TRUE; /* "^=" */
4276 ++len;
4277 }
4278 else if (arg[len] == '-')
4279 {
4280 removing = TRUE; /* "-=" */
4281 ++len;
4282 }
4283 }
4284 nextchar = arg[len];
4285
4286 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4287 {
4288 errmsg = (char_u *)N_("E518: Unknown option");
4289 goto skip;
4290 }
4291
4292 if (opt_idx >= 0)
4293 {
4294 if (options[opt_idx].var == NULL) /* hidden option: skip */
4295 {
4296 /* Only give an error message when requesting the value of
4297 * a hidden option, ignore setting it. */
4298 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4299 && (!(options[opt_idx].flags & P_BOOL)
4300 || nextchar == '?'))
4301 errmsg = (char_u *)N_("E519: Option not supported");
4302 goto skip;
4303 }
4304
4305 flags = options[opt_idx].flags;
4306 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4307 }
4308 else
4309 {
4310 flags = P_STRING;
4311 if (key < 0)
4312 {
4313 key_name[0] = KEY2TERMCAP0(key);
4314 key_name[1] = KEY2TERMCAP1(key);
4315 }
4316 else
4317 {
4318 key_name[0] = KS_KEY;
4319 key_name[1] = (key & 0xff);
4320 }
4321 }
4322
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004323 /* Skip all options that are not window-local (used when showing
4324 * an already loaded buffer in a window). */
4325 if ((opt_flags & OPT_WINONLY)
4326 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4327 goto skip;
4328
Bram Moolenaara3227e22006-03-08 21:32:40 +00004329 /* Skip all options that are window-local (used for :vimgrep). */
4330 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4331 && options[opt_idx].var == VAR_WIN)
4332 goto skip;
4333
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004334 /* Disallow changing some options from modelines. */
4335 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004336 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004337 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004338 {
4339 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4340 goto skip;
4341 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004342#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004343 /* In diff mode some options are overruled. This avoids that
4344 * 'foldmethod' becomes "marker" instead of "diff" and that
4345 * "wrap" gets set. */
4346 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004347 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004348 && (options[opt_idx].indir == PV_FDM
4349 || options[opt_idx].indir == PV_WRAP))
4350 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004351#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004352 }
4353
4354#ifdef HAVE_SANDBOX
4355 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004356 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004357 {
4358 errmsg = (char_u *)_(e_sandbox);
4359 goto skip;
4360 }
4361#endif
4362
4363 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4364 {
4365 arg += len;
4366 cp_val = p_cp;
4367 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4368 {
4369 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4370 {
4371 cp_val = FALSE;
4372 arg += 3;
4373 }
4374 else /* "opt&vi": set to Vi default */
4375 {
4376 cp_val = TRUE;
4377 arg += 2;
4378 }
4379 }
4380 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4381 && arg[1] != NUL && !vim_iswhite(arg[1]))
4382 {
4383 errmsg = e_trailing;
4384 goto skip;
4385 }
4386 }
4387
4388 /*
4389 * allow '=' and ':' as MSDOS command.com allows only one
4390 * '=' character per "set" command line. grrr. (jw)
4391 */
4392 if (nextchar == '?'
4393 || (prefix == 1
4394 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4395 && !(flags & P_BOOL)))
4396 {
4397 /*
4398 * print value
4399 */
4400 if (did_show)
4401 msg_putchar('\n'); /* cursor below last one */
4402 else
4403 {
4404 gotocmdline(TRUE); /* cursor at status line */
4405 did_show = TRUE; /* remember that we did a line */
4406 }
4407 if (opt_idx >= 0)
4408 {
4409 showoneopt(&options[opt_idx], opt_flags);
4410#ifdef FEAT_EVAL
4411 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004412 {
4413 /* Mention where the option was last set. */
4414 if (varp == options[opt_idx].var)
4415 last_set_msg(options[opt_idx].scriptID);
4416 else if ((int)options[opt_idx].indir & PV_WIN)
4417 last_set_msg(curwin->w_p_scriptID[
4418 (int)options[opt_idx].indir & PV_MASK]);
4419 else if ((int)options[opt_idx].indir & PV_BUF)
4420 last_set_msg(curbuf->b_p_scriptID[
4421 (int)options[opt_idx].indir & PV_MASK]);
4422 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004423#endif
4424 }
4425 else
4426 {
4427 char_u *p;
4428
4429 p = find_termcode(key_name);
4430 if (p == NULL)
4431 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004432 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004433 goto skip;
4434 }
4435 else
4436 (void)show_one_termcode(key_name, p, TRUE);
4437 }
4438 if (nextchar != '?'
4439 && nextchar != NUL && !vim_iswhite(afterchar))
4440 errmsg = e_trailing;
4441 }
4442 else
4443 {
4444 if (flags & P_BOOL) /* boolean */
4445 {
4446 if (nextchar == '=' || nextchar == ':')
4447 {
4448 errmsg = e_invarg;
4449 goto skip;
4450 }
4451
4452 /*
4453 * ":set opt!": invert
4454 * ":set opt&": reset to default value
4455 * ":set opt<": reset to global value
4456 */
4457 if (nextchar == '!')
4458 value = *(int *)(varp) ^ 1;
4459 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004460 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004461 ((flags & P_VI_DEF) || cp_val)
4462 ? VI_DEFAULT : VIM_DEFAULT];
4463 else if (nextchar == '<')
4464 {
4465 /* For 'autoread' -1 means to use global value. */
4466 if ((int *)varp == &curbuf->b_p_ar
4467 && opt_flags == OPT_LOCAL)
4468 value = -1;
4469 else
4470 value = *(int *)get_varp_scope(&(options[opt_idx]),
4471 OPT_GLOBAL);
4472 }
4473 else
4474 {
4475 /*
4476 * ":set invopt": invert
4477 * ":set opt" or ":set noopt": set or reset
4478 */
4479 if (nextchar != NUL && !vim_iswhite(afterchar))
4480 {
4481 errmsg = e_trailing;
4482 goto skip;
4483 }
4484 if (prefix == 2) /* inv */
4485 value = *(int *)(varp) ^ 1;
4486 else
4487 value = prefix;
4488 }
4489
4490 errmsg = set_bool_option(opt_idx, varp, (int)value,
4491 opt_flags);
4492 }
4493 else /* numeric or string */
4494 {
4495 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4496 || prefix != 1)
4497 {
4498 errmsg = e_invarg;
4499 goto skip;
4500 }
4501
4502 if (flags & P_NUM) /* numeric */
4503 {
4504 /*
4505 * Different ways to set a number option:
4506 * & set to default value
4507 * < set to global value
4508 * <xx> accept special key codes for 'wildchar'
4509 * c accept any non-digit for 'wildchar'
4510 * [-]0-9 set number
4511 * other error
4512 */
4513 ++arg;
4514 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004515 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004516 ((flags & P_VI_DEF) || cp_val)
4517 ? VI_DEFAULT : VIM_DEFAULT];
4518 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004519 {
4520 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4521 * use the global value. */
4522 if ((long *)varp == &curbuf->b_p_ul
4523 && opt_flags == OPT_LOCAL)
4524 value = NO_LOCAL_UNDOLEVEL;
4525 else
4526 value = *(long *)get_varp_scope(
4527 &(options[opt_idx]), OPT_GLOBAL);
4528 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004529 else if (((long *)varp == &p_wc
4530 || (long *)varp == &p_wcm)
4531 && (*arg == '<'
4532 || *arg == '^'
4533 || ((!arg[1] || vim_iswhite(arg[1]))
4534 && !VIM_ISDIGIT(*arg))))
4535 {
4536 value = string_to_key(arg);
4537 if (value == 0 && (long *)varp != &p_wcm)
4538 {
4539 errmsg = e_invarg;
4540 goto skip;
4541 }
4542 }
4543 /* allow negative numbers (for 'undolevels') */
4544 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4545 {
4546 i = 0;
4547 if (*arg == '-')
4548 i = 1;
4549#ifdef HAVE_STRTOL
4550 value = strtol((char *)arg, NULL, 0);
4551 if (arg[i] == '0' && TOLOWER_ASC(arg[i + 1]) == 'x')
4552 i += 2;
4553#else
4554 value = atol((char *)arg);
4555#endif
4556 while (VIM_ISDIGIT(arg[i]))
4557 ++i;
4558 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4559 {
4560 errmsg = e_invarg;
4561 goto skip;
4562 }
4563 }
4564 else
4565 {
4566 errmsg = (char_u *)N_("E521: Number required after =");
4567 goto skip;
4568 }
4569
4570 if (adding)
4571 value = *(long *)varp + value;
4572 if (prepending)
4573 value = *(long *)varp * value;
4574 if (removing)
4575 value = *(long *)varp - value;
4576 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004577 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004578 }
4579 else if (opt_idx >= 0) /* string */
4580 {
4581 char_u *save_arg = NULL;
4582 char_u *s = NULL;
4583 char_u *oldval; /* previous value if *varp */
4584 char_u *newval;
4585 char_u *origval;
4586 unsigned newlen;
4587 int comma;
4588 int bs;
4589 int new_value_alloced; /* new string option
4590 was allocated */
4591
4592 /* When using ":set opt=val" for a global option
4593 * with a local value the local value will be
4594 * reset, use the global value here. */
4595 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004596 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004597 varp = options[opt_idx].var;
4598
4599 /* The old value is kept until we are sure that the
4600 * new value is valid. */
4601 oldval = *(char_u **)varp;
4602 if (nextchar == '&') /* set to default val */
4603 {
4604 newval = options[opt_idx].def_val[
4605 ((flags & P_VI_DEF) || cp_val)
4606 ? VI_DEFAULT : VIM_DEFAULT];
4607 if ((char_u **)varp == &p_bg)
4608 {
4609 /* guess the value of 'background' */
4610#ifdef FEAT_GUI
4611 if (gui.in_use)
4612 newval = gui_bg_default();
4613 else
4614#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004615 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004616 }
4617
4618 /* expand environment variables and ~ (since the
4619 * default value was already expanded, only
4620 * required when an environment variable was set
4621 * later */
4622 if (newval == NULL)
4623 newval = empty_option;
4624 else
4625 {
4626 s = option_expand(opt_idx, newval);
4627 if (s == NULL)
4628 s = newval;
4629 newval = vim_strsave(s);
4630 }
4631 new_value_alloced = TRUE;
4632 }
4633 else if (nextchar == '<') /* set to global val */
4634 {
4635 newval = vim_strsave(*(char_u **)get_varp_scope(
4636 &(options[opt_idx]), OPT_GLOBAL));
4637 new_value_alloced = TRUE;
4638 }
4639 else
4640 {
4641 ++arg; /* jump to after the '=' or ':' */
4642
4643 /*
4644 * Set 'keywordprg' to ":help" if an empty
4645 * value was passed to :set by the user.
4646 * Misuse errbuf[] for the resulting string.
4647 */
4648 if (varp == (char_u *)&p_kp
4649 && (*arg == NUL || *arg == ' '))
4650 {
4651 STRCPY(errbuf, ":help");
4652 save_arg = arg;
4653 arg = errbuf;
4654 }
4655 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004656 * Convert 'backspace' number to string, for
4657 * adding, prepending and removing string.
4658 */
4659 else if (varp == (char_u *)&p_bs
4660 && VIM_ISDIGIT(**(char_u **)varp))
4661 {
4662 i = getdigits((char_u **)varp);
4663 switch (i)
4664 {
4665 case 0:
4666 *(char_u **)varp = empty_option;
4667 break;
4668 case 1:
4669 *(char_u **)varp = vim_strsave(
4670 (char_u *)"indent,eol");
4671 break;
4672 case 2:
4673 *(char_u **)varp = vim_strsave(
4674 (char_u *)"indent,eol,start");
4675 break;
4676 }
4677 vim_free(oldval);
4678 oldval = *(char_u **)varp;
4679 }
4680 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004681 * Convert 'whichwrap' number to string, for
4682 * backwards compatibility with Vim 3.0.
4683 * Misuse errbuf[] for the resulting string.
4684 */
4685 else if (varp == (char_u *)&p_ww
4686 && VIM_ISDIGIT(*arg))
4687 {
4688 *errbuf = NUL;
4689 i = getdigits(&arg);
4690 if (i & 1)
4691 STRCAT(errbuf, "b,");
4692 if (i & 2)
4693 STRCAT(errbuf, "s,");
4694 if (i & 4)
4695 STRCAT(errbuf, "h,l,");
4696 if (i & 8)
4697 STRCAT(errbuf, "<,>,");
4698 if (i & 16)
4699 STRCAT(errbuf, "[,],");
4700 if (*errbuf != NUL) /* remove trailing , */
4701 errbuf[STRLEN(errbuf) - 1] = NUL;
4702 save_arg = arg;
4703 arg = errbuf;
4704 }
4705 /*
4706 * Remove '>' before 'dir' and 'bdir', for
4707 * backwards compatibility with version 3.0
4708 */
4709 else if ( *arg == '>'
4710 && (varp == (char_u *)&p_dir
4711 || varp == (char_u *)&p_bdir))
4712 {
4713 ++arg;
4714 }
4715
4716 /* When setting the local value of a global
4717 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004718 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004719 && (opt_flags & OPT_LOCAL))
4720 origval = *(char_u **)get_varp(
4721 &options[opt_idx]);
4722 else
4723 origval = oldval;
4724
4725 /*
4726 * Copy the new string into allocated memory.
4727 * Can't use set_string_option_direct(), because
4728 * we need to remove the backslashes.
4729 */
4730 /* get a bit too much */
4731 newlen = (unsigned)STRLEN(arg) + 1;
4732 if (adding || prepending || removing)
4733 newlen += (unsigned)STRLEN(origval) + 1;
4734 newval = alloc(newlen);
4735 if (newval == NULL) /* out of mem, don't change */
4736 break;
4737 s = newval;
4738
4739 /*
4740 * Copy the string, skip over escaped chars.
4741 * For MS-DOS and WIN32 backslashes before normal
4742 * file name characters are not removed, and keep
4743 * backslash at start, for "\\machine\path", but
4744 * do remove it for "\\\\machine\\path".
4745 * The reverse is found in ExpandOldSetting().
4746 */
4747 while (*arg && !vim_iswhite(*arg))
4748 {
4749 if (*arg == '\\' && arg[1] != NUL
4750#ifdef BACKSLASH_IN_FILENAME
4751 && !((flags & P_EXPAND)
4752 && vim_isfilec(arg[1])
4753 && (arg[1] != '\\'
4754 || (s == newval
4755 && arg[2] != '\\')))
4756#endif
4757 )
4758 ++arg; /* remove backslash */
4759#ifdef FEAT_MBYTE
4760 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004761 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004762 {
4763 /* copy multibyte char */
4764 mch_memmove(s, arg, (size_t)i);
4765 arg += i;
4766 s += i;
4767 }
4768 else
4769#endif
4770 *s++ = *arg++;
4771 }
4772 *s = NUL;
4773
4774 /*
4775 * Expand environment variables and ~.
4776 * Don't do it when adding without inserting a
4777 * comma.
4778 */
4779 if (!(adding || prepending || removing)
4780 || (flags & P_COMMA))
4781 {
4782 s = option_expand(opt_idx, newval);
4783 if (s != NULL)
4784 {
4785 vim_free(newval);
4786 newlen = (unsigned)STRLEN(s) + 1;
4787 if (adding || prepending || removing)
4788 newlen += (unsigned)STRLEN(origval) + 1;
4789 newval = alloc(newlen);
4790 if (newval == NULL)
4791 break;
4792 STRCPY(newval, s);
4793 }
4794 }
4795
4796 /* locate newval[] in origval[] when removing it
4797 * and when adding to avoid duplicates */
4798 i = 0; /* init for GCC */
4799 if (removing || (flags & P_NODUP))
4800 {
4801 i = (int)STRLEN(newval);
4802 bs = 0;
4803 for (s = origval; *s; ++s)
4804 {
4805 if ((!(flags & P_COMMA)
4806 || s == origval
4807 || (s[-1] == ',' && !(bs & 1)))
4808 && STRNCMP(s, newval, i) == 0
4809 && (!(flags & P_COMMA)
4810 || s[i] == ','
4811 || s[i] == NUL))
4812 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004813 /* Count backslashes. Only a comma with an
4814 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004815 * recognized as a separator */
4816 if (s > origval && s[-1] == '\\')
4817 ++bs;
4818 else
4819 bs = 0;
4820 }
4821
4822 /* do not add if already there */
4823 if ((adding || prepending) && *s)
4824 {
4825 prepending = FALSE;
4826 adding = FALSE;
4827 STRCPY(newval, origval);
4828 }
4829 }
4830
4831 /* concatenate the two strings; add a ',' if
4832 * needed */
4833 if (adding || prepending)
4834 {
4835 comma = ((flags & P_COMMA) && *origval != NUL
4836 && *newval != NUL);
4837 if (adding)
4838 {
4839 i = (int)STRLEN(origval);
4840 mch_memmove(newval + i + comma, newval,
4841 STRLEN(newval) + 1);
4842 mch_memmove(newval, origval, (size_t)i);
4843 }
4844 else
4845 {
4846 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004847 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004848 }
4849 if (comma)
4850 newval[i] = ',';
4851 }
4852
4853 /* Remove newval[] from origval[]. (Note: "i" has
4854 * been set above and is used here). */
4855 if (removing)
4856 {
4857 STRCPY(newval, origval);
4858 if (*s)
4859 {
4860 /* may need to remove a comma */
4861 if (flags & P_COMMA)
4862 {
4863 if (s == origval)
4864 {
4865 /* include comma after string */
4866 if (s[i] == ',')
4867 ++i;
4868 }
4869 else
4870 {
4871 /* include comma before string */
4872 --s;
4873 ++i;
4874 }
4875 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004876 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004877 }
4878 }
4879
4880 if (flags & P_FLAGLIST)
4881 {
4882 /* Remove flags that appear twice. */
4883 for (s = newval; *s; ++s)
4884 if ((!(flags & P_COMMA) || *s != ',')
4885 && vim_strchr(s + 1, *s) != NULL)
4886 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004887 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004888 --s;
4889 }
4890 }
4891
4892 if (save_arg != NULL) /* number for 'whichwrap' */
4893 arg = save_arg;
4894 new_value_alloced = TRUE;
4895 }
4896
4897 /* Set the new value. */
4898 *(char_u **)(varp) = newval;
4899
4900 /* Handle side effects, and set the global value for
4901 * ":set" on local options. */
4902 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4903 new_value_alloced, oldval, errbuf, opt_flags);
4904
4905 /* If error detected, print the error message. */
4906 if (errmsg != NULL)
4907 goto skip;
4908 }
4909 else /* key code option */
4910 {
4911 char_u *p;
4912
4913 if (nextchar == '&')
4914 {
4915 if (add_termcap_entry(key_name, TRUE) == FAIL)
4916 errmsg = (char_u *)N_("E522: Not found in termcap");
4917 }
4918 else
4919 {
4920 ++arg; /* jump to after the '=' or ':' */
4921 for (p = arg; *p && !vim_iswhite(*p); ++p)
4922 if (*p == '\\' && p[1] != NUL)
4923 ++p;
4924 nextchar = *p;
4925 *p = NUL;
4926 add_termcode(key_name, arg, FALSE);
4927 *p = nextchar;
4928 }
4929 if (full_screen)
4930 ttest(FALSE);
4931 redraw_all_later(CLEAR);
4932 }
4933 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004934
Bram Moolenaar071d4272004-06-13 20:20:40 +00004935 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004936 did_set_option(opt_idx, opt_flags,
4937 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004938 }
4939
4940skip:
4941 /*
4942 * Advance to next argument.
4943 * - skip until a blank found, taking care of backslashes
4944 * - skip blanks
4945 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4946 */
4947 for (i = 0; i < 2 ; ++i)
4948 {
4949 while (*arg != NUL && !vim_iswhite(*arg))
4950 if (*arg++ == '\\' && *arg != NUL)
4951 ++arg;
4952 arg = skipwhite(arg);
4953 if (*arg != '=')
4954 break;
4955 }
4956 }
4957
4958 if (errmsg != NULL)
4959 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004960 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004961 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004962 if (i + (arg - startarg) < IOSIZE)
4963 {
4964 /* append the argument with the error */
4965 STRCAT(IObuff, ": ");
4966 mch_memmove(IObuff + i, startarg, (arg - startarg));
4967 IObuff[i + (arg - startarg)] = NUL;
4968 }
4969 /* make sure all characters are printable */
4970 trans_characters(IObuff, IOSIZE);
4971
4972 ++no_wait_return; /* wait_return done later */
4973 emsg(IObuff); /* show error highlighted */
4974 --no_wait_return;
4975
4976 return FAIL;
4977 }
4978
4979 arg = skipwhite(arg);
4980 }
4981
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004982theend:
4983 if (silent_mode && did_show)
4984 {
4985 /* After displaying option values in silent mode. */
4986 silent_mode = FALSE;
4987 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4988 msg_putchar('\n');
4989 cursor_on(); /* msg_start() switches it off */
4990 out_flush();
4991 silent_mode = TRUE;
4992 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4993 }
4994
Bram Moolenaar071d4272004-06-13 20:20:40 +00004995 return OK;
4996}
4997
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004998/*
4999 * Call this when an option has been given a new value through a user command.
5000 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5001 */
5002 static void
5003did_set_option(opt_idx, opt_flags, new_value)
5004 int opt_idx;
5005 int opt_flags; /* possibly with OPT_MODELINE */
5006 int new_value; /* value was replaced completely */
5007{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005008 long_u *p;
5009
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005010 options[opt_idx].flags |= P_WAS_SET;
5011
5012 /* When an option is set in the sandbox, from a modeline or in secure mode
5013 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005014 * flag. */
5015 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005016 if (secure
5017#ifdef HAVE_SANDBOX
5018 || sandbox != 0
5019#endif
5020 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005021 *p = *p | P_INSECURE;
5022 else if (new_value)
5023 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005024}
5025
Bram Moolenaar071d4272004-06-13 20:20:40 +00005026 static char_u *
5027illegal_char(errbuf, c)
5028 char_u *errbuf;
5029 int c;
5030{
5031 if (errbuf == NULL)
5032 return (char_u *)"";
5033 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005034 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005035 return errbuf;
5036}
5037
5038/*
5039 * Convert a key name or string into a key value.
5040 * Used for 'wildchar' and 'cedit' options.
5041 */
5042 static int
5043string_to_key(arg)
5044 char_u *arg;
5045{
5046 if (*arg == '<')
5047 return find_key_option(arg + 1);
5048 if (*arg == '^')
5049 return Ctrl_chr(arg[1]);
5050 return *arg;
5051}
5052
5053#ifdef FEAT_CMDWIN
5054/*
5055 * Check value of 'cedit' and set cedit_key.
5056 * Returns NULL if value is OK, error message otherwise.
5057 */
5058 static char_u *
5059check_cedit()
5060{
5061 int n;
5062
5063 if (*p_cedit == NUL)
5064 cedit_key = -1;
5065 else
5066 {
5067 n = string_to_key(p_cedit);
5068 if (vim_isprintc(n))
5069 return e_invarg;
5070 cedit_key = n;
5071 }
5072 return NULL;
5073}
5074#endif
5075
5076#ifdef FEAT_TITLE
5077/*
5078 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5079 * maketitle() to create and display it.
5080 * When switching the title or icon off, call mch_restore_title() to get
5081 * the old value back.
5082 */
5083 static void
5084did_set_title(icon)
5085 int icon; /* Did set icon instead of title */
5086{
5087 if (starting != NO_SCREEN
5088#ifdef FEAT_GUI
5089 && !gui.starting
5090#endif
5091 )
5092 {
5093 maketitle();
5094 if (icon)
5095 {
5096 if (!p_icon)
5097 mch_restore_title(2);
5098 }
5099 else
5100 {
5101 if (!p_title)
5102 mch_restore_title(1);
5103 }
5104 }
5105}
5106#endif
5107
5108/*
5109 * set_options_bin - called when 'bin' changes value.
5110 */
5111 void
5112set_options_bin(oldval, newval, opt_flags)
5113 int oldval;
5114 int newval;
5115 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5116{
5117 /*
5118 * The option values that are changed when 'bin' changes are
5119 * copied when 'bin is set and restored when 'bin' is reset.
5120 */
5121 if (newval)
5122 {
5123 if (!oldval) /* switched on */
5124 {
5125 if (!(opt_flags & OPT_GLOBAL))
5126 {
5127 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5128 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5129 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5130 curbuf->b_p_et_nobin = curbuf->b_p_et;
5131 }
5132 if (!(opt_flags & OPT_LOCAL))
5133 {
5134 p_tw_nobin = p_tw;
5135 p_wm_nobin = p_wm;
5136 p_ml_nobin = p_ml;
5137 p_et_nobin = p_et;
5138 }
5139 }
5140
5141 if (!(opt_flags & OPT_GLOBAL))
5142 {
5143 curbuf->b_p_tw = 0; /* no automatic line wrap */
5144 curbuf->b_p_wm = 0; /* no automatic line wrap */
5145 curbuf->b_p_ml = 0; /* no modelines */
5146 curbuf->b_p_et = 0; /* no expandtab */
5147 }
5148 if (!(opt_flags & OPT_LOCAL))
5149 {
5150 p_tw = 0;
5151 p_wm = 0;
5152 p_ml = FALSE;
5153 p_et = FALSE;
5154 p_bin = TRUE; /* needed when called for the "-b" argument */
5155 }
5156 }
5157 else if (oldval) /* switched off */
5158 {
5159 if (!(opt_flags & OPT_GLOBAL))
5160 {
5161 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5162 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5163 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5164 curbuf->b_p_et = curbuf->b_p_et_nobin;
5165 }
5166 if (!(opt_flags & OPT_LOCAL))
5167 {
5168 p_tw = p_tw_nobin;
5169 p_wm = p_wm_nobin;
5170 p_ml = p_ml_nobin;
5171 p_et = p_et_nobin;
5172 }
5173 }
5174}
5175
5176#ifdef FEAT_VIMINFO
5177/*
5178 * Find the parameter represented by the given character (eg ', :, ", or /),
5179 * and return its associated value in the 'viminfo' string.
5180 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005181 * If the parameter is not specified in the string or there is no following
5182 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005183 */
5184 int
5185get_viminfo_parameter(type)
5186 int type;
5187{
5188 char_u *p;
5189
5190 p = find_viminfo_parameter(type);
5191 if (p != NULL && VIM_ISDIGIT(*p))
5192 return atoi((char *)p);
5193 return -1;
5194}
5195
5196/*
5197 * Find the parameter represented by the given character (eg ''', ':', '"', or
5198 * '/') in the 'viminfo' option and return a pointer to the string after it.
5199 * Return NULL if the parameter is not specified in the string.
5200 */
5201 char_u *
5202find_viminfo_parameter(type)
5203 int type;
5204{
5205 char_u *p;
5206
5207 for (p = p_viminfo; *p; ++p)
5208 {
5209 if (*p == type)
5210 return p + 1;
5211 if (*p == 'n') /* 'n' is always the last one */
5212 break;
5213 p = vim_strchr(p, ','); /* skip until next ',' */
5214 if (p == NULL) /* hit the end without finding parameter */
5215 break;
5216 }
5217 return NULL;
5218}
5219#endif
5220
5221/*
5222 * Expand environment variables for some string options.
5223 * These string options cannot be indirect!
5224 * If "val" is NULL expand the current value of the option.
5225 * Return pointer to NameBuff, or NULL when not expanded.
5226 */
5227 static char_u *
5228option_expand(opt_idx, val)
5229 int opt_idx;
5230 char_u *val;
5231{
5232 /* if option doesn't need expansion nothing to do */
5233 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5234 return NULL;
5235
5236 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5237 * expand_env() would truncate the string. */
5238 if (val != NULL && STRLEN(val) > MAXPATHL)
5239 return NULL;
5240
5241 if (val == NULL)
5242 val = *(char_u **)options[opt_idx].var;
5243
5244 /*
5245 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5246 * Escape spaces when expanding 'tags', they are used to separate file
5247 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005248 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005249 */
5250 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005251 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005252#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005253 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5254#endif
5255 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005256 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5257 return NULL;
5258
5259 return NameBuff;
5260}
5261
5262/*
5263 * After setting various option values: recompute variables that depend on
5264 * option values.
5265 */
5266 static void
5267didset_options()
5268{
5269 /* initialize the table for 'iskeyword' et.al. */
5270 (void)init_chartab();
5271
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005272#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005275 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5276#ifdef FEAT_SESSION
5277 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5278 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5279#endif
5280#ifdef FEAT_FOLDING
5281 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5282#endif
5283 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5284#ifdef FEAT_VIRTUALEDIT
5285 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5286#endif
5287#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5288 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5289#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005290#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005291 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005292 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005293 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005294#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005295#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5296 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5297#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005298#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005299 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5300#endif
5301#ifdef FEAT_CMDWIN
5302 /* set cedit_key */
5303 (void)check_cedit();
5304#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005305#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005306 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308}
5309
5310/*
5311 * Check for string options that are NULL (normally only termcap options).
5312 */
5313 void
5314check_options()
5315{
5316 int opt_idx;
5317
5318 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5319 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5320 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5321}
5322
5323/*
5324 * Check string options in a buffer for NULL value.
5325 */
5326 void
5327check_buf_options(buf)
5328 buf_T *buf;
5329{
5330#if defined(FEAT_QUICKFIX)
5331 check_string_option(&buf->b_p_bh);
5332 check_string_option(&buf->b_p_bt);
5333#endif
5334#ifdef FEAT_MBYTE
5335 check_string_option(&buf->b_p_fenc);
5336#endif
5337 check_string_option(&buf->b_p_ff);
5338#ifdef FEAT_FIND_ID
5339 check_string_option(&buf->b_p_def);
5340 check_string_option(&buf->b_p_inc);
5341# ifdef FEAT_EVAL
5342 check_string_option(&buf->b_p_inex);
5343# endif
5344#endif
5345#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5346 check_string_option(&buf->b_p_inde);
5347 check_string_option(&buf->b_p_indk);
5348#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005349#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5350 check_string_option(&buf->b_p_bexpr);
5351#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005352#if defined(FEAT_CRYPT)
5353 check_string_option(&buf->b_p_cm);
5354#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005355#if defined(FEAT_EVAL)
5356 check_string_option(&buf->b_p_fex);
5357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005358#ifdef FEAT_CRYPT
5359 check_string_option(&buf->b_p_key);
5360#endif
5361 check_string_option(&buf->b_p_kp);
5362 check_string_option(&buf->b_p_mps);
5363 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005364 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005365 check_string_option(&buf->b_p_isk);
5366#ifdef FEAT_COMMENTS
5367 check_string_option(&buf->b_p_com);
5368#endif
5369#ifdef FEAT_FOLDING
5370 check_string_option(&buf->b_p_cms);
5371#endif
5372 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005373#ifdef FEAT_TEXTOBJ
5374 check_string_option(&buf->b_p_qe);
5375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376#ifdef FEAT_SYN_HL
5377 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005378#endif
5379#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005380 check_string_option(&buf->b_s.b_p_spc);
5381 check_string_option(&buf->b_s.b_p_spf);
5382 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005383#endif
5384#ifdef FEAT_SEARCHPATH
5385 check_string_option(&buf->b_p_sua);
5386#endif
5387#ifdef FEAT_CINDENT
5388 check_string_option(&buf->b_p_cink);
5389 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005390 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005391#endif
5392#ifdef FEAT_AUTOCMD
5393 check_string_option(&buf->b_p_ft);
5394#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005395#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5396 check_string_option(&buf->b_p_cinw);
5397#endif
5398#ifdef FEAT_INS_EXPAND
5399 check_string_option(&buf->b_p_cpt);
5400#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005401#ifdef FEAT_COMPL_FUNC
5402 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005403 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005405#ifdef FEAT_KEYMAP
5406 check_string_option(&buf->b_p_keymap);
5407#endif
5408#ifdef FEAT_QUICKFIX
5409 check_string_option(&buf->b_p_gp);
5410 check_string_option(&buf->b_p_mp);
5411 check_string_option(&buf->b_p_efm);
5412#endif
5413 check_string_option(&buf->b_p_ep);
5414 check_string_option(&buf->b_p_path);
5415 check_string_option(&buf->b_p_tags);
5416#ifdef FEAT_INS_EXPAND
5417 check_string_option(&buf->b_p_dict);
5418 check_string_option(&buf->b_p_tsr);
5419#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005420#ifdef FEAT_LISP
5421 check_string_option(&buf->b_p_lw);
5422#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005423 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005424}
5425
5426/*
5427 * Free the string allocated for an option.
5428 * Checks for the string being empty_option. This may happen if we're out of
5429 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5430 * check_options().
5431 * Does NOT check for P_ALLOCED flag!
5432 */
5433 void
5434free_string_option(p)
5435 char_u *p;
5436{
5437 if (p != empty_option)
5438 vim_free(p);
5439}
5440
5441 void
5442clear_string_option(pp)
5443 char_u **pp;
5444{
5445 if (*pp != empty_option)
5446 vim_free(*pp);
5447 *pp = empty_option;
5448}
5449
5450 static void
5451check_string_option(pp)
5452 char_u **pp;
5453{
5454 if (*pp == NULL)
5455 *pp = empty_option;
5456}
5457
5458/*
5459 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5460 */
5461 void
5462set_term_option_alloced(p)
5463 char_u **p;
5464{
5465 int opt_idx;
5466
5467 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5468 if (options[opt_idx].var == (char_u *)p)
5469 {
5470 options[opt_idx].flags |= P_ALLOCED;
5471 return;
5472 }
5473 return; /* cannot happen: didn't find it! */
5474}
5475
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005476#if defined(FEAT_EVAL) || defined(PROTO)
5477/*
5478 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5479 * Return FALSE when it wasn't.
5480 * Return -1 for an unknown option.
5481 */
5482 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005483was_set_insecurely(opt, opt_flags)
5484 char_u *opt;
5485 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005486{
5487 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005488 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005489
5490 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005491 {
5492 flagp = insecure_flag(idx, opt_flags);
5493 return (*flagp & P_INSECURE) != 0;
5494 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005495 EMSG2(_(e_intern2), "was_set_insecurely()");
5496 return -1;
5497}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005498
5499/*
5500 * Get a pointer to the flags used for the P_INSECURE flag of option
5501 * "opt_idx". For some local options a local flags field is used.
5502 */
5503 static long_u *
5504insecure_flag(opt_idx, opt_flags)
5505 int opt_idx;
5506 int opt_flags;
5507{
5508 if (opt_flags & OPT_LOCAL)
5509 switch ((int)options[opt_idx].indir)
5510 {
5511#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005512 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005513#endif
5514#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005515# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005516 case PV_FDE: return &curwin->w_p_fde_flags;
5517 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005518# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005519# ifdef FEAT_BEVAL
5520 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5521# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005522# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005523 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005524# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005525 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005526# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005527 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005528# endif
5529#endif
5530 }
5531
5532 /* Nothing special, return global flags field. */
5533 return &options[opt_idx].flags;
5534}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005535#endif
5536
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005537#ifdef FEAT_TITLE
5538static void redraw_titles __ARGS((void));
5539
5540/*
5541 * Redraw the window title and/or tab page text later.
5542 */
5543static void redraw_titles()
5544{
5545 need_maketitle = TRUE;
5546# ifdef FEAT_WINDOWS
5547 redraw_tabline = TRUE;
5548# endif
5549}
5550#endif
5551
Bram Moolenaar071d4272004-06-13 20:20:40 +00005552/*
5553 * Set a string option to a new value (without checking the effect).
5554 * The string is copied into allocated memory.
5555 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005556 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005557 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558 */
5559 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005560set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005561 char_u *name;
5562 int opt_idx;
5563 char_u *val;
5564 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005565 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005566{
5567 char_u *s;
5568 char_u **varp;
5569 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005570 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571
Bram Moolenaar89d40322006-08-29 15:30:07 +00005572 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005574 idx = findoption(name);
5575 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005576 {
5577 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005579 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005580 }
5581
Bram Moolenaar89d40322006-08-29 15:30:07 +00005582 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583 return;
5584
5585 s = vim_strsave(val);
5586 if (s != NULL)
5587 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005588 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005590 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591 free_string_option(*varp);
5592 *varp = s;
5593
5594 /* For buffer/window local option may also set the global value. */
5595 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005596 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005597
Bram Moolenaar89d40322006-08-29 15:30:07 +00005598 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005599
5600 /* When setting both values of a global option with a local value,
5601 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005602 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005603 {
5604 free_string_option(*varp);
5605 *varp = empty_option;
5606 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005607# ifdef FEAT_EVAL
5608 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005609 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005610 set_sid == 0 ? current_SID : set_sid);
5611# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005612 }
5613}
5614
5615/*
5616 * Set global value for string option when it's a local option.
5617 */
5618 static void
5619set_string_option_global(opt_idx, varp)
5620 int opt_idx; /* option index */
5621 char_u **varp; /* pointer to option variable */
5622{
5623 char_u **p, *s;
5624
5625 /* the global value is always allocated */
5626 if (options[opt_idx].var == VAR_WIN)
5627 p = (char_u **)GLOBAL_WO(varp);
5628 else
5629 p = (char_u **)options[opt_idx].var;
5630 if (options[opt_idx].indir != PV_NONE
5631 && p != varp
5632 && (s = vim_strsave(*varp)) != NULL)
5633 {
5634 free_string_option(*p);
5635 *p = s;
5636 }
5637}
5638
5639/*
5640 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005641 *
5642 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005643 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005644 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645set_string_option(opt_idx, value, opt_flags)
5646 int opt_idx;
5647 char_u *value;
5648 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5649{
5650 char_u *s;
5651 char_u **varp;
5652 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005653 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005654
5655 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005656 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657
5658 s = vim_strsave(value);
5659 if (s != NULL)
5660 {
5661 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5662 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005663 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664 ? OPT_GLOBAL : OPT_LOCAL)
5665 : opt_flags);
5666 oldval = *varp;
5667 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005668 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5669 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005670 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005672 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673}
5674
5675/*
5676 * Handle string options that need some action to perform when changed.
5677 * Returns NULL for success, or an error message for an error.
5678 */
5679 static char_u *
5680did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5681 opt_flags)
5682 int opt_idx; /* index in options[] table */
5683 char_u **varp; /* pointer to the option variable */
5684 int new_value_alloced; /* new value was allocated */
5685 char_u *oldval; /* previous value of the option */
5686 char_u *errbuf; /* buffer for errors, or NULL */
5687 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5688{
5689 char_u *errmsg = NULL;
5690 char_u *s, *p;
5691 int did_chartab = FALSE;
5692 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005693 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005694#ifdef FEAT_GUI
5695 /* set when changing an option that only requires a redraw in the GUI */
5696 int redraw_gui_only = FALSE;
5697#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698
5699 /* Get the global option to compare with, otherwise we would have to check
5700 * two values for all local options. */
5701 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5702
5703 /* Disallow changing some options from secure mode */
5704 if ((secure
5705#ifdef HAVE_SANDBOX
5706 || sandbox != 0
5707#endif
5708 ) && (options[opt_idx].flags & P_SECURE))
5709 {
5710 errmsg = e_secure;
5711 }
5712
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005713 /* Check for a "normal" file name in some options. Disallow a path
5714 * separator (slash and/or backslash), wildcards and characters that are
5715 * often illegal in a file name. */
5716 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005717 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005718 {
5719 errmsg = e_invarg;
5720 }
5721
Bram Moolenaar071d4272004-06-13 20:20:40 +00005722 /* 'term' */
5723 else if (varp == &T_NAME)
5724 {
5725 if (T_NAME[0] == NUL)
5726 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5727#ifdef FEAT_GUI
5728 if (gui.in_use)
5729 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5730 else if (term_is_gui(T_NAME))
5731 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5732#endif
5733 else if (set_termname(T_NAME) == FAIL)
5734 errmsg = (char_u *)N_("E522: Not found in termcap");
5735 else
5736 /* Screen colors may have changed. */
5737 redraw_later_clear();
5738 }
5739
5740 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005741 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005743 char_u *bkc = p_bkc;
5744 unsigned int *flags = &bkc_flags;
5745
5746 if (opt_flags & OPT_LOCAL)
5747 {
5748 bkc = curbuf->b_p_bkc;
5749 flags = &curbuf->b_bkc_flags;
5750 }
5751
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005752 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5753 /* make the local value empty: use the global value */
5754 *flags = 0;
5755 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005756 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005757 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5758 errmsg = e_invarg;
5759 if ((((int)*flags & BKC_AUTO) != 0)
5760 + (((int)*flags & BKC_YES) != 0)
5761 + (((int)*flags & BKC_NO) != 0) != 1)
5762 {
5763 /* Must have exactly one of "auto", "yes" and "no". */
5764 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5765 errmsg = e_invarg;
5766 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005767 }
5768 }
5769
5770 /* 'backupext' and 'patchmode' */
5771 else if (varp == &p_bex || varp == &p_pm)
5772 {
5773 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5774 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5775 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5776 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005777#ifdef FEAT_LINEBREAK
5778 /* 'breakindentopt' */
5779 else if (varp == &curwin->w_p_briopt)
5780 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005781 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005782 errmsg = e_invarg;
5783 }
5784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785
5786 /*
5787 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5788 * If the new option is invalid, use old value. 'lisp' option: refill
5789 * chartab[] for '-' char
5790 */
5791 else if ( varp == &p_isi
5792 || varp == &(curbuf->b_p_isk)
5793 || varp == &p_isp
5794 || varp == &p_isf)
5795 {
5796 if (init_chartab() == FAIL)
5797 {
5798 did_chartab = TRUE; /* need to restore it below */
5799 errmsg = e_invarg; /* error in value */
5800 }
5801 }
5802
5803 /* 'helpfile' */
5804 else if (varp == &p_hf)
5805 {
5806 /* May compute new values for $VIM and $VIMRUNTIME */
5807 if (didset_vim)
5808 {
5809 vim_setenv((char_u *)"VIM", (char_u *)"");
5810 didset_vim = FALSE;
5811 }
5812 if (didset_vimruntime)
5813 {
5814 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5815 didset_vimruntime = FALSE;
5816 }
5817 }
5818
Bram Moolenaar1a384422010-07-14 19:53:30 +02005819#ifdef FEAT_SYN_HL
5820 /* 'colorcolumn' */
5821 else if (varp == &curwin->w_p_cc)
5822 errmsg = check_colorcolumn(curwin);
5823#endif
5824
Bram Moolenaar071d4272004-06-13 20:20:40 +00005825#ifdef FEAT_MULTI_LANG
5826 /* 'helplang' */
5827 else if (varp == &p_hlg)
5828 {
5829 /* Check for "", "ab", "ab,cd", etc. */
5830 for (s = p_hlg; *s != NUL; s += 3)
5831 {
5832 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5833 {
5834 errmsg = e_invarg;
5835 break;
5836 }
5837 if (s[2] == NUL)
5838 break;
5839 }
5840 }
5841#endif
5842
5843 /* 'highlight' */
5844 else if (varp == &p_hl)
5845 {
5846 if (highlight_changed() == FAIL)
5847 errmsg = e_invarg; /* invalid flags */
5848 }
5849
5850 /* 'nrformats' */
5851 else if (gvarp == &p_nf)
5852 {
5853 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5854 errmsg = e_invarg;
5855 }
5856
5857#ifdef FEAT_SESSION
5858 /* 'sessionoptions' */
5859 else if (varp == &p_ssop)
5860 {
5861 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5862 errmsg = e_invarg;
5863 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5864 {
5865 /* Don't allow both "sesdir" and "curdir". */
5866 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5867 errmsg = e_invarg;
5868 }
5869 }
5870 /* 'viewoptions' */
5871 else if (varp == &p_vop)
5872 {
5873 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5874 errmsg = e_invarg;
5875 }
5876#endif
5877
5878 /* 'scrollopt' */
5879#ifdef FEAT_SCROLLBIND
5880 else if (varp == &p_sbo)
5881 {
5882 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5883 errmsg = e_invarg;
5884 }
5885#endif
5886
5887 /* 'ambiwidth' */
5888#ifdef FEAT_MBYTE
5889 else if (varp == &p_ambw)
5890 {
5891 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5892 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005893 else if (set_chars_option(&p_lcs) != NULL)
5894 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5895# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5896 else if (set_chars_option(&p_fcs) != NULL)
5897 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5898# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005899 }
5900#endif
5901
5902 /* 'background' */
5903 else if (varp == &p_bg)
5904 {
5905 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5906 {
5907#ifdef FEAT_EVAL
5908 int dark = (*p_bg == 'd');
5909#endif
5910
5911 init_highlight(FALSE, FALSE);
5912
5913#ifdef FEAT_EVAL
5914 if (dark != (*p_bg == 'd')
5915 && get_var_value((char_u *)"g:colors_name") != NULL)
5916 {
5917 /* The color scheme must have set 'background' back to another
5918 * value, that's not what we want here. Disable the color
5919 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005920 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005921 free_string_option(p_bg);
5922 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5923 check_string_option(&p_bg);
5924 init_highlight(FALSE, FALSE);
5925 }
5926#endif
5927 }
5928 else
5929 errmsg = e_invarg;
5930 }
5931
5932 /* 'wildmode' */
5933 else if (varp == &p_wim)
5934 {
5935 if (check_opt_wim() == FAIL)
5936 errmsg = e_invarg;
5937 }
5938
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005939#ifdef FEAT_CMDL_COMPL
5940 /* 'wildoptions' */
5941 else if (varp == &p_wop)
5942 {
5943 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5944 errmsg = e_invarg;
5945 }
5946#endif
5947
Bram Moolenaar071d4272004-06-13 20:20:40 +00005948#ifdef FEAT_WAK
5949 /* 'winaltkeys' */
5950 else if (varp == &p_wak)
5951 {
5952 if (*p_wak == NUL
5953 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5954 errmsg = e_invarg;
5955# ifdef FEAT_MENU
5956# ifdef FEAT_GUI_MOTIF
5957 else if (gui.in_use)
5958 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5959# else
5960# ifdef FEAT_GUI_GTK
5961 else if (gui.in_use)
5962 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5963# endif
5964# endif
5965# endif
5966 }
5967#endif
5968
5969#ifdef FEAT_AUTOCMD
5970 /* 'eventignore' */
5971 else if (varp == &p_ei)
5972 {
5973 if (check_ei() == FAIL)
5974 errmsg = e_invarg;
5975 }
5976#endif
5977
5978#ifdef FEAT_MBYTE
5979 /* 'encoding' and 'fileencoding' */
5980 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5981 {
5982 if (gvarp == &p_fenc)
5983 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005984 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005985 errmsg = e_modifiable;
5986 else if (vim_strchr(*varp, ',') != NULL)
5987 /* No comma allowed in 'fileencoding'; catches confusing it
5988 * with 'fileencodings'. */
5989 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005991 {
5992# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005993 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005994 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005995# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005996 /* Add 'fileencoding' to the swap file. */
5997 ml_setflags(curbuf);
5998 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999 }
6000 if (errmsg == NULL)
6001 {
6002 /* canonize the value, so that STRCMP() can be used on it */
6003 p = enc_canonize(*varp);
6004 if (p != NULL)
6005 {
6006 vim_free(*varp);
6007 *varp = p;
6008 }
6009 if (varp == &p_enc)
6010 {
6011 errmsg = mb_init();
6012# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006013 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006014# endif
6015 }
6016 }
6017
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006018# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006019 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6020 {
6021 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6022 if (STRCMP(p_tenc, "utf-8") != 0)
6023 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6024 }
6025# endif
6026
6027 if (errmsg == NULL)
6028 {
6029# ifdef FEAT_KEYMAP
6030 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6031 * (with another encoding). */
6032 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6033 (void)keymap_init();
6034# endif
6035
6036 /* When 'termencoding' is not empty and 'encoding' changes or when
6037 * 'termencoding' changes, need to setup for keyboard input and
6038 * display output conversion. */
6039 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6040 {
6041 convert_setup(&input_conv, p_tenc, p_enc);
6042 convert_setup(&output_conv, p_enc, p_tenc);
6043 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006044
6045# if defined(WIN3264) && defined(FEAT_MBYTE)
6046 /* $HOME may have characters in active code page. */
6047 if (varp == &p_enc)
6048 init_homedir();
6049# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006050 }
6051 }
6052#endif
6053
6054#if defined(FEAT_POSTSCRIPT)
6055 else if (varp == &p_penc)
6056 {
6057 /* Canonize printencoding if VIM standard one */
6058 p = enc_canonize(p_penc);
6059 if (p != NULL)
6060 {
6061 vim_free(p_penc);
6062 p_penc = p;
6063 }
6064 else
6065 {
6066 /* Ensure lower case and '-' for '_' */
6067 for (s = p_penc; *s != NUL; s++)
6068 {
6069 if (*s == '_')
6070 *s = '-';
6071 else
6072 *s = TOLOWER_ASC(*s);
6073 }
6074 }
6075 }
6076#endif
6077
Bram Moolenaar9372a112005-12-06 19:59:18 +00006078#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079 else if (varp == &p_imak)
6080 {
6081 if (gui.in_use && !im_xim_isvalid_imactivate())
6082 errmsg = e_invarg;
6083 }
6084#endif
6085
6086#ifdef FEAT_KEYMAP
6087 else if (varp == &curbuf->b_p_keymap)
6088 {
6089 /* load or unload key mapping tables */
6090 errmsg = keymap_init();
6091
Bram Moolenaarfab06232009-03-04 03:13:35 +00006092 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006093 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006094 if (*curbuf->b_p_keymap != NUL)
6095 {
6096 /* Installed a new keymap, switch on using it. */
6097 curbuf->b_p_iminsert = B_IMODE_LMAP;
6098 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6099 curbuf->b_p_imsearch = B_IMODE_LMAP;
6100 }
6101 else
6102 {
6103 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6104 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6105 curbuf->b_p_iminsert = B_IMODE_NONE;
6106 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6107 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6108 }
6109 if ((opt_flags & OPT_LOCAL) == 0)
6110 {
6111 set_iminsert_global();
6112 set_imsearch_global();
6113 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006114# ifdef FEAT_WINDOWS
6115 status_redraw_curbuf();
6116# endif
6117 }
6118 }
6119#endif
6120
6121 /* 'fileformat' */
6122 else if (gvarp == &p_ff)
6123 {
6124 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6125 errmsg = e_modifiable;
6126 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6127 errmsg = e_invarg;
6128 else
6129 {
6130 /* may also change 'textmode' */
6131 if (get_fileformat(curbuf) == EOL_DOS)
6132 curbuf->b_p_tx = TRUE;
6133 else
6134 curbuf->b_p_tx = FALSE;
6135#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006136 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006138 /* update flag in swap file */
6139 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006140 /* Redraw needed when switching to/from "mac": a CR in the text
6141 * will be displayed differently. */
6142 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6143 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144 }
6145 }
6146
6147 /* 'fileformats' */
6148 else if (varp == &p_ffs)
6149 {
6150 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6151 errmsg = e_invarg;
6152 else
6153 {
6154 /* also change 'textauto' */
6155 if (*p_ffs == NUL)
6156 p_ta = FALSE;
6157 else
6158 p_ta = TRUE;
6159 }
6160 }
6161
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006162#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006163 /* 'cryptkey' */
6164 else if (gvarp == &p_key)
6165 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006166# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006167 /* Make sure the ":set" command doesn't show the new value in the
6168 * history. */
6169 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006170# endif
6171 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6172 /* Need to update the swapfile. */
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006173 ml_set_crypt_key(curbuf, oldval, crypt_get_method_nr(curbuf));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006174 }
6175
6176 else if (gvarp == &p_cm)
6177 {
6178 if (opt_flags & OPT_LOCAL)
6179 p = curbuf->b_p_cm;
6180 else
6181 p = p_cm;
6182 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6183 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006184 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006185 errmsg = e_invarg;
6186 else
6187 {
6188 /* When setting the global value to empty, make it "zip". */
6189 if (*p_cm == NUL)
6190 {
6191 if (new_value_alloced)
6192 free_string_option(p_cm);
6193 p_cm = vim_strsave((char_u *)"zip");
6194 new_value_alloced = TRUE;
6195 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006196 /* When using ":set cm=name" the local value is going to be empty.
6197 * Do that here, otherwise the crypt functions will still use the
6198 * local value. */
6199 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6200 {
6201 free_string_option(curbuf->b_p_cm);
6202 curbuf->b_p_cm = empty_option;
6203 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006204
6205 /* Need to update the swapfile when the effective method changed.
6206 * Set "s" to the effective old value, "p" to the effective new
6207 * method and compare. */
6208 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6209 s = p_cm; /* was previously using the global value */
6210 else
6211 s = oldval;
6212 if (*curbuf->b_p_cm == NUL)
6213 p = p_cm; /* is now using the global value */
6214 else
6215 p = curbuf->b_p_cm;
6216 if (STRCMP(s, p) != 0)
6217 ml_set_crypt_key(curbuf, curbuf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006218 crypt_method_nr_from_name(s));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006219
6220 /* If the global value changes need to update the swapfile for all
6221 * buffers using that value. */
6222 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6223 {
6224 buf_T *buf;
6225
6226 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6227 if (buf != curbuf && *buf->b_p_cm == NUL)
6228 ml_set_crypt_key(buf, buf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006229 crypt_method_nr_from_name(oldval));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006230 }
6231 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006232 }
6233#endif
6234
6235 /* 'matchpairs' */
6236 else if (gvarp == &p_mps)
6237 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006238#ifdef FEAT_MBYTE
6239 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006241 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006242 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006243 int x2 = -1;
6244 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006245
6246 if (*p != NUL)
6247 p += mb_ptr2len(p);
6248 if (*p != NUL)
6249 x2 = *p++;
6250 if (*p != NUL)
6251 {
6252 x3 = mb_ptr2char(p);
6253 p += mb_ptr2len(p);
6254 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006255 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006256 {
6257 errmsg = e_invarg;
6258 break;
6259 }
6260 if (*p == NUL)
6261 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006262 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006263 }
6264 else
6265#endif
6266 {
6267 /* Check for "x:y,x:y" */
6268 for (p = *varp; *p != NUL; p += 4)
6269 {
6270 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6271 {
6272 errmsg = e_invarg;
6273 break;
6274 }
6275 if (p[3] == NUL)
6276 break;
6277 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006278 }
6279 }
6280
6281#ifdef FEAT_COMMENTS
6282 /* 'comments' */
6283 else if (gvarp == &p_com)
6284 {
6285 for (s = *varp; *s; )
6286 {
6287 while (*s && *s != ':')
6288 {
6289 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6290 && !VIM_ISDIGIT(*s) && *s != '-')
6291 {
6292 errmsg = illegal_char(errbuf, *s);
6293 break;
6294 }
6295 ++s;
6296 }
6297 if (*s++ == NUL)
6298 errmsg = (char_u *)N_("E524: Missing colon");
6299 else if (*s == ',' || *s == NUL)
6300 errmsg = (char_u *)N_("E525: Zero length string");
6301 if (errmsg != NULL)
6302 break;
6303 while (*s && *s != ',')
6304 {
6305 if (*s == '\\' && s[1] != NUL)
6306 ++s;
6307 ++s;
6308 }
6309 s = skip_to_option_part(s);
6310 }
6311 }
6312#endif
6313
6314 /* 'listchars' */
6315 else if (varp == &p_lcs)
6316 {
6317 errmsg = set_chars_option(varp);
6318 }
6319
6320#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6321 /* 'fillchars' */
6322 else if (varp == &p_fcs)
6323 {
6324 errmsg = set_chars_option(varp);
6325 }
6326#endif
6327
6328#ifdef FEAT_CMDWIN
6329 /* 'cedit' */
6330 else if (varp == &p_cedit)
6331 {
6332 errmsg = check_cedit();
6333 }
6334#endif
6335
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006336 /* 'verbosefile' */
6337 else if (varp == &p_vfile)
6338 {
6339 verbose_stop();
6340 if (*p_vfile != NUL && verbose_open() == FAIL)
6341 errmsg = e_invarg;
6342 }
6343
Bram Moolenaar071d4272004-06-13 20:20:40 +00006344#ifdef FEAT_VIMINFO
6345 /* 'viminfo' */
6346 else if (varp == &p_viminfo)
6347 {
6348 for (s = p_viminfo; *s;)
6349 {
6350 /* Check it's a valid character */
6351 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6352 {
6353 errmsg = illegal_char(errbuf, *s);
6354 break;
6355 }
6356 if (*s == 'n') /* name is always last one */
6357 {
6358 break;
6359 }
6360 else if (*s == 'r') /* skip until next ',' */
6361 {
6362 while (*++s && *s != ',')
6363 ;
6364 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006365 else if (*s == '%')
6366 {
6367 /* optional number */
6368 while (vim_isdigit(*++s))
6369 ;
6370 }
6371 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006372 ++s; /* no extra chars */
6373 else /* must have a number */
6374 {
6375 while (vim_isdigit(*++s))
6376 ;
6377
6378 if (!VIM_ISDIGIT(*(s - 1)))
6379 {
6380 if (errbuf != NULL)
6381 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006382 sprintf((char *)errbuf,
6383 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006384 transchar_byte(*(s - 1)));
6385 errmsg = errbuf;
6386 }
6387 else
6388 errmsg = (char_u *)"";
6389 break;
6390 }
6391 }
6392 if (*s == ',')
6393 ++s;
6394 else if (*s)
6395 {
6396 if (errbuf != NULL)
6397 errmsg = (char_u *)N_("E527: Missing comma");
6398 else
6399 errmsg = (char_u *)"";
6400 break;
6401 }
6402 }
6403 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6404 errmsg = (char_u *)N_("E528: Must specify a ' value");
6405 }
6406#endif /* FEAT_VIMINFO */
6407
6408 /* terminal options */
6409 else if (istermoption(&options[opt_idx]) && full_screen)
6410 {
6411 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6412 if (varp == &T_CCO)
6413 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006414 int colors = atoi((char *)T_CCO);
6415
6416 /* Only reinitialize colors if t_Co value has really changed to
6417 * avoid expensive reload of colorscheme if t_Co is set to the
6418 * same value multiple times. */
6419 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006420 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006421 t_colors = colors;
6422 if (t_colors <= 1)
6423 {
6424 if (new_value_alloced)
6425 vim_free(T_CCO);
6426 T_CCO = empty_option;
6427 }
6428 /* We now have a different color setup, initialize it again. */
6429 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006431 }
6432 ttest(FALSE);
6433 if (varp == &T_ME)
6434 {
6435 out_str(T_ME);
6436 redraw_later(CLEAR);
6437#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6438 /* Since t_me has been set, this probably means that the user
6439 * wants to use this as default colors. Need to reset default
6440 * background/foreground colors. */
6441 mch_set_normal_colors();
6442#endif
6443 }
6444 }
6445
6446#ifdef FEAT_LINEBREAK
6447 /* 'showbreak' */
6448 else if (varp == &p_sbr)
6449 {
6450 for (s = p_sbr; *s; )
6451 {
6452 if (ptr2cells(s) != 1)
6453 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006454 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006455 }
6456 }
6457#endif
6458
6459#ifdef FEAT_GUI
6460 /* 'guifont' */
6461 else if (varp == &p_guifont)
6462 {
6463 if (gui.in_use)
6464 {
6465 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006466# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 /*
6468 * Put up a font dialog and let the user select a new value.
6469 * If this is cancelled go back to the old value but don't
6470 * give an error message.
6471 */
6472 if (STRCMP(p, "*") == 0)
6473 {
6474 p = gui_mch_font_dialog(oldval);
6475
6476 if (new_value_alloced)
6477 free_string_option(p_guifont);
6478
6479 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6480 new_value_alloced = TRUE;
6481 }
6482# endif
6483 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6484 {
6485# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6486 if (STRCMP(p_guifont, "*") == 0)
6487 {
6488 /* Dialog was cancelled: Keep the old value without giving
6489 * an error message. */
6490 if (new_value_alloced)
6491 free_string_option(p_guifont);
6492 p_guifont = vim_strsave(oldval);
6493 new_value_alloced = TRUE;
6494 }
6495 else
6496# endif
6497 errmsg = (char_u *)N_("E596: Invalid font(s)");
6498 }
6499 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006500 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006501 }
6502# ifdef FEAT_XFONTSET
6503 else if (varp == &p_guifontset)
6504 {
6505 if (STRCMP(p_guifontset, "*") == 0)
6506 errmsg = (char_u *)N_("E597: can't select fontset");
6507 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6508 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006509 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006510 }
6511# endif
6512# ifdef FEAT_MBYTE
6513 else if (varp == &p_guifontwide)
6514 {
6515 if (STRCMP(p_guifontwide, "*") == 0)
6516 errmsg = (char_u *)N_("E533: can't select wide font");
6517 else if (gui_get_wide_font() == FAIL)
6518 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006519 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006520 }
6521# endif
6522#endif
6523
6524#ifdef CURSOR_SHAPE
6525 /* 'guicursor' */
6526 else if (varp == &p_guicursor)
6527 errmsg = parse_shape_opt(SHAPE_CURSOR);
6528#endif
6529
6530#ifdef FEAT_MOUSESHAPE
6531 /* 'mouseshape' */
6532 else if (varp == &p_mouseshape)
6533 {
6534 errmsg = parse_shape_opt(SHAPE_MOUSE);
6535 update_mouseshape(-1);
6536 }
6537#endif
6538
6539#ifdef FEAT_PRINTER
6540 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006541 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006542# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006543 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006544 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006545# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006546#endif
6547
6548#ifdef FEAT_LANGMAP
6549 /* 'langmap' */
6550 else if (varp == &p_langmap)
6551 langmap_set();
6552#endif
6553
6554#ifdef FEAT_LINEBREAK
6555 /* 'breakat' */
6556 else if (varp == &p_breakat)
6557 fill_breakat_flags();
6558#endif
6559
6560#ifdef FEAT_TITLE
6561 /* 'titlestring' and 'iconstring' */
6562 else if (varp == &p_titlestring || varp == &p_iconstring)
6563 {
6564# ifdef FEAT_STL_OPT
6565 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6566
6567 /* NULL => statusline syntax */
6568 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6569 stl_syntax |= flagval;
6570 else
6571 stl_syntax &= ~flagval;
6572# endif
6573 did_set_title(varp == &p_iconstring);
6574
6575 }
6576#endif
6577
6578#ifdef FEAT_GUI
6579 /* 'guioptions' */
6580 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006581 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006583 redraw_gui_only = TRUE;
6584 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006585#endif
6586
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006587#if defined(FEAT_GUI_TABLINE)
6588 /* 'guitablabel' */
6589 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006590 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006591 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006592 redraw_gui_only = TRUE;
6593 }
6594 /* 'guitabtooltip' */
6595 else if (varp == &p_gtt)
6596 {
6597 redraw_gui_only = TRUE;
6598 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006599#endif
6600
Bram Moolenaar071d4272004-06-13 20:20:40 +00006601#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6602 /* 'ttymouse' */
6603 else if (varp == &p_ttym)
6604 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006605 /* Switch the mouse off before changing the escape sequences used for
6606 * that. */
6607 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006608 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6609 errmsg = e_invarg;
6610 else
6611 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006612 if (termcap_active)
6613 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006614 }
6615#endif
6616
Bram Moolenaar071d4272004-06-13 20:20:40 +00006617 /* 'selection' */
6618 else if (varp == &p_sel)
6619 {
6620 if (*p_sel == NUL
6621 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6622 errmsg = e_invarg;
6623 }
6624
6625 /* 'selectmode' */
6626 else if (varp == &p_slm)
6627 {
6628 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6629 errmsg = e_invarg;
6630 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631
6632#ifdef FEAT_BROWSE
6633 /* 'browsedir' */
6634 else if (varp == &p_bsdir)
6635 {
6636 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6637 && !mch_isdir(p_bsdir))
6638 errmsg = e_invarg;
6639 }
6640#endif
6641
Bram Moolenaar071d4272004-06-13 20:20:40 +00006642 /* 'keymodel' */
6643 else if (varp == &p_km)
6644 {
6645 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6646 errmsg = e_invarg;
6647 else
6648 {
6649 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6650 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6651 }
6652 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006653
6654 /* 'mousemodel' */
6655 else if (varp == &p_mousem)
6656 {
6657 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6658 errmsg = e_invarg;
6659#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6660 else if (*p_mousem != *oldval)
6661 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6662 * to create or delete the popup menus. */
6663 gui_motif_update_mousemodel(root_menu);
6664#endif
6665 }
6666
6667 /* 'switchbuf' */
6668 else if (varp == &p_swb)
6669 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006670 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006671 errmsg = e_invarg;
6672 }
6673
6674 /* 'debug' */
6675 else if (varp == &p_debug)
6676 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006677 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006678 errmsg = e_invarg;
6679 }
6680
6681 /* 'display' */
6682 else if (varp == &p_dy)
6683 {
6684 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6685 errmsg = e_invarg;
6686 else
6687 (void)init_chartab();
6688
6689 }
6690
6691#ifdef FEAT_VERTSPLIT
6692 /* 'eadirection' */
6693 else if (varp == &p_ead)
6694 {
6695 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6696 errmsg = e_invarg;
6697 }
6698#endif
6699
6700#ifdef FEAT_CLIPBOARD
6701 /* 'clipboard' */
6702 else if (varp == &p_cb)
6703 errmsg = check_clipboard_option();
6704#endif
6705
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006706#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006707 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6708 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006709 else if (varp == &(curbuf->b_s.b_p_spl) || varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006710 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006711 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006712 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006713
Bram Moolenaar860cae12010-06-05 23:22:07 +02006714 if (varp == &(curbuf->b_s.b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006715 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006716 l = (int)STRLEN(curbuf->b_s.b_p_spf);
6717 if (l > 0 && (l < 4 || STRCMP(curbuf->b_s.b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006718 ".add") != 0))
6719 errmsg = e_invarg;
6720 }
6721
6722 if (errmsg == NULL)
6723 {
6724 FOR_ALL_WINDOWS(wp)
6725 if (wp->w_buffer == curbuf && wp->w_p_spell)
6726 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006727 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006728# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006729 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006730# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006731 }
6732 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006733 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006734 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006735 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006736 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006737 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006738 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006739 /* 'spellsuggest' */
6740 else if (varp == &p_sps)
6741 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006742 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006743 errmsg = e_invarg;
6744 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006745 /* 'mkspellmem' */
6746 else if (varp == &p_msm)
6747 {
6748 if (spell_check_msm() != OK)
6749 errmsg = e_invarg;
6750 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006751#endif
6752
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753#ifdef FEAT_QUICKFIX
6754 /* When 'bufhidden' is set, check for valid value. */
6755 else if (gvarp == &p_bh)
6756 {
6757 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6758 errmsg = e_invarg;
6759 }
6760
6761 /* When 'buftype' is set, check for valid value. */
6762 else if (gvarp == &p_bt)
6763 {
6764 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6765 errmsg = e_invarg;
6766 else
6767 {
6768# ifdef FEAT_WINDOWS
6769 if (curwin->w_status_height)
6770 {
6771 curwin->w_redr_status = TRUE;
6772 redraw_later(VALID);
6773 }
6774# endif
6775 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006776# ifdef FEAT_TITLE
6777 redraw_titles();
6778# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006779 }
6780 }
6781#endif
6782
6783#ifdef FEAT_STL_OPT
6784 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006785 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006786 {
6787 int wid;
6788
6789 if (varp == &p_ruf) /* reset ru_wid first */
6790 ru_wid = 0;
6791 s = *varp;
6792 if (varp == &p_ruf && *s == '%')
6793 {
6794 /* set ru_wid if 'ruf' starts with "%99(" */
6795 if (*++s == '-') /* ignore a '-' */
6796 s++;
6797 wid = getdigits(&s);
6798 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6799 ru_wid = wid;
6800 else
6801 errmsg = check_stl_option(p_ruf);
6802 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006803 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006804 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006805 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006806 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006807 comp_col();
6808 }
6809#endif
6810
6811#ifdef FEAT_INS_EXPAND
6812 /* check if it is a valid value for 'complete' -- Acevedo */
6813 else if (gvarp == &p_cpt)
6814 {
6815 for (s = *varp; *s;)
6816 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006817 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006818 s++;
6819 if (!*s)
6820 break;
6821 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6822 {
6823 errmsg = illegal_char(errbuf, *s);
6824 break;
6825 }
6826 if (*++s != NUL && *s != ',' && *s != ' ')
6827 {
6828 if (s[-1] == 'k' || s[-1] == 's')
6829 {
6830 /* skip optional filename after 'k' and 's' */
6831 while (*s && *s != ',' && *s != ' ')
6832 {
6833 if (*s == '\\')
6834 ++s;
6835 ++s;
6836 }
6837 }
6838 else
6839 {
6840 if (errbuf != NULL)
6841 {
6842 sprintf((char *)errbuf,
6843 _("E535: Illegal character after <%c>"),
6844 *--s);
6845 errmsg = errbuf;
6846 }
6847 else
6848 errmsg = (char_u *)"";
6849 break;
6850 }
6851 }
6852 }
6853 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006854
6855 /* 'completeopt' */
6856 else if (varp == &p_cot)
6857 {
6858 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6859 errmsg = e_invarg;
6860 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006861#endif /* FEAT_INS_EXPAND */
6862
6863
6864#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6865 else if (varp == &p_toolbar)
6866 {
6867 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6868 &toolbar_flags, TRUE) != OK)
6869 errmsg = e_invarg;
6870 else
6871 {
6872 out_flush();
6873 gui_mch_show_toolbar((toolbar_flags &
6874 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6875 }
6876 }
6877#endif
6878
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006879#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006880 /* 'toolbariconsize': GTK+ 2 only */
6881 else if (varp == &p_tbis)
6882 {
6883 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6884 errmsg = e_invarg;
6885 else
6886 {
6887 out_flush();
6888 gui_mch_show_toolbar((toolbar_flags &
6889 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6890 }
6891 }
6892#endif
6893
6894 /* 'pastetoggle': translate key codes like in a mapping */
6895 else if (varp == &p_pt)
6896 {
6897 if (*p_pt)
6898 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006899 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006900 if (p != NULL)
6901 {
6902 if (new_value_alloced)
6903 free_string_option(p_pt);
6904 p_pt = p;
6905 new_value_alloced = TRUE;
6906 }
6907 }
6908 }
6909
6910 /* 'backspace' */
6911 else if (varp == &p_bs)
6912 {
6913 if (VIM_ISDIGIT(*p_bs))
6914 {
6915 if (*p_bs >'2' || p_bs[1] != NUL)
6916 errmsg = e_invarg;
6917 }
6918 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6919 errmsg = e_invarg;
6920 }
6921
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006922#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006923 /* 'casemap' */
6924 else if (varp == &p_cmp)
6925 {
6926 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6927 errmsg = e_invarg;
6928 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006929#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006930
6931#ifdef FEAT_DIFF
6932 /* 'diffopt' */
6933 else if (varp == &p_dip)
6934 {
6935 if (diffopt_changed() == FAIL)
6936 errmsg = e_invarg;
6937 }
6938#endif
6939
6940#ifdef FEAT_FOLDING
6941 /* 'foldmethod' */
6942 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6943 {
6944 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6945 || *curwin->w_p_fdm == NUL)
6946 errmsg = e_invarg;
6947 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006948 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006949 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006950 if (foldmethodIsDiff(curwin))
6951 newFoldLevel();
6952 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006953 }
6954# ifdef FEAT_EVAL
6955 /* 'foldexpr' */
6956 else if (varp == &curwin->w_p_fde)
6957 {
6958 if (foldmethodIsExpr(curwin))
6959 foldUpdateAll(curwin);
6960 }
6961# endif
6962 /* 'foldmarker' */
6963 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6964 {
6965 p = vim_strchr(*varp, ',');
6966 if (p == NULL)
6967 errmsg = (char_u *)N_("E536: comma required");
6968 else if (p == *varp || p[1] == NUL)
6969 errmsg = e_invarg;
6970 else if (foldmethodIsMarker(curwin))
6971 foldUpdateAll(curwin);
6972 }
6973 /* 'commentstring' */
6974 else if (gvarp == &p_cms)
6975 {
6976 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6977 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6978 }
6979 /* 'foldopen' */
6980 else if (varp == &p_fdo)
6981 {
6982 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6983 errmsg = e_invarg;
6984 }
6985 /* 'foldclose' */
6986 else if (varp == &p_fcl)
6987 {
6988 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6989 errmsg = e_invarg;
6990 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006991 /* 'foldignore' */
6992 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6993 {
6994 if (foldmethodIsIndent(curwin))
6995 foldUpdateAll(curwin);
6996 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006997#endif
6998
6999#ifdef FEAT_VIRTUALEDIT
7000 /* 'virtualedit' */
7001 else if (varp == &p_ve)
7002 {
7003 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7004 errmsg = e_invarg;
7005 else if (STRCMP(p_ve, oldval) != 0)
7006 {
7007 /* Recompute cursor position in case the new 've' setting
7008 * changes something. */
7009 validate_virtcol();
7010 coladvance(curwin->w_virtcol);
7011 }
7012 }
7013#endif
7014
7015#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7016 else if (varp == &p_csqf)
7017 {
7018 if (p_csqf != NULL)
7019 {
7020 p = p_csqf;
7021 while (*p != NUL)
7022 {
7023 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7024 || p[1] == NUL
7025 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7026 || (p[2] != NUL && p[2] != ','))
7027 {
7028 errmsg = e_invarg;
7029 break;
7030 }
7031 else if (p[2] == NUL)
7032 break;
7033 else
7034 p += 3;
7035 }
7036 }
7037 }
7038#endif
7039
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007040#ifdef FEAT_CINDENT
7041 /* 'cinoptions' */
7042 else if (gvarp == &p_cino)
7043 {
7044 /* TODO: recognize errors */
7045 parse_cino(curbuf);
7046 }
7047#endif
7048
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007049#if defined(FEAT_RENDER_OPTIONS)
7050 else if (varp == &p_rop && gui.in_use)
7051 {
7052 if (!gui_mch_set_rendering_options(p_rop))
7053 errmsg = e_invarg;
7054 }
7055#endif
7056
Bram Moolenaar071d4272004-06-13 20:20:40 +00007057 /* Options that are a list of flags. */
7058 else
7059 {
7060 p = NULL;
7061 if (varp == &p_ww)
7062 p = (char_u *)WW_ALL;
7063 if (varp == &p_shm)
7064 p = (char_u *)SHM_ALL;
7065 else if (varp == &(p_cpo))
7066 p = (char_u *)CPO_ALL;
7067 else if (varp == &(curbuf->b_p_fo))
7068 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007069#ifdef FEAT_CONCEAL
7070 else if (varp == &curwin->w_p_cocu)
7071 p = (char_u *)COCU_ALL;
7072#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007073 else if (varp == &p_mouse)
7074 {
7075#ifdef FEAT_MOUSE
7076 p = (char_u *)MOUSE_ALL;
7077#else
7078 if (*p_mouse != NUL)
7079 errmsg = (char_u *)N_("E538: No mouse support");
7080#endif
7081 }
7082#if defined(FEAT_GUI)
7083 else if (varp == &p_go)
7084 p = (char_u *)GO_ALL;
7085#endif
7086 if (p != NULL)
7087 {
7088 for (s = *varp; *s; ++s)
7089 if (vim_strchr(p, *s) == NULL)
7090 {
7091 errmsg = illegal_char(errbuf, *s);
7092 break;
7093 }
7094 }
7095 }
7096
7097 /*
7098 * If error detected, restore the previous value.
7099 */
7100 if (errmsg != NULL)
7101 {
7102 if (new_value_alloced)
7103 free_string_option(*varp);
7104 *varp = oldval;
7105 /*
7106 * When resetting some values, need to act on it.
7107 */
7108 if (did_chartab)
7109 (void)init_chartab();
7110 if (varp == &p_hl)
7111 (void)highlight_changed();
7112 }
7113 else
7114 {
7115#ifdef FEAT_EVAL
7116 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007117 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007118#endif
7119 /*
7120 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007121 * Use "free_oldval", because recursiveness may change the flags under
7122 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007123 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007124 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125 free_string_option(oldval);
7126 if (new_value_alloced)
7127 options[opt_idx].flags |= P_ALLOCED;
7128 else
7129 options[opt_idx].flags &= ~P_ALLOCED;
7130
7131 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007132 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 {
7134 /* global option with local value set to use global value; free
7135 * the local value and make it empty */
7136 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7137 free_string_option(*(char_u **)p);
7138 *(char_u **)p = empty_option;
7139 }
7140
7141 /* May set global value for local option. */
7142 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7143 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007144
7145#ifdef FEAT_AUTOCMD
7146 /*
7147 * Trigger the autocommand only after setting the flags.
7148 */
7149# ifdef FEAT_SYN_HL
7150 /* When 'syntax' is set, load the syntax of that name */
7151 if (varp == &(curbuf->b_p_syn))
7152 {
7153 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7154 curbuf->b_fname, TRUE, curbuf);
7155 }
7156# endif
7157 else if (varp == &(curbuf->b_p_ft))
7158 {
7159 /* 'filetype' is set, trigger the FileType autocommand */
7160 did_filetype = TRUE;
7161 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7162 curbuf->b_fname, TRUE, curbuf);
7163 }
7164#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007165#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007166 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007167 {
7168 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007169 char_u *q = curwin->w_s->b_p_spl;
7170
7171 /* Skip the first name if it is "cjk". */
7172 if (STRNCMP(q, "cjk,", 4) == 0)
7173 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007174
7175 /*
7176 * Source the spell/LANG.vim in 'runtimepath'.
7177 * They could set 'spellcapcheck' depending on the language.
7178 * Use the first name in 'spelllang' up to '_region' or
7179 * '.encoding'.
7180 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007181 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007182 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7183 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007184 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007185 source_runtime(fname, TRUE);
7186 }
7187#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007188 }
7189
7190#ifdef FEAT_MOUSE
7191 if (varp == &p_mouse)
7192 {
7193# ifdef FEAT_MOUSE_TTY
7194 if (*p_mouse == NUL)
7195 mch_setmouse(FALSE); /* switch mouse off */
7196 else
7197# endif
7198 setmouse(); /* in case 'mouse' changed */
7199 }
7200#endif
7201
Bram Moolenaar913077c2012-03-28 19:59:04 +02007202 if (curwin->w_curswant != MAXCOL
7203 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
7204 curwin->w_set_curswant = TRUE;
7205
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007206#ifdef FEAT_GUI
7207 /* check redraw when it's not a GUI option or the GUI is active. */
7208 if (!redraw_gui_only || gui.in_use)
7209#endif
7210 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007211
7212 return errmsg;
7213}
7214
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007215#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007216/*
7217 * Simple int comparison function for use with qsort()
7218 */
7219 static int
7220int_cmp(a, b)
7221 const void *a;
7222 const void *b;
7223{
7224 return *(const int *)a - *(const int *)b;
7225}
7226
7227/*
7228 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7229 * Returns error message, NULL if it's OK.
7230 */
7231 char_u *
7232check_colorcolumn(wp)
7233 win_T *wp;
7234{
7235 char_u *s;
7236 int col;
7237 int count = 0;
7238 int color_cols[256];
7239 int i;
7240 int j = 0;
7241
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007242 if (wp->w_buffer == NULL)
7243 return NULL; /* buffer was closed */
7244
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007245 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007246 {
7247 if (*s == '-' || *s == '+')
7248 {
7249 /* -N and +N: add to 'textwidth' */
7250 col = (*s == '-') ? -1 : 1;
7251 ++s;
7252 if (!VIM_ISDIGIT(*s))
7253 return e_invarg;
7254 col = col * getdigits(&s);
7255 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007256 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007257 col += wp->w_buffer->b_p_tw;
7258 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007259 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007260 }
7261 else if (VIM_ISDIGIT(*s))
7262 col = getdigits(&s);
7263 else
7264 return e_invarg;
7265 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007266skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007267 if (*s == NUL)
7268 break;
7269 if (*s != ',')
7270 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007271 if (*++s == NUL)
7272 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007273 }
7274
7275 vim_free(wp->w_p_cc_cols);
7276 if (count == 0)
7277 wp->w_p_cc_cols = NULL;
7278 else
7279 {
7280 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7281 if (wp->w_p_cc_cols != NULL)
7282 {
7283 /* sort the columns for faster usage on screen redraw inside
7284 * win_line() */
7285 qsort(color_cols, count, sizeof(int), int_cmp);
7286
7287 for (i = 0; i < count; ++i)
7288 /* skip duplicates */
7289 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7290 wp->w_p_cc_cols[j++] = color_cols[i];
7291 wp->w_p_cc_cols[j] = -1; /* end marker */
7292 }
7293 }
7294
7295 return NULL; /* no error */
7296}
7297#endif
7298
Bram Moolenaar071d4272004-06-13 20:20:40 +00007299/*
7300 * Handle setting 'listchars' or 'fillchars'.
7301 * Returns error message, NULL if it's OK.
7302 */
7303 static char_u *
7304set_chars_option(varp)
7305 char_u **varp;
7306{
7307 int round, i, len, entries;
7308 char_u *p, *s;
7309 int c1, c2 = 0;
7310 struct charstab
7311 {
7312 int *cp;
7313 char *name;
7314 };
7315#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7316 static struct charstab filltab[] =
7317 {
7318 {&fill_stl, "stl"},
7319 {&fill_stlnc, "stlnc"},
7320 {&fill_vert, "vert"},
7321 {&fill_fold, "fold"},
7322 {&fill_diff, "diff"},
7323 };
7324#endif
7325 static struct charstab lcstab[] =
7326 {
7327 {&lcs_eol, "eol"},
7328 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007329 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007330 {&lcs_prec, "precedes"},
7331 {&lcs_tab2, "tab"},
7332 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007333#ifdef FEAT_CONCEAL
7334 {&lcs_conceal, "conceal"},
7335#else
7336 {NULL, "conceal"},
7337#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007338 };
7339 struct charstab *tab;
7340
7341#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7342 if (varp == &p_lcs)
7343#endif
7344 {
7345 tab = lcstab;
7346 entries = sizeof(lcstab) / sizeof(struct charstab);
7347 }
7348#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7349 else
7350 {
7351 tab = filltab;
7352 entries = sizeof(filltab) / sizeof(struct charstab);
7353 }
7354#endif
7355
7356 /* first round: check for valid value, second round: assign values */
7357 for (round = 0; round <= 1; ++round)
7358 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007359 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007360 {
7361 /* After checking that the value is valid: set defaults: space for
7362 * 'fillchars', NUL for 'listchars' */
7363 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007364 if (tab[i].cp != NULL)
7365 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007366 if (varp == &p_lcs)
7367 lcs_tab1 = NUL;
7368#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7369 else
7370 fill_diff = '-';
7371#endif
7372 }
7373 p = *varp;
7374 while (*p)
7375 {
7376 for (i = 0; i < entries; ++i)
7377 {
7378 len = (int)STRLEN(tab[i].name);
7379 if (STRNCMP(p, tab[i].name, len) == 0
7380 && p[len] == ':'
7381 && p[len + 1] != NUL)
7382 {
7383 s = p + len + 1;
7384#ifdef FEAT_MBYTE
7385 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007386 if (mb_char2cells(c1) > 1)
7387 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007388#else
7389 c1 = *s++;
7390#endif
7391 if (tab[i].cp == &lcs_tab2)
7392 {
7393 if (*s == NUL)
7394 continue;
7395#ifdef FEAT_MBYTE
7396 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007397 if (mb_char2cells(c2) > 1)
7398 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007399#else
7400 c2 = *s++;
7401#endif
7402 }
7403 if (*s == ',' || *s == NUL)
7404 {
7405 if (round)
7406 {
7407 if (tab[i].cp == &lcs_tab2)
7408 {
7409 lcs_tab1 = c1;
7410 lcs_tab2 = c2;
7411 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007412 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007413 *(tab[i].cp) = c1;
7414
7415 }
7416 p = s;
7417 break;
7418 }
7419 }
7420 }
7421
7422 if (i == entries)
7423 return e_invarg;
7424 if (*p == ',')
7425 ++p;
7426 }
7427 }
7428
7429 return NULL; /* no error */
7430}
7431
7432#ifdef FEAT_STL_OPT
7433/*
7434 * Check validity of options with the 'statusline' format.
7435 * Return error message or NULL.
7436 */
7437 char_u *
7438check_stl_option(s)
7439 char_u *s;
7440{
7441 int itemcnt = 0;
7442 int groupdepth = 0;
7443 static char_u errbuf[80];
7444
7445 while (*s && itemcnt < STL_MAX_ITEM)
7446 {
7447 /* Check for valid keys after % sequences */
7448 while (*s && *s != '%')
7449 s++;
7450 if (!*s)
7451 break;
7452 s++;
7453 if (*s != '%' && *s != ')')
7454 ++itemcnt;
7455 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7456 {
7457 s++;
7458 continue;
7459 }
7460 if (*s == ')')
7461 {
7462 s++;
7463 if (--groupdepth < 0)
7464 break;
7465 continue;
7466 }
7467 if (*s == '-')
7468 s++;
7469 while (VIM_ISDIGIT(*s))
7470 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007471 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007472 continue;
7473 if (*s == '.')
7474 {
7475 s++;
7476 while (*s && VIM_ISDIGIT(*s))
7477 s++;
7478 }
7479 if (*s == '(')
7480 {
7481 groupdepth++;
7482 continue;
7483 }
7484 if (vim_strchr(STL_ALL, *s) == NULL)
7485 {
7486 return illegal_char(errbuf, *s);
7487 }
7488 if (*s == '{')
7489 {
7490 s++;
7491 while (*s != '}' && *s)
7492 s++;
7493 if (*s != '}')
7494 return (char_u *)N_("E540: Unclosed expression sequence");
7495 }
7496 }
7497 if (itemcnt >= STL_MAX_ITEM)
7498 return (char_u *)N_("E541: too many items");
7499 if (groupdepth != 0)
7500 return (char_u *)N_("E542: unbalanced groups");
7501 return NULL;
7502}
7503#endif
7504
7505#ifdef FEAT_CLIPBOARD
7506/*
7507 * Extract the items in the 'clipboard' option and set global values.
7508 */
7509 static char_u *
7510check_clipboard_option()
7511{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007512 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007513 int new_autoselect_star = FALSE;
7514 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007515 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007516 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007517 regprog_T *new_exclude_prog = NULL;
7518 char_u *errmsg = NULL;
7519 char_u *p;
7520
7521 for (p = p_cb; *p != NUL; )
7522 {
7523 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7524 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007525 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007526 p += 7;
7527 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007528 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007529 && (p[11] == ',' || p[11] == NUL))
7530 {
7531 new_unnamed |= CLIP_UNNAMED_PLUS;
7532 p += 11;
7533 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007534 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007535 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007536 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007537 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007538 p += 10;
7539 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007540 else if (STRNCMP(p, "autoselectplus", 14) == 0
7541 && (p[14] == ',' || p[14] == NUL))
7542 {
7543 new_autoselect_plus = TRUE;
7544 p += 14;
7545 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007547 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548 {
7549 new_autoselectml = TRUE;
7550 p += 12;
7551 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007552 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7553 {
7554 new_html = TRUE;
7555 p += 4;
7556 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007557 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7558 {
7559 p += 8;
7560 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7561 if (new_exclude_prog == NULL)
7562 errmsg = e_invarg;
7563 break;
7564 }
7565 else
7566 {
7567 errmsg = e_invarg;
7568 break;
7569 }
7570 if (*p == ',')
7571 ++p;
7572 }
7573 if (errmsg == NULL)
7574 {
7575 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007576 clip_autoselect_star = new_autoselect_star;
7577 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007578 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007579 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007580 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007581 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007582#ifdef FEAT_GUI_GTK
7583 if (gui.in_use)
7584 {
7585 gui_gtk_set_selection_targets();
7586 gui_gtk_set_dnd_targets();
7587 }
7588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007589 }
7590 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007591 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007592
7593 return errmsg;
7594}
7595#endif
7596
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007597#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007598/*
7599 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7600 * Return error message when failed, NULL when OK.
7601 */
7602 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007603compile_cap_prog(synblock)
7604 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007605{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007606 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007607 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007608
Bram Moolenaar860cae12010-06-05 23:22:07 +02007609 if (*synblock->b_p_spc == NUL)
7610 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007611 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007612 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007613 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007614 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007615 if (re != NULL)
7616 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007617 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007618 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007619 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007620 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007621 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007622 return e_invarg;
7623 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007624 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007625 }
7626
Bram Moolenaar473de612013-06-08 18:19:48 +02007627 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007628 return NULL;
7629}
7630#endif
7631
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007632#if defined(FEAT_EVAL) || defined(PROTO)
7633/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007634 * Set the scriptID for an option, taking care of setting the buffer- or
7635 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007636 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007637 static void
7638set_option_scriptID_idx(opt_idx, opt_flags, id)
7639 int opt_idx;
7640 int opt_flags;
7641 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007642{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007643 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7644 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007645
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007646 /* Remember where the option was set. For local options need to do that
7647 * in the buffer or window structure. */
7648 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007649 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007650 if (both || (opt_flags & OPT_LOCAL))
7651 {
7652 if (indir & PV_BUF)
7653 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7654 else if (indir & PV_WIN)
7655 curwin->w_p_scriptID[indir & PV_MASK] = id;
7656 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007657}
7658#endif
7659
Bram Moolenaar071d4272004-06-13 20:20:40 +00007660/*
7661 * Set the value of a boolean option, and take care of side effects.
7662 * Returns NULL for success, or an error message for an error.
7663 */
7664 static char_u *
7665set_bool_option(opt_idx, varp, value, opt_flags)
7666 int opt_idx; /* index in options[] table */
7667 char_u *varp; /* pointer to the option variable */
7668 int value; /* new value */
7669 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7670{
7671 int old_value = *(int *)varp;
7672
Bram Moolenaar071d4272004-06-13 20:20:40 +00007673 /* Disallow changing some options from secure mode */
7674 if ((secure
7675#ifdef HAVE_SANDBOX
7676 || sandbox != 0
7677#endif
7678 ) && (options[opt_idx].flags & P_SECURE))
7679 return e_secure;
7680
7681 *(int *)varp = value; /* set the new value */
7682#ifdef FEAT_EVAL
7683 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007684 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007685#endif
7686
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007687#ifdef FEAT_GUI
7688 need_mouse_correct = TRUE;
7689#endif
7690
Bram Moolenaar071d4272004-06-13 20:20:40 +00007691 /* May set global value for local option. */
7692 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7693 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7694
7695 /*
7696 * Handle side effects of changing a bool option.
7697 */
7698
7699 /* 'compatible' */
7700 if ((int *)varp == &p_cp)
7701 {
7702 compatible_set();
7703 }
7704
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007705#ifdef FEAT_PERSISTENT_UNDO
7706 /* 'undofile' */
7707 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7708 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007709 /* Only take action when the option was set. When reset we do not
7710 * delete the undo file, the option may be set again without making
7711 * any changes in between. */
7712 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007713 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007714 char_u hash[UNDO_HASH_SIZE];
7715 buf_T *save_curbuf = curbuf;
7716
7717 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007718 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007719 /* When 'undofile' is set globally: for every buffer, otherwise
7720 * only for the current buffer: Try to read in the undofile,
7721 * if one exists, the buffer wasn't changed and the buffer was
7722 * loaded */
7723 if ((curbuf == save_curbuf
7724 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7725 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7726 {
7727 u_compute_hash(hash);
7728 u_read_undo(NULL, hash, curbuf->b_fname);
7729 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007730 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007731 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007732 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007733 }
7734#endif
7735
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736 else if ((int *)varp == &curbuf->b_p_ro)
7737 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007738 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7740 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007741
7742 /* when 'readonly' is set may give W10 again */
7743 if (curbuf->b_p_ro)
7744 curbuf->b_did_warn = FALSE;
7745
Bram Moolenaar071d4272004-06-13 20:20:40 +00007746#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007747 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748#endif
7749 }
7750
Bram Moolenaar9c449722010-07-20 18:44:27 +02007751#ifdef FEAT_GUI
7752 else if ((int *)varp == &p_mh)
7753 {
7754 if (!p_mh)
7755 gui_mch_mousehide(FALSE);
7756 }
7757#endif
7758
Bram Moolenaara539df02010-08-01 14:35:05 +02007759#ifdef FEAT_TITLE
7760 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007762 {
7763 redraw_titles();
7764 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007765 /* when 'endofline' is changed, redraw the window title */
7766 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007767 {
7768 redraw_titles();
7769 }
7770# ifdef FEAT_MBYTE
7771 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007772 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007773 {
7774 redraw_titles();
7775 }
7776# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007777#endif
7778
7779 /* when 'bin' is set also set some other options */
7780 else if ((int *)varp == &curbuf->b_p_bin)
7781 {
7782 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7783#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007784 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785#endif
7786 }
7787
7788#ifdef FEAT_AUTOCMD
7789 /* when 'buflisted' changes, trigger autocommands */
7790 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7791 {
7792 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7793 NULL, NULL, TRUE, curbuf);
7794 }
7795#endif
7796
7797 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7798 else if ((int *)varp == &curbuf->b_p_swf)
7799 {
7800 if (curbuf->b_p_swf && p_uc)
7801 ml_open_file(curbuf); /* create the swap file */
7802 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007803 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7804 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007805 mf_close_file(curbuf, TRUE); /* remove the swap file */
7806 }
7807
7808 /* when 'terse' is set change 'shortmess' */
7809 else if ((int *)varp == &p_terse)
7810 {
7811 char_u *p;
7812
7813 p = vim_strchr(p_shm, SHM_SEARCH);
7814
7815 /* insert 's' in p_shm */
7816 if (p_terse && p == NULL)
7817 {
7818 STRCPY(IObuff, p_shm);
7819 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007820 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007821 }
7822 /* remove 's' from p_shm */
7823 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007824 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007825 }
7826
7827 /* when 'paste' is set or reset also change other options */
7828 else if ((int *)varp == &p_paste)
7829 {
7830 paste_option_changed();
7831 }
7832
7833 /* when 'insertmode' is set from an autocommand need to do work here */
7834 else if ((int *)varp == &p_im)
7835 {
7836 if (p_im)
7837 {
7838 if ((State & INSERT) == 0)
7839 need_start_insertmode = TRUE;
7840 stop_insert_mode = FALSE;
7841 }
7842 else
7843 {
7844 need_start_insertmode = FALSE;
7845 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007846 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007847 clear_cmdline = TRUE; /* remove "(insert)" */
7848 restart_edit = 0;
7849 }
7850 }
7851
7852 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7853 else if ((int *)varp == &p_ic && p_hls)
7854 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007855 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007856 }
7857
7858#ifdef FEAT_SEARCH_EXTRA
7859 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7860 else if ((int *)varp == &p_hls)
7861 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007862 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007863 }
7864#endif
7865
7866#ifdef FEAT_SCROLLBIND
7867 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7868 * at the end of normal_cmd() */
7869 else if ((int *)varp == &curwin->w_p_scb)
7870 {
7871 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007872 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007874 curwin->w_scbind_pos = curwin->w_topline;
7875 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007876 }
7877#endif
7878
7879#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7880 /* There can be only one window with 'previewwindow' set. */
7881 else if ((int *)varp == &curwin->w_p_pvw)
7882 {
7883 if (curwin->w_p_pvw)
7884 {
7885 win_T *win;
7886
7887 for (win = firstwin; win != NULL; win = win->w_next)
7888 if (win->w_p_pvw && win != curwin)
7889 {
7890 curwin->w_p_pvw = FALSE;
7891 return (char_u *)N_("E590: A preview window already exists");
7892 }
7893 }
7894 }
7895#endif
7896
7897 /* when 'textmode' is set or reset also change 'fileformat' */
7898 else if ((int *)varp == &curbuf->b_p_tx)
7899 {
7900 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7901 }
7902
7903 /* when 'textauto' is set or reset also change 'fileformats' */
7904 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905 set_string_option_direct((char_u *)"ffs", -1,
7906 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007907 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007908
7909 /*
7910 * When 'lisp' option changes include/exclude '-' in
7911 * keyword characters.
7912 */
7913#ifdef FEAT_LISP
7914 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7915 {
7916 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7917 }
7918#endif
7919
7920#ifdef FEAT_TITLE
7921 /* when 'title' changed, may need to change the title; same for 'icon' */
7922 else if ((int *)varp == &p_title)
7923 {
7924 did_set_title(FALSE);
7925 }
7926
7927 else if ((int *)varp == &p_icon)
7928 {
7929 did_set_title(TRUE);
7930 }
7931#endif
7932
7933 else if ((int *)varp == &curbuf->b_changed)
7934 {
7935 if (!value)
7936 save_file_ff(curbuf); /* Buffer is unchanged */
7937#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007938 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939#endif
7940#ifdef FEAT_AUTOCMD
7941 modified_was_set = value;
7942#endif
7943 }
7944
7945#ifdef BACKSLASH_IN_FILENAME
7946 else if ((int *)varp == &p_ssl)
7947 {
7948 if (p_ssl)
7949 {
7950 psepc = '/';
7951 psepcN = '\\';
7952 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953 }
7954 else
7955 {
7956 psepc = '\\';
7957 psepcN = '/';
7958 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007959 }
7960
7961 /* need to adjust the file name arguments and buffer names. */
7962 buflist_slash_adjust();
7963 alist_slash_adjust();
7964# ifdef FEAT_EVAL
7965 scriptnames_slash_adjust();
7966# endif
7967 }
7968#endif
7969
7970 /* If 'wrap' is set, set w_leftcol to zero. */
7971 else if ((int *)varp == &curwin->w_p_wrap)
7972 {
7973 if (curwin->w_p_wrap)
7974 curwin->w_leftcol = 0;
7975 }
7976
7977#ifdef FEAT_WINDOWS
7978 else if ((int *)varp == &p_ea)
7979 {
7980 if (p_ea && !old_value)
7981 win_equal(curwin, FALSE, 0);
7982 }
7983#endif
7984
7985 else if ((int *)varp == &p_wiv)
7986 {
7987 /*
7988 * When 'weirdinvert' changed, set/reset 't_xs'.
7989 * Then set 'weirdinvert' according to value of 't_xs'.
7990 */
7991 if (p_wiv && !old_value)
7992 T_XS = (char_u *)"y";
7993 else if (!p_wiv && old_value)
7994 T_XS = empty_option;
7995 p_wiv = (*T_XS != NUL);
7996 }
7997
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007998#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 else if ((int *)varp == &p_beval)
8000 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008001 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008003 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008004 gui_mch_disable_beval_area(balloonEval);
8005 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008006#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008008#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009 else if ((int *)varp == &p_acd)
8010 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008011 /* Change directories when the 'acd' option is set now. */
8012 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013 }
8014#endif
8015
8016#ifdef FEAT_DIFF
8017 /* 'diff' */
8018 else if ((int *)varp == &curwin->w_p_diff)
8019 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008020 /* May add or remove the buffer from the list of diff buffers. */
8021 diff_buf_adjust(curwin);
8022# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008023 if (foldmethodIsDiff(curwin))
8024 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008025# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008026 }
8027#endif
8028
8029#ifdef USE_IM_CONTROL
8030 /* 'imdisable' */
8031 else if ((int *)varp == &p_imdisable)
8032 {
8033 /* Only de-activate it here, it will be enabled when changing mode. */
8034 if (p_imdisable)
8035 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008036 else if (State & INSERT)
8037 /* When the option is set from an autocommand, it may need to take
8038 * effect right away. */
8039 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008040 }
8041#endif
8042
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008043#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008044 /* 'spell' */
8045 else if ((int *)varp == &curwin->w_p_spell)
8046 {
8047 if (curwin->w_p_spell)
8048 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008049 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008050 if (errmsg != NULL)
8051 EMSG(_(errmsg));
8052 }
8053 }
8054#endif
8055
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056#ifdef FEAT_FKMAP
8057 else if ((int *)varp == &p_altkeymap)
8058 {
8059 if (old_value != p_altkeymap)
8060 {
8061 if (!p_altkeymap)
8062 {
8063 p_hkmap = p_fkmap;
8064 p_fkmap = 0;
8065 }
8066 else
8067 {
8068 p_fkmap = p_hkmap;
8069 p_hkmap = 0;
8070 }
8071 (void)init_chartab();
8072 }
8073 }
8074
8075 /*
8076 * In case some second language keymapping options have changed, check
8077 * and correct the setting in a consistent way.
8078 */
8079
8080 /*
8081 * If hkmap or fkmap are set, reset Arabic keymapping.
8082 */
8083 if ((p_hkmap || p_fkmap) && p_altkeymap)
8084 {
8085 p_altkeymap = p_fkmap;
8086# ifdef FEAT_ARABIC
8087 curwin->w_p_arab = FALSE;
8088# endif
8089 (void)init_chartab();
8090 }
8091
8092 /*
8093 * If hkmap set, reset Farsi keymapping.
8094 */
8095 if (p_hkmap && p_altkeymap)
8096 {
8097 p_altkeymap = 0;
8098 p_fkmap = 0;
8099# ifdef FEAT_ARABIC
8100 curwin->w_p_arab = FALSE;
8101# endif
8102 (void)init_chartab();
8103 }
8104
8105 /*
8106 * If fkmap set, reset Hebrew keymapping.
8107 */
8108 if (p_fkmap && !p_altkeymap)
8109 {
8110 p_altkeymap = 1;
8111 p_hkmap = 0;
8112# ifdef FEAT_ARABIC
8113 curwin->w_p_arab = FALSE;
8114# endif
8115 (void)init_chartab();
8116 }
8117#endif
8118
8119#ifdef FEAT_ARABIC
8120 if ((int *)varp == &curwin->w_p_arab)
8121 {
8122 if (curwin->w_p_arab)
8123 {
8124 /*
8125 * 'arabic' is set, handle various sub-settings.
8126 */
8127 if (!p_tbidi)
8128 {
8129 /* set rightleft mode */
8130 if (!curwin->w_p_rl)
8131 {
8132 curwin->w_p_rl = TRUE;
8133 changed_window_setting();
8134 }
8135
8136 /* Enable Arabic shaping (major part of what Arabic requires) */
8137 if (!p_arshape)
8138 {
8139 p_arshape = TRUE;
8140 redraw_later_clear();
8141 }
8142 }
8143
8144 /* Arabic requires a utf-8 encoding, inform the user if its not
8145 * set. */
8146 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008147 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008148 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8149
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008150 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008151 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8152#ifdef FEAT_EVAL
8153 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8154#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008155 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156
8157# ifdef FEAT_MBYTE
8158 /* set 'delcombine' */
8159 p_deco = TRUE;
8160# endif
8161
8162# ifdef FEAT_KEYMAP
8163 /* Force-set the necessary keymap for arabic */
8164 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8165 OPT_LOCAL);
8166# endif
8167# ifdef FEAT_FKMAP
8168 p_altkeymap = 0;
8169 p_hkmap = 0;
8170 p_fkmap = 0;
8171 (void)init_chartab();
8172# endif
8173 }
8174 else
8175 {
8176 /*
8177 * 'arabic' is reset, handle various sub-settings.
8178 */
8179 if (!p_tbidi)
8180 {
8181 /* reset rightleft mode */
8182 if (curwin->w_p_rl)
8183 {
8184 curwin->w_p_rl = FALSE;
8185 changed_window_setting();
8186 }
8187
8188 /* 'arabicshape' isn't reset, it is a global option and
8189 * another window may still need it "on". */
8190 }
8191
8192 /* 'delcombine' isn't reset, it is a global option and another
8193 * window may still want it "on". */
8194
8195# ifdef FEAT_KEYMAP
8196 /* Revert to the default keymap */
8197 curbuf->b_p_iminsert = B_IMODE_NONE;
8198 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8199# endif
8200 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008201 }
8202
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008203#endif
8204
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 /*
8206 * End of handling side effects for bool options.
8207 */
8208
8209 options[opt_idx].flags |= P_WAS_SET;
8210
8211 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008212 if (curwin->w_curswant != MAXCOL
8213 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8214 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008215 check_redraw(options[opt_idx].flags);
8216
8217 return NULL;
8218}
8219
8220/*
8221 * Set the value of a number option, and take care of side effects.
8222 * Returns NULL for success, or an error message for an error.
8223 */
8224 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008225set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008226 int opt_idx; /* index in options[] table */
8227 char_u *varp; /* pointer to the option variable */
8228 long value; /* new value */
8229 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008230 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008231 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8232 OPT_MODELINE */
8233{
8234 char_u *errmsg = NULL;
8235 long old_value = *(long *)varp;
8236 long old_Rows = Rows; /* remember old Rows */
8237 long old_Columns = Columns; /* remember old Columns */
8238 long *pp = (long *)varp;
8239
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008240 /* Disallow changing some options from secure mode. */
8241 if ((secure
8242#ifdef HAVE_SANDBOX
8243 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008244#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008245 ) && (options[opt_idx].flags & P_SECURE))
8246 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008247
8248 *pp = value;
8249#ifdef FEAT_EVAL
8250 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008251 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008252#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008253#ifdef FEAT_GUI
8254 need_mouse_correct = TRUE;
8255#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008256
Bram Moolenaar14f24742012-08-08 18:01:05 +02008257 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008258 {
8259 errmsg = e_positive;
8260 curbuf->b_p_sw = curbuf->b_p_ts;
8261 }
8262
8263 /*
8264 * Number options that need some action when changed
8265 */
8266#ifdef FEAT_WINDOWS
8267 if (pp == &p_wh || pp == &p_hh)
8268 {
8269 if (p_wh < 1)
8270 {
8271 errmsg = e_positive;
8272 p_wh = 1;
8273 }
8274 if (p_wmh > p_wh)
8275 {
8276 errmsg = e_winheight;
8277 p_wh = p_wmh;
8278 }
8279 if (p_hh < 0)
8280 {
8281 errmsg = e_positive;
8282 p_hh = 0;
8283 }
8284
8285 /* Change window height NOW */
8286 if (lastwin != firstwin)
8287 {
8288 if (pp == &p_wh && curwin->w_height < p_wh)
8289 win_setheight((int)p_wh);
8290 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8291 win_setheight((int)p_hh);
8292 }
8293 }
8294
8295 /* 'winminheight' */
8296 else if (pp == &p_wmh)
8297 {
8298 if (p_wmh < 0)
8299 {
8300 errmsg = e_positive;
8301 p_wmh = 0;
8302 }
8303 if (p_wmh > p_wh)
8304 {
8305 errmsg = e_winheight;
8306 p_wmh = p_wh;
8307 }
8308 win_setminheight();
8309 }
8310
8311# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008312 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008313 {
8314 if (p_wiw < 1)
8315 {
8316 errmsg = e_positive;
8317 p_wiw = 1;
8318 }
8319 if (p_wmw > p_wiw)
8320 {
8321 errmsg = e_winwidth;
8322 p_wiw = p_wmw;
8323 }
8324
8325 /* Change window width NOW */
8326 if (lastwin != firstwin && curwin->w_width < p_wiw)
8327 win_setwidth((int)p_wiw);
8328 }
8329
8330 /* 'winminwidth' */
8331 else if (pp == &p_wmw)
8332 {
8333 if (p_wmw < 0)
8334 {
8335 errmsg = e_positive;
8336 p_wmw = 0;
8337 }
8338 if (p_wmw > p_wiw)
8339 {
8340 errmsg = e_winwidth;
8341 p_wmw = p_wiw;
8342 }
8343 win_setminheight();
8344 }
8345# endif
8346
8347#endif
8348
8349#ifdef FEAT_WINDOWS
8350 /* (re)set last window status line */
8351 else if (pp == &p_ls)
8352 {
8353 last_status(FALSE);
8354 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008355
8356 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008357 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008358 {
8359 shell_new_rows(); /* recompute window positions and heights */
8360 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008361#endif
8362
8363#ifdef FEAT_GUI
8364 else if (pp == &p_linespace)
8365 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008366 /* Recompute gui.char_height and resize the Vim window to keep the
8367 * same number of lines. */
8368 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008369 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008370 }
8371#endif
8372
8373#ifdef FEAT_FOLDING
8374 /* 'foldlevel' */
8375 else if (pp == &curwin->w_p_fdl)
8376 {
8377 if (curwin->w_p_fdl < 0)
8378 curwin->w_p_fdl = 0;
8379 newFoldLevel();
8380 }
8381
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008382 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383 else if (pp == &curwin->w_p_fml)
8384 {
8385 foldUpdateAll(curwin);
8386 }
8387
8388 /* 'foldnestmax' */
8389 else if (pp == &curwin->w_p_fdn)
8390 {
8391 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8392 foldUpdateAll(curwin);
8393 }
8394
8395 /* 'foldcolumn' */
8396 else if (pp == &curwin->w_p_fdc)
8397 {
8398 if (curwin->w_p_fdc < 0)
8399 {
8400 errmsg = e_positive;
8401 curwin->w_p_fdc = 0;
8402 }
8403 else if (curwin->w_p_fdc > 12)
8404 {
8405 errmsg = e_invarg;
8406 curwin->w_p_fdc = 12;
8407 }
8408 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008409#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008410
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008411#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412 /* 'shiftwidth' or 'tabstop' */
8413 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8414 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008415# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008416 if (foldmethodIsIndent(curwin))
8417 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008418# endif
8419# ifdef FEAT_CINDENT
8420 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8421 * parse 'cinoptions'. */
8422 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8423 parse_cino(curbuf);
8424# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008425 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008426#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008427
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008428#ifdef FEAT_MBYTE
8429 /* 'maxcombine' */
8430 else if (pp == &p_mco)
8431 {
8432 if (p_mco > MAX_MCO)
8433 p_mco = MAX_MCO;
8434 else if (p_mco < 0)
8435 p_mco = 0;
8436 screenclear(); /* will re-allocate the screen */
8437 }
8438#endif
8439
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 else if (pp == &curbuf->b_p_iminsert)
8441 {
8442 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8443 {
8444 errmsg = e_invarg;
8445 curbuf->b_p_iminsert = B_IMODE_NONE;
8446 }
8447 p_iminsert = curbuf->b_p_iminsert;
8448 if (termcap_active) /* don't do this in the alternate screen */
8449 showmode();
8450#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8451 /* Show/unshow value of 'keymap' in status lines. */
8452 status_redraw_curbuf();
8453#endif
8454 }
8455
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008456 else if (pp == &p_window)
8457 {
8458 if (p_window < 1)
8459 p_window = 1;
8460 else if (p_window >= Rows)
8461 p_window = Rows - 1;
8462 }
8463
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464 else if (pp == &curbuf->b_p_imsearch)
8465 {
8466 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8467 {
8468 errmsg = e_invarg;
8469 curbuf->b_p_imsearch = B_IMODE_NONE;
8470 }
8471 p_imsearch = curbuf->b_p_imsearch;
8472 }
8473
8474#ifdef FEAT_TITLE
8475 /* if 'titlelen' has changed, redraw the title */
8476 else if (pp == &p_titlelen)
8477 {
8478 if (p_titlelen < 0)
8479 {
8480 errmsg = e_positive;
8481 p_titlelen = 85;
8482 }
8483 if (starting != NO_SCREEN && old_value != p_titlelen)
8484 need_maketitle = TRUE;
8485 }
8486#endif
8487
8488 /* if p_ch changed value, change the command line height */
8489 else if (pp == &p_ch)
8490 {
8491 if (p_ch < 1)
8492 {
8493 errmsg = e_positive;
8494 p_ch = 1;
8495 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008496 if (p_ch > Rows - min_rows() + 1)
8497 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008498
8499 /* Only compute the new window layout when startup has been
8500 * completed. Otherwise the frame sizes may be wrong. */
8501 if (p_ch != old_value && full_screen
8502#ifdef FEAT_GUI
8503 && !gui.starting
8504#endif
8505 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008506 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008507 }
8508
8509 /* when 'updatecount' changes from zero to non-zero, open swap files */
8510 else if (pp == &p_uc)
8511 {
8512 if (p_uc < 0)
8513 {
8514 errmsg = e_positive;
8515 p_uc = 100;
8516 }
8517 if (p_uc && !old_value)
8518 ml_open_files();
8519 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008520#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008521 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008522 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008523 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008524 {
8525 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008526 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008527 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008528 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008529 {
8530 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008531 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008532 }
8533 }
8534#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008535#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008536 else if (pp == &p_mzq)
8537 mzvim_reset_timer();
8538#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008539
8540 /* sync undo before 'undolevels' changes */
8541 else if (pp == &p_ul)
8542 {
8543 /* use the old value, otherwise u_sync() may not work properly */
8544 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008545 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008546 p_ul = value;
8547 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008548 else if (pp == &curbuf->b_p_ul)
8549 {
8550 /* use the old value, otherwise u_sync() may not work properly */
8551 curbuf->b_p_ul = old_value;
8552 u_sync(TRUE);
8553 curbuf->b_p_ul = value;
8554 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008555
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008556#ifdef FEAT_LINEBREAK
8557 /* 'numberwidth' must be positive */
8558 else if (pp == &curwin->w_p_nuw)
8559 {
8560 if (curwin->w_p_nuw < 1)
8561 {
8562 errmsg = e_positive;
8563 curwin->w_p_nuw = 1;
8564 }
8565 if (curwin->w_p_nuw > 10)
8566 {
8567 errmsg = e_invarg;
8568 curwin->w_p_nuw = 10;
8569 }
8570 curwin->w_nrwidth_line_count = 0;
8571 }
8572#endif
8573
Bram Moolenaar1a384422010-07-14 19:53:30 +02008574 else if (pp == &curbuf->b_p_tw)
8575 {
8576 if (curbuf->b_p_tw < 0)
8577 {
8578 errmsg = e_positive;
8579 curbuf->b_p_tw = 0;
8580 }
8581#ifdef FEAT_SYN_HL
8582# ifdef FEAT_WINDOWS
8583 {
8584 win_T *wp;
8585 tabpage_T *tp;
8586
8587 FOR_ALL_TAB_WINDOWS(tp, wp)
8588 check_colorcolumn(wp);
8589 }
8590# else
8591 check_colorcolumn(curwin);
8592# endif
8593#endif
8594 }
8595
Bram Moolenaar071d4272004-06-13 20:20:40 +00008596 /*
8597 * Check the bounds for numeric options here
8598 */
8599 if (Rows < min_rows() && full_screen)
8600 {
8601 if (errbuf != NULL)
8602 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008603 vim_snprintf((char *)errbuf, errbuflen,
8604 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008605 errmsg = errbuf;
8606 }
8607 Rows = min_rows();
8608 }
8609 if (Columns < MIN_COLUMNS && full_screen)
8610 {
8611 if (errbuf != NULL)
8612 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008613 vim_snprintf((char *)errbuf, errbuflen,
8614 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008615 errmsg = errbuf;
8616 }
8617 Columns = MIN_COLUMNS;
8618 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008619 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008620
8621#ifdef DJGPP
8622 /* avoid a crash by checking for a too large value of 'columns' */
8623 if (old_Columns != Columns && full_screen && term_console)
8624 mch_check_columns();
8625#endif
8626
8627 /*
8628 * If the screen (shell) height has been changed, assume it is the
8629 * physical screenheight.
8630 */
8631 if (old_Rows != Rows || old_Columns != Columns)
8632 {
8633 /* Changing the screen size is not allowed while updating the screen. */
8634 if (updating_screen)
8635 *pp = old_value;
8636 else if (full_screen
8637#ifdef FEAT_GUI
8638 && !gui.starting
8639#endif
8640 )
8641 set_shellsize((int)Columns, (int)Rows, TRUE);
8642 else
8643 {
8644 /* Postpone the resizing; check the size and cmdline position for
8645 * messages. */
8646 check_shellsize();
8647 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8648 cmdline_row = Rows - p_ch;
8649 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008650 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008651 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652 }
8653
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654 if (curbuf->b_p_ts <= 0)
8655 {
8656 errmsg = e_positive;
8657 curbuf->b_p_ts = 8;
8658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008659 if (p_tm < 0)
8660 {
8661 errmsg = e_positive;
8662 p_tm = 0;
8663 }
8664 if ((curwin->w_p_scr <= 0
8665 || (curwin->w_p_scr > curwin->w_height
8666 && curwin->w_height > 0))
8667 && full_screen)
8668 {
8669 if (pp == &(curwin->w_p_scr))
8670 {
8671 if (curwin->w_p_scr != 0)
8672 errmsg = e_scroll;
8673 win_comp_scroll(curwin);
8674 }
8675 /* If 'scroll' became invalid because of a side effect silently adjust
8676 * it. */
8677 else if (curwin->w_p_scr <= 0)
8678 curwin->w_p_scr = 1;
8679 else /* curwin->w_p_scr > curwin->w_height */
8680 curwin->w_p_scr = curwin->w_height;
8681 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008682 if (p_hi < 0)
8683 {
8684 errmsg = e_positive;
8685 p_hi = 0;
8686 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008687 else if (p_hi > 10000)
8688 {
8689 errmsg = e_invarg;
8690 p_hi = 10000;
8691 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008692 if (p_re < 0 || p_re > 2)
8693 {
8694 errmsg = e_invarg;
8695 p_re = 0;
8696 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697 if (p_report < 0)
8698 {
8699 errmsg = e_positive;
8700 p_report = 1;
8701 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008702 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008703 {
8704 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8705 p_sj = Rows / 2;
8706 else
8707 {
8708 errmsg = e_scroll;
8709 p_sj = 1;
8710 }
8711 }
8712 if (p_so < 0 && full_screen)
8713 {
8714 errmsg = e_scroll;
8715 p_so = 0;
8716 }
8717 if (p_siso < 0 && full_screen)
8718 {
8719 errmsg = e_positive;
8720 p_siso = 0;
8721 }
8722#ifdef FEAT_CMDWIN
8723 if (p_cwh < 1)
8724 {
8725 errmsg = e_positive;
8726 p_cwh = 1;
8727 }
8728#endif
8729 if (p_ut < 0)
8730 {
8731 errmsg = e_positive;
8732 p_ut = 2000;
8733 }
8734 if (p_ss < 0)
8735 {
8736 errmsg = e_positive;
8737 p_ss = 0;
8738 }
8739
8740 /* May set global value for local option. */
8741 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8742 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8743
8744 options[opt_idx].flags |= P_WAS_SET;
8745
8746 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008747 if (curwin->w_curswant != MAXCOL
8748 && (options[opt_idx].flags & (P_CURSWANT | P_RCLR)) != 0)
8749 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750 check_redraw(options[opt_idx].flags);
8751
8752 return errmsg;
8753}
8754
8755/*
8756 * Called after an option changed: check if something needs to be redrawn.
8757 */
8758 static void
8759check_redraw(flags)
8760 long_u flags;
8761{
8762 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008763 int doclear = (flags & P_RCLR) == P_RCLR;
8764 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765
8766#ifdef FEAT_WINDOWS
8767 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8768 status_redraw_all();
8769#endif
8770
8771 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8772 changed_window_setting();
8773 if (flags & P_RBUF)
8774 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008775 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776 redraw_all_later(CLEAR);
8777 else if (all)
8778 redraw_all_later(NOT_VALID);
8779}
8780
8781/*
8782 * Find index for option 'arg'.
8783 * Return -1 if not found.
8784 */
8785 static int
8786findoption(arg)
8787 char_u *arg;
8788{
8789 int opt_idx;
8790 char *s, *p;
8791 static short quick_tab[27] = {0, 0}; /* quick access table */
8792 int is_term_opt;
8793
8794 /*
8795 * For first call: Initialize the quick-access table.
8796 * It contains the index for the first option that starts with a certain
8797 * letter. There are 26 letters, plus the first "t_" option.
8798 */
8799 if (quick_tab[1] == 0)
8800 {
8801 p = options[0].fullname;
8802 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8803 {
8804 if (s[0] != p[0])
8805 {
8806 if (s[0] == 't' && s[1] == '_')
8807 quick_tab[26] = opt_idx;
8808 else
8809 quick_tab[CharOrdLow(s[0])] = opt_idx;
8810 }
8811 p = s;
8812 }
8813 }
8814
8815 /*
8816 * Check for name starting with an illegal character.
8817 */
8818#ifdef EBCDIC
8819 if (!islower(arg[0]))
8820#else
8821 if (arg[0] < 'a' || arg[0] > 'z')
8822#endif
8823 return -1;
8824
8825 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8826 if (is_term_opt)
8827 opt_idx = quick_tab[26];
8828 else
8829 opt_idx = quick_tab[CharOrdLow(arg[0])];
8830 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8831 {
8832 if (STRCMP(arg, s) == 0) /* match full name */
8833 break;
8834 }
8835 if (s == NULL && !is_term_opt)
8836 {
8837 opt_idx = quick_tab[CharOrdLow(arg[0])];
8838 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8839 {
8840 s = options[opt_idx].shortname;
8841 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8842 break;
8843 s = NULL;
8844 }
8845 }
8846 if (s == NULL)
8847 opt_idx = -1;
8848 return opt_idx;
8849}
8850
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008851#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852/*
8853 * Get the value for an option.
8854 *
8855 * Returns:
8856 * Number or Toggle option: 1, *numval gets value.
8857 * String option: 0, *stringval gets allocated string.
8858 * Hidden Number or Toggle option: -1.
8859 * hidden String option: -2.
8860 * unknown option: -3.
8861 */
8862 int
8863get_option_value(name, numval, stringval, opt_flags)
8864 char_u *name;
8865 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008866 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008867 int opt_flags;
8868{
8869 int opt_idx;
8870 char_u *varp;
8871
8872 opt_idx = findoption(name);
8873 if (opt_idx < 0) /* unknown option */
8874 return -3;
8875
8876 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8877
8878 if (options[opt_idx].flags & P_STRING)
8879 {
8880 if (varp == NULL) /* hidden option */
8881 return -2;
8882 if (stringval != NULL)
8883 {
8884#ifdef FEAT_CRYPT
8885 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008886 if ((char_u **)varp == &curbuf->b_p_key
8887 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008888 *stringval = vim_strsave((char_u *)"*****");
8889 else
8890#endif
8891 *stringval = vim_strsave(*(char_u **)(varp));
8892 }
8893 return 0;
8894 }
8895
8896 if (varp == NULL) /* hidden option */
8897 return -1;
8898 if (options[opt_idx].flags & P_NUM)
8899 *numval = *(long *)varp;
8900 else
8901 {
8902 /* Special case: 'modified' is b_changed, but we also want to consider
8903 * it set when 'ff' or 'fenc' changed. */
8904 if ((int *)varp == &curbuf->b_changed)
8905 *numval = curbufIsChanged();
8906 else
8907 *numval = *(int *)varp;
8908 }
8909 return 1;
8910}
8911#endif
8912
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008913#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008914/*
8915 * Returns the option attributes and its value. Unlike the above function it
8916 * will return either global value or local value of the option depending on
8917 * what was requested, but it will never return global value if it was
8918 * requested to return local one and vice versa. Neither it will return
8919 * buffer-local value if it was requested to return window-local one.
8920 *
8921 * Pretends that option is absent if it is not present in the requested scope
8922 * (i.e. has no global, window-local or buffer-local value depending on
8923 * opt_type). Uses
8924 *
8925 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008926 * 0 hidden or unknown option, also option that does not have requested
8927 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008928 * see SOPT_* in vim.h for other flags
8929 *
8930 * Possible opt_type values: see SREQ_* in vim.h
8931 */
8932 int
8933get_option_value_strict(name, numval, stringval, opt_type, from)
8934 char_u *name;
8935 long *numval;
8936 char_u **stringval; /* NULL when only obtaining attributes */
8937 int opt_type;
8938 void *from;
8939{
8940 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008941 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008942 struct vimoption *p;
8943 int r = 0;
8944
8945 opt_idx = findoption(name);
8946 if (opt_idx < 0)
8947 return 0;
8948
8949 p = &(options[opt_idx]);
8950
8951 /* Hidden option */
8952 if (p->var == NULL)
8953 return 0;
8954
8955 if (p->flags & P_BOOL)
8956 r |= SOPT_BOOL;
8957 else if (p->flags & P_NUM)
8958 r |= SOPT_NUM;
8959 else if (p->flags & P_STRING)
8960 r |= SOPT_STRING;
8961
8962 if (p->indir == PV_NONE)
8963 {
8964 if (opt_type == SREQ_GLOBAL)
8965 r |= SOPT_GLOBAL;
8966 else
8967 return 0; /* Did not request global-only option */
8968 }
8969 else
8970 {
8971 if (p->indir & PV_BOTH)
8972 r |= SOPT_GLOBAL;
8973 else if (opt_type == SREQ_GLOBAL)
8974 return 0; /* Requested global option */
8975
8976 if (p->indir & PV_WIN)
8977 {
8978 if (opt_type == SREQ_BUF)
8979 return 0; /* Did not request window-local option */
8980 else
8981 r |= SOPT_WIN;
8982 }
8983 else if (p->indir & PV_BUF)
8984 {
8985 if (opt_type == SREQ_WIN)
8986 return 0; /* Did not request buffer-local option */
8987 else
8988 r |= SOPT_BUF;
8989 }
8990 }
8991
8992 if (stringval == NULL)
8993 return r;
8994
8995 if (opt_type == SREQ_GLOBAL)
8996 varp = p->var;
8997 else
8998 {
8999 if (opt_type == SREQ_BUF)
9000 {
9001 /* Special case: 'modified' is b_changed, but we also want to
9002 * consider it set when 'ff' or 'fenc' changed. */
9003 if (p->indir == PV_MOD)
9004 {
9005 *numval = bufIsChanged((buf_T *) from);
9006 varp = NULL;
9007 }
9008#ifdef FEAT_CRYPT
9009 else if (p->indir == PV_KEY)
9010 {
9011 /* never return the value of the crypt key */
9012 *stringval = NULL;
9013 varp = NULL;
9014 }
9015#endif
9016 else
9017 {
9018 aco_save_T aco;
9019 aucmd_prepbuf(&aco, (buf_T *) from);
9020 varp = get_varp(p);
9021 aucmd_restbuf(&aco);
9022 }
9023 }
9024 else if (opt_type == SREQ_WIN)
9025 {
9026 win_T *save_curwin;
9027 save_curwin = curwin;
9028 curwin = (win_T *) from;
9029 curbuf = curwin->w_buffer;
9030 varp = get_varp(p);
9031 curwin = save_curwin;
9032 curbuf = curwin->w_buffer;
9033 }
9034 if (varp == p->var)
9035 return (r | SOPT_UNSET);
9036 }
9037
9038 if (varp != NULL)
9039 {
9040 if (p->flags & P_STRING)
9041 *stringval = vim_strsave(*(char_u **)(varp));
9042 else if (p->flags & P_NUM)
9043 *numval = *(long *) varp;
9044 else
9045 *numval = *(int *)varp;
9046 }
9047
9048 return r;
9049}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009050
9051/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009052 * Iterate over options. First argument is a pointer to a pointer to a
9053 * structure inside options[] array, second is option type like in the above
9054 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009055 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009056 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009057 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009058 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009059 * first argument to NULL.
9060 *
9061 * Returns full option name for current option on each call.
9062 */
9063 char_u *
9064option_iter_next(option, opt_type)
9065 void **option;
9066 int opt_type;
9067{
9068 struct vimoption *ret = NULL;
9069 do
9070 {
9071 if (*option == NULL)
9072 *option = (void *) options;
9073 else if (((struct vimoption *) (*option))->fullname == NULL)
9074 {
9075 *option = NULL;
9076 return NULL;
9077 }
9078 else
9079 *option = (void *) (((struct vimoption *) (*option)) + 1);
9080
9081 ret = ((struct vimoption *) (*option));
9082
9083 /* Hidden option */
9084 if (ret->var == NULL)
9085 {
9086 ret = NULL;
9087 continue;
9088 }
9089
9090 switch (opt_type)
9091 {
9092 case SREQ_GLOBAL:
9093 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9094 ret = NULL;
9095 break;
9096 case SREQ_BUF:
9097 if (!(ret->indir & PV_BUF))
9098 ret = NULL;
9099 break;
9100 case SREQ_WIN:
9101 if (!(ret->indir & PV_WIN))
9102 ret = NULL;
9103 break;
9104 default:
9105 EMSG2(_(e_intern2), "option_iter_next()");
9106 return NULL;
9107 }
9108 }
9109 while (ret == NULL);
9110
9111 return (char_u *)ret->fullname;
9112}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009113#endif
9114
Bram Moolenaar071d4272004-06-13 20:20:40 +00009115/*
9116 * Set the value of option "name".
9117 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009118 *
9119 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009120 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009121 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009122set_option_value(name, number, string, opt_flags)
9123 char_u *name;
9124 long number;
9125 char_u *string;
9126 int opt_flags; /* OPT_LOCAL or 0 (both) */
9127{
9128 int opt_idx;
9129 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009130 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009131
9132 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009133 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009134 EMSG2(_("E355: Unknown option: %s"), name);
9135 else
9136 {
9137 flags = options[opt_idx].flags;
9138#ifdef HAVE_SANDBOX
9139 /* Disallow changing some options in the sandbox */
9140 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009141 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009143 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009144 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009145#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009146 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009147 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 else
9149 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009150 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009151 if (varp != NULL) /* hidden option is not changed */
9152 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009153 if (number == 0 && string != NULL)
9154 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009155 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009156
9157 /* Either we are given a string or we are setting option
9158 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009159 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009160 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009161 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009162 {
9163 /* There's another character after zeros or the string
9164 * is empty. In both cases, we are trying to set a
9165 * num option using a string. */
9166 EMSG3(_("E521: Number required: &%s = '%s'"),
9167 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009168 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009169
9170 }
9171 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009173 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009174 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009175 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009176 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009177 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009178 }
9179 }
9180 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009181 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009182}
9183
9184/*
9185 * Get the terminal code for a terminal option.
9186 * Returns NULL when not found.
9187 */
9188 char_u *
9189get_term_code(tname)
9190 char_u *tname;
9191{
9192 int opt_idx;
9193 char_u *varp;
9194
9195 if (tname[0] != 't' || tname[1] != '_' ||
9196 tname[2] == NUL || tname[3] == NUL)
9197 return NULL;
9198 if ((opt_idx = findoption(tname)) >= 0)
9199 {
9200 varp = get_varp(&(options[opt_idx]));
9201 if (varp != NULL)
9202 varp = *(char_u **)(varp);
9203 return varp;
9204 }
9205 return find_termcode(tname + 2);
9206}
9207
9208 char_u *
9209get_highlight_default()
9210{
9211 int i;
9212
9213 i = findoption((char_u *)"hl");
9214 if (i >= 0)
9215 return options[i].def_val[VI_DEFAULT];
9216 return (char_u *)NULL;
9217}
9218
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009219#if defined(FEAT_MBYTE) || defined(PROTO)
9220 char_u *
9221get_encoding_default()
9222{
9223 int i;
9224
9225 i = findoption((char_u *)"enc");
9226 if (i >= 0)
9227 return options[i].def_val[VI_DEFAULT];
9228 return (char_u *)NULL;
9229}
9230#endif
9231
Bram Moolenaar071d4272004-06-13 20:20:40 +00009232/*
9233 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9234 */
9235 static int
9236find_key_option(arg)
9237 char_u *arg;
9238{
9239 int key;
9240 int modifiers;
9241
9242 /*
9243 * Don't use get_special_key_code() for t_xx, we don't want it to call
9244 * add_termcap_entry().
9245 */
9246 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9247 key = TERMCAP2KEY(arg[2], arg[3]);
9248 else
9249 {
9250 --arg; /* put arg at the '<' */
9251 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009252 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009253 if (modifiers) /* can't handle modifiers here */
9254 key = 0;
9255 }
9256 return key;
9257}
9258
9259/*
9260 * if 'all' == 0: show changed options
9261 * if 'all' == 1: show all normal options
9262 * if 'all' == 2: show all terminal options
9263 */
9264 static void
9265showoptions(all, opt_flags)
9266 int all;
9267 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9268{
9269 struct vimoption *p;
9270 int col;
9271 int isterm;
9272 char_u *varp;
9273 struct vimoption **items;
9274 int item_count;
9275 int run;
9276 int row, rows;
9277 int cols;
9278 int i;
9279 int len;
9280
9281#define INC 20
9282#define GAP 3
9283
9284 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9285 PARAM_COUNT));
9286 if (items == NULL)
9287 return;
9288
9289 /* Highlight title */
9290 if (all == 2)
9291 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9292 else if (opt_flags & OPT_GLOBAL)
9293 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9294 else if (opt_flags & OPT_LOCAL)
9295 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9296 else
9297 MSG_PUTS_TITLE(_("\n--- Options ---"));
9298
9299 /*
9300 * do the loop two times:
9301 * 1. display the short items
9302 * 2. display the long items (only strings and numbers)
9303 */
9304 for (run = 1; run <= 2 && !got_int; ++run)
9305 {
9306 /*
9307 * collect the items in items[]
9308 */
9309 item_count = 0;
9310 for (p = &options[0]; p->fullname != NULL; p++)
9311 {
9312 varp = NULL;
9313 isterm = istermoption(p);
9314 if (opt_flags != 0)
9315 {
9316 if (p->indir != PV_NONE && !isterm)
9317 varp = get_varp_scope(p, opt_flags);
9318 }
9319 else
9320 varp = get_varp(p);
9321 if (varp != NULL
9322 && ((all == 2 && isterm)
9323 || (all == 1 && !isterm)
9324 || (all == 0 && !optval_default(p, varp))))
9325 {
9326 if (p->flags & P_BOOL)
9327 len = 1; /* a toggle option fits always */
9328 else
9329 {
9330 option_value2string(p, opt_flags);
9331 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9332 }
9333 if ((len <= INC - GAP && run == 1) ||
9334 (len > INC - GAP && run == 2))
9335 items[item_count++] = p;
9336 }
9337 }
9338
9339 /*
9340 * display the items
9341 */
9342 if (run == 1)
9343 {
9344 cols = (Columns + GAP - 3) / INC;
9345 if (cols == 0)
9346 cols = 1;
9347 rows = (item_count + cols - 1) / cols;
9348 }
9349 else /* run == 2 */
9350 rows = item_count;
9351 for (row = 0; row < rows && !got_int; ++row)
9352 {
9353 msg_putchar('\n'); /* go to next line */
9354 if (got_int) /* 'q' typed in more */
9355 break;
9356 col = 0;
9357 for (i = row; i < item_count; i += rows)
9358 {
9359 msg_col = col; /* make columns */
9360 showoneopt(items[i], opt_flags);
9361 col += INC;
9362 }
9363 out_flush();
9364 ui_breakcheck();
9365 }
9366 }
9367 vim_free(items);
9368}
9369
9370/*
9371 * Return TRUE if option "p" has its default value.
9372 */
9373 static int
9374optval_default(p, varp)
9375 struct vimoption *p;
9376 char_u *varp;
9377{
9378 int dvi;
9379
9380 if (varp == NULL)
9381 return TRUE; /* hidden option is always at default */
9382 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9383 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009384 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009385 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009386 /* the cast to long is required for Manx C, long_i is
9387 * needed for MSVC */
9388 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009389 /* P_STRING */
9390 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9391}
9392
9393/*
9394 * showoneopt: show the value of one option
9395 * must not be called with a hidden option!
9396 */
9397 static void
9398showoneopt(p, opt_flags)
9399 struct vimoption *p;
9400 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9401{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009402 char_u *varp;
9403 int save_silent = silent_mode;
9404
9405 silent_mode = FALSE;
9406 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009407
9408 varp = get_varp_scope(p, opt_flags);
9409
9410 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9411 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9412 ? !curbufIsChanged() : !*(int *)varp))
9413 MSG_PUTS("no");
9414 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9415 MSG_PUTS("--");
9416 else
9417 MSG_PUTS(" ");
9418 MSG_PUTS(p->fullname);
9419 if (!(p->flags & P_BOOL))
9420 {
9421 msg_putchar('=');
9422 /* put value string in NameBuff */
9423 option_value2string(p, opt_flags);
9424 msg_outtrans(NameBuff);
9425 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009426
9427 silent_mode = save_silent;
9428 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009429}
9430
9431/*
9432 * Write modified options as ":set" commands to a file.
9433 *
9434 * There are three values for "opt_flags":
9435 * OPT_GLOBAL: Write global option values and fresh values of
9436 * buffer-local options (used for start of a session
9437 * file).
9438 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9439 * curwin (used for a vimrc file).
9440 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9441 * and local values for window-local options of
9442 * curwin. Local values are also written when at the
9443 * default value, because a modeline or autocommand
9444 * may have set them when doing ":edit file" and the
9445 * user has set them back at the default or fresh
9446 * value.
9447 * When "local_only" is TRUE, don't write fresh
9448 * values, only local values (for ":mkview").
9449 * (fresh value = value used for a new buffer or window for a local option).
9450 *
9451 * Return FAIL on error, OK otherwise.
9452 */
9453 int
9454makeset(fd, opt_flags, local_only)
9455 FILE *fd;
9456 int opt_flags;
9457 int local_only;
9458{
9459 struct vimoption *p;
9460 char_u *varp; /* currently used value */
9461 char_u *varp_fresh; /* local value */
9462 char_u *varp_local = NULL; /* fresh value */
9463 char *cmd;
9464 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009465 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009466
9467 /*
9468 * The options that don't have a default (terminal name, columns, lines)
9469 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009470 * Do the loop over "options[]" twice: once for options with the
9471 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009472 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009473 for (pri = 1; pri >= 0; --pri)
9474 {
9475 for (p = &options[0]; !istermoption(p); p++)
9476 if (!(p->flags & P_NO_MKRC)
9477 && !istermoption(p)
9478 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009479 {
9480 /* skip global option when only doing locals */
9481 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9482 continue;
9483
9484 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9485 * file, they are always buffer-specific. */
9486 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9487 continue;
9488
9489 /* Global values are only written when not at the default value. */
9490 varp = get_varp_scope(p, opt_flags);
9491 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9492 continue;
9493
9494 round = 2;
9495 if (p->indir != PV_NONE)
9496 {
9497 if (p->var == VAR_WIN)
9498 {
9499 /* skip window-local option when only doing globals */
9500 if (!(opt_flags & OPT_LOCAL))
9501 continue;
9502 /* When fresh value of window-local option is not at the
9503 * default, need to write it too. */
9504 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9505 {
9506 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9507 if (!optval_default(p, varp_fresh))
9508 {
9509 round = 1;
9510 varp_local = varp;
9511 varp = varp_fresh;
9512 }
9513 }
9514 }
9515 }
9516
9517 /* Round 1: fresh value for window-local options.
9518 * Round 2: other values */
9519 for ( ; round <= 2; varp = varp_local, ++round)
9520 {
9521 if (round == 1 || (opt_flags & OPT_GLOBAL))
9522 cmd = "set";
9523 else
9524 cmd = "setlocal";
9525
9526 if (p->flags & P_BOOL)
9527 {
9528 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9529 return FAIL;
9530 }
9531 else if (p->flags & P_NUM)
9532 {
9533 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9534 return FAIL;
9535 }
9536 else /* P_STRING */
9537 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009538#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9539 int do_endif = FALSE;
9540
Bram Moolenaar071d4272004-06-13 20:20:40 +00009541 /* Don't set 'syntax' and 'filetype' again if the value is
9542 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009543 if (
9544# if defined(FEAT_SYN_HL)
9545 p->indir == PV_SYN
9546# if defined(FEAT_AUTOCMD)
9547 ||
9548# endif
9549# endif
9550# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009551 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009552# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009553 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009554 {
9555 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9556 *(char_u **)(varp)) < 0
9557 || put_eol(fd) < 0)
9558 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009559 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009560 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009561#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009562 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9563 (p->flags & P_EXPAND) != 0) == FAIL)
9564 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009565#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9566 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009567 {
9568 if (put_line(fd, "endif") == FAIL)
9569 return FAIL;
9570 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009571#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009572 }
9573 }
9574 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576 return OK;
9577}
9578
9579#if defined(FEAT_FOLDING) || defined(PROTO)
9580/*
9581 * Generate set commands for the local fold options only. Used when
9582 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9583 */
9584 int
9585makefoldset(fd)
9586 FILE *fd;
9587{
9588 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9589# ifdef FEAT_EVAL
9590 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9591 == FAIL
9592# endif
9593 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9594 == FAIL
9595 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9596 == FAIL
9597 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9598 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9599 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9600 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9601 )
9602 return FAIL;
9603
9604 return OK;
9605}
9606#endif
9607
9608 static int
9609put_setstring(fd, cmd, name, valuep, expand)
9610 FILE *fd;
9611 char *cmd;
9612 char *name;
9613 char_u **valuep;
9614 int expand;
9615{
9616 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009617 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009618
9619 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9620 return FAIL;
9621 if (*valuep != NULL)
9622 {
9623 /* Output 'pastetoggle' as key names. For other
9624 * options some characters have to be escaped with
9625 * CTRL-V or backslash */
9626 if (valuep == &p_pt)
9627 {
9628 s = *valuep;
9629 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009630 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009631 return FAIL;
9632 }
9633 else if (expand)
9634 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009635 buf = alloc(MAXPATHL);
9636 if (buf == NULL)
9637 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009638 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9639 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009640 {
9641 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009642 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009643 }
9644 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645 }
9646 else if (put_escstr(fd, *valuep, 2) == FAIL)
9647 return FAIL;
9648 }
9649 if (put_eol(fd) < 0)
9650 return FAIL;
9651 return OK;
9652}
9653
9654 static int
9655put_setnum(fd, cmd, name, valuep)
9656 FILE *fd;
9657 char *cmd;
9658 char *name;
9659 long *valuep;
9660{
9661 long wc;
9662
9663 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9664 return FAIL;
9665 if (wc_use_keyname((char_u *)valuep, &wc))
9666 {
9667 /* print 'wildchar' and 'wildcharm' as a key name */
9668 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9669 return FAIL;
9670 }
9671 else if (fprintf(fd, "%ld", *valuep) < 0)
9672 return FAIL;
9673 if (put_eol(fd) < 0)
9674 return FAIL;
9675 return OK;
9676}
9677
9678 static int
9679put_setbool(fd, cmd, name, value)
9680 FILE *fd;
9681 char *cmd;
9682 char *name;
9683 int value;
9684{
Bram Moolenaar893de922007-10-02 18:40:57 +00009685 if (value < 0) /* global/local option using global value */
9686 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009687 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9688 || put_eol(fd) < 0)
9689 return FAIL;
9690 return OK;
9691}
9692
9693/*
9694 * Clear all the terminal options.
9695 * If the option has been allocated, free the memory.
9696 * Terminal options are never hidden or indirect.
9697 */
9698 void
9699clear_termoptions()
9700{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009701 /*
9702 * Reset a few things before clearing the old options. This may cause
9703 * outputting a few things that the terminal doesn't understand, but the
9704 * screen will be cleared later, so this is OK.
9705 */
9706#ifdef FEAT_MOUSE_TTY
9707 mch_setmouse(FALSE); /* switch mouse off */
9708#endif
9709#ifdef FEAT_TITLE
9710 mch_restore_title(3); /* restore window titles */
9711#endif
9712#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9713 /* When starting the GUI close the display opened for the clipboard.
9714 * After restoring the title, because that will need the display. */
9715 if (gui.starting)
9716 clear_xterm_clip();
9717#endif
9718#ifdef WIN3264
9719 /*
9720 * Check if this is allowed now.
9721 */
9722 if (can_end_termcap_mode(FALSE) == TRUE)
9723#endif
9724 stoptermcap(); /* stop termcap mode */
9725
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009726 free_termoptions();
9727}
9728
9729 void
9730free_termoptions()
9731{
9732 struct vimoption *p;
9733
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 for (p = &options[0]; p->fullname != NULL; p++)
9735 if (istermoption(p))
9736 {
9737 if (p->flags & P_ALLOCED)
9738 free_string_option(*(char_u **)(p->var));
9739 if (p->flags & P_DEF_ALLOCED)
9740 free_string_option(p->def_val[VI_DEFAULT]);
9741 *(char_u **)(p->var) = empty_option;
9742 p->def_val[VI_DEFAULT] = empty_option;
9743 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9744 }
9745 clear_termcodes();
9746}
9747
9748/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009749 * Free the string for one term option, if it was allocated.
9750 * Set the string to empty_option and clear allocated flag.
9751 * "var" points to the option value.
9752 */
9753 void
9754free_one_termoption(var)
9755 char_u *var;
9756{
9757 struct vimoption *p;
9758
9759 for (p = &options[0]; p->fullname != NULL; p++)
9760 if (p->var == var)
9761 {
9762 if (p->flags & P_ALLOCED)
9763 free_string_option(*(char_u **)(p->var));
9764 *(char_u **)(p->var) = empty_option;
9765 p->flags &= ~P_ALLOCED;
9766 break;
9767 }
9768}
9769
9770/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009771 * Set the terminal option defaults to the current value.
9772 * Used after setting the terminal name.
9773 */
9774 void
9775set_term_defaults()
9776{
9777 struct vimoption *p;
9778
9779 for (p = &options[0]; p->fullname != NULL; p++)
9780 {
9781 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9782 {
9783 if (p->flags & P_DEF_ALLOCED)
9784 {
9785 free_string_option(p->def_val[VI_DEFAULT]);
9786 p->flags &= ~P_DEF_ALLOCED;
9787 }
9788 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9789 if (p->flags & P_ALLOCED)
9790 {
9791 p->flags |= P_DEF_ALLOCED;
9792 p->flags &= ~P_ALLOCED; /* don't free the value now */
9793 }
9794 }
9795 }
9796}
9797
9798/*
9799 * return TRUE if 'p' starts with 't_'
9800 */
9801 static int
9802istermoption(p)
9803 struct vimoption *p;
9804{
9805 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9806}
9807
9808/*
9809 * Compute columns for ruler and shown command. 'sc_col' is also used to
9810 * decide what the maximum length of a message on the status line can be.
9811 * If there is a status line for the last window, 'sc_col' is independent
9812 * of 'ru_col'.
9813 */
9814
9815#define COL_RULER 17 /* columns needed by standard ruler */
9816
9817 void
9818comp_col()
9819{
9820#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9821 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9822
9823 sc_col = 0;
9824 ru_col = 0;
9825 if (p_ru)
9826 {
9827#ifdef FEAT_STL_OPT
9828 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9829#else
9830 ru_col = COL_RULER + 1;
9831#endif
9832 /* no last status line, adjust sc_col */
9833 if (!last_has_status)
9834 sc_col = ru_col;
9835 }
9836 if (p_sc)
9837 {
9838 sc_col += SHOWCMD_COLS;
9839 if (!p_ru || last_has_status) /* no need for separating space */
9840 ++sc_col;
9841 }
9842 sc_col = Columns - sc_col;
9843 ru_col = Columns - ru_col;
9844 if (sc_col <= 0) /* screen too narrow, will become a mess */
9845 sc_col = 1;
9846 if (ru_col <= 0)
9847 ru_col = 1;
9848#else
9849 sc_col = Columns;
9850 ru_col = Columns;
9851#endif
9852}
9853
9854/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009855 * Unset local option value, similar to ":set opt<".
9856 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009857 void
9858unset_global_local_option(name, from)
9859 char_u *name;
9860 void *from;
9861{
9862 struct vimoption *p;
9863 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009864 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009865
9866 opt_idx = findoption(name);
9867 p = &(options[opt_idx]);
9868
9869 switch ((int)p->indir)
9870 {
9871 /* global option with local value: use local value if it's been set */
9872 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009873 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009874 break;
9875 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009876 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009877 break;
9878 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009879 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009880 break;
9881 case PV_AR:
9882 buf->b_p_ar = -1;
9883 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009884 case PV_BKC:
9885 clear_string_option(&buf->b_p_bkc);
9886 buf->b_bkc_flags = 0;
9887 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009888 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009889 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009890 break;
9891#ifdef FEAT_FIND_ID
9892 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009893 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009894 break;
9895 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009896 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009897 break;
9898#endif
9899#ifdef FEAT_INS_EXPAND
9900 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009901 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009902 break;
9903 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009904 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009905 break;
9906#endif
9907#ifdef FEAT_QUICKFIX
9908 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009909 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009910 break;
9911 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009912 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009913 break;
9914 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009915 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009916 break;
9917#endif
9918#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9919 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009920 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009921 break;
9922#endif
9923#if defined(FEAT_CRYPT)
9924 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009925 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009926 break;
9927#endif
9928#ifdef FEAT_STL_OPT
9929 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009930 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009931 break;
9932#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009933 case PV_UL:
9934 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9935 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009936#ifdef FEAT_LISP
9937 case PV_LW:
9938 clear_string_option(&buf->b_p_lw);
9939 break;
9940#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009941 }
9942}
9943
9944/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009945 * Get pointer to option variable, depending on local or global scope.
9946 */
9947 static char_u *
9948get_varp_scope(p, opt_flags)
9949 struct vimoption *p;
9950 int opt_flags;
9951{
9952 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9953 {
9954 if (p->var == VAR_WIN)
9955 return (char_u *)GLOBAL_WO(get_varp(p));
9956 return p->var;
9957 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009958 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959 {
9960 switch ((int)p->indir)
9961 {
9962#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009963 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9964 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9965 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009967 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9968 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9969 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009970 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009971 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009972#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009973 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9974 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009975#endif
9976#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009977 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9978 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009979#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009980#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9981 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9982#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009983#if defined(FEAT_CRYPT)
9984 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9985#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009986#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009987 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009988#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009989 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009990#ifdef FEAT_LISP
9991 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9992#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009993 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009994 }
9995 return NULL; /* "cannot happen" */
9996 }
9997 return get_varp(p);
9998}
9999
10000/*
10001 * Get pointer to option variable.
10002 */
10003 static char_u *
10004get_varp(p)
10005 struct vimoption *p;
10006{
10007 /* hidden option, always return NULL */
10008 if (p->var == NULL)
10009 return NULL;
10010
10011 switch ((int)p->indir)
10012 {
10013 case PV_NONE: return p->var;
10014
10015 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010016 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010017 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010018 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010019 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010020 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010021 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010022 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010023 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010024 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010025 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010026 case PV_BKC: return *curbuf->b_p_bkc != NUL
10027 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010028#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010029 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010030 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010031 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010032 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10033#endif
10034#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010035 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010036 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010037 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010038 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10039#endif
10040#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010041 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010042 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010043 case PV_GP: return *curbuf->b_p_gp != NUL
10044 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10045 case PV_MP: return *curbuf->b_p_mp != NUL
10046 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010047#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010048#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10049 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10050 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10051#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010052#if defined(FEAT_CRYPT)
10053 case PV_CM: return *curbuf->b_p_cm != NUL
10054 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10055#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010056#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010057 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010058 ? (char_u *)&(curwin->w_p_stl) : p->var;
10059#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010060 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10061 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010062#ifdef FEAT_LISP
10063 case PV_LW: return *curbuf->b_p_lw != NUL
10064 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10065#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066
10067#ifdef FEAT_ARABIC
10068 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10069#endif
10070 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010071#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010072 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10073#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010074#ifdef FEAT_SYN_HL
10075 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10076 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010077 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010078#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010079#ifdef FEAT_DIFF
10080 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10081#endif
10082#ifdef FEAT_FOLDING
10083 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10084 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10085 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10086 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10087 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10088 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10089 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10090# ifdef FEAT_EVAL
10091 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10092 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10093# endif
10094 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10095#endif
10096 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010097 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010098#ifdef FEAT_LINEBREAK
10099 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10100#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010101#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010102 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10103#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010104#ifdef FEAT_VERTSPLIT
10105 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10106#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010107#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10108 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10109#endif
10110#ifdef FEAT_RIGHTLEFT
10111 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10112 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10113#endif
10114 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10115 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10116#ifdef FEAT_LINEBREAK
10117 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010118 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10119 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120#endif
10121#ifdef FEAT_SCROLLBIND
10122 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10123#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010124#ifdef FEAT_CURSORBIND
10125 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10126#endif
10127#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010128 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10129 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010130#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010131
10132 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10133 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10134#ifdef FEAT_MBYTE
10135 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10136#endif
10137#if defined(FEAT_QUICKFIX)
10138 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10139 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10140#endif
10141 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10142 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10143#ifdef FEAT_CINDENT
10144 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10145 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10146 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10147#endif
10148#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10149 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10150#endif
10151#ifdef FEAT_COMMENTS
10152 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10153#endif
10154#ifdef FEAT_FOLDING
10155 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10156#endif
10157#ifdef FEAT_INS_EXPAND
10158 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10159#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010160#ifdef FEAT_COMPL_FUNC
10161 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010162 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010164 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10165 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10166#ifdef FEAT_MBYTE
10167 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10168#endif
10169 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10170#ifdef FEAT_AUTOCMD
10171 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10172#endif
10173 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010174 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10176 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10177 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10178 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10179#ifdef FEAT_FIND_ID
10180# ifdef FEAT_EVAL
10181 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10182# endif
10183#endif
10184#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10185 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10186 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10187#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010188#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010189 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10190#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191#ifdef FEAT_CRYPT
10192 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10193#endif
10194#ifdef FEAT_LISP
10195 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10196#endif
10197 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10198 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10199 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10200 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10201 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010203#ifdef FEAT_TEXTOBJ
10204 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010206 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10207#ifdef FEAT_SMARTINDENT
10208 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10209#endif
10210#ifndef SHORT_FNAME
10211 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10212#endif
10213 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10214#ifdef FEAT_SEARCHPATH
10215 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10216#endif
10217 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10218#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010219 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010220 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10221#endif
10222#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010223 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10224 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10225 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010226#endif
10227 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10228 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10229 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10230 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010231#ifdef FEAT_PERSISTENT_UNDO
10232 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10233#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10235#ifdef FEAT_KEYMAP
10236 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10237#endif
10238 default: EMSG(_("E356: get_varp ERROR"));
10239 }
10240 /* always return a valid pointer to avoid a crash! */
10241 return (char_u *)&(curbuf->b_p_wm);
10242}
10243
10244/*
10245 * Get the value of 'equalprg', either the buffer-local one or the global one.
10246 */
10247 char_u *
10248get_equalprg()
10249{
10250 if (*curbuf->b_p_ep == NUL)
10251 return p_ep;
10252 return curbuf->b_p_ep;
10253}
10254
10255#if defined(FEAT_WINDOWS) || defined(PROTO)
10256/*
10257 * Copy options from one window to another.
10258 * Used when splitting a window.
10259 */
10260 void
10261win_copy_options(wp_from, wp_to)
10262 win_T *wp_from;
10263 win_T *wp_to;
10264{
10265 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10266 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10267# ifdef FEAT_RIGHTLEFT
10268# ifdef FEAT_FKMAP
10269 /* Is this right? */
10270 wp_to->w_farsi = wp_from->w_farsi;
10271# endif
10272# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010273#if defined(FEAT_LINEBREAK)
10274 briopt_check(wp_to);
10275#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010276}
10277#endif
10278
10279/*
10280 * Copy the options from one winopt_T to another.
10281 * Doesn't free the old option values in "to", use clear_winopt() for that.
10282 * The 'scroll' option is not copied, because it depends on the window height.
10283 * The 'previewwindow' option is reset, there can be only one preview window.
10284 */
10285 void
10286copy_winopt(from, to)
10287 winopt_T *from;
10288 winopt_T *to;
10289{
10290#ifdef FEAT_ARABIC
10291 to->wo_arab = from->wo_arab;
10292#endif
10293 to->wo_list = from->wo_list;
10294 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010295 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010296#ifdef FEAT_LINEBREAK
10297 to->wo_nuw = from->wo_nuw;
10298#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010299#ifdef FEAT_RIGHTLEFT
10300 to->wo_rl = from->wo_rl;
10301 to->wo_rlc = vim_strsave(from->wo_rlc);
10302#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010303#ifdef FEAT_STL_OPT
10304 to->wo_stl = vim_strsave(from->wo_stl);
10305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010307#ifdef FEAT_DIFF
10308 to->wo_wrap_save = from->wo_wrap_save;
10309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010310#ifdef FEAT_LINEBREAK
10311 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010312 to->wo_bri = from->wo_bri;
10313 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314#endif
10315#ifdef FEAT_SCROLLBIND
10316 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010317 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010319#ifdef FEAT_CURSORBIND
10320 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010321 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010322#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010323#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010324 to->wo_spell = from->wo_spell;
10325#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010326#ifdef FEAT_SYN_HL
10327 to->wo_cuc = from->wo_cuc;
10328 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010329 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331#ifdef FEAT_DIFF
10332 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010333 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010334#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010335#ifdef FEAT_CONCEAL
10336 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010337 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010338#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010339#ifdef FEAT_FOLDING
10340 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010341 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010343 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344 to->wo_fdi = vim_strsave(from->wo_fdi);
10345 to->wo_fml = from->wo_fml;
10346 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010347 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010349 to->wo_fdm_save = from->wo_diff_saved
10350 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351 to->wo_fdn = from->wo_fdn;
10352# ifdef FEAT_EVAL
10353 to->wo_fde = vim_strsave(from->wo_fde);
10354 to->wo_fdt = vim_strsave(from->wo_fdt);
10355# endif
10356 to->wo_fmr = vim_strsave(from->wo_fmr);
10357#endif
10358 check_winopt(to); /* don't want NULL pointers */
10359}
10360
10361/*
10362 * Check string options in a window for a NULL value.
10363 */
10364 void
10365check_win_options(win)
10366 win_T *win;
10367{
10368 check_winopt(&win->w_onebuf_opt);
10369 check_winopt(&win->w_allbuf_opt);
10370}
10371
10372/*
10373 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10374 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010375 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010376check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010377 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010378{
10379#ifdef FEAT_FOLDING
10380 check_string_option(&wop->wo_fdi);
10381 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010382 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383# ifdef FEAT_EVAL
10384 check_string_option(&wop->wo_fde);
10385 check_string_option(&wop->wo_fdt);
10386# endif
10387 check_string_option(&wop->wo_fmr);
10388#endif
10389#ifdef FEAT_RIGHTLEFT
10390 check_string_option(&wop->wo_rlc);
10391#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010392#ifdef FEAT_STL_OPT
10393 check_string_option(&wop->wo_stl);
10394#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010395#ifdef FEAT_SYN_HL
10396 check_string_option(&wop->wo_cc);
10397#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010398#ifdef FEAT_CONCEAL
10399 check_string_option(&wop->wo_cocu);
10400#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010401#ifdef FEAT_LINEBREAK
10402 check_string_option(&wop->wo_briopt);
10403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010404}
10405
10406/*
10407 * Free the allocated memory inside a winopt_T.
10408 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010409 void
10410clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010411 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010412{
10413#ifdef FEAT_FOLDING
10414 clear_string_option(&wop->wo_fdi);
10415 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010416 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010417# ifdef FEAT_EVAL
10418 clear_string_option(&wop->wo_fde);
10419 clear_string_option(&wop->wo_fdt);
10420# endif
10421 clear_string_option(&wop->wo_fmr);
10422#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010423#ifdef FEAT_LINEBREAK
10424 clear_string_option(&wop->wo_briopt);
10425#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426#ifdef FEAT_RIGHTLEFT
10427 clear_string_option(&wop->wo_rlc);
10428#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010429#ifdef FEAT_STL_OPT
10430 clear_string_option(&wop->wo_stl);
10431#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010432#ifdef FEAT_SYN_HL
10433 clear_string_option(&wop->wo_cc);
10434#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010435#ifdef FEAT_CONCEAL
10436 clear_string_option(&wop->wo_cocu);
10437#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010438}
10439
10440/*
10441 * Copy global option values to local options for one buffer.
10442 * Used when creating a new buffer and sometimes when entering a buffer.
10443 * flags:
10444 * BCO_ENTER We will enter the buf buffer.
10445 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10446 * appropriate.
10447 * BCO_NOHELP Don't copy the values to a help buffer.
10448 */
10449 void
10450buf_copy_options(buf, flags)
10451 buf_T *buf;
10452 int flags;
10453{
10454 int should_copy = TRUE;
10455 char_u *save_p_isk = NULL; /* init for GCC */
10456 int dont_do_help;
10457 int did_isk = FALSE;
10458
10459 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010460 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010461 */
10462 if (buf == NULL || !buf_valid(buf))
10463 return;
10464
10465 /*
10466 * Skip this when the option defaults have not been set yet. Happens when
10467 * main() allocates the first buffer.
10468 */
10469 if (p_cpo != NULL)
10470 {
10471 /*
10472 * Always copy when entering and 'cpo' contains 'S'.
10473 * Don't copy when already initialized.
10474 * Don't copy when 'cpo' contains 's' and not entering.
10475 * 'S' BCO_ENTER initialized 's' should_copy
10476 * yes yes X X TRUE
10477 * yes no yes X FALSE
10478 * no X yes X FALSE
10479 * X no no yes FALSE
10480 * X no no no TRUE
10481 * no yes no X TRUE
10482 */
10483 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10484 && (buf->b_p_initialized
10485 || (!(flags & BCO_ENTER)
10486 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10487 should_copy = FALSE;
10488
10489 if (should_copy || (flags & BCO_ALWAYS))
10490 {
10491 /* Don't copy the options specific to a help buffer when
10492 * BCO_NOHELP is given or the options were initialized already
10493 * (jumping back to a help file with CTRL-T or CTRL-O) */
10494 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10495 || buf->b_p_initialized;
10496 if (dont_do_help) /* don't free b_p_isk */
10497 {
10498 save_p_isk = buf->b_p_isk;
10499 buf->b_p_isk = NULL;
10500 }
10501 /*
10502 * Always free the allocated strings.
10503 * If not already initialized, set 'readonly' and copy 'fileformat'.
10504 */
10505 if (!buf->b_p_initialized)
10506 {
10507 free_buf_options(buf, TRUE);
10508 buf->b_p_ro = FALSE; /* don't copy readonly */
10509 buf->b_p_tx = p_tx;
10510#ifdef FEAT_MBYTE
10511 buf->b_p_fenc = vim_strsave(p_fenc);
10512#endif
10513 buf->b_p_ff = vim_strsave(p_ff);
10514#if defined(FEAT_QUICKFIX)
10515 buf->b_p_bh = empty_option;
10516 buf->b_p_bt = empty_option;
10517#endif
10518 }
10519 else
10520 free_buf_options(buf, FALSE);
10521
10522 buf->b_p_ai = p_ai;
10523 buf->b_p_ai_nopaste = p_ai_nopaste;
10524 buf->b_p_sw = p_sw;
10525 buf->b_p_tw = p_tw;
10526 buf->b_p_tw_nopaste = p_tw_nopaste;
10527 buf->b_p_tw_nobin = p_tw_nobin;
10528 buf->b_p_wm = p_wm;
10529 buf->b_p_wm_nopaste = p_wm_nopaste;
10530 buf->b_p_wm_nobin = p_wm_nobin;
10531 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010532#ifdef FEAT_MBYTE
10533 buf->b_p_bomb = p_bomb;
10534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 buf->b_p_et = p_et;
10536 buf->b_p_et_nobin = p_et_nobin;
10537 buf->b_p_ml = p_ml;
10538 buf->b_p_ml_nobin = p_ml_nobin;
10539 buf->b_p_inf = p_inf;
10540 buf->b_p_swf = p_swf;
10541#ifdef FEAT_INS_EXPAND
10542 buf->b_p_cpt = vim_strsave(p_cpt);
10543#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010544#ifdef FEAT_COMPL_FUNC
10545 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010546 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010547#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548 buf->b_p_sts = p_sts;
10549 buf->b_p_sts_nopaste = p_sts_nopaste;
10550#ifndef SHORT_FNAME
10551 buf->b_p_sn = p_sn;
10552#endif
10553#ifdef FEAT_COMMENTS
10554 buf->b_p_com = vim_strsave(p_com);
10555#endif
10556#ifdef FEAT_FOLDING
10557 buf->b_p_cms = vim_strsave(p_cms);
10558#endif
10559 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010560 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561 buf->b_p_nf = vim_strsave(p_nf);
10562 buf->b_p_mps = vim_strsave(p_mps);
10563#ifdef FEAT_SMARTINDENT
10564 buf->b_p_si = p_si;
10565#endif
10566 buf->b_p_ci = p_ci;
10567#ifdef FEAT_CINDENT
10568 buf->b_p_cin = p_cin;
10569 buf->b_p_cink = vim_strsave(p_cink);
10570 buf->b_p_cino = vim_strsave(p_cino);
10571#endif
10572#ifdef FEAT_AUTOCMD
10573 /* Don't copy 'filetype', it must be detected */
10574 buf->b_p_ft = empty_option;
10575#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576 buf->b_p_pi = p_pi;
10577#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10578 buf->b_p_cinw = vim_strsave(p_cinw);
10579#endif
10580#ifdef FEAT_LISP
10581 buf->b_p_lisp = p_lisp;
10582#endif
10583#ifdef FEAT_SYN_HL
10584 /* Don't copy 'syntax', it must be set */
10585 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010586 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010587#endif
10588#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010589 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010590 (void)compile_cap_prog(&buf->b_s);
10591 buf->b_s.b_p_spf = vim_strsave(p_spf);
10592 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593#endif
10594#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10595 buf->b_p_inde = vim_strsave(p_inde);
10596 buf->b_p_indk = vim_strsave(p_indk);
10597#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010598#if defined(FEAT_EVAL)
10599 buf->b_p_fex = vim_strsave(p_fex);
10600#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601#ifdef FEAT_CRYPT
10602 buf->b_p_key = vim_strsave(p_key);
10603#endif
10604#ifdef FEAT_SEARCHPATH
10605 buf->b_p_sua = vim_strsave(p_sua);
10606#endif
10607#ifdef FEAT_KEYMAP
10608 buf->b_p_keymap = vim_strsave(p_keymap);
10609 buf->b_kmap_state |= KEYMAP_INIT;
10610#endif
10611 /* This isn't really an option, but copying the langmap and IME
10612 * state from the current buffer is better than resetting it. */
10613 buf->b_p_iminsert = p_iminsert;
10614 buf->b_p_imsearch = p_imsearch;
10615
10616 /* options that are normally global but also have a local value
10617 * are not copied, start using the global value */
10618 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010619 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010620 buf->b_p_bkc = empty_option;
10621 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010622#ifdef FEAT_QUICKFIX
10623 buf->b_p_gp = empty_option;
10624 buf->b_p_mp = empty_option;
10625 buf->b_p_efm = empty_option;
10626#endif
10627 buf->b_p_ep = empty_option;
10628 buf->b_p_kp = empty_option;
10629 buf->b_p_path = empty_option;
10630 buf->b_p_tags = empty_option;
10631#ifdef FEAT_FIND_ID
10632 buf->b_p_def = empty_option;
10633 buf->b_p_inc = empty_option;
10634# ifdef FEAT_EVAL
10635 buf->b_p_inex = vim_strsave(p_inex);
10636# endif
10637#endif
10638#ifdef FEAT_INS_EXPAND
10639 buf->b_p_dict = empty_option;
10640 buf->b_p_tsr = empty_option;
10641#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010642#ifdef FEAT_TEXTOBJ
10643 buf->b_p_qe = vim_strsave(p_qe);
10644#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010645#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10646 buf->b_p_bexpr = empty_option;
10647#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010648#if defined(FEAT_CRYPT)
10649 buf->b_p_cm = empty_option;
10650#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010651#ifdef FEAT_PERSISTENT_UNDO
10652 buf->b_p_udf = p_udf;
10653#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010654#ifdef FEAT_LISP
10655 buf->b_p_lw = empty_option;
10656#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657
10658 /*
10659 * Don't copy the options set by ex_help(), use the saved values,
10660 * when going from a help buffer to a non-help buffer.
10661 * Don't touch these at all when BCO_NOHELP is used and going from
10662 * or to a help buffer.
10663 */
10664 if (dont_do_help)
10665 buf->b_p_isk = save_p_isk;
10666 else
10667 {
10668 buf->b_p_isk = vim_strsave(p_isk);
10669 did_isk = TRUE;
10670 buf->b_p_ts = p_ts;
10671 buf->b_help = FALSE;
10672#ifdef FEAT_QUICKFIX
10673 if (buf->b_p_bt[0] == 'h')
10674 clear_string_option(&buf->b_p_bt);
10675#endif
10676 buf->b_p_ma = p_ma;
10677 }
10678 }
10679
10680 /*
10681 * When the options should be copied (ignoring BCO_ALWAYS), set the
10682 * flag that indicates that the options have been initialized.
10683 */
10684 if (should_copy)
10685 buf->b_p_initialized = TRUE;
10686 }
10687
10688 check_buf_options(buf); /* make sure we don't have NULLs */
10689 if (did_isk)
10690 (void)buf_init_chartab(buf, FALSE);
10691}
10692
10693/*
10694 * Reset the 'modifiable' option and its default value.
10695 */
10696 void
10697reset_modifiable()
10698{
10699 int opt_idx;
10700
10701 curbuf->b_p_ma = FALSE;
10702 p_ma = FALSE;
10703 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010704 if (opt_idx >= 0)
10705 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010706}
10707
10708/*
10709 * Set the global value for 'iminsert' to the local value.
10710 */
10711 void
10712set_iminsert_global()
10713{
10714 p_iminsert = curbuf->b_p_iminsert;
10715}
10716
10717/*
10718 * Set the global value for 'imsearch' to the local value.
10719 */
10720 void
10721set_imsearch_global()
10722{
10723 p_imsearch = curbuf->b_p_imsearch;
10724}
10725
10726#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10727static int expand_option_idx = -1;
10728static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10729static int expand_option_flags = 0;
10730
10731 void
10732set_context_in_set_cmd(xp, arg, opt_flags)
10733 expand_T *xp;
10734 char_u *arg;
10735 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10736{
10737 int nextchar;
10738 long_u flags = 0; /* init for GCC */
10739 int opt_idx = 0; /* init for GCC */
10740 char_u *p;
10741 char_u *s;
10742 int is_term_option = FALSE;
10743 int key;
10744
10745 expand_option_flags = opt_flags;
10746
10747 xp->xp_context = EXPAND_SETTINGS;
10748 if (*arg == NUL)
10749 {
10750 xp->xp_pattern = arg;
10751 return;
10752 }
10753 p = arg + STRLEN(arg) - 1;
10754 if (*p == ' ' && *(p - 1) != '\\')
10755 {
10756 xp->xp_pattern = p + 1;
10757 return;
10758 }
10759 while (p > arg)
10760 {
10761 s = p;
10762 /* count number of backslashes before ' ' or ',' */
10763 if (*p == ' ' || *p == ',')
10764 {
10765 while (s > arg && *(s - 1) == '\\')
10766 --s;
10767 }
10768 /* break at a space with an even number of backslashes */
10769 if (*p == ' ' && ((p - s) & 1) == 0)
10770 {
10771 ++p;
10772 break;
10773 }
10774 --p;
10775 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010776 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777 {
10778 xp->xp_context = EXPAND_BOOL_SETTINGS;
10779 p += 2;
10780 }
10781 if (STRNCMP(p, "inv", 3) == 0)
10782 {
10783 xp->xp_context = EXPAND_BOOL_SETTINGS;
10784 p += 3;
10785 }
10786 xp->xp_pattern = arg = p;
10787 if (*arg == '<')
10788 {
10789 while (*p != '>')
10790 if (*p++ == NUL) /* expand terminal option name */
10791 return;
10792 key = get_special_key_code(arg + 1);
10793 if (key == 0) /* unknown name */
10794 {
10795 xp->xp_context = EXPAND_NOTHING;
10796 return;
10797 }
10798 nextchar = *++p;
10799 is_term_option = TRUE;
10800 expand_option_name[2] = KEY2TERMCAP0(key);
10801 expand_option_name[3] = KEY2TERMCAP1(key);
10802 }
10803 else
10804 {
10805 if (p[0] == 't' && p[1] == '_')
10806 {
10807 p += 2;
10808 if (*p != NUL)
10809 ++p;
10810 if (*p == NUL)
10811 return; /* expand option name */
10812 nextchar = *++p;
10813 is_term_option = TRUE;
10814 expand_option_name[2] = p[-2];
10815 expand_option_name[3] = p[-1];
10816 }
10817 else
10818 {
10819 /* Allow * wildcard */
10820 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10821 p++;
10822 if (*p == NUL)
10823 return;
10824 nextchar = *p;
10825 *p = NUL;
10826 opt_idx = findoption(arg);
10827 *p = nextchar;
10828 if (opt_idx == -1 || options[opt_idx].var == NULL)
10829 {
10830 xp->xp_context = EXPAND_NOTHING;
10831 return;
10832 }
10833 flags = options[opt_idx].flags;
10834 if (flags & P_BOOL)
10835 {
10836 xp->xp_context = EXPAND_NOTHING;
10837 return;
10838 }
10839 }
10840 }
10841 /* handle "-=" and "+=" */
10842 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10843 {
10844 ++p;
10845 nextchar = '=';
10846 }
10847 if ((nextchar != '=' && nextchar != ':')
10848 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10849 {
10850 xp->xp_context = EXPAND_UNSUCCESSFUL;
10851 return;
10852 }
10853 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10854 {
10855 xp->xp_context = EXPAND_OLD_SETTING;
10856 if (is_term_option)
10857 expand_option_idx = -1;
10858 else
10859 expand_option_idx = opt_idx;
10860 xp->xp_pattern = p + 1;
10861 return;
10862 }
10863 xp->xp_context = EXPAND_NOTHING;
10864 if (is_term_option || (flags & P_NUM))
10865 return;
10866
10867 xp->xp_pattern = p + 1;
10868
10869 if (flags & P_EXPAND)
10870 {
10871 p = options[opt_idx].var;
10872 if (p == (char_u *)&p_bdir
10873 || p == (char_u *)&p_dir
10874 || p == (char_u *)&p_path
10875 || p == (char_u *)&p_rtp
10876#ifdef FEAT_SEARCHPATH
10877 || p == (char_u *)&p_cdpath
10878#endif
10879#ifdef FEAT_SESSION
10880 || p == (char_u *)&p_vdir
10881#endif
10882 )
10883 {
10884 xp->xp_context = EXPAND_DIRECTORIES;
10885 if (p == (char_u *)&p_path
10886#ifdef FEAT_SEARCHPATH
10887 || p == (char_u *)&p_cdpath
10888#endif
10889 )
10890 xp->xp_backslash = XP_BS_THREE;
10891 else
10892 xp->xp_backslash = XP_BS_ONE;
10893 }
10894 else
10895 {
10896 xp->xp_context = EXPAND_FILES;
10897 /* for 'tags' need three backslashes for a space */
10898 if (p == (char_u *)&p_tags)
10899 xp->xp_backslash = XP_BS_THREE;
10900 else
10901 xp->xp_backslash = XP_BS_ONE;
10902 }
10903 }
10904
10905 /* For an option that is a list of file names, find the start of the
10906 * last file name. */
10907 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10908 {
10909 /* count number of backslashes before ' ' or ',' */
10910 if (*p == ' ' || *p == ',')
10911 {
10912 s = p;
10913 while (s > xp->xp_pattern && *(s - 1) == '\\')
10914 --s;
10915 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10916 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10917 {
10918 xp->xp_pattern = p + 1;
10919 break;
10920 }
10921 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010922
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010923#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010924 /* for 'spellsuggest' start at "file:" */
10925 if (options[opt_idx].var == (char_u *)&p_sps
10926 && STRNCMP(p, "file:", 5) == 0)
10927 {
10928 xp->xp_pattern = p + 5;
10929 break;
10930 }
10931#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010932 }
10933
10934 return;
10935}
10936
10937 int
10938ExpandSettings(xp, regmatch, num_file, file)
10939 expand_T *xp;
10940 regmatch_T *regmatch;
10941 int *num_file;
10942 char_u ***file;
10943{
10944 int num_normal = 0; /* Nr of matching non-term-code settings */
10945 int num_term = 0; /* Nr of matching terminal code settings */
10946 int opt_idx;
10947 int match;
10948 int count = 0;
10949 char_u *str;
10950 int loop;
10951 int is_term_opt;
10952 char_u name_buf[MAX_KEY_NAME_LEN];
10953 static char *(names[]) = {"all", "termcap"};
10954 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10955
10956 /* do this loop twice:
10957 * loop == 0: count the number of matching options
10958 * loop == 1: copy the matching options into allocated memory
10959 */
10960 for (loop = 0; loop <= 1; ++loop)
10961 {
10962 regmatch->rm_ic = ic;
10963 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10964 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010965 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10966 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010967 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10968 {
10969 if (loop == 0)
10970 num_normal++;
10971 else
10972 (*file)[count++] = vim_strsave((char_u *)names[match]);
10973 }
10974 }
10975 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10976 opt_idx++)
10977 {
10978 if (options[opt_idx].var == NULL)
10979 continue;
10980 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10981 && !(options[opt_idx].flags & P_BOOL))
10982 continue;
10983 is_term_opt = istermoption(&options[opt_idx]);
10984 if (is_term_opt && num_normal > 0)
10985 continue;
10986 match = FALSE;
10987 if (vim_regexec(regmatch, str, (colnr_T)0)
10988 || (options[opt_idx].shortname != NULL
10989 && vim_regexec(regmatch,
10990 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10991 match = TRUE;
10992 else if (is_term_opt)
10993 {
10994 name_buf[0] = '<';
10995 name_buf[1] = 't';
10996 name_buf[2] = '_';
10997 name_buf[3] = str[2];
10998 name_buf[4] = str[3];
10999 name_buf[5] = '>';
11000 name_buf[6] = NUL;
11001 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11002 {
11003 match = TRUE;
11004 str = name_buf;
11005 }
11006 }
11007 if (match)
11008 {
11009 if (loop == 0)
11010 {
11011 if (is_term_opt)
11012 num_term++;
11013 else
11014 num_normal++;
11015 }
11016 else
11017 (*file)[count++] = vim_strsave(str);
11018 }
11019 }
11020 /*
11021 * Check terminal key codes, these are not in the option table
11022 */
11023 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11024 {
11025 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11026 {
11027 if (!isprint(str[0]) || !isprint(str[1]))
11028 continue;
11029
11030 name_buf[0] = 't';
11031 name_buf[1] = '_';
11032 name_buf[2] = str[0];
11033 name_buf[3] = str[1];
11034 name_buf[4] = NUL;
11035
11036 match = FALSE;
11037 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11038 match = TRUE;
11039 else
11040 {
11041 name_buf[0] = '<';
11042 name_buf[1] = 't';
11043 name_buf[2] = '_';
11044 name_buf[3] = str[0];
11045 name_buf[4] = str[1];
11046 name_buf[5] = '>';
11047 name_buf[6] = NUL;
11048
11049 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11050 match = TRUE;
11051 }
11052 if (match)
11053 {
11054 if (loop == 0)
11055 num_term++;
11056 else
11057 (*file)[count++] = vim_strsave(name_buf);
11058 }
11059 }
11060
11061 /*
11062 * Check special key names.
11063 */
11064 regmatch->rm_ic = TRUE; /* ignore case here */
11065 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11066 {
11067 name_buf[0] = '<';
11068 STRCPY(name_buf + 1, str);
11069 STRCAT(name_buf, ">");
11070
11071 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11072 {
11073 if (loop == 0)
11074 num_term++;
11075 else
11076 (*file)[count++] = vim_strsave(name_buf);
11077 }
11078 }
11079 }
11080 if (loop == 0)
11081 {
11082 if (num_normal > 0)
11083 *num_file = num_normal;
11084 else if (num_term > 0)
11085 *num_file = num_term;
11086 else
11087 return OK;
11088 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11089 if (*file == NULL)
11090 {
11091 *file = (char_u **)"";
11092 return FAIL;
11093 }
11094 }
11095 }
11096 return OK;
11097}
11098
11099 int
11100ExpandOldSetting(num_file, file)
11101 int *num_file;
11102 char_u ***file;
11103{
11104 char_u *var = NULL; /* init for GCC */
11105 char_u *buf;
11106
11107 *num_file = 0;
11108 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11109 if (*file == NULL)
11110 return FAIL;
11111
11112 /*
11113 * For a terminal key code expand_option_idx is < 0.
11114 */
11115 if (expand_option_idx < 0)
11116 {
11117 var = find_termcode(expand_option_name + 2);
11118 if (var == NULL)
11119 expand_option_idx = findoption(expand_option_name);
11120 }
11121
11122 if (expand_option_idx >= 0)
11123 {
11124 /* put string of option value in NameBuff */
11125 option_value2string(&options[expand_option_idx], expand_option_flags);
11126 var = NameBuff;
11127 }
11128 else if (var == NULL)
11129 var = (char_u *)"";
11130
11131 /* A backslash is required before some characters. This is the reverse of
11132 * what happens in do_set(). */
11133 buf = vim_strsave_escaped(var, escape_chars);
11134
11135 if (buf == NULL)
11136 {
11137 vim_free(*file);
11138 *file = NULL;
11139 return FAIL;
11140 }
11141
11142#ifdef BACKSLASH_IN_FILENAME
11143 /* For MS-Windows et al. we don't double backslashes at the start and
11144 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011145 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011146 if (var[0] == '\\' && var[1] == '\\'
11147 && expand_option_idx >= 0
11148 && (options[expand_option_idx].flags & P_EXPAND)
11149 && vim_isfilec(var[2])
11150 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011151 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011152#endif
11153
11154 *file[0] = buf;
11155 *num_file = 1;
11156 return OK;
11157}
11158#endif
11159
11160/*
11161 * Get the value for the numeric or string option *opp in a nice format into
11162 * NameBuff[]. Must not be called with a hidden option!
11163 */
11164 static void
11165option_value2string(opp, opt_flags)
11166 struct vimoption *opp;
11167 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11168{
11169 char_u *varp;
11170
11171 varp = get_varp_scope(opp, opt_flags);
11172
11173 if (opp->flags & P_NUM)
11174 {
11175 long wc = 0;
11176
11177 if (wc_use_keyname(varp, &wc))
11178 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11179 else if (wc != 0)
11180 STRCPY(NameBuff, transchar((int)wc));
11181 else
11182 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11183 }
11184 else /* P_STRING */
11185 {
11186 varp = *(char_u **)(varp);
11187 if (varp == NULL) /* just in case */
11188 NameBuff[0] = NUL;
11189#ifdef FEAT_CRYPT
11190 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011191 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011192 STRCPY(NameBuff, "*****");
11193#endif
11194 else if (opp->flags & P_EXPAND)
11195 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11196 /* Translate 'pastetoggle' into special key names */
11197 else if ((char_u **)opp->var == &p_pt)
11198 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11199 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011200 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011201 }
11202}
11203
11204/*
11205 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11206 * printed as a keyname.
11207 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11208 */
11209 static int
11210wc_use_keyname(varp, wcp)
11211 char_u *varp;
11212 long *wcp;
11213{
11214 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11215 {
11216 *wcp = *(long *)varp;
11217 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11218 return TRUE;
11219 }
11220 return FALSE;
11221}
11222
11223#ifdef FEAT_LANGMAP
11224/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011225 * Any character has an equivalent 'langmap' character. This is used for
11226 * keyboards that have a special language mode that sends characters above
11227 * 128 (although other characters can be translated too). The "to" field is a
11228 * Vim command character. This avoids having to switch the keyboard back to
11229 * ASCII mode when leaving Insert mode.
11230 *
11231 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11232 * commands.
11233 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11234 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11235 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011237# ifdef FEAT_MBYTE
11238/*
11239 * With multi-byte support use growarray for 'langmap' chars >= 256
11240 */
11241typedef struct
11242{
11243 int from;
11244 int to;
11245} langmap_entry_T;
11246
11247static garray_T langmap_mapga;
11248static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011249
11250/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011251 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11252 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011253 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011254 static void
11255langmap_set_entry(from, to)
11256 int from;
11257 int to;
11258{
11259 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011260 int a = 0;
11261 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011262
11263 /* Do a binary search for an existing entry. */
11264 while (a != b)
11265 {
11266 int i = (a + b) / 2;
11267 int d = entries[i].from - from;
11268
11269 if (d == 0)
11270 {
11271 entries[i].to = to;
11272 return;
11273 }
11274 if (d < 0)
11275 a = i + 1;
11276 else
11277 b = i;
11278 }
11279
11280 if (ga_grow(&langmap_mapga, 1) != OK)
11281 return; /* out of memory */
11282
11283 /* insert new entry at position "a" */
11284 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11285 mch_memmove(entries + 1, entries,
11286 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11287 ++langmap_mapga.ga_len;
11288 entries[0].from = from;
11289 entries[0].to = to;
11290}
11291
11292/*
11293 * Apply 'langmap' to multi-byte character "c" and return the result.
11294 */
11295 int
11296langmap_adjust_mb(c)
11297 int c;
11298{
11299 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11300 int a = 0;
11301 int b = langmap_mapga.ga_len;
11302
11303 while (a != b)
11304 {
11305 int i = (a + b) / 2;
11306 int d = entries[i].from - c;
11307
11308 if (d == 0)
11309 return entries[i].to; /* found matching entry */
11310 if (d < 0)
11311 a = i + 1;
11312 else
11313 b = i;
11314 }
11315 return c; /* no entry found, return "c" unmodified */
11316}
11317# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011318
11319 static void
11320langmap_init()
11321{
11322 int i;
11323
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011324 for (i = 0; i < 256; i++)
11325 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11326# ifdef FEAT_MBYTE
11327 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11328# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011329}
11330
11331/*
11332 * Called when langmap option is set; the language map can be
11333 * changed at any time!
11334 */
11335 static void
11336langmap_set()
11337{
11338 char_u *p;
11339 char_u *p2;
11340 int from, to;
11341
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011342#ifdef FEAT_MBYTE
11343 ga_clear(&langmap_mapga); /* clear the previous map first */
11344#endif
11345 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011346
11347 for (p = p_langmap; p[0] != NUL; )
11348 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011349 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11350 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011351 {
11352 if (p2[0] == '\\' && p2[1] != NUL)
11353 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011354 }
11355 if (p2[0] == ';')
11356 ++p2; /* abcd;ABCD form, p2 points to A */
11357 else
11358 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11359 while (p[0])
11360 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011361 if (p[0] == ',')
11362 {
11363 ++p;
11364 break;
11365 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366 if (p[0] == '\\' && p[1] != NUL)
11367 ++p;
11368#ifdef FEAT_MBYTE
11369 from = (*mb_ptr2char)(p);
11370#else
11371 from = p[0];
11372#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011373 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011374 if (p2 == NULL)
11375 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011376 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011377 if (p[0] != ',')
11378 {
11379 if (p[0] == '\\')
11380 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011381#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011382 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011383#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011384 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011385#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011386 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387 }
11388 else
11389 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011390 if (p2[0] != ',')
11391 {
11392 if (p2[0] == '\\')
11393 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011394#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011395 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011396#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011397 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011398#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011399 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011400 }
11401 if (to == NUL)
11402 {
11403 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11404 transchar(from));
11405 return;
11406 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011407
11408#ifdef FEAT_MBYTE
11409 if (from >= 256)
11410 langmap_set_entry(from, to);
11411 else
11412#endif
11413 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011414
11415 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011416 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011417 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011418 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011419 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011420 if (*p == ';')
11421 {
11422 p = p2;
11423 if (p[0] != NUL)
11424 {
11425 if (p[0] != ',')
11426 {
11427 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11428 return;
11429 }
11430 ++p;
11431 }
11432 break;
11433 }
11434 }
11435 }
11436 }
11437}
11438#endif
11439
11440/*
11441 * Return TRUE if format option 'x' is in effect.
11442 * Take care of no formatting when 'paste' is set.
11443 */
11444 int
11445has_format_option(x)
11446 int x;
11447{
11448 if (p_paste)
11449 return FALSE;
11450 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11451}
11452
11453/*
11454 * Return TRUE if "x" is present in 'shortmess' option, or
11455 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11456 */
11457 int
11458shortmess(x)
11459 int x;
11460{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011461 return p_shm != NULL &&
11462 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011463 || (vim_strchr(p_shm, 'a') != NULL
11464 && vim_strchr((char_u *)SHM_A, x) != NULL));
11465}
11466
11467/*
11468 * paste_option_changed() - Called after p_paste was set or reset.
11469 */
11470 static void
11471paste_option_changed()
11472{
11473 static int old_p_paste = FALSE;
11474 static int save_sm = 0;
11475#ifdef FEAT_CMDL_INFO
11476 static int save_ru = 0;
11477#endif
11478#ifdef FEAT_RIGHTLEFT
11479 static int save_ri = 0;
11480 static int save_hkmap = 0;
11481#endif
11482 buf_T *buf;
11483
11484 if (p_paste)
11485 {
11486 /*
11487 * Paste switched from off to on.
11488 * Save the current values, so they can be restored later.
11489 */
11490 if (!old_p_paste)
11491 {
11492 /* save options for each buffer */
11493 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11494 {
11495 buf->b_p_tw_nopaste = buf->b_p_tw;
11496 buf->b_p_wm_nopaste = buf->b_p_wm;
11497 buf->b_p_sts_nopaste = buf->b_p_sts;
11498 buf->b_p_ai_nopaste = buf->b_p_ai;
11499 }
11500
11501 /* save global options */
11502 save_sm = p_sm;
11503#ifdef FEAT_CMDL_INFO
11504 save_ru = p_ru;
11505#endif
11506#ifdef FEAT_RIGHTLEFT
11507 save_ri = p_ri;
11508 save_hkmap = p_hkmap;
11509#endif
11510 /* save global values for local buffer options */
11511 p_tw_nopaste = p_tw;
11512 p_wm_nopaste = p_wm;
11513 p_sts_nopaste = p_sts;
11514 p_ai_nopaste = p_ai;
11515 }
11516
11517 /*
11518 * Always set the option values, also when 'paste' is set when it is
11519 * already on.
11520 */
11521 /* set options for each buffer */
11522 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11523 {
11524 buf->b_p_tw = 0; /* textwidth is 0 */
11525 buf->b_p_wm = 0; /* wrapmargin is 0 */
11526 buf->b_p_sts = 0; /* softtabstop is 0 */
11527 buf->b_p_ai = 0; /* no auto-indent */
11528 }
11529
11530 /* set global options */
11531 p_sm = 0; /* no showmatch */
11532#ifdef FEAT_CMDL_INFO
11533# ifdef FEAT_WINDOWS
11534 if (p_ru)
11535 status_redraw_all(); /* redraw to remove the ruler */
11536# endif
11537 p_ru = 0; /* no ruler */
11538#endif
11539#ifdef FEAT_RIGHTLEFT
11540 p_ri = 0; /* no reverse insert */
11541 p_hkmap = 0; /* no Hebrew keyboard */
11542#endif
11543 /* set global values for local buffer options */
11544 p_tw = 0;
11545 p_wm = 0;
11546 p_sts = 0;
11547 p_ai = 0;
11548 }
11549
11550 /*
11551 * Paste switched from on to off: Restore saved values.
11552 */
11553 else if (old_p_paste)
11554 {
11555 /* restore options for each buffer */
11556 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11557 {
11558 buf->b_p_tw = buf->b_p_tw_nopaste;
11559 buf->b_p_wm = buf->b_p_wm_nopaste;
11560 buf->b_p_sts = buf->b_p_sts_nopaste;
11561 buf->b_p_ai = buf->b_p_ai_nopaste;
11562 }
11563
11564 /* restore global options */
11565 p_sm = save_sm;
11566#ifdef FEAT_CMDL_INFO
11567# ifdef FEAT_WINDOWS
11568 if (p_ru != save_ru)
11569 status_redraw_all(); /* redraw to draw the ruler */
11570# endif
11571 p_ru = save_ru;
11572#endif
11573#ifdef FEAT_RIGHTLEFT
11574 p_ri = save_ri;
11575 p_hkmap = save_hkmap;
11576#endif
11577 /* set global values for local buffer options */
11578 p_tw = p_tw_nopaste;
11579 p_wm = p_wm_nopaste;
11580 p_sts = p_sts_nopaste;
11581 p_ai = p_ai_nopaste;
11582 }
11583
11584 old_p_paste = p_paste;
11585}
11586
11587/*
11588 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11589 *
11590 * Reset 'compatible' and set the values for options that didn't get set yet
11591 * to the Vim defaults.
11592 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011593 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011594 */
11595 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011596vimrc_found(fname, envname)
11597 char_u *fname;
11598 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011599{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011600 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011601 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011602 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011603
11604 if (!option_was_set((char_u *)"cp"))
11605 {
11606 p_cp = FALSE;
11607 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11608 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11609 set_option_default(opt_idx, OPT_FREE, FALSE);
11610 didset_options();
11611 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011612
11613 if (fname != NULL)
11614 {
11615 p = vim_getenv(envname, &dofree);
11616 if (p == NULL)
11617 {
11618 /* Set $MYVIMRC to the first vimrc file found. */
11619 p = FullName_save(fname, FALSE);
11620 if (p != NULL)
11621 {
11622 vim_setenv(envname, p);
11623 vim_free(p);
11624 }
11625 }
11626 else if (dofree)
11627 vim_free(p);
11628 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011629}
11630
11631/*
11632 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11633 */
11634 void
11635change_compatible(on)
11636 int on;
11637{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011638 int opt_idx;
11639
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640 if (p_cp != on)
11641 {
11642 p_cp = on;
11643 compatible_set();
11644 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011645 opt_idx = findoption((char_u *)"cp");
11646 if (opt_idx >= 0)
11647 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011648}
11649
11650/*
11651 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011652 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011653 */
11654 int
11655option_was_set(name)
11656 char_u *name;
11657{
11658 int idx;
11659
11660 idx = findoption(name);
11661 if (idx < 0) /* unknown option */
11662 return FALSE;
11663 if (options[idx].flags & P_WAS_SET)
11664 return TRUE;
11665 return FALSE;
11666}
11667
11668/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011669 * Reset the flag indicating option "name" was set.
11670 */
11671 void
11672reset_option_was_set(name)
11673 char_u *name;
11674{
11675 int idx = findoption(name);
11676
11677 if (idx >= 0)
11678 options[idx].flags &= ~P_WAS_SET;
11679}
11680
11681/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011682 * compatible_set() - Called when 'compatible' has been set or unset.
11683 *
11684 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11685 * flag) to a Vi compatible value.
11686 * When 'compatible' is unset: Set all options that have a different default
11687 * for Vim (without the P_VI_DEF flag) to that default.
11688 */
11689 static void
11690compatible_set()
11691{
11692 int opt_idx;
11693
11694 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11695 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11696 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11697 set_option_default(opt_idx, OPT_FREE, p_cp);
11698 didset_options();
11699}
11700
11701#ifdef FEAT_LINEBREAK
11702
11703# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11704 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011705 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011706# endif
11707
11708/*
11709 * fill_breakat_flags() -- called when 'breakat' changes value.
11710 */
11711 static void
11712fill_breakat_flags()
11713{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011714 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011715 int i;
11716
11717 for (i = 0; i < 256; i++)
11718 breakat_flags[i] = FALSE;
11719
11720 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011721 for (p = p_breakat; *p; p++)
11722 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011723}
11724
11725# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011726 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011727# endif
11728
11729#endif
11730
11731/*
11732 * Check an option that can be a range of string values.
11733 *
11734 * Return OK for correct value, FAIL otherwise.
11735 * Empty is always OK.
11736 */
11737 static int
11738check_opt_strings(val, values, list)
11739 char_u *val;
11740 char **values;
11741 int list; /* when TRUE: accept a list of values */
11742{
11743 return opt_strings_flags(val, values, NULL, list);
11744}
11745
11746/*
11747 * Handle an option that can be a range of string values.
11748 * Set a flag in "*flagp" for each string present.
11749 *
11750 * Return OK for correct value, FAIL otherwise.
11751 * Empty is always OK.
11752 */
11753 static int
11754opt_strings_flags(val, values, flagp, list)
11755 char_u *val; /* new value */
11756 char **values; /* array of valid string values */
11757 unsigned *flagp;
11758 int list; /* when TRUE: accept a list of values */
11759{
11760 int i;
11761 int len;
11762 unsigned new_flags = 0;
11763
11764 while (*val)
11765 {
11766 for (i = 0; ; ++i)
11767 {
11768 if (values[i] == NULL) /* val not found in values[] */
11769 return FAIL;
11770
11771 len = (int)STRLEN(values[i]);
11772 if (STRNCMP(values[i], val, len) == 0
11773 && ((list && val[len] == ',') || val[len] == NUL))
11774 {
11775 val += len + (val[len] == ',');
11776 new_flags |= (1 << i);
11777 break; /* check next item in val list */
11778 }
11779 }
11780 }
11781 if (flagp != NULL)
11782 *flagp = new_flags;
11783
11784 return OK;
11785}
11786
11787/*
11788 * Read the 'wildmode' option, fill wim_flags[].
11789 */
11790 static int
11791check_opt_wim()
11792{
11793 char_u new_wim_flags[4];
11794 char_u *p;
11795 int i;
11796 int idx = 0;
11797
11798 for (i = 0; i < 4; ++i)
11799 new_wim_flags[i] = 0;
11800
11801 for (p = p_wim; *p; ++p)
11802 {
11803 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11804 ;
11805 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11806 return FAIL;
11807 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11808 new_wim_flags[idx] |= WIM_LONGEST;
11809 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11810 new_wim_flags[idx] |= WIM_FULL;
11811 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11812 new_wim_flags[idx] |= WIM_LIST;
11813 else
11814 return FAIL;
11815 p += i;
11816 if (*p == NUL)
11817 break;
11818 if (*p == ',')
11819 {
11820 if (idx == 3)
11821 return FAIL;
11822 ++idx;
11823 }
11824 }
11825
11826 /* fill remaining entries with last flag */
11827 while (idx < 3)
11828 {
11829 new_wim_flags[idx + 1] = new_wim_flags[idx];
11830 ++idx;
11831 }
11832
11833 /* only when there are no errors, wim_flags[] is changed */
11834 for (i = 0; i < 4; ++i)
11835 wim_flags[i] = new_wim_flags[i];
11836 return OK;
11837}
11838
11839/*
11840 * Check if backspacing over something is allowed.
11841 */
11842 int
11843can_bs(what)
11844 int what; /* BS_INDENT, BS_EOL or BS_START */
11845{
11846 switch (*p_bs)
11847 {
11848 case '2': return TRUE;
11849 case '1': return (what != BS_START);
11850 case '0': return FALSE;
11851 }
11852 return vim_strchr(p_bs, what) != NULL;
11853}
11854
11855/*
11856 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11857 * the file must be considered changed when the value is different.
11858 */
11859 void
11860save_file_ff(buf)
11861 buf_T *buf;
11862{
11863 buf->b_start_ffc = *buf->b_p_ff;
11864 buf->b_start_eol = buf->b_p_eol;
11865#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011866 buf->b_start_bomb = buf->b_p_bomb;
11867
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868 /* Only use free/alloc when necessary, they take time. */
11869 if (buf->b_start_fenc == NULL
11870 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11871 {
11872 vim_free(buf->b_start_fenc);
11873 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11874 }
11875#endif
11876}
11877
11878/*
11879 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11880 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011881 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11882 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011883 * When "ignore_empty" is true don't consider a new, empty buffer to be
11884 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011885 */
11886 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011887file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011888 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011889 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011890{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011891 /* In a buffer that was never loaded the options are not valid. */
11892 if (buf->b_flags & BF_NEVERLOADED)
11893 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011894 if (ignore_empty
11895 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011896 && buf->b_ml.ml_line_count == 1
11897 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11898 return FALSE;
11899 if (buf->b_start_ffc != *buf->b_p_ff)
11900 return TRUE;
11901 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11902 return TRUE;
11903#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011904 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11905 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906 if (buf->b_start_fenc == NULL)
11907 return (*buf->b_p_fenc != NUL);
11908 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11909#else
11910 return FALSE;
11911#endif
11912}
11913
11914/*
11915 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11916 */
11917 int
11918check_ff_value(p)
11919 char_u *p;
11920{
11921 return check_opt_strings(p, p_ff_values, FALSE);
11922}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011923
11924/*
11925 * Return the effective shiftwidth value for current buffer, using the
11926 * 'tabstop' value when 'shiftwidth' is zero.
11927 */
11928 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011929get_sw_value(buf)
11930 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011931{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011932 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011933}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011934
11935/*
11936 * Return the effective softtabstop value for the current buffer, using the
11937 * 'tabstop' value when 'softtabstop' is negative.
11938 */
11939 long
11940get_sts_value()
11941{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011942 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011943}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011944
11945/*
11946 * Check matchpairs option for "*initc".
11947 * If there is a match set "*initc" to the matching character and "*findc" to
11948 * the opposite character. Set "*backwards" to the direction.
11949 * When "switchit" is TRUE swap the direction.
11950 */
11951 void
11952find_mps_values(initc, findc, backwards, switchit)
11953 int *initc;
11954 int *findc;
11955 int *backwards;
11956 int switchit;
11957{
11958 char_u *ptr;
11959
11960 ptr = curbuf->b_p_mps;
11961 while (*ptr != NUL)
11962 {
11963#ifdef FEAT_MBYTE
11964 if (has_mbyte)
11965 {
11966 char_u *prev;
11967
11968 if (mb_ptr2char(ptr) == *initc)
11969 {
11970 if (switchit)
11971 {
11972 *findc = *initc;
11973 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11974 *backwards = TRUE;
11975 }
11976 else
11977 {
11978 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11979 *backwards = FALSE;
11980 }
11981 return;
11982 }
11983 prev = ptr;
11984 ptr += mb_ptr2len(ptr) + 1;
11985 if (mb_ptr2char(ptr) == *initc)
11986 {
11987 if (switchit)
11988 {
11989 *findc = *initc;
11990 *initc = mb_ptr2char(prev);
11991 *backwards = FALSE;
11992 }
11993 else
11994 {
11995 *findc = mb_ptr2char(prev);
11996 *backwards = TRUE;
11997 }
11998 return;
11999 }
12000 ptr += mb_ptr2len(ptr);
12001 }
12002 else
12003#endif
12004 {
12005 if (*ptr == *initc)
12006 {
12007 if (switchit)
12008 {
12009 *backwards = TRUE;
12010 *findc = *initc;
12011 *initc = ptr[2];
12012 }
12013 else
12014 {
12015 *backwards = FALSE;
12016 *findc = ptr[2];
12017 }
12018 return;
12019 }
12020 ptr += 2;
12021 if (*ptr == *initc)
12022 {
12023 if (switchit)
12024 {
12025 *backwards = FALSE;
12026 *findc = *initc;
12027 *initc = ptr[-2];
12028 }
12029 else
12030 {
12031 *backwards = TRUE;
12032 *findc = ptr[-2];
12033 }
12034 return;
12035 }
12036 ++ptr;
12037 }
12038 if (*ptr == ',')
12039 ++ptr;
12040 }
12041}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012042
12043#if defined(FEAT_LINEBREAK) || defined(PROTO)
12044/*
12045 * This is called when 'breakindentopt' is changed and when a window is
12046 * initialized.
12047 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012048 static int
12049briopt_check(wp)
12050 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012051{
12052 char_u *p;
12053 int bri_shift = 0;
12054 long bri_min = 20;
12055 int bri_sbr = FALSE;
12056
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012057 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012058 while (*p != NUL)
12059 {
12060 if (STRNCMP(p, "shift:", 6) == 0
12061 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12062 {
12063 p += 6;
12064 bri_shift = getdigits(&p);
12065 }
12066 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12067 {
12068 p += 4;
12069 bri_min = getdigits(&p);
12070 }
12071 else if (STRNCMP(p, "sbr", 3) == 0)
12072 {
12073 p += 3;
12074 bri_sbr = TRUE;
12075 }
12076 if (*p != ',' && *p != NUL)
12077 return FAIL;
12078 if (*p == ',')
12079 ++p;
12080 }
12081
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012082 wp->w_p_brishift = bri_shift;
12083 wp->w_p_brimin = bri_min;
12084 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012085
12086 return OK;
12087}
12088#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012089
12090/*
12091 * Get the local or global value of 'backupcopy'.
12092 */
12093 unsigned int
12094get_bkc_value(buf)
12095 buf_T *buf;
12096{
12097 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12098}