blob: 2e805d785ba6d5036c4e212e24632cfb486574eb [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
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 p_term("t_da", T_DA)
2957 p_term("t_db", T_DB)
2958 p_term("t_DL", T_CDL)
2959 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002960 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961 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)
Bram Moolenaare5401222015-06-25 19:16:56 +02002974 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975 p_term("t_RI", T_CRI)
2976 p_term("t_RV", T_CRV)
2977 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002979 p_term("t_Sf", T_CSF)
2980 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02002982 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984 p_term("t_te", T_TE)
2985 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02002986 p_term("t_ts", T_TS)
2987 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 p_term("t_ue", T_UE)
2989 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02002990 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 p_term("t_vb", T_VB)
2992 p_term("t_ve", T_VE)
2993 p_term("t_vi", T_VI)
2994 p_term("t_vs", T_VS)
2995 p_term("t_WP", T_CWP)
2996 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01002997 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 p_term("t_xs", T_XS)
2999 p_term("t_ZH", T_CZH)
3000 p_term("t_ZR", T_CZR)
3001
3002/* terminal key codes are not in here */
3003
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003004 /* end marker */
3005 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006};
3007
3008#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3009
3010#ifdef FEAT_MBYTE
3011static char *(p_ambw_values[]) = {"single", "double", NULL};
3012#endif
3013static char *(p_bg_values[]) = {"light", "dark", NULL};
3014static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
3015static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003016#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003017static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003018#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003019#ifdef FEAT_CMDL_COMPL
3020static char *(p_wop_values[]) = {"tagfile", NULL};
3021#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022#ifdef FEAT_WAK
3023static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3024#endif
3025static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3027static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029#ifdef FEAT_BROWSE
3030static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3031#endif
3032#ifdef FEAT_SCROLLBIND
3033static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3034#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003035static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036#ifdef FEAT_VERTSPLIT
3037static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3038#endif
3039#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003040# ifdef FEAT_AUTOCMD
3041static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3042# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003044# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3046#endif
3047static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3048#ifdef FEAT_FOLDING
3049static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003050# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003052# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 NULL};
3054static char *(p_fcl_values[]) = {"all", NULL};
3055#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003056#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003057static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003058#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059
3060static void set_option_default __ARGS((int, int opt_flags, int compatible));
3061static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003062static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003063static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064static char_u *illegal_char __ARGS((char_u *, int));
3065static int string_to_key __ARGS((char_u *arg));
3066#ifdef FEAT_CMDWIN
3067static char_u *check_cedit __ARGS((void));
3068#endif
3069#ifdef FEAT_TITLE
3070static void did_set_title __ARGS((int icon));
3071#endif
3072static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3073static void didset_options __ARGS((void));
3074static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003075#if defined(FEAT_EVAL) || defined(PROTO)
3076static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3077#else
3078# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3079#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003081static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082static 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));
3083static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003084#ifdef FEAT_SYN_HL
3085static int int_cmp __ARGS((const void *a, const void *b));
3086#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087#ifdef FEAT_CLIPBOARD
3088static char_u *check_clipboard_option __ARGS((void));
3089#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003090#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003091static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003092#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003093#ifdef FEAT_EVAL
3094static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003097static 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 +00003098static void check_redraw __ARGS((long_u flags));
3099static int findoption __ARGS((char_u *));
3100static int find_key_option __ARGS((char_u *));
3101static void showoptions __ARGS((int all, int opt_flags));
3102static int optval_default __ARGS((struct vimoption *, char_u *varp));
3103static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3104static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3105static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3106static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3107static int istermoption __ARGS((struct vimoption *));
3108static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3109static char_u *get_varp __ARGS((struct vimoption *));
3110static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003111static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3113#ifdef FEAT_LANGMAP
3114static void langmap_init __ARGS((void));
3115static void langmap_set __ARGS((void));
3116#endif
3117static void paste_option_changed __ARGS((void));
3118static void compatible_set __ARGS((void));
3119#ifdef FEAT_LINEBREAK
3120static void fill_breakat_flags __ARGS((void));
3121#endif
3122static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3123static int check_opt_strings __ARGS((char_u *val, char **values, int));
3124static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003125#ifdef FEAT_LINEBREAK
3126static int briopt_check __ARGS((win_T *wp));
3127#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128
3129/*
3130 * Initialize the options, first part.
3131 *
3132 * Called only once from main(), just after creating the first buffer.
3133 */
3134 void
3135set_init_1()
3136{
3137 char_u *p;
3138 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003139 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140
3141#ifdef FEAT_LANGMAP
3142 langmap_init();
3143#endif
3144
3145 /* Be Vi compatible by default */
3146 p_cp = TRUE;
3147
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003148 /* Use POSIX compatibility when $VIM_POSIX is set. */
3149 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003150 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003151 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003152 set_string_default("shm", (char_u *)"A");
3153 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003154
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 /*
3156 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003157 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003159 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3161# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003162 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003164 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003166 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167# endif
3168#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003169 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 set_string_default("sh", p);
3171
3172#ifdef FEAT_WILDIGN
3173 /*
3174 * Set the default for 'backupskip' to include environment variables for
3175 * temp files.
3176 */
3177 {
3178# ifdef UNIX
3179 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3180# else
3181 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3182# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003183 int len;
3184 garray_T ga;
3185 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186
3187 ga_init2(&ga, 1, 100);
3188 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3189 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003190 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191# ifdef UNIX
3192 if (*names[n] == NUL)
3193 p = (char_u *)"/tmp";
3194 else
3195# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003196 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 if (p != NULL && *p != NUL)
3198 {
3199 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003200 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201 if (ga_grow(&ga, len) == OK)
3202 {
3203 if (ga.ga_len > 0)
3204 STRCAT(ga.ga_data, ",");
3205 STRCAT(ga.ga_data, p);
3206 add_pathsep(ga.ga_data);
3207 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208 ga.ga_len += len;
3209 }
3210 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003211 if (mustfree)
3212 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213 }
3214 if (ga.ga_data != NULL)
3215 {
3216 set_string_default("bsk", ga.ga_data);
3217 vim_free(ga.ga_data);
3218 }
3219 }
3220#endif
3221
3222 /*
3223 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3224 */
3225 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003226 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003228#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3229 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3230#endif
3231 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003233 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003234 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235#else
3236# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003237 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003238 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003240 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003241# endif
3242#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003244 opt_idx = findoption((char_u *)"maxmem");
3245 if (opt_idx >= 0)
3246 {
3247#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003248 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003249 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3250#endif
3251 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3252 }
3253 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254 }
3255
3256#ifdef FEAT_GUI_W32
3257 /* force 'shortname' for Win32s */
3258 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 {
3260 opt_idx = findoption((char_u *)"shortname");
3261 if (opt_idx >= 0)
3262 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3263 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264#endif
3265
3266#ifdef FEAT_SEARCHPATH
3267 {
3268 char_u *cdpath;
3269 char_u *buf;
3270 int i;
3271 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003272 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273
3274 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003275 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276 if (cdpath != NULL)
3277 {
3278 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3279 if (buf != NULL)
3280 {
3281 buf[0] = ','; /* start with ",", current dir first */
3282 j = 1;
3283 for (i = 0; cdpath[i] != NUL; ++i)
3284 {
3285 if (vim_ispathlistsep(cdpath[i]))
3286 buf[j++] = ',';
3287 else
3288 {
3289 if (cdpath[i] == ' ' || cdpath[i] == ',')
3290 buf[j++] = '\\';
3291 buf[j++] = cdpath[i];
3292 }
3293 }
3294 buf[j] = NUL;
3295 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003296 if (opt_idx >= 0)
3297 {
3298 options[opt_idx].def_val[VI_DEFAULT] = buf;
3299 options[opt_idx].flags |= P_DEF_ALLOCED;
3300 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003301 else
3302 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003304 if (mustfree)
3305 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306 }
3307 }
3308#endif
3309
3310#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3311 /* Set print encoding on platforms that don't default to latin1 */
3312 set_string_default("penc",
3313# if defined(MSWIN) || defined(OS2)
3314 (char_u *)"cp1252"
3315# else
3316# ifdef VMS
3317 (char_u *)"dec-mcs"
3318# else
3319# ifdef EBCDIC
3320 (char_u *)"ebcdic-uk"
3321# else
3322# ifdef MAC
3323 (char_u *)"mac-roman"
3324# else /* HPUX */
3325 (char_u *)"hp-roman8"
3326# endif
3327# endif
3328# endif
3329# endif
3330 );
3331#endif
3332
3333#ifdef FEAT_POSTSCRIPT
3334 /* 'printexpr' must be allocated to be able to evaluate it. */
3335 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003336# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3337 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338# else
3339# ifdef VMS
3340 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3341
3342# else
3343 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3344# endif
3345# endif
3346 );
3347#endif
3348
3349 /*
3350 * Set all the options (except the terminal options) to their default
3351 * value. Also set the global value for local options.
3352 */
3353 set_options_default(0);
3354
3355#ifdef FEAT_GUI
3356 if (found_reverse_arg)
3357 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3358#endif
3359
3360 curbuf->b_p_initialized = TRUE;
3361 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003362 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363 check_buf_options(curbuf);
3364 check_win_options(curwin);
3365 check_options();
3366
3367 /* Must be before option_expand(), because that one needs vim_isIDc() */
3368 didset_options();
3369
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003370#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003371 /* Use the current chartab for the generic chartab. */
3372 init_spell_chartab();
3373#endif
3374
Bram Moolenaar071d4272004-06-13 20:20:40 +00003375#ifdef FEAT_LINEBREAK
3376 /*
3377 * initialize the table for 'breakat'.
3378 */
3379 fill_breakat_flags();
3380#endif
3381
3382 /*
3383 * Expand environment variables and things like "~" for the defaults.
3384 * If option_expand() returns non-NULL the variable is expanded. This can
3385 * only happen for non-indirect options.
3386 * Also set the default to the expanded value, so ":set" does not list
3387 * them.
3388 * Don't set the P_ALLOCED flag, because we don't want to free the
3389 * default.
3390 */
3391 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3392 {
3393 if ((options[opt_idx].flags & P_GETTEXT)
3394 && options[opt_idx].var != NULL)
3395 p = (char_u *)_(*(char **)options[opt_idx].var);
3396 else
3397 p = option_expand(opt_idx, NULL);
3398 if (p != NULL && (p = vim_strsave(p)) != NULL)
3399 {
3400 *(char_u **)options[opt_idx].var = p;
3401 /* VIMEXP
3402 * Defaults for all expanded options are currently the same for Vi
3403 * and Vim. When this changes, add some code here! Also need to
3404 * split P_DEF_ALLOCED in two.
3405 */
3406 if (options[opt_idx].flags & P_DEF_ALLOCED)
3407 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3408 options[opt_idx].def_val[VI_DEFAULT] = p;
3409 options[opt_idx].flags |= P_DEF_ALLOCED;
3410 }
3411 }
3412
3413 /* Initialize the highlight_attr[] table. */
3414 highlight_changed();
3415
3416 save_file_ff(curbuf); /* Buffer is unchanged */
3417
3418 /* Parse default for 'wildmode' */
3419 check_opt_wim();
3420
3421#if defined(FEAT_ARABIC)
3422 /* Detect use of mlterm.
3423 * Mlterm is a terminal emulator akin to xterm that has some special
3424 * abilities (bidi namely).
3425 * NOTE: mlterm's author is being asked to 'set' a variable
3426 * instead of an environment variable due to inheritance.
3427 */
3428 if (mch_getenv((char_u *)"MLTERM") != NULL)
3429 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3430#endif
3431
3432#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3433 /* Parse default for 'fillchars'. */
3434 (void)set_chars_option(&p_fcs);
3435#endif
3436
3437#ifdef FEAT_CLIPBOARD
3438 /* Parse default for 'clipboard' */
3439 (void)check_clipboard_option();
3440#endif
3441
3442#ifdef FEAT_MBYTE
3443# if defined(WIN3264) && defined(FEAT_GETTEXT)
3444 /*
3445 * If $LANG isn't set, try to get a good value for it. This makes the
3446 * right language be used automatically. Don't do this for English.
3447 */
3448 if (mch_getenv((char_u *)"LANG") == NULL)
3449 {
3450 char buf[20];
3451
3452 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3453 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3454 * only the first two. */
3455 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3456 (LPTSTR)buf, 20);
3457 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3458 {
3459 /* There are a few exceptions (probably more) */
3460 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3461 STRCPY(buf, "zh_TW");
3462 else if (STRNICMP(buf, "chs", 3) == 0
3463 || STRNICMP(buf, "zhc", 3) == 0)
3464 STRCPY(buf, "zh_CN");
3465 else if (STRNICMP(buf, "jp", 2) == 0)
3466 STRCPY(buf, "ja");
3467 else
3468 buf[2] = NUL; /* truncate to two-letter code */
3469 vim_setenv("LANG", buf);
3470 }
3471 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003472# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003473# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003474 /* Moved to os_mac_conv.c to avoid dependency problems. */
3475 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003476# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477# endif
3478
3479 /* enc_locale() will try to find the encoding of the current locale. */
3480 p = enc_locale();
3481 if (p != NULL)
3482 {
3483 char_u *save_enc;
3484
3485 /* Try setting 'encoding' and check if the value is valid.
3486 * If not, go back to the default "latin1". */
3487 save_enc = p_enc;
3488 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003489 if (STRCMP(p_enc, "gb18030") == 0)
3490 {
3491 /* We don't support "gb18030", but "cp936" is a good substitute
3492 * for practical purposes, thus use that. It's not an alias to
3493 * still support conversion between gb18030 and utf-8. */
3494 p_enc = vim_strsave((char_u *)"cp936");
3495 vim_free(p);
3496 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003497 if (mb_init() == NULL)
3498 {
3499 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003500 if (opt_idx >= 0)
3501 {
3502 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3503 options[opt_idx].flags |= P_DEF_ALLOCED;
3504 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003506#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3507 || defined(VMS)
3508 if (STRCMP(p_enc, "latin1") == 0
3509# ifdef FEAT_MBYTE
3510 || enc_utf8
3511# endif
3512 )
3513 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003514 /* Adjust the default for 'isprint' and 'iskeyword' to match
3515 * latin1. Also set the defaults for when 'nocompatible' is
3516 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003517 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003518 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003519 set_string_option_direct((char_u *)"isk", -1,
3520 ISK_LATIN1, OPT_FREE, SID_NONE);
3521 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003522 if (opt_idx >= 0)
3523 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003524 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003525 if (opt_idx >= 0)
3526 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003527 (void)init_chartab();
3528 }
3529#endif
3530
Bram Moolenaar071d4272004-06-13 20:20:40 +00003531# if defined(WIN3264) && !defined(FEAT_GUI)
3532 /* Win32 console: When GetACP() returns a different value from
3533 * GetConsoleCP() set 'termencoding'. */
3534 if (GetACP() != GetConsoleCP())
3535 {
3536 char buf[50];
3537
3538 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3539 p_tenc = vim_strsave((char_u *)buf);
3540 if (p_tenc != NULL)
3541 {
3542 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003543 if (opt_idx >= 0)
3544 {
3545 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3546 options[opt_idx].flags |= P_DEF_ALLOCED;
3547 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003548 convert_setup(&input_conv, p_tenc, p_enc);
3549 convert_setup(&output_conv, p_enc, p_tenc);
3550 }
3551 else
3552 p_tenc = empty_option;
3553 }
3554# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003555# if defined(WIN3264) && defined(FEAT_MBYTE)
3556 /* $HOME may have characters in active code page. */
3557 init_homedir();
3558# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003559 }
3560 else
3561 {
3562 vim_free(p_enc);
3563 p_enc = save_enc;
3564 }
3565 }
3566#endif
3567
3568#ifdef FEAT_MULTI_LANG
3569 /* Set the default for 'helplang'. */
3570 set_helplang_default(get_mess_lang());
3571#endif
3572}
3573
3574/*
3575 * Set an option to its default value.
3576 * This does not take care of side effects!
3577 */
3578 static void
3579set_option_default(opt_idx, opt_flags, compatible)
3580 int opt_idx;
3581 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3582 int compatible; /* use Vi default value */
3583{
3584 char_u *varp; /* pointer to variable for current option */
3585 int dvi; /* index in def_val[] */
3586 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003587 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3589
3590 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3591 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003592 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 {
3594 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3595 if (flags & P_STRING)
3596 {
3597 /* Use set_string_option_direct() for local options to handle
3598 * freeing and allocating the value. */
3599 if (options[opt_idx].indir != PV_NONE)
3600 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003601 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003602 else
3603 {
3604 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3605 free_string_option(*(char_u **)(varp));
3606 *(char_u **)varp = options[opt_idx].def_val[dvi];
3607 options[opt_idx].flags &= ~P_ALLOCED;
3608 }
3609 }
3610 else if (flags & P_NUM)
3611 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003612 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003613 win_comp_scroll(curwin);
3614 else
3615 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003616 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003617 /* May also set global value for local option. */
3618 if (both)
3619 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3620 *(long *)varp;
3621 }
3622 }
3623 else /* P_BOOL */
3624 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003625 /* the cast to long is required for Manx C, long_i is needed for
3626 * MSVC */
3627 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003628#ifdef UNIX
3629 /* 'modeline' defaults to off for root */
3630 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3631 *(int *)varp = FALSE;
3632#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003633 /* May also set global value for local option. */
3634 if (both)
3635 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3636 *(int *)varp;
3637 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003638
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003639 /* The default value is not insecure. */
3640 flagsp = insecure_flag(opt_idx, opt_flags);
3641 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003642 }
3643
3644#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003645 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646#endif
3647}
3648
3649/*
3650 * Set all options (except terminal options) to their default value.
3651 */
3652 static void
3653set_options_default(opt_flags)
3654 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3655{
3656 int i;
3657#ifdef FEAT_WINDOWS
3658 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003659 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003660#endif
3661
3662 for (i = 0; !istermoption(&options[i]); i++)
3663 if (!(options[i].flags & P_NODEFAULT))
3664 set_option_default(i, opt_flags, p_cp);
3665
3666#ifdef FEAT_WINDOWS
3667 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003668 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003669 win_comp_scroll(wp);
3670#else
3671 win_comp_scroll(curwin);
3672#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003673#ifdef FEAT_CINDENT
3674 parse_cino(curbuf);
3675#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676}
3677
3678/*
3679 * Set the Vi-default value of a string option.
3680 * Used for 'sh', 'backupskip' and 'term'.
3681 */
3682 void
3683set_string_default(name, val)
3684 char *name;
3685 char_u *val;
3686{
3687 char_u *p;
3688 int opt_idx;
3689
3690 p = vim_strsave(val);
3691 if (p != NULL) /* we don't want a NULL */
3692 {
3693 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003694 if (opt_idx >= 0)
3695 {
3696 if (options[opt_idx].flags & P_DEF_ALLOCED)
3697 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3698 options[opt_idx].def_val[VI_DEFAULT] = p;
3699 options[opt_idx].flags |= P_DEF_ALLOCED;
3700 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003701 }
3702}
3703
3704/*
3705 * Set the Vi-default value of a number option.
3706 * Used for 'lines' and 'columns'.
3707 */
3708 void
3709set_number_default(name, val)
3710 char *name;
3711 long val;
3712{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003713 int opt_idx;
3714
3715 opt_idx = findoption((char_u *)name);
3716 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003717 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718}
3719
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003720#if defined(EXITFREE) || defined(PROTO)
3721/*
3722 * Free all options.
3723 */
3724 void
3725free_all_options()
3726{
3727 int i;
3728
3729 for (i = 0; !istermoption(&options[i]); i++)
3730 {
3731 if (options[i].indir == PV_NONE)
3732 {
3733 /* global option: free value and default value. */
3734 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3735 free_string_option(*(char_u **)options[i].var);
3736 if (options[i].flags & P_DEF_ALLOCED)
3737 free_string_option(options[i].def_val[VI_DEFAULT]);
3738 }
3739 else if (options[i].var != VAR_WIN
3740 && (options[i].flags & P_STRING))
3741 /* buffer-local option: free global value */
3742 free_string_option(*(char_u **)options[i].var);
3743 }
3744}
3745#endif
3746
3747
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748/*
3749 * Initialize the options, part two: After getting Rows and Columns and
3750 * setting 'term'.
3751 */
3752 void
3753set_init_2()
3754{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003755 int idx;
3756
Bram Moolenaar071d4272004-06-13 20:20:40 +00003757 /*
3758 * 'scroll' defaults to half the window height. Note that this default is
3759 * wrong when the window height changes.
3760 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003761 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003762 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003763 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003764 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003765 comp_col();
3766
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003767 /*
3768 * 'window' is only for backwards compatibility with Vi.
3769 * Default is Rows - 1.
3770 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003771 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003772 p_window = Rows - 1;
3773 set_number_default("window", Rows - 1);
3774
Bram Moolenaarf740b292006-02-16 22:11:02 +00003775 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003777 /*
3778 * If 'background' wasn't set by the user, try guessing the value,
3779 * depending on the terminal name. Only need to check for terminals
3780 * with a dark background, that can handle color.
3781 */
3782 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003783 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3784 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003786 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003787 /* don't mark it as set, when starting the GUI it may be
3788 * changed again */
3789 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790 }
3791#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003792
3793#ifdef CURSOR_SHAPE
3794 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3795#endif
3796#ifdef FEAT_MOUSESHAPE
3797 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3798#endif
3799#ifdef FEAT_PRINTER
3800 (void)parse_printoptions(); /* parse 'printoptions' default value */
3801#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802}
3803
3804/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003805 * Return "dark" or "light" depending on the kind of terminal.
3806 * This is just guessing! Recognized are:
3807 * "linux" Linux console
3808 * "screen.linux" Linux console with screen
3809 * "cygwin" Cygwin shell
3810 * "putty" Putty program
3811 * We also check the COLORFGBG environment variable, which is set by
3812 * rxvt and derivatives. This variable contains either two or three
3813 * values separated by semicolons; we want the last value in either
3814 * case. If this value is 0-6 or 8, our background is dark.
3815 */
3816 static char_u *
3817term_bg_default()
3818{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003819#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3820 /* DOS console nearly always black */
3821 return (char_u *)"dark";
3822#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003823 char_u *p;
3824
Bram Moolenaarf740b292006-02-16 22:11:02 +00003825 if (STRCMP(T_NAME, "linux") == 0
3826 || STRCMP(T_NAME, "screen.linux") == 0
3827 || STRCMP(T_NAME, "cygwin") == 0
3828 || STRCMP(T_NAME, "putty") == 0
3829 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3830 && (p = vim_strrchr(p, ';')) != NULL
3831 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3832 && p[2] == NUL))
3833 return (char_u *)"dark";
3834 return (char_u *)"light";
3835#endif
3836}
3837
3838/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839 * Initialize the options, part three: After reading the .vimrc
3840 */
3841 void
3842set_init_3()
3843{
3844#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3845/*
3846 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3847 * This is done after other initializations, where 'shell' might have been
3848 * set, but only if they have not been set before.
3849 */
3850 char_u *p;
3851 int idx_srr;
3852 int do_srr;
3853#ifdef FEAT_QUICKFIX
3854 int idx_sp;
3855 int do_sp;
3856#endif
3857
3858 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003859 if (idx_srr < 0)
3860 do_srr = FALSE;
3861 else
3862 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863#ifdef FEAT_QUICKFIX
3864 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003865 if (idx_sp < 0)
3866 do_sp = FALSE;
3867 else
3868 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003870 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871 if (p != NULL)
3872 {
3873 /*
3874 * Default for p_sp is "| tee", for p_srr is ">".
3875 * For known shells it is changed here to include stderr.
3876 */
3877 if ( fnamecmp(p, "csh") == 0
3878 || fnamecmp(p, "tcsh") == 0
3879# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3880 || fnamecmp(p, "csh.exe") == 0
3881 || fnamecmp(p, "tcsh.exe") == 0
3882# endif
3883 )
3884 {
3885#if defined(FEAT_QUICKFIX)
3886 if (do_sp)
3887 {
3888# ifdef WIN3264
3889 p_sp = (char_u *)">&";
3890# else
3891 p_sp = (char_u *)"|& tee";
3892# endif
3893 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3894 }
3895#endif
3896 if (do_srr)
3897 {
3898 p_srr = (char_u *)">&";
3899 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3900 }
3901 }
3902 else
3903# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3904 if ( fnamecmp(p, "sh") == 0
3905 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003906 || fnamecmp(p, "mksh") == 0
3907 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003909 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003911 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912# ifdef WIN3264
3913 || fnamecmp(p, "cmd") == 0
3914 || fnamecmp(p, "sh.exe") == 0
3915 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003916 || fnamecmp(p, "mksh.exe") == 0
3917 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003919 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920 || fnamecmp(p, "bash.exe") == 0
3921 || fnamecmp(p, "cmd.exe") == 0
3922# endif
3923 )
3924# endif
3925 {
3926#if defined(FEAT_QUICKFIX)
3927 if (do_sp)
3928 {
3929# ifdef WIN3264
3930 p_sp = (char_u *)">%s 2>&1";
3931# else
3932 p_sp = (char_u *)"2>&1| tee";
3933# endif
3934 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3935 }
3936#endif
3937 if (do_srr)
3938 {
3939 p_srr = (char_u *)">%s 2>&1";
3940 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3941 }
3942 }
3943 vim_free(p);
3944 }
3945#endif
3946
3947#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3948 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003949 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3950 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 * This is done after other initializations, where 'shell' might have been
3952 * set, but only if they have not been set before. Default for p_shcf is
3953 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3954 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3955 * command.com. And for Win32 we need to set p_sxq instead.
3956 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003957 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958 {
3959 int idx3;
3960
3961 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003962 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 {
3964 p_shcf = (char_u *)"-c";
3965 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3966 }
3967
3968# ifndef DJGPP
3969# ifdef WIN3264
3970 /* Somehow Win32 requires the quotes around the redirection too */
3971 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003972 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003973 {
3974 p_sxq = (char_u *)"\"";
3975 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3976 }
3977# else
3978 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003979 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003980 {
3981 p_shq = (char_u *)"\"";
3982 options[idx3].def_val[VI_DEFAULT] = p_shq;
3983 }
3984# endif
3985# endif
3986 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003987 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3988 {
3989 int idx3;
3990
3991 /*
3992 * cmd.exe on Windows will strip the first and last double quote given
3993 * on the command line, e.g. most of the time things like:
3994 * cmd /c "my path/to/echo" "my args to echo"
3995 * become:
3996 * my path/to/echo" "my args to echo
3997 * when executed.
3998 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003999 * To avoid this, set shellxquote to surround the command in
4000 * parenthesis. This appears to make most commands work, without
4001 * breaking commands that worked previously, such as
4002 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004003 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004004 idx3 = findoption((char_u *)"sxq");
4005 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4006 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004007 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004008 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4009 }
4010
Bram Moolenaara64ba222012-02-12 23:23:31 +01004011 idx3 = findoption((char_u *)"shcf");
4012 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4013 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004014 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004015 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4016 }
4017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018#endif
4019
4020#ifdef FEAT_TITLE
4021 set_title_defaults();
4022#endif
4023}
4024
4025#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4026/*
4027 * When 'helplang' is still at its default value, set it to "lang".
4028 * Only the first two characters of "lang" are used.
4029 */
4030 void
4031set_helplang_default(lang)
4032 char_u *lang;
4033{
4034 int idx;
4035
4036 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4037 return;
4038 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004039 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 {
4041 if (options[idx].flags & P_ALLOCED)
4042 free_string_option(p_hlg);
4043 p_hlg = vim_strsave(lang);
4044 if (p_hlg == NULL)
4045 p_hlg = empty_option;
4046 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004047 {
4048 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4049 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4050 {
4051 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4052 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4053 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004055 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 options[idx].flags |= P_ALLOCED;
4057 }
4058}
4059#endif
4060
4061#ifdef FEAT_GUI
4062static char_u *gui_bg_default __ARGS((void));
4063
4064 static char_u *
4065gui_bg_default()
4066{
4067 if (gui_get_lightness(gui.back_pixel) < 127)
4068 return (char_u *)"dark";
4069 return (char_u *)"light";
4070}
4071
4072/*
4073 * Option initializations that can only be done after opening the GUI window.
4074 */
4075 void
4076init_gui_options()
4077{
4078 /* Set the 'background' option according to the lightness of the
4079 * background color, unless the user has set it already. */
4080 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4081 {
4082 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4083 highlight_changed();
4084 }
4085}
4086#endif
4087
4088#ifdef FEAT_TITLE
4089/*
4090 * 'title' and 'icon' only default to true if they have not been set or reset
4091 * in .vimrc and we can read the old value.
4092 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4093 * they can be reset. This reduces startup time when using X on a remote
4094 * machine.
4095 */
4096 void
4097set_title_defaults()
4098{
4099 int idx1;
4100 long val;
4101
4102 /*
4103 * If GUI is (going to be) used, we can always set the window title and
4104 * icon name. Saves a bit of time, because the X11 display server does
4105 * not need to be contacted.
4106 */
4107 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004108 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 {
4110#ifdef FEAT_GUI
4111 if (gui.starting || gui.in_use)
4112 val = TRUE;
4113 else
4114#endif
4115 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004116 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 p_title = val;
4118 }
4119 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004120 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 {
4122#ifdef FEAT_GUI
4123 if (gui.starting || gui.in_use)
4124 val = TRUE;
4125 else
4126#endif
4127 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004128 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 p_icon = val;
4130 }
4131}
4132#endif
4133
4134/*
4135 * Parse 'arg' for option settings.
4136 *
4137 * 'arg' may be IObuff, but only when no errors can be present and option
4138 * does not need to be expanded with option_expand().
4139 * "opt_flags":
4140 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004141 * OPT_GLOBAL for ":setglobal"
4142 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004144 * OPT_WINONLY to only set window-local options
4145 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 *
4147 * returns FAIL if an error is detected, OK otherwise
4148 */
4149 int
4150do_set(arg, opt_flags)
4151 char_u *arg; /* option string (may be written to!) */
4152 int opt_flags;
4153{
4154 int opt_idx;
4155 char_u *errmsg;
4156 char_u errbuf[80];
4157 char_u *startarg;
4158 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4159 int nextchar; /* next non-white char after option name */
4160 int afterchar; /* character just after option name */
4161 int len;
4162 int i;
4163 long value;
4164 int key;
4165 long_u flags; /* flags for current option */
4166 char_u *varp = NULL; /* pointer to variable for current option */
4167 int did_show = FALSE; /* already showed one value */
4168 int adding; /* "opt+=arg" */
4169 int prepending; /* "opt^=arg" */
4170 int removing; /* "opt-=arg" */
4171 int cp_val = 0;
4172 char_u key_name[2];
4173
4174 if (*arg == NUL)
4175 {
4176 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004177 did_show = TRUE;
4178 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 }
4180
4181 while (*arg != NUL) /* loop to process all options */
4182 {
4183 errmsg = NULL;
4184 startarg = arg; /* remember for error message */
4185
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004186 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4187 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004188 {
4189 /*
4190 * ":set all" show all options.
4191 * ":set all&" set all options to their default value.
4192 */
4193 arg += 3;
4194 if (*arg == '&')
4195 {
4196 ++arg;
4197 /* Only for :set command set global value of local options. */
4198 set_options_default(OPT_FREE | opt_flags);
4199 }
4200 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004201 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004202 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004203 did_show = TRUE;
4204 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004205 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004206 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004207 {
4208 showoptions(2, opt_flags);
4209 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004210 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004211 arg += 7;
4212 }
4213 else
4214 {
4215 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004216 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004217 {
4218 prefix = 0;
4219 arg += 2;
4220 }
4221 else if (STRNCMP(arg, "inv", 3) == 0)
4222 {
4223 prefix = 2;
4224 arg += 3;
4225 }
4226
4227 /* find end of name */
4228 key = 0;
4229 if (*arg == '<')
4230 {
4231 nextchar = 0;
4232 opt_idx = -1;
4233 /* look out for <t_>;> */
4234 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4235 len = 5;
4236 else
4237 {
4238 len = 1;
4239 while (arg[len] != NUL && arg[len] != '>')
4240 ++len;
4241 }
4242 if (arg[len] != '>')
4243 {
4244 errmsg = e_invarg;
4245 goto skip;
4246 }
4247 arg[len] = NUL; /* put NUL after name */
4248 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4249 opt_idx = findoption(arg + 1);
4250 arg[len++] = '>'; /* restore '>' */
4251 if (opt_idx == -1)
4252 key = find_key_option(arg + 1);
4253 }
4254 else
4255 {
4256 len = 0;
4257 /*
4258 * The two characters after "t_" may not be alphanumeric.
4259 */
4260 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4261 len = 4;
4262 else
4263 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4264 ++len;
4265 nextchar = arg[len];
4266 arg[len] = NUL; /* put NUL after name */
4267 opt_idx = findoption(arg);
4268 arg[len] = nextchar; /* restore nextchar */
4269 if (opt_idx == -1)
4270 key = find_key_option(arg);
4271 }
4272
4273 /* remember character after option name */
4274 afterchar = arg[len];
4275
4276 /* skip white space, allow ":set ai ?" */
4277 while (vim_iswhite(arg[len]))
4278 ++len;
4279
4280 adding = FALSE;
4281 prepending = FALSE;
4282 removing = FALSE;
4283 if (arg[len] != NUL && arg[len + 1] == '=')
4284 {
4285 if (arg[len] == '+')
4286 {
4287 adding = TRUE; /* "+=" */
4288 ++len;
4289 }
4290 else if (arg[len] == '^')
4291 {
4292 prepending = TRUE; /* "^=" */
4293 ++len;
4294 }
4295 else if (arg[len] == '-')
4296 {
4297 removing = TRUE; /* "-=" */
4298 ++len;
4299 }
4300 }
4301 nextchar = arg[len];
4302
4303 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4304 {
4305 errmsg = (char_u *)N_("E518: Unknown option");
4306 goto skip;
4307 }
4308
4309 if (opt_idx >= 0)
4310 {
4311 if (options[opt_idx].var == NULL) /* hidden option: skip */
4312 {
4313 /* Only give an error message when requesting the value of
4314 * a hidden option, ignore setting it. */
4315 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4316 && (!(options[opt_idx].flags & P_BOOL)
4317 || nextchar == '?'))
4318 errmsg = (char_u *)N_("E519: Option not supported");
4319 goto skip;
4320 }
4321
4322 flags = options[opt_idx].flags;
4323 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4324 }
4325 else
4326 {
4327 flags = P_STRING;
4328 if (key < 0)
4329 {
4330 key_name[0] = KEY2TERMCAP0(key);
4331 key_name[1] = KEY2TERMCAP1(key);
4332 }
4333 else
4334 {
4335 key_name[0] = KS_KEY;
4336 key_name[1] = (key & 0xff);
4337 }
4338 }
4339
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004340 /* Skip all options that are not window-local (used when showing
4341 * an already loaded buffer in a window). */
4342 if ((opt_flags & OPT_WINONLY)
4343 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4344 goto skip;
4345
Bram Moolenaara3227e22006-03-08 21:32:40 +00004346 /* Skip all options that are window-local (used for :vimgrep). */
4347 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4348 && options[opt_idx].var == VAR_WIN)
4349 goto skip;
4350
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004351 /* Disallow changing some options from modelines. */
4352 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004353 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004354 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004355 {
4356 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4357 goto skip;
4358 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004359#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004360 /* In diff mode some options are overruled. This avoids that
4361 * 'foldmethod' becomes "marker" instead of "diff" and that
4362 * "wrap" gets set. */
4363 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004364 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004365 && (options[opt_idx].indir == PV_FDM
4366 || options[opt_idx].indir == PV_WRAP))
4367 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004369 }
4370
4371#ifdef HAVE_SANDBOX
4372 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004373 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004374 {
4375 errmsg = (char_u *)_(e_sandbox);
4376 goto skip;
4377 }
4378#endif
4379
4380 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4381 {
4382 arg += len;
4383 cp_val = p_cp;
4384 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4385 {
4386 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4387 {
4388 cp_val = FALSE;
4389 arg += 3;
4390 }
4391 else /* "opt&vi": set to Vi default */
4392 {
4393 cp_val = TRUE;
4394 arg += 2;
4395 }
4396 }
4397 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4398 && arg[1] != NUL && !vim_iswhite(arg[1]))
4399 {
4400 errmsg = e_trailing;
4401 goto skip;
4402 }
4403 }
4404
4405 /*
4406 * allow '=' and ':' as MSDOS command.com allows only one
4407 * '=' character per "set" command line. grrr. (jw)
4408 */
4409 if (nextchar == '?'
4410 || (prefix == 1
4411 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4412 && !(flags & P_BOOL)))
4413 {
4414 /*
4415 * print value
4416 */
4417 if (did_show)
4418 msg_putchar('\n'); /* cursor below last one */
4419 else
4420 {
4421 gotocmdline(TRUE); /* cursor at status line */
4422 did_show = TRUE; /* remember that we did a line */
4423 }
4424 if (opt_idx >= 0)
4425 {
4426 showoneopt(&options[opt_idx], opt_flags);
4427#ifdef FEAT_EVAL
4428 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004429 {
4430 /* Mention where the option was last set. */
4431 if (varp == options[opt_idx].var)
4432 last_set_msg(options[opt_idx].scriptID);
4433 else if ((int)options[opt_idx].indir & PV_WIN)
4434 last_set_msg(curwin->w_p_scriptID[
4435 (int)options[opt_idx].indir & PV_MASK]);
4436 else if ((int)options[opt_idx].indir & PV_BUF)
4437 last_set_msg(curbuf->b_p_scriptID[
4438 (int)options[opt_idx].indir & PV_MASK]);
4439 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004440#endif
4441 }
4442 else
4443 {
4444 char_u *p;
4445
4446 p = find_termcode(key_name);
4447 if (p == NULL)
4448 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004449 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004450 goto skip;
4451 }
4452 else
4453 (void)show_one_termcode(key_name, p, TRUE);
4454 }
4455 if (nextchar != '?'
4456 && nextchar != NUL && !vim_iswhite(afterchar))
4457 errmsg = e_trailing;
4458 }
4459 else
4460 {
4461 if (flags & P_BOOL) /* boolean */
4462 {
4463 if (nextchar == '=' || nextchar == ':')
4464 {
4465 errmsg = e_invarg;
4466 goto skip;
4467 }
4468
4469 /*
4470 * ":set opt!": invert
4471 * ":set opt&": reset to default value
4472 * ":set opt<": reset to global value
4473 */
4474 if (nextchar == '!')
4475 value = *(int *)(varp) ^ 1;
4476 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004477 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004478 ((flags & P_VI_DEF) || cp_val)
4479 ? VI_DEFAULT : VIM_DEFAULT];
4480 else if (nextchar == '<')
4481 {
4482 /* For 'autoread' -1 means to use global value. */
4483 if ((int *)varp == &curbuf->b_p_ar
4484 && opt_flags == OPT_LOCAL)
4485 value = -1;
4486 else
4487 value = *(int *)get_varp_scope(&(options[opt_idx]),
4488 OPT_GLOBAL);
4489 }
4490 else
4491 {
4492 /*
4493 * ":set invopt": invert
4494 * ":set opt" or ":set noopt": set or reset
4495 */
4496 if (nextchar != NUL && !vim_iswhite(afterchar))
4497 {
4498 errmsg = e_trailing;
4499 goto skip;
4500 }
4501 if (prefix == 2) /* inv */
4502 value = *(int *)(varp) ^ 1;
4503 else
4504 value = prefix;
4505 }
4506
4507 errmsg = set_bool_option(opt_idx, varp, (int)value,
4508 opt_flags);
4509 }
4510 else /* numeric or string */
4511 {
4512 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4513 || prefix != 1)
4514 {
4515 errmsg = e_invarg;
4516 goto skip;
4517 }
4518
4519 if (flags & P_NUM) /* numeric */
4520 {
4521 /*
4522 * Different ways to set a number option:
4523 * & set to default value
4524 * < set to global value
4525 * <xx> accept special key codes for 'wildchar'
4526 * c accept any non-digit for 'wildchar'
4527 * [-]0-9 set number
4528 * other error
4529 */
4530 ++arg;
4531 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004532 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004533 ((flags & P_VI_DEF) || cp_val)
4534 ? VI_DEFAULT : VIM_DEFAULT];
4535 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004536 {
4537 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4538 * use the global value. */
4539 if ((long *)varp == &curbuf->b_p_ul
4540 && opt_flags == OPT_LOCAL)
4541 value = NO_LOCAL_UNDOLEVEL;
4542 else
4543 value = *(long *)get_varp_scope(
4544 &(options[opt_idx]), OPT_GLOBAL);
4545 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004546 else if (((long *)varp == &p_wc
4547 || (long *)varp == &p_wcm)
4548 && (*arg == '<'
4549 || *arg == '^'
4550 || ((!arg[1] || vim_iswhite(arg[1]))
4551 && !VIM_ISDIGIT(*arg))))
4552 {
4553 value = string_to_key(arg);
4554 if (value == 0 && (long *)varp != &p_wcm)
4555 {
4556 errmsg = e_invarg;
4557 goto skip;
4558 }
4559 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004560 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4561 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004562 /* Allow negative (for 'undolevels'), octal and
4563 * hex numbers. */
Bram Moolenaar5d1bc782015-07-17 13:03:48 +02004564 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004565 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4566 {
4567 errmsg = e_invarg;
4568 goto skip;
4569 }
4570 }
4571 else
4572 {
4573 errmsg = (char_u *)N_("E521: Number required after =");
4574 goto skip;
4575 }
4576
4577 if (adding)
4578 value = *(long *)varp + value;
4579 if (prepending)
4580 value = *(long *)varp * value;
4581 if (removing)
4582 value = *(long *)varp - value;
4583 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004584 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004585 }
4586 else if (opt_idx >= 0) /* string */
4587 {
4588 char_u *save_arg = NULL;
4589 char_u *s = NULL;
4590 char_u *oldval; /* previous value if *varp */
4591 char_u *newval;
4592 char_u *origval;
4593 unsigned newlen;
4594 int comma;
4595 int bs;
4596 int new_value_alloced; /* new string option
4597 was allocated */
4598
4599 /* When using ":set opt=val" for a global option
4600 * with a local value the local value will be
4601 * reset, use the global value here. */
4602 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004603 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004604 varp = options[opt_idx].var;
4605
4606 /* The old value is kept until we are sure that the
4607 * new value is valid. */
4608 oldval = *(char_u **)varp;
4609 if (nextchar == '&') /* set to default val */
4610 {
4611 newval = options[opt_idx].def_val[
4612 ((flags & P_VI_DEF) || cp_val)
4613 ? VI_DEFAULT : VIM_DEFAULT];
4614 if ((char_u **)varp == &p_bg)
4615 {
4616 /* guess the value of 'background' */
4617#ifdef FEAT_GUI
4618 if (gui.in_use)
4619 newval = gui_bg_default();
4620 else
4621#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004622 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004623 }
4624
4625 /* expand environment variables and ~ (since the
4626 * default value was already expanded, only
4627 * required when an environment variable was set
4628 * later */
4629 if (newval == NULL)
4630 newval = empty_option;
4631 else
4632 {
4633 s = option_expand(opt_idx, newval);
4634 if (s == NULL)
4635 s = newval;
4636 newval = vim_strsave(s);
4637 }
4638 new_value_alloced = TRUE;
4639 }
4640 else if (nextchar == '<') /* set to global val */
4641 {
4642 newval = vim_strsave(*(char_u **)get_varp_scope(
4643 &(options[opt_idx]), OPT_GLOBAL));
4644 new_value_alloced = TRUE;
4645 }
4646 else
4647 {
4648 ++arg; /* jump to after the '=' or ':' */
4649
4650 /*
4651 * Set 'keywordprg' to ":help" if an empty
4652 * value was passed to :set by the user.
4653 * Misuse errbuf[] for the resulting string.
4654 */
4655 if (varp == (char_u *)&p_kp
4656 && (*arg == NUL || *arg == ' '))
4657 {
4658 STRCPY(errbuf, ":help");
4659 save_arg = arg;
4660 arg = errbuf;
4661 }
4662 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004663 * Convert 'backspace' number to string, for
4664 * adding, prepending and removing string.
4665 */
4666 else if (varp == (char_u *)&p_bs
4667 && VIM_ISDIGIT(**(char_u **)varp))
4668 {
4669 i = getdigits((char_u **)varp);
4670 switch (i)
4671 {
4672 case 0:
4673 *(char_u **)varp = empty_option;
4674 break;
4675 case 1:
4676 *(char_u **)varp = vim_strsave(
4677 (char_u *)"indent,eol");
4678 break;
4679 case 2:
4680 *(char_u **)varp = vim_strsave(
4681 (char_u *)"indent,eol,start");
4682 break;
4683 }
4684 vim_free(oldval);
4685 oldval = *(char_u **)varp;
4686 }
4687 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004688 * Convert 'whichwrap' number to string, for
4689 * backwards compatibility with Vim 3.0.
4690 * Misuse errbuf[] for the resulting string.
4691 */
4692 else if (varp == (char_u *)&p_ww
4693 && VIM_ISDIGIT(*arg))
4694 {
4695 *errbuf = NUL;
4696 i = getdigits(&arg);
4697 if (i & 1)
4698 STRCAT(errbuf, "b,");
4699 if (i & 2)
4700 STRCAT(errbuf, "s,");
4701 if (i & 4)
4702 STRCAT(errbuf, "h,l,");
4703 if (i & 8)
4704 STRCAT(errbuf, "<,>,");
4705 if (i & 16)
4706 STRCAT(errbuf, "[,],");
4707 if (*errbuf != NUL) /* remove trailing , */
4708 errbuf[STRLEN(errbuf) - 1] = NUL;
4709 save_arg = arg;
4710 arg = errbuf;
4711 }
4712 /*
4713 * Remove '>' before 'dir' and 'bdir', for
4714 * backwards compatibility with version 3.0
4715 */
4716 else if ( *arg == '>'
4717 && (varp == (char_u *)&p_dir
4718 || varp == (char_u *)&p_bdir))
4719 {
4720 ++arg;
4721 }
4722
4723 /* When setting the local value of a global
4724 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004725 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004726 && (opt_flags & OPT_LOCAL))
4727 origval = *(char_u **)get_varp(
4728 &options[opt_idx]);
4729 else
4730 origval = oldval;
4731
4732 /*
4733 * Copy the new string into allocated memory.
4734 * Can't use set_string_option_direct(), because
4735 * we need to remove the backslashes.
4736 */
4737 /* get a bit too much */
4738 newlen = (unsigned)STRLEN(arg) + 1;
4739 if (adding || prepending || removing)
4740 newlen += (unsigned)STRLEN(origval) + 1;
4741 newval = alloc(newlen);
4742 if (newval == NULL) /* out of mem, don't change */
4743 break;
4744 s = newval;
4745
4746 /*
4747 * Copy the string, skip over escaped chars.
4748 * For MS-DOS and WIN32 backslashes before normal
4749 * file name characters are not removed, and keep
4750 * backslash at start, for "\\machine\path", but
4751 * do remove it for "\\\\machine\\path".
4752 * The reverse is found in ExpandOldSetting().
4753 */
4754 while (*arg && !vim_iswhite(*arg))
4755 {
4756 if (*arg == '\\' && arg[1] != NUL
4757#ifdef BACKSLASH_IN_FILENAME
4758 && !((flags & P_EXPAND)
4759 && vim_isfilec(arg[1])
4760 && (arg[1] != '\\'
4761 || (s == newval
4762 && arg[2] != '\\')))
4763#endif
4764 )
4765 ++arg; /* remove backslash */
4766#ifdef FEAT_MBYTE
4767 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004768 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004769 {
4770 /* copy multibyte char */
4771 mch_memmove(s, arg, (size_t)i);
4772 arg += i;
4773 s += i;
4774 }
4775 else
4776#endif
4777 *s++ = *arg++;
4778 }
4779 *s = NUL;
4780
4781 /*
4782 * Expand environment variables and ~.
4783 * Don't do it when adding without inserting a
4784 * comma.
4785 */
4786 if (!(adding || prepending || removing)
4787 || (flags & P_COMMA))
4788 {
4789 s = option_expand(opt_idx, newval);
4790 if (s != NULL)
4791 {
4792 vim_free(newval);
4793 newlen = (unsigned)STRLEN(s) + 1;
4794 if (adding || prepending || removing)
4795 newlen += (unsigned)STRLEN(origval) + 1;
4796 newval = alloc(newlen);
4797 if (newval == NULL)
4798 break;
4799 STRCPY(newval, s);
4800 }
4801 }
4802
4803 /* locate newval[] in origval[] when removing it
4804 * and when adding to avoid duplicates */
4805 i = 0; /* init for GCC */
4806 if (removing || (flags & P_NODUP))
4807 {
4808 i = (int)STRLEN(newval);
4809 bs = 0;
4810 for (s = origval; *s; ++s)
4811 {
4812 if ((!(flags & P_COMMA)
4813 || s == origval
4814 || (s[-1] == ',' && !(bs & 1)))
4815 && STRNCMP(s, newval, i) == 0
4816 && (!(flags & P_COMMA)
4817 || s[i] == ','
4818 || s[i] == NUL))
4819 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004820 /* Count backslashes. Only a comma with an
4821 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004822 * recognized as a separator */
4823 if (s > origval && s[-1] == '\\')
4824 ++bs;
4825 else
4826 bs = 0;
4827 }
4828
4829 /* do not add if already there */
4830 if ((adding || prepending) && *s)
4831 {
4832 prepending = FALSE;
4833 adding = FALSE;
4834 STRCPY(newval, origval);
4835 }
4836 }
4837
4838 /* concatenate the two strings; add a ',' if
4839 * needed */
4840 if (adding || prepending)
4841 {
4842 comma = ((flags & P_COMMA) && *origval != NUL
4843 && *newval != NUL);
4844 if (adding)
4845 {
4846 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004847 /* strip a trailing comma, would get 2 */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02004848 if (comma && (flags & P_ONECOMMA) && i > 1
4849 && origval[i - 1] == ','
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004850 && origval[i - 2] != '\\')
4851 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004852 mch_memmove(newval + i + comma, newval,
4853 STRLEN(newval) + 1);
4854 mch_memmove(newval, origval, (size_t)i);
4855 }
4856 else
4857 {
4858 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004859 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004860 }
4861 if (comma)
4862 newval[i] = ',';
4863 }
4864
4865 /* Remove newval[] from origval[]. (Note: "i" has
4866 * been set above and is used here). */
4867 if (removing)
4868 {
4869 STRCPY(newval, origval);
4870 if (*s)
4871 {
4872 /* may need to remove a comma */
4873 if (flags & P_COMMA)
4874 {
4875 if (s == origval)
4876 {
4877 /* include comma after string */
4878 if (s[i] == ',')
4879 ++i;
4880 }
4881 else
4882 {
4883 /* include comma before string */
4884 --s;
4885 ++i;
4886 }
4887 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004888 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004889 }
4890 }
4891
4892 if (flags & P_FLAGLIST)
4893 {
4894 /* Remove flags that appear twice. */
4895 for (s = newval; *s; ++s)
4896 if ((!(flags & P_COMMA) || *s != ',')
4897 && vim_strchr(s + 1, *s) != NULL)
4898 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004899 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004900 --s;
4901 }
4902 }
4903
4904 if (save_arg != NULL) /* number for 'whichwrap' */
4905 arg = save_arg;
4906 new_value_alloced = TRUE;
4907 }
4908
4909 /* Set the new value. */
4910 *(char_u **)(varp) = newval;
4911
4912 /* Handle side effects, and set the global value for
4913 * ":set" on local options. */
4914 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4915 new_value_alloced, oldval, errbuf, opt_flags);
4916
4917 /* If error detected, print the error message. */
4918 if (errmsg != NULL)
4919 goto skip;
4920 }
4921 else /* key code option */
4922 {
4923 char_u *p;
4924
4925 if (nextchar == '&')
4926 {
4927 if (add_termcap_entry(key_name, TRUE) == FAIL)
4928 errmsg = (char_u *)N_("E522: Not found in termcap");
4929 }
4930 else
4931 {
4932 ++arg; /* jump to after the '=' or ':' */
4933 for (p = arg; *p && !vim_iswhite(*p); ++p)
4934 if (*p == '\\' && p[1] != NUL)
4935 ++p;
4936 nextchar = *p;
4937 *p = NUL;
4938 add_termcode(key_name, arg, FALSE);
4939 *p = nextchar;
4940 }
4941 if (full_screen)
4942 ttest(FALSE);
4943 redraw_all_later(CLEAR);
4944 }
4945 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004946
Bram Moolenaar071d4272004-06-13 20:20:40 +00004947 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004948 did_set_option(opt_idx, opt_flags,
4949 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004950 }
4951
4952skip:
4953 /*
4954 * Advance to next argument.
4955 * - skip until a blank found, taking care of backslashes
4956 * - skip blanks
4957 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4958 */
4959 for (i = 0; i < 2 ; ++i)
4960 {
4961 while (*arg != NUL && !vim_iswhite(*arg))
4962 if (*arg++ == '\\' && *arg != NUL)
4963 ++arg;
4964 arg = skipwhite(arg);
4965 if (*arg != '=')
4966 break;
4967 }
4968 }
4969
4970 if (errmsg != NULL)
4971 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004972 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004973 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004974 if (i + (arg - startarg) < IOSIZE)
4975 {
4976 /* append the argument with the error */
4977 STRCAT(IObuff, ": ");
4978 mch_memmove(IObuff + i, startarg, (arg - startarg));
4979 IObuff[i + (arg - startarg)] = NUL;
4980 }
4981 /* make sure all characters are printable */
4982 trans_characters(IObuff, IOSIZE);
4983
4984 ++no_wait_return; /* wait_return done later */
4985 emsg(IObuff); /* show error highlighted */
4986 --no_wait_return;
4987
4988 return FAIL;
4989 }
4990
4991 arg = skipwhite(arg);
4992 }
4993
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004994theend:
4995 if (silent_mode && did_show)
4996 {
4997 /* After displaying option values in silent mode. */
4998 silent_mode = FALSE;
4999 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5000 msg_putchar('\n');
5001 cursor_on(); /* msg_start() switches it off */
5002 out_flush();
5003 silent_mode = TRUE;
5004 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5005 }
5006
Bram Moolenaar071d4272004-06-13 20:20:40 +00005007 return OK;
5008}
5009
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005010/*
5011 * Call this when an option has been given a new value through a user command.
5012 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5013 */
5014 static void
5015did_set_option(opt_idx, opt_flags, new_value)
5016 int opt_idx;
5017 int opt_flags; /* possibly with OPT_MODELINE */
5018 int new_value; /* value was replaced completely */
5019{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005020 long_u *p;
5021
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005022 options[opt_idx].flags |= P_WAS_SET;
5023
5024 /* When an option is set in the sandbox, from a modeline or in secure mode
5025 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005026 * flag. */
5027 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005028 if (secure
5029#ifdef HAVE_SANDBOX
5030 || sandbox != 0
5031#endif
5032 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005033 *p = *p | P_INSECURE;
5034 else if (new_value)
5035 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005036}
5037
Bram Moolenaar071d4272004-06-13 20:20:40 +00005038 static char_u *
5039illegal_char(errbuf, c)
5040 char_u *errbuf;
5041 int c;
5042{
5043 if (errbuf == NULL)
5044 return (char_u *)"";
5045 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005046 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005047 return errbuf;
5048}
5049
5050/*
5051 * Convert a key name or string into a key value.
5052 * Used for 'wildchar' and 'cedit' options.
5053 */
5054 static int
5055string_to_key(arg)
5056 char_u *arg;
5057{
5058 if (*arg == '<')
5059 return find_key_option(arg + 1);
5060 if (*arg == '^')
5061 return Ctrl_chr(arg[1]);
5062 return *arg;
5063}
5064
5065#ifdef FEAT_CMDWIN
5066/*
5067 * Check value of 'cedit' and set cedit_key.
5068 * Returns NULL if value is OK, error message otherwise.
5069 */
5070 static char_u *
5071check_cedit()
5072{
5073 int n;
5074
5075 if (*p_cedit == NUL)
5076 cedit_key = -1;
5077 else
5078 {
5079 n = string_to_key(p_cedit);
5080 if (vim_isprintc(n))
5081 return e_invarg;
5082 cedit_key = n;
5083 }
5084 return NULL;
5085}
5086#endif
5087
5088#ifdef FEAT_TITLE
5089/*
5090 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5091 * maketitle() to create and display it.
5092 * When switching the title or icon off, call mch_restore_title() to get
5093 * the old value back.
5094 */
5095 static void
5096did_set_title(icon)
5097 int icon; /* Did set icon instead of title */
5098{
5099 if (starting != NO_SCREEN
5100#ifdef FEAT_GUI
5101 && !gui.starting
5102#endif
5103 )
5104 {
5105 maketitle();
5106 if (icon)
5107 {
5108 if (!p_icon)
5109 mch_restore_title(2);
5110 }
5111 else
5112 {
5113 if (!p_title)
5114 mch_restore_title(1);
5115 }
5116 }
5117}
5118#endif
5119
5120/*
5121 * set_options_bin - called when 'bin' changes value.
5122 */
5123 void
5124set_options_bin(oldval, newval, opt_flags)
5125 int oldval;
5126 int newval;
5127 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5128{
5129 /*
5130 * The option values that are changed when 'bin' changes are
5131 * copied when 'bin is set and restored when 'bin' is reset.
5132 */
5133 if (newval)
5134 {
5135 if (!oldval) /* switched on */
5136 {
5137 if (!(opt_flags & OPT_GLOBAL))
5138 {
5139 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5140 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5141 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5142 curbuf->b_p_et_nobin = curbuf->b_p_et;
5143 }
5144 if (!(opt_flags & OPT_LOCAL))
5145 {
5146 p_tw_nobin = p_tw;
5147 p_wm_nobin = p_wm;
5148 p_ml_nobin = p_ml;
5149 p_et_nobin = p_et;
5150 }
5151 }
5152
5153 if (!(opt_flags & OPT_GLOBAL))
5154 {
5155 curbuf->b_p_tw = 0; /* no automatic line wrap */
5156 curbuf->b_p_wm = 0; /* no automatic line wrap */
5157 curbuf->b_p_ml = 0; /* no modelines */
5158 curbuf->b_p_et = 0; /* no expandtab */
5159 }
5160 if (!(opt_flags & OPT_LOCAL))
5161 {
5162 p_tw = 0;
5163 p_wm = 0;
5164 p_ml = FALSE;
5165 p_et = FALSE;
5166 p_bin = TRUE; /* needed when called for the "-b" argument */
5167 }
5168 }
5169 else if (oldval) /* switched off */
5170 {
5171 if (!(opt_flags & OPT_GLOBAL))
5172 {
5173 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5174 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5175 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5176 curbuf->b_p_et = curbuf->b_p_et_nobin;
5177 }
5178 if (!(opt_flags & OPT_LOCAL))
5179 {
5180 p_tw = p_tw_nobin;
5181 p_wm = p_wm_nobin;
5182 p_ml = p_ml_nobin;
5183 p_et = p_et_nobin;
5184 }
5185 }
5186}
5187
5188#ifdef FEAT_VIMINFO
5189/*
5190 * Find the parameter represented by the given character (eg ', :, ", or /),
5191 * and return its associated value in the 'viminfo' string.
5192 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005193 * If the parameter is not specified in the string or there is no following
5194 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005195 */
5196 int
5197get_viminfo_parameter(type)
5198 int type;
5199{
5200 char_u *p;
5201
5202 p = find_viminfo_parameter(type);
5203 if (p != NULL && VIM_ISDIGIT(*p))
5204 return atoi((char *)p);
5205 return -1;
5206}
5207
5208/*
5209 * Find the parameter represented by the given character (eg ''', ':', '"', or
5210 * '/') in the 'viminfo' option and return a pointer to the string after it.
5211 * Return NULL if the parameter is not specified in the string.
5212 */
5213 char_u *
5214find_viminfo_parameter(type)
5215 int type;
5216{
5217 char_u *p;
5218
5219 for (p = p_viminfo; *p; ++p)
5220 {
5221 if (*p == type)
5222 return p + 1;
5223 if (*p == 'n') /* 'n' is always the last one */
5224 break;
5225 p = vim_strchr(p, ','); /* skip until next ',' */
5226 if (p == NULL) /* hit the end without finding parameter */
5227 break;
5228 }
5229 return NULL;
5230}
5231#endif
5232
5233/*
5234 * Expand environment variables for some string options.
5235 * These string options cannot be indirect!
5236 * If "val" is NULL expand the current value of the option.
5237 * Return pointer to NameBuff, or NULL when not expanded.
5238 */
5239 static char_u *
5240option_expand(opt_idx, val)
5241 int opt_idx;
5242 char_u *val;
5243{
5244 /* if option doesn't need expansion nothing to do */
5245 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5246 return NULL;
5247
5248 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5249 * expand_env() would truncate the string. */
5250 if (val != NULL && STRLEN(val) > MAXPATHL)
5251 return NULL;
5252
5253 if (val == NULL)
5254 val = *(char_u **)options[opt_idx].var;
5255
5256 /*
5257 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5258 * Escape spaces when expanding 'tags', they are used to separate file
5259 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005260 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005261 */
5262 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005263 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005264#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005265 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5266#endif
5267 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005268 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5269 return NULL;
5270
5271 return NameBuff;
5272}
5273
5274/*
5275 * After setting various option values: recompute variables that depend on
5276 * option values.
5277 */
5278 static void
5279didset_options()
5280{
5281 /* initialize the table for 'iskeyword' et.al. */
5282 (void)init_chartab();
5283
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005284#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005286#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005287 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5288#ifdef FEAT_SESSION
5289 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5290 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5291#endif
5292#ifdef FEAT_FOLDING
5293 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5294#endif
5295 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5296#ifdef FEAT_VIRTUALEDIT
5297 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5298#endif
5299#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5300 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5301#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005302#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005303 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005304 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005305 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5308 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5309#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005310#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005311 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5312#endif
5313#ifdef FEAT_CMDWIN
5314 /* set cedit_key */
5315 (void)check_cedit();
5316#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005317#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005318 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005319#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005320}
5321
5322/*
5323 * Check for string options that are NULL (normally only termcap options).
5324 */
5325 void
5326check_options()
5327{
5328 int opt_idx;
5329
5330 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5331 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5332 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5333}
5334
5335/*
5336 * Check string options in a buffer for NULL value.
5337 */
5338 void
5339check_buf_options(buf)
5340 buf_T *buf;
5341{
5342#if defined(FEAT_QUICKFIX)
5343 check_string_option(&buf->b_p_bh);
5344 check_string_option(&buf->b_p_bt);
5345#endif
5346#ifdef FEAT_MBYTE
5347 check_string_option(&buf->b_p_fenc);
5348#endif
5349 check_string_option(&buf->b_p_ff);
5350#ifdef FEAT_FIND_ID
5351 check_string_option(&buf->b_p_def);
5352 check_string_option(&buf->b_p_inc);
5353# ifdef FEAT_EVAL
5354 check_string_option(&buf->b_p_inex);
5355# endif
5356#endif
5357#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5358 check_string_option(&buf->b_p_inde);
5359 check_string_option(&buf->b_p_indk);
5360#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005361#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5362 check_string_option(&buf->b_p_bexpr);
5363#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005364#if defined(FEAT_CRYPT)
5365 check_string_option(&buf->b_p_cm);
5366#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005367#if defined(FEAT_EVAL)
5368 check_string_option(&buf->b_p_fex);
5369#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005370#ifdef FEAT_CRYPT
5371 check_string_option(&buf->b_p_key);
5372#endif
5373 check_string_option(&buf->b_p_kp);
5374 check_string_option(&buf->b_p_mps);
5375 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005376 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005377 check_string_option(&buf->b_p_isk);
5378#ifdef FEAT_COMMENTS
5379 check_string_option(&buf->b_p_com);
5380#endif
5381#ifdef FEAT_FOLDING
5382 check_string_option(&buf->b_p_cms);
5383#endif
5384 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005385#ifdef FEAT_TEXTOBJ
5386 check_string_option(&buf->b_p_qe);
5387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005388#ifdef FEAT_SYN_HL
5389 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005390#endif
5391#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005392 check_string_option(&buf->b_s.b_p_spc);
5393 check_string_option(&buf->b_s.b_p_spf);
5394 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005395#endif
5396#ifdef FEAT_SEARCHPATH
5397 check_string_option(&buf->b_p_sua);
5398#endif
5399#ifdef FEAT_CINDENT
5400 check_string_option(&buf->b_p_cink);
5401 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005402 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005403#endif
5404#ifdef FEAT_AUTOCMD
5405 check_string_option(&buf->b_p_ft);
5406#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005407#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5408 check_string_option(&buf->b_p_cinw);
5409#endif
5410#ifdef FEAT_INS_EXPAND
5411 check_string_option(&buf->b_p_cpt);
5412#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005413#ifdef FEAT_COMPL_FUNC
5414 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005415 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005416#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005417#ifdef FEAT_KEYMAP
5418 check_string_option(&buf->b_p_keymap);
5419#endif
5420#ifdef FEAT_QUICKFIX
5421 check_string_option(&buf->b_p_gp);
5422 check_string_option(&buf->b_p_mp);
5423 check_string_option(&buf->b_p_efm);
5424#endif
5425 check_string_option(&buf->b_p_ep);
5426 check_string_option(&buf->b_p_path);
5427 check_string_option(&buf->b_p_tags);
5428#ifdef FEAT_INS_EXPAND
5429 check_string_option(&buf->b_p_dict);
5430 check_string_option(&buf->b_p_tsr);
5431#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005432#ifdef FEAT_LISP
5433 check_string_option(&buf->b_p_lw);
5434#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005435 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005436}
5437
5438/*
5439 * Free the string allocated for an option.
5440 * Checks for the string being empty_option. This may happen if we're out of
5441 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5442 * check_options().
5443 * Does NOT check for P_ALLOCED flag!
5444 */
5445 void
5446free_string_option(p)
5447 char_u *p;
5448{
5449 if (p != empty_option)
5450 vim_free(p);
5451}
5452
5453 void
5454clear_string_option(pp)
5455 char_u **pp;
5456{
5457 if (*pp != empty_option)
5458 vim_free(*pp);
5459 *pp = empty_option;
5460}
5461
5462 static void
5463check_string_option(pp)
5464 char_u **pp;
5465{
5466 if (*pp == NULL)
5467 *pp = empty_option;
5468}
5469
5470/*
5471 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5472 */
5473 void
5474set_term_option_alloced(p)
5475 char_u **p;
5476{
5477 int opt_idx;
5478
5479 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5480 if (options[opt_idx].var == (char_u *)p)
5481 {
5482 options[opt_idx].flags |= P_ALLOCED;
5483 return;
5484 }
5485 return; /* cannot happen: didn't find it! */
5486}
5487
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005488#if defined(FEAT_EVAL) || defined(PROTO)
5489/*
5490 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5491 * Return FALSE when it wasn't.
5492 * Return -1 for an unknown option.
5493 */
5494 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005495was_set_insecurely(opt, opt_flags)
5496 char_u *opt;
5497 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005498{
5499 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005500 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005501
5502 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005503 {
5504 flagp = insecure_flag(idx, opt_flags);
5505 return (*flagp & P_INSECURE) != 0;
5506 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005507 EMSG2(_(e_intern2), "was_set_insecurely()");
5508 return -1;
5509}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005510
5511/*
5512 * Get a pointer to the flags used for the P_INSECURE flag of option
5513 * "opt_idx". For some local options a local flags field is used.
5514 */
5515 static long_u *
5516insecure_flag(opt_idx, opt_flags)
5517 int opt_idx;
5518 int opt_flags;
5519{
5520 if (opt_flags & OPT_LOCAL)
5521 switch ((int)options[opt_idx].indir)
5522 {
5523#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005524 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005525#endif
5526#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005527# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005528 case PV_FDE: return &curwin->w_p_fde_flags;
5529 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005530# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005531# ifdef FEAT_BEVAL
5532 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5533# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005534# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005535 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005536# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005537 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005538# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005539 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005540# endif
5541#endif
5542 }
5543
5544 /* Nothing special, return global flags field. */
5545 return &options[opt_idx].flags;
5546}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005547#endif
5548
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005549#ifdef FEAT_TITLE
5550static void redraw_titles __ARGS((void));
5551
5552/*
5553 * Redraw the window title and/or tab page text later.
5554 */
5555static void redraw_titles()
5556{
5557 need_maketitle = TRUE;
5558# ifdef FEAT_WINDOWS
5559 redraw_tabline = TRUE;
5560# endif
5561}
5562#endif
5563
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564/*
5565 * Set a string option to a new value (without checking the effect).
5566 * The string is copied into allocated memory.
5567 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005568 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005569 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005570 */
5571 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005572set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573 char_u *name;
5574 int opt_idx;
5575 char_u *val;
5576 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005577 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578{
5579 char_u *s;
5580 char_u **varp;
5581 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005582 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583
Bram Moolenaar89d40322006-08-29 15:30:07 +00005584 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005585 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005586 idx = findoption(name);
5587 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005588 {
5589 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005590 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005592 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005593 }
5594
Bram Moolenaar89d40322006-08-29 15:30:07 +00005595 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005596 return;
5597
5598 s = vim_strsave(val);
5599 if (s != NULL)
5600 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005601 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005602 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005603 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005604 free_string_option(*varp);
5605 *varp = s;
5606
5607 /* For buffer/window local option may also set the global value. */
5608 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005609 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005610
Bram Moolenaar89d40322006-08-29 15:30:07 +00005611 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005612
5613 /* When setting both values of a global option with a local value,
5614 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005615 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005616 {
5617 free_string_option(*varp);
5618 *varp = empty_option;
5619 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005620# ifdef FEAT_EVAL
5621 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005622 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005623 set_sid == 0 ? current_SID : set_sid);
5624# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005625 }
5626}
5627
5628/*
5629 * Set global value for string option when it's a local option.
5630 */
5631 static void
5632set_string_option_global(opt_idx, varp)
5633 int opt_idx; /* option index */
5634 char_u **varp; /* pointer to option variable */
5635{
5636 char_u **p, *s;
5637
5638 /* the global value is always allocated */
5639 if (options[opt_idx].var == VAR_WIN)
5640 p = (char_u **)GLOBAL_WO(varp);
5641 else
5642 p = (char_u **)options[opt_idx].var;
5643 if (options[opt_idx].indir != PV_NONE
5644 && p != varp
5645 && (s = vim_strsave(*varp)) != NULL)
5646 {
5647 free_string_option(*p);
5648 *p = s;
5649 }
5650}
5651
5652/*
5653 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005654 *
5655 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005656 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005657 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005658set_string_option(opt_idx, value, opt_flags)
5659 int opt_idx;
5660 char_u *value;
5661 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5662{
5663 char_u *s;
5664 char_u **varp;
5665 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005666 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667
5668 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005669 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670
5671 s = vim_strsave(value);
5672 if (s != NULL)
5673 {
5674 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5675 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005676 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677 ? OPT_GLOBAL : OPT_LOCAL)
5678 : opt_flags);
5679 oldval = *varp;
5680 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005681 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5682 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005683 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005685 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005686}
5687
5688/*
5689 * Handle string options that need some action to perform when changed.
5690 * Returns NULL for success, or an error message for an error.
5691 */
5692 static char_u *
5693did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5694 opt_flags)
5695 int opt_idx; /* index in options[] table */
5696 char_u **varp; /* pointer to the option variable */
5697 int new_value_alloced; /* new value was allocated */
5698 char_u *oldval; /* previous value of the option */
5699 char_u *errbuf; /* buffer for errors, or NULL */
5700 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5701{
5702 char_u *errmsg = NULL;
5703 char_u *s, *p;
5704 int did_chartab = FALSE;
5705 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005706 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005707#ifdef FEAT_GUI
5708 /* set when changing an option that only requires a redraw in the GUI */
5709 int redraw_gui_only = FALSE;
5710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711
5712 /* Get the global option to compare with, otherwise we would have to check
5713 * two values for all local options. */
5714 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5715
5716 /* Disallow changing some options from secure mode */
5717 if ((secure
5718#ifdef HAVE_SANDBOX
5719 || sandbox != 0
5720#endif
5721 ) && (options[opt_idx].flags & P_SECURE))
5722 {
5723 errmsg = e_secure;
5724 }
5725
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005726 /* Check for a "normal" file name in some options. Disallow a path
5727 * separator (slash and/or backslash), wildcards and characters that are
5728 * often illegal in a file name. */
5729 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005730 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005731 {
5732 errmsg = e_invarg;
5733 }
5734
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735 /* 'term' */
5736 else if (varp == &T_NAME)
5737 {
5738 if (T_NAME[0] == NUL)
5739 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5740#ifdef FEAT_GUI
5741 if (gui.in_use)
5742 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5743 else if (term_is_gui(T_NAME))
5744 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5745#endif
5746 else if (set_termname(T_NAME) == FAIL)
5747 errmsg = (char_u *)N_("E522: Not found in termcap");
5748 else
5749 /* Screen colors may have changed. */
5750 redraw_later_clear();
5751 }
5752
5753 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005754 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005755 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005756 char_u *bkc = p_bkc;
5757 unsigned int *flags = &bkc_flags;
5758
5759 if (opt_flags & OPT_LOCAL)
5760 {
5761 bkc = curbuf->b_p_bkc;
5762 flags = &curbuf->b_bkc_flags;
5763 }
5764
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005765 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5766 /* make the local value empty: use the global value */
5767 *flags = 0;
5768 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005769 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005770 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5771 errmsg = e_invarg;
5772 if ((((int)*flags & BKC_AUTO) != 0)
5773 + (((int)*flags & BKC_YES) != 0)
5774 + (((int)*flags & BKC_NO) != 0) != 1)
5775 {
5776 /* Must have exactly one of "auto", "yes" and "no". */
5777 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5778 errmsg = e_invarg;
5779 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005780 }
5781 }
5782
5783 /* 'backupext' and 'patchmode' */
5784 else if (varp == &p_bex || varp == &p_pm)
5785 {
5786 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5787 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5788 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5789 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005790#ifdef FEAT_LINEBREAK
5791 /* 'breakindentopt' */
5792 else if (varp == &curwin->w_p_briopt)
5793 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005794 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005795 errmsg = e_invarg;
5796 }
5797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005798
5799 /*
5800 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5801 * If the new option is invalid, use old value. 'lisp' option: refill
5802 * chartab[] for '-' char
5803 */
5804 else if ( varp == &p_isi
5805 || varp == &(curbuf->b_p_isk)
5806 || varp == &p_isp
5807 || varp == &p_isf)
5808 {
5809 if (init_chartab() == FAIL)
5810 {
5811 did_chartab = TRUE; /* need to restore it below */
5812 errmsg = e_invarg; /* error in value */
5813 }
5814 }
5815
5816 /* 'helpfile' */
5817 else if (varp == &p_hf)
5818 {
5819 /* May compute new values for $VIM and $VIMRUNTIME */
5820 if (didset_vim)
5821 {
5822 vim_setenv((char_u *)"VIM", (char_u *)"");
5823 didset_vim = FALSE;
5824 }
5825 if (didset_vimruntime)
5826 {
5827 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5828 didset_vimruntime = FALSE;
5829 }
5830 }
5831
Bram Moolenaar1a384422010-07-14 19:53:30 +02005832#ifdef FEAT_SYN_HL
5833 /* 'colorcolumn' */
5834 else if (varp == &curwin->w_p_cc)
5835 errmsg = check_colorcolumn(curwin);
5836#endif
5837
Bram Moolenaar071d4272004-06-13 20:20:40 +00005838#ifdef FEAT_MULTI_LANG
5839 /* 'helplang' */
5840 else if (varp == &p_hlg)
5841 {
5842 /* Check for "", "ab", "ab,cd", etc. */
5843 for (s = p_hlg; *s != NUL; s += 3)
5844 {
5845 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5846 {
5847 errmsg = e_invarg;
5848 break;
5849 }
5850 if (s[2] == NUL)
5851 break;
5852 }
5853 }
5854#endif
5855
5856 /* 'highlight' */
5857 else if (varp == &p_hl)
5858 {
5859 if (highlight_changed() == FAIL)
5860 errmsg = e_invarg; /* invalid flags */
5861 }
5862
5863 /* 'nrformats' */
5864 else if (gvarp == &p_nf)
5865 {
5866 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5867 errmsg = e_invarg;
5868 }
5869
5870#ifdef FEAT_SESSION
5871 /* 'sessionoptions' */
5872 else if (varp == &p_ssop)
5873 {
5874 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5875 errmsg = e_invarg;
5876 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5877 {
5878 /* Don't allow both "sesdir" and "curdir". */
5879 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5880 errmsg = e_invarg;
5881 }
5882 }
5883 /* 'viewoptions' */
5884 else if (varp == &p_vop)
5885 {
5886 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5887 errmsg = e_invarg;
5888 }
5889#endif
5890
5891 /* 'scrollopt' */
5892#ifdef FEAT_SCROLLBIND
5893 else if (varp == &p_sbo)
5894 {
5895 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5896 errmsg = e_invarg;
5897 }
5898#endif
5899
5900 /* 'ambiwidth' */
5901#ifdef FEAT_MBYTE
5902 else if (varp == &p_ambw)
5903 {
5904 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5905 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005906 else if (set_chars_option(&p_lcs) != NULL)
5907 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5908# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5909 else if (set_chars_option(&p_fcs) != NULL)
5910 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5911# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 }
5913#endif
5914
5915 /* 'background' */
5916 else if (varp == &p_bg)
5917 {
5918 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5919 {
5920#ifdef FEAT_EVAL
5921 int dark = (*p_bg == 'd');
5922#endif
5923
5924 init_highlight(FALSE, FALSE);
5925
5926#ifdef FEAT_EVAL
5927 if (dark != (*p_bg == 'd')
5928 && get_var_value((char_u *)"g:colors_name") != NULL)
5929 {
5930 /* The color scheme must have set 'background' back to another
5931 * value, that's not what we want here. Disable the color
5932 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005933 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005934 free_string_option(p_bg);
5935 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5936 check_string_option(&p_bg);
5937 init_highlight(FALSE, FALSE);
5938 }
5939#endif
5940 }
5941 else
5942 errmsg = e_invarg;
5943 }
5944
5945 /* 'wildmode' */
5946 else if (varp == &p_wim)
5947 {
5948 if (check_opt_wim() == FAIL)
5949 errmsg = e_invarg;
5950 }
5951
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005952#ifdef FEAT_CMDL_COMPL
5953 /* 'wildoptions' */
5954 else if (varp == &p_wop)
5955 {
5956 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5957 errmsg = e_invarg;
5958 }
5959#endif
5960
Bram Moolenaar071d4272004-06-13 20:20:40 +00005961#ifdef FEAT_WAK
5962 /* 'winaltkeys' */
5963 else if (varp == &p_wak)
5964 {
5965 if (*p_wak == NUL
5966 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5967 errmsg = e_invarg;
5968# ifdef FEAT_MENU
5969# ifdef FEAT_GUI_MOTIF
5970 else if (gui.in_use)
5971 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5972# else
5973# ifdef FEAT_GUI_GTK
5974 else if (gui.in_use)
5975 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5976# endif
5977# endif
5978# endif
5979 }
5980#endif
5981
5982#ifdef FEAT_AUTOCMD
5983 /* 'eventignore' */
5984 else if (varp == &p_ei)
5985 {
5986 if (check_ei() == FAIL)
5987 errmsg = e_invarg;
5988 }
5989#endif
5990
5991#ifdef FEAT_MBYTE
5992 /* 'encoding' and 'fileencoding' */
5993 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5994 {
5995 if (gvarp == &p_fenc)
5996 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005997 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005998 errmsg = e_modifiable;
5999 else if (vim_strchr(*varp, ',') != NULL)
6000 /* No comma allowed in 'fileencoding'; catches confusing it
6001 * with 'fileencodings'. */
6002 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006003 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006004 {
6005# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006007 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006008# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006009 /* Add 'fileencoding' to the swap file. */
6010 ml_setflags(curbuf);
6011 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006012 }
6013 if (errmsg == NULL)
6014 {
6015 /* canonize the value, so that STRCMP() can be used on it */
6016 p = enc_canonize(*varp);
6017 if (p != NULL)
6018 {
6019 vim_free(*varp);
6020 *varp = p;
6021 }
6022 if (varp == &p_enc)
6023 {
6024 errmsg = mb_init();
6025# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006026 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006027# endif
6028 }
6029 }
6030
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006031# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006032 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6033 {
6034 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6035 if (STRCMP(p_tenc, "utf-8") != 0)
6036 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6037 }
6038# endif
6039
6040 if (errmsg == NULL)
6041 {
6042# ifdef FEAT_KEYMAP
6043 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6044 * (with another encoding). */
6045 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6046 (void)keymap_init();
6047# endif
6048
6049 /* When 'termencoding' is not empty and 'encoding' changes or when
6050 * 'termencoding' changes, need to setup for keyboard input and
6051 * display output conversion. */
6052 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6053 {
6054 convert_setup(&input_conv, p_tenc, p_enc);
6055 convert_setup(&output_conv, p_enc, p_tenc);
6056 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006057
6058# if defined(WIN3264) && defined(FEAT_MBYTE)
6059 /* $HOME may have characters in active code page. */
6060 if (varp == &p_enc)
6061 init_homedir();
6062# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006063 }
6064 }
6065#endif
6066
6067#if defined(FEAT_POSTSCRIPT)
6068 else if (varp == &p_penc)
6069 {
6070 /* Canonize printencoding if VIM standard one */
6071 p = enc_canonize(p_penc);
6072 if (p != NULL)
6073 {
6074 vim_free(p_penc);
6075 p_penc = p;
6076 }
6077 else
6078 {
6079 /* Ensure lower case and '-' for '_' */
6080 for (s = p_penc; *s != NUL; s++)
6081 {
6082 if (*s == '_')
6083 *s = '-';
6084 else
6085 *s = TOLOWER_ASC(*s);
6086 }
6087 }
6088 }
6089#endif
6090
Bram Moolenaar9372a112005-12-06 19:59:18 +00006091#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006092 else if (varp == &p_imak)
6093 {
6094 if (gui.in_use && !im_xim_isvalid_imactivate())
6095 errmsg = e_invarg;
6096 }
6097#endif
6098
6099#ifdef FEAT_KEYMAP
6100 else if (varp == &curbuf->b_p_keymap)
6101 {
6102 /* load or unload key mapping tables */
6103 errmsg = keymap_init();
6104
Bram Moolenaarfab06232009-03-04 03:13:35 +00006105 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006106 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006107 if (*curbuf->b_p_keymap != NUL)
6108 {
6109 /* Installed a new keymap, switch on using it. */
6110 curbuf->b_p_iminsert = B_IMODE_LMAP;
6111 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6112 curbuf->b_p_imsearch = B_IMODE_LMAP;
6113 }
6114 else
6115 {
6116 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6117 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6118 curbuf->b_p_iminsert = B_IMODE_NONE;
6119 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6120 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6121 }
6122 if ((opt_flags & OPT_LOCAL) == 0)
6123 {
6124 set_iminsert_global();
6125 set_imsearch_global();
6126 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127# ifdef FEAT_WINDOWS
6128 status_redraw_curbuf();
6129# endif
6130 }
6131 }
6132#endif
6133
6134 /* 'fileformat' */
6135 else if (gvarp == &p_ff)
6136 {
6137 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6138 errmsg = e_modifiable;
6139 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6140 errmsg = e_invarg;
6141 else
6142 {
6143 /* may also change 'textmode' */
6144 if (get_fileformat(curbuf) == EOL_DOS)
6145 curbuf->b_p_tx = TRUE;
6146 else
6147 curbuf->b_p_tx = FALSE;
6148#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006149 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006151 /* update flag in swap file */
6152 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006153 /* Redraw needed when switching to/from "mac": a CR in the text
6154 * will be displayed differently. */
6155 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6156 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006157 }
6158 }
6159
6160 /* 'fileformats' */
6161 else if (varp == &p_ffs)
6162 {
6163 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6164 errmsg = e_invarg;
6165 else
6166 {
6167 /* also change 'textauto' */
6168 if (*p_ffs == NUL)
6169 p_ta = FALSE;
6170 else
6171 p_ta = TRUE;
6172 }
6173 }
6174
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006175#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006176 /* 'cryptkey' */
6177 else if (gvarp == &p_key)
6178 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006179# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006180 /* Make sure the ":set" command doesn't show the new value in the
6181 * history. */
6182 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006183# endif
6184 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6185 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006186 ml_set_crypt_key(curbuf, oldval,
6187 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006188 }
6189
6190 else if (gvarp == &p_cm)
6191 {
6192 if (opt_flags & OPT_LOCAL)
6193 p = curbuf->b_p_cm;
6194 else
6195 p = p_cm;
6196 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6197 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006198 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006199 errmsg = e_invarg;
6200 else
6201 {
6202 /* When setting the global value to empty, make it "zip". */
6203 if (*p_cm == NUL)
6204 {
6205 if (new_value_alloced)
6206 free_string_option(p_cm);
6207 p_cm = vim_strsave((char_u *)"zip");
6208 new_value_alloced = TRUE;
6209 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006210 /* When using ":set cm=name" the local value is going to be empty.
6211 * Do that here, otherwise the crypt functions will still use the
6212 * local value. */
6213 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6214 {
6215 free_string_option(curbuf->b_p_cm);
6216 curbuf->b_p_cm = empty_option;
6217 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006218
6219 /* Need to update the swapfile when the effective method changed.
6220 * Set "s" to the effective old value, "p" to the effective new
6221 * method and compare. */
6222 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6223 s = p_cm; /* was previously using the global value */
6224 else
6225 s = oldval;
6226 if (*curbuf->b_p_cm == NUL)
6227 p = p_cm; /* is now using the global value */
6228 else
6229 p = curbuf->b_p_cm;
6230 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006231 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006232
6233 /* If the global value changes need to update the swapfile for all
6234 * buffers using that value. */
6235 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6236 {
6237 buf_T *buf;
6238
6239 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6240 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006241 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006242 }
6243 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006244 }
6245#endif
6246
6247 /* 'matchpairs' */
6248 else if (gvarp == &p_mps)
6249 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006250#ifdef FEAT_MBYTE
6251 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006252 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006253 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006254 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006255 int x2 = -1;
6256 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006257
6258 if (*p != NUL)
6259 p += mb_ptr2len(p);
6260 if (*p != NUL)
6261 x2 = *p++;
6262 if (*p != NUL)
6263 {
6264 x3 = mb_ptr2char(p);
6265 p += mb_ptr2len(p);
6266 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006267 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006268 {
6269 errmsg = e_invarg;
6270 break;
6271 }
6272 if (*p == NUL)
6273 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006274 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006275 }
6276 else
6277#endif
6278 {
6279 /* Check for "x:y,x:y" */
6280 for (p = *varp; *p != NUL; p += 4)
6281 {
6282 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6283 {
6284 errmsg = e_invarg;
6285 break;
6286 }
6287 if (p[3] == NUL)
6288 break;
6289 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006290 }
6291 }
6292
6293#ifdef FEAT_COMMENTS
6294 /* 'comments' */
6295 else if (gvarp == &p_com)
6296 {
6297 for (s = *varp; *s; )
6298 {
6299 while (*s && *s != ':')
6300 {
6301 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6302 && !VIM_ISDIGIT(*s) && *s != '-')
6303 {
6304 errmsg = illegal_char(errbuf, *s);
6305 break;
6306 }
6307 ++s;
6308 }
6309 if (*s++ == NUL)
6310 errmsg = (char_u *)N_("E524: Missing colon");
6311 else if (*s == ',' || *s == NUL)
6312 errmsg = (char_u *)N_("E525: Zero length string");
6313 if (errmsg != NULL)
6314 break;
6315 while (*s && *s != ',')
6316 {
6317 if (*s == '\\' && s[1] != NUL)
6318 ++s;
6319 ++s;
6320 }
6321 s = skip_to_option_part(s);
6322 }
6323 }
6324#endif
6325
6326 /* 'listchars' */
6327 else if (varp == &p_lcs)
6328 {
6329 errmsg = set_chars_option(varp);
6330 }
6331
6332#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6333 /* 'fillchars' */
6334 else if (varp == &p_fcs)
6335 {
6336 errmsg = set_chars_option(varp);
6337 }
6338#endif
6339
6340#ifdef FEAT_CMDWIN
6341 /* 'cedit' */
6342 else if (varp == &p_cedit)
6343 {
6344 errmsg = check_cedit();
6345 }
6346#endif
6347
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006348 /* 'verbosefile' */
6349 else if (varp == &p_vfile)
6350 {
6351 verbose_stop();
6352 if (*p_vfile != NUL && verbose_open() == FAIL)
6353 errmsg = e_invarg;
6354 }
6355
Bram Moolenaar071d4272004-06-13 20:20:40 +00006356#ifdef FEAT_VIMINFO
6357 /* 'viminfo' */
6358 else if (varp == &p_viminfo)
6359 {
6360 for (s = p_viminfo; *s;)
6361 {
6362 /* Check it's a valid character */
6363 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6364 {
6365 errmsg = illegal_char(errbuf, *s);
6366 break;
6367 }
6368 if (*s == 'n') /* name is always last one */
6369 {
6370 break;
6371 }
6372 else if (*s == 'r') /* skip until next ',' */
6373 {
6374 while (*++s && *s != ',')
6375 ;
6376 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006377 else if (*s == '%')
6378 {
6379 /* optional number */
6380 while (vim_isdigit(*++s))
6381 ;
6382 }
6383 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006384 ++s; /* no extra chars */
6385 else /* must have a number */
6386 {
6387 while (vim_isdigit(*++s))
6388 ;
6389
6390 if (!VIM_ISDIGIT(*(s - 1)))
6391 {
6392 if (errbuf != NULL)
6393 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006394 sprintf((char *)errbuf,
6395 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396 transchar_byte(*(s - 1)));
6397 errmsg = errbuf;
6398 }
6399 else
6400 errmsg = (char_u *)"";
6401 break;
6402 }
6403 }
6404 if (*s == ',')
6405 ++s;
6406 else if (*s)
6407 {
6408 if (errbuf != NULL)
6409 errmsg = (char_u *)N_("E527: Missing comma");
6410 else
6411 errmsg = (char_u *)"";
6412 break;
6413 }
6414 }
6415 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6416 errmsg = (char_u *)N_("E528: Must specify a ' value");
6417 }
6418#endif /* FEAT_VIMINFO */
6419
6420 /* terminal options */
6421 else if (istermoption(&options[opt_idx]) && full_screen)
6422 {
6423 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6424 if (varp == &T_CCO)
6425 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006426 int colors = atoi((char *)T_CCO);
6427
6428 /* Only reinitialize colors if t_Co value has really changed to
6429 * avoid expensive reload of colorscheme if t_Co is set to the
6430 * same value multiple times. */
6431 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006432 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006433 t_colors = colors;
6434 if (t_colors <= 1)
6435 {
6436 if (new_value_alloced)
6437 vim_free(T_CCO);
6438 T_CCO = empty_option;
6439 }
6440 /* We now have a different color setup, initialize it again. */
6441 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006442 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006443 }
6444 ttest(FALSE);
6445 if (varp == &T_ME)
6446 {
6447 out_str(T_ME);
6448 redraw_later(CLEAR);
6449#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6450 /* Since t_me has been set, this probably means that the user
6451 * wants to use this as default colors. Need to reset default
6452 * background/foreground colors. */
6453 mch_set_normal_colors();
6454#endif
6455 }
6456 }
6457
6458#ifdef FEAT_LINEBREAK
6459 /* 'showbreak' */
6460 else if (varp == &p_sbr)
6461 {
6462 for (s = p_sbr; *s; )
6463 {
6464 if (ptr2cells(s) != 1)
6465 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006466 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 }
6468 }
6469#endif
6470
6471#ifdef FEAT_GUI
6472 /* 'guifont' */
6473 else if (varp == &p_guifont)
6474 {
6475 if (gui.in_use)
6476 {
6477 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006478# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006479 /*
6480 * Put up a font dialog and let the user select a new value.
6481 * If this is cancelled go back to the old value but don't
6482 * give an error message.
6483 */
6484 if (STRCMP(p, "*") == 0)
6485 {
6486 p = gui_mch_font_dialog(oldval);
6487
6488 if (new_value_alloced)
6489 free_string_option(p_guifont);
6490
6491 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6492 new_value_alloced = TRUE;
6493 }
6494# endif
6495 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6496 {
6497# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6498 if (STRCMP(p_guifont, "*") == 0)
6499 {
6500 /* Dialog was cancelled: Keep the old value without giving
6501 * an error message. */
6502 if (new_value_alloced)
6503 free_string_option(p_guifont);
6504 p_guifont = vim_strsave(oldval);
6505 new_value_alloced = TRUE;
6506 }
6507 else
6508# endif
6509 errmsg = (char_u *)N_("E596: Invalid font(s)");
6510 }
6511 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006512 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006513 }
6514# ifdef FEAT_XFONTSET
6515 else if (varp == &p_guifontset)
6516 {
6517 if (STRCMP(p_guifontset, "*") == 0)
6518 errmsg = (char_u *)N_("E597: can't select fontset");
6519 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6520 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006521 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522 }
6523# endif
6524# ifdef FEAT_MBYTE
6525 else if (varp == &p_guifontwide)
6526 {
6527 if (STRCMP(p_guifontwide, "*") == 0)
6528 errmsg = (char_u *)N_("E533: can't select wide font");
6529 else if (gui_get_wide_font() == FAIL)
6530 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006531 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006532 }
6533# endif
6534#endif
6535
6536#ifdef CURSOR_SHAPE
6537 /* 'guicursor' */
6538 else if (varp == &p_guicursor)
6539 errmsg = parse_shape_opt(SHAPE_CURSOR);
6540#endif
6541
6542#ifdef FEAT_MOUSESHAPE
6543 /* 'mouseshape' */
6544 else if (varp == &p_mouseshape)
6545 {
6546 errmsg = parse_shape_opt(SHAPE_MOUSE);
6547 update_mouseshape(-1);
6548 }
6549#endif
6550
6551#ifdef FEAT_PRINTER
6552 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006553 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006554# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006555 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006556 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006557# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006558#endif
6559
6560#ifdef FEAT_LANGMAP
6561 /* 'langmap' */
6562 else if (varp == &p_langmap)
6563 langmap_set();
6564#endif
6565
6566#ifdef FEAT_LINEBREAK
6567 /* 'breakat' */
6568 else if (varp == &p_breakat)
6569 fill_breakat_flags();
6570#endif
6571
6572#ifdef FEAT_TITLE
6573 /* 'titlestring' and 'iconstring' */
6574 else if (varp == &p_titlestring || varp == &p_iconstring)
6575 {
6576# ifdef FEAT_STL_OPT
6577 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6578
6579 /* NULL => statusline syntax */
6580 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6581 stl_syntax |= flagval;
6582 else
6583 stl_syntax &= ~flagval;
6584# endif
6585 did_set_title(varp == &p_iconstring);
6586
6587 }
6588#endif
6589
6590#ifdef FEAT_GUI
6591 /* 'guioptions' */
6592 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006593 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006594 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006595 redraw_gui_only = TRUE;
6596 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006597#endif
6598
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006599#if defined(FEAT_GUI_TABLINE)
6600 /* 'guitablabel' */
6601 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006602 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006603 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006604 redraw_gui_only = TRUE;
6605 }
6606 /* 'guitabtooltip' */
6607 else if (varp == &p_gtt)
6608 {
6609 redraw_gui_only = TRUE;
6610 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006611#endif
6612
Bram Moolenaar071d4272004-06-13 20:20:40 +00006613#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6614 /* 'ttymouse' */
6615 else if (varp == &p_ttym)
6616 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006617 /* Switch the mouse off before changing the escape sequences used for
6618 * that. */
6619 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006620 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6621 errmsg = e_invarg;
6622 else
6623 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006624 if (termcap_active)
6625 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006626 }
6627#endif
6628
Bram Moolenaar071d4272004-06-13 20:20:40 +00006629 /* 'selection' */
6630 else if (varp == &p_sel)
6631 {
6632 if (*p_sel == NUL
6633 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6634 errmsg = e_invarg;
6635 }
6636
6637 /* 'selectmode' */
6638 else if (varp == &p_slm)
6639 {
6640 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6641 errmsg = e_invarg;
6642 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006643
6644#ifdef FEAT_BROWSE
6645 /* 'browsedir' */
6646 else if (varp == &p_bsdir)
6647 {
6648 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6649 && !mch_isdir(p_bsdir))
6650 errmsg = e_invarg;
6651 }
6652#endif
6653
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 /* 'keymodel' */
6655 else if (varp == &p_km)
6656 {
6657 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6658 errmsg = e_invarg;
6659 else
6660 {
6661 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6662 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6663 }
6664 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665
6666 /* 'mousemodel' */
6667 else if (varp == &p_mousem)
6668 {
6669 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6670 errmsg = e_invarg;
6671#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6672 else if (*p_mousem != *oldval)
6673 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6674 * to create or delete the popup menus. */
6675 gui_motif_update_mousemodel(root_menu);
6676#endif
6677 }
6678
6679 /* 'switchbuf' */
6680 else if (varp == &p_swb)
6681 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006682 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006683 errmsg = e_invarg;
6684 }
6685
6686 /* 'debug' */
6687 else if (varp == &p_debug)
6688 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006689 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006690 errmsg = e_invarg;
6691 }
6692
6693 /* 'display' */
6694 else if (varp == &p_dy)
6695 {
6696 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6697 errmsg = e_invarg;
6698 else
6699 (void)init_chartab();
6700
6701 }
6702
6703#ifdef FEAT_VERTSPLIT
6704 /* 'eadirection' */
6705 else if (varp == &p_ead)
6706 {
6707 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6708 errmsg = e_invarg;
6709 }
6710#endif
6711
6712#ifdef FEAT_CLIPBOARD
6713 /* 'clipboard' */
6714 else if (varp == &p_cb)
6715 errmsg = check_clipboard_option();
6716#endif
6717
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006718#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006719 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6720 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006721 else if (varp == &(curwin->w_s->b_p_spl)
6722 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006723 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006724 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006725 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006726
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006727 if (varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006728 {
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006729 l = (int)STRLEN(curwin->w_s->b_p_spf);
6730 if (l > 0 && (l < 4 || STRCMP(curwin->w_s->b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006731 ".add") != 0))
6732 errmsg = e_invarg;
6733 }
6734
6735 if (errmsg == NULL)
6736 {
6737 FOR_ALL_WINDOWS(wp)
6738 if (wp->w_buffer == curbuf && wp->w_p_spell)
6739 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006740 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006741# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006742 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006743# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006744 }
6745 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006746 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006747 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006748 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006749 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006750 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006751 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006752 /* 'spellsuggest' */
6753 else if (varp == &p_sps)
6754 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006755 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006756 errmsg = e_invarg;
6757 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006758 /* 'mkspellmem' */
6759 else if (varp == &p_msm)
6760 {
6761 if (spell_check_msm() != OK)
6762 errmsg = e_invarg;
6763 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006764#endif
6765
Bram Moolenaar071d4272004-06-13 20:20:40 +00006766#ifdef FEAT_QUICKFIX
6767 /* When 'bufhidden' is set, check for valid value. */
6768 else if (gvarp == &p_bh)
6769 {
6770 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6771 errmsg = e_invarg;
6772 }
6773
6774 /* When 'buftype' is set, check for valid value. */
6775 else if (gvarp == &p_bt)
6776 {
6777 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6778 errmsg = e_invarg;
6779 else
6780 {
6781# ifdef FEAT_WINDOWS
6782 if (curwin->w_status_height)
6783 {
6784 curwin->w_redr_status = TRUE;
6785 redraw_later(VALID);
6786 }
6787# endif
6788 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006789# ifdef FEAT_TITLE
6790 redraw_titles();
6791# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792 }
6793 }
6794#endif
6795
6796#ifdef FEAT_STL_OPT
6797 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006798 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006799 {
6800 int wid;
6801
6802 if (varp == &p_ruf) /* reset ru_wid first */
6803 ru_wid = 0;
6804 s = *varp;
6805 if (varp == &p_ruf && *s == '%')
6806 {
6807 /* set ru_wid if 'ruf' starts with "%99(" */
6808 if (*++s == '-') /* ignore a '-' */
6809 s++;
6810 wid = getdigits(&s);
6811 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6812 ru_wid = wid;
6813 else
6814 errmsg = check_stl_option(p_ruf);
6815 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006816 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006817 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006818 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006819 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006820 comp_col();
6821 }
6822#endif
6823
6824#ifdef FEAT_INS_EXPAND
6825 /* check if it is a valid value for 'complete' -- Acevedo */
6826 else if (gvarp == &p_cpt)
6827 {
6828 for (s = *varp; *s;)
6829 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006830 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006831 s++;
6832 if (!*s)
6833 break;
6834 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6835 {
6836 errmsg = illegal_char(errbuf, *s);
6837 break;
6838 }
6839 if (*++s != NUL && *s != ',' && *s != ' ')
6840 {
6841 if (s[-1] == 'k' || s[-1] == 's')
6842 {
6843 /* skip optional filename after 'k' and 's' */
6844 while (*s && *s != ',' && *s != ' ')
6845 {
6846 if (*s == '\\')
6847 ++s;
6848 ++s;
6849 }
6850 }
6851 else
6852 {
6853 if (errbuf != NULL)
6854 {
6855 sprintf((char *)errbuf,
6856 _("E535: Illegal character after <%c>"),
6857 *--s);
6858 errmsg = errbuf;
6859 }
6860 else
6861 errmsg = (char_u *)"";
6862 break;
6863 }
6864 }
6865 }
6866 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006867
6868 /* 'completeopt' */
6869 else if (varp == &p_cot)
6870 {
6871 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6872 errmsg = e_invarg;
6873 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006874#endif /* FEAT_INS_EXPAND */
6875
6876
6877#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6878 else if (varp == &p_toolbar)
6879 {
6880 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6881 &toolbar_flags, TRUE) != OK)
6882 errmsg = e_invarg;
6883 else
6884 {
6885 out_flush();
6886 gui_mch_show_toolbar((toolbar_flags &
6887 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6888 }
6889 }
6890#endif
6891
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006892#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006893 /* 'toolbariconsize': GTK+ 2 only */
6894 else if (varp == &p_tbis)
6895 {
6896 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6897 errmsg = e_invarg;
6898 else
6899 {
6900 out_flush();
6901 gui_mch_show_toolbar((toolbar_flags &
6902 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6903 }
6904 }
6905#endif
6906
6907 /* 'pastetoggle': translate key codes like in a mapping */
6908 else if (varp == &p_pt)
6909 {
6910 if (*p_pt)
6911 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006912 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006913 if (p != NULL)
6914 {
6915 if (new_value_alloced)
6916 free_string_option(p_pt);
6917 p_pt = p;
6918 new_value_alloced = TRUE;
6919 }
6920 }
6921 }
6922
6923 /* 'backspace' */
6924 else if (varp == &p_bs)
6925 {
6926 if (VIM_ISDIGIT(*p_bs))
6927 {
6928 if (*p_bs >'2' || p_bs[1] != NUL)
6929 errmsg = e_invarg;
6930 }
6931 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6932 errmsg = e_invarg;
6933 }
6934
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006935#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936 /* 'casemap' */
6937 else if (varp == &p_cmp)
6938 {
6939 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6940 errmsg = e_invarg;
6941 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006942#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943
6944#ifdef FEAT_DIFF
6945 /* 'diffopt' */
6946 else if (varp == &p_dip)
6947 {
6948 if (diffopt_changed() == FAIL)
6949 errmsg = e_invarg;
6950 }
6951#endif
6952
6953#ifdef FEAT_FOLDING
6954 /* 'foldmethod' */
6955 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6956 {
6957 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6958 || *curwin->w_p_fdm == NUL)
6959 errmsg = e_invarg;
6960 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006961 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006962 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006963 if (foldmethodIsDiff(curwin))
6964 newFoldLevel();
6965 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966 }
6967# ifdef FEAT_EVAL
6968 /* 'foldexpr' */
6969 else if (varp == &curwin->w_p_fde)
6970 {
6971 if (foldmethodIsExpr(curwin))
6972 foldUpdateAll(curwin);
6973 }
6974# endif
6975 /* 'foldmarker' */
6976 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6977 {
6978 p = vim_strchr(*varp, ',');
6979 if (p == NULL)
6980 errmsg = (char_u *)N_("E536: comma required");
6981 else if (p == *varp || p[1] == NUL)
6982 errmsg = e_invarg;
6983 else if (foldmethodIsMarker(curwin))
6984 foldUpdateAll(curwin);
6985 }
6986 /* 'commentstring' */
6987 else if (gvarp == &p_cms)
6988 {
6989 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6990 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6991 }
6992 /* 'foldopen' */
6993 else if (varp == &p_fdo)
6994 {
6995 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6996 errmsg = e_invarg;
6997 }
6998 /* 'foldclose' */
6999 else if (varp == &p_fcl)
7000 {
7001 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7002 errmsg = e_invarg;
7003 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007004 /* 'foldignore' */
7005 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7006 {
7007 if (foldmethodIsIndent(curwin))
7008 foldUpdateAll(curwin);
7009 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007010#endif
7011
7012#ifdef FEAT_VIRTUALEDIT
7013 /* 'virtualedit' */
7014 else if (varp == &p_ve)
7015 {
7016 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7017 errmsg = e_invarg;
7018 else if (STRCMP(p_ve, oldval) != 0)
7019 {
7020 /* Recompute cursor position in case the new 've' setting
7021 * changes something. */
7022 validate_virtcol();
7023 coladvance(curwin->w_virtcol);
7024 }
7025 }
7026#endif
7027
7028#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7029 else if (varp == &p_csqf)
7030 {
7031 if (p_csqf != NULL)
7032 {
7033 p = p_csqf;
7034 while (*p != NUL)
7035 {
7036 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7037 || p[1] == NUL
7038 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7039 || (p[2] != NUL && p[2] != ','))
7040 {
7041 errmsg = e_invarg;
7042 break;
7043 }
7044 else if (p[2] == NUL)
7045 break;
7046 else
7047 p += 3;
7048 }
7049 }
7050 }
7051#endif
7052
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007053#ifdef FEAT_CINDENT
7054 /* 'cinoptions' */
7055 else if (gvarp == &p_cino)
7056 {
7057 /* TODO: recognize errors */
7058 parse_cino(curbuf);
7059 }
7060#endif
7061
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007062#if defined(FEAT_RENDER_OPTIONS)
7063 else if (varp == &p_rop && gui.in_use)
7064 {
7065 if (!gui_mch_set_rendering_options(p_rop))
7066 errmsg = e_invarg;
7067 }
7068#endif
7069
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 /* Options that are a list of flags. */
7071 else
7072 {
7073 p = NULL;
7074 if (varp == &p_ww)
7075 p = (char_u *)WW_ALL;
7076 if (varp == &p_shm)
7077 p = (char_u *)SHM_ALL;
7078 else if (varp == &(p_cpo))
7079 p = (char_u *)CPO_ALL;
7080 else if (varp == &(curbuf->b_p_fo))
7081 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007082#ifdef FEAT_CONCEAL
7083 else if (varp == &curwin->w_p_cocu)
7084 p = (char_u *)COCU_ALL;
7085#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007086 else if (varp == &p_mouse)
7087 {
7088#ifdef FEAT_MOUSE
7089 p = (char_u *)MOUSE_ALL;
7090#else
7091 if (*p_mouse != NUL)
7092 errmsg = (char_u *)N_("E538: No mouse support");
7093#endif
7094 }
7095#if defined(FEAT_GUI)
7096 else if (varp == &p_go)
7097 p = (char_u *)GO_ALL;
7098#endif
7099 if (p != NULL)
7100 {
7101 for (s = *varp; *s; ++s)
7102 if (vim_strchr(p, *s) == NULL)
7103 {
7104 errmsg = illegal_char(errbuf, *s);
7105 break;
7106 }
7107 }
7108 }
7109
7110 /*
7111 * If error detected, restore the previous value.
7112 */
7113 if (errmsg != NULL)
7114 {
7115 if (new_value_alloced)
7116 free_string_option(*varp);
7117 *varp = oldval;
7118 /*
7119 * When resetting some values, need to act on it.
7120 */
7121 if (did_chartab)
7122 (void)init_chartab();
7123 if (varp == &p_hl)
7124 (void)highlight_changed();
7125 }
7126 else
7127 {
7128#ifdef FEAT_EVAL
7129 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007130 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007131#endif
7132 /*
7133 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007134 * Use "free_oldval", because recursiveness may change the flags under
7135 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007136 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007137 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007138 free_string_option(oldval);
7139 if (new_value_alloced)
7140 options[opt_idx].flags |= P_ALLOCED;
7141 else
7142 options[opt_idx].flags &= ~P_ALLOCED;
7143
7144 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007145 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007146 {
7147 /* global option with local value set to use global value; free
7148 * the local value and make it empty */
7149 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7150 free_string_option(*(char_u **)p);
7151 *(char_u **)p = empty_option;
7152 }
7153
7154 /* May set global value for local option. */
7155 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7156 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007157
7158#ifdef FEAT_AUTOCMD
7159 /*
7160 * Trigger the autocommand only after setting the flags.
7161 */
7162# ifdef FEAT_SYN_HL
7163 /* When 'syntax' is set, load the syntax of that name */
7164 if (varp == &(curbuf->b_p_syn))
7165 {
7166 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7167 curbuf->b_fname, TRUE, curbuf);
7168 }
7169# endif
7170 else if (varp == &(curbuf->b_p_ft))
7171 {
7172 /* 'filetype' is set, trigger the FileType autocommand */
7173 did_filetype = TRUE;
7174 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7175 curbuf->b_fname, TRUE, curbuf);
7176 }
7177#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007178#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007179 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007180 {
7181 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007182 char_u *q = curwin->w_s->b_p_spl;
7183
7184 /* Skip the first name if it is "cjk". */
7185 if (STRNCMP(q, "cjk,", 4) == 0)
7186 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007187
7188 /*
7189 * Source the spell/LANG.vim in 'runtimepath'.
7190 * They could set 'spellcapcheck' depending on the language.
7191 * Use the first name in 'spelllang' up to '_region' or
7192 * '.encoding'.
7193 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007194 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007195 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7196 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007197 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007198 source_runtime(fname, TRUE);
7199 }
7200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007201 }
7202
7203#ifdef FEAT_MOUSE
7204 if (varp == &p_mouse)
7205 {
7206# ifdef FEAT_MOUSE_TTY
7207 if (*p_mouse == NUL)
7208 mch_setmouse(FALSE); /* switch mouse off */
7209 else
7210# endif
7211 setmouse(); /* in case 'mouse' changed */
7212 }
7213#endif
7214
Bram Moolenaar913077c2012-03-28 19:59:04 +02007215 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007216 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007217 curwin->w_set_curswant = TRUE;
7218
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007219#ifdef FEAT_GUI
7220 /* check redraw when it's not a GUI option or the GUI is active. */
7221 if (!redraw_gui_only || gui.in_use)
7222#endif
7223 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007224
7225 return errmsg;
7226}
7227
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007228#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007229/*
7230 * Simple int comparison function for use with qsort()
7231 */
7232 static int
7233int_cmp(a, b)
7234 const void *a;
7235 const void *b;
7236{
7237 return *(const int *)a - *(const int *)b;
7238}
7239
7240/*
7241 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7242 * Returns error message, NULL if it's OK.
7243 */
7244 char_u *
7245check_colorcolumn(wp)
7246 win_T *wp;
7247{
7248 char_u *s;
7249 int col;
7250 int count = 0;
7251 int color_cols[256];
7252 int i;
7253 int j = 0;
7254
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007255 if (wp->w_buffer == NULL)
7256 return NULL; /* buffer was closed */
7257
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007258 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007259 {
7260 if (*s == '-' || *s == '+')
7261 {
7262 /* -N and +N: add to 'textwidth' */
7263 col = (*s == '-') ? -1 : 1;
7264 ++s;
7265 if (!VIM_ISDIGIT(*s))
7266 return e_invarg;
7267 col = col * getdigits(&s);
7268 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007269 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007270 col += wp->w_buffer->b_p_tw;
7271 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007272 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007273 }
7274 else if (VIM_ISDIGIT(*s))
7275 col = getdigits(&s);
7276 else
7277 return e_invarg;
7278 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007279skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007280 if (*s == NUL)
7281 break;
7282 if (*s != ',')
7283 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007284 if (*++s == NUL)
7285 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007286 }
7287
7288 vim_free(wp->w_p_cc_cols);
7289 if (count == 0)
7290 wp->w_p_cc_cols = NULL;
7291 else
7292 {
7293 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7294 if (wp->w_p_cc_cols != NULL)
7295 {
7296 /* sort the columns for faster usage on screen redraw inside
7297 * win_line() */
7298 qsort(color_cols, count, sizeof(int), int_cmp);
7299
7300 for (i = 0; i < count; ++i)
7301 /* skip duplicates */
7302 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7303 wp->w_p_cc_cols[j++] = color_cols[i];
7304 wp->w_p_cc_cols[j] = -1; /* end marker */
7305 }
7306 }
7307
7308 return NULL; /* no error */
7309}
7310#endif
7311
Bram Moolenaar071d4272004-06-13 20:20:40 +00007312/*
7313 * Handle setting 'listchars' or 'fillchars'.
7314 * Returns error message, NULL if it's OK.
7315 */
7316 static char_u *
7317set_chars_option(varp)
7318 char_u **varp;
7319{
7320 int round, i, len, entries;
7321 char_u *p, *s;
7322 int c1, c2 = 0;
7323 struct charstab
7324 {
7325 int *cp;
7326 char *name;
7327 };
7328#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7329 static struct charstab filltab[] =
7330 {
7331 {&fill_stl, "stl"},
7332 {&fill_stlnc, "stlnc"},
7333 {&fill_vert, "vert"},
7334 {&fill_fold, "fold"},
7335 {&fill_diff, "diff"},
7336 };
7337#endif
7338 static struct charstab lcstab[] =
7339 {
7340 {&lcs_eol, "eol"},
7341 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007342 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007343 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007344 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007345 {&lcs_tab2, "tab"},
7346 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007347#ifdef FEAT_CONCEAL
7348 {&lcs_conceal, "conceal"},
7349#else
7350 {NULL, "conceal"},
7351#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007352 };
7353 struct charstab *tab;
7354
7355#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7356 if (varp == &p_lcs)
7357#endif
7358 {
7359 tab = lcstab;
7360 entries = sizeof(lcstab) / sizeof(struct charstab);
7361 }
7362#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7363 else
7364 {
7365 tab = filltab;
7366 entries = sizeof(filltab) / sizeof(struct charstab);
7367 }
7368#endif
7369
7370 /* first round: check for valid value, second round: assign values */
7371 for (round = 0; round <= 1; ++round)
7372 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007373 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007374 {
7375 /* After checking that the value is valid: set defaults: space for
7376 * 'fillchars', NUL for 'listchars' */
7377 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007378 if (tab[i].cp != NULL)
7379 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007380 if (varp == &p_lcs)
7381 lcs_tab1 = NUL;
7382#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7383 else
7384 fill_diff = '-';
7385#endif
7386 }
7387 p = *varp;
7388 while (*p)
7389 {
7390 for (i = 0; i < entries; ++i)
7391 {
7392 len = (int)STRLEN(tab[i].name);
7393 if (STRNCMP(p, tab[i].name, len) == 0
7394 && p[len] == ':'
7395 && p[len + 1] != NUL)
7396 {
7397 s = p + len + 1;
7398#ifdef FEAT_MBYTE
7399 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007400 if (mb_char2cells(c1) > 1)
7401 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007402#else
7403 c1 = *s++;
7404#endif
7405 if (tab[i].cp == &lcs_tab2)
7406 {
7407 if (*s == NUL)
7408 continue;
7409#ifdef FEAT_MBYTE
7410 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007411 if (mb_char2cells(c2) > 1)
7412 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007413#else
7414 c2 = *s++;
7415#endif
7416 }
7417 if (*s == ',' || *s == NUL)
7418 {
7419 if (round)
7420 {
7421 if (tab[i].cp == &lcs_tab2)
7422 {
7423 lcs_tab1 = c1;
7424 lcs_tab2 = c2;
7425 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007426 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007427 *(tab[i].cp) = c1;
7428
7429 }
7430 p = s;
7431 break;
7432 }
7433 }
7434 }
7435
7436 if (i == entries)
7437 return e_invarg;
7438 if (*p == ',')
7439 ++p;
7440 }
7441 }
7442
7443 return NULL; /* no error */
7444}
7445
7446#ifdef FEAT_STL_OPT
7447/*
7448 * Check validity of options with the 'statusline' format.
7449 * Return error message or NULL.
7450 */
7451 char_u *
7452check_stl_option(s)
7453 char_u *s;
7454{
7455 int itemcnt = 0;
7456 int groupdepth = 0;
7457 static char_u errbuf[80];
7458
7459 while (*s && itemcnt < STL_MAX_ITEM)
7460 {
7461 /* Check for valid keys after % sequences */
7462 while (*s && *s != '%')
7463 s++;
7464 if (!*s)
7465 break;
7466 s++;
7467 if (*s != '%' && *s != ')')
7468 ++itemcnt;
7469 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7470 {
7471 s++;
7472 continue;
7473 }
7474 if (*s == ')')
7475 {
7476 s++;
7477 if (--groupdepth < 0)
7478 break;
7479 continue;
7480 }
7481 if (*s == '-')
7482 s++;
7483 while (VIM_ISDIGIT(*s))
7484 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007485 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 continue;
7487 if (*s == '.')
7488 {
7489 s++;
7490 while (*s && VIM_ISDIGIT(*s))
7491 s++;
7492 }
7493 if (*s == '(')
7494 {
7495 groupdepth++;
7496 continue;
7497 }
7498 if (vim_strchr(STL_ALL, *s) == NULL)
7499 {
7500 return illegal_char(errbuf, *s);
7501 }
7502 if (*s == '{')
7503 {
7504 s++;
7505 while (*s != '}' && *s)
7506 s++;
7507 if (*s != '}')
7508 return (char_u *)N_("E540: Unclosed expression sequence");
7509 }
7510 }
7511 if (itemcnt >= STL_MAX_ITEM)
7512 return (char_u *)N_("E541: too many items");
7513 if (groupdepth != 0)
7514 return (char_u *)N_("E542: unbalanced groups");
7515 return NULL;
7516}
7517#endif
7518
7519#ifdef FEAT_CLIPBOARD
7520/*
7521 * Extract the items in the 'clipboard' option and set global values.
7522 */
7523 static char_u *
7524check_clipboard_option()
7525{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007526 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007527 int new_autoselect_star = FALSE;
7528 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007529 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007530 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007531 regprog_T *new_exclude_prog = NULL;
7532 char_u *errmsg = NULL;
7533 char_u *p;
7534
7535 for (p = p_cb; *p != NUL; )
7536 {
7537 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7538 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007539 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007540 p += 7;
7541 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007542 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007543 && (p[11] == ',' || p[11] == NUL))
7544 {
7545 new_unnamed |= CLIP_UNNAMED_PLUS;
7546 p += 11;
7547 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007549 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007550 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007551 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007552 p += 10;
7553 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007554 else if (STRNCMP(p, "autoselectplus", 14) == 0
7555 && (p[14] == ',' || p[14] == NUL))
7556 {
7557 new_autoselect_plus = TRUE;
7558 p += 14;
7559 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007560 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007561 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007562 {
7563 new_autoselectml = TRUE;
7564 p += 12;
7565 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007566 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7567 {
7568 new_html = TRUE;
7569 p += 4;
7570 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007571 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7572 {
7573 p += 8;
7574 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7575 if (new_exclude_prog == NULL)
7576 errmsg = e_invarg;
7577 break;
7578 }
7579 else
7580 {
7581 errmsg = e_invarg;
7582 break;
7583 }
7584 if (*p == ',')
7585 ++p;
7586 }
7587 if (errmsg == NULL)
7588 {
7589 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007590 clip_autoselect_star = new_autoselect_star;
7591 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007592 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007593 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007594 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007595 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007596#ifdef FEAT_GUI_GTK
7597 if (gui.in_use)
7598 {
7599 gui_gtk_set_selection_targets();
7600 gui_gtk_set_dnd_targets();
7601 }
7602#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007603 }
7604 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007605 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007606
7607 return errmsg;
7608}
7609#endif
7610
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007611#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007612/*
7613 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7614 * Return error message when failed, NULL when OK.
7615 */
7616 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007617compile_cap_prog(synblock)
7618 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007619{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007620 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007621 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007622
Bram Moolenaar860cae12010-06-05 23:22:07 +02007623 if (*synblock->b_p_spc == NUL)
7624 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007625 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007626 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007627 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007628 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007629 if (re != NULL)
7630 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007631 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007632 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007633 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007634 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007635 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007636 return e_invarg;
7637 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007638 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007639 }
7640
Bram Moolenaar473de612013-06-08 18:19:48 +02007641 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007642 return NULL;
7643}
7644#endif
7645
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007646#if defined(FEAT_EVAL) || defined(PROTO)
7647/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007648 * Set the scriptID for an option, taking care of setting the buffer- or
7649 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007650 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007651 static void
7652set_option_scriptID_idx(opt_idx, opt_flags, id)
7653 int opt_idx;
7654 int opt_flags;
7655 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007656{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007657 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7658 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007659
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007660 /* Remember where the option was set. For local options need to do that
7661 * in the buffer or window structure. */
7662 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007663 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007664 if (both || (opt_flags & OPT_LOCAL))
7665 {
7666 if (indir & PV_BUF)
7667 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7668 else if (indir & PV_WIN)
7669 curwin->w_p_scriptID[indir & PV_MASK] = id;
7670 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007671}
7672#endif
7673
Bram Moolenaar071d4272004-06-13 20:20:40 +00007674/*
7675 * Set the value of a boolean option, and take care of side effects.
7676 * Returns NULL for success, or an error message for an error.
7677 */
7678 static char_u *
7679set_bool_option(opt_idx, varp, value, opt_flags)
7680 int opt_idx; /* index in options[] table */
7681 char_u *varp; /* pointer to the option variable */
7682 int value; /* new value */
7683 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7684{
7685 int old_value = *(int *)varp;
7686
Bram Moolenaar071d4272004-06-13 20:20:40 +00007687 /* Disallow changing some options from secure mode */
7688 if ((secure
7689#ifdef HAVE_SANDBOX
7690 || sandbox != 0
7691#endif
7692 ) && (options[opt_idx].flags & P_SECURE))
7693 return e_secure;
7694
7695 *(int *)varp = value; /* set the new value */
7696#ifdef FEAT_EVAL
7697 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007698 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007699#endif
7700
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007701#ifdef FEAT_GUI
7702 need_mouse_correct = TRUE;
7703#endif
7704
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705 /* May set global value for local option. */
7706 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7707 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7708
7709 /*
7710 * Handle side effects of changing a bool option.
7711 */
7712
7713 /* 'compatible' */
7714 if ((int *)varp == &p_cp)
7715 {
7716 compatible_set();
7717 }
7718
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007719#ifdef FEAT_PERSISTENT_UNDO
7720 /* 'undofile' */
7721 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7722 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007723 /* Only take action when the option was set. When reset we do not
7724 * delete the undo file, the option may be set again without making
7725 * any changes in between. */
7726 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007727 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007728 char_u hash[UNDO_HASH_SIZE];
7729 buf_T *save_curbuf = curbuf;
7730
7731 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007732 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007733 /* When 'undofile' is set globally: for every buffer, otherwise
7734 * only for the current buffer: Try to read in the undofile,
7735 * if one exists, the buffer wasn't changed and the buffer was
7736 * loaded */
7737 if ((curbuf == save_curbuf
7738 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7739 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7740 {
7741 u_compute_hash(hash);
7742 u_read_undo(NULL, hash, curbuf->b_fname);
7743 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007744 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007745 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007746 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007747 }
7748#endif
7749
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 else if ((int *)varp == &curbuf->b_p_ro)
7751 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007752 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007753 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7754 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007755
7756 /* when 'readonly' is set may give W10 again */
7757 if (curbuf->b_p_ro)
7758 curbuf->b_did_warn = FALSE;
7759
Bram Moolenaar071d4272004-06-13 20:20:40 +00007760#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007761 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007762#endif
7763 }
7764
Bram Moolenaar9c449722010-07-20 18:44:27 +02007765#ifdef FEAT_GUI
7766 else if ((int *)varp == &p_mh)
7767 {
7768 if (!p_mh)
7769 gui_mch_mousehide(FALSE);
7770 }
7771#endif
7772
Bram Moolenaara539df02010-08-01 14:35:05 +02007773#ifdef FEAT_TITLE
7774 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007775 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007776 {
7777 redraw_titles();
7778 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779 /* when 'endofline' is changed, redraw the window title */
7780 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007781 {
7782 redraw_titles();
7783 }
7784# ifdef FEAT_MBYTE
7785 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007786 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007787 {
7788 redraw_titles();
7789 }
7790# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791#endif
7792
7793 /* when 'bin' is set also set some other options */
7794 else if ((int *)varp == &curbuf->b_p_bin)
7795 {
7796 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7797#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007798 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799#endif
7800 }
7801
7802#ifdef FEAT_AUTOCMD
7803 /* when 'buflisted' changes, trigger autocommands */
7804 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7805 {
7806 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7807 NULL, NULL, TRUE, curbuf);
7808 }
7809#endif
7810
7811 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7812 else if ((int *)varp == &curbuf->b_p_swf)
7813 {
7814 if (curbuf->b_p_swf && p_uc)
7815 ml_open_file(curbuf); /* create the swap file */
7816 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007817 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7818 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819 mf_close_file(curbuf, TRUE); /* remove the swap file */
7820 }
7821
7822 /* when 'terse' is set change 'shortmess' */
7823 else if ((int *)varp == &p_terse)
7824 {
7825 char_u *p;
7826
7827 p = vim_strchr(p_shm, SHM_SEARCH);
7828
7829 /* insert 's' in p_shm */
7830 if (p_terse && p == NULL)
7831 {
7832 STRCPY(IObuff, p_shm);
7833 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007834 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007835 }
7836 /* remove 's' from p_shm */
7837 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007838 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007839 }
7840
7841 /* when 'paste' is set or reset also change other options */
7842 else if ((int *)varp == &p_paste)
7843 {
7844 paste_option_changed();
7845 }
7846
7847 /* when 'insertmode' is set from an autocommand need to do work here */
7848 else if ((int *)varp == &p_im)
7849 {
7850 if (p_im)
7851 {
7852 if ((State & INSERT) == 0)
7853 need_start_insertmode = TRUE;
7854 stop_insert_mode = FALSE;
7855 }
7856 else
7857 {
7858 need_start_insertmode = FALSE;
7859 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007860 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861 clear_cmdline = TRUE; /* remove "(insert)" */
7862 restart_edit = 0;
7863 }
7864 }
7865
7866 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7867 else if ((int *)varp == &p_ic && p_hls)
7868 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007869 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007870 }
7871
7872#ifdef FEAT_SEARCH_EXTRA
7873 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7874 else if ((int *)varp == &p_hls)
7875 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007876 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877 }
7878#endif
7879
7880#ifdef FEAT_SCROLLBIND
7881 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7882 * at the end of normal_cmd() */
7883 else if ((int *)varp == &curwin->w_p_scb)
7884 {
7885 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007886 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007887 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007888 curwin->w_scbind_pos = curwin->w_topline;
7889 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890 }
7891#endif
7892
7893#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7894 /* There can be only one window with 'previewwindow' set. */
7895 else if ((int *)varp == &curwin->w_p_pvw)
7896 {
7897 if (curwin->w_p_pvw)
7898 {
7899 win_T *win;
7900
7901 for (win = firstwin; win != NULL; win = win->w_next)
7902 if (win->w_p_pvw && win != curwin)
7903 {
7904 curwin->w_p_pvw = FALSE;
7905 return (char_u *)N_("E590: A preview window already exists");
7906 }
7907 }
7908 }
7909#endif
7910
7911 /* when 'textmode' is set or reset also change 'fileformat' */
7912 else if ((int *)varp == &curbuf->b_p_tx)
7913 {
7914 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7915 }
7916
7917 /* when 'textauto' is set or reset also change 'fileformats' */
7918 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919 set_string_option_direct((char_u *)"ffs", -1,
7920 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007921 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007922
7923 /*
7924 * When 'lisp' option changes include/exclude '-' in
7925 * keyword characters.
7926 */
7927#ifdef FEAT_LISP
7928 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7929 {
7930 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7931 }
7932#endif
7933
7934#ifdef FEAT_TITLE
7935 /* when 'title' changed, may need to change the title; same for 'icon' */
7936 else if ((int *)varp == &p_title)
7937 {
7938 did_set_title(FALSE);
7939 }
7940
7941 else if ((int *)varp == &p_icon)
7942 {
7943 did_set_title(TRUE);
7944 }
7945#endif
7946
7947 else if ((int *)varp == &curbuf->b_changed)
7948 {
7949 if (!value)
7950 save_file_ff(curbuf); /* Buffer is unchanged */
7951#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007952 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007953#endif
7954#ifdef FEAT_AUTOCMD
7955 modified_was_set = value;
7956#endif
7957 }
7958
7959#ifdef BACKSLASH_IN_FILENAME
7960 else if ((int *)varp == &p_ssl)
7961 {
7962 if (p_ssl)
7963 {
7964 psepc = '/';
7965 psepcN = '\\';
7966 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 }
7968 else
7969 {
7970 psepc = '\\';
7971 psepcN = '/';
7972 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973 }
7974
7975 /* need to adjust the file name arguments and buffer names. */
7976 buflist_slash_adjust();
7977 alist_slash_adjust();
7978# ifdef FEAT_EVAL
7979 scriptnames_slash_adjust();
7980# endif
7981 }
7982#endif
7983
7984 /* If 'wrap' is set, set w_leftcol to zero. */
7985 else if ((int *)varp == &curwin->w_p_wrap)
7986 {
7987 if (curwin->w_p_wrap)
7988 curwin->w_leftcol = 0;
7989 }
7990
7991#ifdef FEAT_WINDOWS
7992 else if ((int *)varp == &p_ea)
7993 {
7994 if (p_ea && !old_value)
7995 win_equal(curwin, FALSE, 0);
7996 }
7997#endif
7998
7999 else if ((int *)varp == &p_wiv)
8000 {
8001 /*
8002 * When 'weirdinvert' changed, set/reset 't_xs'.
8003 * Then set 'weirdinvert' according to value of 't_xs'.
8004 */
8005 if (p_wiv && !old_value)
8006 T_XS = (char_u *)"y";
8007 else if (!p_wiv && old_value)
8008 T_XS = empty_option;
8009 p_wiv = (*T_XS != NUL);
8010 }
8011
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008012#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013 else if ((int *)varp == &p_beval)
8014 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008015 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008017 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018 gui_mch_disable_beval_area(balloonEval);
8019 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008020#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008022#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008023 else if ((int *)varp == &p_acd)
8024 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008025 /* Change directories when the 'acd' option is set now. */
8026 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008027 }
8028#endif
8029
8030#ifdef FEAT_DIFF
8031 /* 'diff' */
8032 else if ((int *)varp == &curwin->w_p_diff)
8033 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008034 /* May add or remove the buffer from the list of diff buffers. */
8035 diff_buf_adjust(curwin);
8036# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 if (foldmethodIsDiff(curwin))
8038 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008039# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008040 }
8041#endif
8042
8043#ifdef USE_IM_CONTROL
8044 /* 'imdisable' */
8045 else if ((int *)varp == &p_imdisable)
8046 {
8047 /* Only de-activate it here, it will be enabled when changing mode. */
8048 if (p_imdisable)
8049 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008050 else if (State & INSERT)
8051 /* When the option is set from an autocommand, it may need to take
8052 * effect right away. */
8053 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008054 }
8055#endif
8056
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008057#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008058 /* 'spell' */
8059 else if ((int *)varp == &curwin->w_p_spell)
8060 {
8061 if (curwin->w_p_spell)
8062 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008063 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008064 if (errmsg != NULL)
8065 EMSG(_(errmsg));
8066 }
8067 }
8068#endif
8069
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070#ifdef FEAT_FKMAP
8071 else if ((int *)varp == &p_altkeymap)
8072 {
8073 if (old_value != p_altkeymap)
8074 {
8075 if (!p_altkeymap)
8076 {
8077 p_hkmap = p_fkmap;
8078 p_fkmap = 0;
8079 }
8080 else
8081 {
8082 p_fkmap = p_hkmap;
8083 p_hkmap = 0;
8084 }
8085 (void)init_chartab();
8086 }
8087 }
8088
8089 /*
8090 * In case some second language keymapping options have changed, check
8091 * and correct the setting in a consistent way.
8092 */
8093
8094 /*
8095 * If hkmap or fkmap are set, reset Arabic keymapping.
8096 */
8097 if ((p_hkmap || p_fkmap) && p_altkeymap)
8098 {
8099 p_altkeymap = p_fkmap;
8100# ifdef FEAT_ARABIC
8101 curwin->w_p_arab = FALSE;
8102# endif
8103 (void)init_chartab();
8104 }
8105
8106 /*
8107 * If hkmap set, reset Farsi keymapping.
8108 */
8109 if (p_hkmap && p_altkeymap)
8110 {
8111 p_altkeymap = 0;
8112 p_fkmap = 0;
8113# ifdef FEAT_ARABIC
8114 curwin->w_p_arab = FALSE;
8115# endif
8116 (void)init_chartab();
8117 }
8118
8119 /*
8120 * If fkmap set, reset Hebrew keymapping.
8121 */
8122 if (p_fkmap && !p_altkeymap)
8123 {
8124 p_altkeymap = 1;
8125 p_hkmap = 0;
8126# ifdef FEAT_ARABIC
8127 curwin->w_p_arab = FALSE;
8128# endif
8129 (void)init_chartab();
8130 }
8131#endif
8132
8133#ifdef FEAT_ARABIC
8134 if ((int *)varp == &curwin->w_p_arab)
8135 {
8136 if (curwin->w_p_arab)
8137 {
8138 /*
8139 * 'arabic' is set, handle various sub-settings.
8140 */
8141 if (!p_tbidi)
8142 {
8143 /* set rightleft mode */
8144 if (!curwin->w_p_rl)
8145 {
8146 curwin->w_p_rl = TRUE;
8147 changed_window_setting();
8148 }
8149
8150 /* Enable Arabic shaping (major part of what Arabic requires) */
8151 if (!p_arshape)
8152 {
8153 p_arshape = TRUE;
8154 redraw_later_clear();
8155 }
8156 }
8157
8158 /* Arabic requires a utf-8 encoding, inform the user if its not
8159 * set. */
8160 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008161 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008162 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8163
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008164 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008165 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8166#ifdef FEAT_EVAL
8167 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8168#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008169 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008170
8171# ifdef FEAT_MBYTE
8172 /* set 'delcombine' */
8173 p_deco = TRUE;
8174# endif
8175
8176# ifdef FEAT_KEYMAP
8177 /* Force-set the necessary keymap for arabic */
8178 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8179 OPT_LOCAL);
8180# endif
8181# ifdef FEAT_FKMAP
8182 p_altkeymap = 0;
8183 p_hkmap = 0;
8184 p_fkmap = 0;
8185 (void)init_chartab();
8186# endif
8187 }
8188 else
8189 {
8190 /*
8191 * 'arabic' is reset, handle various sub-settings.
8192 */
8193 if (!p_tbidi)
8194 {
8195 /* reset rightleft mode */
8196 if (curwin->w_p_rl)
8197 {
8198 curwin->w_p_rl = FALSE;
8199 changed_window_setting();
8200 }
8201
8202 /* 'arabicshape' isn't reset, it is a global option and
8203 * another window may still need it "on". */
8204 }
8205
8206 /* 'delcombine' isn't reset, it is a global option and another
8207 * window may still want it "on". */
8208
8209# ifdef FEAT_KEYMAP
8210 /* Revert to the default keymap */
8211 curbuf->b_p_iminsert = B_IMODE_NONE;
8212 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8213# endif
8214 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008215 }
8216
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008217#endif
8218
Bram Moolenaar071d4272004-06-13 20:20:40 +00008219 /*
8220 * End of handling side effects for bool options.
8221 */
8222
8223 options[opt_idx].flags |= P_WAS_SET;
8224
8225 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008226 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008227 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008228 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008229 check_redraw(options[opt_idx].flags);
8230
8231 return NULL;
8232}
8233
8234/*
8235 * Set the value of a number option, and take care of side effects.
8236 * Returns NULL for success, or an error message for an error.
8237 */
8238 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008239set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008240 int opt_idx; /* index in options[] table */
8241 char_u *varp; /* pointer to the option variable */
8242 long value; /* new value */
8243 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008244 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8246 OPT_MODELINE */
8247{
8248 char_u *errmsg = NULL;
8249 long old_value = *(long *)varp;
8250 long old_Rows = Rows; /* remember old Rows */
8251 long old_Columns = Columns; /* remember old Columns */
8252 long *pp = (long *)varp;
8253
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008254 /* Disallow changing some options from secure mode. */
8255 if ((secure
8256#ifdef HAVE_SANDBOX
8257 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008258#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008259 ) && (options[opt_idx].flags & P_SECURE))
8260 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261
8262 *pp = value;
8263#ifdef FEAT_EVAL
8264 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008265 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008266#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008267#ifdef FEAT_GUI
8268 need_mouse_correct = TRUE;
8269#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008270
Bram Moolenaar14f24742012-08-08 18:01:05 +02008271 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008272 {
8273 errmsg = e_positive;
8274 curbuf->b_p_sw = curbuf->b_p_ts;
8275 }
8276
8277 /*
8278 * Number options that need some action when changed
8279 */
8280#ifdef FEAT_WINDOWS
8281 if (pp == &p_wh || pp == &p_hh)
8282 {
8283 if (p_wh < 1)
8284 {
8285 errmsg = e_positive;
8286 p_wh = 1;
8287 }
8288 if (p_wmh > p_wh)
8289 {
8290 errmsg = e_winheight;
8291 p_wh = p_wmh;
8292 }
8293 if (p_hh < 0)
8294 {
8295 errmsg = e_positive;
8296 p_hh = 0;
8297 }
8298
8299 /* Change window height NOW */
8300 if (lastwin != firstwin)
8301 {
8302 if (pp == &p_wh && curwin->w_height < p_wh)
8303 win_setheight((int)p_wh);
8304 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8305 win_setheight((int)p_hh);
8306 }
8307 }
8308
8309 /* 'winminheight' */
8310 else if (pp == &p_wmh)
8311 {
8312 if (p_wmh < 0)
8313 {
8314 errmsg = e_positive;
8315 p_wmh = 0;
8316 }
8317 if (p_wmh > p_wh)
8318 {
8319 errmsg = e_winheight;
8320 p_wmh = p_wh;
8321 }
8322 win_setminheight();
8323 }
8324
8325# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008326 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008327 {
8328 if (p_wiw < 1)
8329 {
8330 errmsg = e_positive;
8331 p_wiw = 1;
8332 }
8333 if (p_wmw > p_wiw)
8334 {
8335 errmsg = e_winwidth;
8336 p_wiw = p_wmw;
8337 }
8338
8339 /* Change window width NOW */
8340 if (lastwin != firstwin && curwin->w_width < p_wiw)
8341 win_setwidth((int)p_wiw);
8342 }
8343
8344 /* 'winminwidth' */
8345 else if (pp == &p_wmw)
8346 {
8347 if (p_wmw < 0)
8348 {
8349 errmsg = e_positive;
8350 p_wmw = 0;
8351 }
8352 if (p_wmw > p_wiw)
8353 {
8354 errmsg = e_winwidth;
8355 p_wmw = p_wiw;
8356 }
8357 win_setminheight();
8358 }
8359# endif
8360
8361#endif
8362
8363#ifdef FEAT_WINDOWS
8364 /* (re)set last window status line */
8365 else if (pp == &p_ls)
8366 {
8367 last_status(FALSE);
8368 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008369
8370 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008371 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008372 {
8373 shell_new_rows(); /* recompute window positions and heights */
8374 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008375#endif
8376
8377#ifdef FEAT_GUI
8378 else if (pp == &p_linespace)
8379 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008380 /* Recompute gui.char_height and resize the Vim window to keep the
8381 * same number of lines. */
8382 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008383 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008384 }
8385#endif
8386
8387#ifdef FEAT_FOLDING
8388 /* 'foldlevel' */
8389 else if (pp == &curwin->w_p_fdl)
8390 {
8391 if (curwin->w_p_fdl < 0)
8392 curwin->w_p_fdl = 0;
8393 newFoldLevel();
8394 }
8395
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008396 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008397 else if (pp == &curwin->w_p_fml)
8398 {
8399 foldUpdateAll(curwin);
8400 }
8401
8402 /* 'foldnestmax' */
8403 else if (pp == &curwin->w_p_fdn)
8404 {
8405 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8406 foldUpdateAll(curwin);
8407 }
8408
8409 /* 'foldcolumn' */
8410 else if (pp == &curwin->w_p_fdc)
8411 {
8412 if (curwin->w_p_fdc < 0)
8413 {
8414 errmsg = e_positive;
8415 curwin->w_p_fdc = 0;
8416 }
8417 else if (curwin->w_p_fdc > 12)
8418 {
8419 errmsg = e_invarg;
8420 curwin->w_p_fdc = 12;
8421 }
8422 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008423#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008425#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008426 /* 'shiftwidth' or 'tabstop' */
8427 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8428 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008429# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 if (foldmethodIsIndent(curwin))
8431 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008432# endif
8433# ifdef FEAT_CINDENT
8434 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8435 * parse 'cinoptions'. */
8436 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8437 parse_cino(curbuf);
8438# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008439 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008442#ifdef FEAT_MBYTE
8443 /* 'maxcombine' */
8444 else if (pp == &p_mco)
8445 {
8446 if (p_mco > MAX_MCO)
8447 p_mco = MAX_MCO;
8448 else if (p_mco < 0)
8449 p_mco = 0;
8450 screenclear(); /* will re-allocate the screen */
8451 }
8452#endif
8453
Bram Moolenaar071d4272004-06-13 20:20:40 +00008454 else if (pp == &curbuf->b_p_iminsert)
8455 {
8456 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8457 {
8458 errmsg = e_invarg;
8459 curbuf->b_p_iminsert = B_IMODE_NONE;
8460 }
8461 p_iminsert = curbuf->b_p_iminsert;
8462 if (termcap_active) /* don't do this in the alternate screen */
8463 showmode();
8464#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8465 /* Show/unshow value of 'keymap' in status lines. */
8466 status_redraw_curbuf();
8467#endif
8468 }
8469
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008470 else if (pp == &p_window)
8471 {
8472 if (p_window < 1)
8473 p_window = 1;
8474 else if (p_window >= Rows)
8475 p_window = Rows - 1;
8476 }
8477
Bram Moolenaar071d4272004-06-13 20:20:40 +00008478 else if (pp == &curbuf->b_p_imsearch)
8479 {
8480 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8481 {
8482 errmsg = e_invarg;
8483 curbuf->b_p_imsearch = B_IMODE_NONE;
8484 }
8485 p_imsearch = curbuf->b_p_imsearch;
8486 }
8487
8488#ifdef FEAT_TITLE
8489 /* if 'titlelen' has changed, redraw the title */
8490 else if (pp == &p_titlelen)
8491 {
8492 if (p_titlelen < 0)
8493 {
8494 errmsg = e_positive;
8495 p_titlelen = 85;
8496 }
8497 if (starting != NO_SCREEN && old_value != p_titlelen)
8498 need_maketitle = TRUE;
8499 }
8500#endif
8501
8502 /* if p_ch changed value, change the command line height */
8503 else if (pp == &p_ch)
8504 {
8505 if (p_ch < 1)
8506 {
8507 errmsg = e_positive;
8508 p_ch = 1;
8509 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008510 if (p_ch > Rows - min_rows() + 1)
8511 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008512
8513 /* Only compute the new window layout when startup has been
8514 * completed. Otherwise the frame sizes may be wrong. */
8515 if (p_ch != old_value && full_screen
8516#ifdef FEAT_GUI
8517 && !gui.starting
8518#endif
8519 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008520 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521 }
8522
8523 /* when 'updatecount' changes from zero to non-zero, open swap files */
8524 else if (pp == &p_uc)
8525 {
8526 if (p_uc < 0)
8527 {
8528 errmsg = e_positive;
8529 p_uc = 100;
8530 }
8531 if (p_uc && !old_value)
8532 ml_open_files();
8533 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008534#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008535 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008536 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008537 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008538 {
8539 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008540 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008541 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008542 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008543 {
8544 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008545 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008546 }
8547 }
8548#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008549#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008550 else if (pp == &p_mzq)
8551 mzvim_reset_timer();
8552#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008553
8554 /* sync undo before 'undolevels' changes */
8555 else if (pp == &p_ul)
8556 {
8557 /* use the old value, otherwise u_sync() may not work properly */
8558 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008559 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560 p_ul = value;
8561 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008562 else if (pp == &curbuf->b_p_ul)
8563 {
8564 /* use the old value, otherwise u_sync() may not work properly */
8565 curbuf->b_p_ul = old_value;
8566 u_sync(TRUE);
8567 curbuf->b_p_ul = value;
8568 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008569
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008570#ifdef FEAT_LINEBREAK
8571 /* 'numberwidth' must be positive */
8572 else if (pp == &curwin->w_p_nuw)
8573 {
8574 if (curwin->w_p_nuw < 1)
8575 {
8576 errmsg = e_positive;
8577 curwin->w_p_nuw = 1;
8578 }
8579 if (curwin->w_p_nuw > 10)
8580 {
8581 errmsg = e_invarg;
8582 curwin->w_p_nuw = 10;
8583 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008584 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008585 }
8586#endif
8587
Bram Moolenaar1a384422010-07-14 19:53:30 +02008588 else if (pp == &curbuf->b_p_tw)
8589 {
8590 if (curbuf->b_p_tw < 0)
8591 {
8592 errmsg = e_positive;
8593 curbuf->b_p_tw = 0;
8594 }
8595#ifdef FEAT_SYN_HL
8596# ifdef FEAT_WINDOWS
8597 {
8598 win_T *wp;
8599 tabpage_T *tp;
8600
8601 FOR_ALL_TAB_WINDOWS(tp, wp)
8602 check_colorcolumn(wp);
8603 }
8604# else
8605 check_colorcolumn(curwin);
8606# endif
8607#endif
8608 }
8609
Bram Moolenaar071d4272004-06-13 20:20:40 +00008610 /*
8611 * Check the bounds for numeric options here
8612 */
8613 if (Rows < min_rows() && full_screen)
8614 {
8615 if (errbuf != NULL)
8616 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008617 vim_snprintf((char *)errbuf, errbuflen,
8618 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008619 errmsg = errbuf;
8620 }
8621 Rows = min_rows();
8622 }
8623 if (Columns < MIN_COLUMNS && full_screen)
8624 {
8625 if (errbuf != NULL)
8626 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008627 vim_snprintf((char *)errbuf, errbuflen,
8628 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008629 errmsg = errbuf;
8630 }
8631 Columns = MIN_COLUMNS;
8632 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008633 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008634
8635#ifdef DJGPP
8636 /* avoid a crash by checking for a too large value of 'columns' */
8637 if (old_Columns != Columns && full_screen && term_console)
8638 mch_check_columns();
8639#endif
8640
8641 /*
8642 * If the screen (shell) height has been changed, assume it is the
8643 * physical screenheight.
8644 */
8645 if (old_Rows != Rows || old_Columns != Columns)
8646 {
8647 /* Changing the screen size is not allowed while updating the screen. */
8648 if (updating_screen)
8649 *pp = old_value;
8650 else if (full_screen
8651#ifdef FEAT_GUI
8652 && !gui.starting
8653#endif
8654 )
8655 set_shellsize((int)Columns, (int)Rows, TRUE);
8656 else
8657 {
8658 /* Postpone the resizing; check the size and cmdline position for
8659 * messages. */
8660 check_shellsize();
8661 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8662 cmdline_row = Rows - p_ch;
8663 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008664 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008665 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008666 }
8667
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668 if (curbuf->b_p_ts <= 0)
8669 {
8670 errmsg = e_positive;
8671 curbuf->b_p_ts = 8;
8672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673 if (p_tm < 0)
8674 {
8675 errmsg = e_positive;
8676 p_tm = 0;
8677 }
8678 if ((curwin->w_p_scr <= 0
8679 || (curwin->w_p_scr > curwin->w_height
8680 && curwin->w_height > 0))
8681 && full_screen)
8682 {
8683 if (pp == &(curwin->w_p_scr))
8684 {
8685 if (curwin->w_p_scr != 0)
8686 errmsg = e_scroll;
8687 win_comp_scroll(curwin);
8688 }
8689 /* If 'scroll' became invalid because of a side effect silently adjust
8690 * it. */
8691 else if (curwin->w_p_scr <= 0)
8692 curwin->w_p_scr = 1;
8693 else /* curwin->w_p_scr > curwin->w_height */
8694 curwin->w_p_scr = curwin->w_height;
8695 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008696 if (p_hi < 0)
8697 {
8698 errmsg = e_positive;
8699 p_hi = 0;
8700 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008701 else if (p_hi > 10000)
8702 {
8703 errmsg = e_invarg;
8704 p_hi = 10000;
8705 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008706 if (p_re < 0 || p_re > 2)
8707 {
8708 errmsg = e_invarg;
8709 p_re = 0;
8710 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008711 if (p_report < 0)
8712 {
8713 errmsg = e_positive;
8714 p_report = 1;
8715 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008716 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008717 {
8718 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8719 p_sj = Rows / 2;
8720 else
8721 {
8722 errmsg = e_scroll;
8723 p_sj = 1;
8724 }
8725 }
8726 if (p_so < 0 && full_screen)
8727 {
8728 errmsg = e_scroll;
8729 p_so = 0;
8730 }
8731 if (p_siso < 0 && full_screen)
8732 {
8733 errmsg = e_positive;
8734 p_siso = 0;
8735 }
8736#ifdef FEAT_CMDWIN
8737 if (p_cwh < 1)
8738 {
8739 errmsg = e_positive;
8740 p_cwh = 1;
8741 }
8742#endif
8743 if (p_ut < 0)
8744 {
8745 errmsg = e_positive;
8746 p_ut = 2000;
8747 }
8748 if (p_ss < 0)
8749 {
8750 errmsg = e_positive;
8751 p_ss = 0;
8752 }
8753
8754 /* May set global value for local option. */
8755 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8756 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8757
8758 options[opt_idx].flags |= P_WAS_SET;
8759
8760 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008761 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008762 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008763 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008764 check_redraw(options[opt_idx].flags);
8765
8766 return errmsg;
8767}
8768
8769/*
8770 * Called after an option changed: check if something needs to be redrawn.
8771 */
8772 static void
8773check_redraw(flags)
8774 long_u flags;
8775{
8776 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008777 int doclear = (flags & P_RCLR) == P_RCLR;
8778 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008779
8780#ifdef FEAT_WINDOWS
8781 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8782 status_redraw_all();
8783#endif
8784
8785 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8786 changed_window_setting();
8787 if (flags & P_RBUF)
8788 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008789 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008790 redraw_all_later(CLEAR);
8791 else if (all)
8792 redraw_all_later(NOT_VALID);
8793}
8794
8795/*
8796 * Find index for option 'arg'.
8797 * Return -1 if not found.
8798 */
8799 static int
8800findoption(arg)
8801 char_u *arg;
8802{
8803 int opt_idx;
8804 char *s, *p;
8805 static short quick_tab[27] = {0, 0}; /* quick access table */
8806 int is_term_opt;
8807
8808 /*
8809 * For first call: Initialize the quick-access table.
8810 * It contains the index for the first option that starts with a certain
8811 * letter. There are 26 letters, plus the first "t_" option.
8812 */
8813 if (quick_tab[1] == 0)
8814 {
8815 p = options[0].fullname;
8816 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8817 {
8818 if (s[0] != p[0])
8819 {
8820 if (s[0] == 't' && s[1] == '_')
8821 quick_tab[26] = opt_idx;
8822 else
8823 quick_tab[CharOrdLow(s[0])] = opt_idx;
8824 }
8825 p = s;
8826 }
8827 }
8828
8829 /*
8830 * Check for name starting with an illegal character.
8831 */
8832#ifdef EBCDIC
8833 if (!islower(arg[0]))
8834#else
8835 if (arg[0] < 'a' || arg[0] > 'z')
8836#endif
8837 return -1;
8838
8839 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8840 if (is_term_opt)
8841 opt_idx = quick_tab[26];
8842 else
8843 opt_idx = quick_tab[CharOrdLow(arg[0])];
8844 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8845 {
8846 if (STRCMP(arg, s) == 0) /* match full name */
8847 break;
8848 }
8849 if (s == NULL && !is_term_opt)
8850 {
8851 opt_idx = quick_tab[CharOrdLow(arg[0])];
8852 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8853 {
8854 s = options[opt_idx].shortname;
8855 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8856 break;
8857 s = NULL;
8858 }
8859 }
8860 if (s == NULL)
8861 opt_idx = -1;
8862 return opt_idx;
8863}
8864
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008865#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008866/*
8867 * Get the value for an option.
8868 *
8869 * Returns:
8870 * Number or Toggle option: 1, *numval gets value.
8871 * String option: 0, *stringval gets allocated string.
8872 * Hidden Number or Toggle option: -1.
8873 * hidden String option: -2.
8874 * unknown option: -3.
8875 */
8876 int
8877get_option_value(name, numval, stringval, opt_flags)
8878 char_u *name;
8879 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008880 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881 int opt_flags;
8882{
8883 int opt_idx;
8884 char_u *varp;
8885
8886 opt_idx = findoption(name);
8887 if (opt_idx < 0) /* unknown option */
8888 return -3;
8889
8890 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8891
8892 if (options[opt_idx].flags & P_STRING)
8893 {
8894 if (varp == NULL) /* hidden option */
8895 return -2;
8896 if (stringval != NULL)
8897 {
8898#ifdef FEAT_CRYPT
8899 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008900 if ((char_u **)varp == &curbuf->b_p_key
8901 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008902 *stringval = vim_strsave((char_u *)"*****");
8903 else
8904#endif
8905 *stringval = vim_strsave(*(char_u **)(varp));
8906 }
8907 return 0;
8908 }
8909
8910 if (varp == NULL) /* hidden option */
8911 return -1;
8912 if (options[opt_idx].flags & P_NUM)
8913 *numval = *(long *)varp;
8914 else
8915 {
8916 /* Special case: 'modified' is b_changed, but we also want to consider
8917 * it set when 'ff' or 'fenc' changed. */
8918 if ((int *)varp == &curbuf->b_changed)
8919 *numval = curbufIsChanged();
8920 else
8921 *numval = *(int *)varp;
8922 }
8923 return 1;
8924}
8925#endif
8926
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008927#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008928/*
8929 * Returns the option attributes and its value. Unlike the above function it
8930 * will return either global value or local value of the option depending on
8931 * what was requested, but it will never return global value if it was
8932 * requested to return local one and vice versa. Neither it will return
8933 * buffer-local value if it was requested to return window-local one.
8934 *
8935 * Pretends that option is absent if it is not present in the requested scope
8936 * (i.e. has no global, window-local or buffer-local value depending on
8937 * opt_type). Uses
8938 *
8939 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008940 * 0 hidden or unknown option, also option that does not have requested
8941 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008942 * see SOPT_* in vim.h for other flags
8943 *
8944 * Possible opt_type values: see SREQ_* in vim.h
8945 */
8946 int
8947get_option_value_strict(name, numval, stringval, opt_type, from)
8948 char_u *name;
8949 long *numval;
8950 char_u **stringval; /* NULL when only obtaining attributes */
8951 int opt_type;
8952 void *from;
8953{
8954 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008955 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008956 struct vimoption *p;
8957 int r = 0;
8958
8959 opt_idx = findoption(name);
8960 if (opt_idx < 0)
8961 return 0;
8962
8963 p = &(options[opt_idx]);
8964
8965 /* Hidden option */
8966 if (p->var == NULL)
8967 return 0;
8968
8969 if (p->flags & P_BOOL)
8970 r |= SOPT_BOOL;
8971 else if (p->flags & P_NUM)
8972 r |= SOPT_NUM;
8973 else if (p->flags & P_STRING)
8974 r |= SOPT_STRING;
8975
8976 if (p->indir == PV_NONE)
8977 {
8978 if (opt_type == SREQ_GLOBAL)
8979 r |= SOPT_GLOBAL;
8980 else
8981 return 0; /* Did not request global-only option */
8982 }
8983 else
8984 {
8985 if (p->indir & PV_BOTH)
8986 r |= SOPT_GLOBAL;
8987 else if (opt_type == SREQ_GLOBAL)
8988 return 0; /* Requested global option */
8989
8990 if (p->indir & PV_WIN)
8991 {
8992 if (opt_type == SREQ_BUF)
8993 return 0; /* Did not request window-local option */
8994 else
8995 r |= SOPT_WIN;
8996 }
8997 else if (p->indir & PV_BUF)
8998 {
8999 if (opt_type == SREQ_WIN)
9000 return 0; /* Did not request buffer-local option */
9001 else
9002 r |= SOPT_BUF;
9003 }
9004 }
9005
9006 if (stringval == NULL)
9007 return r;
9008
9009 if (opt_type == SREQ_GLOBAL)
9010 varp = p->var;
9011 else
9012 {
9013 if (opt_type == SREQ_BUF)
9014 {
9015 /* Special case: 'modified' is b_changed, but we also want to
9016 * consider it set when 'ff' or 'fenc' changed. */
9017 if (p->indir == PV_MOD)
9018 {
9019 *numval = bufIsChanged((buf_T *) from);
9020 varp = NULL;
9021 }
9022#ifdef FEAT_CRYPT
9023 else if (p->indir == PV_KEY)
9024 {
9025 /* never return the value of the crypt key */
9026 *stringval = NULL;
9027 varp = NULL;
9028 }
9029#endif
9030 else
9031 {
9032 aco_save_T aco;
9033 aucmd_prepbuf(&aco, (buf_T *) from);
9034 varp = get_varp(p);
9035 aucmd_restbuf(&aco);
9036 }
9037 }
9038 else if (opt_type == SREQ_WIN)
9039 {
9040 win_T *save_curwin;
9041 save_curwin = curwin;
9042 curwin = (win_T *) from;
9043 curbuf = curwin->w_buffer;
9044 varp = get_varp(p);
9045 curwin = save_curwin;
9046 curbuf = curwin->w_buffer;
9047 }
9048 if (varp == p->var)
9049 return (r | SOPT_UNSET);
9050 }
9051
9052 if (varp != NULL)
9053 {
9054 if (p->flags & P_STRING)
9055 *stringval = vim_strsave(*(char_u **)(varp));
9056 else if (p->flags & P_NUM)
9057 *numval = *(long *) varp;
9058 else
9059 *numval = *(int *)varp;
9060 }
9061
9062 return r;
9063}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009064
9065/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009066 * Iterate over options. First argument is a pointer to a pointer to a
9067 * structure inside options[] array, second is option type like in the above
9068 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009069 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009070 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009071 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009072 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009073 * first argument to NULL.
9074 *
9075 * Returns full option name for current option on each call.
9076 */
9077 char_u *
9078option_iter_next(option, opt_type)
9079 void **option;
9080 int opt_type;
9081{
9082 struct vimoption *ret = NULL;
9083 do
9084 {
9085 if (*option == NULL)
9086 *option = (void *) options;
9087 else if (((struct vimoption *) (*option))->fullname == NULL)
9088 {
9089 *option = NULL;
9090 return NULL;
9091 }
9092 else
9093 *option = (void *) (((struct vimoption *) (*option)) + 1);
9094
9095 ret = ((struct vimoption *) (*option));
9096
9097 /* Hidden option */
9098 if (ret->var == NULL)
9099 {
9100 ret = NULL;
9101 continue;
9102 }
9103
9104 switch (opt_type)
9105 {
9106 case SREQ_GLOBAL:
9107 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9108 ret = NULL;
9109 break;
9110 case SREQ_BUF:
9111 if (!(ret->indir & PV_BUF))
9112 ret = NULL;
9113 break;
9114 case SREQ_WIN:
9115 if (!(ret->indir & PV_WIN))
9116 ret = NULL;
9117 break;
9118 default:
9119 EMSG2(_(e_intern2), "option_iter_next()");
9120 return NULL;
9121 }
9122 }
9123 while (ret == NULL);
9124
9125 return (char_u *)ret->fullname;
9126}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009127#endif
9128
Bram Moolenaar071d4272004-06-13 20:20:40 +00009129/*
9130 * Set the value of option "name".
9131 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009132 *
9133 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009134 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009135 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009136set_option_value(name, number, string, opt_flags)
9137 char_u *name;
9138 long number;
9139 char_u *string;
9140 int opt_flags; /* OPT_LOCAL or 0 (both) */
9141{
9142 int opt_idx;
9143 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009144 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009145
9146 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009147 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009148 EMSG2(_("E355: Unknown option: %s"), name);
9149 else
9150 {
9151 flags = options[opt_idx].flags;
9152#ifdef HAVE_SANDBOX
9153 /* Disallow changing some options in the sandbox */
9154 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009155 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009156 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009157 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009158 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009159#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009160 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009161 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009162 else
9163 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009164 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009165 if (varp != NULL) /* hidden option is not changed */
9166 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009167 if (number == 0 && string != NULL)
9168 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009169 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009170
9171 /* Either we are given a string or we are setting option
9172 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009173 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009174 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009175 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009176 {
9177 /* There's another character after zeros or the string
9178 * is empty. In both cases, we are trying to set a
9179 * num option using a string. */
9180 EMSG3(_("E521: Number required: &%s = '%s'"),
9181 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009182 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009183
9184 }
9185 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009186 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009187 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009188 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009189 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009190 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009191 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009192 }
9193 }
9194 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009195 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009196}
9197
9198/*
9199 * Get the terminal code for a terminal option.
9200 * Returns NULL when not found.
9201 */
9202 char_u *
9203get_term_code(tname)
9204 char_u *tname;
9205{
9206 int opt_idx;
9207 char_u *varp;
9208
9209 if (tname[0] != 't' || tname[1] != '_' ||
9210 tname[2] == NUL || tname[3] == NUL)
9211 return NULL;
9212 if ((opt_idx = findoption(tname)) >= 0)
9213 {
9214 varp = get_varp(&(options[opt_idx]));
9215 if (varp != NULL)
9216 varp = *(char_u **)(varp);
9217 return varp;
9218 }
9219 return find_termcode(tname + 2);
9220}
9221
9222 char_u *
9223get_highlight_default()
9224{
9225 int i;
9226
9227 i = findoption((char_u *)"hl");
9228 if (i >= 0)
9229 return options[i].def_val[VI_DEFAULT];
9230 return (char_u *)NULL;
9231}
9232
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009233#if defined(FEAT_MBYTE) || defined(PROTO)
9234 char_u *
9235get_encoding_default()
9236{
9237 int i;
9238
9239 i = findoption((char_u *)"enc");
9240 if (i >= 0)
9241 return options[i].def_val[VI_DEFAULT];
9242 return (char_u *)NULL;
9243}
9244#endif
9245
Bram Moolenaar071d4272004-06-13 20:20:40 +00009246/*
9247 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9248 */
9249 static int
9250find_key_option(arg)
9251 char_u *arg;
9252{
9253 int key;
9254 int modifiers;
9255
9256 /*
9257 * Don't use get_special_key_code() for t_xx, we don't want it to call
9258 * add_termcap_entry().
9259 */
9260 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9261 key = TERMCAP2KEY(arg[2], arg[3]);
9262 else
9263 {
9264 --arg; /* put arg at the '<' */
9265 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009266 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009267 if (modifiers) /* can't handle modifiers here */
9268 key = 0;
9269 }
9270 return key;
9271}
9272
9273/*
9274 * if 'all' == 0: show changed options
9275 * if 'all' == 1: show all normal options
9276 * if 'all' == 2: show all terminal options
9277 */
9278 static void
9279showoptions(all, opt_flags)
9280 int all;
9281 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9282{
9283 struct vimoption *p;
9284 int col;
9285 int isterm;
9286 char_u *varp;
9287 struct vimoption **items;
9288 int item_count;
9289 int run;
9290 int row, rows;
9291 int cols;
9292 int i;
9293 int len;
9294
9295#define INC 20
9296#define GAP 3
9297
9298 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9299 PARAM_COUNT));
9300 if (items == NULL)
9301 return;
9302
9303 /* Highlight title */
9304 if (all == 2)
9305 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9306 else if (opt_flags & OPT_GLOBAL)
9307 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9308 else if (opt_flags & OPT_LOCAL)
9309 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9310 else
9311 MSG_PUTS_TITLE(_("\n--- Options ---"));
9312
9313 /*
9314 * do the loop two times:
9315 * 1. display the short items
9316 * 2. display the long items (only strings and numbers)
9317 */
9318 for (run = 1; run <= 2 && !got_int; ++run)
9319 {
9320 /*
9321 * collect the items in items[]
9322 */
9323 item_count = 0;
9324 for (p = &options[0]; p->fullname != NULL; p++)
9325 {
9326 varp = NULL;
9327 isterm = istermoption(p);
9328 if (opt_flags != 0)
9329 {
9330 if (p->indir != PV_NONE && !isterm)
9331 varp = get_varp_scope(p, opt_flags);
9332 }
9333 else
9334 varp = get_varp(p);
9335 if (varp != NULL
9336 && ((all == 2 && isterm)
9337 || (all == 1 && !isterm)
9338 || (all == 0 && !optval_default(p, varp))))
9339 {
9340 if (p->flags & P_BOOL)
9341 len = 1; /* a toggle option fits always */
9342 else
9343 {
9344 option_value2string(p, opt_flags);
9345 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9346 }
9347 if ((len <= INC - GAP && run == 1) ||
9348 (len > INC - GAP && run == 2))
9349 items[item_count++] = p;
9350 }
9351 }
9352
9353 /*
9354 * display the items
9355 */
9356 if (run == 1)
9357 {
9358 cols = (Columns + GAP - 3) / INC;
9359 if (cols == 0)
9360 cols = 1;
9361 rows = (item_count + cols - 1) / cols;
9362 }
9363 else /* run == 2 */
9364 rows = item_count;
9365 for (row = 0; row < rows && !got_int; ++row)
9366 {
9367 msg_putchar('\n'); /* go to next line */
9368 if (got_int) /* 'q' typed in more */
9369 break;
9370 col = 0;
9371 for (i = row; i < item_count; i += rows)
9372 {
9373 msg_col = col; /* make columns */
9374 showoneopt(items[i], opt_flags);
9375 col += INC;
9376 }
9377 out_flush();
9378 ui_breakcheck();
9379 }
9380 }
9381 vim_free(items);
9382}
9383
9384/*
9385 * Return TRUE if option "p" has its default value.
9386 */
9387 static int
9388optval_default(p, varp)
9389 struct vimoption *p;
9390 char_u *varp;
9391{
9392 int dvi;
9393
9394 if (varp == NULL)
9395 return TRUE; /* hidden option is always at default */
9396 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9397 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009398 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009399 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009400 /* the cast to long is required for Manx C, long_i is
9401 * needed for MSVC */
9402 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009403 /* P_STRING */
9404 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9405}
9406
9407/*
9408 * showoneopt: show the value of one option
9409 * must not be called with a hidden option!
9410 */
9411 static void
9412showoneopt(p, opt_flags)
9413 struct vimoption *p;
9414 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9415{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009416 char_u *varp;
9417 int save_silent = silent_mode;
9418
9419 silent_mode = FALSE;
9420 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009421
9422 varp = get_varp_scope(p, opt_flags);
9423
9424 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9425 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9426 ? !curbufIsChanged() : !*(int *)varp))
9427 MSG_PUTS("no");
9428 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9429 MSG_PUTS("--");
9430 else
9431 MSG_PUTS(" ");
9432 MSG_PUTS(p->fullname);
9433 if (!(p->flags & P_BOOL))
9434 {
9435 msg_putchar('=');
9436 /* put value string in NameBuff */
9437 option_value2string(p, opt_flags);
9438 msg_outtrans(NameBuff);
9439 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009440
9441 silent_mode = save_silent;
9442 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443}
9444
9445/*
9446 * Write modified options as ":set" commands to a file.
9447 *
9448 * There are three values for "opt_flags":
9449 * OPT_GLOBAL: Write global option values and fresh values of
9450 * buffer-local options (used for start of a session
9451 * file).
9452 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9453 * curwin (used for a vimrc file).
9454 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9455 * and local values for window-local options of
9456 * curwin. Local values are also written when at the
9457 * default value, because a modeline or autocommand
9458 * may have set them when doing ":edit file" and the
9459 * user has set them back at the default or fresh
9460 * value.
9461 * When "local_only" is TRUE, don't write fresh
9462 * values, only local values (for ":mkview").
9463 * (fresh value = value used for a new buffer or window for a local option).
9464 *
9465 * Return FAIL on error, OK otherwise.
9466 */
9467 int
9468makeset(fd, opt_flags, local_only)
9469 FILE *fd;
9470 int opt_flags;
9471 int local_only;
9472{
9473 struct vimoption *p;
9474 char_u *varp; /* currently used value */
9475 char_u *varp_fresh; /* local value */
9476 char_u *varp_local = NULL; /* fresh value */
9477 char *cmd;
9478 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009479 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009480
9481 /*
9482 * The options that don't have a default (terminal name, columns, lines)
9483 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009484 * Do the loop over "options[]" twice: once for options with the
9485 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009486 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009487 for (pri = 1; pri >= 0; --pri)
9488 {
9489 for (p = &options[0]; !istermoption(p); p++)
9490 if (!(p->flags & P_NO_MKRC)
9491 && !istermoption(p)
9492 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009493 {
9494 /* skip global option when only doing locals */
9495 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9496 continue;
9497
9498 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9499 * file, they are always buffer-specific. */
9500 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9501 continue;
9502
9503 /* Global values are only written when not at the default value. */
9504 varp = get_varp_scope(p, opt_flags);
9505 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9506 continue;
9507
9508 round = 2;
9509 if (p->indir != PV_NONE)
9510 {
9511 if (p->var == VAR_WIN)
9512 {
9513 /* skip window-local option when only doing globals */
9514 if (!(opt_flags & OPT_LOCAL))
9515 continue;
9516 /* When fresh value of window-local option is not at the
9517 * default, need to write it too. */
9518 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9519 {
9520 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9521 if (!optval_default(p, varp_fresh))
9522 {
9523 round = 1;
9524 varp_local = varp;
9525 varp = varp_fresh;
9526 }
9527 }
9528 }
9529 }
9530
9531 /* Round 1: fresh value for window-local options.
9532 * Round 2: other values */
9533 for ( ; round <= 2; varp = varp_local, ++round)
9534 {
9535 if (round == 1 || (opt_flags & OPT_GLOBAL))
9536 cmd = "set";
9537 else
9538 cmd = "setlocal";
9539
9540 if (p->flags & P_BOOL)
9541 {
9542 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9543 return FAIL;
9544 }
9545 else if (p->flags & P_NUM)
9546 {
9547 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9548 return FAIL;
9549 }
9550 else /* P_STRING */
9551 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009552#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9553 int do_endif = FALSE;
9554
Bram Moolenaar071d4272004-06-13 20:20:40 +00009555 /* Don't set 'syntax' and 'filetype' again if the value is
9556 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009557 if (
9558# if defined(FEAT_SYN_HL)
9559 p->indir == PV_SYN
9560# if defined(FEAT_AUTOCMD)
9561 ||
9562# endif
9563# endif
9564# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009565 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009566# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009567 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568 {
9569 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9570 *(char_u **)(varp)) < 0
9571 || put_eol(fd) < 0)
9572 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009573 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009574 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009575#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9577 (p->flags & P_EXPAND) != 0) == FAIL)
9578 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009579#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9580 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009581 {
9582 if (put_line(fd, "endif") == FAIL)
9583 return FAIL;
9584 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009585#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009586 }
9587 }
9588 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009590 return OK;
9591}
9592
9593#if defined(FEAT_FOLDING) || defined(PROTO)
9594/*
9595 * Generate set commands for the local fold options only. Used when
9596 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9597 */
9598 int
9599makefoldset(fd)
9600 FILE *fd;
9601{
9602 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9603# ifdef FEAT_EVAL
9604 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9605 == FAIL
9606# endif
9607 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9608 == FAIL
9609 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9610 == FAIL
9611 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9612 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9613 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9614 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9615 )
9616 return FAIL;
9617
9618 return OK;
9619}
9620#endif
9621
9622 static int
9623put_setstring(fd, cmd, name, valuep, expand)
9624 FILE *fd;
9625 char *cmd;
9626 char *name;
9627 char_u **valuep;
9628 int expand;
9629{
9630 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009631 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009632
9633 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9634 return FAIL;
9635 if (*valuep != NULL)
9636 {
9637 /* Output 'pastetoggle' as key names. For other
9638 * options some characters have to be escaped with
9639 * CTRL-V or backslash */
9640 if (valuep == &p_pt)
9641 {
9642 s = *valuep;
9643 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009644 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645 return FAIL;
9646 }
9647 else if (expand)
9648 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009649 buf = alloc(MAXPATHL);
9650 if (buf == NULL)
9651 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009652 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9653 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009654 {
9655 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009656 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009657 }
9658 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009659 }
9660 else if (put_escstr(fd, *valuep, 2) == FAIL)
9661 return FAIL;
9662 }
9663 if (put_eol(fd) < 0)
9664 return FAIL;
9665 return OK;
9666}
9667
9668 static int
9669put_setnum(fd, cmd, name, valuep)
9670 FILE *fd;
9671 char *cmd;
9672 char *name;
9673 long *valuep;
9674{
9675 long wc;
9676
9677 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9678 return FAIL;
9679 if (wc_use_keyname((char_u *)valuep, &wc))
9680 {
9681 /* print 'wildchar' and 'wildcharm' as a key name */
9682 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9683 return FAIL;
9684 }
9685 else if (fprintf(fd, "%ld", *valuep) < 0)
9686 return FAIL;
9687 if (put_eol(fd) < 0)
9688 return FAIL;
9689 return OK;
9690}
9691
9692 static int
9693put_setbool(fd, cmd, name, value)
9694 FILE *fd;
9695 char *cmd;
9696 char *name;
9697 int value;
9698{
Bram Moolenaar893de922007-10-02 18:40:57 +00009699 if (value < 0) /* global/local option using global value */
9700 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009701 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9702 || put_eol(fd) < 0)
9703 return FAIL;
9704 return OK;
9705}
9706
9707/*
9708 * Clear all the terminal options.
9709 * If the option has been allocated, free the memory.
9710 * Terminal options are never hidden or indirect.
9711 */
9712 void
9713clear_termoptions()
9714{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715 /*
9716 * Reset a few things before clearing the old options. This may cause
9717 * outputting a few things that the terminal doesn't understand, but the
9718 * screen will be cleared later, so this is OK.
9719 */
9720#ifdef FEAT_MOUSE_TTY
9721 mch_setmouse(FALSE); /* switch mouse off */
9722#endif
9723#ifdef FEAT_TITLE
9724 mch_restore_title(3); /* restore window titles */
9725#endif
9726#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9727 /* When starting the GUI close the display opened for the clipboard.
9728 * After restoring the title, because that will need the display. */
9729 if (gui.starting)
9730 clear_xterm_clip();
9731#endif
9732#ifdef WIN3264
9733 /*
9734 * Check if this is allowed now.
9735 */
9736 if (can_end_termcap_mode(FALSE) == TRUE)
9737#endif
9738 stoptermcap(); /* stop termcap mode */
9739
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009740 free_termoptions();
9741}
9742
9743 void
9744free_termoptions()
9745{
9746 struct vimoption *p;
9747
Bram Moolenaar071d4272004-06-13 20:20:40 +00009748 for (p = &options[0]; p->fullname != NULL; p++)
9749 if (istermoption(p))
9750 {
9751 if (p->flags & P_ALLOCED)
9752 free_string_option(*(char_u **)(p->var));
9753 if (p->flags & P_DEF_ALLOCED)
9754 free_string_option(p->def_val[VI_DEFAULT]);
9755 *(char_u **)(p->var) = empty_option;
9756 p->def_val[VI_DEFAULT] = empty_option;
9757 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9758 }
9759 clear_termcodes();
9760}
9761
9762/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009763 * Free the string for one term option, if it was allocated.
9764 * Set the string to empty_option and clear allocated flag.
9765 * "var" points to the option value.
9766 */
9767 void
9768free_one_termoption(var)
9769 char_u *var;
9770{
9771 struct vimoption *p;
9772
9773 for (p = &options[0]; p->fullname != NULL; p++)
9774 if (p->var == var)
9775 {
9776 if (p->flags & P_ALLOCED)
9777 free_string_option(*(char_u **)(p->var));
9778 *(char_u **)(p->var) = empty_option;
9779 p->flags &= ~P_ALLOCED;
9780 break;
9781 }
9782}
9783
9784/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009785 * Set the terminal option defaults to the current value.
9786 * Used after setting the terminal name.
9787 */
9788 void
9789set_term_defaults()
9790{
9791 struct vimoption *p;
9792
9793 for (p = &options[0]; p->fullname != NULL; p++)
9794 {
9795 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9796 {
9797 if (p->flags & P_DEF_ALLOCED)
9798 {
9799 free_string_option(p->def_val[VI_DEFAULT]);
9800 p->flags &= ~P_DEF_ALLOCED;
9801 }
9802 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9803 if (p->flags & P_ALLOCED)
9804 {
9805 p->flags |= P_DEF_ALLOCED;
9806 p->flags &= ~P_ALLOCED; /* don't free the value now */
9807 }
9808 }
9809 }
9810}
9811
9812/*
9813 * return TRUE if 'p' starts with 't_'
9814 */
9815 static int
9816istermoption(p)
9817 struct vimoption *p;
9818{
9819 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9820}
9821
9822/*
9823 * Compute columns for ruler and shown command. 'sc_col' is also used to
9824 * decide what the maximum length of a message on the status line can be.
9825 * If there is a status line for the last window, 'sc_col' is independent
9826 * of 'ru_col'.
9827 */
9828
9829#define COL_RULER 17 /* columns needed by standard ruler */
9830
9831 void
9832comp_col()
9833{
9834#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9835 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9836
9837 sc_col = 0;
9838 ru_col = 0;
9839 if (p_ru)
9840 {
9841#ifdef FEAT_STL_OPT
9842 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9843#else
9844 ru_col = COL_RULER + 1;
9845#endif
9846 /* no last status line, adjust sc_col */
9847 if (!last_has_status)
9848 sc_col = ru_col;
9849 }
9850 if (p_sc)
9851 {
9852 sc_col += SHOWCMD_COLS;
9853 if (!p_ru || last_has_status) /* no need for separating space */
9854 ++sc_col;
9855 }
9856 sc_col = Columns - sc_col;
9857 ru_col = Columns - ru_col;
9858 if (sc_col <= 0) /* screen too narrow, will become a mess */
9859 sc_col = 1;
9860 if (ru_col <= 0)
9861 ru_col = 1;
9862#else
9863 sc_col = Columns;
9864 ru_col = Columns;
9865#endif
9866}
9867
9868/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009869 * Unset local option value, similar to ":set opt<".
9870 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009871 void
9872unset_global_local_option(name, from)
9873 char_u *name;
9874 void *from;
9875{
9876 struct vimoption *p;
9877 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009878 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009879
9880 opt_idx = findoption(name);
9881 p = &(options[opt_idx]);
9882
9883 switch ((int)p->indir)
9884 {
9885 /* global option with local value: use local value if it's been set */
9886 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009887 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009888 break;
9889 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009890 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009891 break;
9892 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009893 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009894 break;
9895 case PV_AR:
9896 buf->b_p_ar = -1;
9897 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009898 case PV_BKC:
9899 clear_string_option(&buf->b_p_bkc);
9900 buf->b_bkc_flags = 0;
9901 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009902 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009903 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009904 break;
9905#ifdef FEAT_FIND_ID
9906 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009907 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009908 break;
9909 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009910 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009911 break;
9912#endif
9913#ifdef FEAT_INS_EXPAND
9914 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009915 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009916 break;
9917 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009918 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009919 break;
9920#endif
9921#ifdef FEAT_QUICKFIX
9922 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009923 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009924 break;
9925 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009926 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009927 break;
9928 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009929 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009930 break;
9931#endif
9932#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9933 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009934 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009935 break;
9936#endif
9937#if defined(FEAT_CRYPT)
9938 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009939 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009940 break;
9941#endif
9942#ifdef FEAT_STL_OPT
9943 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009944 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009945 break;
9946#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009947 case PV_UL:
9948 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9949 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009950#ifdef FEAT_LISP
9951 case PV_LW:
9952 clear_string_option(&buf->b_p_lw);
9953 break;
9954#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009955 }
9956}
9957
9958/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959 * Get pointer to option variable, depending on local or global scope.
9960 */
9961 static char_u *
9962get_varp_scope(p, opt_flags)
9963 struct vimoption *p;
9964 int opt_flags;
9965{
9966 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9967 {
9968 if (p->var == VAR_WIN)
9969 return (char_u *)GLOBAL_WO(get_varp(p));
9970 return p->var;
9971 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009972 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973 {
9974 switch ((int)p->indir)
9975 {
9976#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009977 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9978 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9979 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009980#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009981 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9982 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9983 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009984 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009985 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009986#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009987 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9988 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989#endif
9990#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009991 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9992 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009994#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9995 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9996#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009997#if defined(FEAT_CRYPT)
9998 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9999#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010000#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010001 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010002#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010003 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010004#ifdef FEAT_LISP
10005 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10006#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010007 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008 }
10009 return NULL; /* "cannot happen" */
10010 }
10011 return get_varp(p);
10012}
10013
10014/*
10015 * Get pointer to option variable.
10016 */
10017 static char_u *
10018get_varp(p)
10019 struct vimoption *p;
10020{
10021 /* hidden option, always return NULL */
10022 if (p->var == NULL)
10023 return NULL;
10024
10025 switch ((int)p->indir)
10026 {
10027 case PV_NONE: return p->var;
10028
10029 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010030 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010032 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010033 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010034 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010035 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010036 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010037 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010038 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010039 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010040 case PV_BKC: return *curbuf->b_p_bkc != NUL
10041 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010042#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010043 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010044 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010045 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010046 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10047#endif
10048#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010049 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010050 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010051 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10053#endif
10054#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010055 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010057 case PV_GP: return *curbuf->b_p_gp != NUL
10058 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10059 case PV_MP: return *curbuf->b_p_mp != NUL
10060 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010061#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010062#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10063 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10064 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10065#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010066#if defined(FEAT_CRYPT)
10067 case PV_CM: return *curbuf->b_p_cm != NUL
10068 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10069#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010070#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010071 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010072 ? (char_u *)&(curwin->w_p_stl) : p->var;
10073#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010074 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10075 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010076#ifdef FEAT_LISP
10077 case PV_LW: return *curbuf->b_p_lw != NUL
10078 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10079#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010080
10081#ifdef FEAT_ARABIC
10082 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10083#endif
10084 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010085#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010086 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10087#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010088#ifdef FEAT_SYN_HL
10089 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10090 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010091 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010092#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010093#ifdef FEAT_DIFF
10094 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10095#endif
10096#ifdef FEAT_FOLDING
10097 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10098 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10099 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10100 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10101 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10102 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10103 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10104# ifdef FEAT_EVAL
10105 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10106 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10107# endif
10108 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10109#endif
10110 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010111 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010112#ifdef FEAT_LINEBREAK
10113 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10114#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010115#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010116 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10117#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010118#ifdef FEAT_VERTSPLIT
10119 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10120#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010121#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10122 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10123#endif
10124#ifdef FEAT_RIGHTLEFT
10125 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10126 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10127#endif
10128 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10129 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10130#ifdef FEAT_LINEBREAK
10131 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010132 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10133 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010134#endif
10135#ifdef FEAT_SCROLLBIND
10136 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10137#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010138#ifdef FEAT_CURSORBIND
10139 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10140#endif
10141#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010142 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10143 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010144#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145
10146 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10147 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10148#ifdef FEAT_MBYTE
10149 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10150#endif
10151#if defined(FEAT_QUICKFIX)
10152 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10153 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10154#endif
10155 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10156 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10157#ifdef FEAT_CINDENT
10158 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10159 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10160 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10161#endif
10162#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10163 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10164#endif
10165#ifdef FEAT_COMMENTS
10166 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10167#endif
10168#ifdef FEAT_FOLDING
10169 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10170#endif
10171#ifdef FEAT_INS_EXPAND
10172 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10173#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010174#ifdef FEAT_COMPL_FUNC
10175 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010176 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010177#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10179 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10180#ifdef FEAT_MBYTE
10181 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10182#endif
10183 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10184#ifdef FEAT_AUTOCMD
10185 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10186#endif
10187 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010188 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10190 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10191 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10192 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10193#ifdef FEAT_FIND_ID
10194# ifdef FEAT_EVAL
10195 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10196# endif
10197#endif
10198#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10199 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10200 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10201#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010202#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010203 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10204#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205#ifdef FEAT_CRYPT
10206 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10207#endif
10208#ifdef FEAT_LISP
10209 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10210#endif
10211 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10212 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10213 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10214 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10215 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010216 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010217#ifdef FEAT_TEXTOBJ
10218 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10221#ifdef FEAT_SMARTINDENT
10222 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10223#endif
10224#ifndef SHORT_FNAME
10225 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10226#endif
10227 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10228#ifdef FEAT_SEARCHPATH
10229 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10230#endif
10231 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10232#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010233 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010234 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10235#endif
10236#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010237 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10238 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10239 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010240#endif
10241 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10242 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10243 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10244 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010245#ifdef FEAT_PERSISTENT_UNDO
10246 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10247#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10249#ifdef FEAT_KEYMAP
10250 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10251#endif
10252 default: EMSG(_("E356: get_varp ERROR"));
10253 }
10254 /* always return a valid pointer to avoid a crash! */
10255 return (char_u *)&(curbuf->b_p_wm);
10256}
10257
10258/*
10259 * Get the value of 'equalprg', either the buffer-local one or the global one.
10260 */
10261 char_u *
10262get_equalprg()
10263{
10264 if (*curbuf->b_p_ep == NUL)
10265 return p_ep;
10266 return curbuf->b_p_ep;
10267}
10268
10269#if defined(FEAT_WINDOWS) || defined(PROTO)
10270/*
10271 * Copy options from one window to another.
10272 * Used when splitting a window.
10273 */
10274 void
10275win_copy_options(wp_from, wp_to)
10276 win_T *wp_from;
10277 win_T *wp_to;
10278{
10279 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10280 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10281# ifdef FEAT_RIGHTLEFT
10282# ifdef FEAT_FKMAP
10283 /* Is this right? */
10284 wp_to->w_farsi = wp_from->w_farsi;
10285# endif
10286# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010287#if defined(FEAT_LINEBREAK)
10288 briopt_check(wp_to);
10289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290}
10291#endif
10292
10293/*
10294 * Copy the options from one winopt_T to another.
10295 * Doesn't free the old option values in "to", use clear_winopt() for that.
10296 * The 'scroll' option is not copied, because it depends on the window height.
10297 * The 'previewwindow' option is reset, there can be only one preview window.
10298 */
10299 void
10300copy_winopt(from, to)
10301 winopt_T *from;
10302 winopt_T *to;
10303{
10304#ifdef FEAT_ARABIC
10305 to->wo_arab = from->wo_arab;
10306#endif
10307 to->wo_list = from->wo_list;
10308 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010309 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010310#ifdef FEAT_LINEBREAK
10311 to->wo_nuw = from->wo_nuw;
10312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010313#ifdef FEAT_RIGHTLEFT
10314 to->wo_rl = from->wo_rl;
10315 to->wo_rlc = vim_strsave(from->wo_rlc);
10316#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010317#ifdef FEAT_STL_OPT
10318 to->wo_stl = vim_strsave(from->wo_stl);
10319#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010321#ifdef FEAT_DIFF
10322 to->wo_wrap_save = from->wo_wrap_save;
10323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324#ifdef FEAT_LINEBREAK
10325 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010326 to->wo_bri = from->wo_bri;
10327 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010328#endif
10329#ifdef FEAT_SCROLLBIND
10330 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010331 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010332#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010333#ifdef FEAT_CURSORBIND
10334 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010335 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010336#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010337#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010338 to->wo_spell = from->wo_spell;
10339#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010340#ifdef FEAT_SYN_HL
10341 to->wo_cuc = from->wo_cuc;
10342 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010343 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345#ifdef FEAT_DIFF
10346 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010347 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010349#ifdef FEAT_CONCEAL
10350 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010351 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010353#ifdef FEAT_FOLDING
10354 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010355 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010357 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358 to->wo_fdi = vim_strsave(from->wo_fdi);
10359 to->wo_fml = from->wo_fml;
10360 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010361 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010362 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010363 to->wo_fdm_save = from->wo_diff_saved
10364 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365 to->wo_fdn = from->wo_fdn;
10366# ifdef FEAT_EVAL
10367 to->wo_fde = vim_strsave(from->wo_fde);
10368 to->wo_fdt = vim_strsave(from->wo_fdt);
10369# endif
10370 to->wo_fmr = vim_strsave(from->wo_fmr);
10371#endif
10372 check_winopt(to); /* don't want NULL pointers */
10373}
10374
10375/*
10376 * Check string options in a window for a NULL value.
10377 */
10378 void
10379check_win_options(win)
10380 win_T *win;
10381{
10382 check_winopt(&win->w_onebuf_opt);
10383 check_winopt(&win->w_allbuf_opt);
10384}
10385
10386/*
10387 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10388 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010389 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010390check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010391 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010392{
10393#ifdef FEAT_FOLDING
10394 check_string_option(&wop->wo_fdi);
10395 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010396 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010397# ifdef FEAT_EVAL
10398 check_string_option(&wop->wo_fde);
10399 check_string_option(&wop->wo_fdt);
10400# endif
10401 check_string_option(&wop->wo_fmr);
10402#endif
10403#ifdef FEAT_RIGHTLEFT
10404 check_string_option(&wop->wo_rlc);
10405#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010406#ifdef FEAT_STL_OPT
10407 check_string_option(&wop->wo_stl);
10408#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010409#ifdef FEAT_SYN_HL
10410 check_string_option(&wop->wo_cc);
10411#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010412#ifdef FEAT_CONCEAL
10413 check_string_option(&wop->wo_cocu);
10414#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010415#ifdef FEAT_LINEBREAK
10416 check_string_option(&wop->wo_briopt);
10417#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010418}
10419
10420/*
10421 * Free the allocated memory inside a winopt_T.
10422 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010423 void
10424clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010425 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426{
10427#ifdef FEAT_FOLDING
10428 clear_string_option(&wop->wo_fdi);
10429 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010430 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431# ifdef FEAT_EVAL
10432 clear_string_option(&wop->wo_fde);
10433 clear_string_option(&wop->wo_fdt);
10434# endif
10435 clear_string_option(&wop->wo_fmr);
10436#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010437#ifdef FEAT_LINEBREAK
10438 clear_string_option(&wop->wo_briopt);
10439#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010440#ifdef FEAT_RIGHTLEFT
10441 clear_string_option(&wop->wo_rlc);
10442#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010443#ifdef FEAT_STL_OPT
10444 clear_string_option(&wop->wo_stl);
10445#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010446#ifdef FEAT_SYN_HL
10447 clear_string_option(&wop->wo_cc);
10448#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010449#ifdef FEAT_CONCEAL
10450 clear_string_option(&wop->wo_cocu);
10451#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010452}
10453
10454/*
10455 * Copy global option values to local options for one buffer.
10456 * Used when creating a new buffer and sometimes when entering a buffer.
10457 * flags:
10458 * BCO_ENTER We will enter the buf buffer.
10459 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10460 * appropriate.
10461 * BCO_NOHELP Don't copy the values to a help buffer.
10462 */
10463 void
10464buf_copy_options(buf, flags)
10465 buf_T *buf;
10466 int flags;
10467{
10468 int should_copy = TRUE;
10469 char_u *save_p_isk = NULL; /* init for GCC */
10470 int dont_do_help;
10471 int did_isk = FALSE;
10472
10473 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010474 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475 */
10476 if (buf == NULL || !buf_valid(buf))
10477 return;
10478
10479 /*
10480 * Skip this when the option defaults have not been set yet. Happens when
10481 * main() allocates the first buffer.
10482 */
10483 if (p_cpo != NULL)
10484 {
10485 /*
10486 * Always copy when entering and 'cpo' contains 'S'.
10487 * Don't copy when already initialized.
10488 * Don't copy when 'cpo' contains 's' and not entering.
10489 * 'S' BCO_ENTER initialized 's' should_copy
10490 * yes yes X X TRUE
10491 * yes no yes X FALSE
10492 * no X yes X FALSE
10493 * X no no yes FALSE
10494 * X no no no TRUE
10495 * no yes no X TRUE
10496 */
10497 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10498 && (buf->b_p_initialized
10499 || (!(flags & BCO_ENTER)
10500 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10501 should_copy = FALSE;
10502
10503 if (should_copy || (flags & BCO_ALWAYS))
10504 {
10505 /* Don't copy the options specific to a help buffer when
10506 * BCO_NOHELP is given or the options were initialized already
10507 * (jumping back to a help file with CTRL-T or CTRL-O) */
10508 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10509 || buf->b_p_initialized;
10510 if (dont_do_help) /* don't free b_p_isk */
10511 {
10512 save_p_isk = buf->b_p_isk;
10513 buf->b_p_isk = NULL;
10514 }
10515 /*
10516 * Always free the allocated strings.
10517 * If not already initialized, set 'readonly' and copy 'fileformat'.
10518 */
10519 if (!buf->b_p_initialized)
10520 {
10521 free_buf_options(buf, TRUE);
10522 buf->b_p_ro = FALSE; /* don't copy readonly */
10523 buf->b_p_tx = p_tx;
10524#ifdef FEAT_MBYTE
10525 buf->b_p_fenc = vim_strsave(p_fenc);
10526#endif
10527 buf->b_p_ff = vim_strsave(p_ff);
10528#if defined(FEAT_QUICKFIX)
10529 buf->b_p_bh = empty_option;
10530 buf->b_p_bt = empty_option;
10531#endif
10532 }
10533 else
10534 free_buf_options(buf, FALSE);
10535
10536 buf->b_p_ai = p_ai;
10537 buf->b_p_ai_nopaste = p_ai_nopaste;
10538 buf->b_p_sw = p_sw;
10539 buf->b_p_tw = p_tw;
10540 buf->b_p_tw_nopaste = p_tw_nopaste;
10541 buf->b_p_tw_nobin = p_tw_nobin;
10542 buf->b_p_wm = p_wm;
10543 buf->b_p_wm_nopaste = p_wm_nopaste;
10544 buf->b_p_wm_nobin = p_wm_nobin;
10545 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010546#ifdef FEAT_MBYTE
10547 buf->b_p_bomb = p_bomb;
10548#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549 buf->b_p_et = p_et;
10550 buf->b_p_et_nobin = p_et_nobin;
10551 buf->b_p_ml = p_ml;
10552 buf->b_p_ml_nobin = p_ml_nobin;
10553 buf->b_p_inf = p_inf;
10554 buf->b_p_swf = p_swf;
10555#ifdef FEAT_INS_EXPAND
10556 buf->b_p_cpt = vim_strsave(p_cpt);
10557#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010558#ifdef FEAT_COMPL_FUNC
10559 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010560 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010561#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562 buf->b_p_sts = p_sts;
10563 buf->b_p_sts_nopaste = p_sts_nopaste;
10564#ifndef SHORT_FNAME
10565 buf->b_p_sn = p_sn;
10566#endif
10567#ifdef FEAT_COMMENTS
10568 buf->b_p_com = vim_strsave(p_com);
10569#endif
10570#ifdef FEAT_FOLDING
10571 buf->b_p_cms = vim_strsave(p_cms);
10572#endif
10573 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010574 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575 buf->b_p_nf = vim_strsave(p_nf);
10576 buf->b_p_mps = vim_strsave(p_mps);
10577#ifdef FEAT_SMARTINDENT
10578 buf->b_p_si = p_si;
10579#endif
10580 buf->b_p_ci = p_ci;
10581#ifdef FEAT_CINDENT
10582 buf->b_p_cin = p_cin;
10583 buf->b_p_cink = vim_strsave(p_cink);
10584 buf->b_p_cino = vim_strsave(p_cino);
10585#endif
10586#ifdef FEAT_AUTOCMD
10587 /* Don't copy 'filetype', it must be detected */
10588 buf->b_p_ft = empty_option;
10589#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590 buf->b_p_pi = p_pi;
10591#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10592 buf->b_p_cinw = vim_strsave(p_cinw);
10593#endif
10594#ifdef FEAT_LISP
10595 buf->b_p_lisp = p_lisp;
10596#endif
10597#ifdef FEAT_SYN_HL
10598 /* Don't copy 'syntax', it must be set */
10599 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010600 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010601#endif
10602#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010603 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010604 (void)compile_cap_prog(&buf->b_s);
10605 buf->b_s.b_p_spf = vim_strsave(p_spf);
10606 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010607#endif
10608#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10609 buf->b_p_inde = vim_strsave(p_inde);
10610 buf->b_p_indk = vim_strsave(p_indk);
10611#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010612#if defined(FEAT_EVAL)
10613 buf->b_p_fex = vim_strsave(p_fex);
10614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010615#ifdef FEAT_CRYPT
10616 buf->b_p_key = vim_strsave(p_key);
10617#endif
10618#ifdef FEAT_SEARCHPATH
10619 buf->b_p_sua = vim_strsave(p_sua);
10620#endif
10621#ifdef FEAT_KEYMAP
10622 buf->b_p_keymap = vim_strsave(p_keymap);
10623 buf->b_kmap_state |= KEYMAP_INIT;
10624#endif
10625 /* This isn't really an option, but copying the langmap and IME
10626 * state from the current buffer is better than resetting it. */
10627 buf->b_p_iminsert = p_iminsert;
10628 buf->b_p_imsearch = p_imsearch;
10629
10630 /* options that are normally global but also have a local value
10631 * are not copied, start using the global value */
10632 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010633 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010634 buf->b_p_bkc = empty_option;
10635 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636#ifdef FEAT_QUICKFIX
10637 buf->b_p_gp = empty_option;
10638 buf->b_p_mp = empty_option;
10639 buf->b_p_efm = empty_option;
10640#endif
10641 buf->b_p_ep = empty_option;
10642 buf->b_p_kp = empty_option;
10643 buf->b_p_path = empty_option;
10644 buf->b_p_tags = empty_option;
10645#ifdef FEAT_FIND_ID
10646 buf->b_p_def = empty_option;
10647 buf->b_p_inc = empty_option;
10648# ifdef FEAT_EVAL
10649 buf->b_p_inex = vim_strsave(p_inex);
10650# endif
10651#endif
10652#ifdef FEAT_INS_EXPAND
10653 buf->b_p_dict = empty_option;
10654 buf->b_p_tsr = empty_option;
10655#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010656#ifdef FEAT_TEXTOBJ
10657 buf->b_p_qe = vim_strsave(p_qe);
10658#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010659#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10660 buf->b_p_bexpr = empty_option;
10661#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010662#if defined(FEAT_CRYPT)
10663 buf->b_p_cm = empty_option;
10664#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010665#ifdef FEAT_PERSISTENT_UNDO
10666 buf->b_p_udf = p_udf;
10667#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010668#ifdef FEAT_LISP
10669 buf->b_p_lw = empty_option;
10670#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010671
10672 /*
10673 * Don't copy the options set by ex_help(), use the saved values,
10674 * when going from a help buffer to a non-help buffer.
10675 * Don't touch these at all when BCO_NOHELP is used and going from
10676 * or to a help buffer.
10677 */
10678 if (dont_do_help)
10679 buf->b_p_isk = save_p_isk;
10680 else
10681 {
10682 buf->b_p_isk = vim_strsave(p_isk);
10683 did_isk = TRUE;
10684 buf->b_p_ts = p_ts;
10685 buf->b_help = FALSE;
10686#ifdef FEAT_QUICKFIX
10687 if (buf->b_p_bt[0] == 'h')
10688 clear_string_option(&buf->b_p_bt);
10689#endif
10690 buf->b_p_ma = p_ma;
10691 }
10692 }
10693
10694 /*
10695 * When the options should be copied (ignoring BCO_ALWAYS), set the
10696 * flag that indicates that the options have been initialized.
10697 */
10698 if (should_copy)
10699 buf->b_p_initialized = TRUE;
10700 }
10701
10702 check_buf_options(buf); /* make sure we don't have NULLs */
10703 if (did_isk)
10704 (void)buf_init_chartab(buf, FALSE);
10705}
10706
10707/*
10708 * Reset the 'modifiable' option and its default value.
10709 */
10710 void
10711reset_modifiable()
10712{
10713 int opt_idx;
10714
10715 curbuf->b_p_ma = FALSE;
10716 p_ma = FALSE;
10717 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010718 if (opt_idx >= 0)
10719 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010720}
10721
10722/*
10723 * Set the global value for 'iminsert' to the local value.
10724 */
10725 void
10726set_iminsert_global()
10727{
10728 p_iminsert = curbuf->b_p_iminsert;
10729}
10730
10731/*
10732 * Set the global value for 'imsearch' to the local value.
10733 */
10734 void
10735set_imsearch_global()
10736{
10737 p_imsearch = curbuf->b_p_imsearch;
10738}
10739
10740#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10741static int expand_option_idx = -1;
10742static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10743static int expand_option_flags = 0;
10744
10745 void
10746set_context_in_set_cmd(xp, arg, opt_flags)
10747 expand_T *xp;
10748 char_u *arg;
10749 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10750{
10751 int nextchar;
10752 long_u flags = 0; /* init for GCC */
10753 int opt_idx = 0; /* init for GCC */
10754 char_u *p;
10755 char_u *s;
10756 int is_term_option = FALSE;
10757 int key;
10758
10759 expand_option_flags = opt_flags;
10760
10761 xp->xp_context = EXPAND_SETTINGS;
10762 if (*arg == NUL)
10763 {
10764 xp->xp_pattern = arg;
10765 return;
10766 }
10767 p = arg + STRLEN(arg) - 1;
10768 if (*p == ' ' && *(p - 1) != '\\')
10769 {
10770 xp->xp_pattern = p + 1;
10771 return;
10772 }
10773 while (p > arg)
10774 {
10775 s = p;
10776 /* count number of backslashes before ' ' or ',' */
10777 if (*p == ' ' || *p == ',')
10778 {
10779 while (s > arg && *(s - 1) == '\\')
10780 --s;
10781 }
10782 /* break at a space with an even number of backslashes */
10783 if (*p == ' ' && ((p - s) & 1) == 0)
10784 {
10785 ++p;
10786 break;
10787 }
10788 --p;
10789 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010790 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010791 {
10792 xp->xp_context = EXPAND_BOOL_SETTINGS;
10793 p += 2;
10794 }
10795 if (STRNCMP(p, "inv", 3) == 0)
10796 {
10797 xp->xp_context = EXPAND_BOOL_SETTINGS;
10798 p += 3;
10799 }
10800 xp->xp_pattern = arg = p;
10801 if (*arg == '<')
10802 {
10803 while (*p != '>')
10804 if (*p++ == NUL) /* expand terminal option name */
10805 return;
10806 key = get_special_key_code(arg + 1);
10807 if (key == 0) /* unknown name */
10808 {
10809 xp->xp_context = EXPAND_NOTHING;
10810 return;
10811 }
10812 nextchar = *++p;
10813 is_term_option = TRUE;
10814 expand_option_name[2] = KEY2TERMCAP0(key);
10815 expand_option_name[3] = KEY2TERMCAP1(key);
10816 }
10817 else
10818 {
10819 if (p[0] == 't' && p[1] == '_')
10820 {
10821 p += 2;
10822 if (*p != NUL)
10823 ++p;
10824 if (*p == NUL)
10825 return; /* expand option name */
10826 nextchar = *++p;
10827 is_term_option = TRUE;
10828 expand_option_name[2] = p[-2];
10829 expand_option_name[3] = p[-1];
10830 }
10831 else
10832 {
10833 /* Allow * wildcard */
10834 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10835 p++;
10836 if (*p == NUL)
10837 return;
10838 nextchar = *p;
10839 *p = NUL;
10840 opt_idx = findoption(arg);
10841 *p = nextchar;
10842 if (opt_idx == -1 || options[opt_idx].var == NULL)
10843 {
10844 xp->xp_context = EXPAND_NOTHING;
10845 return;
10846 }
10847 flags = options[opt_idx].flags;
10848 if (flags & P_BOOL)
10849 {
10850 xp->xp_context = EXPAND_NOTHING;
10851 return;
10852 }
10853 }
10854 }
10855 /* handle "-=" and "+=" */
10856 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10857 {
10858 ++p;
10859 nextchar = '=';
10860 }
10861 if ((nextchar != '=' && nextchar != ':')
10862 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10863 {
10864 xp->xp_context = EXPAND_UNSUCCESSFUL;
10865 return;
10866 }
10867 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10868 {
10869 xp->xp_context = EXPAND_OLD_SETTING;
10870 if (is_term_option)
10871 expand_option_idx = -1;
10872 else
10873 expand_option_idx = opt_idx;
10874 xp->xp_pattern = p + 1;
10875 return;
10876 }
10877 xp->xp_context = EXPAND_NOTHING;
10878 if (is_term_option || (flags & P_NUM))
10879 return;
10880
10881 xp->xp_pattern = p + 1;
10882
10883 if (flags & P_EXPAND)
10884 {
10885 p = options[opt_idx].var;
10886 if (p == (char_u *)&p_bdir
10887 || p == (char_u *)&p_dir
10888 || p == (char_u *)&p_path
10889 || p == (char_u *)&p_rtp
10890#ifdef FEAT_SEARCHPATH
10891 || p == (char_u *)&p_cdpath
10892#endif
10893#ifdef FEAT_SESSION
10894 || p == (char_u *)&p_vdir
10895#endif
10896 )
10897 {
10898 xp->xp_context = EXPAND_DIRECTORIES;
10899 if (p == (char_u *)&p_path
10900#ifdef FEAT_SEARCHPATH
10901 || p == (char_u *)&p_cdpath
10902#endif
10903 )
10904 xp->xp_backslash = XP_BS_THREE;
10905 else
10906 xp->xp_backslash = XP_BS_ONE;
10907 }
10908 else
10909 {
10910 xp->xp_context = EXPAND_FILES;
10911 /* for 'tags' need three backslashes for a space */
10912 if (p == (char_u *)&p_tags)
10913 xp->xp_backslash = XP_BS_THREE;
10914 else
10915 xp->xp_backslash = XP_BS_ONE;
10916 }
10917 }
10918
10919 /* For an option that is a list of file names, find the start of the
10920 * last file name. */
10921 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10922 {
10923 /* count number of backslashes before ' ' or ',' */
10924 if (*p == ' ' || *p == ',')
10925 {
10926 s = p;
10927 while (s > xp->xp_pattern && *(s - 1) == '\\')
10928 --s;
10929 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10930 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10931 {
10932 xp->xp_pattern = p + 1;
10933 break;
10934 }
10935 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010936
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010937#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010938 /* for 'spellsuggest' start at "file:" */
10939 if (options[opt_idx].var == (char_u *)&p_sps
10940 && STRNCMP(p, "file:", 5) == 0)
10941 {
10942 xp->xp_pattern = p + 5;
10943 break;
10944 }
10945#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010946 }
10947
10948 return;
10949}
10950
10951 int
10952ExpandSettings(xp, regmatch, num_file, file)
10953 expand_T *xp;
10954 regmatch_T *regmatch;
10955 int *num_file;
10956 char_u ***file;
10957{
10958 int num_normal = 0; /* Nr of matching non-term-code settings */
10959 int num_term = 0; /* Nr of matching terminal code settings */
10960 int opt_idx;
10961 int match;
10962 int count = 0;
10963 char_u *str;
10964 int loop;
10965 int is_term_opt;
10966 char_u name_buf[MAX_KEY_NAME_LEN];
10967 static char *(names[]) = {"all", "termcap"};
10968 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10969
10970 /* do this loop twice:
10971 * loop == 0: count the number of matching options
10972 * loop == 1: copy the matching options into allocated memory
10973 */
10974 for (loop = 0; loop <= 1; ++loop)
10975 {
10976 regmatch->rm_ic = ic;
10977 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10978 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010979 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10980 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010981 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10982 {
10983 if (loop == 0)
10984 num_normal++;
10985 else
10986 (*file)[count++] = vim_strsave((char_u *)names[match]);
10987 }
10988 }
10989 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10990 opt_idx++)
10991 {
10992 if (options[opt_idx].var == NULL)
10993 continue;
10994 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10995 && !(options[opt_idx].flags & P_BOOL))
10996 continue;
10997 is_term_opt = istermoption(&options[opt_idx]);
10998 if (is_term_opt && num_normal > 0)
10999 continue;
11000 match = FALSE;
11001 if (vim_regexec(regmatch, str, (colnr_T)0)
11002 || (options[opt_idx].shortname != NULL
11003 && vim_regexec(regmatch,
11004 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11005 match = TRUE;
11006 else if (is_term_opt)
11007 {
11008 name_buf[0] = '<';
11009 name_buf[1] = 't';
11010 name_buf[2] = '_';
11011 name_buf[3] = str[2];
11012 name_buf[4] = str[3];
11013 name_buf[5] = '>';
11014 name_buf[6] = NUL;
11015 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11016 {
11017 match = TRUE;
11018 str = name_buf;
11019 }
11020 }
11021 if (match)
11022 {
11023 if (loop == 0)
11024 {
11025 if (is_term_opt)
11026 num_term++;
11027 else
11028 num_normal++;
11029 }
11030 else
11031 (*file)[count++] = vim_strsave(str);
11032 }
11033 }
11034 /*
11035 * Check terminal key codes, these are not in the option table
11036 */
11037 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11038 {
11039 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11040 {
11041 if (!isprint(str[0]) || !isprint(str[1]))
11042 continue;
11043
11044 name_buf[0] = 't';
11045 name_buf[1] = '_';
11046 name_buf[2] = str[0];
11047 name_buf[3] = str[1];
11048 name_buf[4] = NUL;
11049
11050 match = FALSE;
11051 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11052 match = TRUE;
11053 else
11054 {
11055 name_buf[0] = '<';
11056 name_buf[1] = 't';
11057 name_buf[2] = '_';
11058 name_buf[3] = str[0];
11059 name_buf[4] = str[1];
11060 name_buf[5] = '>';
11061 name_buf[6] = NUL;
11062
11063 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11064 match = TRUE;
11065 }
11066 if (match)
11067 {
11068 if (loop == 0)
11069 num_term++;
11070 else
11071 (*file)[count++] = vim_strsave(name_buf);
11072 }
11073 }
11074
11075 /*
11076 * Check special key names.
11077 */
11078 regmatch->rm_ic = TRUE; /* ignore case here */
11079 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11080 {
11081 name_buf[0] = '<';
11082 STRCPY(name_buf + 1, str);
11083 STRCAT(name_buf, ">");
11084
11085 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11086 {
11087 if (loop == 0)
11088 num_term++;
11089 else
11090 (*file)[count++] = vim_strsave(name_buf);
11091 }
11092 }
11093 }
11094 if (loop == 0)
11095 {
11096 if (num_normal > 0)
11097 *num_file = num_normal;
11098 else if (num_term > 0)
11099 *num_file = num_term;
11100 else
11101 return OK;
11102 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11103 if (*file == NULL)
11104 {
11105 *file = (char_u **)"";
11106 return FAIL;
11107 }
11108 }
11109 }
11110 return OK;
11111}
11112
11113 int
11114ExpandOldSetting(num_file, file)
11115 int *num_file;
11116 char_u ***file;
11117{
11118 char_u *var = NULL; /* init for GCC */
11119 char_u *buf;
11120
11121 *num_file = 0;
11122 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11123 if (*file == NULL)
11124 return FAIL;
11125
11126 /*
11127 * For a terminal key code expand_option_idx is < 0.
11128 */
11129 if (expand_option_idx < 0)
11130 {
11131 var = find_termcode(expand_option_name + 2);
11132 if (var == NULL)
11133 expand_option_idx = findoption(expand_option_name);
11134 }
11135
11136 if (expand_option_idx >= 0)
11137 {
11138 /* put string of option value in NameBuff */
11139 option_value2string(&options[expand_option_idx], expand_option_flags);
11140 var = NameBuff;
11141 }
11142 else if (var == NULL)
11143 var = (char_u *)"";
11144
11145 /* A backslash is required before some characters. This is the reverse of
11146 * what happens in do_set(). */
11147 buf = vim_strsave_escaped(var, escape_chars);
11148
11149 if (buf == NULL)
11150 {
11151 vim_free(*file);
11152 *file = NULL;
11153 return FAIL;
11154 }
11155
11156#ifdef BACKSLASH_IN_FILENAME
11157 /* For MS-Windows et al. we don't double backslashes at the start and
11158 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011159 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011160 if (var[0] == '\\' && var[1] == '\\'
11161 && expand_option_idx >= 0
11162 && (options[expand_option_idx].flags & P_EXPAND)
11163 && vim_isfilec(var[2])
11164 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011165 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011166#endif
11167
11168 *file[0] = buf;
11169 *num_file = 1;
11170 return OK;
11171}
11172#endif
11173
11174/*
11175 * Get the value for the numeric or string option *opp in a nice format into
11176 * NameBuff[]. Must not be called with a hidden option!
11177 */
11178 static void
11179option_value2string(opp, opt_flags)
11180 struct vimoption *opp;
11181 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11182{
11183 char_u *varp;
11184
11185 varp = get_varp_scope(opp, opt_flags);
11186
11187 if (opp->flags & P_NUM)
11188 {
11189 long wc = 0;
11190
11191 if (wc_use_keyname(varp, &wc))
11192 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11193 else if (wc != 0)
11194 STRCPY(NameBuff, transchar((int)wc));
11195 else
11196 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11197 }
11198 else /* P_STRING */
11199 {
11200 varp = *(char_u **)(varp);
11201 if (varp == NULL) /* just in case */
11202 NameBuff[0] = NUL;
11203#ifdef FEAT_CRYPT
11204 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011205 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206 STRCPY(NameBuff, "*****");
11207#endif
11208 else if (opp->flags & P_EXPAND)
11209 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11210 /* Translate 'pastetoggle' into special key names */
11211 else if ((char_u **)opp->var == &p_pt)
11212 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11213 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011214 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011215 }
11216}
11217
11218/*
11219 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11220 * printed as a keyname.
11221 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11222 */
11223 static int
11224wc_use_keyname(varp, wcp)
11225 char_u *varp;
11226 long *wcp;
11227{
11228 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11229 {
11230 *wcp = *(long *)varp;
11231 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11232 return TRUE;
11233 }
11234 return FALSE;
11235}
11236
Bram Moolenaar01615492015-02-03 13:00:38 +010011237#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011238/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011239 * Any character has an equivalent 'langmap' character. This is used for
11240 * keyboards that have a special language mode that sends characters above
11241 * 128 (although other characters can be translated too). The "to" field is a
11242 * Vim command character. This avoids having to switch the keyboard back to
11243 * ASCII mode when leaving Insert mode.
11244 *
11245 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11246 * commands.
11247 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11248 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11249 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011250 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011251# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011252/*
11253 * With multi-byte support use growarray for 'langmap' chars >= 256
11254 */
11255typedef struct
11256{
11257 int from;
11258 int to;
11259} langmap_entry_T;
11260
11261static garray_T langmap_mapga;
11262static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011263
11264/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011265 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11266 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011268 static void
11269langmap_set_entry(from, to)
11270 int from;
11271 int to;
11272{
11273 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011274 int a = 0;
11275 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011276
11277 /* Do a binary search for an existing entry. */
11278 while (a != b)
11279 {
11280 int i = (a + b) / 2;
11281 int d = entries[i].from - from;
11282
11283 if (d == 0)
11284 {
11285 entries[i].to = to;
11286 return;
11287 }
11288 if (d < 0)
11289 a = i + 1;
11290 else
11291 b = i;
11292 }
11293
11294 if (ga_grow(&langmap_mapga, 1) != OK)
11295 return; /* out of memory */
11296
11297 /* insert new entry at position "a" */
11298 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11299 mch_memmove(entries + 1, entries,
11300 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11301 ++langmap_mapga.ga_len;
11302 entries[0].from = from;
11303 entries[0].to = to;
11304}
11305
11306/*
11307 * Apply 'langmap' to multi-byte character "c" and return the result.
11308 */
11309 int
11310langmap_adjust_mb(c)
11311 int c;
11312{
11313 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11314 int a = 0;
11315 int b = langmap_mapga.ga_len;
11316
11317 while (a != b)
11318 {
11319 int i = (a + b) / 2;
11320 int d = entries[i].from - c;
11321
11322 if (d == 0)
11323 return entries[i].to; /* found matching entry */
11324 if (d < 0)
11325 a = i + 1;
11326 else
11327 b = i;
11328 }
11329 return c; /* no entry found, return "c" unmodified */
11330}
11331# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332
11333 static void
11334langmap_init()
11335{
11336 int i;
11337
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011338 for (i = 0; i < 256; i++)
11339 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11340# ifdef FEAT_MBYTE
11341 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11342# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011343}
11344
11345/*
11346 * Called when langmap option is set; the language map can be
11347 * changed at any time!
11348 */
11349 static void
11350langmap_set()
11351{
11352 char_u *p;
11353 char_u *p2;
11354 int from, to;
11355
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011356#ifdef FEAT_MBYTE
11357 ga_clear(&langmap_mapga); /* clear the previous map first */
11358#endif
11359 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011360
11361 for (p = p_langmap; p[0] != NUL; )
11362 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011363 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11364 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011365 {
11366 if (p2[0] == '\\' && p2[1] != NUL)
11367 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368 }
11369 if (p2[0] == ';')
11370 ++p2; /* abcd;ABCD form, p2 points to A */
11371 else
11372 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11373 while (p[0])
11374 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011375 if (p[0] == ',')
11376 {
11377 ++p;
11378 break;
11379 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011380 if (p[0] == '\\' && p[1] != NUL)
11381 ++p;
11382#ifdef FEAT_MBYTE
11383 from = (*mb_ptr2char)(p);
11384#else
11385 from = p[0];
11386#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011387 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388 if (p2 == NULL)
11389 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011390 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011391 if (p[0] != ',')
11392 {
11393 if (p[0] == '\\')
11394 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011395#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011396 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011397#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011398 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011399#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011400 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011401 }
11402 else
11403 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011404 if (p2[0] != ',')
11405 {
11406 if (p2[0] == '\\')
11407 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011409 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011410#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011411 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011412#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011414 }
11415 if (to == NUL)
11416 {
11417 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11418 transchar(from));
11419 return;
11420 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011421
11422#ifdef FEAT_MBYTE
11423 if (from >= 256)
11424 langmap_set_entry(from, to);
11425 else
11426#endif
11427 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011428
11429 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011430 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011431 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011432 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011433 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011434 if (*p == ';')
11435 {
11436 p = p2;
11437 if (p[0] != NUL)
11438 {
11439 if (p[0] != ',')
11440 {
11441 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11442 return;
11443 }
11444 ++p;
11445 }
11446 break;
11447 }
11448 }
11449 }
11450 }
11451}
11452#endif
11453
11454/*
11455 * Return TRUE if format option 'x' is in effect.
11456 * Take care of no formatting when 'paste' is set.
11457 */
11458 int
11459has_format_option(x)
11460 int x;
11461{
11462 if (p_paste)
11463 return FALSE;
11464 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11465}
11466
11467/*
11468 * Return TRUE if "x" is present in 'shortmess' option, or
11469 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11470 */
11471 int
11472shortmess(x)
11473 int x;
11474{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011475 return p_shm != NULL &&
11476 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011477 || (vim_strchr(p_shm, 'a') != NULL
11478 && vim_strchr((char_u *)SHM_A, x) != NULL));
11479}
11480
11481/*
11482 * paste_option_changed() - Called after p_paste was set or reset.
11483 */
11484 static void
11485paste_option_changed()
11486{
11487 static int old_p_paste = FALSE;
11488 static int save_sm = 0;
11489#ifdef FEAT_CMDL_INFO
11490 static int save_ru = 0;
11491#endif
11492#ifdef FEAT_RIGHTLEFT
11493 static int save_ri = 0;
11494 static int save_hkmap = 0;
11495#endif
11496 buf_T *buf;
11497
11498 if (p_paste)
11499 {
11500 /*
11501 * Paste switched from off to on.
11502 * Save the current values, so they can be restored later.
11503 */
11504 if (!old_p_paste)
11505 {
11506 /* save options for each buffer */
11507 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11508 {
11509 buf->b_p_tw_nopaste = buf->b_p_tw;
11510 buf->b_p_wm_nopaste = buf->b_p_wm;
11511 buf->b_p_sts_nopaste = buf->b_p_sts;
11512 buf->b_p_ai_nopaste = buf->b_p_ai;
11513 }
11514
11515 /* save global options */
11516 save_sm = p_sm;
11517#ifdef FEAT_CMDL_INFO
11518 save_ru = p_ru;
11519#endif
11520#ifdef FEAT_RIGHTLEFT
11521 save_ri = p_ri;
11522 save_hkmap = p_hkmap;
11523#endif
11524 /* save global values for local buffer options */
11525 p_tw_nopaste = p_tw;
11526 p_wm_nopaste = p_wm;
11527 p_sts_nopaste = p_sts;
11528 p_ai_nopaste = p_ai;
11529 }
11530
11531 /*
11532 * Always set the option values, also when 'paste' is set when it is
11533 * already on.
11534 */
11535 /* set options for each buffer */
11536 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11537 {
11538 buf->b_p_tw = 0; /* textwidth is 0 */
11539 buf->b_p_wm = 0; /* wrapmargin is 0 */
11540 buf->b_p_sts = 0; /* softtabstop is 0 */
11541 buf->b_p_ai = 0; /* no auto-indent */
11542 }
11543
11544 /* set global options */
11545 p_sm = 0; /* no showmatch */
11546#ifdef FEAT_CMDL_INFO
11547# ifdef FEAT_WINDOWS
11548 if (p_ru)
11549 status_redraw_all(); /* redraw to remove the ruler */
11550# endif
11551 p_ru = 0; /* no ruler */
11552#endif
11553#ifdef FEAT_RIGHTLEFT
11554 p_ri = 0; /* no reverse insert */
11555 p_hkmap = 0; /* no Hebrew keyboard */
11556#endif
11557 /* set global values for local buffer options */
11558 p_tw = 0;
11559 p_wm = 0;
11560 p_sts = 0;
11561 p_ai = 0;
11562 }
11563
11564 /*
11565 * Paste switched from on to off: Restore saved values.
11566 */
11567 else if (old_p_paste)
11568 {
11569 /* restore options for each buffer */
11570 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11571 {
11572 buf->b_p_tw = buf->b_p_tw_nopaste;
11573 buf->b_p_wm = buf->b_p_wm_nopaste;
11574 buf->b_p_sts = buf->b_p_sts_nopaste;
11575 buf->b_p_ai = buf->b_p_ai_nopaste;
11576 }
11577
11578 /* restore global options */
11579 p_sm = save_sm;
11580#ifdef FEAT_CMDL_INFO
11581# ifdef FEAT_WINDOWS
11582 if (p_ru != save_ru)
11583 status_redraw_all(); /* redraw to draw the ruler */
11584# endif
11585 p_ru = save_ru;
11586#endif
11587#ifdef FEAT_RIGHTLEFT
11588 p_ri = save_ri;
11589 p_hkmap = save_hkmap;
11590#endif
11591 /* set global values for local buffer options */
11592 p_tw = p_tw_nopaste;
11593 p_wm = p_wm_nopaste;
11594 p_sts = p_sts_nopaste;
11595 p_ai = p_ai_nopaste;
11596 }
11597
11598 old_p_paste = p_paste;
11599}
11600
11601/*
11602 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11603 *
11604 * Reset 'compatible' and set the values for options that didn't get set yet
11605 * to the Vim defaults.
11606 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011607 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011608 */
11609 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011610vimrc_found(fname, envname)
11611 char_u *fname;
11612 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011613{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011614 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011615 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011616 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011617
11618 if (!option_was_set((char_u *)"cp"))
11619 {
11620 p_cp = FALSE;
11621 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11622 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11623 set_option_default(opt_idx, OPT_FREE, FALSE);
11624 didset_options();
11625 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011626
11627 if (fname != NULL)
11628 {
11629 p = vim_getenv(envname, &dofree);
11630 if (p == NULL)
11631 {
11632 /* Set $MYVIMRC to the first vimrc file found. */
11633 p = FullName_save(fname, FALSE);
11634 if (p != NULL)
11635 {
11636 vim_setenv(envname, p);
11637 vim_free(p);
11638 }
11639 }
11640 else if (dofree)
11641 vim_free(p);
11642 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011643}
11644
11645/*
11646 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11647 */
11648 void
11649change_compatible(on)
11650 int on;
11651{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011652 int opt_idx;
11653
Bram Moolenaar071d4272004-06-13 20:20:40 +000011654 if (p_cp != on)
11655 {
11656 p_cp = on;
11657 compatible_set();
11658 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011659 opt_idx = findoption((char_u *)"cp");
11660 if (opt_idx >= 0)
11661 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011662}
11663
11664/*
11665 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011666 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011667 */
11668 int
11669option_was_set(name)
11670 char_u *name;
11671{
11672 int idx;
11673
11674 idx = findoption(name);
11675 if (idx < 0) /* unknown option */
11676 return FALSE;
11677 if (options[idx].flags & P_WAS_SET)
11678 return TRUE;
11679 return FALSE;
11680}
11681
11682/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011683 * Reset the flag indicating option "name" was set.
11684 */
11685 void
11686reset_option_was_set(name)
11687 char_u *name;
11688{
11689 int idx = findoption(name);
11690
11691 if (idx >= 0)
11692 options[idx].flags &= ~P_WAS_SET;
11693}
11694
11695/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011696 * compatible_set() - Called when 'compatible' has been set or unset.
11697 *
11698 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11699 * flag) to a Vi compatible value.
11700 * When 'compatible' is unset: Set all options that have a different default
11701 * for Vim (without the P_VI_DEF flag) to that default.
11702 */
11703 static void
11704compatible_set()
11705{
11706 int opt_idx;
11707
11708 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11709 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11710 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11711 set_option_default(opt_idx, OPT_FREE, p_cp);
11712 didset_options();
11713}
11714
11715#ifdef FEAT_LINEBREAK
11716
11717# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11718 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011719 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011720# endif
11721
11722/*
11723 * fill_breakat_flags() -- called when 'breakat' changes value.
11724 */
11725 static void
11726fill_breakat_flags()
11727{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011728 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011729 int i;
11730
11731 for (i = 0; i < 256; i++)
11732 breakat_flags[i] = FALSE;
11733
11734 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011735 for (p = p_breakat; *p; p++)
11736 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011737}
11738
11739# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011740 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741# endif
11742
11743#endif
11744
11745/*
11746 * Check an option that can be a range of string values.
11747 *
11748 * Return OK for correct value, FAIL otherwise.
11749 * Empty is always OK.
11750 */
11751 static int
11752check_opt_strings(val, values, list)
11753 char_u *val;
11754 char **values;
11755 int list; /* when TRUE: accept a list of values */
11756{
11757 return opt_strings_flags(val, values, NULL, list);
11758}
11759
11760/*
11761 * Handle an option that can be a range of string values.
11762 * Set a flag in "*flagp" for each string present.
11763 *
11764 * Return OK for correct value, FAIL otherwise.
11765 * Empty is always OK.
11766 */
11767 static int
11768opt_strings_flags(val, values, flagp, list)
11769 char_u *val; /* new value */
11770 char **values; /* array of valid string values */
11771 unsigned *flagp;
11772 int list; /* when TRUE: accept a list of values */
11773{
11774 int i;
11775 int len;
11776 unsigned new_flags = 0;
11777
11778 while (*val)
11779 {
11780 for (i = 0; ; ++i)
11781 {
11782 if (values[i] == NULL) /* val not found in values[] */
11783 return FAIL;
11784
11785 len = (int)STRLEN(values[i]);
11786 if (STRNCMP(values[i], val, len) == 0
11787 && ((list && val[len] == ',') || val[len] == NUL))
11788 {
11789 val += len + (val[len] == ',');
11790 new_flags |= (1 << i);
11791 break; /* check next item in val list */
11792 }
11793 }
11794 }
11795 if (flagp != NULL)
11796 *flagp = new_flags;
11797
11798 return OK;
11799}
11800
11801/*
11802 * Read the 'wildmode' option, fill wim_flags[].
11803 */
11804 static int
11805check_opt_wim()
11806{
11807 char_u new_wim_flags[4];
11808 char_u *p;
11809 int i;
11810 int idx = 0;
11811
11812 for (i = 0; i < 4; ++i)
11813 new_wim_flags[i] = 0;
11814
11815 for (p = p_wim; *p; ++p)
11816 {
11817 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11818 ;
11819 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11820 return FAIL;
11821 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11822 new_wim_flags[idx] |= WIM_LONGEST;
11823 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11824 new_wim_flags[idx] |= WIM_FULL;
11825 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11826 new_wim_flags[idx] |= WIM_LIST;
11827 else
11828 return FAIL;
11829 p += i;
11830 if (*p == NUL)
11831 break;
11832 if (*p == ',')
11833 {
11834 if (idx == 3)
11835 return FAIL;
11836 ++idx;
11837 }
11838 }
11839
11840 /* fill remaining entries with last flag */
11841 while (idx < 3)
11842 {
11843 new_wim_flags[idx + 1] = new_wim_flags[idx];
11844 ++idx;
11845 }
11846
11847 /* only when there are no errors, wim_flags[] is changed */
11848 for (i = 0; i < 4; ++i)
11849 wim_flags[i] = new_wim_flags[i];
11850 return OK;
11851}
11852
11853/*
11854 * Check if backspacing over something is allowed.
11855 */
11856 int
11857can_bs(what)
11858 int what; /* BS_INDENT, BS_EOL or BS_START */
11859{
11860 switch (*p_bs)
11861 {
11862 case '2': return TRUE;
11863 case '1': return (what != BS_START);
11864 case '0': return FALSE;
11865 }
11866 return vim_strchr(p_bs, what) != NULL;
11867}
11868
11869/*
11870 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11871 * the file must be considered changed when the value is different.
11872 */
11873 void
11874save_file_ff(buf)
11875 buf_T *buf;
11876{
11877 buf->b_start_ffc = *buf->b_p_ff;
11878 buf->b_start_eol = buf->b_p_eol;
11879#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011880 buf->b_start_bomb = buf->b_p_bomb;
11881
Bram Moolenaar071d4272004-06-13 20:20:40 +000011882 /* Only use free/alloc when necessary, they take time. */
11883 if (buf->b_start_fenc == NULL
11884 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11885 {
11886 vim_free(buf->b_start_fenc);
11887 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11888 }
11889#endif
11890}
11891
11892/*
11893 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11894 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011895 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11896 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011897 * When "ignore_empty" is true don't consider a new, empty buffer to be
11898 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011899 */
11900 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011901file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011903 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011904{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011905 /* In a buffer that was never loaded the options are not valid. */
11906 if (buf->b_flags & BF_NEVERLOADED)
11907 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011908 if (ignore_empty
11909 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011910 && buf->b_ml.ml_line_count == 1
11911 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11912 return FALSE;
11913 if (buf->b_start_ffc != *buf->b_p_ff)
11914 return TRUE;
11915 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11916 return TRUE;
11917#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011918 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11919 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011920 if (buf->b_start_fenc == NULL)
11921 return (*buf->b_p_fenc != NUL);
11922 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11923#else
11924 return FALSE;
11925#endif
11926}
11927
11928/*
11929 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11930 */
11931 int
11932check_ff_value(p)
11933 char_u *p;
11934{
11935 return check_opt_strings(p, p_ff_values, FALSE);
11936}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011937
11938/*
11939 * Return the effective shiftwidth value for current buffer, using the
11940 * 'tabstop' value when 'shiftwidth' is zero.
11941 */
11942 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011943get_sw_value(buf)
11944 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011945{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011946 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011947}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011948
11949/*
11950 * Return the effective softtabstop value for the current buffer, using the
11951 * 'tabstop' value when 'softtabstop' is negative.
11952 */
11953 long
11954get_sts_value()
11955{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011956 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011957}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011958
11959/*
11960 * Check matchpairs option for "*initc".
11961 * If there is a match set "*initc" to the matching character and "*findc" to
11962 * the opposite character. Set "*backwards" to the direction.
11963 * When "switchit" is TRUE swap the direction.
11964 */
11965 void
11966find_mps_values(initc, findc, backwards, switchit)
11967 int *initc;
11968 int *findc;
11969 int *backwards;
11970 int switchit;
11971{
11972 char_u *ptr;
11973
11974 ptr = curbuf->b_p_mps;
11975 while (*ptr != NUL)
11976 {
11977#ifdef FEAT_MBYTE
11978 if (has_mbyte)
11979 {
11980 char_u *prev;
11981
11982 if (mb_ptr2char(ptr) == *initc)
11983 {
11984 if (switchit)
11985 {
11986 *findc = *initc;
11987 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11988 *backwards = TRUE;
11989 }
11990 else
11991 {
11992 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11993 *backwards = FALSE;
11994 }
11995 return;
11996 }
11997 prev = ptr;
11998 ptr += mb_ptr2len(ptr) + 1;
11999 if (mb_ptr2char(ptr) == *initc)
12000 {
12001 if (switchit)
12002 {
12003 *findc = *initc;
12004 *initc = mb_ptr2char(prev);
12005 *backwards = FALSE;
12006 }
12007 else
12008 {
12009 *findc = mb_ptr2char(prev);
12010 *backwards = TRUE;
12011 }
12012 return;
12013 }
12014 ptr += mb_ptr2len(ptr);
12015 }
12016 else
12017#endif
12018 {
12019 if (*ptr == *initc)
12020 {
12021 if (switchit)
12022 {
12023 *backwards = TRUE;
12024 *findc = *initc;
12025 *initc = ptr[2];
12026 }
12027 else
12028 {
12029 *backwards = FALSE;
12030 *findc = ptr[2];
12031 }
12032 return;
12033 }
12034 ptr += 2;
12035 if (*ptr == *initc)
12036 {
12037 if (switchit)
12038 {
12039 *backwards = FALSE;
12040 *findc = *initc;
12041 *initc = ptr[-2];
12042 }
12043 else
12044 {
12045 *backwards = TRUE;
12046 *findc = ptr[-2];
12047 }
12048 return;
12049 }
12050 ++ptr;
12051 }
12052 if (*ptr == ',')
12053 ++ptr;
12054 }
12055}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012056
12057#if defined(FEAT_LINEBREAK) || defined(PROTO)
12058/*
12059 * This is called when 'breakindentopt' is changed and when a window is
12060 * initialized.
12061 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012062 static int
12063briopt_check(wp)
12064 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012065{
12066 char_u *p;
12067 int bri_shift = 0;
12068 long bri_min = 20;
12069 int bri_sbr = FALSE;
12070
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012071 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012072 while (*p != NUL)
12073 {
12074 if (STRNCMP(p, "shift:", 6) == 0
12075 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12076 {
12077 p += 6;
12078 bri_shift = getdigits(&p);
12079 }
12080 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12081 {
12082 p += 4;
12083 bri_min = getdigits(&p);
12084 }
12085 else if (STRNCMP(p, "sbr", 3) == 0)
12086 {
12087 p += 3;
12088 bri_sbr = TRUE;
12089 }
12090 if (*p != ',' && *p != NUL)
12091 return FAIL;
12092 if (*p == ',')
12093 ++p;
12094 }
12095
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012096 wp->w_p_brishift = bri_shift;
12097 wp->w_p_brimin = bri_min;
12098 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012099
12100 return OK;
12101}
12102#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012103
12104/*
12105 * Get the local or global value of 'backupcopy'.
12106 */
12107 unsigned int
12108get_bkc_value(buf)
12109 buf_T *buf;
12110{
12111 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12112}