blob: aea7d823f600b8d9f2b82e346c922013dffbbc1f [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
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200442#define P_COMMA 0x8000 /* comma separated list */
443#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
444 * commas */
445#define P_NODUP 0x20000L /* don't allow duplicate strings */
446#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000447
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200448#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
449#define P_GETTEXT 0x100000L /* expand default value with _() */
450#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
451#define P_NFNAME 0x400000L /* only normal file name chars allowed */
452#define P_INSECURE 0x800000L /* option was set from a modeline */
453#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000454 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200455#define P_NO_ML 0x2000000L /* not allowed in modeline */
456#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200457 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000458
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000459#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
460
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000461/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
462 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000463#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000464# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000465#else
466# define ISP_LATIN1 (char_u *)"@,161-255"
467#endif
468
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000469/* The 16 bit MS-DOS version is low on space, make the string as short as
470 * possible when compiling with few features. */
471#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
472 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200473 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
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,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 +0000475#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100476# 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 +0000477#endif
478
Bram Moolenaar071d4272004-06-13 20:20:40 +0000479/*
480 * options[] is initialized here.
481 * The order of the options MUST be alphabetic for ":set all" and findoption().
482 * All option names MUST start with a lowercase letter (for findoption()).
483 * Exception: "t_" options are at the end.
484 * The options with a NULL variable are 'hidden': a set command for them is
485 * ignored and they are not printed.
486 */
487static struct vimoption
488#ifdef FEAT_GUI_W16
489 _far
490#endif
491 options[] =
492{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200493 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494#ifdef FEAT_RIGHTLEFT
495 (char_u *)&p_aleph, PV_NONE,
496#else
497 (char_u *)NULL, PV_NONE,
498#endif
499 {
500#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
501 (char_u *)128L,
502#else
503 (char_u *)224L,
504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000505 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
507#if defined(FEAT_GUI) && defined(MACOS_X)
508 (char_u *)&p_antialias, PV_NONE,
509 {(char_u *)FALSE, (char_u *)FALSE}
510#else
511 (char_u *)NULL, PV_NONE,
512 {(char_u *)FALSE, (char_u *)FALSE}
513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000514 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200515 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000516#ifdef FEAT_ARABIC
517 (char_u *)VAR_WIN, PV_ARAB,
518#else
519 (char_u *)NULL, PV_NONE,
520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
523#ifdef FEAT_ARABIC
524 (char_u *)&p_arshape, PV_NONE,
525#else
526 (char_u *)NULL, PV_NONE,
527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000528 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
530#ifdef FEAT_RIGHTLEFT
531 (char_u *)&p_ari, PV_NONE,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
537#ifdef FEAT_FKMAP
538 (char_u *)&p_altkeymap, PV_NONE,
539#else
540 (char_u *)NULL, PV_NONE,
541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000543 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
544#if defined(FEAT_MBYTE)
545 (char_u *)&p_ambw, PV_NONE,
546 {(char_u *)"single", (char_u *)0L}
547#else
548 (char_u *)NULL, PV_NONE,
549 {(char_u *)0L, (char_u *)0L}
550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000551 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000552#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autochdir", "acd", P_BOOL|P_VI_DEF,
554 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556#endif
557 {"autoindent", "ai", P_BOOL|P_VI_DEF,
558 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autoprint", "ap", P_BOOL|P_VI_DEF,
561 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000564 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autowrite", "aw", P_BOOL|P_VI_DEF,
567 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autowriteall","awa", P_BOOL|P_VI_DEF,
570 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
573 (char_u *)&p_bg, PV_NONE,
574 {
575#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
576 (char_u *)"dark",
577#else
578 (char_u *)"light",
579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200581 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
585 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200587 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200588 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589#ifdef UNIX
590 {(char_u *)"yes", (char_u *)"auto"}
591#else
592 {(char_u *)"auto", (char_u *)"auto"}
593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000594 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200595 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
596 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000598 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000599 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600 (char_u *)&p_bex, PV_NONE,
601 {
602#ifdef VMS
603 (char_u *)"_",
604#else
605 (char_u *)"~",
606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000607 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200608 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609#ifdef FEAT_WILDIGN
610 (char_u *)&p_bsk, PV_NONE,
611 {(char_u *)"", (char_u *)0L}
612#else
613 (char_u *)NULL, PV_NONE,
614 {(char_u *)0L, (char_u *)0L}
615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617#ifdef FEAT_BEVAL
618 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
619 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
622 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000624# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000625 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000626 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000627 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000628# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629#endif
630 {"beautify", "bf", P_BOOL|P_VI_DEF,
631 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000632 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
634 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000635 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
637#ifdef MSDOS
638 (char_u *)&p_biosk, PV_NONE,
639#else
640 (char_u *)NULL, PV_NONE,
641#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000642 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000643 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
644#ifdef FEAT_MBYTE
645 (char_u *)&p_bomb, PV_BOMB,
646#else
647 (char_u *)NULL, PV_NONE,
648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000649 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000650 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
651#ifdef FEAT_LINEBREAK
652 (char_u *)&p_breakat, PV_NONE,
653 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
654#else
655 (char_u *)NULL, PV_NONE,
656 {(char_u *)0L, (char_u *)0L}
657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000658 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200659 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
660#ifdef FEAT_LINEBREAK
661 (char_u *)VAR_WIN, PV_BRI,
662 {(char_u *)FALSE, (char_u *)0L}
663#else
664 (char_u *)NULL, PV_NONE,
665 {(char_u *)0L, (char_u *)0L}
666#endif
667 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200668 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
669 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200670#ifdef FEAT_LINEBREAK
671 (char_u *)VAR_WIN, PV_BRIOPT,
672 {(char_u *)"", (char_u *)NULL}
673#else
674 (char_u *)NULL, PV_NONE,
675 {(char_u *)"", (char_u *)NULL}
676#endif
677 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
679#ifdef FEAT_BROWSE
680 (char_u *)&p_bsdir, PV_NONE,
681 {(char_u *)"last", (char_u *)0L}
682#else
683 (char_u *)NULL, PV_NONE,
684 {(char_u *)0L, (char_u *)0L}
685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000686 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000687 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
688#if defined(FEAT_QUICKFIX)
689 (char_u *)&p_bh, PV_BH,
690 {(char_u *)"", (char_u *)0L}
691#else
692 (char_u *)NULL, PV_NONE,
693 {(char_u *)0L, (char_u *)0L}
694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
697 (char_u *)&p_bl, PV_BL,
698 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000699 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000700 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
701#if defined(FEAT_QUICKFIX)
702 (char_u *)&p_bt, PV_BT,
703 {(char_u *)"", (char_u *)0L}
704#else
705 (char_u *)NULL, PV_NONE,
706 {(char_u *)0L, (char_u *)0L}
707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000708 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200709 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000710#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 (char_u *)&p_cmp, PV_NONE,
712 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000713#else
714 (char_u *)NULL, PV_NONE,
715 {(char_u *)0L, (char_u *)0L}
716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000717 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
719#ifdef FEAT_SEARCHPATH
720 (char_u *)&p_cdpath, PV_NONE,
721 {(char_u *)",,", (char_u *)0L}
722#else
723 (char_u *)NULL, PV_NONE,
724 {(char_u *)0L, (char_u *)0L}
725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 {"cedit", NULL, P_STRING,
728#ifdef FEAT_CMDWIN
729 (char_u *)&p_cedit, PV_NONE,
730 {(char_u *)"", (char_u *)CTRL_F_STR}
731#else
732 (char_u *)NULL, PV_NONE,
733 {(char_u *)0L, (char_u *)0L}
734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000735 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000736 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
737#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
738 (char_u *)&p_ccv, PV_NONE,
739 {(char_u *)"", (char_u *)0L}
740#else
741 (char_u *)NULL, PV_NONE,
742 {(char_u *)0L, (char_u *)0L}
743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000744 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
746#ifdef FEAT_CINDENT
747 (char_u *)&p_cin, PV_CIN,
748#else
749 (char_u *)NULL, PV_NONE,
750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000751 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200752 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000753#ifdef FEAT_CINDENT
754 (char_u *)&p_cink, PV_CINK,
755 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
756#else
757 (char_u *)NULL, PV_NONE,
758 {(char_u *)0L, (char_u *)0L}
759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000760 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200761 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762#ifdef FEAT_CINDENT
763 (char_u *)&p_cino, PV_CINO,
764#else
765 (char_u *)NULL, PV_NONE,
766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000767 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200768 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
770 (char_u *)&p_cinw, PV_CINW,
771 {(char_u *)"if,else,while,do,for,switch",
772 (char_u *)0L}
773#else
774 (char_u *)NULL, PV_NONE,
775 {(char_u *)0L, (char_u *)0L}
776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000777 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200778 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000779#ifdef FEAT_CLIPBOARD
780 (char_u *)&p_cb, PV_NONE,
781# ifdef FEAT_XCLIPBOARD
782 {(char_u *)"autoselect,exclude:cons\\|linux",
783 (char_u *)0L}
784# else
785 {(char_u *)"", (char_u *)0L}
786# endif
787#else
788 (char_u *)NULL, PV_NONE,
789 {(char_u *)"", (char_u *)0L}
790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000791 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
793 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000794 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000795 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
796#ifdef FEAT_CMDWIN
797 (char_u *)&p_cwh, PV_NONE,
798#else
799 (char_u *)NULL, PV_NONE,
800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000801 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200802 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200803#ifdef FEAT_SYN_HL
804 (char_u *)VAR_WIN, PV_CC,
805#else
806 (char_u *)NULL, PV_NONE,
807#endif
808 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
810 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000811 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200812 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
813 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814#ifdef FEAT_COMMENTS
815 (char_u *)&p_com, PV_COM,
816 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
817 (char_u *)0L}
818#else
819 (char_u *)NULL, PV_NONE,
820 {(char_u *)0L, (char_u *)0L}
821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000822 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200823 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000824#ifdef FEAT_FOLDING
825 (char_u *)&p_cms, PV_CMS,
826 {(char_u *)"/*%s*/", (char_u *)0L}
827#else
828 (char_u *)NULL, PV_NONE,
829 {(char_u *)0L, (char_u *)0L}
830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000832 /* P_PRI_MKRC isn't needed here, optval_default()
833 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000834 {"compatible", "cp", P_BOOL|P_RALL,
835 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000836 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200837 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838#ifdef FEAT_INS_EXPAND
839 (char_u *)&p_cpt, PV_CPT,
840 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
841#else
842 (char_u *)NULL, PV_NONE,
843 {(char_u *)0L, (char_u *)0L}
844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000845 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200846 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200847#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200848 (char_u *)VAR_WIN, PV_COCU,
849 {(char_u *)"", (char_u *)NULL}
850#else
851 (char_u *)NULL, PV_NONE,
852 {(char_u *)NULL, (char_u *)0L}
853#endif
854 SCRIPTID_INIT},
855 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
856#ifdef FEAT_CONCEAL
857 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200858#else
859 (char_u *)NULL, PV_NONE,
860#endif
861 {(char_u *)0L, (char_u *)0L}
862 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000863 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
864#ifdef FEAT_COMPL_FUNC
865 (char_u *)&p_cfu, PV_CFU,
866 {(char_u *)"", (char_u *)0L}
867#else
868 (char_u *)NULL, PV_NONE,
869 {(char_u *)0L, (char_u *)0L}
870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000871 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200872 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000873#ifdef FEAT_INS_EXPAND
874 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000875 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000876#else
877 (char_u *)NULL, PV_NONE,
878 {(char_u *)0L, (char_u *)0L}
879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000880 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000881 {"confirm", "cf", P_BOOL|P_VI_DEF,
882#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
883 (char_u *)&p_confirm, PV_NONE,
884#else
885 (char_u *)NULL, PV_NONE,
886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000887 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000888 {"conskey", "consk",P_BOOL|P_VI_DEF,
889#ifdef MSDOS
890 (char_u *)&p_consk, PV_NONE,
891#else
892 (char_u *)NULL, PV_NONE,
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
896 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000897 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000898 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
899 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
901 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200902 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200903#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200904 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200905 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200906#else
907 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200908 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200909#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200910 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
912#ifdef FEAT_CSCOPE
913 (char_u *)&p_cspc, PV_NONE,
914#else
915 (char_u *)NULL, PV_NONE,
916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
919#ifdef FEAT_CSCOPE
920 (char_u *)&p_csprg, PV_NONE,
921 {(char_u *)"cscope", (char_u *)0L}
922#else
923 (char_u *)NULL, PV_NONE,
924 {(char_u *)0L, (char_u *)0L}
925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200927 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000928#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
929 (char_u *)&p_csqf, PV_NONE,
930 {(char_u *)"", (char_u *)0L}
931#else
932 (char_u *)NULL, PV_NONE,
933 {(char_u *)0L, (char_u *)0L}
934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000935 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200936 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
937#ifdef FEAT_CSCOPE
938 (char_u *)&p_csre, PV_NONE,
939#else
940 (char_u *)NULL, PV_NONE,
941#endif
942 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000943 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
944#ifdef FEAT_CSCOPE
945 (char_u *)&p_cst, PV_NONE,
946#else
947 (char_u *)NULL, PV_NONE,
948#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000949 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000950 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
951#ifdef FEAT_CSCOPE
952 (char_u *)&p_csto, PV_NONE,
953#else
954 (char_u *)NULL, PV_NONE,
955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000956 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
958#ifdef FEAT_CSCOPE
959 (char_u *)&p_csverbose, PV_NONE,
960#else
961 (char_u *)NULL, PV_NONE,
962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000963 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200964 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
965#ifdef FEAT_CURSORBIND
966 (char_u *)VAR_WIN, PV_CRBIND,
967#else
968 (char_u *)NULL, PV_NONE,
969#endif
970 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000971 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
972#ifdef FEAT_SYN_HL
973 (char_u *)VAR_WIN, PV_CUC,
974#else
975 (char_u *)NULL, PV_NONE,
976#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000978 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
979#ifdef FEAT_SYN_HL
980 (char_u *)VAR_WIN, PV_CUL,
981#else
982 (char_u *)NULL, PV_NONE,
983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985 {"debug", NULL, P_STRING|P_VI_DEF,
986 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000987 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200988 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000989#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000990 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000991 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992#else
993 (char_u *)NULL, PV_NONE,
994 {(char_u *)NULL, (char_u *)0L}
995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000996 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000997 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
998#ifdef FEAT_MBYTE
999 (char_u *)&p_deco, PV_NONE,
1000#else
1001 (char_u *)NULL, PV_NONE,
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001004 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001006 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#else
1008 (char_u *)NULL, PV_NONE,
1009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1012#ifdef FEAT_DIFF
1013 (char_u *)VAR_WIN, PV_DIFF,
1014#else
1015 (char_u *)NULL, PV_NONE,
1016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001018 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001019#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1020 (char_u *)&p_dex, PV_NONE,
1021 {(char_u *)"", (char_u *)0L}
1022#else
1023 (char_u *)NULL, PV_NONE,
1024 {(char_u *)0L, (char_u *)0L}
1025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001026 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001027 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1028 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029#ifdef FEAT_DIFF
1030 (char_u *)&p_dip, PV_NONE,
1031 {(char_u *)"filler", (char_u *)NULL}
1032#else
1033 (char_u *)NULL, PV_NONE,
1034 {(char_u *)"", (char_u *)NULL}
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1038#ifdef FEAT_DIGRAPHS
1039 (char_u *)&p_dg, PV_NONE,
1040#else
1041 (char_u *)NULL, PV_NONE,
1042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001044 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1045 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001047 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001048 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 {"eadirection", "ead", P_STRING|P_VI_DEF,
1052#ifdef FEAT_VERTSPLIT
1053 (char_u *)&p_ead, PV_NONE,
1054 {(char_u *)"both", (char_u *)0L}
1055#else
1056 (char_u *)NULL, PV_NONE,
1057 {(char_u *)NULL, (char_u *)0L}
1058#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001059 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1061 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001063 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064#ifdef FEAT_MBYTE
1065 (char_u *)&p_enc, PV_NONE,
1066 {(char_u *)ENC_DFLT, (char_u *)0L}
1067#else
1068 (char_u *)NULL, PV_NONE,
1069 {(char_u *)0L, (char_u *)0L}
1070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001071 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1073 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1076 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001079 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1082 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001083 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1085#ifdef FEAT_QUICKFIX
1086 (char_u *)&p_ef, PV_NONE,
1087 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1088#else
1089 (char_u *)NULL, PV_NONE,
1090 {(char_u *)NULL, (char_u *)0L}
1091#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001092 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001093 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001095 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001096 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097#else
1098 (char_u *)NULL, PV_NONE,
1099 {(char_u *)NULL, (char_u *)0L}
1100#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 {"esckeys", "ek", P_BOOL|P_VIM,
1103 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001105 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106#ifdef FEAT_AUTOCMD
1107 (char_u *)&p_ei, PV_NONE,
1108#else
1109 (char_u *)NULL, PV_NONE,
1110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1113 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1116 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001118 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1119 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120#ifdef FEAT_MBYTE
1121 (char_u *)&p_fenc, PV_FENC,
1122 {(char_u *)"", (char_u *)0L}
1123#else
1124 (char_u *)NULL, PV_NONE,
1125 {(char_u *)0L, (char_u *)0L}
1126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001128 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129#ifdef FEAT_MBYTE
1130 (char_u *)&p_fencs, PV_NONE,
1131 {(char_u *)"ucs-bom", (char_u *)0L}
1132#else
1133 (char_u *)NULL, PV_NONE,
1134 {(char_u *)0L, (char_u *)0L}
1135#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001137 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1138 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001139 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001141 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1144 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001145 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1146 (char_u *)&p_fic, PV_NONE,
1147 {
1148#ifdef CASE_INSENSITIVE_FILENAME
1149 (char_u *)TRUE,
1150#else
1151 (char_u *)FALSE,
1152#endif
1153 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001154 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155#ifdef FEAT_AUTOCMD
1156 (char_u *)&p_ft, PV_FT,
1157 {(char_u *)"", (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)0L, (char_u *)0L}
1161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1165 (char_u *)&p_fcs, PV_NONE,
1166 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1167#else
1168 (char_u *)NULL, PV_NONE,
1169 {(char_u *)"", (char_u *)0L}
1170#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1173#ifdef FEAT_FKMAP
1174 (char_u *)&p_fkmap, PV_NONE,
1175#else
1176 (char_u *)NULL, PV_NONE,
1177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179 {"flash", "fl", P_BOOL|P_VI_DEF,
1180 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001181 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001183 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1187 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1190 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1193# ifdef FEAT_EVAL
1194 (char_u *)VAR_WIN, PV_FDE,
1195 {(char_u *)"0", (char_u *)NULL}
1196# else
1197 (char_u *)NULL, PV_NONE,
1198 {(char_u *)NULL, (char_u *)0L}
1199# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1202 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1205 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001207 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001208 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001211 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)"{{{,}}}", (char_u *)NULL}
1214 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1216 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1219 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001224 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 (char_u *)&p_fdo, PV_NONE,
1226 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001227 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1229# ifdef FEAT_EVAL
1230 (char_u *)VAR_WIN, PV_FDT,
1231 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001232# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 (char_u *)NULL, PV_NONE,
1234 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001235# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001237#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001238 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001239#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001240 (char_u *)&p_fex, PV_FEX,
1241 {(char_u *)"", (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)0L, (char_u *)0L}
1245#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1248 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1250 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001251 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1252 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001253 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1254 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1256 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001257 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001258 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1259#ifdef HAVE_FSYNC
1260 (char_u *)&p_fs, PV_NONE,
1261 {(char_u *)TRUE, (char_u *)0L}
1262#else
1263 (char_u *)NULL, PV_NONE,
1264 {(char_u *)FALSE, (char_u *)0L}
1265#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1268 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001269 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 {"graphic", "gr", P_BOOL|P_VI_DEF,
1271 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001273 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001274#ifdef FEAT_QUICKFIX
1275 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001276 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277#else
1278 (char_u *)NULL, PV_NONE,
1279 {(char_u *)NULL, (char_u *)0L}
1280#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1283#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001284 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285 {
1286# ifdef WIN3264
1287 /* may be changed to "grep -n" in os_win32.c */
1288 (char_u *)"findstr /n",
1289# else
1290# ifdef UNIX
1291 /* Add an extra file name so that grep will always
1292 * insert a file name in the match line. */
1293 (char_u *)"grep -n $* /dev/null",
1294# else
1295# ifdef VMS
1296 (char_u *)"SEARCH/NUMBERS ",
1297# else
1298 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001299# endif
1300# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001302 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303#else
1304 (char_u *)NULL, PV_NONE,
1305 {(char_u *)NULL, (char_u *)0L}
1306#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001307 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001308 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#ifdef CURSOR_SHAPE
1310 (char_u *)&p_guicursor, PV_NONE,
1311 {
1312# ifdef FEAT_GUI
1313 (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",
1314# else /* MSDOS or Win32 console */
1315 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1316# endif
1317 (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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001323 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001324#ifdef FEAT_GUI
1325 (char_u *)&p_guifont, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001332 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1334 (char_u *)&p_guifontset, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001341 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1343 (char_u *)&p_guifontwide, PV_NONE,
1344 {(char_u *)"", (char_u *)0L}
1345#else
1346 (char_u *)NULL, PV_NONE,
1347 {(char_u *)NULL, (char_u *)0L}
1348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001351#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352 (char_u *)&p_ghr, PV_NONE,
1353#else
1354 (char_u *)NULL, PV_NONE,
1355#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001356 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001358#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359 (char_u *)&p_go, PV_NONE,
1360# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001361 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001363 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364# endif
1365#else
1366 (char_u *)NULL, PV_NONE,
1367 {(char_u *)NULL, (char_u *)0L}
1368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001369 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370 {"guipty", NULL, P_BOOL|P_VI_DEF,
1371#if defined(FEAT_GUI)
1372 (char_u *)&p_guipty, PV_NONE,
1373#else
1374 (char_u *)NULL, PV_NONE,
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001377 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001378#if defined(FEAT_GUI_TABLINE)
1379 (char_u *)&p_gtl, 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 Moolenaarf9393ef2006-04-24 19:47:27 +00001386 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001387#if defined(FEAT_GUI_TABLINE)
1388 (char_u *)&p_gtt, PV_NONE,
1389 {(char_u *)"", (char_u *)0L}
1390#else
1391 (char_u *)NULL, PV_NONE,
1392 {(char_u *)NULL, (char_u *)0L}
1393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1396 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1399 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1401 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402 {"helpheight", "hh", P_NUM|P_VI_DEF,
1403#ifdef FEAT_WINDOWS
1404 (char_u *)&p_hh, PV_NONE,
1405#else
1406 (char_u *)NULL, PV_NONE,
1407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001409 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410#ifdef FEAT_MULTI_LANG
1411 (char_u *)&p_hlg, PV_NONE,
1412 {(char_u *)"", (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)0L, (char_u *)0L}
1416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418 {"hidden", "hid", P_BOOL|P_VI_DEF,
1419 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001420 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001421 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001422 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1424 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425 {"history", "hi", P_NUM|P_VIM,
1426 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001427 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1429#ifdef FEAT_RIGHTLEFT
1430 (char_u *)&p_hkmap, PV_NONE,
1431#else
1432 (char_u *)NULL, PV_NONE,
1433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1436#ifdef FEAT_RIGHTLEFT
1437 (char_u *)&p_hkmapp, PV_NONE,
1438#else
1439 (char_u *)NULL, PV_NONE,
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1443 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"icon", NULL, P_BOOL|P_VI_DEF,
1446#ifdef FEAT_TITLE
1447 (char_u *)&p_icon, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"iconstring", NULL, P_STRING|P_VI_DEF,
1453#ifdef FEAT_TITLE
1454 (char_u *)&p_iconstring, PV_NONE,
1455#else
1456 (char_u *)NULL, PV_NONE,
1457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001458 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1460 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001462 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1463# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1464 (char_u *)&p_imaf, PV_NONE,
1465 {(char_u *)"", (char_u *)NULL}
1466# else
1467 (char_u *)NULL, PV_NONE,
1468 {(char_u *)NULL, (char_u *)0L}
1469# endif
1470 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001472#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 (char_u *)&p_imak, PV_NONE,
1474#else
1475 (char_u *)NULL, PV_NONE,
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001478 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1479#ifdef USE_IM_CONTROL
1480 (char_u *)&p_imcmdline, PV_NONE,
1481#else
1482 (char_u *)NULL, PV_NONE,
1483#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001484 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1486#ifdef USE_IM_CONTROL
1487 (char_u *)&p_imdisable, PV_NONE,
1488#else
1489 (char_u *)NULL, PV_NONE,
1490#endif
1491#ifdef __sgi
1492 {(char_u *)TRUE, (char_u *)0L}
1493#else
1494 {(char_u *)FALSE, (char_u *)0L}
1495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"iminsert", "imi", P_NUM|P_VI_DEF,
1498 (char_u *)&p_iminsert, PV_IMI,
1499#ifdef B_IMODE_IM
1500 {(char_u *)B_IMODE_IM, (char_u *)0L}
1501#else
1502 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001504 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505 {"imsearch", "ims", P_NUM|P_VI_DEF,
1506 (char_u *)&p_imsearch, PV_IMS,
1507#ifdef B_IMODE_IM
1508 {(char_u *)B_IMODE_IM, (char_u *)0L}
1509#else
1510 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001512 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001513 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001514# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1515 (char_u *)&p_imsf, PV_NONE,
1516 {(char_u *)"", (char_u *)NULL}
1517# else
1518 (char_u *)NULL, PV_NONE,
1519 {(char_u *)NULL, (char_u *)0L}
1520# endif
1521 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1523#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001524 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001525 {(char_u *)"^\\s*#\\s*include", (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 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1532#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1533 (char_u *)&p_inex, PV_INEX,
1534 {(char_u *)"", (char_u *)0L}
1535#else
1536 (char_u *)NULL, PV_NONE,
1537 {(char_u *)0L, (char_u *)0L}
1538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1541 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1544#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1545 (char_u *)&p_inde, PV_INDE,
1546 {(char_u *)"", (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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001552 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1554 (char_u *)&p_indk, PV_INDK,
1555 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1556#else
1557 (char_u *)NULL, PV_NONE,
1558 {(char_u *)0L, (char_u *)0L}
1559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001560 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {"infercase", "inf", P_BOOL|P_VI_DEF,
1562 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1565 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1568 (char_u *)&p_isf, PV_NONE,
1569 {
1570#ifdef BACKSLASH_IN_FILENAME
1571 /* Excluded are: & and ^ are special in cmd.exe
1572 * ( and ) are used in text separating fnames */
1573 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1574#else
1575# ifdef AMIGA
1576 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1577# else
1578# ifdef VMS
1579 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1580# else /* UNIX et al. */
1581# ifdef EBCDIC
1582 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1583# else
1584 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1585# endif
1586# endif
1587# endif
1588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001589 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1591 (char_u *)&p_isi, PV_NONE,
1592 {
1593#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1594 (char_u *)"@,48-57,_,128-167,224-235",
1595#else
1596# ifdef EBCDIC
1597 /* TODO: EBCDIC Check this! @ == isalpha()*/
1598 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1599 "112-120,128,140-142,156,158,172,"
1600 "174,186,191,203-207,219-225,235-239,"
1601 "251-254",
1602# else
1603 (char_u *)"@,48-57,_,192-255",
1604# endif
1605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001606 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1608 (char_u *)&p_isk, PV_ISK,
1609 {
1610#ifdef EBCDIC
1611 (char_u *)"@,240-249,_",
1612 /* TODO: EBCDIC Check this! @ == isalpha()*/
1613 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1614 "112-120,128,140-142,156,158,172,"
1615 "174,186,191,203-207,219-225,235-239,"
1616 "251-254",
1617#else
1618 (char_u *)"@,48-57,_",
1619# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1620 (char_u *)"@,48-57,_,128-167,224-235"
1621# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001622 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623# endif
1624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001625 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1627 (char_u *)&p_isp, PV_NONE,
1628 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001629#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1630 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631 || defined(VMS)
1632 (char_u *)"@,~-255",
1633#else
1634# ifdef EBCDIC
1635 /* all chars above 63 are printable */
1636 (char_u *)"63-255",
1637# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001638 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001639# endif
1640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001641 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001642 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1643 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001644 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1646#ifdef FEAT_CRYPT
1647 (char_u *)&p_key, PV_KEY,
1648 {(char_u *)"", (char_u *)0L}
1649#else
1650 (char_u *)NULL, PV_NONE,
1651 {(char_u *)0L, (char_u *)0L}
1652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001653 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001654 {"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 +00001655#ifdef FEAT_KEYMAP
1656 (char_u *)&p_keymap, PV_KMAP,
1657 {(char_u *)"", (char_u *)0L}
1658#else
1659 (char_u *)NULL, PV_NONE,
1660 {(char_u *)"", (char_u *)0L}
1661#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001662 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001663 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001664 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001665 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001667 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {
1669#if defined(MSDOS) || defined(MSWIN)
1670 (char_u *)":help",
1671#else
1672#ifdef VMS
1673 (char_u *)"help",
1674#else
1675# if defined(OS2)
1676 (char_u *)"view /",
1677# else
1678# ifdef USEMAN_S
1679 (char_u *)"man -s",
1680# else
1681 (char_u *)"man",
1682# endif
1683# endif
1684#endif
1685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001686 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001687 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688#ifdef FEAT_LANGMAP
1689 (char_u *)&p_langmap, PV_NONE,
1690 {(char_u *)"", /* unmatched } */
1691#else
1692 (char_u *)NULL, PV_NONE,
1693 {(char_u *)NULL,
1694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001695 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001696 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1698 (char_u *)&p_lm, PV_NONE,
1699#else
1700 (char_u *)NULL, PV_NONE,
1701#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001702 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001703 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1704#ifdef FEAT_LANGMAP
1705 (char_u *)&p_lnr, PV_NONE,
1706#else
1707 (char_u *)NULL, PV_NONE,
1708#endif
1709 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1711#ifdef FEAT_WINDOWS
1712 (char_u *)&p_ls, PV_NONE,
1713#else
1714 (char_u *)NULL, PV_NONE,
1715#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001716 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1718 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1721#ifdef FEAT_LINEBREAK
1722 (char_u *)VAR_WIN, PV_LBR,
1723#else
1724 (char_u *)NULL, PV_NONE,
1725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001726 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1728 (char_u *)&Rows, PV_NONE,
1729 {
1730#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1731 (char_u *)25L,
1732#else
1733 (char_u *)24L,
1734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001735 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1737#ifdef FEAT_GUI
1738 (char_u *)&p_linespace, PV_NONE,
1739#else
1740 (char_u *)NULL, PV_NONE,
1741#endif
1742#ifdef FEAT_GUI_W32
1743 {(char_u *)1L, (char_u *)0L}
1744#else
1745 {(char_u *)0L, (char_u *)0L}
1746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 {"lisp", NULL, P_BOOL|P_VI_DEF,
1749#ifdef FEAT_LISP
1750 (char_u *)&p_lisp, PV_LISP,
1751#else
1752 (char_u *)NULL, PV_NONE,
1753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001755 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001757 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1759#else
1760 (char_u *)NULL, PV_NONE,
1761 {(char_u *)"", (char_u *)0L}
1762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1765 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001766 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001767 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001769 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1771 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001773#ifdef FEAT_GUI_MAC
1774 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1775 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001776 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001777#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {"magic", NULL, P_BOOL|P_VI_DEF,
1779 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001781 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782#ifdef FEAT_QUICKFIX
1783 (char_u *)&p_mef, PV_NONE,
1784 {(char_u *)"", (char_u *)0L}
1785#else
1786 (char_u *)NULL, PV_NONE,
1787 {(char_u *)NULL, (char_u *)0L}
1788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001789 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1791#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001792 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793# ifdef VMS
1794 {(char_u *)"MMS", (char_u *)0L}
1795# else
1796 {(char_u *)"make", (char_u *)0L}
1797# endif
1798#else
1799 (char_u *)NULL, PV_NONE,
1800 {(char_u *)NULL, (char_u *)0L}
1801#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001802 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001803 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001805 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1806 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807 {"matchtime", "mat", P_NUM|P_VI_DEF,
1808 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001809 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001810 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001811#ifdef FEAT_MBYTE
1812 (char_u *)&p_mco, PV_NONE,
1813#else
1814 (char_u *)NULL, PV_NONE,
1815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1818#ifdef FEAT_EVAL
1819 (char_u *)&p_mfd, PV_NONE,
1820#else
1821 (char_u *)NULL, PV_NONE,
1822#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1825 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001826 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 {"maxmem", "mm", P_NUM|P_VI_DEF,
1828 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001829 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1830 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001831 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1832 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001833 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001834 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1835 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001836 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1837 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001838 {"menuitems", "mis", P_NUM|P_VI_DEF,
1839#ifdef FEAT_MENU
1840 (char_u *)&p_mis, PV_NONE,
1841#else
1842 (char_u *)NULL, PV_NONE,
1843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 {"mesg", NULL, P_BOOL|P_VI_DEF,
1846 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001848 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001849#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001850 (char_u *)&p_msm, PV_NONE,
1851 {(char_u *)"460000,2000,500", (char_u *)0L}
1852#else
1853 (char_u *)NULL, PV_NONE,
1854 {(char_u *)0L, (char_u *)0L}
1855#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001856 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"modeline", "ml", P_BOOL|P_VIM,
1858 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"modelines", "mls", P_NUM|P_VI_DEF,
1861 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1864 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001865 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1867 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001868 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"more", NULL, P_BOOL|P_VIM,
1870 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1873 (char_u *)&p_mouse, PV_NONE,
1874 {
1875#if defined(MSDOS) || defined(WIN3264)
1876 (char_u *)"a",
1877#else
1878 (char_u *)"",
1879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1882#ifdef FEAT_GUI
1883 (char_u *)&p_mousef, PV_NONE,
1884#else
1885 (char_u *)NULL, PV_NONE,
1886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001887 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1889#ifdef FEAT_GUI
1890 (char_u *)&p_mh, PV_NONE,
1891#else
1892 (char_u *)NULL, PV_NONE,
1893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001894 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1896 (char_u *)&p_mousem, PV_NONE,
1897 {
1898#if defined(MSDOS) || defined(MSWIN)
1899 (char_u *)"popup",
1900#else
1901# if defined(MACOS)
1902 (char_u *)"popup_setpos",
1903# else
1904 (char_u *)"extend",
1905# endif
1906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001907 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001908 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909#ifdef FEAT_MOUSESHAPE
1910 (char_u *)&p_mouseshape, PV_NONE,
1911 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1912#else
1913 (char_u *)NULL, PV_NONE,
1914 {(char_u *)NULL, (char_u *)0L}
1915#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001916 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1918 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001920 {"mzquantum", "mzq", P_NUM,
1921#ifdef FEAT_MZSCHEME
1922 (char_u *)&p_mzq, PV_NONE,
1923#else
1924 (char_u *)NULL, PV_NONE,
1925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {"novice", NULL, P_BOOL|P_VI_DEF,
1928 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001929 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001930 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001932 {(char_u *)"octal,hex", (char_u *)0L}
1933 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1935 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001936 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001937 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1938#ifdef FEAT_LINEBREAK
1939 (char_u *)VAR_WIN, PV_NUW,
1940#else
1941 (char_u *)NULL, PV_NONE,
1942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001944 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001945#ifdef FEAT_COMPL_FUNC
1946 (char_u *)&p_ofu, PV_OFU,
1947 {(char_u *)"", (char_u *)0L}
1948#else
1949 (char_u *)NULL, PV_NONE,
1950 {(char_u *)0L, (char_u *)0L}
1951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001952 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"open", NULL, P_BOOL|P_VI_DEF,
1954 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001956 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1957#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1958 (char_u *)&p_odev, PV_NONE,
1959#else
1960 (char_u *)NULL, PV_NONE,
1961#endif
1962 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001964 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1965 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001966 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001967 {"optimize", "opt", P_BOOL|P_VI_DEF,
1968 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001969 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001970 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001972 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"paragraphs", "para", P_STRING|P_VI_DEF,
1974 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001975 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001976 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001977 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1981 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1984#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1985 (char_u *)&p_pex, PV_NONE,
1986 {(char_u *)"", (char_u *)0L}
1987#else
1988 (char_u *)NULL, PV_NONE,
1989 {(char_u *)0L, (char_u *)0L}
1990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001992 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001993 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001996 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {
1998#if defined AMIGA || defined MSDOS || defined MSWIN
1999 (char_u *)".,,",
2000#else
2001# if defined(__EMX__)
2002 (char_u *)".,/emx/include,,",
2003# else /* Unix, probably */
2004 (char_u *)".,/usr/include,,",
2005# endif
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2009 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002011 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002012#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2013 (char_u *)&p_pvh, PV_NONE,
2014#else
2015 (char_u *)NULL, PV_NONE,
2016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002017 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2019#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2020 (char_u *)VAR_WIN, PV_PVW,
2021#else
2022 (char_u *)NULL, PV_NONE,
2023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002024 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002025 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026#ifdef FEAT_PRINTER
2027 (char_u *)&p_pdev, 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 {"printencoding", "penc", P_STRING|P_VI_DEF,
2035#ifdef FEAT_POSTSCRIPT
2036 (char_u *)&p_penc, 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 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2044#ifdef FEAT_POSTSCRIPT
2045 (char_u *)&p_pexpr, PV_NONE,
2046 {(char_u *)"", (char_u *)0L}
2047#else
2048 (char_u *)NULL, PV_NONE,
2049 {(char_u *)NULL, (char_u *)0L}
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"printfont", "pfn", P_STRING|P_VI_DEF,
2053#ifdef FEAT_PRINTER
2054 (char_u *)&p_pfn, PV_NONE,
2055 {
2056# ifdef MSWIN
2057 (char_u *)"Courier_New:h10",
2058# else
2059 (char_u *)"courier",
2060# endif
2061 (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 Moolenaar071d4272004-06-13 20:20:40 +00002067 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2068#ifdef FEAT_PRINTER
2069 (char_u *)&p_header, PV_NONE,
2070 {(char_u *)N_("%<%f%h%m%=Page %N"), (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 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2077#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2078 (char_u *)&p_pmcs, 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 Moolenaar8299df92004-07-10 09:47:34 +00002085 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2086#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2087 (char_u *)&p_pmfn, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002094 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095#ifdef FEAT_PRINTER
2096 (char_u *)&p_popt, PV_NONE,
2097 {(char_u *)"", (char_u *)0L}
2098#else
2099 (char_u *)NULL, PV_NONE,
2100 {(char_u *)NULL, (char_u *)0L}
2101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002102 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002104 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002105 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002106 {"pumheight", "ph", P_NUM|P_VI_DEF,
2107#ifdef FEAT_INS_EXPAND
2108 (char_u *)&p_ph, PV_NONE,
2109#else
2110 (char_u *)NULL, PV_NONE,
2111#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002113 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2114#ifdef FEAT_TEXTOBJ
2115 (char_u *)&p_qe, PV_QE,
2116 {(char_u *)"\\", (char_u *)0L}
2117#else
2118 (char_u *)NULL, PV_NONE,
2119 {(char_u *)NULL, (char_u *)0L}
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2123 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125 {"redraw", NULL, P_BOOL|P_VI_DEF,
2126 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002127 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002128 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2129#ifdef FEAT_RELTIME
2130 (char_u *)&p_rdt, PV_NONE,
2131#else
2132 (char_u *)NULL, PV_NONE,
2133#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002135 {"regexpengine", "re", P_NUM|P_VI_DEF,
2136 (char_u *)&p_re, PV_NONE,
2137 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002138 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2139 (char_u *)VAR_WIN, PV_RNU,
2140 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141 {"remap", NULL, P_BOOL|P_VI_DEF,
2142 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002143 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002144 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002145#ifdef FEAT_RENDER_OPTIONS
2146 (char_u *)&p_rop, PV_NONE,
2147 {(char_u *)"", (char_u *)0L}
2148#else
2149 (char_u *)NULL, PV_NONE,
2150 {(char_u *)NULL, (char_u *)0L}
2151#endif
2152 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"report", NULL, P_NUM|P_VI_DEF,
2154 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002155 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2157#ifdef WIN3264
2158 (char_u *)&p_rs, PV_NONE,
2159#else
2160 (char_u *)NULL, PV_NONE,
2161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002162 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002163 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2164#ifdef FEAT_RIGHTLEFT
2165 (char_u *)&p_ri, PV_NONE,
2166#else
2167 (char_u *)NULL, PV_NONE,
2168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2171#ifdef FEAT_RIGHTLEFT
2172 (char_u *)VAR_WIN, PV_RL,
2173#else
2174 (char_u *)NULL, PV_NONE,
2175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002176 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2178#ifdef FEAT_RIGHTLEFT
2179 (char_u *)VAR_WIN, PV_RLC,
2180 {(char_u *)"search", (char_u *)NULL}
2181#else
2182 (char_u *)NULL, PV_NONE,
2183 {(char_u *)NULL, (char_u *)0L}
2184#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2187#ifdef FEAT_CMDL_INFO
2188 (char_u *)&p_ru, PV_NONE,
2189#else
2190 (char_u *)NULL, PV_NONE,
2191#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002192 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2194#ifdef FEAT_STL_OPT
2195 (char_u *)&p_ruf, PV_NONE,
2196#else
2197 (char_u *)NULL, PV_NONE,
2198#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002199 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002200 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2201 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002202 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002203 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2206 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2209#ifdef FEAT_SCROLLBIND
2210 (char_u *)VAR_WIN, PV_SCBIND,
2211#else
2212 (char_u *)NULL, PV_NONE,
2213#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2216 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002217 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002218 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2219 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002220 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002221 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222#ifdef FEAT_SCROLLBIND
2223 (char_u *)&p_sbo, PV_NONE,
2224 {(char_u *)"ver,jump", (char_u *)0L}
2225#else
2226 (char_u *)NULL, PV_NONE,
2227 {(char_u *)0L, (char_u *)0L}
2228#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230 {"sections", "sect", P_STRING|P_VI_DEF,
2231 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002232 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2233 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2235 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002236 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002239 {(char_u *)"inclusive", (char_u *)0L}
2240 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002241 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002242 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002244 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002245#ifdef FEAT_SESSION
2246 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002247 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002248 (char_u *)0L}
2249#else
2250 (char_u *)NULL, PV_NONE,
2251 {(char_u *)0L, (char_u *)0L}
2252#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002253 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2255 (char_u *)&p_sh, PV_NONE,
2256 {
2257#ifdef VMS
2258 (char_u *)"-",
2259#else
2260# if defined(MSDOS)
2261 (char_u *)"command",
2262# else
2263# if defined(WIN16)
2264 (char_u *)"command.com",
2265# else
2266# if defined(WIN3264)
2267 (char_u *)"", /* set in set_init_1() */
2268# else
2269# if defined(OS2)
2270 (char_u *)"cmd.exe",
2271# else
2272# if defined(ARCHIE)
2273 (char_u *)"gos",
2274# else
2275 (char_u *)"sh",
2276# endif
2277# endif
2278# endif
2279# endif
2280# endif
2281#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2284 (char_u *)&p_shcf, PV_NONE,
2285 {
2286#if defined(MSDOS) || defined(MSWIN)
2287 (char_u *)"/c",
2288#else
2289# if defined(OS2)
2290 (char_u *)"/c",
2291# else
2292 (char_u *)"-c",
2293# endif
2294#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002295 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2297#ifdef FEAT_QUICKFIX
2298 (char_u *)&p_sp, PV_NONE,
2299 {
2300#if defined(UNIX) || defined(OS2)
2301# ifdef ARCHIE
2302 (char_u *)"2>",
2303# else
2304 (char_u *)"| tee",
2305# endif
2306#else
2307 (char_u *)">",
2308#endif
2309 (char_u *)0L}
2310#else
2311 (char_u *)NULL, PV_NONE,
2312 {(char_u *)0L, (char_u *)0L}
2313#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2316 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2319 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002320 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2322#ifdef BACKSLASH_IN_FILENAME
2323 (char_u *)&p_ssl, PV_NONE,
2324#else
2325 (char_u *)NULL, PV_NONE,
2326#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002328 {"shelltemp", "stmp", P_BOOL,
2329 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"shelltype", "st", P_NUM|P_VI_DEF,
2332#ifdef AMIGA
2333 (char_u *)&p_st, PV_NONE,
2334#else
2335 (char_u *)NULL, PV_NONE,
2336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2339 (char_u *)&p_sxq, PV_NONE,
2340 {
2341#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2342 (char_u *)"\"",
2343#else
2344 (char_u *)"",
2345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002347 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2348 (char_u *)&p_sxe, PV_NONE,
2349 {
2350#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2351 (char_u *)"\"&|<>()@^",
2352#else
2353 (char_u *)"",
2354#endif
2355 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2357 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002359 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2360 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002362 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2363 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002364 {(char_u *)"", (char_u *)"filnxtToO"}
2365 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"shortname", "sn", P_BOOL|P_VI_DEF,
2367#ifdef SHORT_FNAME
2368 (char_u *)NULL, PV_NONE,
2369#else
2370 (char_u *)&p_sn, PV_SN,
2371#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002372 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2374#ifdef FEAT_LINEBREAK
2375 (char_u *)&p_sbr, PV_NONE,
2376#else
2377 (char_u *)NULL, PV_NONE,
2378#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002379 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 {"showcmd", "sc", P_BOOL|P_VIM,
2381#ifdef FEAT_CMDL_INFO
2382 (char_u *)&p_sc, PV_NONE,
2383#else
2384 (char_u *)NULL, PV_NONE,
2385#endif
2386 {(char_u *)FALSE,
2387#ifdef UNIX
2388 (char_u *)FALSE
2389#else
2390 (char_u *)TRUE
2391#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2394 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2397 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002398 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399 {"showmode", "smd", P_BOOL|P_VIM,
2400 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002401 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002402 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2403#ifdef FEAT_WINDOWS
2404 (char_u *)&p_stal, PV_NONE,
2405#else
2406 (char_u *)NULL, PV_NONE,
2407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002408 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2410 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002411 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2413 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002414 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2416 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002417 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2419 (char_u *)&p_scs, 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 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2422#ifdef FEAT_SMARTINDENT
2423 (char_u *)&p_si, PV_SI,
2424#else
2425 (char_u *)NULL, PV_NONE,
2426#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002427 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2429 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2432 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002433 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2435 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002437 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002438#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002439 (char_u *)VAR_WIN, PV_SPELL,
2440#else
2441 (char_u *)NULL, PV_NONE,
2442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002443 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002444 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002445#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002446 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002447 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002448#else
2449 (char_u *)NULL, PV_NONE,
2450 {(char_u *)0L, (char_u *)0L}
2451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002453 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2454 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002455#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002456 (char_u *)&p_spf, PV_SPF,
2457 {(char_u *)"", (char_u *)0L}
2458#else
2459 (char_u *)NULL, PV_NONE,
2460 {(char_u *)0L, (char_u *)0L}
2461#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002462 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002463 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2464 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002465#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002466 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002467 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002468#else
2469 (char_u *)NULL, PV_NONE,
2470 {(char_u *)0L, (char_u *)0L}
2471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002473 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002474#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002475 (char_u *)&p_sps, PV_NONE,
2476 {(char_u *)"best", (char_u *)0L}
2477#else
2478 (char_u *)NULL, PV_NONE,
2479 {(char_u *)0L, (char_u *)0L}
2480#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002481 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2483#ifdef FEAT_WINDOWS
2484 (char_u *)&p_sb, PV_NONE,
2485#else
2486 (char_u *)NULL, PV_NONE,
2487#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002488 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 {"splitright", "spr", P_BOOL|P_VI_DEF,
2490#ifdef FEAT_VERTSPLIT
2491 (char_u *)&p_spr, PV_NONE,
2492#else
2493 (char_u *)NULL, PV_NONE,
2494#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002495 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2497 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2500#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002501 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502#else
2503 (char_u *)NULL, PV_NONE,
2504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002506 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 (char_u *)&p_su, PV_NONE,
2508 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002509 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002510 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002511#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 (char_u *)&p_sua, PV_SUA,
2513 {(char_u *)"", (char_u *)0L}
2514#else
2515 (char_u *)NULL, PV_NONE,
2516 {(char_u *)0L, (char_u *)0L}
2517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2520 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"swapsync", "sws", P_STRING|P_VI_DEF,
2523 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002524 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002525 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002528 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2529#ifdef FEAT_SYN_HL
2530 (char_u *)&p_smc, PV_SMC,
2531 {(char_u *)3000L, (char_u *)0L}
2532#else
2533 (char_u *)NULL, PV_NONE,
2534 {(char_u *)0L, (char_u *)0L}
2535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002537 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538#ifdef FEAT_SYN_HL
2539 (char_u *)&p_syn, PV_SYN,
2540 {(char_u *)"", (char_u *)0L}
2541#else
2542 (char_u *)NULL, PV_NONE,
2543 {(char_u *)0L, (char_u *)0L}
2544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002545 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002546 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2547#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002548 (char_u *)&p_tal, PV_NONE,
2549#else
2550 (char_u *)NULL, PV_NONE,
2551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002552 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002553 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2554#ifdef FEAT_WINDOWS
2555 (char_u *)&p_tpm, PV_NONE,
2556#else
2557 (char_u *)NULL, PV_NONE,
2558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2561 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2564 (char_u *)&p_tbs, PV_NONE,
2565#ifdef VMS /* binary searching doesn't appear to work on VMS */
2566 {(char_u *)0L, (char_u *)0L}
2567#else
2568 {(char_u *)TRUE, (char_u *)0L}
2569#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {"taglength", "tl", P_NUM|P_VI_DEF,
2572 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002573 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"tagrelative", "tr", P_BOOL|P_VIM,
2575 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002577 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002578 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {
2580#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2581 (char_u *)"./tags,./TAGS,tags,TAGS",
2582#else
2583 (char_u *)"./tags,tags",
2584#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002585 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2587 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2590 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2593#ifdef FEAT_ARABIC
2594 (char_u *)&p_tbidi, PV_NONE,
2595#else
2596 (char_u *)NULL, PV_NONE,
2597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2600#ifdef FEAT_MBYTE
2601 (char_u *)&p_tenc, PV_NONE,
2602 {(char_u *)"", (char_u *)0L}
2603#else
2604 (char_u *)NULL, PV_NONE,
2605 {(char_u *)0L, (char_u *)0L}
2606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 {"terse", NULL, P_BOOL|P_VI_DEF,
2609 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002610 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611 {"textauto", "ta", P_BOOL|P_VIM,
2612 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2614 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2616 (char_u *)&p_tx, PV_TX,
2617 {
2618#ifdef USE_CRNL
2619 (char_u *)TRUE,
2620#else
2621 (char_u *)FALSE,
2622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002624 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002627 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002629 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630#else
2631 (char_u *)NULL, PV_NONE,
2632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2635 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"timeout", "to", P_BOOL|P_VI_DEF,
2638 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2641 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"title", NULL, P_BOOL|P_VI_DEF,
2644#ifdef FEAT_TITLE
2645 (char_u *)&p_title, PV_NONE,
2646#else
2647 (char_u *)NULL, PV_NONE,
2648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"titlelen", NULL, P_NUM|P_VI_DEF,
2651#ifdef FEAT_TITLE
2652 (char_u *)&p_titlelen, PV_NONE,
2653#else
2654 (char_u *)NULL, PV_NONE,
2655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002657 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658#ifdef FEAT_TITLE
2659 (char_u *)&p_titleold, PV_NONE,
2660 {(char_u *)N_("Thanks for flying Vim"),
2661 (char_u *)0L}
2662#else
2663 (char_u *)NULL, PV_NONE,
2664 {(char_u *)0L, (char_u *)0L}
2665#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002666 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"titlestring", NULL, P_STRING|P_VI_DEF,
2668#ifdef FEAT_TITLE
2669 (char_u *)&p_titlestring, PV_NONE,
2670#else
2671 (char_u *)NULL, PV_NONE,
2672#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002673 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002675 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002676 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)"icons,tooltips", (char_u *)0L}
2678 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002680#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2682 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684#endif
2685 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2686 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2689 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2692 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002693 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2695 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2698#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2699 (char_u *)&p_ttym, PV_NONE,
2700#else
2701 (char_u *)NULL, PV_NONE,
2702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2705 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002706 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2708 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002709 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002710 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2711 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002712#ifdef FEAT_PERSISTENT_UNDO
2713 (char_u *)&p_udir, PV_NONE,
2714 {(char_u *)".", (char_u *)0L}
2715#else
2716 (char_u *)NULL, PV_NONE,
2717 {(char_u *)0L, (char_u *)0L}
2718#endif
2719 SCRIPTID_INIT},
2720 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2721#ifdef FEAT_PERSISTENT_UNDO
2722 (char_u *)&p_udf, PV_UDF,
2723#else
2724 (char_u *)NULL, PV_NONE,
2725#endif
2726 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002727 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002728 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {
2730#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2731 (char_u *)1000L,
2732#else
2733 (char_u *)100L,
2734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002736 {"undoreload", "ur", P_NUM|P_VI_DEF,
2737 (char_u *)&p_ur, PV_NONE,
2738 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 {"updatecount", "uc", P_NUM|P_VI_DEF,
2740 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002741 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 {"updatetime", "ut", P_NUM|P_VI_DEF,
2743 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"verbose", "vbs", P_NUM|P_VI_DEF,
2746 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002748 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2749 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002750 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2752#ifdef FEAT_SESSION
2753 (char_u *)&p_vdir, PV_NONE,
2754 {(char_u *)DFLT_VDIR, (char_u *)0L}
2755#else
2756 (char_u *)NULL, PV_NONE,
2757 {(char_u *)0L, (char_u *)0L}
2758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002759 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002760 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761#ifdef FEAT_SESSION
2762 (char_u *)&p_vop, PV_NONE,
2763 {(char_u *)"folds,options,cursor", (char_u *)0L}
2764#else
2765 (char_u *)NULL, PV_NONE,
2766 {(char_u *)0L, (char_u *)0L}
2767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002768 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002769 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770#ifdef FEAT_VIMINFO
2771 (char_u *)&p_viminfo, PV_NONE,
2772#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002773 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774#else
2775# ifdef AMIGA
2776 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002777 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002779 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780# endif
2781#endif
2782#else
2783 (char_u *)NULL, PV_NONE,
2784 {(char_u *)0L, (char_u *)0L}
2785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002787 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2788 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789#ifdef FEAT_VIRTUALEDIT
2790 (char_u *)&p_ve, PV_NONE,
2791 {(char_u *)"", (char_u *)""}
2792#else
2793 (char_u *)NULL, PV_NONE,
2794 {(char_u *)0L, (char_u *)0L}
2795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2798 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 {"w300", NULL, P_NUM|P_VI_DEF,
2801 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"w1200", NULL, P_NUM|P_VI_DEF,
2804 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"w9600", NULL, P_NUM|P_VI_DEF,
2807 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"warn", NULL, P_BOOL|P_VI_DEF,
2810 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002811 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2813 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002814 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002815 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002817 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {"wildchar", "wc", P_NUM|P_VIM,
2819 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002820 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2821 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002822 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002825 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826#ifdef FEAT_WILDIGN
2827 (char_u *)&p_wig, PV_NONE,
2828#else
2829 (char_u *)NULL, PV_NONE,
2830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002832 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2833 (char_u *)&p_wic, PV_NONE,
2834 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2836#ifdef FEAT_WILDMENU
2837 (char_u *)&p_wmnu, PV_NONE,
2838#else
2839 (char_u *)NULL, PV_NONE,
2840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002841 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002842 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002844 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002845 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2846#ifdef FEAT_CMDL_COMPL
2847 (char_u *)&p_wop, PV_NONE,
2848 {(char_u *)"", (char_u *)0L}
2849#else
2850 (char_u *)NULL, PV_NONE,
2851 {(char_u *)NULL, (char_u *)0L}
2852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002853 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2855#ifdef FEAT_WAK
2856 (char_u *)&p_wak, PV_NONE,
2857 {(char_u *)"menu", (char_u *)0L}
2858#else
2859 (char_u *)NULL, PV_NONE,
2860 {(char_u *)NULL, (char_u *)0L}
2861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002864 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002865 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"winheight", "wh", P_NUM|P_VI_DEF,
2867#ifdef FEAT_WINDOWS
2868 (char_u *)&p_wh, PV_NONE,
2869#else
2870 (char_u *)NULL, PV_NONE,
2871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002874#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002875 (char_u *)VAR_WIN, PV_WFH,
2876#else
2877 (char_u *)NULL, PV_NONE,
2878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002880 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2881#ifdef FEAT_VERTSPLIT
2882 (char_u *)VAR_WIN, PV_WFW,
2883#else
2884 (char_u *)NULL, PV_NONE,
2885#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2888#ifdef FEAT_WINDOWS
2889 (char_u *)&p_wmh, PV_NONE,
2890#else
2891 (char_u *)NULL, PV_NONE,
2892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2895#ifdef FEAT_VERTSPLIT
2896 (char_u *)&p_wmw, PV_NONE,
2897#else
2898 (char_u *)NULL, PV_NONE,
2899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2902#ifdef FEAT_VERTSPLIT
2903 (char_u *)&p_wiw, PV_NONE,
2904#else
2905 (char_u *)NULL, PV_NONE,
2906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002907 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2909 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002910 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2912 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002913 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2915 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002916 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"write", NULL, P_BOOL|P_VI_DEF,
2918 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002919 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"writeany", "wa", P_BOOL|P_VI_DEF,
2921 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002922 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2924 (char_u *)&p_wb, PV_NONE,
2925 {
2926#ifdef FEAT_WRITEBACKUP
2927 (char_u *)TRUE,
2928#else
2929 (char_u *)FALSE,
2930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002931 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 {"writedelay", "wd", P_NUM|P_VI_DEF,
2933 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935
2936/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002937#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940
2941 p_term("t_AB", T_CAB)
2942 p_term("t_AF", T_CAF)
2943 p_term("t_AL", T_CAL)
2944 p_term("t_al", T_AL)
2945 p_term("t_bc", T_BC)
2946 p_term("t_cd", T_CD)
2947 p_term("t_ce", T_CE)
2948 p_term("t_cl", T_CL)
2949 p_term("t_cm", T_CM)
2950 p_term("t_Co", T_CCO)
2951 p_term("t_CS", T_CCS)
2952 p_term("t_cs", T_CS)
2953#ifdef FEAT_VERTSPLIT
2954 p_term("t_CV", T_CSV)
2955#endif
2956 p_term("t_ut", T_UT)
2957 p_term("t_da", T_DA)
2958 p_term("t_db", T_DB)
2959 p_term("t_DL", T_CDL)
2960 p_term("t_dl", T_DL)
2961 p_term("t_fs", T_FS)
2962 p_term("t_IE", T_CIE)
2963 p_term("t_IS", T_CIS)
2964 p_term("t_ke", T_KE)
2965 p_term("t_ks", T_KS)
2966 p_term("t_le", T_LE)
2967 p_term("t_mb", T_MB)
2968 p_term("t_md", T_MD)
2969 p_term("t_me", T_ME)
2970 p_term("t_mr", T_MR)
2971 p_term("t_ms", T_MS)
2972 p_term("t_nd", T_ND)
2973 p_term("t_op", T_OP)
2974 p_term("t_RI", T_CRI)
2975 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002976 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 p_term("t_Sb", T_CSB)
2978 p_term("t_Sf", T_CSF)
2979 p_term("t_se", T_SE)
2980 p_term("t_so", T_SO)
2981 p_term("t_sr", T_SR)
2982 p_term("t_ts", T_TS)
2983 p_term("t_te", T_TE)
2984 p_term("t_ti", T_TI)
2985 p_term("t_ue", T_UE)
2986 p_term("t_us", T_US)
2987 p_term("t_vb", T_VB)
2988 p_term("t_ve", T_VE)
2989 p_term("t_vi", T_VI)
2990 p_term("t_vs", T_VS)
2991 p_term("t_WP", T_CWP)
2992 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002993 p_term("t_SI", T_CSI)
2994 p_term("t_EI", T_CEI)
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02002995 p_term("t_SR", T_CSR)
Bram Moolenaar494838a2015-02-10 19:20:37 +01002996 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 p_term("t_xs", T_XS)
2998 p_term("t_ZH", T_CZH)
2999 p_term("t_ZR", T_CZR)
3000
3001/* terminal key codes are not in here */
3002
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003003 /* end marker */
3004 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005};
3006
3007#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3008
3009#ifdef FEAT_MBYTE
3010static char *(p_ambw_values[]) = {"single", "double", NULL};
3011#endif
3012static char *(p_bg_values[]) = {"light", "dark", NULL};
3013static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
3014static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003015#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003016static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003017#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003018#ifdef FEAT_CMDL_COMPL
3019static char *(p_wop_values[]) = {"tagfile", NULL};
3020#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021#ifdef FEAT_WAK
3022static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3023#endif
3024static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3026static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028#ifdef FEAT_BROWSE
3029static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3030#endif
3031#ifdef FEAT_SCROLLBIND
3032static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3033#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003034static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035#ifdef FEAT_VERTSPLIT
3036static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3037#endif
3038#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003039# ifdef FEAT_AUTOCMD
3040static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3041# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003043# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3045#endif
3046static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3047#ifdef FEAT_FOLDING
3048static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003049# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003051# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 NULL};
3053static char *(p_fcl_values[]) = {"all", NULL};
3054#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003055#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003056static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003057#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058
3059static void set_option_default __ARGS((int, int opt_flags, int compatible));
3060static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003061static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003062static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063static char_u *illegal_char __ARGS((char_u *, int));
3064static int string_to_key __ARGS((char_u *arg));
3065#ifdef FEAT_CMDWIN
3066static char_u *check_cedit __ARGS((void));
3067#endif
3068#ifdef FEAT_TITLE
3069static void did_set_title __ARGS((int icon));
3070#endif
3071static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3072static void didset_options __ARGS((void));
3073static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003074#if defined(FEAT_EVAL) || defined(PROTO)
3075static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3076#else
3077# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3078#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003080static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081static 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));
3082static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003083#ifdef FEAT_SYN_HL
3084static int int_cmp __ARGS((const void *a, const void *b));
3085#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086#ifdef FEAT_CLIPBOARD
3087static char_u *check_clipboard_option __ARGS((void));
3088#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003089#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003090static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003091#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003092#ifdef FEAT_EVAL
3093static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3094#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003096static 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 +00003097static void check_redraw __ARGS((long_u flags));
3098static int findoption __ARGS((char_u *));
3099static int find_key_option __ARGS((char_u *));
3100static void showoptions __ARGS((int all, int opt_flags));
3101static int optval_default __ARGS((struct vimoption *, char_u *varp));
3102static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3103static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3104static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3105static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3106static int istermoption __ARGS((struct vimoption *));
3107static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3108static char_u *get_varp __ARGS((struct vimoption *));
3109static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003110static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3112#ifdef FEAT_LANGMAP
3113static void langmap_init __ARGS((void));
3114static void langmap_set __ARGS((void));
3115#endif
3116static void paste_option_changed __ARGS((void));
3117static void compatible_set __ARGS((void));
3118#ifdef FEAT_LINEBREAK
3119static void fill_breakat_flags __ARGS((void));
3120#endif
3121static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3122static int check_opt_strings __ARGS((char_u *val, char **values, int));
3123static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003124#ifdef FEAT_LINEBREAK
3125static int briopt_check __ARGS((win_T *wp));
3126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127
3128/*
3129 * Initialize the options, first part.
3130 *
3131 * Called only once from main(), just after creating the first buffer.
3132 */
3133 void
3134set_init_1()
3135{
3136 char_u *p;
3137 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003138 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139
3140#ifdef FEAT_LANGMAP
3141 langmap_init();
3142#endif
3143
3144 /* Be Vi compatible by default */
3145 p_cp = TRUE;
3146
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003147 /* Use POSIX compatibility when $VIM_POSIX is set. */
3148 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003149 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003150 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003151 set_string_default("shm", (char_u *)"A");
3152 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003153
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154 /*
3155 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003156 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003158 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3160# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003161 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003163 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003165 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166# endif
3167#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003168 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 set_string_default("sh", p);
3170
3171#ifdef FEAT_WILDIGN
3172 /*
3173 * Set the default for 'backupskip' to include environment variables for
3174 * temp files.
3175 */
3176 {
3177# ifdef UNIX
3178 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3179# else
3180 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3181# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003182 int len;
3183 garray_T ga;
3184 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185
3186 ga_init2(&ga, 1, 100);
3187 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3188 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003189 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190# ifdef UNIX
3191 if (*names[n] == NUL)
3192 p = (char_u *)"/tmp";
3193 else
3194# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003195 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196 if (p != NULL && *p != NUL)
3197 {
3198 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003199 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 if (ga_grow(&ga, len) == OK)
3201 {
3202 if (ga.ga_len > 0)
3203 STRCAT(ga.ga_data, ",");
3204 STRCAT(ga.ga_data, p);
3205 add_pathsep(ga.ga_data);
3206 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207 ga.ga_len += len;
3208 }
3209 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003210 if (mustfree)
3211 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 }
3213 if (ga.ga_data != NULL)
3214 {
3215 set_string_default("bsk", ga.ga_data);
3216 vim_free(ga.ga_data);
3217 }
3218 }
3219#endif
3220
3221 /*
3222 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3223 */
3224 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003225 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003227#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3228 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3229#endif
3230 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003232 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003233 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234#else
3235# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003236 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003237 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003239 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240# endif
3241#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003243 opt_idx = findoption((char_u *)"maxmem");
3244 if (opt_idx >= 0)
3245 {
3246#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003247 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003248 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3249#endif
3250 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3251 }
3252 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253 }
3254
3255#ifdef FEAT_GUI_W32
3256 /* force 'shortname' for Win32s */
3257 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003258 {
3259 opt_idx = findoption((char_u *)"shortname");
3260 if (opt_idx >= 0)
3261 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3262 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263#endif
3264
3265#ifdef FEAT_SEARCHPATH
3266 {
3267 char_u *cdpath;
3268 char_u *buf;
3269 int i;
3270 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003271 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272
3273 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003274 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275 if (cdpath != NULL)
3276 {
3277 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3278 if (buf != NULL)
3279 {
3280 buf[0] = ','; /* start with ",", current dir first */
3281 j = 1;
3282 for (i = 0; cdpath[i] != NUL; ++i)
3283 {
3284 if (vim_ispathlistsep(cdpath[i]))
3285 buf[j++] = ',';
3286 else
3287 {
3288 if (cdpath[i] == ' ' || cdpath[i] == ',')
3289 buf[j++] = '\\';
3290 buf[j++] = cdpath[i];
3291 }
3292 }
3293 buf[j] = NUL;
3294 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003295 if (opt_idx >= 0)
3296 {
3297 options[opt_idx].def_val[VI_DEFAULT] = buf;
3298 options[opt_idx].flags |= P_DEF_ALLOCED;
3299 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003300 else
3301 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003303 if (mustfree)
3304 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305 }
3306 }
3307#endif
3308
3309#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3310 /* Set print encoding on platforms that don't default to latin1 */
3311 set_string_default("penc",
3312# if defined(MSWIN) || defined(OS2)
3313 (char_u *)"cp1252"
3314# else
3315# ifdef VMS
3316 (char_u *)"dec-mcs"
3317# else
3318# ifdef EBCDIC
3319 (char_u *)"ebcdic-uk"
3320# else
3321# ifdef MAC
3322 (char_u *)"mac-roman"
3323# else /* HPUX */
3324 (char_u *)"hp-roman8"
3325# endif
3326# endif
3327# endif
3328# endif
3329 );
3330#endif
3331
3332#ifdef FEAT_POSTSCRIPT
3333 /* 'printexpr' must be allocated to be able to evaluate it. */
3334 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003335# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3336 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337# else
3338# ifdef VMS
3339 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3340
3341# else
3342 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3343# endif
3344# endif
3345 );
3346#endif
3347
3348 /*
3349 * Set all the options (except the terminal options) to their default
3350 * value. Also set the global value for local options.
3351 */
3352 set_options_default(0);
3353
3354#ifdef FEAT_GUI
3355 if (found_reverse_arg)
3356 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3357#endif
3358
3359 curbuf->b_p_initialized = TRUE;
3360 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003361 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362 check_buf_options(curbuf);
3363 check_win_options(curwin);
3364 check_options();
3365
3366 /* Must be before option_expand(), because that one needs vim_isIDc() */
3367 didset_options();
3368
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003369#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003370 /* Use the current chartab for the generic chartab. */
3371 init_spell_chartab();
3372#endif
3373
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374#ifdef FEAT_LINEBREAK
3375 /*
3376 * initialize the table for 'breakat'.
3377 */
3378 fill_breakat_flags();
3379#endif
3380
3381 /*
3382 * Expand environment variables and things like "~" for the defaults.
3383 * If option_expand() returns non-NULL the variable is expanded. This can
3384 * only happen for non-indirect options.
3385 * Also set the default to the expanded value, so ":set" does not list
3386 * them.
3387 * Don't set the P_ALLOCED flag, because we don't want to free the
3388 * default.
3389 */
3390 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3391 {
3392 if ((options[opt_idx].flags & P_GETTEXT)
3393 && options[opt_idx].var != NULL)
3394 p = (char_u *)_(*(char **)options[opt_idx].var);
3395 else
3396 p = option_expand(opt_idx, NULL);
3397 if (p != NULL && (p = vim_strsave(p)) != NULL)
3398 {
3399 *(char_u **)options[opt_idx].var = p;
3400 /* VIMEXP
3401 * Defaults for all expanded options are currently the same for Vi
3402 * and Vim. When this changes, add some code here! Also need to
3403 * split P_DEF_ALLOCED in two.
3404 */
3405 if (options[opt_idx].flags & P_DEF_ALLOCED)
3406 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3407 options[opt_idx].def_val[VI_DEFAULT] = p;
3408 options[opt_idx].flags |= P_DEF_ALLOCED;
3409 }
3410 }
3411
3412 /* Initialize the highlight_attr[] table. */
3413 highlight_changed();
3414
3415 save_file_ff(curbuf); /* Buffer is unchanged */
3416
3417 /* Parse default for 'wildmode' */
3418 check_opt_wim();
3419
3420#if defined(FEAT_ARABIC)
3421 /* Detect use of mlterm.
3422 * Mlterm is a terminal emulator akin to xterm that has some special
3423 * abilities (bidi namely).
3424 * NOTE: mlterm's author is being asked to 'set' a variable
3425 * instead of an environment variable due to inheritance.
3426 */
3427 if (mch_getenv((char_u *)"MLTERM") != NULL)
3428 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3429#endif
3430
3431#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3432 /* Parse default for 'fillchars'. */
3433 (void)set_chars_option(&p_fcs);
3434#endif
3435
3436#ifdef FEAT_CLIPBOARD
3437 /* Parse default for 'clipboard' */
3438 (void)check_clipboard_option();
3439#endif
3440
3441#ifdef FEAT_MBYTE
3442# if defined(WIN3264) && defined(FEAT_GETTEXT)
3443 /*
3444 * If $LANG isn't set, try to get a good value for it. This makes the
3445 * right language be used automatically. Don't do this for English.
3446 */
3447 if (mch_getenv((char_u *)"LANG") == NULL)
3448 {
3449 char buf[20];
3450
3451 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3452 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3453 * only the first two. */
3454 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3455 (LPTSTR)buf, 20);
3456 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3457 {
3458 /* There are a few exceptions (probably more) */
3459 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3460 STRCPY(buf, "zh_TW");
3461 else if (STRNICMP(buf, "chs", 3) == 0
3462 || STRNICMP(buf, "zhc", 3) == 0)
3463 STRCPY(buf, "zh_CN");
3464 else if (STRNICMP(buf, "jp", 2) == 0)
3465 STRCPY(buf, "ja");
3466 else
3467 buf[2] = NUL; /* truncate to two-letter code */
3468 vim_setenv("LANG", buf);
3469 }
3470 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003471# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003472# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003473 /* Moved to os_mac_conv.c to avoid dependency problems. */
3474 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003475# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476# endif
3477
3478 /* enc_locale() will try to find the encoding of the current locale. */
3479 p = enc_locale();
3480 if (p != NULL)
3481 {
3482 char_u *save_enc;
3483
3484 /* Try setting 'encoding' and check if the value is valid.
3485 * If not, go back to the default "latin1". */
3486 save_enc = p_enc;
3487 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003488 if (STRCMP(p_enc, "gb18030") == 0)
3489 {
3490 /* We don't support "gb18030", but "cp936" is a good substitute
3491 * for practical purposes, thus use that. It's not an alias to
3492 * still support conversion between gb18030 and utf-8. */
3493 p_enc = vim_strsave((char_u *)"cp936");
3494 vim_free(p);
3495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496 if (mb_init() == NULL)
3497 {
3498 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003499 if (opt_idx >= 0)
3500 {
3501 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3502 options[opt_idx].flags |= P_DEF_ALLOCED;
3503 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003504
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003505#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3506 || defined(VMS)
3507 if (STRCMP(p_enc, "latin1") == 0
3508# ifdef FEAT_MBYTE
3509 || enc_utf8
3510# endif
3511 )
3512 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003513 /* Adjust the default for 'isprint' and 'iskeyword' to match
3514 * latin1. Also set the defaults for when 'nocompatible' is
3515 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003516 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003517 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003518 set_string_option_direct((char_u *)"isk", -1,
3519 ISK_LATIN1, OPT_FREE, SID_NONE);
3520 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003521 if (opt_idx >= 0)
3522 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003523 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003524 if (opt_idx >= 0)
3525 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003526 (void)init_chartab();
3527 }
3528#endif
3529
Bram Moolenaar071d4272004-06-13 20:20:40 +00003530# if defined(WIN3264) && !defined(FEAT_GUI)
3531 /* Win32 console: When GetACP() returns a different value from
3532 * GetConsoleCP() set 'termencoding'. */
3533 if (GetACP() != GetConsoleCP())
3534 {
3535 char buf[50];
3536
3537 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3538 p_tenc = vim_strsave((char_u *)buf);
3539 if (p_tenc != NULL)
3540 {
3541 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003542 if (opt_idx >= 0)
3543 {
3544 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3545 options[opt_idx].flags |= P_DEF_ALLOCED;
3546 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003547 convert_setup(&input_conv, p_tenc, p_enc);
3548 convert_setup(&output_conv, p_enc, p_tenc);
3549 }
3550 else
3551 p_tenc = empty_option;
3552 }
3553# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003554# if defined(WIN3264) && defined(FEAT_MBYTE)
3555 /* $HOME may have characters in active code page. */
3556 init_homedir();
3557# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003558 }
3559 else
3560 {
3561 vim_free(p_enc);
3562 p_enc = save_enc;
3563 }
3564 }
3565#endif
3566
3567#ifdef FEAT_MULTI_LANG
3568 /* Set the default for 'helplang'. */
3569 set_helplang_default(get_mess_lang());
3570#endif
3571}
3572
3573/*
3574 * Set an option to its default value.
3575 * This does not take care of side effects!
3576 */
3577 static void
3578set_option_default(opt_idx, opt_flags, compatible)
3579 int opt_idx;
3580 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3581 int compatible; /* use Vi default value */
3582{
3583 char_u *varp; /* pointer to variable for current option */
3584 int dvi; /* index in def_val[] */
3585 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003586 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003587 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3588
3589 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3590 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003591 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592 {
3593 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3594 if (flags & P_STRING)
3595 {
3596 /* Use set_string_option_direct() for local options to handle
3597 * freeing and allocating the value. */
3598 if (options[opt_idx].indir != PV_NONE)
3599 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003600 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 else
3602 {
3603 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3604 free_string_option(*(char_u **)(varp));
3605 *(char_u **)varp = options[opt_idx].def_val[dvi];
3606 options[opt_idx].flags &= ~P_ALLOCED;
3607 }
3608 }
3609 else if (flags & P_NUM)
3610 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003611 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003612 win_comp_scroll(curwin);
3613 else
3614 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003615 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003616 /* May also set global value for local option. */
3617 if (both)
3618 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3619 *(long *)varp;
3620 }
3621 }
3622 else /* P_BOOL */
3623 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003624 /* the cast to long is required for Manx C, long_i is needed for
3625 * MSVC */
3626 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003627#ifdef UNIX
3628 /* 'modeline' defaults to off for root */
3629 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3630 *(int *)varp = FALSE;
3631#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632 /* May also set global value for local option. */
3633 if (both)
3634 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3635 *(int *)varp;
3636 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003637
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003638 /* The default value is not insecure. */
3639 flagsp = insecure_flag(opt_idx, opt_flags);
3640 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641 }
3642
3643#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003644 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003645#endif
3646}
3647
3648/*
3649 * Set all options (except terminal options) to their default value.
3650 */
3651 static void
3652set_options_default(opt_flags)
3653 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3654{
3655 int i;
3656#ifdef FEAT_WINDOWS
3657 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003658 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003659#endif
3660
3661 for (i = 0; !istermoption(&options[i]); i++)
3662 if (!(options[i].flags & P_NODEFAULT))
3663 set_option_default(i, opt_flags, p_cp);
3664
3665#ifdef FEAT_WINDOWS
3666 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003667 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003668 win_comp_scroll(wp);
3669#else
3670 win_comp_scroll(curwin);
3671#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003672#ifdef FEAT_CINDENT
3673 parse_cino(curbuf);
3674#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003675}
3676
3677/*
3678 * Set the Vi-default value of a string option.
3679 * Used for 'sh', 'backupskip' and 'term'.
3680 */
3681 void
3682set_string_default(name, val)
3683 char *name;
3684 char_u *val;
3685{
3686 char_u *p;
3687 int opt_idx;
3688
3689 p = vim_strsave(val);
3690 if (p != NULL) /* we don't want a NULL */
3691 {
3692 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003693 if (opt_idx >= 0)
3694 {
3695 if (options[opt_idx].flags & P_DEF_ALLOCED)
3696 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3697 options[opt_idx].def_val[VI_DEFAULT] = p;
3698 options[opt_idx].flags |= P_DEF_ALLOCED;
3699 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700 }
3701}
3702
3703/*
3704 * Set the Vi-default value of a number option.
3705 * Used for 'lines' and 'columns'.
3706 */
3707 void
3708set_number_default(name, val)
3709 char *name;
3710 long val;
3711{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003712 int opt_idx;
3713
3714 opt_idx = findoption((char_u *)name);
3715 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003716 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717}
3718
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003719#if defined(EXITFREE) || defined(PROTO)
3720/*
3721 * Free all options.
3722 */
3723 void
3724free_all_options()
3725{
3726 int i;
3727
3728 for (i = 0; !istermoption(&options[i]); i++)
3729 {
3730 if (options[i].indir == PV_NONE)
3731 {
3732 /* global option: free value and default value. */
3733 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3734 free_string_option(*(char_u **)options[i].var);
3735 if (options[i].flags & P_DEF_ALLOCED)
3736 free_string_option(options[i].def_val[VI_DEFAULT]);
3737 }
3738 else if (options[i].var != VAR_WIN
3739 && (options[i].flags & P_STRING))
3740 /* buffer-local option: free global value */
3741 free_string_option(*(char_u **)options[i].var);
3742 }
3743}
3744#endif
3745
3746
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747/*
3748 * Initialize the options, part two: After getting Rows and Columns and
3749 * setting 'term'.
3750 */
3751 void
3752set_init_2()
3753{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003754 int idx;
3755
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756 /*
3757 * 'scroll' defaults to half the window height. Note that this default is
3758 * wrong when the window height changes.
3759 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003760 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003761 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003762 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003763 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003764 comp_col();
3765
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003766 /*
3767 * 'window' is only for backwards compatibility with Vi.
3768 * Default is Rows - 1.
3769 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003770 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003771 p_window = Rows - 1;
3772 set_number_default("window", Rows - 1);
3773
Bram Moolenaarf740b292006-02-16 22:11:02 +00003774 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003775#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003776 /*
3777 * If 'background' wasn't set by the user, try guessing the value,
3778 * depending on the terminal name. Only need to check for terminals
3779 * with a dark background, that can handle color.
3780 */
3781 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003782 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3783 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003784 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003785 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003786 /* don't mark it as set, when starting the GUI it may be
3787 * changed again */
3788 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 }
3790#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003791
3792#ifdef CURSOR_SHAPE
3793 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3794#endif
3795#ifdef FEAT_MOUSESHAPE
3796 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3797#endif
3798#ifdef FEAT_PRINTER
3799 (void)parse_printoptions(); /* parse 'printoptions' default value */
3800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801}
3802
3803/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003804 * Return "dark" or "light" depending on the kind of terminal.
3805 * This is just guessing! Recognized are:
3806 * "linux" Linux console
3807 * "screen.linux" Linux console with screen
3808 * "cygwin" Cygwin shell
3809 * "putty" Putty program
3810 * We also check the COLORFGBG environment variable, which is set by
3811 * rxvt and derivatives. This variable contains either two or three
3812 * values separated by semicolons; we want the last value in either
3813 * case. If this value is 0-6 or 8, our background is dark.
3814 */
3815 static char_u *
3816term_bg_default()
3817{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003818#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3819 /* DOS console nearly always black */
3820 return (char_u *)"dark";
3821#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003822 char_u *p;
3823
Bram Moolenaarf740b292006-02-16 22:11:02 +00003824 if (STRCMP(T_NAME, "linux") == 0
3825 || STRCMP(T_NAME, "screen.linux") == 0
3826 || STRCMP(T_NAME, "cygwin") == 0
3827 || STRCMP(T_NAME, "putty") == 0
3828 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3829 && (p = vim_strrchr(p, ';')) != NULL
3830 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3831 && p[2] == NUL))
3832 return (char_u *)"dark";
3833 return (char_u *)"light";
3834#endif
3835}
3836
3837/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838 * Initialize the options, part three: After reading the .vimrc
3839 */
3840 void
3841set_init_3()
3842{
3843#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3844/*
3845 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3846 * This is done after other initializations, where 'shell' might have been
3847 * set, but only if they have not been set before.
3848 */
3849 char_u *p;
3850 int idx_srr;
3851 int do_srr;
3852#ifdef FEAT_QUICKFIX
3853 int idx_sp;
3854 int do_sp;
3855#endif
3856
3857 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003858 if (idx_srr < 0)
3859 do_srr = FALSE;
3860 else
3861 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862#ifdef FEAT_QUICKFIX
3863 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003864 if (idx_sp < 0)
3865 do_sp = FALSE;
3866 else
3867 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003869 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870 if (p != NULL)
3871 {
3872 /*
3873 * Default for p_sp is "| tee", for p_srr is ">".
3874 * For known shells it is changed here to include stderr.
3875 */
3876 if ( fnamecmp(p, "csh") == 0
3877 || fnamecmp(p, "tcsh") == 0
3878# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3879 || fnamecmp(p, "csh.exe") == 0
3880 || fnamecmp(p, "tcsh.exe") == 0
3881# endif
3882 )
3883 {
3884#if defined(FEAT_QUICKFIX)
3885 if (do_sp)
3886 {
3887# ifdef WIN3264
3888 p_sp = (char_u *)">&";
3889# else
3890 p_sp = (char_u *)"|& tee";
3891# endif
3892 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3893 }
3894#endif
3895 if (do_srr)
3896 {
3897 p_srr = (char_u *)">&";
3898 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3899 }
3900 }
3901 else
3902# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3903 if ( fnamecmp(p, "sh") == 0
3904 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003905 || fnamecmp(p, "mksh") == 0
3906 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003908 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003910 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911# ifdef WIN3264
3912 || fnamecmp(p, "cmd") == 0
3913 || fnamecmp(p, "sh.exe") == 0
3914 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003915 || fnamecmp(p, "mksh.exe") == 0
3916 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003918 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 || fnamecmp(p, "bash.exe") == 0
3920 || fnamecmp(p, "cmd.exe") == 0
3921# endif
3922 )
3923# endif
3924 {
3925#if defined(FEAT_QUICKFIX)
3926 if (do_sp)
3927 {
3928# ifdef WIN3264
3929 p_sp = (char_u *)">%s 2>&1";
3930# else
3931 p_sp = (char_u *)"2>&1| tee";
3932# endif
3933 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3934 }
3935#endif
3936 if (do_srr)
3937 {
3938 p_srr = (char_u *)">%s 2>&1";
3939 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3940 }
3941 }
3942 vim_free(p);
3943 }
3944#endif
3945
3946#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3947 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003948 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3949 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 * This is done after other initializations, where 'shell' might have been
3951 * set, but only if they have not been set before. Default for p_shcf is
3952 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3953 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3954 * command.com. And for Win32 we need to set p_sxq instead.
3955 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003956 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003957 {
3958 int idx3;
3959
3960 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003961 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 {
3963 p_shcf = (char_u *)"-c";
3964 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3965 }
3966
3967# ifndef DJGPP
3968# ifdef WIN3264
3969 /* Somehow Win32 requires the quotes around the redirection too */
3970 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003971 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972 {
3973 p_sxq = (char_u *)"\"";
3974 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3975 }
3976# else
3977 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003978 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 {
3980 p_shq = (char_u *)"\"";
3981 options[idx3].def_val[VI_DEFAULT] = p_shq;
3982 }
3983# endif
3984# endif
3985 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003986 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3987 {
3988 int idx3;
3989
3990 /*
3991 * cmd.exe on Windows will strip the first and last double quote given
3992 * on the command line, e.g. most of the time things like:
3993 * cmd /c "my path/to/echo" "my args to echo"
3994 * become:
3995 * my path/to/echo" "my args to echo
3996 * when executed.
3997 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003998 * To avoid this, set shellxquote to surround the command in
3999 * parenthesis. This appears to make most commands work, without
4000 * breaking commands that worked previously, such as
4001 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004002 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004003 idx3 = findoption((char_u *)"sxq");
4004 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4005 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004006 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004007 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4008 }
4009
Bram Moolenaara64ba222012-02-12 23:23:31 +01004010 idx3 = findoption((char_u *)"shcf");
4011 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4012 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004013 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004014 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4015 }
4016 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004017#endif
4018
4019#ifdef FEAT_TITLE
4020 set_title_defaults();
4021#endif
4022}
4023
4024#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4025/*
4026 * When 'helplang' is still at its default value, set it to "lang".
4027 * Only the first two characters of "lang" are used.
4028 */
4029 void
4030set_helplang_default(lang)
4031 char_u *lang;
4032{
4033 int idx;
4034
4035 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4036 return;
4037 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004038 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 {
4040 if (options[idx].flags & P_ALLOCED)
4041 free_string_option(p_hlg);
4042 p_hlg = vim_strsave(lang);
4043 if (p_hlg == NULL)
4044 p_hlg = empty_option;
4045 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004046 {
4047 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4048 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4049 {
4050 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4051 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4052 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004054 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 options[idx].flags |= P_ALLOCED;
4056 }
4057}
4058#endif
4059
4060#ifdef FEAT_GUI
4061static char_u *gui_bg_default __ARGS((void));
4062
4063 static char_u *
4064gui_bg_default()
4065{
4066 if (gui_get_lightness(gui.back_pixel) < 127)
4067 return (char_u *)"dark";
4068 return (char_u *)"light";
4069}
4070
4071/*
4072 * Option initializations that can only be done after opening the GUI window.
4073 */
4074 void
4075init_gui_options()
4076{
4077 /* Set the 'background' option according to the lightness of the
4078 * background color, unless the user has set it already. */
4079 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4080 {
4081 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4082 highlight_changed();
4083 }
4084}
4085#endif
4086
4087#ifdef FEAT_TITLE
4088/*
4089 * 'title' and 'icon' only default to true if they have not been set or reset
4090 * in .vimrc and we can read the old value.
4091 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4092 * they can be reset. This reduces startup time when using X on a remote
4093 * machine.
4094 */
4095 void
4096set_title_defaults()
4097{
4098 int idx1;
4099 long val;
4100
4101 /*
4102 * If GUI is (going to be) used, we can always set the window title and
4103 * icon name. Saves a bit of time, because the X11 display server does
4104 * not need to be contacted.
4105 */
4106 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004107 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004108 {
4109#ifdef FEAT_GUI
4110 if (gui.starting || gui.in_use)
4111 val = TRUE;
4112 else
4113#endif
4114 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004115 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 p_title = val;
4117 }
4118 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004119 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 {
4121#ifdef FEAT_GUI
4122 if (gui.starting || gui.in_use)
4123 val = TRUE;
4124 else
4125#endif
4126 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004127 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 p_icon = val;
4129 }
4130}
4131#endif
4132
4133/*
4134 * Parse 'arg' for option settings.
4135 *
4136 * 'arg' may be IObuff, but only when no errors can be present and option
4137 * does not need to be expanded with option_expand().
4138 * "opt_flags":
4139 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004140 * OPT_GLOBAL for ":setglobal"
4141 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004143 * OPT_WINONLY to only set window-local options
4144 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 *
4146 * returns FAIL if an error is detected, OK otherwise
4147 */
4148 int
4149do_set(arg, opt_flags)
4150 char_u *arg; /* option string (may be written to!) */
4151 int opt_flags;
4152{
4153 int opt_idx;
4154 char_u *errmsg;
4155 char_u errbuf[80];
4156 char_u *startarg;
4157 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4158 int nextchar; /* next non-white char after option name */
4159 int afterchar; /* character just after option name */
4160 int len;
4161 int i;
4162 long value;
4163 int key;
4164 long_u flags; /* flags for current option */
4165 char_u *varp = NULL; /* pointer to variable for current option */
4166 int did_show = FALSE; /* already showed one value */
4167 int adding; /* "opt+=arg" */
4168 int prepending; /* "opt^=arg" */
4169 int removing; /* "opt-=arg" */
4170 int cp_val = 0;
4171 char_u key_name[2];
4172
4173 if (*arg == NUL)
4174 {
4175 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004176 did_show = TRUE;
4177 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004178 }
4179
4180 while (*arg != NUL) /* loop to process all options */
4181 {
4182 errmsg = NULL;
4183 startarg = arg; /* remember for error message */
4184
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004185 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4186 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 {
4188 /*
4189 * ":set all" show all options.
4190 * ":set all&" set all options to their default value.
4191 */
4192 arg += 3;
4193 if (*arg == '&')
4194 {
4195 ++arg;
4196 /* Only for :set command set global value of local options. */
4197 set_options_default(OPT_FREE | opt_flags);
4198 }
4199 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004200 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004202 did_show = TRUE;
4203 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004204 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004205 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206 {
4207 showoptions(2, opt_flags);
4208 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004209 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210 arg += 7;
4211 }
4212 else
4213 {
4214 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004215 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004216 {
4217 prefix = 0;
4218 arg += 2;
4219 }
4220 else if (STRNCMP(arg, "inv", 3) == 0)
4221 {
4222 prefix = 2;
4223 arg += 3;
4224 }
4225
4226 /* find end of name */
4227 key = 0;
4228 if (*arg == '<')
4229 {
4230 nextchar = 0;
4231 opt_idx = -1;
4232 /* look out for <t_>;> */
4233 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4234 len = 5;
4235 else
4236 {
4237 len = 1;
4238 while (arg[len] != NUL && arg[len] != '>')
4239 ++len;
4240 }
4241 if (arg[len] != '>')
4242 {
4243 errmsg = e_invarg;
4244 goto skip;
4245 }
4246 arg[len] = NUL; /* put NUL after name */
4247 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4248 opt_idx = findoption(arg + 1);
4249 arg[len++] = '>'; /* restore '>' */
4250 if (opt_idx == -1)
4251 key = find_key_option(arg + 1);
4252 }
4253 else
4254 {
4255 len = 0;
4256 /*
4257 * The two characters after "t_" may not be alphanumeric.
4258 */
4259 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4260 len = 4;
4261 else
4262 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4263 ++len;
4264 nextchar = arg[len];
4265 arg[len] = NUL; /* put NUL after name */
4266 opt_idx = findoption(arg);
4267 arg[len] = nextchar; /* restore nextchar */
4268 if (opt_idx == -1)
4269 key = find_key_option(arg);
4270 }
4271
4272 /* remember character after option name */
4273 afterchar = arg[len];
4274
4275 /* skip white space, allow ":set ai ?" */
4276 while (vim_iswhite(arg[len]))
4277 ++len;
4278
4279 adding = FALSE;
4280 prepending = FALSE;
4281 removing = FALSE;
4282 if (arg[len] != NUL && arg[len + 1] == '=')
4283 {
4284 if (arg[len] == '+')
4285 {
4286 adding = TRUE; /* "+=" */
4287 ++len;
4288 }
4289 else if (arg[len] == '^')
4290 {
4291 prepending = TRUE; /* "^=" */
4292 ++len;
4293 }
4294 else if (arg[len] == '-')
4295 {
4296 removing = TRUE; /* "-=" */
4297 ++len;
4298 }
4299 }
4300 nextchar = arg[len];
4301
4302 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4303 {
4304 errmsg = (char_u *)N_("E518: Unknown option");
4305 goto skip;
4306 }
4307
4308 if (opt_idx >= 0)
4309 {
4310 if (options[opt_idx].var == NULL) /* hidden option: skip */
4311 {
4312 /* Only give an error message when requesting the value of
4313 * a hidden option, ignore setting it. */
4314 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4315 && (!(options[opt_idx].flags & P_BOOL)
4316 || nextchar == '?'))
4317 errmsg = (char_u *)N_("E519: Option not supported");
4318 goto skip;
4319 }
4320
4321 flags = options[opt_idx].flags;
4322 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4323 }
4324 else
4325 {
4326 flags = P_STRING;
4327 if (key < 0)
4328 {
4329 key_name[0] = KEY2TERMCAP0(key);
4330 key_name[1] = KEY2TERMCAP1(key);
4331 }
4332 else
4333 {
4334 key_name[0] = KS_KEY;
4335 key_name[1] = (key & 0xff);
4336 }
4337 }
4338
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004339 /* Skip all options that are not window-local (used when showing
4340 * an already loaded buffer in a window). */
4341 if ((opt_flags & OPT_WINONLY)
4342 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4343 goto skip;
4344
Bram Moolenaara3227e22006-03-08 21:32:40 +00004345 /* Skip all options that are window-local (used for :vimgrep). */
4346 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4347 && options[opt_idx].var == VAR_WIN)
4348 goto skip;
4349
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004350 /* Disallow changing some options from modelines. */
4351 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004352 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004353 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004354 {
4355 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4356 goto skip;
4357 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004358#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004359 /* In diff mode some options are overruled. This avoids that
4360 * 'foldmethod' becomes "marker" instead of "diff" and that
4361 * "wrap" gets set. */
4362 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004363 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004364 && (options[opt_idx].indir == PV_FDM
4365 || options[opt_idx].indir == PV_WRAP))
4366 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004367#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004368 }
4369
4370#ifdef HAVE_SANDBOX
4371 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004372 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004373 {
4374 errmsg = (char_u *)_(e_sandbox);
4375 goto skip;
4376 }
4377#endif
4378
4379 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4380 {
4381 arg += len;
4382 cp_val = p_cp;
4383 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4384 {
4385 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4386 {
4387 cp_val = FALSE;
4388 arg += 3;
4389 }
4390 else /* "opt&vi": set to Vi default */
4391 {
4392 cp_val = TRUE;
4393 arg += 2;
4394 }
4395 }
4396 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4397 && arg[1] != NUL && !vim_iswhite(arg[1]))
4398 {
4399 errmsg = e_trailing;
4400 goto skip;
4401 }
4402 }
4403
4404 /*
4405 * allow '=' and ':' as MSDOS command.com allows only one
4406 * '=' character per "set" command line. grrr. (jw)
4407 */
4408 if (nextchar == '?'
4409 || (prefix == 1
4410 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4411 && !(flags & P_BOOL)))
4412 {
4413 /*
4414 * print value
4415 */
4416 if (did_show)
4417 msg_putchar('\n'); /* cursor below last one */
4418 else
4419 {
4420 gotocmdline(TRUE); /* cursor at status line */
4421 did_show = TRUE; /* remember that we did a line */
4422 }
4423 if (opt_idx >= 0)
4424 {
4425 showoneopt(&options[opt_idx], opt_flags);
4426#ifdef FEAT_EVAL
4427 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004428 {
4429 /* Mention where the option was last set. */
4430 if (varp == options[opt_idx].var)
4431 last_set_msg(options[opt_idx].scriptID);
4432 else if ((int)options[opt_idx].indir & PV_WIN)
4433 last_set_msg(curwin->w_p_scriptID[
4434 (int)options[opt_idx].indir & PV_MASK]);
4435 else if ((int)options[opt_idx].indir & PV_BUF)
4436 last_set_msg(curbuf->b_p_scriptID[
4437 (int)options[opt_idx].indir & PV_MASK]);
4438 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439#endif
4440 }
4441 else
4442 {
4443 char_u *p;
4444
4445 p = find_termcode(key_name);
4446 if (p == NULL)
4447 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004448 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004449 goto skip;
4450 }
4451 else
4452 (void)show_one_termcode(key_name, p, TRUE);
4453 }
4454 if (nextchar != '?'
4455 && nextchar != NUL && !vim_iswhite(afterchar))
4456 errmsg = e_trailing;
4457 }
4458 else
4459 {
4460 if (flags & P_BOOL) /* boolean */
4461 {
4462 if (nextchar == '=' || nextchar == ':')
4463 {
4464 errmsg = e_invarg;
4465 goto skip;
4466 }
4467
4468 /*
4469 * ":set opt!": invert
4470 * ":set opt&": reset to default value
4471 * ":set opt<": reset to global value
4472 */
4473 if (nextchar == '!')
4474 value = *(int *)(varp) ^ 1;
4475 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004476 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004477 ((flags & P_VI_DEF) || cp_val)
4478 ? VI_DEFAULT : VIM_DEFAULT];
4479 else if (nextchar == '<')
4480 {
4481 /* For 'autoread' -1 means to use global value. */
4482 if ((int *)varp == &curbuf->b_p_ar
4483 && opt_flags == OPT_LOCAL)
4484 value = -1;
4485 else
4486 value = *(int *)get_varp_scope(&(options[opt_idx]),
4487 OPT_GLOBAL);
4488 }
4489 else
4490 {
4491 /*
4492 * ":set invopt": invert
4493 * ":set opt" or ":set noopt": set or reset
4494 */
4495 if (nextchar != NUL && !vim_iswhite(afterchar))
4496 {
4497 errmsg = e_trailing;
4498 goto skip;
4499 }
4500 if (prefix == 2) /* inv */
4501 value = *(int *)(varp) ^ 1;
4502 else
4503 value = prefix;
4504 }
4505
4506 errmsg = set_bool_option(opt_idx, varp, (int)value,
4507 opt_flags);
4508 }
4509 else /* numeric or string */
4510 {
4511 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4512 || prefix != 1)
4513 {
4514 errmsg = e_invarg;
4515 goto skip;
4516 }
4517
4518 if (flags & P_NUM) /* numeric */
4519 {
4520 /*
4521 * Different ways to set a number option:
4522 * & set to default value
4523 * < set to global value
4524 * <xx> accept special key codes for 'wildchar'
4525 * c accept any non-digit for 'wildchar'
4526 * [-]0-9 set number
4527 * other error
4528 */
4529 ++arg;
4530 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004531 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004532 ((flags & P_VI_DEF) || cp_val)
4533 ? VI_DEFAULT : VIM_DEFAULT];
4534 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004535 {
4536 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4537 * use the global value. */
4538 if ((long *)varp == &curbuf->b_p_ul
4539 && opt_flags == OPT_LOCAL)
4540 value = NO_LOCAL_UNDOLEVEL;
4541 else
4542 value = *(long *)get_varp_scope(
4543 &(options[opt_idx]), OPT_GLOBAL);
4544 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004545 else if (((long *)varp == &p_wc
4546 || (long *)varp == &p_wcm)
4547 && (*arg == '<'
4548 || *arg == '^'
4549 || ((!arg[1] || vim_iswhite(arg[1]))
4550 && !VIM_ISDIGIT(*arg))))
4551 {
4552 value = string_to_key(arg);
4553 if (value == 0 && (long *)varp != &p_wcm)
4554 {
4555 errmsg = e_invarg;
4556 goto skip;
4557 }
4558 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004559 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4560 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004561 /* Allow negative (for 'undolevels'), octal and
4562 * hex numbers. */
4563 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004564 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4565 {
4566 errmsg = e_invarg;
4567 goto skip;
4568 }
4569 }
4570 else
4571 {
4572 errmsg = (char_u *)N_("E521: Number required after =");
4573 goto skip;
4574 }
4575
4576 if (adding)
4577 value = *(long *)varp + value;
4578 if (prepending)
4579 value = *(long *)varp * value;
4580 if (removing)
4581 value = *(long *)varp - value;
4582 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004583 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004584 }
4585 else if (opt_idx >= 0) /* string */
4586 {
4587 char_u *save_arg = NULL;
4588 char_u *s = NULL;
4589 char_u *oldval; /* previous value if *varp */
4590 char_u *newval;
4591 char_u *origval;
4592 unsigned newlen;
4593 int comma;
4594 int bs;
4595 int new_value_alloced; /* new string option
4596 was allocated */
4597
4598 /* When using ":set opt=val" for a global option
4599 * with a local value the local value will be
4600 * reset, use the global value here. */
4601 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004602 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004603 varp = options[opt_idx].var;
4604
4605 /* The old value is kept until we are sure that the
4606 * new value is valid. */
4607 oldval = *(char_u **)varp;
4608 if (nextchar == '&') /* set to default val */
4609 {
4610 newval = options[opt_idx].def_val[
4611 ((flags & P_VI_DEF) || cp_val)
4612 ? VI_DEFAULT : VIM_DEFAULT];
4613 if ((char_u **)varp == &p_bg)
4614 {
4615 /* guess the value of 'background' */
4616#ifdef FEAT_GUI
4617 if (gui.in_use)
4618 newval = gui_bg_default();
4619 else
4620#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004621 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004622 }
4623
4624 /* expand environment variables and ~ (since the
4625 * default value was already expanded, only
4626 * required when an environment variable was set
4627 * later */
4628 if (newval == NULL)
4629 newval = empty_option;
4630 else
4631 {
4632 s = option_expand(opt_idx, newval);
4633 if (s == NULL)
4634 s = newval;
4635 newval = vim_strsave(s);
4636 }
4637 new_value_alloced = TRUE;
4638 }
4639 else if (nextchar == '<') /* set to global val */
4640 {
4641 newval = vim_strsave(*(char_u **)get_varp_scope(
4642 &(options[opt_idx]), OPT_GLOBAL));
4643 new_value_alloced = TRUE;
4644 }
4645 else
4646 {
4647 ++arg; /* jump to after the '=' or ':' */
4648
4649 /*
4650 * Set 'keywordprg' to ":help" if an empty
4651 * value was passed to :set by the user.
4652 * Misuse errbuf[] for the resulting string.
4653 */
4654 if (varp == (char_u *)&p_kp
4655 && (*arg == NUL || *arg == ' '))
4656 {
4657 STRCPY(errbuf, ":help");
4658 save_arg = arg;
4659 arg = errbuf;
4660 }
4661 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004662 * Convert 'backspace' number to string, for
4663 * adding, prepending and removing string.
4664 */
4665 else if (varp == (char_u *)&p_bs
4666 && VIM_ISDIGIT(**(char_u **)varp))
4667 {
4668 i = getdigits((char_u **)varp);
4669 switch (i)
4670 {
4671 case 0:
4672 *(char_u **)varp = empty_option;
4673 break;
4674 case 1:
4675 *(char_u **)varp = vim_strsave(
4676 (char_u *)"indent,eol");
4677 break;
4678 case 2:
4679 *(char_u **)varp = vim_strsave(
4680 (char_u *)"indent,eol,start");
4681 break;
4682 }
4683 vim_free(oldval);
4684 oldval = *(char_u **)varp;
4685 }
4686 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004687 * Convert 'whichwrap' number to string, for
4688 * backwards compatibility with Vim 3.0.
4689 * Misuse errbuf[] for the resulting string.
4690 */
4691 else if (varp == (char_u *)&p_ww
4692 && VIM_ISDIGIT(*arg))
4693 {
4694 *errbuf = NUL;
4695 i = getdigits(&arg);
4696 if (i & 1)
4697 STRCAT(errbuf, "b,");
4698 if (i & 2)
4699 STRCAT(errbuf, "s,");
4700 if (i & 4)
4701 STRCAT(errbuf, "h,l,");
4702 if (i & 8)
4703 STRCAT(errbuf, "<,>,");
4704 if (i & 16)
4705 STRCAT(errbuf, "[,],");
4706 if (*errbuf != NUL) /* remove trailing , */
4707 errbuf[STRLEN(errbuf) - 1] = NUL;
4708 save_arg = arg;
4709 arg = errbuf;
4710 }
4711 /*
4712 * Remove '>' before 'dir' and 'bdir', for
4713 * backwards compatibility with version 3.0
4714 */
4715 else if ( *arg == '>'
4716 && (varp == (char_u *)&p_dir
4717 || varp == (char_u *)&p_bdir))
4718 {
4719 ++arg;
4720 }
4721
4722 /* When setting the local value of a global
4723 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004724 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004725 && (opt_flags & OPT_LOCAL))
4726 origval = *(char_u **)get_varp(
4727 &options[opt_idx]);
4728 else
4729 origval = oldval;
4730
4731 /*
4732 * Copy the new string into allocated memory.
4733 * Can't use set_string_option_direct(), because
4734 * we need to remove the backslashes.
4735 */
4736 /* get a bit too much */
4737 newlen = (unsigned)STRLEN(arg) + 1;
4738 if (adding || prepending || removing)
4739 newlen += (unsigned)STRLEN(origval) + 1;
4740 newval = alloc(newlen);
4741 if (newval == NULL) /* out of mem, don't change */
4742 break;
4743 s = newval;
4744
4745 /*
4746 * Copy the string, skip over escaped chars.
4747 * For MS-DOS and WIN32 backslashes before normal
4748 * file name characters are not removed, and keep
4749 * backslash at start, for "\\machine\path", but
4750 * do remove it for "\\\\machine\\path".
4751 * The reverse is found in ExpandOldSetting().
4752 */
4753 while (*arg && !vim_iswhite(*arg))
4754 {
4755 if (*arg == '\\' && arg[1] != NUL
4756#ifdef BACKSLASH_IN_FILENAME
4757 && !((flags & P_EXPAND)
4758 && vim_isfilec(arg[1])
4759 && (arg[1] != '\\'
4760 || (s == newval
4761 && arg[2] != '\\')))
4762#endif
4763 )
4764 ++arg; /* remove backslash */
4765#ifdef FEAT_MBYTE
4766 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004767 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004768 {
4769 /* copy multibyte char */
4770 mch_memmove(s, arg, (size_t)i);
4771 arg += i;
4772 s += i;
4773 }
4774 else
4775#endif
4776 *s++ = *arg++;
4777 }
4778 *s = NUL;
4779
4780 /*
4781 * Expand environment variables and ~.
4782 * Don't do it when adding without inserting a
4783 * comma.
4784 */
4785 if (!(adding || prepending || removing)
4786 || (flags & P_COMMA))
4787 {
4788 s = option_expand(opt_idx, newval);
4789 if (s != NULL)
4790 {
4791 vim_free(newval);
4792 newlen = (unsigned)STRLEN(s) + 1;
4793 if (adding || prepending || removing)
4794 newlen += (unsigned)STRLEN(origval) + 1;
4795 newval = alloc(newlen);
4796 if (newval == NULL)
4797 break;
4798 STRCPY(newval, s);
4799 }
4800 }
4801
4802 /* locate newval[] in origval[] when removing it
4803 * and when adding to avoid duplicates */
4804 i = 0; /* init for GCC */
4805 if (removing || (flags & P_NODUP))
4806 {
4807 i = (int)STRLEN(newval);
4808 bs = 0;
4809 for (s = origval; *s; ++s)
4810 {
4811 if ((!(flags & P_COMMA)
4812 || s == origval
4813 || (s[-1] == ',' && !(bs & 1)))
4814 && STRNCMP(s, newval, i) == 0
4815 && (!(flags & P_COMMA)
4816 || s[i] == ','
4817 || s[i] == NUL))
4818 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004819 /* Count backslashes. Only a comma with an
4820 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004821 * recognized as a separator */
4822 if (s > origval && s[-1] == '\\')
4823 ++bs;
4824 else
4825 bs = 0;
4826 }
4827
4828 /* do not add if already there */
4829 if ((adding || prepending) && *s)
4830 {
4831 prepending = FALSE;
4832 adding = FALSE;
4833 STRCPY(newval, origval);
4834 }
4835 }
4836
4837 /* concatenate the two strings; add a ',' if
4838 * needed */
4839 if (adding || prepending)
4840 {
4841 comma = ((flags & P_COMMA) && *origval != NUL
4842 && *newval != NUL);
4843 if (adding)
4844 {
4845 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004846 /* strip a trailing comma, would get 2 */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02004847 if (comma && (flags & P_ONECOMMA) && i > 1
4848 && origval[i - 1] == ','
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004849 && origval[i - 2] != '\\')
4850 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004851 mch_memmove(newval + i + comma, newval,
4852 STRLEN(newval) + 1);
4853 mch_memmove(newval, origval, (size_t)i);
4854 }
4855 else
4856 {
4857 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004858 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004859 }
4860 if (comma)
4861 newval[i] = ',';
4862 }
4863
4864 /* Remove newval[] from origval[]. (Note: "i" has
4865 * been set above and is used here). */
4866 if (removing)
4867 {
4868 STRCPY(newval, origval);
4869 if (*s)
4870 {
4871 /* may need to remove a comma */
4872 if (flags & P_COMMA)
4873 {
4874 if (s == origval)
4875 {
4876 /* include comma after string */
4877 if (s[i] == ',')
4878 ++i;
4879 }
4880 else
4881 {
4882 /* include comma before string */
4883 --s;
4884 ++i;
4885 }
4886 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004887 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004888 }
4889 }
4890
4891 if (flags & P_FLAGLIST)
4892 {
4893 /* Remove flags that appear twice. */
4894 for (s = newval; *s; ++s)
4895 if ((!(flags & P_COMMA) || *s != ',')
4896 && vim_strchr(s + 1, *s) != NULL)
4897 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004898 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004899 --s;
4900 }
4901 }
4902
4903 if (save_arg != NULL) /* number for 'whichwrap' */
4904 arg = save_arg;
4905 new_value_alloced = TRUE;
4906 }
4907
4908 /* Set the new value. */
4909 *(char_u **)(varp) = newval;
4910
4911 /* Handle side effects, and set the global value for
4912 * ":set" on local options. */
4913 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4914 new_value_alloced, oldval, errbuf, opt_flags);
4915
4916 /* If error detected, print the error message. */
4917 if (errmsg != NULL)
4918 goto skip;
4919 }
4920 else /* key code option */
4921 {
4922 char_u *p;
4923
4924 if (nextchar == '&')
4925 {
4926 if (add_termcap_entry(key_name, TRUE) == FAIL)
4927 errmsg = (char_u *)N_("E522: Not found in termcap");
4928 }
4929 else
4930 {
4931 ++arg; /* jump to after the '=' or ':' */
4932 for (p = arg; *p && !vim_iswhite(*p); ++p)
4933 if (*p == '\\' && p[1] != NUL)
4934 ++p;
4935 nextchar = *p;
4936 *p = NUL;
4937 add_termcode(key_name, arg, FALSE);
4938 *p = nextchar;
4939 }
4940 if (full_screen)
4941 ttest(FALSE);
4942 redraw_all_later(CLEAR);
4943 }
4944 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004945
Bram Moolenaar071d4272004-06-13 20:20:40 +00004946 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004947 did_set_option(opt_idx, opt_flags,
4948 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004949 }
4950
4951skip:
4952 /*
4953 * Advance to next argument.
4954 * - skip until a blank found, taking care of backslashes
4955 * - skip blanks
4956 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4957 */
4958 for (i = 0; i < 2 ; ++i)
4959 {
4960 while (*arg != NUL && !vim_iswhite(*arg))
4961 if (*arg++ == '\\' && *arg != NUL)
4962 ++arg;
4963 arg = skipwhite(arg);
4964 if (*arg != '=')
4965 break;
4966 }
4967 }
4968
4969 if (errmsg != NULL)
4970 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004971 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004972 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004973 if (i + (arg - startarg) < IOSIZE)
4974 {
4975 /* append the argument with the error */
4976 STRCAT(IObuff, ": ");
4977 mch_memmove(IObuff + i, startarg, (arg - startarg));
4978 IObuff[i + (arg - startarg)] = NUL;
4979 }
4980 /* make sure all characters are printable */
4981 trans_characters(IObuff, IOSIZE);
4982
4983 ++no_wait_return; /* wait_return done later */
4984 emsg(IObuff); /* show error highlighted */
4985 --no_wait_return;
4986
4987 return FAIL;
4988 }
4989
4990 arg = skipwhite(arg);
4991 }
4992
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004993theend:
4994 if (silent_mode && did_show)
4995 {
4996 /* After displaying option values in silent mode. */
4997 silent_mode = FALSE;
4998 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4999 msg_putchar('\n');
5000 cursor_on(); /* msg_start() switches it off */
5001 out_flush();
5002 silent_mode = TRUE;
5003 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5004 }
5005
Bram Moolenaar071d4272004-06-13 20:20:40 +00005006 return OK;
5007}
5008
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005009/*
5010 * Call this when an option has been given a new value through a user command.
5011 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5012 */
5013 static void
5014did_set_option(opt_idx, opt_flags, new_value)
5015 int opt_idx;
5016 int opt_flags; /* possibly with OPT_MODELINE */
5017 int new_value; /* value was replaced completely */
5018{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005019 long_u *p;
5020
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005021 options[opt_idx].flags |= P_WAS_SET;
5022
5023 /* When an option is set in the sandbox, from a modeline or in secure mode
5024 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005025 * flag. */
5026 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005027 if (secure
5028#ifdef HAVE_SANDBOX
5029 || sandbox != 0
5030#endif
5031 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005032 *p = *p | P_INSECURE;
5033 else if (new_value)
5034 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005035}
5036
Bram Moolenaar071d4272004-06-13 20:20:40 +00005037 static char_u *
5038illegal_char(errbuf, c)
5039 char_u *errbuf;
5040 int c;
5041{
5042 if (errbuf == NULL)
5043 return (char_u *)"";
5044 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005045 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005046 return errbuf;
5047}
5048
5049/*
5050 * Convert a key name or string into a key value.
5051 * Used for 'wildchar' and 'cedit' options.
5052 */
5053 static int
5054string_to_key(arg)
5055 char_u *arg;
5056{
5057 if (*arg == '<')
5058 return find_key_option(arg + 1);
5059 if (*arg == '^')
5060 return Ctrl_chr(arg[1]);
5061 return *arg;
5062}
5063
5064#ifdef FEAT_CMDWIN
5065/*
5066 * Check value of 'cedit' and set cedit_key.
5067 * Returns NULL if value is OK, error message otherwise.
5068 */
5069 static char_u *
5070check_cedit()
5071{
5072 int n;
5073
5074 if (*p_cedit == NUL)
5075 cedit_key = -1;
5076 else
5077 {
5078 n = string_to_key(p_cedit);
5079 if (vim_isprintc(n))
5080 return e_invarg;
5081 cedit_key = n;
5082 }
5083 return NULL;
5084}
5085#endif
5086
5087#ifdef FEAT_TITLE
5088/*
5089 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5090 * maketitle() to create and display it.
5091 * When switching the title or icon off, call mch_restore_title() to get
5092 * the old value back.
5093 */
5094 static void
5095did_set_title(icon)
5096 int icon; /* Did set icon instead of title */
5097{
5098 if (starting != NO_SCREEN
5099#ifdef FEAT_GUI
5100 && !gui.starting
5101#endif
5102 )
5103 {
5104 maketitle();
5105 if (icon)
5106 {
5107 if (!p_icon)
5108 mch_restore_title(2);
5109 }
5110 else
5111 {
5112 if (!p_title)
5113 mch_restore_title(1);
5114 }
5115 }
5116}
5117#endif
5118
5119/*
5120 * set_options_bin - called when 'bin' changes value.
5121 */
5122 void
5123set_options_bin(oldval, newval, opt_flags)
5124 int oldval;
5125 int newval;
5126 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5127{
5128 /*
5129 * The option values that are changed when 'bin' changes are
5130 * copied when 'bin is set and restored when 'bin' is reset.
5131 */
5132 if (newval)
5133 {
5134 if (!oldval) /* switched on */
5135 {
5136 if (!(opt_flags & OPT_GLOBAL))
5137 {
5138 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5139 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5140 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5141 curbuf->b_p_et_nobin = curbuf->b_p_et;
5142 }
5143 if (!(opt_flags & OPT_LOCAL))
5144 {
5145 p_tw_nobin = p_tw;
5146 p_wm_nobin = p_wm;
5147 p_ml_nobin = p_ml;
5148 p_et_nobin = p_et;
5149 }
5150 }
5151
5152 if (!(opt_flags & OPT_GLOBAL))
5153 {
5154 curbuf->b_p_tw = 0; /* no automatic line wrap */
5155 curbuf->b_p_wm = 0; /* no automatic line wrap */
5156 curbuf->b_p_ml = 0; /* no modelines */
5157 curbuf->b_p_et = 0; /* no expandtab */
5158 }
5159 if (!(opt_flags & OPT_LOCAL))
5160 {
5161 p_tw = 0;
5162 p_wm = 0;
5163 p_ml = FALSE;
5164 p_et = FALSE;
5165 p_bin = TRUE; /* needed when called for the "-b" argument */
5166 }
5167 }
5168 else if (oldval) /* switched off */
5169 {
5170 if (!(opt_flags & OPT_GLOBAL))
5171 {
5172 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5173 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5174 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5175 curbuf->b_p_et = curbuf->b_p_et_nobin;
5176 }
5177 if (!(opt_flags & OPT_LOCAL))
5178 {
5179 p_tw = p_tw_nobin;
5180 p_wm = p_wm_nobin;
5181 p_ml = p_ml_nobin;
5182 p_et = p_et_nobin;
5183 }
5184 }
5185}
5186
5187#ifdef FEAT_VIMINFO
5188/*
5189 * Find the parameter represented by the given character (eg ', :, ", or /),
5190 * and return its associated value in the 'viminfo' string.
5191 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005192 * If the parameter is not specified in the string or there is no following
5193 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005194 */
5195 int
5196get_viminfo_parameter(type)
5197 int type;
5198{
5199 char_u *p;
5200
5201 p = find_viminfo_parameter(type);
5202 if (p != NULL && VIM_ISDIGIT(*p))
5203 return atoi((char *)p);
5204 return -1;
5205}
5206
5207/*
5208 * Find the parameter represented by the given character (eg ''', ':', '"', or
5209 * '/') in the 'viminfo' option and return a pointer to the string after it.
5210 * Return NULL if the parameter is not specified in the string.
5211 */
5212 char_u *
5213find_viminfo_parameter(type)
5214 int type;
5215{
5216 char_u *p;
5217
5218 for (p = p_viminfo; *p; ++p)
5219 {
5220 if (*p == type)
5221 return p + 1;
5222 if (*p == 'n') /* 'n' is always the last one */
5223 break;
5224 p = vim_strchr(p, ','); /* skip until next ',' */
5225 if (p == NULL) /* hit the end without finding parameter */
5226 break;
5227 }
5228 return NULL;
5229}
5230#endif
5231
5232/*
5233 * Expand environment variables for some string options.
5234 * These string options cannot be indirect!
5235 * If "val" is NULL expand the current value of the option.
5236 * Return pointer to NameBuff, or NULL when not expanded.
5237 */
5238 static char_u *
5239option_expand(opt_idx, val)
5240 int opt_idx;
5241 char_u *val;
5242{
5243 /* if option doesn't need expansion nothing to do */
5244 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5245 return NULL;
5246
5247 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5248 * expand_env() would truncate the string. */
5249 if (val != NULL && STRLEN(val) > MAXPATHL)
5250 return NULL;
5251
5252 if (val == NULL)
5253 val = *(char_u **)options[opt_idx].var;
5254
5255 /*
5256 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5257 * Escape spaces when expanding 'tags', they are used to separate file
5258 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005259 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005260 */
5261 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005262 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005263#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005264 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5265#endif
5266 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005267 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5268 return NULL;
5269
5270 return NameBuff;
5271}
5272
5273/*
5274 * After setting various option values: recompute variables that depend on
5275 * option values.
5276 */
5277 static void
5278didset_options()
5279{
5280 /* initialize the table for 'iskeyword' et.al. */
5281 (void)init_chartab();
5282
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005283#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005284 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005286 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5287#ifdef FEAT_SESSION
5288 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5289 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5290#endif
5291#ifdef FEAT_FOLDING
5292 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5293#endif
5294 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5295#ifdef FEAT_VIRTUALEDIT
5296 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5297#endif
5298#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5299 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5300#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005301#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005302 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005303 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005304 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005306#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5307 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5308#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005309#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5311#endif
5312#ifdef FEAT_CMDWIN
5313 /* set cedit_key */
5314 (void)check_cedit();
5315#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005316#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005317 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005318#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005319}
5320
5321/*
5322 * Check for string options that are NULL (normally only termcap options).
5323 */
5324 void
5325check_options()
5326{
5327 int opt_idx;
5328
5329 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5330 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5331 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5332}
5333
5334/*
5335 * Check string options in a buffer for NULL value.
5336 */
5337 void
5338check_buf_options(buf)
5339 buf_T *buf;
5340{
5341#if defined(FEAT_QUICKFIX)
5342 check_string_option(&buf->b_p_bh);
5343 check_string_option(&buf->b_p_bt);
5344#endif
5345#ifdef FEAT_MBYTE
5346 check_string_option(&buf->b_p_fenc);
5347#endif
5348 check_string_option(&buf->b_p_ff);
5349#ifdef FEAT_FIND_ID
5350 check_string_option(&buf->b_p_def);
5351 check_string_option(&buf->b_p_inc);
5352# ifdef FEAT_EVAL
5353 check_string_option(&buf->b_p_inex);
5354# endif
5355#endif
5356#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5357 check_string_option(&buf->b_p_inde);
5358 check_string_option(&buf->b_p_indk);
5359#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005360#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5361 check_string_option(&buf->b_p_bexpr);
5362#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005363#if defined(FEAT_CRYPT)
5364 check_string_option(&buf->b_p_cm);
5365#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005366#if defined(FEAT_EVAL)
5367 check_string_option(&buf->b_p_fex);
5368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369#ifdef FEAT_CRYPT
5370 check_string_option(&buf->b_p_key);
5371#endif
5372 check_string_option(&buf->b_p_kp);
5373 check_string_option(&buf->b_p_mps);
5374 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005375 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376 check_string_option(&buf->b_p_isk);
5377#ifdef FEAT_COMMENTS
5378 check_string_option(&buf->b_p_com);
5379#endif
5380#ifdef FEAT_FOLDING
5381 check_string_option(&buf->b_p_cms);
5382#endif
5383 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005384#ifdef FEAT_TEXTOBJ
5385 check_string_option(&buf->b_p_qe);
5386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387#ifdef FEAT_SYN_HL
5388 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005389#endif
5390#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005391 check_string_option(&buf->b_s.b_p_spc);
5392 check_string_option(&buf->b_s.b_p_spf);
5393 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005394#endif
5395#ifdef FEAT_SEARCHPATH
5396 check_string_option(&buf->b_p_sua);
5397#endif
5398#ifdef FEAT_CINDENT
5399 check_string_option(&buf->b_p_cink);
5400 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005401 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005402#endif
5403#ifdef FEAT_AUTOCMD
5404 check_string_option(&buf->b_p_ft);
5405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005406#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5407 check_string_option(&buf->b_p_cinw);
5408#endif
5409#ifdef FEAT_INS_EXPAND
5410 check_string_option(&buf->b_p_cpt);
5411#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005412#ifdef FEAT_COMPL_FUNC
5413 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005414 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005415#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005416#ifdef FEAT_KEYMAP
5417 check_string_option(&buf->b_p_keymap);
5418#endif
5419#ifdef FEAT_QUICKFIX
5420 check_string_option(&buf->b_p_gp);
5421 check_string_option(&buf->b_p_mp);
5422 check_string_option(&buf->b_p_efm);
5423#endif
5424 check_string_option(&buf->b_p_ep);
5425 check_string_option(&buf->b_p_path);
5426 check_string_option(&buf->b_p_tags);
5427#ifdef FEAT_INS_EXPAND
5428 check_string_option(&buf->b_p_dict);
5429 check_string_option(&buf->b_p_tsr);
5430#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005431#ifdef FEAT_LISP
5432 check_string_option(&buf->b_p_lw);
5433#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005434 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005435}
5436
5437/*
5438 * Free the string allocated for an option.
5439 * Checks for the string being empty_option. This may happen if we're out of
5440 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5441 * check_options().
5442 * Does NOT check for P_ALLOCED flag!
5443 */
5444 void
5445free_string_option(p)
5446 char_u *p;
5447{
5448 if (p != empty_option)
5449 vim_free(p);
5450}
5451
5452 void
5453clear_string_option(pp)
5454 char_u **pp;
5455{
5456 if (*pp != empty_option)
5457 vim_free(*pp);
5458 *pp = empty_option;
5459}
5460
5461 static void
5462check_string_option(pp)
5463 char_u **pp;
5464{
5465 if (*pp == NULL)
5466 *pp = empty_option;
5467}
5468
5469/*
5470 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5471 */
5472 void
5473set_term_option_alloced(p)
5474 char_u **p;
5475{
5476 int opt_idx;
5477
5478 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5479 if (options[opt_idx].var == (char_u *)p)
5480 {
5481 options[opt_idx].flags |= P_ALLOCED;
5482 return;
5483 }
5484 return; /* cannot happen: didn't find it! */
5485}
5486
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005487#if defined(FEAT_EVAL) || defined(PROTO)
5488/*
5489 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5490 * Return FALSE when it wasn't.
5491 * Return -1 for an unknown option.
5492 */
5493 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005494was_set_insecurely(opt, opt_flags)
5495 char_u *opt;
5496 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005497{
5498 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005499 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005500
5501 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005502 {
5503 flagp = insecure_flag(idx, opt_flags);
5504 return (*flagp & P_INSECURE) != 0;
5505 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005506 EMSG2(_(e_intern2), "was_set_insecurely()");
5507 return -1;
5508}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005509
5510/*
5511 * Get a pointer to the flags used for the P_INSECURE flag of option
5512 * "opt_idx". For some local options a local flags field is used.
5513 */
5514 static long_u *
5515insecure_flag(opt_idx, opt_flags)
5516 int opt_idx;
5517 int opt_flags;
5518{
5519 if (opt_flags & OPT_LOCAL)
5520 switch ((int)options[opt_idx].indir)
5521 {
5522#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005523 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005524#endif
5525#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005526# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005527 case PV_FDE: return &curwin->w_p_fde_flags;
5528 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005529# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005530# ifdef FEAT_BEVAL
5531 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5532# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005533# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005534 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005535# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005536 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005537# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005538 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005539# endif
5540#endif
5541 }
5542
5543 /* Nothing special, return global flags field. */
5544 return &options[opt_idx].flags;
5545}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005546#endif
5547
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005548#ifdef FEAT_TITLE
5549static void redraw_titles __ARGS((void));
5550
5551/*
5552 * Redraw the window title and/or tab page text later.
5553 */
5554static void redraw_titles()
5555{
5556 need_maketitle = TRUE;
5557# ifdef FEAT_WINDOWS
5558 redraw_tabline = TRUE;
5559# endif
5560}
5561#endif
5562
Bram Moolenaar071d4272004-06-13 20:20:40 +00005563/*
5564 * Set a string option to a new value (without checking the effect).
5565 * The string is copied into allocated memory.
5566 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005567 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005568 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005569 */
5570 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005571set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005572 char_u *name;
5573 int opt_idx;
5574 char_u *val;
5575 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005576 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577{
5578 char_u *s;
5579 char_u **varp;
5580 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005581 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582
Bram Moolenaar89d40322006-08-29 15:30:07 +00005583 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005585 idx = findoption(name);
5586 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005587 {
5588 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005589 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005591 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005592 }
5593
Bram Moolenaar89d40322006-08-29 15:30:07 +00005594 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005595 return;
5596
5597 s = vim_strsave(val);
5598 if (s != NULL)
5599 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005600 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005601 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005602 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005603 free_string_option(*varp);
5604 *varp = s;
5605
5606 /* For buffer/window local option may also set the global value. */
5607 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005608 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005609
Bram Moolenaar89d40322006-08-29 15:30:07 +00005610 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005611
5612 /* When setting both values of a global option with a local value,
5613 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005614 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615 {
5616 free_string_option(*varp);
5617 *varp = empty_option;
5618 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005619# ifdef FEAT_EVAL
5620 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005621 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005622 set_sid == 0 ? current_SID : set_sid);
5623# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005624 }
5625}
5626
5627/*
5628 * Set global value for string option when it's a local option.
5629 */
5630 static void
5631set_string_option_global(opt_idx, varp)
5632 int opt_idx; /* option index */
5633 char_u **varp; /* pointer to option variable */
5634{
5635 char_u **p, *s;
5636
5637 /* the global value is always allocated */
5638 if (options[opt_idx].var == VAR_WIN)
5639 p = (char_u **)GLOBAL_WO(varp);
5640 else
5641 p = (char_u **)options[opt_idx].var;
5642 if (options[opt_idx].indir != PV_NONE
5643 && p != varp
5644 && (s = vim_strsave(*varp)) != NULL)
5645 {
5646 free_string_option(*p);
5647 *p = s;
5648 }
5649}
5650
5651/*
5652 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005653 *
5654 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005655 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005656 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657set_string_option(opt_idx, value, opt_flags)
5658 int opt_idx;
5659 char_u *value;
5660 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5661{
5662 char_u *s;
5663 char_u **varp;
5664 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005665 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666
5667 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005668 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005669
5670 s = vim_strsave(value);
5671 if (s != NULL)
5672 {
5673 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5674 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005675 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676 ? OPT_GLOBAL : OPT_LOCAL)
5677 : opt_flags);
5678 oldval = *varp;
5679 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005680 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5681 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005682 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005684 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685}
5686
5687/*
5688 * Handle string options that need some action to perform when changed.
5689 * Returns NULL for success, or an error message for an error.
5690 */
5691 static char_u *
5692did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5693 opt_flags)
5694 int opt_idx; /* index in options[] table */
5695 char_u **varp; /* pointer to the option variable */
5696 int new_value_alloced; /* new value was allocated */
5697 char_u *oldval; /* previous value of the option */
5698 char_u *errbuf; /* buffer for errors, or NULL */
5699 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5700{
5701 char_u *errmsg = NULL;
5702 char_u *s, *p;
5703 int did_chartab = FALSE;
5704 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005705 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005706#ifdef FEAT_GUI
5707 /* set when changing an option that only requires a redraw in the GUI */
5708 int redraw_gui_only = FALSE;
5709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710
5711 /* Get the global option to compare with, otherwise we would have to check
5712 * two values for all local options. */
5713 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5714
5715 /* Disallow changing some options from secure mode */
5716 if ((secure
5717#ifdef HAVE_SANDBOX
5718 || sandbox != 0
5719#endif
5720 ) && (options[opt_idx].flags & P_SECURE))
5721 {
5722 errmsg = e_secure;
5723 }
5724
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005725 /* Check for a "normal" file name in some options. Disallow a path
5726 * separator (slash and/or backslash), wildcards and characters that are
5727 * often illegal in a file name. */
5728 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005729 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005730 {
5731 errmsg = e_invarg;
5732 }
5733
Bram Moolenaar071d4272004-06-13 20:20:40 +00005734 /* 'term' */
5735 else if (varp == &T_NAME)
5736 {
5737 if (T_NAME[0] == NUL)
5738 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5739#ifdef FEAT_GUI
5740 if (gui.in_use)
5741 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5742 else if (term_is_gui(T_NAME))
5743 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5744#endif
5745 else if (set_termname(T_NAME) == FAIL)
5746 errmsg = (char_u *)N_("E522: Not found in termcap");
5747 else
5748 /* Screen colors may have changed. */
5749 redraw_later_clear();
5750 }
5751
5752 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005753 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005755 char_u *bkc = p_bkc;
5756 unsigned int *flags = &bkc_flags;
5757
5758 if (opt_flags & OPT_LOCAL)
5759 {
5760 bkc = curbuf->b_p_bkc;
5761 flags = &curbuf->b_bkc_flags;
5762 }
5763
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005764 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5765 /* make the local value empty: use the global value */
5766 *flags = 0;
5767 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005768 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005769 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5770 errmsg = e_invarg;
5771 if ((((int)*flags & BKC_AUTO) != 0)
5772 + (((int)*flags & BKC_YES) != 0)
5773 + (((int)*flags & BKC_NO) != 0) != 1)
5774 {
5775 /* Must have exactly one of "auto", "yes" and "no". */
5776 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5777 errmsg = e_invarg;
5778 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005779 }
5780 }
5781
5782 /* 'backupext' and 'patchmode' */
5783 else if (varp == &p_bex || varp == &p_pm)
5784 {
5785 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5786 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5787 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5788 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005789#ifdef FEAT_LINEBREAK
5790 /* 'breakindentopt' */
5791 else if (varp == &curwin->w_p_briopt)
5792 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005793 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005794 errmsg = e_invarg;
5795 }
5796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005797
5798 /*
5799 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5800 * If the new option is invalid, use old value. 'lisp' option: refill
5801 * chartab[] for '-' char
5802 */
5803 else if ( varp == &p_isi
5804 || varp == &(curbuf->b_p_isk)
5805 || varp == &p_isp
5806 || varp == &p_isf)
5807 {
5808 if (init_chartab() == FAIL)
5809 {
5810 did_chartab = TRUE; /* need to restore it below */
5811 errmsg = e_invarg; /* error in value */
5812 }
5813 }
5814
5815 /* 'helpfile' */
5816 else if (varp == &p_hf)
5817 {
5818 /* May compute new values for $VIM and $VIMRUNTIME */
5819 if (didset_vim)
5820 {
5821 vim_setenv((char_u *)"VIM", (char_u *)"");
5822 didset_vim = FALSE;
5823 }
5824 if (didset_vimruntime)
5825 {
5826 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5827 didset_vimruntime = FALSE;
5828 }
5829 }
5830
Bram Moolenaar1a384422010-07-14 19:53:30 +02005831#ifdef FEAT_SYN_HL
5832 /* 'colorcolumn' */
5833 else if (varp == &curwin->w_p_cc)
5834 errmsg = check_colorcolumn(curwin);
5835#endif
5836
Bram Moolenaar071d4272004-06-13 20:20:40 +00005837#ifdef FEAT_MULTI_LANG
5838 /* 'helplang' */
5839 else if (varp == &p_hlg)
5840 {
5841 /* Check for "", "ab", "ab,cd", etc. */
5842 for (s = p_hlg; *s != NUL; s += 3)
5843 {
5844 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5845 {
5846 errmsg = e_invarg;
5847 break;
5848 }
5849 if (s[2] == NUL)
5850 break;
5851 }
5852 }
5853#endif
5854
5855 /* 'highlight' */
5856 else if (varp == &p_hl)
5857 {
5858 if (highlight_changed() == FAIL)
5859 errmsg = e_invarg; /* invalid flags */
5860 }
5861
5862 /* 'nrformats' */
5863 else if (gvarp == &p_nf)
5864 {
5865 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5866 errmsg = e_invarg;
5867 }
5868
5869#ifdef FEAT_SESSION
5870 /* 'sessionoptions' */
5871 else if (varp == &p_ssop)
5872 {
5873 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5874 errmsg = e_invarg;
5875 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5876 {
5877 /* Don't allow both "sesdir" and "curdir". */
5878 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5879 errmsg = e_invarg;
5880 }
5881 }
5882 /* 'viewoptions' */
5883 else if (varp == &p_vop)
5884 {
5885 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5886 errmsg = e_invarg;
5887 }
5888#endif
5889
5890 /* 'scrollopt' */
5891#ifdef FEAT_SCROLLBIND
5892 else if (varp == &p_sbo)
5893 {
5894 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5895 errmsg = e_invarg;
5896 }
5897#endif
5898
5899 /* 'ambiwidth' */
5900#ifdef FEAT_MBYTE
5901 else if (varp == &p_ambw)
5902 {
5903 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5904 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005905 else if (set_chars_option(&p_lcs) != NULL)
5906 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5907# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5908 else if (set_chars_option(&p_fcs) != NULL)
5909 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5910# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911 }
5912#endif
5913
5914 /* 'background' */
5915 else if (varp == &p_bg)
5916 {
5917 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5918 {
5919#ifdef FEAT_EVAL
5920 int dark = (*p_bg == 'd');
5921#endif
5922
5923 init_highlight(FALSE, FALSE);
5924
5925#ifdef FEAT_EVAL
5926 if (dark != (*p_bg == 'd')
5927 && get_var_value((char_u *)"g:colors_name") != NULL)
5928 {
5929 /* The color scheme must have set 'background' back to another
5930 * value, that's not what we want here. Disable the color
5931 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005932 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005933 free_string_option(p_bg);
5934 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5935 check_string_option(&p_bg);
5936 init_highlight(FALSE, FALSE);
5937 }
5938#endif
5939 }
5940 else
5941 errmsg = e_invarg;
5942 }
5943
5944 /* 'wildmode' */
5945 else if (varp == &p_wim)
5946 {
5947 if (check_opt_wim() == FAIL)
5948 errmsg = e_invarg;
5949 }
5950
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005951#ifdef FEAT_CMDL_COMPL
5952 /* 'wildoptions' */
5953 else if (varp == &p_wop)
5954 {
5955 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5956 errmsg = e_invarg;
5957 }
5958#endif
5959
Bram Moolenaar071d4272004-06-13 20:20:40 +00005960#ifdef FEAT_WAK
5961 /* 'winaltkeys' */
5962 else if (varp == &p_wak)
5963 {
5964 if (*p_wak == NUL
5965 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5966 errmsg = e_invarg;
5967# ifdef FEAT_MENU
5968# ifdef FEAT_GUI_MOTIF
5969 else if (gui.in_use)
5970 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5971# else
5972# ifdef FEAT_GUI_GTK
5973 else if (gui.in_use)
5974 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5975# endif
5976# endif
5977# endif
5978 }
5979#endif
5980
5981#ifdef FEAT_AUTOCMD
5982 /* 'eventignore' */
5983 else if (varp == &p_ei)
5984 {
5985 if (check_ei() == FAIL)
5986 errmsg = e_invarg;
5987 }
5988#endif
5989
5990#ifdef FEAT_MBYTE
5991 /* 'encoding' and 'fileencoding' */
5992 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5993 {
5994 if (gvarp == &p_fenc)
5995 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005996 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005997 errmsg = e_modifiable;
5998 else if (vim_strchr(*varp, ',') != NULL)
5999 /* No comma allowed in 'fileencoding'; catches confusing it
6000 * with 'fileencodings'. */
6001 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006002 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006003 {
6004# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006006 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006007# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006008 /* Add 'fileencoding' to the swap file. */
6009 ml_setflags(curbuf);
6010 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011 }
6012 if (errmsg == NULL)
6013 {
6014 /* canonize the value, so that STRCMP() can be used on it */
6015 p = enc_canonize(*varp);
6016 if (p != NULL)
6017 {
6018 vim_free(*varp);
6019 *varp = p;
6020 }
6021 if (varp == &p_enc)
6022 {
6023 errmsg = mb_init();
6024# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006025 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006026# endif
6027 }
6028 }
6029
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006030# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006031 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6032 {
6033 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6034 if (STRCMP(p_tenc, "utf-8") != 0)
6035 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6036 }
6037# endif
6038
6039 if (errmsg == NULL)
6040 {
6041# ifdef FEAT_KEYMAP
6042 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6043 * (with another encoding). */
6044 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6045 (void)keymap_init();
6046# endif
6047
6048 /* When 'termencoding' is not empty and 'encoding' changes or when
6049 * 'termencoding' changes, need to setup for keyboard input and
6050 * display output conversion. */
6051 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6052 {
6053 convert_setup(&input_conv, p_tenc, p_enc);
6054 convert_setup(&output_conv, p_enc, p_tenc);
6055 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006056
6057# if defined(WIN3264) && defined(FEAT_MBYTE)
6058 /* $HOME may have characters in active code page. */
6059 if (varp == &p_enc)
6060 init_homedir();
6061# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006062 }
6063 }
6064#endif
6065
6066#if defined(FEAT_POSTSCRIPT)
6067 else if (varp == &p_penc)
6068 {
6069 /* Canonize printencoding if VIM standard one */
6070 p = enc_canonize(p_penc);
6071 if (p != NULL)
6072 {
6073 vim_free(p_penc);
6074 p_penc = p;
6075 }
6076 else
6077 {
6078 /* Ensure lower case and '-' for '_' */
6079 for (s = p_penc; *s != NUL; s++)
6080 {
6081 if (*s == '_')
6082 *s = '-';
6083 else
6084 *s = TOLOWER_ASC(*s);
6085 }
6086 }
6087 }
6088#endif
6089
Bram Moolenaar9372a112005-12-06 19:59:18 +00006090#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006091 else if (varp == &p_imak)
6092 {
6093 if (gui.in_use && !im_xim_isvalid_imactivate())
6094 errmsg = e_invarg;
6095 }
6096#endif
6097
6098#ifdef FEAT_KEYMAP
6099 else if (varp == &curbuf->b_p_keymap)
6100 {
6101 /* load or unload key mapping tables */
6102 errmsg = keymap_init();
6103
Bram Moolenaarfab06232009-03-04 03:13:35 +00006104 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006105 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006106 if (*curbuf->b_p_keymap != NUL)
6107 {
6108 /* Installed a new keymap, switch on using it. */
6109 curbuf->b_p_iminsert = B_IMODE_LMAP;
6110 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6111 curbuf->b_p_imsearch = B_IMODE_LMAP;
6112 }
6113 else
6114 {
6115 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6116 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6117 curbuf->b_p_iminsert = B_IMODE_NONE;
6118 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6119 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6120 }
6121 if ((opt_flags & OPT_LOCAL) == 0)
6122 {
6123 set_iminsert_global();
6124 set_imsearch_global();
6125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006126# ifdef FEAT_WINDOWS
6127 status_redraw_curbuf();
6128# endif
6129 }
6130 }
6131#endif
6132
6133 /* 'fileformat' */
6134 else if (gvarp == &p_ff)
6135 {
6136 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6137 errmsg = e_modifiable;
6138 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6139 errmsg = e_invarg;
6140 else
6141 {
6142 /* may also change 'textmode' */
6143 if (get_fileformat(curbuf) == EOL_DOS)
6144 curbuf->b_p_tx = TRUE;
6145 else
6146 curbuf->b_p_tx = FALSE;
6147#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006148 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006149#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006150 /* update flag in swap file */
6151 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006152 /* Redraw needed when switching to/from "mac": a CR in the text
6153 * will be displayed differently. */
6154 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6155 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006156 }
6157 }
6158
6159 /* 'fileformats' */
6160 else if (varp == &p_ffs)
6161 {
6162 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6163 errmsg = e_invarg;
6164 else
6165 {
6166 /* also change 'textauto' */
6167 if (*p_ffs == NUL)
6168 p_ta = FALSE;
6169 else
6170 p_ta = TRUE;
6171 }
6172 }
6173
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006174#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006175 /* 'cryptkey' */
6176 else if (gvarp == &p_key)
6177 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006178# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006179 /* Make sure the ":set" command doesn't show the new value in the
6180 * history. */
6181 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006182# endif
6183 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6184 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006185 ml_set_crypt_key(curbuf, oldval,
6186 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006187 }
6188
6189 else if (gvarp == &p_cm)
6190 {
6191 if (opt_flags & OPT_LOCAL)
6192 p = curbuf->b_p_cm;
6193 else
6194 p = p_cm;
6195 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6196 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006197 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006198 errmsg = e_invarg;
6199 else
6200 {
6201 /* When setting the global value to empty, make it "zip". */
6202 if (*p_cm == NUL)
6203 {
6204 if (new_value_alloced)
6205 free_string_option(p_cm);
6206 p_cm = vim_strsave((char_u *)"zip");
6207 new_value_alloced = TRUE;
6208 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006209 /* When using ":set cm=name" the local value is going to be empty.
6210 * Do that here, otherwise the crypt functions will still use the
6211 * local value. */
6212 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6213 {
6214 free_string_option(curbuf->b_p_cm);
6215 curbuf->b_p_cm = empty_option;
6216 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006217
6218 /* Need to update the swapfile when the effective method changed.
6219 * Set "s" to the effective old value, "p" to the effective new
6220 * method and compare. */
6221 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6222 s = p_cm; /* was previously using the global value */
6223 else
6224 s = oldval;
6225 if (*curbuf->b_p_cm == NUL)
6226 p = p_cm; /* is now using the global value */
6227 else
6228 p = curbuf->b_p_cm;
6229 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006230 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006231
6232 /* If the global value changes need to update the swapfile for all
6233 * buffers using that value. */
6234 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6235 {
6236 buf_T *buf;
6237
6238 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6239 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006240 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006241 }
6242 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006243 }
6244#endif
6245
6246 /* 'matchpairs' */
6247 else if (gvarp == &p_mps)
6248 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006249#ifdef FEAT_MBYTE
6250 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006252 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006253 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006254 int x2 = -1;
6255 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006256
6257 if (*p != NUL)
6258 p += mb_ptr2len(p);
6259 if (*p != NUL)
6260 x2 = *p++;
6261 if (*p != NUL)
6262 {
6263 x3 = mb_ptr2char(p);
6264 p += mb_ptr2len(p);
6265 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006266 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006267 {
6268 errmsg = e_invarg;
6269 break;
6270 }
6271 if (*p == NUL)
6272 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006273 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006274 }
6275 else
6276#endif
6277 {
6278 /* Check for "x:y,x:y" */
6279 for (p = *varp; *p != NUL; p += 4)
6280 {
6281 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6282 {
6283 errmsg = e_invarg;
6284 break;
6285 }
6286 if (p[3] == NUL)
6287 break;
6288 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006289 }
6290 }
6291
6292#ifdef FEAT_COMMENTS
6293 /* 'comments' */
6294 else if (gvarp == &p_com)
6295 {
6296 for (s = *varp; *s; )
6297 {
6298 while (*s && *s != ':')
6299 {
6300 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6301 && !VIM_ISDIGIT(*s) && *s != '-')
6302 {
6303 errmsg = illegal_char(errbuf, *s);
6304 break;
6305 }
6306 ++s;
6307 }
6308 if (*s++ == NUL)
6309 errmsg = (char_u *)N_("E524: Missing colon");
6310 else if (*s == ',' || *s == NUL)
6311 errmsg = (char_u *)N_("E525: Zero length string");
6312 if (errmsg != NULL)
6313 break;
6314 while (*s && *s != ',')
6315 {
6316 if (*s == '\\' && s[1] != NUL)
6317 ++s;
6318 ++s;
6319 }
6320 s = skip_to_option_part(s);
6321 }
6322 }
6323#endif
6324
6325 /* 'listchars' */
6326 else if (varp == &p_lcs)
6327 {
6328 errmsg = set_chars_option(varp);
6329 }
6330
6331#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6332 /* 'fillchars' */
6333 else if (varp == &p_fcs)
6334 {
6335 errmsg = set_chars_option(varp);
6336 }
6337#endif
6338
6339#ifdef FEAT_CMDWIN
6340 /* 'cedit' */
6341 else if (varp == &p_cedit)
6342 {
6343 errmsg = check_cedit();
6344 }
6345#endif
6346
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006347 /* 'verbosefile' */
6348 else if (varp == &p_vfile)
6349 {
6350 verbose_stop();
6351 if (*p_vfile != NUL && verbose_open() == FAIL)
6352 errmsg = e_invarg;
6353 }
6354
Bram Moolenaar071d4272004-06-13 20:20:40 +00006355#ifdef FEAT_VIMINFO
6356 /* 'viminfo' */
6357 else if (varp == &p_viminfo)
6358 {
6359 for (s = p_viminfo; *s;)
6360 {
6361 /* Check it's a valid character */
6362 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6363 {
6364 errmsg = illegal_char(errbuf, *s);
6365 break;
6366 }
6367 if (*s == 'n') /* name is always last one */
6368 {
6369 break;
6370 }
6371 else if (*s == 'r') /* skip until next ',' */
6372 {
6373 while (*++s && *s != ',')
6374 ;
6375 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006376 else if (*s == '%')
6377 {
6378 /* optional number */
6379 while (vim_isdigit(*++s))
6380 ;
6381 }
6382 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 ++s; /* no extra chars */
6384 else /* must have a number */
6385 {
6386 while (vim_isdigit(*++s))
6387 ;
6388
6389 if (!VIM_ISDIGIT(*(s - 1)))
6390 {
6391 if (errbuf != NULL)
6392 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006393 sprintf((char *)errbuf,
6394 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006395 transchar_byte(*(s - 1)));
6396 errmsg = errbuf;
6397 }
6398 else
6399 errmsg = (char_u *)"";
6400 break;
6401 }
6402 }
6403 if (*s == ',')
6404 ++s;
6405 else if (*s)
6406 {
6407 if (errbuf != NULL)
6408 errmsg = (char_u *)N_("E527: Missing comma");
6409 else
6410 errmsg = (char_u *)"";
6411 break;
6412 }
6413 }
6414 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6415 errmsg = (char_u *)N_("E528: Must specify a ' value");
6416 }
6417#endif /* FEAT_VIMINFO */
6418
6419 /* terminal options */
6420 else if (istermoption(&options[opt_idx]) && full_screen)
6421 {
6422 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6423 if (varp == &T_CCO)
6424 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006425 int colors = atoi((char *)T_CCO);
6426
6427 /* Only reinitialize colors if t_Co value has really changed to
6428 * avoid expensive reload of colorscheme if t_Co is set to the
6429 * same value multiple times. */
6430 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006431 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006432 t_colors = colors;
6433 if (t_colors <= 1)
6434 {
6435 if (new_value_alloced)
6436 vim_free(T_CCO);
6437 T_CCO = empty_option;
6438 }
6439 /* We now have a different color setup, initialize it again. */
6440 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006441 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006442 }
6443 ttest(FALSE);
6444 if (varp == &T_ME)
6445 {
6446 out_str(T_ME);
6447 redraw_later(CLEAR);
6448#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6449 /* Since t_me has been set, this probably means that the user
6450 * wants to use this as default colors. Need to reset default
6451 * background/foreground colors. */
6452 mch_set_normal_colors();
6453#endif
6454 }
6455 }
6456
6457#ifdef FEAT_LINEBREAK
6458 /* 'showbreak' */
6459 else if (varp == &p_sbr)
6460 {
6461 for (s = p_sbr; *s; )
6462 {
6463 if (ptr2cells(s) != 1)
6464 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006465 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006466 }
6467 }
6468#endif
6469
6470#ifdef FEAT_GUI
6471 /* 'guifont' */
6472 else if (varp == &p_guifont)
6473 {
6474 if (gui.in_use)
6475 {
6476 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006477# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006478 /*
6479 * Put up a font dialog and let the user select a new value.
6480 * If this is cancelled go back to the old value but don't
6481 * give an error message.
6482 */
6483 if (STRCMP(p, "*") == 0)
6484 {
6485 p = gui_mch_font_dialog(oldval);
6486
6487 if (new_value_alloced)
6488 free_string_option(p_guifont);
6489
6490 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6491 new_value_alloced = TRUE;
6492 }
6493# endif
6494 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6495 {
6496# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6497 if (STRCMP(p_guifont, "*") == 0)
6498 {
6499 /* Dialog was cancelled: Keep the old value without giving
6500 * an error message. */
6501 if (new_value_alloced)
6502 free_string_option(p_guifont);
6503 p_guifont = vim_strsave(oldval);
6504 new_value_alloced = TRUE;
6505 }
6506 else
6507# endif
6508 errmsg = (char_u *)N_("E596: Invalid font(s)");
6509 }
6510 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006511 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006512 }
6513# ifdef FEAT_XFONTSET
6514 else if (varp == &p_guifontset)
6515 {
6516 if (STRCMP(p_guifontset, "*") == 0)
6517 errmsg = (char_u *)N_("E597: can't select fontset");
6518 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6519 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006520 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006521 }
6522# endif
6523# ifdef FEAT_MBYTE
6524 else if (varp == &p_guifontwide)
6525 {
6526 if (STRCMP(p_guifontwide, "*") == 0)
6527 errmsg = (char_u *)N_("E533: can't select wide font");
6528 else if (gui_get_wide_font() == FAIL)
6529 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006530 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006531 }
6532# endif
6533#endif
6534
6535#ifdef CURSOR_SHAPE
6536 /* 'guicursor' */
6537 else if (varp == &p_guicursor)
6538 errmsg = parse_shape_opt(SHAPE_CURSOR);
6539#endif
6540
6541#ifdef FEAT_MOUSESHAPE
6542 /* 'mouseshape' */
6543 else if (varp == &p_mouseshape)
6544 {
6545 errmsg = parse_shape_opt(SHAPE_MOUSE);
6546 update_mouseshape(-1);
6547 }
6548#endif
6549
6550#ifdef FEAT_PRINTER
6551 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006552 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006553# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006554 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006555 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006556# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557#endif
6558
6559#ifdef FEAT_LANGMAP
6560 /* 'langmap' */
6561 else if (varp == &p_langmap)
6562 langmap_set();
6563#endif
6564
6565#ifdef FEAT_LINEBREAK
6566 /* 'breakat' */
6567 else if (varp == &p_breakat)
6568 fill_breakat_flags();
6569#endif
6570
6571#ifdef FEAT_TITLE
6572 /* 'titlestring' and 'iconstring' */
6573 else if (varp == &p_titlestring || varp == &p_iconstring)
6574 {
6575# ifdef FEAT_STL_OPT
6576 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6577
6578 /* NULL => statusline syntax */
6579 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6580 stl_syntax |= flagval;
6581 else
6582 stl_syntax &= ~flagval;
6583# endif
6584 did_set_title(varp == &p_iconstring);
6585
6586 }
6587#endif
6588
6589#ifdef FEAT_GUI
6590 /* 'guioptions' */
6591 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006592 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006594 redraw_gui_only = TRUE;
6595 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006596#endif
6597
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006598#if defined(FEAT_GUI_TABLINE)
6599 /* 'guitablabel' */
6600 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006601 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006602 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006603 redraw_gui_only = TRUE;
6604 }
6605 /* 'guitabtooltip' */
6606 else if (varp == &p_gtt)
6607 {
6608 redraw_gui_only = TRUE;
6609 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006610#endif
6611
Bram Moolenaar071d4272004-06-13 20:20:40 +00006612#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6613 /* 'ttymouse' */
6614 else if (varp == &p_ttym)
6615 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006616 /* Switch the mouse off before changing the escape sequences used for
6617 * that. */
6618 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006619 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6620 errmsg = e_invarg;
6621 else
6622 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006623 if (termcap_active)
6624 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006625 }
6626#endif
6627
Bram Moolenaar071d4272004-06-13 20:20:40 +00006628 /* 'selection' */
6629 else if (varp == &p_sel)
6630 {
6631 if (*p_sel == NUL
6632 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6633 errmsg = e_invarg;
6634 }
6635
6636 /* 'selectmode' */
6637 else if (varp == &p_slm)
6638 {
6639 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6640 errmsg = e_invarg;
6641 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006642
6643#ifdef FEAT_BROWSE
6644 /* 'browsedir' */
6645 else if (varp == &p_bsdir)
6646 {
6647 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6648 && !mch_isdir(p_bsdir))
6649 errmsg = e_invarg;
6650 }
6651#endif
6652
Bram Moolenaar071d4272004-06-13 20:20:40 +00006653 /* 'keymodel' */
6654 else if (varp == &p_km)
6655 {
6656 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6657 errmsg = e_invarg;
6658 else
6659 {
6660 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6661 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6662 }
6663 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006664
6665 /* 'mousemodel' */
6666 else if (varp == &p_mousem)
6667 {
6668 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6669 errmsg = e_invarg;
6670#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6671 else if (*p_mousem != *oldval)
6672 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6673 * to create or delete the popup menus. */
6674 gui_motif_update_mousemodel(root_menu);
6675#endif
6676 }
6677
6678 /* 'switchbuf' */
6679 else if (varp == &p_swb)
6680 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006681 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006682 errmsg = e_invarg;
6683 }
6684
6685 /* 'debug' */
6686 else if (varp == &p_debug)
6687 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006688 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006689 errmsg = e_invarg;
6690 }
6691
6692 /* 'display' */
6693 else if (varp == &p_dy)
6694 {
6695 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6696 errmsg = e_invarg;
6697 else
6698 (void)init_chartab();
6699
6700 }
6701
6702#ifdef FEAT_VERTSPLIT
6703 /* 'eadirection' */
6704 else if (varp == &p_ead)
6705 {
6706 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6707 errmsg = e_invarg;
6708 }
6709#endif
6710
6711#ifdef FEAT_CLIPBOARD
6712 /* 'clipboard' */
6713 else if (varp == &p_cb)
6714 errmsg = check_clipboard_option();
6715#endif
6716
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006717#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006718 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6719 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006720 else if (varp == &(curwin->w_s->b_p_spl)
6721 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006722 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006723 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006724 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006725
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006726 if (varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006727 {
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006728 l = (int)STRLEN(curwin->w_s->b_p_spf);
6729 if (l > 0 && (l < 4 || STRCMP(curwin->w_s->b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006730 ".add") != 0))
6731 errmsg = e_invarg;
6732 }
6733
6734 if (errmsg == NULL)
6735 {
6736 FOR_ALL_WINDOWS(wp)
6737 if (wp->w_buffer == curbuf && wp->w_p_spell)
6738 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006739 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006740# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006741 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006742# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006743 }
6744 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006745 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006746 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006747 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006748 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006749 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006750 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006751 /* 'spellsuggest' */
6752 else if (varp == &p_sps)
6753 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006754 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006755 errmsg = e_invarg;
6756 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006757 /* 'mkspellmem' */
6758 else if (varp == &p_msm)
6759 {
6760 if (spell_check_msm() != OK)
6761 errmsg = e_invarg;
6762 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006763#endif
6764
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765#ifdef FEAT_QUICKFIX
6766 /* When 'bufhidden' is set, check for valid value. */
6767 else if (gvarp == &p_bh)
6768 {
6769 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6770 errmsg = e_invarg;
6771 }
6772
6773 /* When 'buftype' is set, check for valid value. */
6774 else if (gvarp == &p_bt)
6775 {
6776 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6777 errmsg = e_invarg;
6778 else
6779 {
6780# ifdef FEAT_WINDOWS
6781 if (curwin->w_status_height)
6782 {
6783 curwin->w_redr_status = TRUE;
6784 redraw_later(VALID);
6785 }
6786# endif
6787 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006788# ifdef FEAT_TITLE
6789 redraw_titles();
6790# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006791 }
6792 }
6793#endif
6794
6795#ifdef FEAT_STL_OPT
6796 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006797 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006798 {
6799 int wid;
6800
6801 if (varp == &p_ruf) /* reset ru_wid first */
6802 ru_wid = 0;
6803 s = *varp;
6804 if (varp == &p_ruf && *s == '%')
6805 {
6806 /* set ru_wid if 'ruf' starts with "%99(" */
6807 if (*++s == '-') /* ignore a '-' */
6808 s++;
6809 wid = getdigits(&s);
6810 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6811 ru_wid = wid;
6812 else
6813 errmsg = check_stl_option(p_ruf);
6814 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006815 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006816 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006817 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006818 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006819 comp_col();
6820 }
6821#endif
6822
6823#ifdef FEAT_INS_EXPAND
6824 /* check if it is a valid value for 'complete' -- Acevedo */
6825 else if (gvarp == &p_cpt)
6826 {
6827 for (s = *varp; *s;)
6828 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006829 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006830 s++;
6831 if (!*s)
6832 break;
6833 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6834 {
6835 errmsg = illegal_char(errbuf, *s);
6836 break;
6837 }
6838 if (*++s != NUL && *s != ',' && *s != ' ')
6839 {
6840 if (s[-1] == 'k' || s[-1] == 's')
6841 {
6842 /* skip optional filename after 'k' and 's' */
6843 while (*s && *s != ',' && *s != ' ')
6844 {
6845 if (*s == '\\')
6846 ++s;
6847 ++s;
6848 }
6849 }
6850 else
6851 {
6852 if (errbuf != NULL)
6853 {
6854 sprintf((char *)errbuf,
6855 _("E535: Illegal character after <%c>"),
6856 *--s);
6857 errmsg = errbuf;
6858 }
6859 else
6860 errmsg = (char_u *)"";
6861 break;
6862 }
6863 }
6864 }
6865 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006866
6867 /* 'completeopt' */
6868 else if (varp == &p_cot)
6869 {
6870 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6871 errmsg = e_invarg;
6872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873#endif /* FEAT_INS_EXPAND */
6874
6875
6876#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6877 else if (varp == &p_toolbar)
6878 {
6879 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6880 &toolbar_flags, TRUE) != OK)
6881 errmsg = e_invarg;
6882 else
6883 {
6884 out_flush();
6885 gui_mch_show_toolbar((toolbar_flags &
6886 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6887 }
6888 }
6889#endif
6890
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006891#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006892 /* 'toolbariconsize': GTK+ 2 only */
6893 else if (varp == &p_tbis)
6894 {
6895 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6896 errmsg = e_invarg;
6897 else
6898 {
6899 out_flush();
6900 gui_mch_show_toolbar((toolbar_flags &
6901 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6902 }
6903 }
6904#endif
6905
6906 /* 'pastetoggle': translate key codes like in a mapping */
6907 else if (varp == &p_pt)
6908 {
6909 if (*p_pt)
6910 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006911 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006912 if (p != NULL)
6913 {
6914 if (new_value_alloced)
6915 free_string_option(p_pt);
6916 p_pt = p;
6917 new_value_alloced = TRUE;
6918 }
6919 }
6920 }
6921
6922 /* 'backspace' */
6923 else if (varp == &p_bs)
6924 {
6925 if (VIM_ISDIGIT(*p_bs))
6926 {
6927 if (*p_bs >'2' || p_bs[1] != NUL)
6928 errmsg = e_invarg;
6929 }
6930 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6931 errmsg = e_invarg;
6932 }
6933
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006934#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006935 /* 'casemap' */
6936 else if (varp == &p_cmp)
6937 {
6938 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6939 errmsg = e_invarg;
6940 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006941#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006942
6943#ifdef FEAT_DIFF
6944 /* 'diffopt' */
6945 else if (varp == &p_dip)
6946 {
6947 if (diffopt_changed() == FAIL)
6948 errmsg = e_invarg;
6949 }
6950#endif
6951
6952#ifdef FEAT_FOLDING
6953 /* 'foldmethod' */
6954 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6955 {
6956 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6957 || *curwin->w_p_fdm == NUL)
6958 errmsg = e_invarg;
6959 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006960 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006962 if (foldmethodIsDiff(curwin))
6963 newFoldLevel();
6964 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965 }
6966# ifdef FEAT_EVAL
6967 /* 'foldexpr' */
6968 else if (varp == &curwin->w_p_fde)
6969 {
6970 if (foldmethodIsExpr(curwin))
6971 foldUpdateAll(curwin);
6972 }
6973# endif
6974 /* 'foldmarker' */
6975 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6976 {
6977 p = vim_strchr(*varp, ',');
6978 if (p == NULL)
6979 errmsg = (char_u *)N_("E536: comma required");
6980 else if (p == *varp || p[1] == NUL)
6981 errmsg = e_invarg;
6982 else if (foldmethodIsMarker(curwin))
6983 foldUpdateAll(curwin);
6984 }
6985 /* 'commentstring' */
6986 else if (gvarp == &p_cms)
6987 {
6988 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6989 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6990 }
6991 /* 'foldopen' */
6992 else if (varp == &p_fdo)
6993 {
6994 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6995 errmsg = e_invarg;
6996 }
6997 /* 'foldclose' */
6998 else if (varp == &p_fcl)
6999 {
7000 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7001 errmsg = e_invarg;
7002 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007003 /* 'foldignore' */
7004 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7005 {
7006 if (foldmethodIsIndent(curwin))
7007 foldUpdateAll(curwin);
7008 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007009#endif
7010
7011#ifdef FEAT_VIRTUALEDIT
7012 /* 'virtualedit' */
7013 else if (varp == &p_ve)
7014 {
7015 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7016 errmsg = e_invarg;
7017 else if (STRCMP(p_ve, oldval) != 0)
7018 {
7019 /* Recompute cursor position in case the new 've' setting
7020 * changes something. */
7021 validate_virtcol();
7022 coladvance(curwin->w_virtcol);
7023 }
7024 }
7025#endif
7026
7027#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7028 else if (varp == &p_csqf)
7029 {
7030 if (p_csqf != NULL)
7031 {
7032 p = p_csqf;
7033 while (*p != NUL)
7034 {
7035 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7036 || p[1] == NUL
7037 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7038 || (p[2] != NUL && p[2] != ','))
7039 {
7040 errmsg = e_invarg;
7041 break;
7042 }
7043 else if (p[2] == NUL)
7044 break;
7045 else
7046 p += 3;
7047 }
7048 }
7049 }
7050#endif
7051
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007052#ifdef FEAT_CINDENT
7053 /* 'cinoptions' */
7054 else if (gvarp == &p_cino)
7055 {
7056 /* TODO: recognize errors */
7057 parse_cino(curbuf);
7058 }
7059#endif
7060
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007061#if defined(FEAT_RENDER_OPTIONS)
7062 else if (varp == &p_rop && gui.in_use)
7063 {
7064 if (!gui_mch_set_rendering_options(p_rop))
7065 errmsg = e_invarg;
7066 }
7067#endif
7068
Bram Moolenaar071d4272004-06-13 20:20:40 +00007069 /* Options that are a list of flags. */
7070 else
7071 {
7072 p = NULL;
7073 if (varp == &p_ww)
7074 p = (char_u *)WW_ALL;
7075 if (varp == &p_shm)
7076 p = (char_u *)SHM_ALL;
7077 else if (varp == &(p_cpo))
7078 p = (char_u *)CPO_ALL;
7079 else if (varp == &(curbuf->b_p_fo))
7080 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007081#ifdef FEAT_CONCEAL
7082 else if (varp == &curwin->w_p_cocu)
7083 p = (char_u *)COCU_ALL;
7084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085 else if (varp == &p_mouse)
7086 {
7087#ifdef FEAT_MOUSE
7088 p = (char_u *)MOUSE_ALL;
7089#else
7090 if (*p_mouse != NUL)
7091 errmsg = (char_u *)N_("E538: No mouse support");
7092#endif
7093 }
7094#if defined(FEAT_GUI)
7095 else if (varp == &p_go)
7096 p = (char_u *)GO_ALL;
7097#endif
7098 if (p != NULL)
7099 {
7100 for (s = *varp; *s; ++s)
7101 if (vim_strchr(p, *s) == NULL)
7102 {
7103 errmsg = illegal_char(errbuf, *s);
7104 break;
7105 }
7106 }
7107 }
7108
7109 /*
7110 * If error detected, restore the previous value.
7111 */
7112 if (errmsg != NULL)
7113 {
7114 if (new_value_alloced)
7115 free_string_option(*varp);
7116 *varp = oldval;
7117 /*
7118 * When resetting some values, need to act on it.
7119 */
7120 if (did_chartab)
7121 (void)init_chartab();
7122 if (varp == &p_hl)
7123 (void)highlight_changed();
7124 }
7125 else
7126 {
7127#ifdef FEAT_EVAL
7128 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007129 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007130#endif
7131 /*
7132 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007133 * Use "free_oldval", because recursiveness may change the flags under
7134 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007135 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007136 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007137 free_string_option(oldval);
7138 if (new_value_alloced)
7139 options[opt_idx].flags |= P_ALLOCED;
7140 else
7141 options[opt_idx].flags &= ~P_ALLOCED;
7142
7143 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007144 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007145 {
7146 /* global option with local value set to use global value; free
7147 * the local value and make it empty */
7148 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7149 free_string_option(*(char_u **)p);
7150 *(char_u **)p = empty_option;
7151 }
7152
7153 /* May set global value for local option. */
7154 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7155 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007156
7157#ifdef FEAT_AUTOCMD
7158 /*
7159 * Trigger the autocommand only after setting the flags.
7160 */
7161# ifdef FEAT_SYN_HL
7162 /* When 'syntax' is set, load the syntax of that name */
7163 if (varp == &(curbuf->b_p_syn))
7164 {
7165 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7166 curbuf->b_fname, TRUE, curbuf);
7167 }
7168# endif
7169 else if (varp == &(curbuf->b_p_ft))
7170 {
7171 /* 'filetype' is set, trigger the FileType autocommand */
7172 did_filetype = TRUE;
7173 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7174 curbuf->b_fname, TRUE, curbuf);
7175 }
7176#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007177#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007178 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007179 {
7180 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007181 char_u *q = curwin->w_s->b_p_spl;
7182
7183 /* Skip the first name if it is "cjk". */
7184 if (STRNCMP(q, "cjk,", 4) == 0)
7185 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007186
7187 /*
7188 * Source the spell/LANG.vim in 'runtimepath'.
7189 * They could set 'spellcapcheck' depending on the language.
7190 * Use the first name in 'spelllang' up to '_region' or
7191 * '.encoding'.
7192 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007193 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007194 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7195 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007196 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007197 source_runtime(fname, TRUE);
7198 }
7199#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007200 }
7201
7202#ifdef FEAT_MOUSE
7203 if (varp == &p_mouse)
7204 {
7205# ifdef FEAT_MOUSE_TTY
7206 if (*p_mouse == NUL)
7207 mch_setmouse(FALSE); /* switch mouse off */
7208 else
7209# endif
7210 setmouse(); /* in case 'mouse' changed */
7211 }
7212#endif
7213
Bram Moolenaar913077c2012-03-28 19:59:04 +02007214 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007215 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007216 curwin->w_set_curswant = TRUE;
7217
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007218#ifdef FEAT_GUI
7219 /* check redraw when it's not a GUI option or the GUI is active. */
7220 if (!redraw_gui_only || gui.in_use)
7221#endif
7222 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007223
7224 return errmsg;
7225}
7226
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007227#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007228/*
7229 * Simple int comparison function for use with qsort()
7230 */
7231 static int
7232int_cmp(a, b)
7233 const void *a;
7234 const void *b;
7235{
7236 return *(const int *)a - *(const int *)b;
7237}
7238
7239/*
7240 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7241 * Returns error message, NULL if it's OK.
7242 */
7243 char_u *
7244check_colorcolumn(wp)
7245 win_T *wp;
7246{
7247 char_u *s;
7248 int col;
7249 int count = 0;
7250 int color_cols[256];
7251 int i;
7252 int j = 0;
7253
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007254 if (wp->w_buffer == NULL)
7255 return NULL; /* buffer was closed */
7256
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007257 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007258 {
7259 if (*s == '-' || *s == '+')
7260 {
7261 /* -N and +N: add to 'textwidth' */
7262 col = (*s == '-') ? -1 : 1;
7263 ++s;
7264 if (!VIM_ISDIGIT(*s))
7265 return e_invarg;
7266 col = col * getdigits(&s);
7267 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007268 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007269 col += wp->w_buffer->b_p_tw;
7270 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007271 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007272 }
7273 else if (VIM_ISDIGIT(*s))
7274 col = getdigits(&s);
7275 else
7276 return e_invarg;
7277 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007278skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007279 if (*s == NUL)
7280 break;
7281 if (*s != ',')
7282 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007283 if (*++s == NUL)
7284 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007285 }
7286
7287 vim_free(wp->w_p_cc_cols);
7288 if (count == 0)
7289 wp->w_p_cc_cols = NULL;
7290 else
7291 {
7292 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7293 if (wp->w_p_cc_cols != NULL)
7294 {
7295 /* sort the columns for faster usage on screen redraw inside
7296 * win_line() */
7297 qsort(color_cols, count, sizeof(int), int_cmp);
7298
7299 for (i = 0; i < count; ++i)
7300 /* skip duplicates */
7301 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7302 wp->w_p_cc_cols[j++] = color_cols[i];
7303 wp->w_p_cc_cols[j] = -1; /* end marker */
7304 }
7305 }
7306
7307 return NULL; /* no error */
7308}
7309#endif
7310
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311/*
7312 * Handle setting 'listchars' or 'fillchars'.
7313 * Returns error message, NULL if it's OK.
7314 */
7315 static char_u *
7316set_chars_option(varp)
7317 char_u **varp;
7318{
7319 int round, i, len, entries;
7320 char_u *p, *s;
7321 int c1, c2 = 0;
7322 struct charstab
7323 {
7324 int *cp;
7325 char *name;
7326 };
7327#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7328 static struct charstab filltab[] =
7329 {
7330 {&fill_stl, "stl"},
7331 {&fill_stlnc, "stlnc"},
7332 {&fill_vert, "vert"},
7333 {&fill_fold, "fold"},
7334 {&fill_diff, "diff"},
7335 };
7336#endif
7337 static struct charstab lcstab[] =
7338 {
7339 {&lcs_eol, "eol"},
7340 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007341 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007342 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007343 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007344 {&lcs_tab2, "tab"},
7345 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007346#ifdef FEAT_CONCEAL
7347 {&lcs_conceal, "conceal"},
7348#else
7349 {NULL, "conceal"},
7350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007351 };
7352 struct charstab *tab;
7353
7354#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7355 if (varp == &p_lcs)
7356#endif
7357 {
7358 tab = lcstab;
7359 entries = sizeof(lcstab) / sizeof(struct charstab);
7360 }
7361#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7362 else
7363 {
7364 tab = filltab;
7365 entries = sizeof(filltab) / sizeof(struct charstab);
7366 }
7367#endif
7368
7369 /* first round: check for valid value, second round: assign values */
7370 for (round = 0; round <= 1; ++round)
7371 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007372 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007373 {
7374 /* After checking that the value is valid: set defaults: space for
7375 * 'fillchars', NUL for 'listchars' */
7376 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007377 if (tab[i].cp != NULL)
7378 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007379 if (varp == &p_lcs)
7380 lcs_tab1 = NUL;
7381#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7382 else
7383 fill_diff = '-';
7384#endif
7385 }
7386 p = *varp;
7387 while (*p)
7388 {
7389 for (i = 0; i < entries; ++i)
7390 {
7391 len = (int)STRLEN(tab[i].name);
7392 if (STRNCMP(p, tab[i].name, len) == 0
7393 && p[len] == ':'
7394 && p[len + 1] != NUL)
7395 {
7396 s = p + len + 1;
7397#ifdef FEAT_MBYTE
7398 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007399 if (mb_char2cells(c1) > 1)
7400 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007401#else
7402 c1 = *s++;
7403#endif
7404 if (tab[i].cp == &lcs_tab2)
7405 {
7406 if (*s == NUL)
7407 continue;
7408#ifdef FEAT_MBYTE
7409 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007410 if (mb_char2cells(c2) > 1)
7411 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007412#else
7413 c2 = *s++;
7414#endif
7415 }
7416 if (*s == ',' || *s == NUL)
7417 {
7418 if (round)
7419 {
7420 if (tab[i].cp == &lcs_tab2)
7421 {
7422 lcs_tab1 = c1;
7423 lcs_tab2 = c2;
7424 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007425 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007426 *(tab[i].cp) = c1;
7427
7428 }
7429 p = s;
7430 break;
7431 }
7432 }
7433 }
7434
7435 if (i == entries)
7436 return e_invarg;
7437 if (*p == ',')
7438 ++p;
7439 }
7440 }
7441
7442 return NULL; /* no error */
7443}
7444
7445#ifdef FEAT_STL_OPT
7446/*
7447 * Check validity of options with the 'statusline' format.
7448 * Return error message or NULL.
7449 */
7450 char_u *
7451check_stl_option(s)
7452 char_u *s;
7453{
7454 int itemcnt = 0;
7455 int groupdepth = 0;
7456 static char_u errbuf[80];
7457
7458 while (*s && itemcnt < STL_MAX_ITEM)
7459 {
7460 /* Check for valid keys after % sequences */
7461 while (*s && *s != '%')
7462 s++;
7463 if (!*s)
7464 break;
7465 s++;
7466 if (*s != '%' && *s != ')')
7467 ++itemcnt;
7468 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7469 {
7470 s++;
7471 continue;
7472 }
7473 if (*s == ')')
7474 {
7475 s++;
7476 if (--groupdepth < 0)
7477 break;
7478 continue;
7479 }
7480 if (*s == '-')
7481 s++;
7482 while (VIM_ISDIGIT(*s))
7483 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007484 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007485 continue;
7486 if (*s == '.')
7487 {
7488 s++;
7489 while (*s && VIM_ISDIGIT(*s))
7490 s++;
7491 }
7492 if (*s == '(')
7493 {
7494 groupdepth++;
7495 continue;
7496 }
7497 if (vim_strchr(STL_ALL, *s) == NULL)
7498 {
7499 return illegal_char(errbuf, *s);
7500 }
7501 if (*s == '{')
7502 {
7503 s++;
7504 while (*s != '}' && *s)
7505 s++;
7506 if (*s != '}')
7507 return (char_u *)N_("E540: Unclosed expression sequence");
7508 }
7509 }
7510 if (itemcnt >= STL_MAX_ITEM)
7511 return (char_u *)N_("E541: too many items");
7512 if (groupdepth != 0)
7513 return (char_u *)N_("E542: unbalanced groups");
7514 return NULL;
7515}
7516#endif
7517
7518#ifdef FEAT_CLIPBOARD
7519/*
7520 * Extract the items in the 'clipboard' option and set global values.
7521 */
7522 static char_u *
7523check_clipboard_option()
7524{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007525 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007526 int new_autoselect_star = FALSE;
7527 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007528 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007529 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007530 regprog_T *new_exclude_prog = NULL;
7531 char_u *errmsg = NULL;
7532 char_u *p;
7533
7534 for (p = p_cb; *p != NUL; )
7535 {
7536 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7537 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007538 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007539 p += 7;
7540 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007541 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007542 && (p[11] == ',' || p[11] == NUL))
7543 {
7544 new_unnamed |= CLIP_UNNAMED_PLUS;
7545 p += 11;
7546 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007547 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007548 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007549 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007550 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007551 p += 10;
7552 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007553 else if (STRNCMP(p, "autoselectplus", 14) == 0
7554 && (p[14] == ',' || p[14] == NUL))
7555 {
7556 new_autoselect_plus = TRUE;
7557 p += 14;
7558 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007559 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007560 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007561 {
7562 new_autoselectml = TRUE;
7563 p += 12;
7564 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007565 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7566 {
7567 new_html = TRUE;
7568 p += 4;
7569 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007570 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7571 {
7572 p += 8;
7573 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7574 if (new_exclude_prog == NULL)
7575 errmsg = e_invarg;
7576 break;
7577 }
7578 else
7579 {
7580 errmsg = e_invarg;
7581 break;
7582 }
7583 if (*p == ',')
7584 ++p;
7585 }
7586 if (errmsg == NULL)
7587 {
7588 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007589 clip_autoselect_star = new_autoselect_star;
7590 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007591 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007592 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007593 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007594 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007595#ifdef FEAT_GUI_GTK
7596 if (gui.in_use)
7597 {
7598 gui_gtk_set_selection_targets();
7599 gui_gtk_set_dnd_targets();
7600 }
7601#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007602 }
7603 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007604 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007605
7606 return errmsg;
7607}
7608#endif
7609
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007610#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007611/*
7612 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7613 * Return error message when failed, NULL when OK.
7614 */
7615 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007616compile_cap_prog(synblock)
7617 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007618{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007619 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007620 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007621
Bram Moolenaar860cae12010-06-05 23:22:07 +02007622 if (*synblock->b_p_spc == NUL)
7623 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007624 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007625 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007626 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007627 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007628 if (re != NULL)
7629 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007630 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007631 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007632 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007633 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007634 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007635 return e_invarg;
7636 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007637 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007638 }
7639
Bram Moolenaar473de612013-06-08 18:19:48 +02007640 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007641 return NULL;
7642}
7643#endif
7644
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007645#if defined(FEAT_EVAL) || defined(PROTO)
7646/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007647 * Set the scriptID for an option, taking care of setting the buffer- or
7648 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007649 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007650 static void
7651set_option_scriptID_idx(opt_idx, opt_flags, id)
7652 int opt_idx;
7653 int opt_flags;
7654 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007655{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007656 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7657 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007658
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007659 /* Remember where the option was set. For local options need to do that
7660 * in the buffer or window structure. */
7661 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007662 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007663 if (both || (opt_flags & OPT_LOCAL))
7664 {
7665 if (indir & PV_BUF)
7666 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7667 else if (indir & PV_WIN)
7668 curwin->w_p_scriptID[indir & PV_MASK] = id;
7669 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007670}
7671#endif
7672
Bram Moolenaar071d4272004-06-13 20:20:40 +00007673/*
7674 * Set the value of a boolean option, and take care of side effects.
7675 * Returns NULL for success, or an error message for an error.
7676 */
7677 static char_u *
7678set_bool_option(opt_idx, varp, value, opt_flags)
7679 int opt_idx; /* index in options[] table */
7680 char_u *varp; /* pointer to the option variable */
7681 int value; /* new value */
7682 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7683{
7684 int old_value = *(int *)varp;
7685
Bram Moolenaar071d4272004-06-13 20:20:40 +00007686 /* Disallow changing some options from secure mode */
7687 if ((secure
7688#ifdef HAVE_SANDBOX
7689 || sandbox != 0
7690#endif
7691 ) && (options[opt_idx].flags & P_SECURE))
7692 return e_secure;
7693
7694 *(int *)varp = value; /* set the new value */
7695#ifdef FEAT_EVAL
7696 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007697 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007698#endif
7699
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007700#ifdef FEAT_GUI
7701 need_mouse_correct = TRUE;
7702#endif
7703
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704 /* May set global value for local option. */
7705 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7706 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7707
7708 /*
7709 * Handle side effects of changing a bool option.
7710 */
7711
7712 /* 'compatible' */
7713 if ((int *)varp == &p_cp)
7714 {
7715 compatible_set();
7716 }
7717
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007718#ifdef FEAT_PERSISTENT_UNDO
7719 /* 'undofile' */
7720 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7721 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007722 /* Only take action when the option was set. When reset we do not
7723 * delete the undo file, the option may be set again without making
7724 * any changes in between. */
7725 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007726 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007727 char_u hash[UNDO_HASH_SIZE];
7728 buf_T *save_curbuf = curbuf;
7729
7730 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007731 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007732 /* When 'undofile' is set globally: for every buffer, otherwise
7733 * only for the current buffer: Try to read in the undofile,
7734 * if one exists, the buffer wasn't changed and the buffer was
7735 * loaded */
7736 if ((curbuf == save_curbuf
7737 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7738 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7739 {
7740 u_compute_hash(hash);
7741 u_read_undo(NULL, hash, curbuf->b_fname);
7742 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007743 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007744 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007745 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007746 }
7747#endif
7748
Bram Moolenaar071d4272004-06-13 20:20:40 +00007749 else if ((int *)varp == &curbuf->b_p_ro)
7750 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007751 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007752 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7753 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007754
7755 /* when 'readonly' is set may give W10 again */
7756 if (curbuf->b_p_ro)
7757 curbuf->b_did_warn = FALSE;
7758
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007760 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761#endif
7762 }
7763
Bram Moolenaar9c449722010-07-20 18:44:27 +02007764#ifdef FEAT_GUI
7765 else if ((int *)varp == &p_mh)
7766 {
7767 if (!p_mh)
7768 gui_mch_mousehide(FALSE);
7769 }
7770#endif
7771
Bram Moolenaara539df02010-08-01 14:35:05 +02007772#ifdef FEAT_TITLE
7773 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007774 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007775 {
7776 redraw_titles();
7777 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778 /* when 'endofline' is changed, redraw the window title */
7779 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007780 {
7781 redraw_titles();
7782 }
7783# ifdef FEAT_MBYTE
7784 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007785 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007786 {
7787 redraw_titles();
7788 }
7789# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007790#endif
7791
7792 /* when 'bin' is set also set some other options */
7793 else if ((int *)varp == &curbuf->b_p_bin)
7794 {
7795 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7796#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007797 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798#endif
7799 }
7800
7801#ifdef FEAT_AUTOCMD
7802 /* when 'buflisted' changes, trigger autocommands */
7803 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7804 {
7805 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7806 NULL, NULL, TRUE, curbuf);
7807 }
7808#endif
7809
7810 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7811 else if ((int *)varp == &curbuf->b_p_swf)
7812 {
7813 if (curbuf->b_p_swf && p_uc)
7814 ml_open_file(curbuf); /* create the swap file */
7815 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007816 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7817 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818 mf_close_file(curbuf, TRUE); /* remove the swap file */
7819 }
7820
7821 /* when 'terse' is set change 'shortmess' */
7822 else if ((int *)varp == &p_terse)
7823 {
7824 char_u *p;
7825
7826 p = vim_strchr(p_shm, SHM_SEARCH);
7827
7828 /* insert 's' in p_shm */
7829 if (p_terse && p == NULL)
7830 {
7831 STRCPY(IObuff, p_shm);
7832 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007833 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007834 }
7835 /* remove 's' from p_shm */
7836 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007837 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007838 }
7839
7840 /* when 'paste' is set or reset also change other options */
7841 else if ((int *)varp == &p_paste)
7842 {
7843 paste_option_changed();
7844 }
7845
7846 /* when 'insertmode' is set from an autocommand need to do work here */
7847 else if ((int *)varp == &p_im)
7848 {
7849 if (p_im)
7850 {
7851 if ((State & INSERT) == 0)
7852 need_start_insertmode = TRUE;
7853 stop_insert_mode = FALSE;
7854 }
7855 else
7856 {
7857 need_start_insertmode = FALSE;
7858 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007859 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007860 clear_cmdline = TRUE; /* remove "(insert)" */
7861 restart_edit = 0;
7862 }
7863 }
7864
7865 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7866 else if ((int *)varp == &p_ic && p_hls)
7867 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007868 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869 }
7870
7871#ifdef FEAT_SEARCH_EXTRA
7872 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7873 else if ((int *)varp == &p_hls)
7874 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007875 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007876 }
7877#endif
7878
7879#ifdef FEAT_SCROLLBIND
7880 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7881 * at the end of normal_cmd() */
7882 else if ((int *)varp == &curwin->w_p_scb)
7883 {
7884 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007885 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007887 curwin->w_scbind_pos = curwin->w_topline;
7888 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889 }
7890#endif
7891
7892#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7893 /* There can be only one window with 'previewwindow' set. */
7894 else if ((int *)varp == &curwin->w_p_pvw)
7895 {
7896 if (curwin->w_p_pvw)
7897 {
7898 win_T *win;
7899
7900 for (win = firstwin; win != NULL; win = win->w_next)
7901 if (win->w_p_pvw && win != curwin)
7902 {
7903 curwin->w_p_pvw = FALSE;
7904 return (char_u *)N_("E590: A preview window already exists");
7905 }
7906 }
7907 }
7908#endif
7909
7910 /* when 'textmode' is set or reset also change 'fileformat' */
7911 else if ((int *)varp == &curbuf->b_p_tx)
7912 {
7913 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7914 }
7915
7916 /* when 'textauto' is set or reset also change 'fileformats' */
7917 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 set_string_option_direct((char_u *)"ffs", -1,
7919 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007920 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007921
7922 /*
7923 * When 'lisp' option changes include/exclude '-' in
7924 * keyword characters.
7925 */
7926#ifdef FEAT_LISP
7927 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7928 {
7929 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7930 }
7931#endif
7932
7933#ifdef FEAT_TITLE
7934 /* when 'title' changed, may need to change the title; same for 'icon' */
7935 else if ((int *)varp == &p_title)
7936 {
7937 did_set_title(FALSE);
7938 }
7939
7940 else if ((int *)varp == &p_icon)
7941 {
7942 did_set_title(TRUE);
7943 }
7944#endif
7945
7946 else if ((int *)varp == &curbuf->b_changed)
7947 {
7948 if (!value)
7949 save_file_ff(curbuf); /* Buffer is unchanged */
7950#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007951 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007952#endif
7953#ifdef FEAT_AUTOCMD
7954 modified_was_set = value;
7955#endif
7956 }
7957
7958#ifdef BACKSLASH_IN_FILENAME
7959 else if ((int *)varp == &p_ssl)
7960 {
7961 if (p_ssl)
7962 {
7963 psepc = '/';
7964 psepcN = '\\';
7965 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 }
7967 else
7968 {
7969 psepc = '\\';
7970 psepcN = '/';
7971 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 }
7973
7974 /* need to adjust the file name arguments and buffer names. */
7975 buflist_slash_adjust();
7976 alist_slash_adjust();
7977# ifdef FEAT_EVAL
7978 scriptnames_slash_adjust();
7979# endif
7980 }
7981#endif
7982
7983 /* If 'wrap' is set, set w_leftcol to zero. */
7984 else if ((int *)varp == &curwin->w_p_wrap)
7985 {
7986 if (curwin->w_p_wrap)
7987 curwin->w_leftcol = 0;
7988 }
7989
7990#ifdef FEAT_WINDOWS
7991 else if ((int *)varp == &p_ea)
7992 {
7993 if (p_ea && !old_value)
7994 win_equal(curwin, FALSE, 0);
7995 }
7996#endif
7997
7998 else if ((int *)varp == &p_wiv)
7999 {
8000 /*
8001 * When 'weirdinvert' changed, set/reset 't_xs'.
8002 * Then set 'weirdinvert' according to value of 't_xs'.
8003 */
8004 if (p_wiv && !old_value)
8005 T_XS = (char_u *)"y";
8006 else if (!p_wiv && old_value)
8007 T_XS = empty_option;
8008 p_wiv = (*T_XS != NUL);
8009 }
8010
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008011#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008012 else if ((int *)varp == &p_beval)
8013 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008014 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008015 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008016 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 gui_mch_disable_beval_area(balloonEval);
8018 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008020
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008021#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008022 else if ((int *)varp == &p_acd)
8023 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008024 /* Change directories when the 'acd' option is set now. */
8025 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008026 }
8027#endif
8028
8029#ifdef FEAT_DIFF
8030 /* 'diff' */
8031 else if ((int *)varp == &curwin->w_p_diff)
8032 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008033 /* May add or remove the buffer from the list of diff buffers. */
8034 diff_buf_adjust(curwin);
8035# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008036 if (foldmethodIsDiff(curwin))
8037 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008038# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008039 }
8040#endif
8041
8042#ifdef USE_IM_CONTROL
8043 /* 'imdisable' */
8044 else if ((int *)varp == &p_imdisable)
8045 {
8046 /* Only de-activate it here, it will be enabled when changing mode. */
8047 if (p_imdisable)
8048 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008049 else if (State & INSERT)
8050 /* When the option is set from an autocommand, it may need to take
8051 * effect right away. */
8052 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008053 }
8054#endif
8055
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008056#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008057 /* 'spell' */
8058 else if ((int *)varp == &curwin->w_p_spell)
8059 {
8060 if (curwin->w_p_spell)
8061 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008062 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008063 if (errmsg != NULL)
8064 EMSG(_(errmsg));
8065 }
8066 }
8067#endif
8068
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069#ifdef FEAT_FKMAP
8070 else if ((int *)varp == &p_altkeymap)
8071 {
8072 if (old_value != p_altkeymap)
8073 {
8074 if (!p_altkeymap)
8075 {
8076 p_hkmap = p_fkmap;
8077 p_fkmap = 0;
8078 }
8079 else
8080 {
8081 p_fkmap = p_hkmap;
8082 p_hkmap = 0;
8083 }
8084 (void)init_chartab();
8085 }
8086 }
8087
8088 /*
8089 * In case some second language keymapping options have changed, check
8090 * and correct the setting in a consistent way.
8091 */
8092
8093 /*
8094 * If hkmap or fkmap are set, reset Arabic keymapping.
8095 */
8096 if ((p_hkmap || p_fkmap) && p_altkeymap)
8097 {
8098 p_altkeymap = p_fkmap;
8099# ifdef FEAT_ARABIC
8100 curwin->w_p_arab = FALSE;
8101# endif
8102 (void)init_chartab();
8103 }
8104
8105 /*
8106 * If hkmap set, reset Farsi keymapping.
8107 */
8108 if (p_hkmap && p_altkeymap)
8109 {
8110 p_altkeymap = 0;
8111 p_fkmap = 0;
8112# ifdef FEAT_ARABIC
8113 curwin->w_p_arab = FALSE;
8114# endif
8115 (void)init_chartab();
8116 }
8117
8118 /*
8119 * If fkmap set, reset Hebrew keymapping.
8120 */
8121 if (p_fkmap && !p_altkeymap)
8122 {
8123 p_altkeymap = 1;
8124 p_hkmap = 0;
8125# ifdef FEAT_ARABIC
8126 curwin->w_p_arab = FALSE;
8127# endif
8128 (void)init_chartab();
8129 }
8130#endif
8131
8132#ifdef FEAT_ARABIC
8133 if ((int *)varp == &curwin->w_p_arab)
8134 {
8135 if (curwin->w_p_arab)
8136 {
8137 /*
8138 * 'arabic' is set, handle various sub-settings.
8139 */
8140 if (!p_tbidi)
8141 {
8142 /* set rightleft mode */
8143 if (!curwin->w_p_rl)
8144 {
8145 curwin->w_p_rl = TRUE;
8146 changed_window_setting();
8147 }
8148
8149 /* Enable Arabic shaping (major part of what Arabic requires) */
8150 if (!p_arshape)
8151 {
8152 p_arshape = TRUE;
8153 redraw_later_clear();
8154 }
8155 }
8156
8157 /* Arabic requires a utf-8 encoding, inform the user if its not
8158 * set. */
8159 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008160 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008161 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8162
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008163 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008164 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8165#ifdef FEAT_EVAL
8166 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8167#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008168 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169
8170# ifdef FEAT_MBYTE
8171 /* set 'delcombine' */
8172 p_deco = TRUE;
8173# endif
8174
8175# ifdef FEAT_KEYMAP
8176 /* Force-set the necessary keymap for arabic */
8177 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8178 OPT_LOCAL);
8179# endif
8180# ifdef FEAT_FKMAP
8181 p_altkeymap = 0;
8182 p_hkmap = 0;
8183 p_fkmap = 0;
8184 (void)init_chartab();
8185# endif
8186 }
8187 else
8188 {
8189 /*
8190 * 'arabic' is reset, handle various sub-settings.
8191 */
8192 if (!p_tbidi)
8193 {
8194 /* reset rightleft mode */
8195 if (curwin->w_p_rl)
8196 {
8197 curwin->w_p_rl = FALSE;
8198 changed_window_setting();
8199 }
8200
8201 /* 'arabicshape' isn't reset, it is a global option and
8202 * another window may still need it "on". */
8203 }
8204
8205 /* 'delcombine' isn't reset, it is a global option and another
8206 * window may still want it "on". */
8207
8208# ifdef FEAT_KEYMAP
8209 /* Revert to the default keymap */
8210 curbuf->b_p_iminsert = B_IMODE_NONE;
8211 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8212# endif
8213 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008214 }
8215
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008216#endif
8217
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 /*
8219 * End of handling side effects for bool options.
8220 */
8221
8222 options[opt_idx].flags |= P_WAS_SET;
8223
8224 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008225 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008226 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008227 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008228 check_redraw(options[opt_idx].flags);
8229
8230 return NULL;
8231}
8232
8233/*
8234 * Set the value of a number option, and take care of side effects.
8235 * Returns NULL for success, or an error message for an error.
8236 */
8237 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008238set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239 int opt_idx; /* index in options[] table */
8240 char_u *varp; /* pointer to the option variable */
8241 long value; /* new value */
8242 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008243 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008244 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8245 OPT_MODELINE */
8246{
8247 char_u *errmsg = NULL;
8248 long old_value = *(long *)varp;
8249 long old_Rows = Rows; /* remember old Rows */
8250 long old_Columns = Columns; /* remember old Columns */
8251 long *pp = (long *)varp;
8252
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008253 /* Disallow changing some options from secure mode. */
8254 if ((secure
8255#ifdef HAVE_SANDBOX
8256 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008257#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008258 ) && (options[opt_idx].flags & P_SECURE))
8259 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008260
8261 *pp = value;
8262#ifdef FEAT_EVAL
8263 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008264 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008265#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008266#ifdef FEAT_GUI
8267 need_mouse_correct = TRUE;
8268#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008269
Bram Moolenaar14f24742012-08-08 18:01:05 +02008270 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008271 {
8272 errmsg = e_positive;
8273 curbuf->b_p_sw = curbuf->b_p_ts;
8274 }
8275
8276 /*
8277 * Number options that need some action when changed
8278 */
8279#ifdef FEAT_WINDOWS
8280 if (pp == &p_wh || pp == &p_hh)
8281 {
8282 if (p_wh < 1)
8283 {
8284 errmsg = e_positive;
8285 p_wh = 1;
8286 }
8287 if (p_wmh > p_wh)
8288 {
8289 errmsg = e_winheight;
8290 p_wh = p_wmh;
8291 }
8292 if (p_hh < 0)
8293 {
8294 errmsg = e_positive;
8295 p_hh = 0;
8296 }
8297
8298 /* Change window height NOW */
8299 if (lastwin != firstwin)
8300 {
8301 if (pp == &p_wh && curwin->w_height < p_wh)
8302 win_setheight((int)p_wh);
8303 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8304 win_setheight((int)p_hh);
8305 }
8306 }
8307
8308 /* 'winminheight' */
8309 else if (pp == &p_wmh)
8310 {
8311 if (p_wmh < 0)
8312 {
8313 errmsg = e_positive;
8314 p_wmh = 0;
8315 }
8316 if (p_wmh > p_wh)
8317 {
8318 errmsg = e_winheight;
8319 p_wmh = p_wh;
8320 }
8321 win_setminheight();
8322 }
8323
8324# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008325 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008326 {
8327 if (p_wiw < 1)
8328 {
8329 errmsg = e_positive;
8330 p_wiw = 1;
8331 }
8332 if (p_wmw > p_wiw)
8333 {
8334 errmsg = e_winwidth;
8335 p_wiw = p_wmw;
8336 }
8337
8338 /* Change window width NOW */
8339 if (lastwin != firstwin && curwin->w_width < p_wiw)
8340 win_setwidth((int)p_wiw);
8341 }
8342
8343 /* 'winminwidth' */
8344 else if (pp == &p_wmw)
8345 {
8346 if (p_wmw < 0)
8347 {
8348 errmsg = e_positive;
8349 p_wmw = 0;
8350 }
8351 if (p_wmw > p_wiw)
8352 {
8353 errmsg = e_winwidth;
8354 p_wmw = p_wiw;
8355 }
8356 win_setminheight();
8357 }
8358# endif
8359
8360#endif
8361
8362#ifdef FEAT_WINDOWS
8363 /* (re)set last window status line */
8364 else if (pp == &p_ls)
8365 {
8366 last_status(FALSE);
8367 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008368
8369 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008370 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008371 {
8372 shell_new_rows(); /* recompute window positions and heights */
8373 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008374#endif
8375
8376#ifdef FEAT_GUI
8377 else if (pp == &p_linespace)
8378 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008379 /* Recompute gui.char_height and resize the Vim window to keep the
8380 * same number of lines. */
8381 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008382 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383 }
8384#endif
8385
8386#ifdef FEAT_FOLDING
8387 /* 'foldlevel' */
8388 else if (pp == &curwin->w_p_fdl)
8389 {
8390 if (curwin->w_p_fdl < 0)
8391 curwin->w_p_fdl = 0;
8392 newFoldLevel();
8393 }
8394
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008395 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396 else if (pp == &curwin->w_p_fml)
8397 {
8398 foldUpdateAll(curwin);
8399 }
8400
8401 /* 'foldnestmax' */
8402 else if (pp == &curwin->w_p_fdn)
8403 {
8404 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8405 foldUpdateAll(curwin);
8406 }
8407
8408 /* 'foldcolumn' */
8409 else if (pp == &curwin->w_p_fdc)
8410 {
8411 if (curwin->w_p_fdc < 0)
8412 {
8413 errmsg = e_positive;
8414 curwin->w_p_fdc = 0;
8415 }
8416 else if (curwin->w_p_fdc > 12)
8417 {
8418 errmsg = e_invarg;
8419 curwin->w_p_fdc = 12;
8420 }
8421 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008422#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008424#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008425 /* 'shiftwidth' or 'tabstop' */
8426 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8427 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008428# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008429 if (foldmethodIsIndent(curwin))
8430 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008431# endif
8432# ifdef FEAT_CINDENT
8433 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8434 * parse 'cinoptions'. */
8435 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8436 parse_cino(curbuf);
8437# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008438 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008439#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008441#ifdef FEAT_MBYTE
8442 /* 'maxcombine' */
8443 else if (pp == &p_mco)
8444 {
8445 if (p_mco > MAX_MCO)
8446 p_mco = MAX_MCO;
8447 else if (p_mco < 0)
8448 p_mco = 0;
8449 screenclear(); /* will re-allocate the screen */
8450 }
8451#endif
8452
Bram Moolenaar071d4272004-06-13 20:20:40 +00008453 else if (pp == &curbuf->b_p_iminsert)
8454 {
8455 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8456 {
8457 errmsg = e_invarg;
8458 curbuf->b_p_iminsert = B_IMODE_NONE;
8459 }
8460 p_iminsert = curbuf->b_p_iminsert;
8461 if (termcap_active) /* don't do this in the alternate screen */
8462 showmode();
8463#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8464 /* Show/unshow value of 'keymap' in status lines. */
8465 status_redraw_curbuf();
8466#endif
8467 }
8468
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008469 else if (pp == &p_window)
8470 {
8471 if (p_window < 1)
8472 p_window = 1;
8473 else if (p_window >= Rows)
8474 p_window = Rows - 1;
8475 }
8476
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477 else if (pp == &curbuf->b_p_imsearch)
8478 {
8479 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8480 {
8481 errmsg = e_invarg;
8482 curbuf->b_p_imsearch = B_IMODE_NONE;
8483 }
8484 p_imsearch = curbuf->b_p_imsearch;
8485 }
8486
8487#ifdef FEAT_TITLE
8488 /* if 'titlelen' has changed, redraw the title */
8489 else if (pp == &p_titlelen)
8490 {
8491 if (p_titlelen < 0)
8492 {
8493 errmsg = e_positive;
8494 p_titlelen = 85;
8495 }
8496 if (starting != NO_SCREEN && old_value != p_titlelen)
8497 need_maketitle = TRUE;
8498 }
8499#endif
8500
8501 /* if p_ch changed value, change the command line height */
8502 else if (pp == &p_ch)
8503 {
8504 if (p_ch < 1)
8505 {
8506 errmsg = e_positive;
8507 p_ch = 1;
8508 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008509 if (p_ch > Rows - min_rows() + 1)
8510 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008511
8512 /* Only compute the new window layout when startup has been
8513 * completed. Otherwise the frame sizes may be wrong. */
8514 if (p_ch != old_value && full_screen
8515#ifdef FEAT_GUI
8516 && !gui.starting
8517#endif
8518 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008519 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520 }
8521
8522 /* when 'updatecount' changes from zero to non-zero, open swap files */
8523 else if (pp == &p_uc)
8524 {
8525 if (p_uc < 0)
8526 {
8527 errmsg = e_positive;
8528 p_uc = 100;
8529 }
8530 if (p_uc && !old_value)
8531 ml_open_files();
8532 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008533#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008534 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008535 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008536 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008537 {
8538 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008539 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008540 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008541 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008542 {
8543 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008544 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008545 }
8546 }
8547#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008548#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008549 else if (pp == &p_mzq)
8550 mzvim_reset_timer();
8551#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008552
8553 /* sync undo before 'undolevels' changes */
8554 else if (pp == &p_ul)
8555 {
8556 /* use the old value, otherwise u_sync() may not work properly */
8557 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008558 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008559 p_ul = value;
8560 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008561 else if (pp == &curbuf->b_p_ul)
8562 {
8563 /* use the old value, otherwise u_sync() may not work properly */
8564 curbuf->b_p_ul = old_value;
8565 u_sync(TRUE);
8566 curbuf->b_p_ul = value;
8567 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008568
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008569#ifdef FEAT_LINEBREAK
8570 /* 'numberwidth' must be positive */
8571 else if (pp == &curwin->w_p_nuw)
8572 {
8573 if (curwin->w_p_nuw < 1)
8574 {
8575 errmsg = e_positive;
8576 curwin->w_p_nuw = 1;
8577 }
8578 if (curwin->w_p_nuw > 10)
8579 {
8580 errmsg = e_invarg;
8581 curwin->w_p_nuw = 10;
8582 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008583 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008584 }
8585#endif
8586
Bram Moolenaar1a384422010-07-14 19:53:30 +02008587 else if (pp == &curbuf->b_p_tw)
8588 {
8589 if (curbuf->b_p_tw < 0)
8590 {
8591 errmsg = e_positive;
8592 curbuf->b_p_tw = 0;
8593 }
8594#ifdef FEAT_SYN_HL
8595# ifdef FEAT_WINDOWS
8596 {
8597 win_T *wp;
8598 tabpage_T *tp;
8599
8600 FOR_ALL_TAB_WINDOWS(tp, wp)
8601 check_colorcolumn(wp);
8602 }
8603# else
8604 check_colorcolumn(curwin);
8605# endif
8606#endif
8607 }
8608
Bram Moolenaar071d4272004-06-13 20:20:40 +00008609 /*
8610 * Check the bounds for numeric options here
8611 */
8612 if (Rows < min_rows() && full_screen)
8613 {
8614 if (errbuf != NULL)
8615 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008616 vim_snprintf((char *)errbuf, errbuflen,
8617 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618 errmsg = errbuf;
8619 }
8620 Rows = min_rows();
8621 }
8622 if (Columns < MIN_COLUMNS && full_screen)
8623 {
8624 if (errbuf != NULL)
8625 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008626 vim_snprintf((char *)errbuf, errbuflen,
8627 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 errmsg = errbuf;
8629 }
8630 Columns = MIN_COLUMNS;
8631 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008632 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008633
8634#ifdef DJGPP
8635 /* avoid a crash by checking for a too large value of 'columns' */
8636 if (old_Columns != Columns && full_screen && term_console)
8637 mch_check_columns();
8638#endif
8639
8640 /*
8641 * If the screen (shell) height has been changed, assume it is the
8642 * physical screenheight.
8643 */
8644 if (old_Rows != Rows || old_Columns != Columns)
8645 {
8646 /* Changing the screen size is not allowed while updating the screen. */
8647 if (updating_screen)
8648 *pp = old_value;
8649 else if (full_screen
8650#ifdef FEAT_GUI
8651 && !gui.starting
8652#endif
8653 )
8654 set_shellsize((int)Columns, (int)Rows, TRUE);
8655 else
8656 {
8657 /* Postpone the resizing; check the size and cmdline position for
8658 * messages. */
8659 check_shellsize();
8660 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8661 cmdline_row = Rows - p_ch;
8662 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008663 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008664 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008665 }
8666
Bram Moolenaar071d4272004-06-13 20:20:40 +00008667 if (curbuf->b_p_ts <= 0)
8668 {
8669 errmsg = e_positive;
8670 curbuf->b_p_ts = 8;
8671 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008672 if (p_tm < 0)
8673 {
8674 errmsg = e_positive;
8675 p_tm = 0;
8676 }
8677 if ((curwin->w_p_scr <= 0
8678 || (curwin->w_p_scr > curwin->w_height
8679 && curwin->w_height > 0))
8680 && full_screen)
8681 {
8682 if (pp == &(curwin->w_p_scr))
8683 {
8684 if (curwin->w_p_scr != 0)
8685 errmsg = e_scroll;
8686 win_comp_scroll(curwin);
8687 }
8688 /* If 'scroll' became invalid because of a side effect silently adjust
8689 * it. */
8690 else if (curwin->w_p_scr <= 0)
8691 curwin->w_p_scr = 1;
8692 else /* curwin->w_p_scr > curwin->w_height */
8693 curwin->w_p_scr = curwin->w_height;
8694 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008695 if (p_hi < 0)
8696 {
8697 errmsg = e_positive;
8698 p_hi = 0;
8699 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008700 else if (p_hi > 10000)
8701 {
8702 errmsg = e_invarg;
8703 p_hi = 10000;
8704 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008705 if (p_re < 0 || p_re > 2)
8706 {
8707 errmsg = e_invarg;
8708 p_re = 0;
8709 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008710 if (p_report < 0)
8711 {
8712 errmsg = e_positive;
8713 p_report = 1;
8714 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008715 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008716 {
8717 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8718 p_sj = Rows / 2;
8719 else
8720 {
8721 errmsg = e_scroll;
8722 p_sj = 1;
8723 }
8724 }
8725 if (p_so < 0 && full_screen)
8726 {
8727 errmsg = e_scroll;
8728 p_so = 0;
8729 }
8730 if (p_siso < 0 && full_screen)
8731 {
8732 errmsg = e_positive;
8733 p_siso = 0;
8734 }
8735#ifdef FEAT_CMDWIN
8736 if (p_cwh < 1)
8737 {
8738 errmsg = e_positive;
8739 p_cwh = 1;
8740 }
8741#endif
8742 if (p_ut < 0)
8743 {
8744 errmsg = e_positive;
8745 p_ut = 2000;
8746 }
8747 if (p_ss < 0)
8748 {
8749 errmsg = e_positive;
8750 p_ss = 0;
8751 }
8752
8753 /* May set global value for local option. */
8754 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8755 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8756
8757 options[opt_idx].flags |= P_WAS_SET;
8758
8759 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008760 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008761 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008762 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763 check_redraw(options[opt_idx].flags);
8764
8765 return errmsg;
8766}
8767
8768/*
8769 * Called after an option changed: check if something needs to be redrawn.
8770 */
8771 static void
8772check_redraw(flags)
8773 long_u flags;
8774{
8775 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008776 int doclear = (flags & P_RCLR) == P_RCLR;
8777 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778
8779#ifdef FEAT_WINDOWS
8780 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8781 status_redraw_all();
8782#endif
8783
8784 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8785 changed_window_setting();
8786 if (flags & P_RBUF)
8787 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008788 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008789 redraw_all_later(CLEAR);
8790 else if (all)
8791 redraw_all_later(NOT_VALID);
8792}
8793
8794/*
8795 * Find index for option 'arg'.
8796 * Return -1 if not found.
8797 */
8798 static int
8799findoption(arg)
8800 char_u *arg;
8801{
8802 int opt_idx;
8803 char *s, *p;
8804 static short quick_tab[27] = {0, 0}; /* quick access table */
8805 int is_term_opt;
8806
8807 /*
8808 * For first call: Initialize the quick-access table.
8809 * It contains the index for the first option that starts with a certain
8810 * letter. There are 26 letters, plus the first "t_" option.
8811 */
8812 if (quick_tab[1] == 0)
8813 {
8814 p = options[0].fullname;
8815 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8816 {
8817 if (s[0] != p[0])
8818 {
8819 if (s[0] == 't' && s[1] == '_')
8820 quick_tab[26] = opt_idx;
8821 else
8822 quick_tab[CharOrdLow(s[0])] = opt_idx;
8823 }
8824 p = s;
8825 }
8826 }
8827
8828 /*
8829 * Check for name starting with an illegal character.
8830 */
8831#ifdef EBCDIC
8832 if (!islower(arg[0]))
8833#else
8834 if (arg[0] < 'a' || arg[0] > 'z')
8835#endif
8836 return -1;
8837
8838 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8839 if (is_term_opt)
8840 opt_idx = quick_tab[26];
8841 else
8842 opt_idx = quick_tab[CharOrdLow(arg[0])];
8843 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8844 {
8845 if (STRCMP(arg, s) == 0) /* match full name */
8846 break;
8847 }
8848 if (s == NULL && !is_term_opt)
8849 {
8850 opt_idx = quick_tab[CharOrdLow(arg[0])];
8851 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8852 {
8853 s = options[opt_idx].shortname;
8854 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8855 break;
8856 s = NULL;
8857 }
8858 }
8859 if (s == NULL)
8860 opt_idx = -1;
8861 return opt_idx;
8862}
8863
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008864#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865/*
8866 * Get the value for an option.
8867 *
8868 * Returns:
8869 * Number or Toggle option: 1, *numval gets value.
8870 * String option: 0, *stringval gets allocated string.
8871 * Hidden Number or Toggle option: -1.
8872 * hidden String option: -2.
8873 * unknown option: -3.
8874 */
8875 int
8876get_option_value(name, numval, stringval, opt_flags)
8877 char_u *name;
8878 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008879 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880 int opt_flags;
8881{
8882 int opt_idx;
8883 char_u *varp;
8884
8885 opt_idx = findoption(name);
8886 if (opt_idx < 0) /* unknown option */
8887 return -3;
8888
8889 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8890
8891 if (options[opt_idx].flags & P_STRING)
8892 {
8893 if (varp == NULL) /* hidden option */
8894 return -2;
8895 if (stringval != NULL)
8896 {
8897#ifdef FEAT_CRYPT
8898 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008899 if ((char_u **)varp == &curbuf->b_p_key
8900 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008901 *stringval = vim_strsave((char_u *)"*****");
8902 else
8903#endif
8904 *stringval = vim_strsave(*(char_u **)(varp));
8905 }
8906 return 0;
8907 }
8908
8909 if (varp == NULL) /* hidden option */
8910 return -1;
8911 if (options[opt_idx].flags & P_NUM)
8912 *numval = *(long *)varp;
8913 else
8914 {
8915 /* Special case: 'modified' is b_changed, but we also want to consider
8916 * it set when 'ff' or 'fenc' changed. */
8917 if ((int *)varp == &curbuf->b_changed)
8918 *numval = curbufIsChanged();
8919 else
8920 *numval = *(int *)varp;
8921 }
8922 return 1;
8923}
8924#endif
8925
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008926#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008927/*
8928 * Returns the option attributes and its value. Unlike the above function it
8929 * will return either global value or local value of the option depending on
8930 * what was requested, but it will never return global value if it was
8931 * requested to return local one and vice versa. Neither it will return
8932 * buffer-local value if it was requested to return window-local one.
8933 *
8934 * Pretends that option is absent if it is not present in the requested scope
8935 * (i.e. has no global, window-local or buffer-local value depending on
8936 * opt_type). Uses
8937 *
8938 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008939 * 0 hidden or unknown option, also option that does not have requested
8940 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008941 * see SOPT_* in vim.h for other flags
8942 *
8943 * Possible opt_type values: see SREQ_* in vim.h
8944 */
8945 int
8946get_option_value_strict(name, numval, stringval, opt_type, from)
8947 char_u *name;
8948 long *numval;
8949 char_u **stringval; /* NULL when only obtaining attributes */
8950 int opt_type;
8951 void *from;
8952{
8953 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008954 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008955 struct vimoption *p;
8956 int r = 0;
8957
8958 opt_idx = findoption(name);
8959 if (opt_idx < 0)
8960 return 0;
8961
8962 p = &(options[opt_idx]);
8963
8964 /* Hidden option */
8965 if (p->var == NULL)
8966 return 0;
8967
8968 if (p->flags & P_BOOL)
8969 r |= SOPT_BOOL;
8970 else if (p->flags & P_NUM)
8971 r |= SOPT_NUM;
8972 else if (p->flags & P_STRING)
8973 r |= SOPT_STRING;
8974
8975 if (p->indir == PV_NONE)
8976 {
8977 if (opt_type == SREQ_GLOBAL)
8978 r |= SOPT_GLOBAL;
8979 else
8980 return 0; /* Did not request global-only option */
8981 }
8982 else
8983 {
8984 if (p->indir & PV_BOTH)
8985 r |= SOPT_GLOBAL;
8986 else if (opt_type == SREQ_GLOBAL)
8987 return 0; /* Requested global option */
8988
8989 if (p->indir & PV_WIN)
8990 {
8991 if (opt_type == SREQ_BUF)
8992 return 0; /* Did not request window-local option */
8993 else
8994 r |= SOPT_WIN;
8995 }
8996 else if (p->indir & PV_BUF)
8997 {
8998 if (opt_type == SREQ_WIN)
8999 return 0; /* Did not request buffer-local option */
9000 else
9001 r |= SOPT_BUF;
9002 }
9003 }
9004
9005 if (stringval == NULL)
9006 return r;
9007
9008 if (opt_type == SREQ_GLOBAL)
9009 varp = p->var;
9010 else
9011 {
9012 if (opt_type == SREQ_BUF)
9013 {
9014 /* Special case: 'modified' is b_changed, but we also want to
9015 * consider it set when 'ff' or 'fenc' changed. */
9016 if (p->indir == PV_MOD)
9017 {
9018 *numval = bufIsChanged((buf_T *) from);
9019 varp = NULL;
9020 }
9021#ifdef FEAT_CRYPT
9022 else if (p->indir == PV_KEY)
9023 {
9024 /* never return the value of the crypt key */
9025 *stringval = NULL;
9026 varp = NULL;
9027 }
9028#endif
9029 else
9030 {
9031 aco_save_T aco;
9032 aucmd_prepbuf(&aco, (buf_T *) from);
9033 varp = get_varp(p);
9034 aucmd_restbuf(&aco);
9035 }
9036 }
9037 else if (opt_type == SREQ_WIN)
9038 {
9039 win_T *save_curwin;
9040 save_curwin = curwin;
9041 curwin = (win_T *) from;
9042 curbuf = curwin->w_buffer;
9043 varp = get_varp(p);
9044 curwin = save_curwin;
9045 curbuf = curwin->w_buffer;
9046 }
9047 if (varp == p->var)
9048 return (r | SOPT_UNSET);
9049 }
9050
9051 if (varp != NULL)
9052 {
9053 if (p->flags & P_STRING)
9054 *stringval = vim_strsave(*(char_u **)(varp));
9055 else if (p->flags & P_NUM)
9056 *numval = *(long *) varp;
9057 else
9058 *numval = *(int *)varp;
9059 }
9060
9061 return r;
9062}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009063
9064/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009065 * Iterate over options. First argument is a pointer to a pointer to a
9066 * structure inside options[] array, second is option type like in the above
9067 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009068 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009069 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009070 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009071 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009072 * first argument to NULL.
9073 *
9074 * Returns full option name for current option on each call.
9075 */
9076 char_u *
9077option_iter_next(option, opt_type)
9078 void **option;
9079 int opt_type;
9080{
9081 struct vimoption *ret = NULL;
9082 do
9083 {
9084 if (*option == NULL)
9085 *option = (void *) options;
9086 else if (((struct vimoption *) (*option))->fullname == NULL)
9087 {
9088 *option = NULL;
9089 return NULL;
9090 }
9091 else
9092 *option = (void *) (((struct vimoption *) (*option)) + 1);
9093
9094 ret = ((struct vimoption *) (*option));
9095
9096 /* Hidden option */
9097 if (ret->var == NULL)
9098 {
9099 ret = NULL;
9100 continue;
9101 }
9102
9103 switch (opt_type)
9104 {
9105 case SREQ_GLOBAL:
9106 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9107 ret = NULL;
9108 break;
9109 case SREQ_BUF:
9110 if (!(ret->indir & PV_BUF))
9111 ret = NULL;
9112 break;
9113 case SREQ_WIN:
9114 if (!(ret->indir & PV_WIN))
9115 ret = NULL;
9116 break;
9117 default:
9118 EMSG2(_(e_intern2), "option_iter_next()");
9119 return NULL;
9120 }
9121 }
9122 while (ret == NULL);
9123
9124 return (char_u *)ret->fullname;
9125}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009126#endif
9127
Bram Moolenaar071d4272004-06-13 20:20:40 +00009128/*
9129 * Set the value of option "name".
9130 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009131 *
9132 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009133 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009134 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009135set_option_value(name, number, string, opt_flags)
9136 char_u *name;
9137 long number;
9138 char_u *string;
9139 int opt_flags; /* OPT_LOCAL or 0 (both) */
9140{
9141 int opt_idx;
9142 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009143 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009144
9145 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009146 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009147 EMSG2(_("E355: Unknown option: %s"), name);
9148 else
9149 {
9150 flags = options[opt_idx].flags;
9151#ifdef HAVE_SANDBOX
9152 /* Disallow changing some options in the sandbox */
9153 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009154 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009155 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009156 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009157 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009158#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009159 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009160 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009161 else
9162 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009163 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009164 if (varp != NULL) /* hidden option is not changed */
9165 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009166 if (number == 0 && string != NULL)
9167 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009168 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009169
9170 /* Either we are given a string or we are setting option
9171 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009172 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009173 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009174 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009175 {
9176 /* There's another character after zeros or the string
9177 * is empty. In both cases, we are trying to set a
9178 * num option using a string. */
9179 EMSG3(_("E521: Number required: &%s = '%s'"),
9180 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009181 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009182
9183 }
9184 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009185 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009186 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009187 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009188 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009189 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009190 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009191 }
9192 }
9193 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009194 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009195}
9196
9197/*
9198 * Get the terminal code for a terminal option.
9199 * Returns NULL when not found.
9200 */
9201 char_u *
9202get_term_code(tname)
9203 char_u *tname;
9204{
9205 int opt_idx;
9206 char_u *varp;
9207
9208 if (tname[0] != 't' || tname[1] != '_' ||
9209 tname[2] == NUL || tname[3] == NUL)
9210 return NULL;
9211 if ((opt_idx = findoption(tname)) >= 0)
9212 {
9213 varp = get_varp(&(options[opt_idx]));
9214 if (varp != NULL)
9215 varp = *(char_u **)(varp);
9216 return varp;
9217 }
9218 return find_termcode(tname + 2);
9219}
9220
9221 char_u *
9222get_highlight_default()
9223{
9224 int i;
9225
9226 i = findoption((char_u *)"hl");
9227 if (i >= 0)
9228 return options[i].def_val[VI_DEFAULT];
9229 return (char_u *)NULL;
9230}
9231
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009232#if defined(FEAT_MBYTE) || defined(PROTO)
9233 char_u *
9234get_encoding_default()
9235{
9236 int i;
9237
9238 i = findoption((char_u *)"enc");
9239 if (i >= 0)
9240 return options[i].def_val[VI_DEFAULT];
9241 return (char_u *)NULL;
9242}
9243#endif
9244
Bram Moolenaar071d4272004-06-13 20:20:40 +00009245/*
9246 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9247 */
9248 static int
9249find_key_option(arg)
9250 char_u *arg;
9251{
9252 int key;
9253 int modifiers;
9254
9255 /*
9256 * Don't use get_special_key_code() for t_xx, we don't want it to call
9257 * add_termcap_entry().
9258 */
9259 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9260 key = TERMCAP2KEY(arg[2], arg[3]);
9261 else
9262 {
9263 --arg; /* put arg at the '<' */
9264 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009265 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009266 if (modifiers) /* can't handle modifiers here */
9267 key = 0;
9268 }
9269 return key;
9270}
9271
9272/*
9273 * if 'all' == 0: show changed options
9274 * if 'all' == 1: show all normal options
9275 * if 'all' == 2: show all terminal options
9276 */
9277 static void
9278showoptions(all, opt_flags)
9279 int all;
9280 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9281{
9282 struct vimoption *p;
9283 int col;
9284 int isterm;
9285 char_u *varp;
9286 struct vimoption **items;
9287 int item_count;
9288 int run;
9289 int row, rows;
9290 int cols;
9291 int i;
9292 int len;
9293
9294#define INC 20
9295#define GAP 3
9296
9297 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9298 PARAM_COUNT));
9299 if (items == NULL)
9300 return;
9301
9302 /* Highlight title */
9303 if (all == 2)
9304 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9305 else if (opt_flags & OPT_GLOBAL)
9306 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9307 else if (opt_flags & OPT_LOCAL)
9308 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9309 else
9310 MSG_PUTS_TITLE(_("\n--- Options ---"));
9311
9312 /*
9313 * do the loop two times:
9314 * 1. display the short items
9315 * 2. display the long items (only strings and numbers)
9316 */
9317 for (run = 1; run <= 2 && !got_int; ++run)
9318 {
9319 /*
9320 * collect the items in items[]
9321 */
9322 item_count = 0;
9323 for (p = &options[0]; p->fullname != NULL; p++)
9324 {
9325 varp = NULL;
9326 isterm = istermoption(p);
9327 if (opt_flags != 0)
9328 {
9329 if (p->indir != PV_NONE && !isterm)
9330 varp = get_varp_scope(p, opt_flags);
9331 }
9332 else
9333 varp = get_varp(p);
9334 if (varp != NULL
9335 && ((all == 2 && isterm)
9336 || (all == 1 && !isterm)
9337 || (all == 0 && !optval_default(p, varp))))
9338 {
9339 if (p->flags & P_BOOL)
9340 len = 1; /* a toggle option fits always */
9341 else
9342 {
9343 option_value2string(p, opt_flags);
9344 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9345 }
9346 if ((len <= INC - GAP && run == 1) ||
9347 (len > INC - GAP && run == 2))
9348 items[item_count++] = p;
9349 }
9350 }
9351
9352 /*
9353 * display the items
9354 */
9355 if (run == 1)
9356 {
9357 cols = (Columns + GAP - 3) / INC;
9358 if (cols == 0)
9359 cols = 1;
9360 rows = (item_count + cols - 1) / cols;
9361 }
9362 else /* run == 2 */
9363 rows = item_count;
9364 for (row = 0; row < rows && !got_int; ++row)
9365 {
9366 msg_putchar('\n'); /* go to next line */
9367 if (got_int) /* 'q' typed in more */
9368 break;
9369 col = 0;
9370 for (i = row; i < item_count; i += rows)
9371 {
9372 msg_col = col; /* make columns */
9373 showoneopt(items[i], opt_flags);
9374 col += INC;
9375 }
9376 out_flush();
9377 ui_breakcheck();
9378 }
9379 }
9380 vim_free(items);
9381}
9382
9383/*
9384 * Return TRUE if option "p" has its default value.
9385 */
9386 static int
9387optval_default(p, varp)
9388 struct vimoption *p;
9389 char_u *varp;
9390{
9391 int dvi;
9392
9393 if (varp == NULL)
9394 return TRUE; /* hidden option is always at default */
9395 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9396 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009397 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009398 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009399 /* the cast to long is required for Manx C, long_i is
9400 * needed for MSVC */
9401 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009402 /* P_STRING */
9403 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9404}
9405
9406/*
9407 * showoneopt: show the value of one option
9408 * must not be called with a hidden option!
9409 */
9410 static void
9411showoneopt(p, opt_flags)
9412 struct vimoption *p;
9413 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9414{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009415 char_u *varp;
9416 int save_silent = silent_mode;
9417
9418 silent_mode = FALSE;
9419 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009420
9421 varp = get_varp_scope(p, opt_flags);
9422
9423 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9424 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9425 ? !curbufIsChanged() : !*(int *)varp))
9426 MSG_PUTS("no");
9427 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9428 MSG_PUTS("--");
9429 else
9430 MSG_PUTS(" ");
9431 MSG_PUTS(p->fullname);
9432 if (!(p->flags & P_BOOL))
9433 {
9434 msg_putchar('=');
9435 /* put value string in NameBuff */
9436 option_value2string(p, opt_flags);
9437 msg_outtrans(NameBuff);
9438 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009439
9440 silent_mode = save_silent;
9441 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009442}
9443
9444/*
9445 * Write modified options as ":set" commands to a file.
9446 *
9447 * There are three values for "opt_flags":
9448 * OPT_GLOBAL: Write global option values and fresh values of
9449 * buffer-local options (used for start of a session
9450 * file).
9451 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9452 * curwin (used for a vimrc file).
9453 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9454 * and local values for window-local options of
9455 * curwin. Local values are also written when at the
9456 * default value, because a modeline or autocommand
9457 * may have set them when doing ":edit file" and the
9458 * user has set them back at the default or fresh
9459 * value.
9460 * When "local_only" is TRUE, don't write fresh
9461 * values, only local values (for ":mkview").
9462 * (fresh value = value used for a new buffer or window for a local option).
9463 *
9464 * Return FAIL on error, OK otherwise.
9465 */
9466 int
9467makeset(fd, opt_flags, local_only)
9468 FILE *fd;
9469 int opt_flags;
9470 int local_only;
9471{
9472 struct vimoption *p;
9473 char_u *varp; /* currently used value */
9474 char_u *varp_fresh; /* local value */
9475 char_u *varp_local = NULL; /* fresh value */
9476 char *cmd;
9477 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009478 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009479
9480 /*
9481 * The options that don't have a default (terminal name, columns, lines)
9482 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009483 * Do the loop over "options[]" twice: once for options with the
9484 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009485 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009486 for (pri = 1; pri >= 0; --pri)
9487 {
9488 for (p = &options[0]; !istermoption(p); p++)
9489 if (!(p->flags & P_NO_MKRC)
9490 && !istermoption(p)
9491 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009492 {
9493 /* skip global option when only doing locals */
9494 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9495 continue;
9496
9497 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9498 * file, they are always buffer-specific. */
9499 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9500 continue;
9501
9502 /* Global values are only written when not at the default value. */
9503 varp = get_varp_scope(p, opt_flags);
9504 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9505 continue;
9506
9507 round = 2;
9508 if (p->indir != PV_NONE)
9509 {
9510 if (p->var == VAR_WIN)
9511 {
9512 /* skip window-local option when only doing globals */
9513 if (!(opt_flags & OPT_LOCAL))
9514 continue;
9515 /* When fresh value of window-local option is not at the
9516 * default, need to write it too. */
9517 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9518 {
9519 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9520 if (!optval_default(p, varp_fresh))
9521 {
9522 round = 1;
9523 varp_local = varp;
9524 varp = varp_fresh;
9525 }
9526 }
9527 }
9528 }
9529
9530 /* Round 1: fresh value for window-local options.
9531 * Round 2: other values */
9532 for ( ; round <= 2; varp = varp_local, ++round)
9533 {
9534 if (round == 1 || (opt_flags & OPT_GLOBAL))
9535 cmd = "set";
9536 else
9537 cmd = "setlocal";
9538
9539 if (p->flags & P_BOOL)
9540 {
9541 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9542 return FAIL;
9543 }
9544 else if (p->flags & P_NUM)
9545 {
9546 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9547 return FAIL;
9548 }
9549 else /* P_STRING */
9550 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009551#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9552 int do_endif = FALSE;
9553
Bram Moolenaar071d4272004-06-13 20:20:40 +00009554 /* Don't set 'syntax' and 'filetype' again if the value is
9555 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009556 if (
9557# if defined(FEAT_SYN_HL)
9558 p->indir == PV_SYN
9559# if defined(FEAT_AUTOCMD)
9560 ||
9561# endif
9562# endif
9563# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009564 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009565# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009566 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009567 {
9568 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9569 *(char_u **)(varp)) < 0
9570 || put_eol(fd) < 0)
9571 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009572 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009573 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009574#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009575 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9576 (p->flags & P_EXPAND) != 0) == FAIL)
9577 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009578#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9579 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009580 {
9581 if (put_line(fd, "endif") == FAIL)
9582 return FAIL;
9583 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009584#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585 }
9586 }
9587 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009588 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009589 return OK;
9590}
9591
9592#if defined(FEAT_FOLDING) || defined(PROTO)
9593/*
9594 * Generate set commands for the local fold options only. Used when
9595 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9596 */
9597 int
9598makefoldset(fd)
9599 FILE *fd;
9600{
9601 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9602# ifdef FEAT_EVAL
9603 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9604 == FAIL
9605# endif
9606 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9607 == FAIL
9608 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9609 == FAIL
9610 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9611 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9612 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9613 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9614 )
9615 return FAIL;
9616
9617 return OK;
9618}
9619#endif
9620
9621 static int
9622put_setstring(fd, cmd, name, valuep, expand)
9623 FILE *fd;
9624 char *cmd;
9625 char *name;
9626 char_u **valuep;
9627 int expand;
9628{
9629 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009630 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009631
9632 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9633 return FAIL;
9634 if (*valuep != NULL)
9635 {
9636 /* Output 'pastetoggle' as key names. For other
9637 * options some characters have to be escaped with
9638 * CTRL-V or backslash */
9639 if (valuep == &p_pt)
9640 {
9641 s = *valuep;
9642 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009643 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009644 return FAIL;
9645 }
9646 else if (expand)
9647 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009648 buf = alloc(MAXPATHL);
9649 if (buf == NULL)
9650 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009651 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9652 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009653 {
9654 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009655 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009656 }
9657 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009658 }
9659 else if (put_escstr(fd, *valuep, 2) == FAIL)
9660 return FAIL;
9661 }
9662 if (put_eol(fd) < 0)
9663 return FAIL;
9664 return OK;
9665}
9666
9667 static int
9668put_setnum(fd, cmd, name, valuep)
9669 FILE *fd;
9670 char *cmd;
9671 char *name;
9672 long *valuep;
9673{
9674 long wc;
9675
9676 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9677 return FAIL;
9678 if (wc_use_keyname((char_u *)valuep, &wc))
9679 {
9680 /* print 'wildchar' and 'wildcharm' as a key name */
9681 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9682 return FAIL;
9683 }
9684 else if (fprintf(fd, "%ld", *valuep) < 0)
9685 return FAIL;
9686 if (put_eol(fd) < 0)
9687 return FAIL;
9688 return OK;
9689}
9690
9691 static int
9692put_setbool(fd, cmd, name, value)
9693 FILE *fd;
9694 char *cmd;
9695 char *name;
9696 int value;
9697{
Bram Moolenaar893de922007-10-02 18:40:57 +00009698 if (value < 0) /* global/local option using global value */
9699 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009700 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9701 || put_eol(fd) < 0)
9702 return FAIL;
9703 return OK;
9704}
9705
9706/*
9707 * Clear all the terminal options.
9708 * If the option has been allocated, free the memory.
9709 * Terminal options are never hidden or indirect.
9710 */
9711 void
9712clear_termoptions()
9713{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009714 /*
9715 * Reset a few things before clearing the old options. This may cause
9716 * outputting a few things that the terminal doesn't understand, but the
9717 * screen will be cleared later, so this is OK.
9718 */
9719#ifdef FEAT_MOUSE_TTY
9720 mch_setmouse(FALSE); /* switch mouse off */
9721#endif
9722#ifdef FEAT_TITLE
9723 mch_restore_title(3); /* restore window titles */
9724#endif
9725#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9726 /* When starting the GUI close the display opened for the clipboard.
9727 * After restoring the title, because that will need the display. */
9728 if (gui.starting)
9729 clear_xterm_clip();
9730#endif
9731#ifdef WIN3264
9732 /*
9733 * Check if this is allowed now.
9734 */
9735 if (can_end_termcap_mode(FALSE) == TRUE)
9736#endif
9737 stoptermcap(); /* stop termcap mode */
9738
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009739 free_termoptions();
9740}
9741
9742 void
9743free_termoptions()
9744{
9745 struct vimoption *p;
9746
Bram Moolenaar071d4272004-06-13 20:20:40 +00009747 for (p = &options[0]; p->fullname != NULL; p++)
9748 if (istermoption(p))
9749 {
9750 if (p->flags & P_ALLOCED)
9751 free_string_option(*(char_u **)(p->var));
9752 if (p->flags & P_DEF_ALLOCED)
9753 free_string_option(p->def_val[VI_DEFAULT]);
9754 *(char_u **)(p->var) = empty_option;
9755 p->def_val[VI_DEFAULT] = empty_option;
9756 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9757 }
9758 clear_termcodes();
9759}
9760
9761/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009762 * Free the string for one term option, if it was allocated.
9763 * Set the string to empty_option and clear allocated flag.
9764 * "var" points to the option value.
9765 */
9766 void
9767free_one_termoption(var)
9768 char_u *var;
9769{
9770 struct vimoption *p;
9771
9772 for (p = &options[0]; p->fullname != NULL; p++)
9773 if (p->var == var)
9774 {
9775 if (p->flags & P_ALLOCED)
9776 free_string_option(*(char_u **)(p->var));
9777 *(char_u **)(p->var) = empty_option;
9778 p->flags &= ~P_ALLOCED;
9779 break;
9780 }
9781}
9782
9783/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009784 * Set the terminal option defaults to the current value.
9785 * Used after setting the terminal name.
9786 */
9787 void
9788set_term_defaults()
9789{
9790 struct vimoption *p;
9791
9792 for (p = &options[0]; p->fullname != NULL; p++)
9793 {
9794 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9795 {
9796 if (p->flags & P_DEF_ALLOCED)
9797 {
9798 free_string_option(p->def_val[VI_DEFAULT]);
9799 p->flags &= ~P_DEF_ALLOCED;
9800 }
9801 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9802 if (p->flags & P_ALLOCED)
9803 {
9804 p->flags |= P_DEF_ALLOCED;
9805 p->flags &= ~P_ALLOCED; /* don't free the value now */
9806 }
9807 }
9808 }
9809}
9810
9811/*
9812 * return TRUE if 'p' starts with 't_'
9813 */
9814 static int
9815istermoption(p)
9816 struct vimoption *p;
9817{
9818 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9819}
9820
9821/*
9822 * Compute columns for ruler and shown command. 'sc_col' is also used to
9823 * decide what the maximum length of a message on the status line can be.
9824 * If there is a status line for the last window, 'sc_col' is independent
9825 * of 'ru_col'.
9826 */
9827
9828#define COL_RULER 17 /* columns needed by standard ruler */
9829
9830 void
9831comp_col()
9832{
9833#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9834 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9835
9836 sc_col = 0;
9837 ru_col = 0;
9838 if (p_ru)
9839 {
9840#ifdef FEAT_STL_OPT
9841 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9842#else
9843 ru_col = COL_RULER + 1;
9844#endif
9845 /* no last status line, adjust sc_col */
9846 if (!last_has_status)
9847 sc_col = ru_col;
9848 }
9849 if (p_sc)
9850 {
9851 sc_col += SHOWCMD_COLS;
9852 if (!p_ru || last_has_status) /* no need for separating space */
9853 ++sc_col;
9854 }
9855 sc_col = Columns - sc_col;
9856 ru_col = Columns - ru_col;
9857 if (sc_col <= 0) /* screen too narrow, will become a mess */
9858 sc_col = 1;
9859 if (ru_col <= 0)
9860 ru_col = 1;
9861#else
9862 sc_col = Columns;
9863 ru_col = Columns;
9864#endif
9865}
9866
9867/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009868 * Unset local option value, similar to ":set opt<".
9869 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009870 void
9871unset_global_local_option(name, from)
9872 char_u *name;
9873 void *from;
9874{
9875 struct vimoption *p;
9876 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009877 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009878
9879 opt_idx = findoption(name);
9880 p = &(options[opt_idx]);
9881
9882 switch ((int)p->indir)
9883 {
9884 /* global option with local value: use local value if it's been set */
9885 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009886 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009887 break;
9888 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009889 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009890 break;
9891 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009892 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009893 break;
9894 case PV_AR:
9895 buf->b_p_ar = -1;
9896 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009897 case PV_BKC:
9898 clear_string_option(&buf->b_p_bkc);
9899 buf->b_bkc_flags = 0;
9900 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009901 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009902 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009903 break;
9904#ifdef FEAT_FIND_ID
9905 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009906 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009907 break;
9908 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009909 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009910 break;
9911#endif
9912#ifdef FEAT_INS_EXPAND
9913 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009914 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009915 break;
9916 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009917 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009918 break;
9919#endif
9920#ifdef FEAT_QUICKFIX
9921 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009922 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009923 break;
9924 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009925 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009926 break;
9927 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009928 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009929 break;
9930#endif
9931#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9932 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009933 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009934 break;
9935#endif
9936#if defined(FEAT_CRYPT)
9937 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009938 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009939 break;
9940#endif
9941#ifdef FEAT_STL_OPT
9942 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009943 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009944 break;
9945#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009946 case PV_UL:
9947 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9948 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009949#ifdef FEAT_LISP
9950 case PV_LW:
9951 clear_string_option(&buf->b_p_lw);
9952 break;
9953#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009954 }
9955}
9956
9957/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958 * Get pointer to option variable, depending on local or global scope.
9959 */
9960 static char_u *
9961get_varp_scope(p, opt_flags)
9962 struct vimoption *p;
9963 int opt_flags;
9964{
9965 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9966 {
9967 if (p->var == VAR_WIN)
9968 return (char_u *)GLOBAL_WO(get_varp(p));
9969 return p->var;
9970 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009971 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009972 {
9973 switch ((int)p->indir)
9974 {
9975#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009976 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9977 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9978 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009979#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009980 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9981 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9982 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009983 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009984 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009985#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009986 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9987 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009988#endif
9989#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009990 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9991 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009993#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9994 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9995#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009996#if defined(FEAT_CRYPT)
9997 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9998#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009999#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010000 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010001#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010002 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010003#ifdef FEAT_LISP
10004 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10005#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010006 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010007 }
10008 return NULL; /* "cannot happen" */
10009 }
10010 return get_varp(p);
10011}
10012
10013/*
10014 * Get pointer to option variable.
10015 */
10016 static char_u *
10017get_varp(p)
10018 struct vimoption *p;
10019{
10020 /* hidden option, always return NULL */
10021 if (p->var == NULL)
10022 return NULL;
10023
10024 switch ((int)p->indir)
10025 {
10026 case PV_NONE: return p->var;
10027
10028 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010029 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010030 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010031 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010032 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010033 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010035 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010036 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010037 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010038 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010039 case PV_BKC: return *curbuf->b_p_bkc != NUL
10040 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010041#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010042 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010043 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010044 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010045 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10046#endif
10047#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010048 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010049 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010050 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010051 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10052#endif
10053#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010054 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010055 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010056 case PV_GP: return *curbuf->b_p_gp != NUL
10057 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10058 case PV_MP: return *curbuf->b_p_mp != NUL
10059 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010060#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010061#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10062 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10063 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10064#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010065#if defined(FEAT_CRYPT)
10066 case PV_CM: return *curbuf->b_p_cm != NUL
10067 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10068#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010069#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010070 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010071 ? (char_u *)&(curwin->w_p_stl) : p->var;
10072#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010073 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10074 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010075#ifdef FEAT_LISP
10076 case PV_LW: return *curbuf->b_p_lw != NUL
10077 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10078#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010079
10080#ifdef FEAT_ARABIC
10081 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10082#endif
10083 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010084#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010085 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10086#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010087#ifdef FEAT_SYN_HL
10088 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10089 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010090 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010091#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010092#ifdef FEAT_DIFF
10093 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10094#endif
10095#ifdef FEAT_FOLDING
10096 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10097 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10098 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10099 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10100 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10101 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10102 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10103# ifdef FEAT_EVAL
10104 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10105 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10106# endif
10107 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10108#endif
10109 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010110 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010111#ifdef FEAT_LINEBREAK
10112 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10113#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010114#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010115 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10116#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010117#ifdef FEAT_VERTSPLIT
10118 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10119#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10121 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10122#endif
10123#ifdef FEAT_RIGHTLEFT
10124 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10125 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10126#endif
10127 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10128 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10129#ifdef FEAT_LINEBREAK
10130 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010131 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10132 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133#endif
10134#ifdef FEAT_SCROLLBIND
10135 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10136#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010137#ifdef FEAT_CURSORBIND
10138 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10139#endif
10140#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010141 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10142 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010143#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010144
10145 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10146 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10147#ifdef FEAT_MBYTE
10148 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10149#endif
10150#if defined(FEAT_QUICKFIX)
10151 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10152 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10153#endif
10154 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10155 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10156#ifdef FEAT_CINDENT
10157 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10158 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10159 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10160#endif
10161#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10162 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10163#endif
10164#ifdef FEAT_COMMENTS
10165 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10166#endif
10167#ifdef FEAT_FOLDING
10168 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10169#endif
10170#ifdef FEAT_INS_EXPAND
10171 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10172#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010173#ifdef FEAT_COMPL_FUNC
10174 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010175 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010176#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010177 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10178 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10179#ifdef FEAT_MBYTE
10180 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10181#endif
10182 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10183#ifdef FEAT_AUTOCMD
10184 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10185#endif
10186 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010187 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10189 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10190 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10191 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10192#ifdef FEAT_FIND_ID
10193# ifdef FEAT_EVAL
10194 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10195# endif
10196#endif
10197#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10198 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10199 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10200#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010201#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010202 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10203#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204#ifdef FEAT_CRYPT
10205 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10206#endif
10207#ifdef FEAT_LISP
10208 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10209#endif
10210 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10211 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10212 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10213 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10214 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010216#ifdef FEAT_TEXTOBJ
10217 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10218#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010219 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10220#ifdef FEAT_SMARTINDENT
10221 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10222#endif
10223#ifndef SHORT_FNAME
10224 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10225#endif
10226 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10227#ifdef FEAT_SEARCHPATH
10228 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10229#endif
10230 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10231#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010232 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010233 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10234#endif
10235#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010236 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10237 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10238 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239#endif
10240 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10241 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10242 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10243 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010244#ifdef FEAT_PERSISTENT_UNDO
10245 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10246#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10248#ifdef FEAT_KEYMAP
10249 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10250#endif
10251 default: EMSG(_("E356: get_varp ERROR"));
10252 }
10253 /* always return a valid pointer to avoid a crash! */
10254 return (char_u *)&(curbuf->b_p_wm);
10255}
10256
10257/*
10258 * Get the value of 'equalprg', either the buffer-local one or the global one.
10259 */
10260 char_u *
10261get_equalprg()
10262{
10263 if (*curbuf->b_p_ep == NUL)
10264 return p_ep;
10265 return curbuf->b_p_ep;
10266}
10267
10268#if defined(FEAT_WINDOWS) || defined(PROTO)
10269/*
10270 * Copy options from one window to another.
10271 * Used when splitting a window.
10272 */
10273 void
10274win_copy_options(wp_from, wp_to)
10275 win_T *wp_from;
10276 win_T *wp_to;
10277{
10278 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10279 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10280# ifdef FEAT_RIGHTLEFT
10281# ifdef FEAT_FKMAP
10282 /* Is this right? */
10283 wp_to->w_farsi = wp_from->w_farsi;
10284# endif
10285# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010286#if defined(FEAT_LINEBREAK)
10287 briopt_check(wp_to);
10288#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010289}
10290#endif
10291
10292/*
10293 * Copy the options from one winopt_T to another.
10294 * Doesn't free the old option values in "to", use clear_winopt() for that.
10295 * The 'scroll' option is not copied, because it depends on the window height.
10296 * The 'previewwindow' option is reset, there can be only one preview window.
10297 */
10298 void
10299copy_winopt(from, to)
10300 winopt_T *from;
10301 winopt_T *to;
10302{
10303#ifdef FEAT_ARABIC
10304 to->wo_arab = from->wo_arab;
10305#endif
10306 to->wo_list = from->wo_list;
10307 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010308 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010309#ifdef FEAT_LINEBREAK
10310 to->wo_nuw = from->wo_nuw;
10311#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312#ifdef FEAT_RIGHTLEFT
10313 to->wo_rl = from->wo_rl;
10314 to->wo_rlc = vim_strsave(from->wo_rlc);
10315#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010316#ifdef FEAT_STL_OPT
10317 to->wo_stl = vim_strsave(from->wo_stl);
10318#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010320#ifdef FEAT_DIFF
10321 to->wo_wrap_save = from->wo_wrap_save;
10322#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323#ifdef FEAT_LINEBREAK
10324 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010325 to->wo_bri = from->wo_bri;
10326 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010327#endif
10328#ifdef FEAT_SCROLLBIND
10329 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010330 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010332#ifdef FEAT_CURSORBIND
10333 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010334 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010335#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010336#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010337 to->wo_spell = from->wo_spell;
10338#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010339#ifdef FEAT_SYN_HL
10340 to->wo_cuc = from->wo_cuc;
10341 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010342 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344#ifdef FEAT_DIFF
10345 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010346 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010347#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010348#ifdef FEAT_CONCEAL
10349 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010350 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010351#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352#ifdef FEAT_FOLDING
10353 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010354 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010355 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010356 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357 to->wo_fdi = vim_strsave(from->wo_fdi);
10358 to->wo_fml = from->wo_fml;
10359 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010360 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010361 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010362 to->wo_fdm_save = from->wo_diff_saved
10363 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010364 to->wo_fdn = from->wo_fdn;
10365# ifdef FEAT_EVAL
10366 to->wo_fde = vim_strsave(from->wo_fde);
10367 to->wo_fdt = vim_strsave(from->wo_fdt);
10368# endif
10369 to->wo_fmr = vim_strsave(from->wo_fmr);
10370#endif
10371 check_winopt(to); /* don't want NULL pointers */
10372}
10373
10374/*
10375 * Check string options in a window for a NULL value.
10376 */
10377 void
10378check_win_options(win)
10379 win_T *win;
10380{
10381 check_winopt(&win->w_onebuf_opt);
10382 check_winopt(&win->w_allbuf_opt);
10383}
10384
10385/*
10386 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10387 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010388 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010389check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010390 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010391{
10392#ifdef FEAT_FOLDING
10393 check_string_option(&wop->wo_fdi);
10394 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010395 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010396# ifdef FEAT_EVAL
10397 check_string_option(&wop->wo_fde);
10398 check_string_option(&wop->wo_fdt);
10399# endif
10400 check_string_option(&wop->wo_fmr);
10401#endif
10402#ifdef FEAT_RIGHTLEFT
10403 check_string_option(&wop->wo_rlc);
10404#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010405#ifdef FEAT_STL_OPT
10406 check_string_option(&wop->wo_stl);
10407#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010408#ifdef FEAT_SYN_HL
10409 check_string_option(&wop->wo_cc);
10410#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010411#ifdef FEAT_CONCEAL
10412 check_string_option(&wop->wo_cocu);
10413#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010414#ifdef FEAT_LINEBREAK
10415 check_string_option(&wop->wo_briopt);
10416#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010417}
10418
10419/*
10420 * Free the allocated memory inside a winopt_T.
10421 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010422 void
10423clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010424 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010425{
10426#ifdef FEAT_FOLDING
10427 clear_string_option(&wop->wo_fdi);
10428 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010429 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010430# ifdef FEAT_EVAL
10431 clear_string_option(&wop->wo_fde);
10432 clear_string_option(&wop->wo_fdt);
10433# endif
10434 clear_string_option(&wop->wo_fmr);
10435#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010436#ifdef FEAT_LINEBREAK
10437 clear_string_option(&wop->wo_briopt);
10438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439#ifdef FEAT_RIGHTLEFT
10440 clear_string_option(&wop->wo_rlc);
10441#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010442#ifdef FEAT_STL_OPT
10443 clear_string_option(&wop->wo_stl);
10444#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010445#ifdef FEAT_SYN_HL
10446 clear_string_option(&wop->wo_cc);
10447#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010448#ifdef FEAT_CONCEAL
10449 clear_string_option(&wop->wo_cocu);
10450#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010451}
10452
10453/*
10454 * Copy global option values to local options for one buffer.
10455 * Used when creating a new buffer and sometimes when entering a buffer.
10456 * flags:
10457 * BCO_ENTER We will enter the buf buffer.
10458 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10459 * appropriate.
10460 * BCO_NOHELP Don't copy the values to a help buffer.
10461 */
10462 void
10463buf_copy_options(buf, flags)
10464 buf_T *buf;
10465 int flags;
10466{
10467 int should_copy = TRUE;
10468 char_u *save_p_isk = NULL; /* init for GCC */
10469 int dont_do_help;
10470 int did_isk = FALSE;
10471
10472 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010473 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010474 */
10475 if (buf == NULL || !buf_valid(buf))
10476 return;
10477
10478 /*
10479 * Skip this when the option defaults have not been set yet. Happens when
10480 * main() allocates the first buffer.
10481 */
10482 if (p_cpo != NULL)
10483 {
10484 /*
10485 * Always copy when entering and 'cpo' contains 'S'.
10486 * Don't copy when already initialized.
10487 * Don't copy when 'cpo' contains 's' and not entering.
10488 * 'S' BCO_ENTER initialized 's' should_copy
10489 * yes yes X X TRUE
10490 * yes no yes X FALSE
10491 * no X yes X FALSE
10492 * X no no yes FALSE
10493 * X no no no TRUE
10494 * no yes no X TRUE
10495 */
10496 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10497 && (buf->b_p_initialized
10498 || (!(flags & BCO_ENTER)
10499 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10500 should_copy = FALSE;
10501
10502 if (should_copy || (flags & BCO_ALWAYS))
10503 {
10504 /* Don't copy the options specific to a help buffer when
10505 * BCO_NOHELP is given or the options were initialized already
10506 * (jumping back to a help file with CTRL-T or CTRL-O) */
10507 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10508 || buf->b_p_initialized;
10509 if (dont_do_help) /* don't free b_p_isk */
10510 {
10511 save_p_isk = buf->b_p_isk;
10512 buf->b_p_isk = NULL;
10513 }
10514 /*
10515 * Always free the allocated strings.
10516 * If not already initialized, set 'readonly' and copy 'fileformat'.
10517 */
10518 if (!buf->b_p_initialized)
10519 {
10520 free_buf_options(buf, TRUE);
10521 buf->b_p_ro = FALSE; /* don't copy readonly */
10522 buf->b_p_tx = p_tx;
10523#ifdef FEAT_MBYTE
10524 buf->b_p_fenc = vim_strsave(p_fenc);
10525#endif
10526 buf->b_p_ff = vim_strsave(p_ff);
10527#if defined(FEAT_QUICKFIX)
10528 buf->b_p_bh = empty_option;
10529 buf->b_p_bt = empty_option;
10530#endif
10531 }
10532 else
10533 free_buf_options(buf, FALSE);
10534
10535 buf->b_p_ai = p_ai;
10536 buf->b_p_ai_nopaste = p_ai_nopaste;
10537 buf->b_p_sw = p_sw;
10538 buf->b_p_tw = p_tw;
10539 buf->b_p_tw_nopaste = p_tw_nopaste;
10540 buf->b_p_tw_nobin = p_tw_nobin;
10541 buf->b_p_wm = p_wm;
10542 buf->b_p_wm_nopaste = p_wm_nopaste;
10543 buf->b_p_wm_nobin = p_wm_nobin;
10544 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010545#ifdef FEAT_MBYTE
10546 buf->b_p_bomb = p_bomb;
10547#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548 buf->b_p_et = p_et;
10549 buf->b_p_et_nobin = p_et_nobin;
10550 buf->b_p_ml = p_ml;
10551 buf->b_p_ml_nobin = p_ml_nobin;
10552 buf->b_p_inf = p_inf;
10553 buf->b_p_swf = p_swf;
10554#ifdef FEAT_INS_EXPAND
10555 buf->b_p_cpt = vim_strsave(p_cpt);
10556#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010557#ifdef FEAT_COMPL_FUNC
10558 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010559 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010560#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010561 buf->b_p_sts = p_sts;
10562 buf->b_p_sts_nopaste = p_sts_nopaste;
10563#ifndef SHORT_FNAME
10564 buf->b_p_sn = p_sn;
10565#endif
10566#ifdef FEAT_COMMENTS
10567 buf->b_p_com = vim_strsave(p_com);
10568#endif
10569#ifdef FEAT_FOLDING
10570 buf->b_p_cms = vim_strsave(p_cms);
10571#endif
10572 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010573 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574 buf->b_p_nf = vim_strsave(p_nf);
10575 buf->b_p_mps = vim_strsave(p_mps);
10576#ifdef FEAT_SMARTINDENT
10577 buf->b_p_si = p_si;
10578#endif
10579 buf->b_p_ci = p_ci;
10580#ifdef FEAT_CINDENT
10581 buf->b_p_cin = p_cin;
10582 buf->b_p_cink = vim_strsave(p_cink);
10583 buf->b_p_cino = vim_strsave(p_cino);
10584#endif
10585#ifdef FEAT_AUTOCMD
10586 /* Don't copy 'filetype', it must be detected */
10587 buf->b_p_ft = empty_option;
10588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 buf->b_p_pi = p_pi;
10590#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10591 buf->b_p_cinw = vim_strsave(p_cinw);
10592#endif
10593#ifdef FEAT_LISP
10594 buf->b_p_lisp = p_lisp;
10595#endif
10596#ifdef FEAT_SYN_HL
10597 /* Don't copy 'syntax', it must be set */
10598 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010599 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010600#endif
10601#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010602 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010603 (void)compile_cap_prog(&buf->b_s);
10604 buf->b_s.b_p_spf = vim_strsave(p_spf);
10605 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606#endif
10607#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10608 buf->b_p_inde = vim_strsave(p_inde);
10609 buf->b_p_indk = vim_strsave(p_indk);
10610#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010611#if defined(FEAT_EVAL)
10612 buf->b_p_fex = vim_strsave(p_fex);
10613#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010614#ifdef FEAT_CRYPT
10615 buf->b_p_key = vim_strsave(p_key);
10616#endif
10617#ifdef FEAT_SEARCHPATH
10618 buf->b_p_sua = vim_strsave(p_sua);
10619#endif
10620#ifdef FEAT_KEYMAP
10621 buf->b_p_keymap = vim_strsave(p_keymap);
10622 buf->b_kmap_state |= KEYMAP_INIT;
10623#endif
10624 /* This isn't really an option, but copying the langmap and IME
10625 * state from the current buffer is better than resetting it. */
10626 buf->b_p_iminsert = p_iminsert;
10627 buf->b_p_imsearch = p_imsearch;
10628
10629 /* options that are normally global but also have a local value
10630 * are not copied, start using the global value */
10631 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010632 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010633 buf->b_p_bkc = empty_option;
10634 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010635#ifdef FEAT_QUICKFIX
10636 buf->b_p_gp = empty_option;
10637 buf->b_p_mp = empty_option;
10638 buf->b_p_efm = empty_option;
10639#endif
10640 buf->b_p_ep = empty_option;
10641 buf->b_p_kp = empty_option;
10642 buf->b_p_path = empty_option;
10643 buf->b_p_tags = empty_option;
10644#ifdef FEAT_FIND_ID
10645 buf->b_p_def = empty_option;
10646 buf->b_p_inc = empty_option;
10647# ifdef FEAT_EVAL
10648 buf->b_p_inex = vim_strsave(p_inex);
10649# endif
10650#endif
10651#ifdef FEAT_INS_EXPAND
10652 buf->b_p_dict = empty_option;
10653 buf->b_p_tsr = empty_option;
10654#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010655#ifdef FEAT_TEXTOBJ
10656 buf->b_p_qe = vim_strsave(p_qe);
10657#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010658#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10659 buf->b_p_bexpr = empty_option;
10660#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010661#if defined(FEAT_CRYPT)
10662 buf->b_p_cm = empty_option;
10663#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010664#ifdef FEAT_PERSISTENT_UNDO
10665 buf->b_p_udf = p_udf;
10666#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010667#ifdef FEAT_LISP
10668 buf->b_p_lw = empty_option;
10669#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010670
10671 /*
10672 * Don't copy the options set by ex_help(), use the saved values,
10673 * when going from a help buffer to a non-help buffer.
10674 * Don't touch these at all when BCO_NOHELP is used and going from
10675 * or to a help buffer.
10676 */
10677 if (dont_do_help)
10678 buf->b_p_isk = save_p_isk;
10679 else
10680 {
10681 buf->b_p_isk = vim_strsave(p_isk);
10682 did_isk = TRUE;
10683 buf->b_p_ts = p_ts;
10684 buf->b_help = FALSE;
10685#ifdef FEAT_QUICKFIX
10686 if (buf->b_p_bt[0] == 'h')
10687 clear_string_option(&buf->b_p_bt);
10688#endif
10689 buf->b_p_ma = p_ma;
10690 }
10691 }
10692
10693 /*
10694 * When the options should be copied (ignoring BCO_ALWAYS), set the
10695 * flag that indicates that the options have been initialized.
10696 */
10697 if (should_copy)
10698 buf->b_p_initialized = TRUE;
10699 }
10700
10701 check_buf_options(buf); /* make sure we don't have NULLs */
10702 if (did_isk)
10703 (void)buf_init_chartab(buf, FALSE);
10704}
10705
10706/*
10707 * Reset the 'modifiable' option and its default value.
10708 */
10709 void
10710reset_modifiable()
10711{
10712 int opt_idx;
10713
10714 curbuf->b_p_ma = FALSE;
10715 p_ma = FALSE;
10716 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010717 if (opt_idx >= 0)
10718 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010719}
10720
10721/*
10722 * Set the global value for 'iminsert' to the local value.
10723 */
10724 void
10725set_iminsert_global()
10726{
10727 p_iminsert = curbuf->b_p_iminsert;
10728}
10729
10730/*
10731 * Set the global value for 'imsearch' to the local value.
10732 */
10733 void
10734set_imsearch_global()
10735{
10736 p_imsearch = curbuf->b_p_imsearch;
10737}
10738
10739#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10740static int expand_option_idx = -1;
10741static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10742static int expand_option_flags = 0;
10743
10744 void
10745set_context_in_set_cmd(xp, arg, opt_flags)
10746 expand_T *xp;
10747 char_u *arg;
10748 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10749{
10750 int nextchar;
10751 long_u flags = 0; /* init for GCC */
10752 int opt_idx = 0; /* init for GCC */
10753 char_u *p;
10754 char_u *s;
10755 int is_term_option = FALSE;
10756 int key;
10757
10758 expand_option_flags = opt_flags;
10759
10760 xp->xp_context = EXPAND_SETTINGS;
10761 if (*arg == NUL)
10762 {
10763 xp->xp_pattern = arg;
10764 return;
10765 }
10766 p = arg + STRLEN(arg) - 1;
10767 if (*p == ' ' && *(p - 1) != '\\')
10768 {
10769 xp->xp_pattern = p + 1;
10770 return;
10771 }
10772 while (p > arg)
10773 {
10774 s = p;
10775 /* count number of backslashes before ' ' or ',' */
10776 if (*p == ' ' || *p == ',')
10777 {
10778 while (s > arg && *(s - 1) == '\\')
10779 --s;
10780 }
10781 /* break at a space with an even number of backslashes */
10782 if (*p == ' ' && ((p - s) & 1) == 0)
10783 {
10784 ++p;
10785 break;
10786 }
10787 --p;
10788 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010789 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010790 {
10791 xp->xp_context = EXPAND_BOOL_SETTINGS;
10792 p += 2;
10793 }
10794 if (STRNCMP(p, "inv", 3) == 0)
10795 {
10796 xp->xp_context = EXPAND_BOOL_SETTINGS;
10797 p += 3;
10798 }
10799 xp->xp_pattern = arg = p;
10800 if (*arg == '<')
10801 {
10802 while (*p != '>')
10803 if (*p++ == NUL) /* expand terminal option name */
10804 return;
10805 key = get_special_key_code(arg + 1);
10806 if (key == 0) /* unknown name */
10807 {
10808 xp->xp_context = EXPAND_NOTHING;
10809 return;
10810 }
10811 nextchar = *++p;
10812 is_term_option = TRUE;
10813 expand_option_name[2] = KEY2TERMCAP0(key);
10814 expand_option_name[3] = KEY2TERMCAP1(key);
10815 }
10816 else
10817 {
10818 if (p[0] == 't' && p[1] == '_')
10819 {
10820 p += 2;
10821 if (*p != NUL)
10822 ++p;
10823 if (*p == NUL)
10824 return; /* expand option name */
10825 nextchar = *++p;
10826 is_term_option = TRUE;
10827 expand_option_name[2] = p[-2];
10828 expand_option_name[3] = p[-1];
10829 }
10830 else
10831 {
10832 /* Allow * wildcard */
10833 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10834 p++;
10835 if (*p == NUL)
10836 return;
10837 nextchar = *p;
10838 *p = NUL;
10839 opt_idx = findoption(arg);
10840 *p = nextchar;
10841 if (opt_idx == -1 || options[opt_idx].var == NULL)
10842 {
10843 xp->xp_context = EXPAND_NOTHING;
10844 return;
10845 }
10846 flags = options[opt_idx].flags;
10847 if (flags & P_BOOL)
10848 {
10849 xp->xp_context = EXPAND_NOTHING;
10850 return;
10851 }
10852 }
10853 }
10854 /* handle "-=" and "+=" */
10855 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10856 {
10857 ++p;
10858 nextchar = '=';
10859 }
10860 if ((nextchar != '=' && nextchar != ':')
10861 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10862 {
10863 xp->xp_context = EXPAND_UNSUCCESSFUL;
10864 return;
10865 }
10866 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10867 {
10868 xp->xp_context = EXPAND_OLD_SETTING;
10869 if (is_term_option)
10870 expand_option_idx = -1;
10871 else
10872 expand_option_idx = opt_idx;
10873 xp->xp_pattern = p + 1;
10874 return;
10875 }
10876 xp->xp_context = EXPAND_NOTHING;
10877 if (is_term_option || (flags & P_NUM))
10878 return;
10879
10880 xp->xp_pattern = p + 1;
10881
10882 if (flags & P_EXPAND)
10883 {
10884 p = options[opt_idx].var;
10885 if (p == (char_u *)&p_bdir
10886 || p == (char_u *)&p_dir
10887 || p == (char_u *)&p_path
10888 || p == (char_u *)&p_rtp
10889#ifdef FEAT_SEARCHPATH
10890 || p == (char_u *)&p_cdpath
10891#endif
10892#ifdef FEAT_SESSION
10893 || p == (char_u *)&p_vdir
10894#endif
10895 )
10896 {
10897 xp->xp_context = EXPAND_DIRECTORIES;
10898 if (p == (char_u *)&p_path
10899#ifdef FEAT_SEARCHPATH
10900 || p == (char_u *)&p_cdpath
10901#endif
10902 )
10903 xp->xp_backslash = XP_BS_THREE;
10904 else
10905 xp->xp_backslash = XP_BS_ONE;
10906 }
10907 else
10908 {
10909 xp->xp_context = EXPAND_FILES;
10910 /* for 'tags' need three backslashes for a space */
10911 if (p == (char_u *)&p_tags)
10912 xp->xp_backslash = XP_BS_THREE;
10913 else
10914 xp->xp_backslash = XP_BS_ONE;
10915 }
10916 }
10917
10918 /* For an option that is a list of file names, find the start of the
10919 * last file name. */
10920 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10921 {
10922 /* count number of backslashes before ' ' or ',' */
10923 if (*p == ' ' || *p == ',')
10924 {
10925 s = p;
10926 while (s > xp->xp_pattern && *(s - 1) == '\\')
10927 --s;
10928 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10929 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10930 {
10931 xp->xp_pattern = p + 1;
10932 break;
10933 }
10934 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010935
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010936#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010937 /* for 'spellsuggest' start at "file:" */
10938 if (options[opt_idx].var == (char_u *)&p_sps
10939 && STRNCMP(p, "file:", 5) == 0)
10940 {
10941 xp->xp_pattern = p + 5;
10942 break;
10943 }
10944#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945 }
10946
10947 return;
10948}
10949
10950 int
10951ExpandSettings(xp, regmatch, num_file, file)
10952 expand_T *xp;
10953 regmatch_T *regmatch;
10954 int *num_file;
10955 char_u ***file;
10956{
10957 int num_normal = 0; /* Nr of matching non-term-code settings */
10958 int num_term = 0; /* Nr of matching terminal code settings */
10959 int opt_idx;
10960 int match;
10961 int count = 0;
10962 char_u *str;
10963 int loop;
10964 int is_term_opt;
10965 char_u name_buf[MAX_KEY_NAME_LEN];
10966 static char *(names[]) = {"all", "termcap"};
10967 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10968
10969 /* do this loop twice:
10970 * loop == 0: count the number of matching options
10971 * loop == 1: copy the matching options into allocated memory
10972 */
10973 for (loop = 0; loop <= 1; ++loop)
10974 {
10975 regmatch->rm_ic = ic;
10976 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10977 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010978 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10979 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010980 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10981 {
10982 if (loop == 0)
10983 num_normal++;
10984 else
10985 (*file)[count++] = vim_strsave((char_u *)names[match]);
10986 }
10987 }
10988 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10989 opt_idx++)
10990 {
10991 if (options[opt_idx].var == NULL)
10992 continue;
10993 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10994 && !(options[opt_idx].flags & P_BOOL))
10995 continue;
10996 is_term_opt = istermoption(&options[opt_idx]);
10997 if (is_term_opt && num_normal > 0)
10998 continue;
10999 match = FALSE;
11000 if (vim_regexec(regmatch, str, (colnr_T)0)
11001 || (options[opt_idx].shortname != NULL
11002 && vim_regexec(regmatch,
11003 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11004 match = TRUE;
11005 else if (is_term_opt)
11006 {
11007 name_buf[0] = '<';
11008 name_buf[1] = 't';
11009 name_buf[2] = '_';
11010 name_buf[3] = str[2];
11011 name_buf[4] = str[3];
11012 name_buf[5] = '>';
11013 name_buf[6] = NUL;
11014 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11015 {
11016 match = TRUE;
11017 str = name_buf;
11018 }
11019 }
11020 if (match)
11021 {
11022 if (loop == 0)
11023 {
11024 if (is_term_opt)
11025 num_term++;
11026 else
11027 num_normal++;
11028 }
11029 else
11030 (*file)[count++] = vim_strsave(str);
11031 }
11032 }
11033 /*
11034 * Check terminal key codes, these are not in the option table
11035 */
11036 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11037 {
11038 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11039 {
11040 if (!isprint(str[0]) || !isprint(str[1]))
11041 continue;
11042
11043 name_buf[0] = 't';
11044 name_buf[1] = '_';
11045 name_buf[2] = str[0];
11046 name_buf[3] = str[1];
11047 name_buf[4] = NUL;
11048
11049 match = FALSE;
11050 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11051 match = TRUE;
11052 else
11053 {
11054 name_buf[0] = '<';
11055 name_buf[1] = 't';
11056 name_buf[2] = '_';
11057 name_buf[3] = str[0];
11058 name_buf[4] = str[1];
11059 name_buf[5] = '>';
11060 name_buf[6] = NUL;
11061
11062 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11063 match = TRUE;
11064 }
11065 if (match)
11066 {
11067 if (loop == 0)
11068 num_term++;
11069 else
11070 (*file)[count++] = vim_strsave(name_buf);
11071 }
11072 }
11073
11074 /*
11075 * Check special key names.
11076 */
11077 regmatch->rm_ic = TRUE; /* ignore case here */
11078 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11079 {
11080 name_buf[0] = '<';
11081 STRCPY(name_buf + 1, str);
11082 STRCAT(name_buf, ">");
11083
11084 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11085 {
11086 if (loop == 0)
11087 num_term++;
11088 else
11089 (*file)[count++] = vim_strsave(name_buf);
11090 }
11091 }
11092 }
11093 if (loop == 0)
11094 {
11095 if (num_normal > 0)
11096 *num_file = num_normal;
11097 else if (num_term > 0)
11098 *num_file = num_term;
11099 else
11100 return OK;
11101 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11102 if (*file == NULL)
11103 {
11104 *file = (char_u **)"";
11105 return FAIL;
11106 }
11107 }
11108 }
11109 return OK;
11110}
11111
11112 int
11113ExpandOldSetting(num_file, file)
11114 int *num_file;
11115 char_u ***file;
11116{
11117 char_u *var = NULL; /* init for GCC */
11118 char_u *buf;
11119
11120 *num_file = 0;
11121 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11122 if (*file == NULL)
11123 return FAIL;
11124
11125 /*
11126 * For a terminal key code expand_option_idx is < 0.
11127 */
11128 if (expand_option_idx < 0)
11129 {
11130 var = find_termcode(expand_option_name + 2);
11131 if (var == NULL)
11132 expand_option_idx = findoption(expand_option_name);
11133 }
11134
11135 if (expand_option_idx >= 0)
11136 {
11137 /* put string of option value in NameBuff */
11138 option_value2string(&options[expand_option_idx], expand_option_flags);
11139 var = NameBuff;
11140 }
11141 else if (var == NULL)
11142 var = (char_u *)"";
11143
11144 /* A backslash is required before some characters. This is the reverse of
11145 * what happens in do_set(). */
11146 buf = vim_strsave_escaped(var, escape_chars);
11147
11148 if (buf == NULL)
11149 {
11150 vim_free(*file);
11151 *file = NULL;
11152 return FAIL;
11153 }
11154
11155#ifdef BACKSLASH_IN_FILENAME
11156 /* For MS-Windows et al. we don't double backslashes at the start and
11157 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011158 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011159 if (var[0] == '\\' && var[1] == '\\'
11160 && expand_option_idx >= 0
11161 && (options[expand_option_idx].flags & P_EXPAND)
11162 && vim_isfilec(var[2])
11163 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011164 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011165#endif
11166
11167 *file[0] = buf;
11168 *num_file = 1;
11169 return OK;
11170}
11171#endif
11172
11173/*
11174 * Get the value for the numeric or string option *opp in a nice format into
11175 * NameBuff[]. Must not be called with a hidden option!
11176 */
11177 static void
11178option_value2string(opp, opt_flags)
11179 struct vimoption *opp;
11180 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11181{
11182 char_u *varp;
11183
11184 varp = get_varp_scope(opp, opt_flags);
11185
11186 if (opp->flags & P_NUM)
11187 {
11188 long wc = 0;
11189
11190 if (wc_use_keyname(varp, &wc))
11191 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11192 else if (wc != 0)
11193 STRCPY(NameBuff, transchar((int)wc));
11194 else
11195 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11196 }
11197 else /* P_STRING */
11198 {
11199 varp = *(char_u **)(varp);
11200 if (varp == NULL) /* just in case */
11201 NameBuff[0] = NUL;
11202#ifdef FEAT_CRYPT
11203 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011204 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011205 STRCPY(NameBuff, "*****");
11206#endif
11207 else if (opp->flags & P_EXPAND)
11208 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11209 /* Translate 'pastetoggle' into special key names */
11210 else if ((char_u **)opp->var == &p_pt)
11211 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11212 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011213 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011214 }
11215}
11216
11217/*
11218 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11219 * printed as a keyname.
11220 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11221 */
11222 static int
11223wc_use_keyname(varp, wcp)
11224 char_u *varp;
11225 long *wcp;
11226{
11227 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11228 {
11229 *wcp = *(long *)varp;
11230 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11231 return TRUE;
11232 }
11233 return FALSE;
11234}
11235
Bram Moolenaar01615492015-02-03 13:00:38 +010011236#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011237/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011238 * Any character has an equivalent 'langmap' character. This is used for
11239 * keyboards that have a special language mode that sends characters above
11240 * 128 (although other characters can be translated too). The "to" field is a
11241 * Vim command character. This avoids having to switch the keyboard back to
11242 * ASCII mode when leaving Insert mode.
11243 *
11244 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11245 * commands.
11246 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11247 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11248 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011249 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011250# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011251/*
11252 * With multi-byte support use growarray for 'langmap' chars >= 256
11253 */
11254typedef struct
11255{
11256 int from;
11257 int to;
11258} langmap_entry_T;
11259
11260static garray_T langmap_mapga;
11261static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011262
11263/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011264 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11265 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011266 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011267 static void
11268langmap_set_entry(from, to)
11269 int from;
11270 int to;
11271{
11272 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011273 int a = 0;
11274 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011275
11276 /* Do a binary search for an existing entry. */
11277 while (a != b)
11278 {
11279 int i = (a + b) / 2;
11280 int d = entries[i].from - from;
11281
11282 if (d == 0)
11283 {
11284 entries[i].to = to;
11285 return;
11286 }
11287 if (d < 0)
11288 a = i + 1;
11289 else
11290 b = i;
11291 }
11292
11293 if (ga_grow(&langmap_mapga, 1) != OK)
11294 return; /* out of memory */
11295
11296 /* insert new entry at position "a" */
11297 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11298 mch_memmove(entries + 1, entries,
11299 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11300 ++langmap_mapga.ga_len;
11301 entries[0].from = from;
11302 entries[0].to = to;
11303}
11304
11305/*
11306 * Apply 'langmap' to multi-byte character "c" and return the result.
11307 */
11308 int
11309langmap_adjust_mb(c)
11310 int c;
11311{
11312 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11313 int a = 0;
11314 int b = langmap_mapga.ga_len;
11315
11316 while (a != b)
11317 {
11318 int i = (a + b) / 2;
11319 int d = entries[i].from - c;
11320
11321 if (d == 0)
11322 return entries[i].to; /* found matching entry */
11323 if (d < 0)
11324 a = i + 1;
11325 else
11326 b = i;
11327 }
11328 return c; /* no entry found, return "c" unmodified */
11329}
11330# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331
11332 static void
11333langmap_init()
11334{
11335 int i;
11336
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011337 for (i = 0; i < 256; i++)
11338 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11339# ifdef FEAT_MBYTE
11340 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11341# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342}
11343
11344/*
11345 * Called when langmap option is set; the language map can be
11346 * changed at any time!
11347 */
11348 static void
11349langmap_set()
11350{
11351 char_u *p;
11352 char_u *p2;
11353 int from, to;
11354
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011355#ifdef FEAT_MBYTE
11356 ga_clear(&langmap_mapga); /* clear the previous map first */
11357#endif
11358 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011359
11360 for (p = p_langmap; p[0] != NUL; )
11361 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011362 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11363 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011364 {
11365 if (p2[0] == '\\' && p2[1] != NUL)
11366 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011367 }
11368 if (p2[0] == ';')
11369 ++p2; /* abcd;ABCD form, p2 points to A */
11370 else
11371 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11372 while (p[0])
11373 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011374 if (p[0] == ',')
11375 {
11376 ++p;
11377 break;
11378 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011379 if (p[0] == '\\' && p[1] != NUL)
11380 ++p;
11381#ifdef FEAT_MBYTE
11382 from = (*mb_ptr2char)(p);
11383#else
11384 from = p[0];
11385#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011386 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387 if (p2 == NULL)
11388 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011389 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011390 if (p[0] != ',')
11391 {
11392 if (p[0] == '\\')
11393 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011394#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011395 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011396#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011397 to = p[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 else
11402 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011403 if (p2[0] != ',')
11404 {
11405 if (p2[0] == '\\')
11406 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011407#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011408 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011409#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011410 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011411#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011412 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011413 }
11414 if (to == NUL)
11415 {
11416 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11417 transchar(from));
11418 return;
11419 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011420
11421#ifdef FEAT_MBYTE
11422 if (from >= 256)
11423 langmap_set_entry(from, to);
11424 else
11425#endif
11426 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011427
11428 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011429 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011430 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011432 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011433 if (*p == ';')
11434 {
11435 p = p2;
11436 if (p[0] != NUL)
11437 {
11438 if (p[0] != ',')
11439 {
11440 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11441 return;
11442 }
11443 ++p;
11444 }
11445 break;
11446 }
11447 }
11448 }
11449 }
11450}
11451#endif
11452
11453/*
11454 * Return TRUE if format option 'x' is in effect.
11455 * Take care of no formatting when 'paste' is set.
11456 */
11457 int
11458has_format_option(x)
11459 int x;
11460{
11461 if (p_paste)
11462 return FALSE;
11463 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11464}
11465
11466/*
11467 * Return TRUE if "x" is present in 'shortmess' option, or
11468 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11469 */
11470 int
11471shortmess(x)
11472 int x;
11473{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011474 return p_shm != NULL &&
11475 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011476 || (vim_strchr(p_shm, 'a') != NULL
11477 && vim_strchr((char_u *)SHM_A, x) != NULL));
11478}
11479
11480/*
11481 * paste_option_changed() - Called after p_paste was set or reset.
11482 */
11483 static void
11484paste_option_changed()
11485{
11486 static int old_p_paste = FALSE;
11487 static int save_sm = 0;
11488#ifdef FEAT_CMDL_INFO
11489 static int save_ru = 0;
11490#endif
11491#ifdef FEAT_RIGHTLEFT
11492 static int save_ri = 0;
11493 static int save_hkmap = 0;
11494#endif
11495 buf_T *buf;
11496
11497 if (p_paste)
11498 {
11499 /*
11500 * Paste switched from off to on.
11501 * Save the current values, so they can be restored later.
11502 */
11503 if (!old_p_paste)
11504 {
11505 /* save options for each buffer */
11506 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11507 {
11508 buf->b_p_tw_nopaste = buf->b_p_tw;
11509 buf->b_p_wm_nopaste = buf->b_p_wm;
11510 buf->b_p_sts_nopaste = buf->b_p_sts;
11511 buf->b_p_ai_nopaste = buf->b_p_ai;
11512 }
11513
11514 /* save global options */
11515 save_sm = p_sm;
11516#ifdef FEAT_CMDL_INFO
11517 save_ru = p_ru;
11518#endif
11519#ifdef FEAT_RIGHTLEFT
11520 save_ri = p_ri;
11521 save_hkmap = p_hkmap;
11522#endif
11523 /* save global values for local buffer options */
11524 p_tw_nopaste = p_tw;
11525 p_wm_nopaste = p_wm;
11526 p_sts_nopaste = p_sts;
11527 p_ai_nopaste = p_ai;
11528 }
11529
11530 /*
11531 * Always set the option values, also when 'paste' is set when it is
11532 * already on.
11533 */
11534 /* set options for each buffer */
11535 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11536 {
11537 buf->b_p_tw = 0; /* textwidth is 0 */
11538 buf->b_p_wm = 0; /* wrapmargin is 0 */
11539 buf->b_p_sts = 0; /* softtabstop is 0 */
11540 buf->b_p_ai = 0; /* no auto-indent */
11541 }
11542
11543 /* set global options */
11544 p_sm = 0; /* no showmatch */
11545#ifdef FEAT_CMDL_INFO
11546# ifdef FEAT_WINDOWS
11547 if (p_ru)
11548 status_redraw_all(); /* redraw to remove the ruler */
11549# endif
11550 p_ru = 0; /* no ruler */
11551#endif
11552#ifdef FEAT_RIGHTLEFT
11553 p_ri = 0; /* no reverse insert */
11554 p_hkmap = 0; /* no Hebrew keyboard */
11555#endif
11556 /* set global values for local buffer options */
11557 p_tw = 0;
11558 p_wm = 0;
11559 p_sts = 0;
11560 p_ai = 0;
11561 }
11562
11563 /*
11564 * Paste switched from on to off: Restore saved values.
11565 */
11566 else if (old_p_paste)
11567 {
11568 /* restore options for each buffer */
11569 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11570 {
11571 buf->b_p_tw = buf->b_p_tw_nopaste;
11572 buf->b_p_wm = buf->b_p_wm_nopaste;
11573 buf->b_p_sts = buf->b_p_sts_nopaste;
11574 buf->b_p_ai = buf->b_p_ai_nopaste;
11575 }
11576
11577 /* restore global options */
11578 p_sm = save_sm;
11579#ifdef FEAT_CMDL_INFO
11580# ifdef FEAT_WINDOWS
11581 if (p_ru != save_ru)
11582 status_redraw_all(); /* redraw to draw the ruler */
11583# endif
11584 p_ru = save_ru;
11585#endif
11586#ifdef FEAT_RIGHTLEFT
11587 p_ri = save_ri;
11588 p_hkmap = save_hkmap;
11589#endif
11590 /* set global values for local buffer options */
11591 p_tw = p_tw_nopaste;
11592 p_wm = p_wm_nopaste;
11593 p_sts = p_sts_nopaste;
11594 p_ai = p_ai_nopaste;
11595 }
11596
11597 old_p_paste = p_paste;
11598}
11599
11600/*
11601 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11602 *
11603 * Reset 'compatible' and set the values for options that didn't get set yet
11604 * to the Vim defaults.
11605 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011606 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011607 */
11608 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011609vimrc_found(fname, envname)
11610 char_u *fname;
11611 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011612{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011613 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011614 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011615 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616
11617 if (!option_was_set((char_u *)"cp"))
11618 {
11619 p_cp = FALSE;
11620 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11621 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11622 set_option_default(opt_idx, OPT_FREE, FALSE);
11623 didset_options();
11624 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011625
11626 if (fname != NULL)
11627 {
11628 p = vim_getenv(envname, &dofree);
11629 if (p == NULL)
11630 {
11631 /* Set $MYVIMRC to the first vimrc file found. */
11632 p = FullName_save(fname, FALSE);
11633 if (p != NULL)
11634 {
11635 vim_setenv(envname, p);
11636 vim_free(p);
11637 }
11638 }
11639 else if (dofree)
11640 vim_free(p);
11641 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011642}
11643
11644/*
11645 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11646 */
11647 void
11648change_compatible(on)
11649 int on;
11650{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011651 int opt_idx;
11652
Bram Moolenaar071d4272004-06-13 20:20:40 +000011653 if (p_cp != on)
11654 {
11655 p_cp = on;
11656 compatible_set();
11657 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011658 opt_idx = findoption((char_u *)"cp");
11659 if (opt_idx >= 0)
11660 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011661}
11662
11663/*
11664 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011665 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011666 */
11667 int
11668option_was_set(name)
11669 char_u *name;
11670{
11671 int idx;
11672
11673 idx = findoption(name);
11674 if (idx < 0) /* unknown option */
11675 return FALSE;
11676 if (options[idx].flags & P_WAS_SET)
11677 return TRUE;
11678 return FALSE;
11679}
11680
11681/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011682 * Reset the flag indicating option "name" was set.
11683 */
11684 void
11685reset_option_was_set(name)
11686 char_u *name;
11687{
11688 int idx = findoption(name);
11689
11690 if (idx >= 0)
11691 options[idx].flags &= ~P_WAS_SET;
11692}
11693
11694/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011695 * compatible_set() - Called when 'compatible' has been set or unset.
11696 *
11697 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11698 * flag) to a Vi compatible value.
11699 * When 'compatible' is unset: Set all options that have a different default
11700 * for Vim (without the P_VI_DEF flag) to that default.
11701 */
11702 static void
11703compatible_set()
11704{
11705 int opt_idx;
11706
11707 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11708 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11709 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11710 set_option_default(opt_idx, OPT_FREE, p_cp);
11711 didset_options();
11712}
11713
11714#ifdef FEAT_LINEBREAK
11715
11716# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11717 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011718 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011719# endif
11720
11721/*
11722 * fill_breakat_flags() -- called when 'breakat' changes value.
11723 */
11724 static void
11725fill_breakat_flags()
11726{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011727 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011728 int i;
11729
11730 for (i = 0; i < 256; i++)
11731 breakat_flags[i] = FALSE;
11732
11733 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011734 for (p = p_breakat; *p; p++)
11735 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011736}
11737
11738# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011739 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011740# endif
11741
11742#endif
11743
11744/*
11745 * Check an option that can be a range of string values.
11746 *
11747 * Return OK for correct value, FAIL otherwise.
11748 * Empty is always OK.
11749 */
11750 static int
11751check_opt_strings(val, values, list)
11752 char_u *val;
11753 char **values;
11754 int list; /* when TRUE: accept a list of values */
11755{
11756 return opt_strings_flags(val, values, NULL, list);
11757}
11758
11759/*
11760 * Handle an option that can be a range of string values.
11761 * Set a flag in "*flagp" for each string present.
11762 *
11763 * Return OK for correct value, FAIL otherwise.
11764 * Empty is always OK.
11765 */
11766 static int
11767opt_strings_flags(val, values, flagp, list)
11768 char_u *val; /* new value */
11769 char **values; /* array of valid string values */
11770 unsigned *flagp;
11771 int list; /* when TRUE: accept a list of values */
11772{
11773 int i;
11774 int len;
11775 unsigned new_flags = 0;
11776
11777 while (*val)
11778 {
11779 for (i = 0; ; ++i)
11780 {
11781 if (values[i] == NULL) /* val not found in values[] */
11782 return FAIL;
11783
11784 len = (int)STRLEN(values[i]);
11785 if (STRNCMP(values[i], val, len) == 0
11786 && ((list && val[len] == ',') || val[len] == NUL))
11787 {
11788 val += len + (val[len] == ',');
11789 new_flags |= (1 << i);
11790 break; /* check next item in val list */
11791 }
11792 }
11793 }
11794 if (flagp != NULL)
11795 *flagp = new_flags;
11796
11797 return OK;
11798}
11799
11800/*
11801 * Read the 'wildmode' option, fill wim_flags[].
11802 */
11803 static int
11804check_opt_wim()
11805{
11806 char_u new_wim_flags[4];
11807 char_u *p;
11808 int i;
11809 int idx = 0;
11810
11811 for (i = 0; i < 4; ++i)
11812 new_wim_flags[i] = 0;
11813
11814 for (p = p_wim; *p; ++p)
11815 {
11816 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11817 ;
11818 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11819 return FAIL;
11820 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11821 new_wim_flags[idx] |= WIM_LONGEST;
11822 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11823 new_wim_flags[idx] |= WIM_FULL;
11824 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11825 new_wim_flags[idx] |= WIM_LIST;
11826 else
11827 return FAIL;
11828 p += i;
11829 if (*p == NUL)
11830 break;
11831 if (*p == ',')
11832 {
11833 if (idx == 3)
11834 return FAIL;
11835 ++idx;
11836 }
11837 }
11838
11839 /* fill remaining entries with last flag */
11840 while (idx < 3)
11841 {
11842 new_wim_flags[idx + 1] = new_wim_flags[idx];
11843 ++idx;
11844 }
11845
11846 /* only when there are no errors, wim_flags[] is changed */
11847 for (i = 0; i < 4; ++i)
11848 wim_flags[i] = new_wim_flags[i];
11849 return OK;
11850}
11851
11852/*
11853 * Check if backspacing over something is allowed.
11854 */
11855 int
11856can_bs(what)
11857 int what; /* BS_INDENT, BS_EOL or BS_START */
11858{
11859 switch (*p_bs)
11860 {
11861 case '2': return TRUE;
11862 case '1': return (what != BS_START);
11863 case '0': return FALSE;
11864 }
11865 return vim_strchr(p_bs, what) != NULL;
11866}
11867
11868/*
11869 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11870 * the file must be considered changed when the value is different.
11871 */
11872 void
11873save_file_ff(buf)
11874 buf_T *buf;
11875{
11876 buf->b_start_ffc = *buf->b_p_ff;
11877 buf->b_start_eol = buf->b_p_eol;
11878#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011879 buf->b_start_bomb = buf->b_p_bomb;
11880
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881 /* Only use free/alloc when necessary, they take time. */
11882 if (buf->b_start_fenc == NULL
11883 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11884 {
11885 vim_free(buf->b_start_fenc);
11886 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11887 }
11888#endif
11889}
11890
11891/*
11892 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11893 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011894 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11895 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011896 * When "ignore_empty" is true don't consider a new, empty buffer to be
11897 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011898 */
11899 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011900file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011902 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011903{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011904 /* In a buffer that was never loaded the options are not valid. */
11905 if (buf->b_flags & BF_NEVERLOADED)
11906 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011907 if (ignore_empty
11908 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011909 && buf->b_ml.ml_line_count == 1
11910 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11911 return FALSE;
11912 if (buf->b_start_ffc != *buf->b_p_ff)
11913 return TRUE;
11914 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11915 return TRUE;
11916#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011917 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11918 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011919 if (buf->b_start_fenc == NULL)
11920 return (*buf->b_p_fenc != NUL);
11921 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11922#else
11923 return FALSE;
11924#endif
11925}
11926
11927/*
11928 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11929 */
11930 int
11931check_ff_value(p)
11932 char_u *p;
11933{
11934 return check_opt_strings(p, p_ff_values, FALSE);
11935}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011936
11937/*
11938 * Return the effective shiftwidth value for current buffer, using the
11939 * 'tabstop' value when 'shiftwidth' is zero.
11940 */
11941 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011942get_sw_value(buf)
11943 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011944{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011945 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011946}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011947
11948/*
11949 * Return the effective softtabstop value for the current buffer, using the
11950 * 'tabstop' value when 'softtabstop' is negative.
11951 */
11952 long
11953get_sts_value()
11954{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011955 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011956}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011957
11958/*
11959 * Check matchpairs option for "*initc".
11960 * If there is a match set "*initc" to the matching character and "*findc" to
11961 * the opposite character. Set "*backwards" to the direction.
11962 * When "switchit" is TRUE swap the direction.
11963 */
11964 void
11965find_mps_values(initc, findc, backwards, switchit)
11966 int *initc;
11967 int *findc;
11968 int *backwards;
11969 int switchit;
11970{
11971 char_u *ptr;
11972
11973 ptr = curbuf->b_p_mps;
11974 while (*ptr != NUL)
11975 {
11976#ifdef FEAT_MBYTE
11977 if (has_mbyte)
11978 {
11979 char_u *prev;
11980
11981 if (mb_ptr2char(ptr) == *initc)
11982 {
11983 if (switchit)
11984 {
11985 *findc = *initc;
11986 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11987 *backwards = TRUE;
11988 }
11989 else
11990 {
11991 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11992 *backwards = FALSE;
11993 }
11994 return;
11995 }
11996 prev = ptr;
11997 ptr += mb_ptr2len(ptr) + 1;
11998 if (mb_ptr2char(ptr) == *initc)
11999 {
12000 if (switchit)
12001 {
12002 *findc = *initc;
12003 *initc = mb_ptr2char(prev);
12004 *backwards = FALSE;
12005 }
12006 else
12007 {
12008 *findc = mb_ptr2char(prev);
12009 *backwards = TRUE;
12010 }
12011 return;
12012 }
12013 ptr += mb_ptr2len(ptr);
12014 }
12015 else
12016#endif
12017 {
12018 if (*ptr == *initc)
12019 {
12020 if (switchit)
12021 {
12022 *backwards = TRUE;
12023 *findc = *initc;
12024 *initc = ptr[2];
12025 }
12026 else
12027 {
12028 *backwards = FALSE;
12029 *findc = ptr[2];
12030 }
12031 return;
12032 }
12033 ptr += 2;
12034 if (*ptr == *initc)
12035 {
12036 if (switchit)
12037 {
12038 *backwards = FALSE;
12039 *findc = *initc;
12040 *initc = ptr[-2];
12041 }
12042 else
12043 {
12044 *backwards = TRUE;
12045 *findc = ptr[-2];
12046 }
12047 return;
12048 }
12049 ++ptr;
12050 }
12051 if (*ptr == ',')
12052 ++ptr;
12053 }
12054}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012055
12056#if defined(FEAT_LINEBREAK) || defined(PROTO)
12057/*
12058 * This is called when 'breakindentopt' is changed and when a window is
12059 * initialized.
12060 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012061 static int
12062briopt_check(wp)
12063 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012064{
12065 char_u *p;
12066 int bri_shift = 0;
12067 long bri_min = 20;
12068 int bri_sbr = FALSE;
12069
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012070 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012071 while (*p != NUL)
12072 {
12073 if (STRNCMP(p, "shift:", 6) == 0
12074 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12075 {
12076 p += 6;
12077 bri_shift = getdigits(&p);
12078 }
12079 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12080 {
12081 p += 4;
12082 bri_min = getdigits(&p);
12083 }
12084 else if (STRNCMP(p, "sbr", 3) == 0)
12085 {
12086 p += 3;
12087 bri_sbr = TRUE;
12088 }
12089 if (*p != ',' && *p != NUL)
12090 return FAIL;
12091 if (*p == ',')
12092 ++p;
12093 }
12094
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012095 wp->w_p_brishift = bri_shift;
12096 wp->w_p_brimin = bri_min;
12097 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012098
12099 return OK;
12100}
12101#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012102
12103/*
12104 * Get the local or global value of 'backupcopy'.
12105 */
12106 unsigned int
12107get_bkc_value(buf)
12108 buf_T *buf;
12109{
12110 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12111}