blob: 6b3b00caa335a8c7dd33dae47d8b397314e4d2a3 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
101#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
102#define PV_ET OPT_BUF(BV_ET)
103#ifdef FEAT_MBYTE
104# define PV_FENC OPT_BUF(BV_FENC)
105#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000106#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
107# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
108#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000109#ifdef FEAT_EVAL
110# define PV_FEX OPT_BUF(BV_FEX)
111#endif
112#define PV_FF OPT_BUF(BV_FF)
113#define PV_FLP OPT_BUF(BV_FLP)
114#define PV_FO OPT_BUF(BV_FO)
115#ifdef FEAT_AUTOCMD
116# define PV_FT OPT_BUF(BV_FT)
117#endif
118#define PV_IMI OPT_BUF(BV_IMI)
119#define PV_IMS OPT_BUF(BV_IMS)
120#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
121# define PV_INDE OPT_BUF(BV_INDE)
122# define PV_INDK OPT_BUF(BV_INDK)
123#endif
124#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
125# define PV_INEX OPT_BUF(BV_INEX)
126#endif
127#define PV_INF OPT_BUF(BV_INF)
128#define PV_ISK OPT_BUF(BV_ISK)
129#ifdef FEAT_CRYPT
130# define PV_KEY OPT_BUF(BV_KEY)
131#endif
132#ifdef FEAT_KEYMAP
133# define PV_KMAP OPT_BUF(BV_KMAP)
134#endif
135#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
136#ifdef FEAT_LISP
137# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100138# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000139#endif
140#define PV_MA OPT_BUF(BV_MA)
141#define PV_ML OPT_BUF(BV_ML)
142#define PV_MOD OPT_BUF(BV_MOD)
143#define PV_MPS OPT_BUF(BV_MPS)
144#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#ifdef FEAT_COMPL_FUNC
146# define PV_OFU OPT_BUF(BV_OFU)
147#endif
148#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
149#define PV_PI OPT_BUF(BV_PI)
150#ifdef FEAT_TEXTOBJ
151# define PV_QE OPT_BUF(BV_QE)
152#endif
153#define PV_RO OPT_BUF(BV_RO)
154#ifdef FEAT_SMARTINDENT
155# define PV_SI OPT_BUF(BV_SI)
156#endif
157#ifndef SHORT_FNAME
158# define PV_SN OPT_BUF(BV_SN)
159#endif
160#ifdef FEAT_SYN_HL
161# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000162# define PV_SYN OPT_BUF(BV_SYN)
163#endif
164#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000165# define PV_SPC OPT_BUF(BV_SPC)
166# define PV_SPF OPT_BUF(BV_SPF)
167# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168#endif
169#define PV_STS OPT_BUF(BV_STS)
170#ifdef FEAT_SEARCHPATH
171# define PV_SUA OPT_BUF(BV_SUA)
172#endif
173#define PV_SW OPT_BUF(BV_SW)
174#define PV_SWF OPT_BUF(BV_SWF)
175#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
176#define PV_TS OPT_BUF(BV_TS)
177#define PV_TW OPT_BUF(BV_TW)
178#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200179#ifdef FEAT_PERSISTENT_UNDO
180# define PV_UDF OPT_BUF(BV_UDF)
181#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000182#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000183
184/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000185 * Definition of the PV_ values for window-local options.
186 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188#define PV_LIST OPT_WIN(WV_LIST)
189#ifdef FEAT_ARABIC
190# define PV_ARAB OPT_WIN(WV_ARAB)
191#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200192#ifdef FEAT_LINEBREAK
193# define PV_BRI OPT_WIN(WV_BRI)
194# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000196#ifdef FEAT_DIFF
197# define PV_DIFF OPT_WIN(WV_DIFF)
198#endif
199#ifdef FEAT_FOLDING
200# define PV_FDC OPT_WIN(WV_FDC)
201# define PV_FEN OPT_WIN(WV_FEN)
202# define PV_FDI OPT_WIN(WV_FDI)
203# define PV_FDL OPT_WIN(WV_FDL)
204# define PV_FDM OPT_WIN(WV_FDM)
205# define PV_FML OPT_WIN(WV_FML)
206# define PV_FDN OPT_WIN(WV_FDN)
207# ifdef FEAT_EVAL
208# define PV_FDE OPT_WIN(WV_FDE)
209# define PV_FDT OPT_WIN(WV_FDT)
210# endif
211# define PV_FMR OPT_WIN(WV_FMR)
212#endif
213#ifdef FEAT_LINEBREAK
214# define PV_LBR OPT_WIN(WV_LBR)
215#endif
216#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200217#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000218#ifdef FEAT_LINEBREAK
219# define PV_NUW OPT_WIN(WV_NUW)
220#endif
221#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
222# define PV_PVW OPT_WIN(WV_PVW)
223#endif
224#ifdef FEAT_RIGHTLEFT
225# define PV_RL OPT_WIN(WV_RL)
226# define PV_RLC OPT_WIN(WV_RLC)
227#endif
228#ifdef FEAT_SCROLLBIND
229# define PV_SCBIND OPT_WIN(WV_SCBIND)
230#endif
231#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000232#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233# define PV_SPELL OPT_WIN(WV_SPELL)
234#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SYN_HL
236# define PV_CUC OPT_WIN(WV_CUC)
237# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200238# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000240#ifdef FEAT_STL_OPT
241# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
242#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100243#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_WINDOWS
245# define PV_WFH OPT_WIN(WV_WFH)
246#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000247#ifdef FEAT_VERTSPLIT
248# define PV_WFW OPT_WIN(WV_WFW)
249#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#ifdef FEAT_CURSORBIND
252# define PV_CRBIND OPT_WIN(WV_CRBIND)
253#endif
254#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200255# define PV_COCU OPT_WIN(WV_COCU)
256# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200257#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000258
259/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260typedef enum
261{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000262 PV_NONE = 0,
263 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264} idopt_T;
265
266/*
267 * Options local to a window have a value local to a buffer and global to all
268 * buffers. Indicate this by setting "var" to VAR_WIN.
269 */
270#define VAR_WIN ((char_u *)-1)
271
272/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000273 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000274 * Only to be used in option.c!
275 */
276static int p_ai;
277static int p_bin;
278#ifdef FEAT_MBYTE
279static int p_bomb;
280#endif
281#if defined(FEAT_QUICKFIX)
282static char_u *p_bh;
283static char_u *p_bt;
284#endif
285static int p_bl;
286static int p_ci;
287#ifdef FEAT_CINDENT
288static int p_cin;
289static char_u *p_cink;
290static char_u *p_cino;
291#endif
292#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
293static char_u *p_cinw;
294#endif
295#ifdef FEAT_COMMENTS
296static char_u *p_com;
297#endif
298#ifdef FEAT_FOLDING
299static char_u *p_cms;
300#endif
301#ifdef FEAT_INS_EXPAND
302static char_u *p_cpt;
303#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000304#ifdef FEAT_COMPL_FUNC
305static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000306static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static int p_eol;
309static int p_et;
310#ifdef FEAT_MBYTE
311static char_u *p_fenc;
312#endif
313static char_u *p_ff;
314static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000315static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316#ifdef FEAT_AUTOCMD
317static char_u *p_ft;
318#endif
319static long p_iminsert;
320static long p_imsearch;
321#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
322static char_u *p_inex;
323#endif
324#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
325static char_u *p_inde;
326static char_u *p_indk;
327#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000328#if defined(FEAT_EVAL)
329static char_u *p_fex;
330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000331static int p_inf;
332static char_u *p_isk;
333#ifdef FEAT_CRYPT
334static char_u *p_key;
335#endif
336#ifdef FEAT_LISP
337static int p_lisp;
338#endif
339static int p_ml;
340static int p_ma;
341static int p_mod;
342static char_u *p_mps;
343static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000344static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000345#ifdef FEAT_TEXTOBJ
346static char_u *p_qe;
347#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348static int p_ro;
349#ifdef FEAT_SMARTINDENT
350static int p_si;
351#endif
352#ifndef SHORT_FNAME
353static int p_sn;
354#endif
355static long p_sts;
356#if defined(FEAT_SEARCHPATH)
357static char_u *p_sua;
358#endif
359static long p_sw;
360static int p_swf;
361#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000362static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000364#endif
365#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000366static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000367static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000368static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369#endif
370static long p_ts;
371static long p_tw;
372static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200373#ifdef FEAT_PERSISTENT_UNDO
374static int p_udf;
375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376static long p_wm;
377#ifdef FEAT_KEYMAP
378static char_u *p_keymap;
379#endif
380
381/* Saved values for when 'bin' is set. */
382static int p_et_nobin;
383static int p_ml_nobin;
384static long p_tw_nobin;
385static long p_wm_nobin;
386
387/* Saved values for when 'paste' is set */
388static long p_tw_nopaste;
389static long p_wm_nopaste;
390static long p_sts_nopaste;
391static int p_ai_nopaste;
392
393struct vimoption
394{
395 char *fullname; /* full option name */
396 char *shortname; /* permissible abbreviation */
397 long_u flags; /* see below */
398 char_u *var; /* global option: pointer to variable;
399 * window-local option: VAR_WIN;
400 * buffer-local option: global value */
401 idopt_T indir; /* global option: PV_NONE;
402 * local option: indirect option index */
403 char_u *def_val[2]; /* default values for variable (vi and vim) */
404#ifdef FEAT_EVAL
405 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000406# define SCRIPTID_INIT , 0
407#else
408# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409#endif
410};
411
412#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
413#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
414
415/*
416 * Flags
417 */
418#define P_BOOL 0x01 /* the option is boolean */
419#define P_NUM 0x02 /* the option is numeric */
420#define P_STRING 0x04 /* the option is a string */
421#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000422 must use free_string_option() when
423 assigning new value. Not set if default is
424 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000425#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
426 never be used for local or hidden options! */
427#define P_NODEFAULT 0x40 /* don't set to default value */
428#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
429 use vim_free() when assigning new value */
430#define P_WAS_SET 0x100 /* option has been set/reset */
431#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
432#define P_VI_DEF 0x400 /* Use Vi default for Vim */
433#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
434
435 /* when option changed, what to display: */
436#define P_RSTAT 0x1000 /* redraw status lines */
437#define P_RWIN 0x2000 /* redraw current window */
438#define P_RBUF 0x4000 /* redraw current buffer */
439#define P_RALL 0x6000 /* redraw all windows */
440#define P_RCLR 0x7000 /* clear and redraw all */
441
442#define P_COMMA 0x8000 /* comma separated list */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200443#define P_NODUP 0x10000L /* don't allow duplicate strings */
444#define P_FLAGLIST 0x20000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445
Bram Moolenaar913077c2012-03-28 19:59:04 +0200446#define P_SECURE 0x40000L /* cannot change in modeline or secure mode */
447#define P_GETTEXT 0x80000L /* expand default value with _() */
448#define P_NOGLOB 0x100000L /* do not use local value for global vimrc */
449#define P_NFNAME 0x200000L /* only normal file name chars allowed */
450#define P_INSECURE 0x400000L /* option was set from a modeline */
451#define P_PRI_MKRC 0x800000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000452 side effects) */
Bram Moolenaar913077c2012-03-28 19:59:04 +0200453#define P_NO_ML 0x1000000L /* not allowed in modeline */
454#define P_CURSWANT 0x2000000L /* update curswant required; not needed when
455 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000457#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
458
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000459/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
460 * for the currency sign. */
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000461#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000462# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000463#else
464# define ISP_LATIN1 (char_u *)"@,161-255"
465#endif
466
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000467/* The 16 bit MS-DOS version is low on space, make the string as short as
468 * possible when compiling with few features. */
469#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
470 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200471 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100472# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000473#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100474# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000475#endif
476
Bram Moolenaar071d4272004-06-13 20:20:40 +0000477/*
478 * options[] is initialized here.
479 * The order of the options MUST be alphabetic for ":set all" and findoption().
480 * All option names MUST start with a lowercase letter (for findoption()).
481 * Exception: "t_" options are at the end.
482 * The options with a NULL variable are 'hidden': a set command for them is
483 * ignored and they are not printed.
484 */
485static struct vimoption
486#ifdef FEAT_GUI_W16
487 _far
488#endif
489 options[] =
490{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200491 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492#ifdef FEAT_RIGHTLEFT
493 (char_u *)&p_aleph, PV_NONE,
494#else
495 (char_u *)NULL, PV_NONE,
496#endif
497 {
498#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
499 (char_u *)128L,
500#else
501 (char_u *)224L,
502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000503 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
505#if defined(FEAT_GUI) && defined(MACOS_X)
506 (char_u *)&p_antialias, PV_NONE,
507 {(char_u *)FALSE, (char_u *)FALSE}
508#else
509 (char_u *)NULL, PV_NONE,
510 {(char_u *)FALSE, (char_u *)FALSE}
511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000512 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200513 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514#ifdef FEAT_ARABIC
515 (char_u *)VAR_WIN, PV_ARAB,
516#else
517 (char_u *)NULL, PV_NONE,
518#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000519 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
521#ifdef FEAT_ARABIC
522 (char_u *)&p_arshape, PV_NONE,
523#else
524 (char_u *)NULL, PV_NONE,
525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000526 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000527 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
528#ifdef FEAT_RIGHTLEFT
529 (char_u *)&p_ari, PV_NONE,
530#else
531 (char_u *)NULL, PV_NONE,
532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000534 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
535#ifdef FEAT_FKMAP
536 (char_u *)&p_altkeymap, PV_NONE,
537#else
538 (char_u *)NULL, PV_NONE,
539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000541 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
542#if defined(FEAT_MBYTE)
543 (char_u *)&p_ambw, PV_NONE,
544 {(char_u *)"single", (char_u *)0L}
545#else
546 (char_u *)NULL, PV_NONE,
547 {(char_u *)0L, (char_u *)0L}
548#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000549 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000550#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 {"autochdir", "acd", P_BOOL|P_VI_DEF,
552 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000553 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554#endif
555 {"autoindent", "ai", P_BOOL|P_VI_DEF,
556 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autoprint", "ap", P_BOOL|P_VI_DEF,
559 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000560 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000562 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564 {"autowrite", "aw", P_BOOL|P_VI_DEF,
565 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autowriteall","awa", P_BOOL|P_VI_DEF,
568 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
571 (char_u *)&p_bg, PV_NONE,
572 {
573#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
574 (char_u *)"dark",
575#else
576 (char_u *)"light",
577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_COMMA|P_NODUP,
580 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
583 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000584 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585 {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200586 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587#ifdef UNIX
588 {(char_u *)"yes", (char_u *)"auto"}
589#else
590 {(char_u *)"auto", (char_u *)"auto"}
591#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000592 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
594 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000595 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000596 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 (char_u *)&p_bex, PV_NONE,
598 {
599#ifdef VMS
600 (char_u *)"_",
601#else
602 (char_u *)"~",
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_COMMA,
606#ifdef FEAT_WILDIGN
607 (char_u *)&p_bsk, PV_NONE,
608 {(char_u *)"", (char_u *)0L}
609#else
610 (char_u *)NULL, PV_NONE,
611 {(char_u *)0L, (char_u *)0L}
612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000613 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614#ifdef FEAT_BEVAL
615 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
616 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
619 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000621# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000622 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000623 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000625# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626#endif
627 {"beautify", "bf", P_BOOL|P_VI_DEF,
628 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000629 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
631 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000632 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
634#ifdef MSDOS
635 (char_u *)&p_biosk, PV_NONE,
636#else
637 (char_u *)NULL, PV_NONE,
638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000639 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
641#ifdef FEAT_MBYTE
642 (char_u *)&p_bomb, PV_BOMB,
643#else
644 (char_u *)NULL, PV_NONE,
645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000647 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
648#ifdef FEAT_LINEBREAK
649 (char_u *)&p_breakat, PV_NONE,
650 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000655 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200656 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
657#ifdef FEAT_LINEBREAK
658 (char_u *)VAR_WIN, PV_BRI,
659 {(char_u *)FALSE, (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
664 SCRIPTID_INIT},
665 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_COMMA|P_NODUP,
666#ifdef FEAT_LINEBREAK
667 (char_u *)VAR_WIN, PV_BRIOPT,
668 {(char_u *)"", (char_u *)NULL}
669#else
670 (char_u *)NULL, PV_NONE,
671 {(char_u *)"", (char_u *)NULL}
672#endif
673 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
675#ifdef FEAT_BROWSE
676 (char_u *)&p_bsdir, PV_NONE,
677 {(char_u *)"last", (char_u *)0L}
678#else
679 (char_u *)NULL, PV_NONE,
680 {(char_u *)0L, (char_u *)0L}
681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000682 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
684#if defined(FEAT_QUICKFIX)
685 (char_u *)&p_bh, PV_BH,
686 {(char_u *)"", (char_u *)0L}
687#else
688 (char_u *)NULL, PV_NONE,
689 {(char_u *)0L, (char_u *)0L}
690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000691 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000692 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
693 (char_u *)&p_bl, PV_BL,
694 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
697#if defined(FEAT_QUICKFIX)
698 (char_u *)&p_bt, PV_BT,
699 {(char_u *)"", (char_u *)0L}
700#else
701 (char_u *)NULL, PV_NONE,
702 {(char_u *)0L, (char_u *)0L}
703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"casemap", "cmp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000706#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 (char_u *)&p_cmp, PV_NONE,
708 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000709#else
710 (char_u *)NULL, PV_NONE,
711 {(char_u *)0L, (char_u *)0L}
712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
715#ifdef FEAT_SEARCHPATH
716 (char_u *)&p_cdpath, PV_NONE,
717 {(char_u *)",,", (char_u *)0L}
718#else
719 (char_u *)NULL, PV_NONE,
720 {(char_u *)0L, (char_u *)0L}
721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"cedit", NULL, P_STRING,
724#ifdef FEAT_CMDWIN
725 (char_u *)&p_cedit, PV_NONE,
726 {(char_u *)"", (char_u *)CTRL_F_STR}
727#else
728 (char_u *)NULL, PV_NONE,
729 {(char_u *)0L, (char_u *)0L}
730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000731 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
733#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
734 (char_u *)&p_ccv, PV_NONE,
735 {(char_u *)"", (char_u *)0L}
736#else
737 (char_u *)NULL, PV_NONE,
738 {(char_u *)0L, (char_u *)0L}
739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000740 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
742#ifdef FEAT_CINDENT
743 (char_u *)&p_cin, PV_CIN,
744#else
745 (char_u *)NULL, PV_NONE,
746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000747 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
749#ifdef FEAT_CINDENT
750 (char_u *)&p_cink, PV_CINK,
751 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
752#else
753 (char_u *)NULL, PV_NONE,
754 {(char_u *)0L, (char_u *)0L}
755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000756 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
758#ifdef FEAT_CINDENT
759 (char_u *)&p_cino, PV_CINO,
760#else
761 (char_u *)NULL, PV_NONE,
762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000763 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
765#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
766 (char_u *)&p_cinw, PV_CINW,
767 {(char_u *)"if,else,while,do,for,switch",
768 (char_u *)0L}
769#else
770 (char_u *)NULL, PV_NONE,
771 {(char_u *)0L, (char_u *)0L}
772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000773 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774 {"clipboard", "cb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
775#ifdef FEAT_CLIPBOARD
776 (char_u *)&p_cb, PV_NONE,
777# ifdef FEAT_XCLIPBOARD
778 {(char_u *)"autoselect,exclude:cons\\|linux",
779 (char_u *)0L}
780# else
781 {(char_u *)"", (char_u *)0L}
782# endif
783#else
784 (char_u *)NULL, PV_NONE,
785 {(char_u *)"", (char_u *)0L}
786#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000787 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000788 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
789 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
792#ifdef FEAT_CMDWIN
793 (char_u *)&p_cwh, PV_NONE,
794#else
795 (char_u *)NULL, PV_NONE,
796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000797 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +0200798 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
799#ifdef FEAT_SYN_HL
800 (char_u *)VAR_WIN, PV_CC,
801#else
802 (char_u *)NULL, PV_NONE,
803#endif
804 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
806 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200808 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809#ifdef FEAT_COMMENTS
810 (char_u *)&p_com, PV_COM,
811 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
812 (char_u *)0L}
813#else
814 (char_u *)NULL, PV_NONE,
815 {(char_u *)0L, (char_u *)0L}
816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000817 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200818 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819#ifdef FEAT_FOLDING
820 (char_u *)&p_cms, PV_CMS,
821 {(char_u *)"/*%s*/", (char_u *)0L}
822#else
823 (char_u *)NULL, PV_NONE,
824 {(char_u *)0L, (char_u *)0L}
825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000826 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000827 /* P_PRI_MKRC isn't needed here, optval_default()
828 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000829 {"compatible", "cp", P_BOOL|P_RALL,
830 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000832 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
833#ifdef FEAT_INS_EXPAND
834 (char_u *)&p_cpt, PV_CPT,
835 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
836#else
837 (char_u *)NULL, PV_NONE,
838 {(char_u *)0L, (char_u *)0L}
839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000840 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200841 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200842#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200843 (char_u *)VAR_WIN, PV_COCU,
844 {(char_u *)"", (char_u *)NULL}
845#else
846 (char_u *)NULL, PV_NONE,
847 {(char_u *)NULL, (char_u *)0L}
848#endif
849 SCRIPTID_INIT},
850 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
851#ifdef FEAT_CONCEAL
852 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200853#else
854 (char_u *)NULL, PV_NONE,
855#endif
856 {(char_u *)0L, (char_u *)0L}
857 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000858 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
859#ifdef FEAT_COMPL_FUNC
860 (char_u *)&p_cfu, PV_CFU,
861 {(char_u *)"", (char_u *)0L}
862#else
863 (char_u *)NULL, PV_NONE,
864 {(char_u *)0L, (char_u *)0L}
865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 SCRIPTID_INIT},
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000867 {"completeopt", "cot", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
868#ifdef FEAT_INS_EXPAND
869 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000870 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000871#else
872 (char_u *)NULL, PV_NONE,
873 {(char_u *)0L, (char_u *)0L}
874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000875 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000876 {"confirm", "cf", P_BOOL|P_VI_DEF,
877#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
878 (char_u *)&p_confirm, PV_NONE,
879#else
880 (char_u *)NULL, PV_NONE,
881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000883 {"conskey", "consk",P_BOOL|P_VI_DEF,
884#ifdef MSDOS
885 (char_u *)&p_consk, PV_NONE,
886#else
887 (char_u *)NULL, PV_NONE,
888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000889 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
891 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000892 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
894 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000895 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
896 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200897 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200898#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200899 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200900 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200901#else
902 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200903 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200904#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200905 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
907#ifdef FEAT_CSCOPE
908 (char_u *)&p_cspc, PV_NONE,
909#else
910 (char_u *)NULL, PV_NONE,
911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000912 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
914#ifdef FEAT_CSCOPE
915 (char_u *)&p_csprg, PV_NONE,
916 {(char_u *)"cscope", (char_u *)0L}
917#else
918 (char_u *)NULL, PV_NONE,
919 {(char_u *)0L, (char_u *)0L}
920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000921 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
923#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
924 (char_u *)&p_csqf, PV_NONE,
925 {(char_u *)"", (char_u *)0L}
926#else
927 (char_u *)NULL, PV_NONE,
928 {(char_u *)0L, (char_u *)0L}
929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000930 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200931 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
932#ifdef FEAT_CSCOPE
933 (char_u *)&p_csre, PV_NONE,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_cst, PV_NONE,
941#else
942 (char_u *)NULL, PV_NONE,
943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000944 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csto, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
953#ifdef FEAT_CSCOPE
954 (char_u *)&p_csverbose, PV_NONE,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000958 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200959 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
960#ifdef FEAT_CURSORBIND
961 (char_u *)VAR_WIN, PV_CRBIND,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
965 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000966 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
967#ifdef FEAT_SYN_HL
968 (char_u *)VAR_WIN, PV_CUC,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000973 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
974#ifdef FEAT_SYN_HL
975 (char_u *)VAR_WIN, PV_CUL,
976#else
977 (char_u *)NULL, PV_NONE,
978#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980 {"debug", NULL, P_STRING|P_VI_DEF,
981 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200983 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000984#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000985 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000986 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000987#else
988 (char_u *)NULL, PV_NONE,
989 {(char_u *)NULL, (char_u *)0L}
990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000991 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
993#ifdef FEAT_MBYTE
994 (char_u *)&p_deco, PV_NONE,
995#else
996 (char_u *)NULL, PV_NONE,
997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000998 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
1000#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001001 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002#else
1003 (char_u *)NULL, PV_NONE,
1004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001005 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1007#ifdef FEAT_DIFF
1008 (char_u *)VAR_WIN, PV_DIFF,
1009#else
1010 (char_u *)NULL, PV_NONE,
1011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001012 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001013 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1015 (char_u *)&p_dex, PV_NONE,
1016 {(char_u *)"", (char_u *)0L}
1017#else
1018 (char_u *)NULL, PV_NONE,
1019 {(char_u *)0L, (char_u *)0L}
1020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001021 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_COMMA|P_NODUP,
1023#ifdef FEAT_DIFF
1024 (char_u *)&p_dip, PV_NONE,
1025 {(char_u *)"filler", (char_u *)NULL}
1026#else
1027 (char_u *)NULL, PV_NONE,
1028 {(char_u *)"", (char_u *)NULL}
1029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1032#ifdef FEAT_DIGRAPHS
1033 (char_u *)&p_dg, PV_NONE,
1034#else
1035 (char_u *)NULL, PV_NONE,
1036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
1039 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001040 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041 {"display", "dy", P_STRING|P_VI_DEF|P_COMMA|P_RALL|P_NODUP,
1042 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 {"eadirection", "ead", P_STRING|P_VI_DEF,
1045#ifdef FEAT_VERTSPLIT
1046 (char_u *)&p_ead, PV_NONE,
1047 {(char_u *)"both", (char_u *)0L}
1048#else
1049 (char_u *)NULL, PV_NONE,
1050 {(char_u *)NULL, (char_u *)0L}
1051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1054 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001055 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001056 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057#ifdef FEAT_MBYTE
1058 (char_u *)&p_enc, PV_NONE,
1059 {(char_u *)ENC_DFLT, (char_u *)0L}
1060#else
1061 (char_u *)NULL, PV_NONE,
1062 {(char_u *)0L, (char_u *)0L}
1063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1066 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1069 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001072 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001073 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1075 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001076 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1078#ifdef FEAT_QUICKFIX
1079 (char_u *)&p_ef, PV_NONE,
1080 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)NULL, (char_u *)0L}
1084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"errorformat", "efm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1087#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001088 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001089 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090#else
1091 (char_u *)NULL, PV_NONE,
1092 {(char_u *)NULL, (char_u *)0L}
1093#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"esckeys", "ek", P_BOOL|P_VIM,
1096 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001097 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 {"eventignore", "ei", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1099#ifdef FEAT_AUTOCMD
1100 (char_u *)&p_ei, PV_NONE,
1101#else
1102 (char_u *)NULL, PV_NONE,
1103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1106 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1109 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF|P_NO_MKRC,
1112#ifdef FEAT_MBYTE
1113 (char_u *)&p_fenc, PV_FENC,
1114 {(char_u *)"", (char_u *)0L}
1115#else
1116 (char_u *)NULL, PV_NONE,
1117 {(char_u *)0L, (char_u *)0L}
1118#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001119 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_COMMA,
1121#ifdef FEAT_MBYTE
1122 (char_u *)&p_fencs, PV_NONE,
1123 {(char_u *)"ucs-bom", (char_u *)0L}
1124#else
1125 (char_u *)NULL, PV_NONE,
1126 {(char_u *)0L, (char_u *)0L}
1127#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001128 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001129 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001131 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132 {"fileformats", "ffs", P_STRING|P_VIM|P_COMMA|P_NODUP,
1133 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001134 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1135 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001136 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1137 (char_u *)&p_fic, PV_NONE,
1138 {
1139#ifdef CASE_INSENSITIVE_FILENAME
1140 (char_u *)TRUE,
1141#else
1142 (char_u *)FALSE,
1143#endif
1144 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001145 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146#ifdef FEAT_AUTOCMD
1147 (char_u *)&p_ft, PV_FT,
1148 {(char_u *)"", (char_u *)0L}
1149#else
1150 (char_u *)NULL, PV_NONE,
1151 {(char_u *)0L, (char_u *)0L}
1152#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001153 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1155#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1156 (char_u *)&p_fcs, PV_NONE,
1157 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)"", (char_u *)0L}
1161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001163 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1164#ifdef FEAT_FKMAP
1165 (char_u *)&p_fkmap, PV_NONE,
1166#else
1167 (char_u *)NULL, PV_NONE,
1168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001170 {"flash", "fl", P_BOOL|P_VI_DEF,
1171 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001173#ifdef FEAT_FOLDING
1174 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
1175 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001176 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1178 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001179 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001180 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1181 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001182 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1184# ifdef FEAT_EVAL
1185 (char_u *)VAR_WIN, PV_FDE,
1186 {(char_u *)"0", (char_u *)NULL}
1187# else
1188 (char_u *)NULL, PV_NONE,
1189 {(char_u *)NULL, (char_u *)0L}
1190# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1193 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1196 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001198 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
1202 P_RWIN|P_COMMA|P_NODUP,
1203 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001204 {(char_u *)"{{{,}}}", (char_u *)NULL}
1205 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001206 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1207 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001208 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1210 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001211 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001212 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1213 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001214 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001215 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 (char_u *)&p_fdo, PV_NONE,
1217 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001218 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1220# ifdef FEAT_EVAL
1221 (char_u *)VAR_WIN, PV_FDT,
1222 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001223# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224 (char_u *)NULL, PV_NONE,
1225 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001226# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001227 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001229 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001230#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001231 (char_u *)&p_fex, PV_FEX,
1232 {(char_u *)"", (char_u *)0L}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)0L, (char_u *)0L}
1236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1239 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001240 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1241 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001242 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1243 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001244 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1245 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001246 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1247 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001248 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001249 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1250#ifdef HAVE_FSYNC
1251 (char_u *)&p_fs, PV_NONE,
1252 {(char_u *)TRUE, (char_u *)0L}
1253#else
1254 (char_u *)NULL, PV_NONE,
1255 {(char_u *)FALSE, (char_u *)0L}
1256#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001257 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1259 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001260 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 {"graphic", "gr", P_BOOL|P_VI_DEF,
1262 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1265#ifdef FEAT_QUICKFIX
1266 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001267 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268#else
1269 (char_u *)NULL, PV_NONE,
1270 {(char_u *)NULL, (char_u *)0L}
1271#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1274#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001275 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {
1277# ifdef WIN3264
1278 /* may be changed to "grep -n" in os_win32.c */
1279 (char_u *)"findstr /n",
1280# else
1281# ifdef UNIX
1282 /* Add an extra file name so that grep will always
1283 * insert a file name in the match line. */
1284 (char_u *)"grep -n $* /dev/null",
1285# else
1286# ifdef VMS
1287 (char_u *)"SEARCH/NUMBERS ",
1288# else
1289 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001290# endif
1291# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001292# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001293 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294#else
1295 (char_u *)NULL, PV_NONE,
1296 {(char_u *)NULL, (char_u *)0L}
1297#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001298 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1300#ifdef CURSOR_SHAPE
1301 (char_u *)&p_guicursor, PV_NONE,
1302 {
1303# ifdef FEAT_GUI
1304 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
1305# else /* MSDOS or Win32 console */
1306 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1307# endif
1308 (char_u *)0L}
1309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001313 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1315#ifdef FEAT_GUI
1316 (char_u *)&p_guifont, PV_NONE,
1317 {(char_u *)"", (char_u *)0L}
1318#else
1319 (char_u *)NULL, PV_NONE,
1320 {(char_u *)NULL, (char_u *)0L}
1321#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001322 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001323 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_COMMA,
1324#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1325 (char_u *)&p_guifontset, PV_NONE,
1326 {(char_u *)"", (char_u *)0L}
1327#else
1328 (char_u *)NULL, PV_NONE,
1329 {(char_u *)NULL, (char_u *)0L}
1330#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1333#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1334 (char_u *)&p_guifontwide, PV_NONE,
1335 {(char_u *)"", (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)NULL, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001342#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343 (char_u *)&p_ghr, PV_NONE,
1344#else
1345 (char_u *)NULL, PV_NONE,
1346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001347 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001349#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 (char_u *)&p_go, PV_NONE,
1351# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001352 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001354 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001355# endif
1356#else
1357 (char_u *)NULL, PV_NONE,
1358 {(char_u *)NULL, (char_u *)0L}
1359#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001360 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 {"guipty", NULL, P_BOOL|P_VI_DEF,
1362#if defined(FEAT_GUI)
1363 (char_u *)&p_guipty, PV_NONE,
1364#else
1365 (char_u *)NULL, PV_NONE,
1366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001368 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001369#if defined(FEAT_GUI_TABLINE)
1370 (char_u *)&p_gtl, PV_NONE,
1371 {(char_u *)"", (char_u *)0L}
1372#else
1373 (char_u *)NULL, PV_NONE,
1374 {(char_u *)NULL, (char_u *)0L}
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001377 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001378#if defined(FEAT_GUI_TABLINE)
1379 (char_u *)&p_gtt, PV_NONE,
1380 {(char_u *)"", (char_u *)0L}
1381#else
1382 (char_u *)NULL, PV_NONE,
1383 {(char_u *)NULL, (char_u *)0L}
1384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001385 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1387 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001388 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1390 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001391 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1392 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 {"helpheight", "hh", P_NUM|P_VI_DEF,
1394#ifdef FEAT_WINDOWS
1395 (char_u *)&p_hh, PV_NONE,
1396#else
1397 (char_u *)NULL, PV_NONE,
1398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001399 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001400 {"helplang", "hlg", P_STRING|P_VI_DEF|P_COMMA,
1401#ifdef FEAT_MULTI_LANG
1402 (char_u *)&p_hlg, PV_NONE,
1403 {(char_u *)"", (char_u *)0L}
1404#else
1405 (char_u *)NULL, PV_NONE,
1406 {(char_u *)0L, (char_u *)0L}
1407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001409 {"hidden", "hid", P_BOOL|P_VI_DEF,
1410 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_COMMA|P_NODUP,
1413 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1415 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416 {"history", "hi", P_NUM|P_VIM,
1417 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001418 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1420#ifdef FEAT_RIGHTLEFT
1421 (char_u *)&p_hkmap, PV_NONE,
1422#else
1423 (char_u *)NULL, PV_NONE,
1424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1427#ifdef FEAT_RIGHTLEFT
1428 (char_u *)&p_hkmapp, PV_NONE,
1429#else
1430 (char_u *)NULL, PV_NONE,
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1434 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 {"icon", NULL, P_BOOL|P_VI_DEF,
1437#ifdef FEAT_TITLE
1438 (char_u *)&p_icon, PV_NONE,
1439#else
1440 (char_u *)NULL, PV_NONE,
1441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001442 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001443 {"iconstring", NULL, P_STRING|P_VI_DEF,
1444#ifdef FEAT_TITLE
1445 (char_u *)&p_iconstring, PV_NONE,
1446#else
1447 (char_u *)NULL, PV_NONE,
1448#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001449 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1451 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001453 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1454# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1455 (char_u *)&p_imaf, PV_NONE,
1456 {(char_u *)"", (char_u *)NULL}
1457# else
1458 (char_u *)NULL, PV_NONE,
1459 {(char_u *)NULL, (char_u *)0L}
1460# endif
1461 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001463#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 (char_u *)&p_imak, PV_NONE,
1465#else
1466 (char_u *)NULL, PV_NONE,
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1470#ifdef USE_IM_CONTROL
1471 (char_u *)&p_imcmdline, PV_NONE,
1472#else
1473 (char_u *)NULL, PV_NONE,
1474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001475 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1477#ifdef USE_IM_CONTROL
1478 (char_u *)&p_imdisable, PV_NONE,
1479#else
1480 (char_u *)NULL, PV_NONE,
1481#endif
1482#ifdef __sgi
1483 {(char_u *)TRUE, (char_u *)0L}
1484#else
1485 {(char_u *)FALSE, (char_u *)0L}
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"iminsert", "imi", P_NUM|P_VI_DEF,
1489 (char_u *)&p_iminsert, PV_IMI,
1490#ifdef B_IMODE_IM
1491 {(char_u *)B_IMODE_IM, (char_u *)0L}
1492#else
1493 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1494#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001495 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496 {"imsearch", "ims", P_NUM|P_VI_DEF,
1497 (char_u *)&p_imsearch, PV_IMS,
1498#ifdef B_IMODE_IM
1499 {(char_u *)B_IMODE_IM, (char_u *)0L}
1500#else
1501 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001503 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001504 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001505# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1506 (char_u *)&p_imsf, PV_NONE,
1507 {(char_u *)"", (char_u *)NULL}
1508# else
1509 (char_u *)NULL, PV_NONE,
1510 {(char_u *)NULL, (char_u *)0L}
1511# endif
1512 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1514#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001515 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1517#else
1518 (char_u *)NULL, PV_NONE,
1519 {(char_u *)0L, (char_u *)0L}
1520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1523#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1524 (char_u *)&p_inex, PV_INEX,
1525 {(char_u *)"", (char_u *)0L}
1526#else
1527 (char_u *)NULL, PV_NONE,
1528 {(char_u *)0L, (char_u *)0L}
1529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001530 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1532 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001534 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1535#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1536 (char_u *)&p_inde, PV_INDE,
1537 {(char_u *)"", (char_u *)0L}
1538#else
1539 (char_u *)NULL, PV_NONE,
1540 {(char_u *)0L, (char_u *)0L}
1541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1544#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1545 (char_u *)&p_indk, PV_INDK,
1546 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1547#else
1548 (char_u *)NULL, PV_NONE,
1549 {(char_u *)0L, (char_u *)0L}
1550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001551 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 {"infercase", "inf", P_BOOL|P_VI_DEF,
1553 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1556 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001557 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1559 (char_u *)&p_isf, PV_NONE,
1560 {
1561#ifdef BACKSLASH_IN_FILENAME
1562 /* Excluded are: & and ^ are special in cmd.exe
1563 * ( and ) are used in text separating fnames */
1564 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1565#else
1566# ifdef AMIGA
1567 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1568# else
1569# ifdef VMS
1570 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1571# else /* UNIX et al. */
1572# ifdef EBCDIC
1573 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1574# else
1575 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1576# endif
1577# endif
1578# endif
1579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001580 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1582 (char_u *)&p_isi, PV_NONE,
1583 {
1584#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1585 (char_u *)"@,48-57,_,128-167,224-235",
1586#else
1587# ifdef EBCDIC
1588 /* TODO: EBCDIC Check this! @ == isalpha()*/
1589 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1590 "112-120,128,140-142,156,158,172,"
1591 "174,186,191,203-207,219-225,235-239,"
1592 "251-254",
1593# else
1594 (char_u *)"@,48-57,_,192-255",
1595# endif
1596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001597 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1599 (char_u *)&p_isk, PV_ISK,
1600 {
1601#ifdef EBCDIC
1602 (char_u *)"@,240-249,_",
1603 /* TODO: EBCDIC Check this! @ == isalpha()*/
1604 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1605 "112-120,128,140-142,156,158,172,"
1606 "174,186,191,203-207,219-225,235-239,"
1607 "251-254",
1608#else
1609 (char_u *)"@,48-57,_",
1610# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1611 (char_u *)"@,48-57,_,128-167,224-235"
1612# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001613 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614# endif
1615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001616 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1618 (char_u *)&p_isp, PV_NONE,
1619 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001620#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1621 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001622 || defined(VMS)
1623 (char_u *)"@,~-255",
1624#else
1625# ifdef EBCDIC
1626 /* all chars above 63 are printable */
1627 (char_u *)"63-255",
1628# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001629 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630# endif
1631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001632 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1634 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001635 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1637#ifdef FEAT_CRYPT
1638 (char_u *)&p_key, PV_KEY,
1639 {(char_u *)"", (char_u *)0L}
1640#else
1641 (char_u *)NULL, PV_NONE,
1642 {(char_u *)0L, (char_u *)0L}
1643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001644 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001645 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646#ifdef FEAT_KEYMAP
1647 (char_u *)&p_keymap, PV_KMAP,
1648 {(char_u *)"", (char_u *)0L}
1649#else
1650 (char_u *)NULL, PV_NONE,
1651 {(char_u *)"", (char_u *)0L}
1652#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001653 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 {"keymodel", "km", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001656 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001658 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {
1660#if defined(MSDOS) || defined(MSWIN)
1661 (char_u *)":help",
1662#else
1663#ifdef VMS
1664 (char_u *)"help",
1665#else
1666# if defined(OS2)
1667 (char_u *)"view /",
1668# else
1669# ifdef USEMAN_S
1670 (char_u *)"man -s",
1671# else
1672 (char_u *)"man",
1673# endif
1674# endif
1675#endif
1676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001677 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaared7547d2014-05-13 12:17:15 +02001678 {"langmap", "lmap", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679#ifdef FEAT_LANGMAP
1680 (char_u *)&p_langmap, PV_NONE,
1681 {(char_u *)"", /* unmatched } */
1682#else
1683 (char_u *)NULL, PV_NONE,
1684 {(char_u *)NULL,
1685#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001686 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001687 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1689 (char_u *)&p_lm, PV_NONE,
1690#else
1691 (char_u *)NULL, PV_NONE,
1692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001693 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001694 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1695#ifdef FEAT_LANGMAP
1696 (char_u *)&p_lnr, PV_NONE,
1697#else
1698 (char_u *)NULL, PV_NONE,
1699#endif
1700 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1702#ifdef FEAT_WINDOWS
1703 (char_u *)&p_ls, PV_NONE,
1704#else
1705 (char_u *)NULL, PV_NONE,
1706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001707 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1709 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1712#ifdef FEAT_LINEBREAK
1713 (char_u *)VAR_WIN, PV_LBR,
1714#else
1715 (char_u *)NULL, PV_NONE,
1716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001717 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1719 (char_u *)&Rows, PV_NONE,
1720 {
1721#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1722 (char_u *)25L,
1723#else
1724 (char_u *)24L,
1725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001726 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1728#ifdef FEAT_GUI
1729 (char_u *)&p_linespace, PV_NONE,
1730#else
1731 (char_u *)NULL, PV_NONE,
1732#endif
1733#ifdef FEAT_GUI_W32
1734 {(char_u *)1L, (char_u *)0L}
1735#else
1736 {(char_u *)0L, (char_u *)0L}
1737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001738 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"lisp", NULL, P_BOOL|P_VI_DEF,
1740#ifdef FEAT_LISP
1741 (char_u *)&p_lisp, PV_LISP,
1742#else
1743 (char_u *)NULL, PV_NONE,
1744#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"lispwords", "lw", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1747#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001748 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1750#else
1751 (char_u *)NULL, PV_NONE,
1752 {(char_u *)"", (char_u *)0L}
1753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1756 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001757 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1759 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1762 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001763 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001764#ifdef FEAT_GUI_MAC
1765 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1766 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001767 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001768#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"magic", NULL, P_BOOL|P_VI_DEF,
1770 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001772 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773#ifdef FEAT_QUICKFIX
1774 (char_u *)&p_mef, PV_NONE,
1775 {(char_u *)"", (char_u *)0L}
1776#else
1777 (char_u *)NULL, PV_NONE,
1778 {(char_u *)NULL, (char_u *)0L}
1779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1782#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001783 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784# ifdef VMS
1785 {(char_u *)"MMS", (char_u *)0L}
1786# else
1787 {(char_u *)"make", (char_u *)0L}
1788# endif
1789#else
1790 (char_u *)NULL, PV_NONE,
1791 {(char_u *)NULL, (char_u *)0L}
1792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001793 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1795 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001796 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1797 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001798 {"matchtime", "mat", P_NUM|P_VI_DEF,
1799 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001800 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001801 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001802#ifdef FEAT_MBYTE
1803 (char_u *)&p_mco, PV_NONE,
1804#else
1805 (char_u *)NULL, PV_NONE,
1806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001807 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1809#ifdef FEAT_EVAL
1810 (char_u *)&p_mfd, PV_NONE,
1811#else
1812 (char_u *)NULL, PV_NONE,
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1816 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"maxmem", "mm", P_NUM|P_VI_DEF,
1819 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1821 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001822 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1823 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1826 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1828 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {"menuitems", "mis", P_NUM|P_VI_DEF,
1830#ifdef FEAT_MENU
1831 (char_u *)&p_mis, PV_NONE,
1832#else
1833 (char_u *)NULL, PV_NONE,
1834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001835 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 {"mesg", NULL, P_BOOL|P_VI_DEF,
1837 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001839 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001840#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001841 (char_u *)&p_msm, PV_NONE,
1842 {(char_u *)"460000,2000,500", (char_u *)0L}
1843#else
1844 (char_u *)NULL, PV_NONE,
1845 {(char_u *)0L, (char_u *)0L}
1846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 {"modeline", "ml", P_BOOL|P_VIM,
1849 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"modelines", "mls", P_NUM|P_VI_DEF,
1852 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001853 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001854 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1855 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001856 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1858 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"more", NULL, P_BOOL|P_VIM,
1861 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1864 (char_u *)&p_mouse, PV_NONE,
1865 {
1866#if defined(MSDOS) || defined(WIN3264)
1867 (char_u *)"a",
1868#else
1869 (char_u *)"",
1870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1873#ifdef FEAT_GUI
1874 (char_u *)&p_mousef, PV_NONE,
1875#else
1876 (char_u *)NULL, PV_NONE,
1877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001878 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1880#ifdef FEAT_GUI
1881 (char_u *)&p_mh, PV_NONE,
1882#else
1883 (char_u *)NULL, PV_NONE,
1884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001885 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1887 (char_u *)&p_mousem, PV_NONE,
1888 {
1889#if defined(MSDOS) || defined(MSWIN)
1890 (char_u *)"popup",
1891#else
1892# if defined(MACOS)
1893 (char_u *)"popup_setpos",
1894# else
1895 (char_u *)"extend",
1896# endif
1897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1900#ifdef FEAT_MOUSESHAPE
1901 (char_u *)&p_mouseshape, PV_NONE,
1902 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1903#else
1904 (char_u *)NULL, PV_NONE,
1905 {(char_u *)NULL, (char_u *)0L}
1906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001907 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001908 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1909 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001910 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001911 {"mzquantum", "mzq", P_NUM,
1912#ifdef FEAT_MZSCHEME
1913 (char_u *)&p_mzq, PV_NONE,
1914#else
1915 (char_u *)NULL, PV_NONE,
1916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001917 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"novice", NULL, P_BOOL|P_VI_DEF,
1919 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
1922 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001923 {(char_u *)"octal,hex", (char_u *)0L}
1924 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1926 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001928 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1929#ifdef FEAT_LINEBREAK
1930 (char_u *)VAR_WIN, PV_NUW,
1931#else
1932 (char_u *)NULL, PV_NONE,
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001935 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001936#ifdef FEAT_COMPL_FUNC
1937 (char_u *)&p_ofu, PV_OFU,
1938 {(char_u *)"", (char_u *)0L}
1939#else
1940 (char_u *)NULL, PV_NONE,
1941 {(char_u *)0L, (char_u *)0L}
1942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 {"open", NULL, P_BOOL|P_VI_DEF,
1945 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001947 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1948#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1949 (char_u *)&p_odev, PV_NONE,
1950#else
1951 (char_u *)NULL, PV_NONE,
1952#endif
1953 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001955 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1956 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001957 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 {"optimize", "opt", P_BOOL|P_VI_DEF,
1959 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001960 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001963 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 {"paragraphs", "para", P_STRING|P_VI_DEF,
1965 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001966 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001968 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001969 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001971 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1972 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001973 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001974 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1975#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1976 (char_u *)&p_pex, PV_NONE,
1977 {(char_u *)"", (char_u *)0L}
1978#else
1979 (char_u *)NULL, PV_NONE,
1980 {(char_u *)0L, (char_u *)0L}
1981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001983 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001985 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001987 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {
1989#if defined AMIGA || defined MSDOS || defined MSWIN
1990 (char_u *)".,,",
1991#else
1992# if defined(__EMX__)
1993 (char_u *)".,/emx/include,,",
1994# else /* Unix, probably */
1995 (char_u *)".,/usr/include,,",
1996# endif
1997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2000 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002001 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002002 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2004 (char_u *)&p_pvh, PV_NONE,
2005#else
2006 (char_u *)NULL, PV_NONE,
2007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002008 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2010#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2011 (char_u *)VAR_WIN, PV_PVW,
2012#else
2013 (char_u *)NULL, PV_NONE,
2014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002016 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017#ifdef FEAT_PRINTER
2018 (char_u *)&p_pdev, PV_NONE,
2019 {(char_u *)"", (char_u *)0L}
2020#else
2021 (char_u *)NULL, PV_NONE,
2022 {(char_u *)NULL, (char_u *)0L}
2023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002024 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 {"printencoding", "penc", P_STRING|P_VI_DEF,
2026#ifdef FEAT_POSTSCRIPT
2027 (char_u *)&p_penc, PV_NONE,
2028 {(char_u *)"", (char_u *)0L}
2029#else
2030 (char_u *)NULL, PV_NONE,
2031 {(char_u *)NULL, (char_u *)0L}
2032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2035#ifdef FEAT_POSTSCRIPT
2036 (char_u *)&p_pexpr, PV_NONE,
2037 {(char_u *)"", (char_u *)0L}
2038#else
2039 (char_u *)NULL, PV_NONE,
2040 {(char_u *)NULL, (char_u *)0L}
2041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 {"printfont", "pfn", P_STRING|P_VI_DEF,
2044#ifdef FEAT_PRINTER
2045 (char_u *)&p_pfn, PV_NONE,
2046 {
2047# ifdef MSWIN
2048 (char_u *)"Courier_New:h10",
2049# else
2050 (char_u *)"courier",
2051# endif
2052 (char_u *)0L}
2053#else
2054 (char_u *)NULL, PV_NONE,
2055 {(char_u *)NULL, (char_u *)0L}
2056#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002057 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2059#ifdef FEAT_PRINTER
2060 (char_u *)&p_header, PV_NONE,
2061 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2062#else
2063 (char_u *)NULL, PV_NONE,
2064 {(char_u *)NULL, (char_u *)0L}
2065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002066 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002067 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2068#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2069 (char_u *)&p_pmcs, PV_NONE,
2070 {(char_u *)"", (char_u *)0L}
2071#else
2072 (char_u *)NULL, PV_NONE,
2073 {(char_u *)NULL, (char_u *)0L}
2074#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002075 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002076 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2077#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2078 (char_u *)&p_pmfn, PV_NONE,
2079 {(char_u *)"", (char_u *)0L}
2080#else
2081 (char_u *)NULL, PV_NONE,
2082 {(char_u *)NULL, (char_u *)0L}
2083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085 {"printoptions", "popt", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2086#ifdef FEAT_PRINTER
2087 (char_u *)&p_popt, PV_NONE,
2088 {(char_u *)"", (char_u *)0L}
2089#else
2090 (char_u *)NULL, PV_NONE,
2091 {(char_u *)NULL, (char_u *)0L}
2092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002095 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002097 {"pumheight", "ph", P_NUM|P_VI_DEF,
2098#ifdef FEAT_INS_EXPAND
2099 (char_u *)&p_ph, PV_NONE,
2100#else
2101 (char_u *)NULL, PV_NONE,
2102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002103 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002104 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2105#ifdef FEAT_TEXTOBJ
2106 (char_u *)&p_qe, PV_QE,
2107 {(char_u *)"\\", (char_u *)0L}
2108#else
2109 (char_u *)NULL, PV_NONE,
2110 {(char_u *)NULL, (char_u *)0L}
2111#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2114 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002115 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 {"redraw", NULL, P_BOOL|P_VI_DEF,
2117 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002118 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002119 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2120#ifdef FEAT_RELTIME
2121 (char_u *)&p_rdt, PV_NONE,
2122#else
2123 (char_u *)NULL, PV_NONE,
2124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002126 {"regexpengine", "re", P_NUM|P_VI_DEF,
2127 (char_u *)&p_re, PV_NONE,
2128 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002129 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2130 (char_u *)VAR_WIN, PV_RNU,
2131 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 {"remap", NULL, P_BOOL|P_VI_DEF,
2133 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002135 {"renderoptions", "rop", P_STRING|P_COMMA|P_RCLR|P_VI_DEF,
2136#ifdef FEAT_RENDER_OPTIONS
2137 (char_u *)&p_rop, PV_NONE,
2138 {(char_u *)"", (char_u *)0L}
2139#else
2140 (char_u *)NULL, PV_NONE,
2141 {(char_u *)NULL, (char_u *)0L}
2142#endif
2143 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002144 {"report", NULL, P_NUM|P_VI_DEF,
2145 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002146 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2148#ifdef WIN3264
2149 (char_u *)&p_rs, PV_NONE,
2150#else
2151 (char_u *)NULL, PV_NONE,
2152#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002153 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2155#ifdef FEAT_RIGHTLEFT
2156 (char_u *)&p_ri, PV_NONE,
2157#else
2158 (char_u *)NULL, PV_NONE,
2159#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2162#ifdef FEAT_RIGHTLEFT
2163 (char_u *)VAR_WIN, PV_RL,
2164#else
2165 (char_u *)NULL, PV_NONE,
2166#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002167 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002168 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2169#ifdef FEAT_RIGHTLEFT
2170 (char_u *)VAR_WIN, PV_RLC,
2171 {(char_u *)"search", (char_u *)NULL}
2172#else
2173 (char_u *)NULL, PV_NONE,
2174 {(char_u *)NULL, (char_u *)0L}
2175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002176 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2178#ifdef FEAT_CMDL_INFO
2179 (char_u *)&p_ru, PV_NONE,
2180#else
2181 (char_u *)NULL, PV_NONE,
2182#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002183 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002184 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2185#ifdef FEAT_STL_OPT
2186 (char_u *)&p_ruf, PV_NONE,
2187#else
2188 (char_u *)NULL, PV_NONE,
2189#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002190 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_COMMA|P_NODUP|P_SECURE,
2192 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2194 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002195 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2196 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002197 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002198 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2199#ifdef FEAT_SCROLLBIND
2200 (char_u *)VAR_WIN, PV_SCBIND,
2201#else
2202 (char_u *)NULL, PV_NONE,
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2206 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2209 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002210 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2212#ifdef FEAT_SCROLLBIND
2213 (char_u *)&p_sbo, PV_NONE,
2214 {(char_u *)"ver,jump", (char_u *)0L}
2215#else
2216 (char_u *)NULL, PV_NONE,
2217 {(char_u *)0L, (char_u *)0L}
2218#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002219 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002220 {"sections", "sect", P_STRING|P_VI_DEF,
2221 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002222 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2223 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2225 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002226 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002227 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002228 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002229 {(char_u *)"inclusive", (char_u *)0L}
2230 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 {"selectmode", "slm", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2235#ifdef FEAT_SESSION
2236 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002237 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 (char_u *)0L}
2239#else
2240 (char_u *)NULL, PV_NONE,
2241 {(char_u *)0L, (char_u *)0L}
2242#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2245 (char_u *)&p_sh, PV_NONE,
2246 {
2247#ifdef VMS
2248 (char_u *)"-",
2249#else
2250# if defined(MSDOS)
2251 (char_u *)"command",
2252# else
2253# if defined(WIN16)
2254 (char_u *)"command.com",
2255# else
2256# if defined(WIN3264)
2257 (char_u *)"", /* set in set_init_1() */
2258# else
2259# if defined(OS2)
2260 (char_u *)"cmd.exe",
2261# else
2262# if defined(ARCHIE)
2263 (char_u *)"gos",
2264# else
2265 (char_u *)"sh",
2266# endif
2267# endif
2268# endif
2269# endif
2270# endif
2271#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2274 (char_u *)&p_shcf, PV_NONE,
2275 {
2276#if defined(MSDOS) || defined(MSWIN)
2277 (char_u *)"/c",
2278#else
2279# if defined(OS2)
2280 (char_u *)"/c",
2281# else
2282 (char_u *)"-c",
2283# endif
2284#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002285 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2287#ifdef FEAT_QUICKFIX
2288 (char_u *)&p_sp, PV_NONE,
2289 {
2290#if defined(UNIX) || defined(OS2)
2291# ifdef ARCHIE
2292 (char_u *)"2>",
2293# else
2294 (char_u *)"| tee",
2295# endif
2296#else
2297 (char_u *)">",
2298#endif
2299 (char_u *)0L}
2300#else
2301 (char_u *)NULL, PV_NONE,
2302 {(char_u *)0L, (char_u *)0L}
2303#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2306 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002307 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002308 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2309 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002310 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2312#ifdef BACKSLASH_IN_FILENAME
2313 (char_u *)&p_ssl, PV_NONE,
2314#else
2315 (char_u *)NULL, PV_NONE,
2316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002318 {"shelltemp", "stmp", P_BOOL,
2319 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002320 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"shelltype", "st", P_NUM|P_VI_DEF,
2322#ifdef AMIGA
2323 (char_u *)&p_st, PV_NONE,
2324#else
2325 (char_u *)NULL, PV_NONE,
2326#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002327 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002328 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2329 (char_u *)&p_sxq, PV_NONE,
2330 {
2331#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2332 (char_u *)"\"",
2333#else
2334 (char_u *)"",
2335#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002337 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2338 (char_u *)&p_sxe, PV_NONE,
2339 {
2340#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2341 (char_u *)"\"&|<>()@^",
2342#else
2343 (char_u *)"",
2344#endif
2345 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2347 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2350 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002352 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2353 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)"", (char_u *)"filnxtToO"}
2355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"shortname", "sn", P_BOOL|P_VI_DEF,
2357#ifdef SHORT_FNAME
2358 (char_u *)NULL, PV_NONE,
2359#else
2360 (char_u *)&p_sn, PV_SN,
2361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2364#ifdef FEAT_LINEBREAK
2365 (char_u *)&p_sbr, PV_NONE,
2366#else
2367 (char_u *)NULL, PV_NONE,
2368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 {"showcmd", "sc", P_BOOL|P_VIM,
2371#ifdef FEAT_CMDL_INFO
2372 (char_u *)&p_sc, PV_NONE,
2373#else
2374 (char_u *)NULL, PV_NONE,
2375#endif
2376 {(char_u *)FALSE,
2377#ifdef UNIX
2378 (char_u *)FALSE
2379#else
2380 (char_u *)TRUE
2381#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002382 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2384 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002385 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2387 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"showmode", "smd", P_BOOL|P_VIM,
2390 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002392 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2393#ifdef FEAT_WINDOWS
2394 (char_u *)&p_stal, PV_NONE,
2395#else
2396 (char_u *)NULL, PV_NONE,
2397#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002398 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2400 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002401 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2403 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2406 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2409 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2412#ifdef FEAT_SMARTINDENT
2413 (char_u *)&p_si, PV_SI,
2414#else
2415 (char_u *)NULL, PV_NONE,
2416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002417 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2419 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002420 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2422 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2425 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002426 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002427 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002428#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002429 (char_u *)VAR_WIN, PV_SPELL,
2430#else
2431 (char_u *)NULL, PV_NONE,
2432#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002433 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002434 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002435#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002436 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002437 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002438#else
2439 (char_u *)NULL, PV_NONE,
2440 {(char_u *)0L, (char_u *)0L}
2441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 SCRIPTID_INIT},
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002443 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002444#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002445 (char_u *)&p_spf, PV_SPF,
2446 {(char_u *)"", (char_u *)0L}
2447#else
2448 (char_u *)NULL, PV_NONE,
2449 {(char_u *)0L, (char_u *)0L}
2450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 SCRIPTID_INIT},
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00002452 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002453#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002454 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002455 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002456#else
2457 (char_u *)NULL, PV_NONE,
2458 {(char_u *)0L, (char_u *)0L}
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 SCRIPTID_INIT},
Bram Moolenaar28e4c8d2006-05-09 16:15:42 +00002461 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_COMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002462#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002463 (char_u *)&p_sps, PV_NONE,
2464 {(char_u *)"best", (char_u *)0L}
2465#else
2466 (char_u *)NULL, PV_NONE,
2467 {(char_u *)0L, (char_u *)0L}
2468#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2471#ifdef FEAT_WINDOWS
2472 (char_u *)&p_sb, PV_NONE,
2473#else
2474 (char_u *)NULL, PV_NONE,
2475#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"splitright", "spr", P_BOOL|P_VI_DEF,
2478#ifdef FEAT_VERTSPLIT
2479 (char_u *)&p_spr, PV_NONE,
2480#else
2481 (char_u *)NULL, PV_NONE,
2482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2485 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2488#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002489 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490#else
2491 (char_u *)NULL, PV_NONE,
2492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"suffixes", "su", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2495 (char_u *)&p_su, PV_NONE,
2496 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002499#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 (char_u *)&p_sua, PV_SUA,
2501 {(char_u *)"", (char_u *)0L}
2502#else
2503 (char_u *)NULL, PV_NONE,
2504 {(char_u *)0L, (char_u *)0L}
2505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002506 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2508 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002509 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"swapsync", "sws", P_STRING|P_VI_DEF,
2511 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2514 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002516 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2517#ifdef FEAT_SYN_HL
2518 (char_u *)&p_smc, PV_SMC,
2519 {(char_u *)3000L, (char_u *)0L}
2520#else
2521 (char_u *)NULL, PV_NONE,
2522 {(char_u *)0L, (char_u *)0L}
2523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002524 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002525 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526#ifdef FEAT_SYN_HL
2527 (char_u *)&p_syn, PV_SYN,
2528 {(char_u *)"", (char_u *)0L}
2529#else
2530 (char_u *)NULL, PV_NONE,
2531 {(char_u *)0L, (char_u *)0L}
2532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002534 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2535#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002536 (char_u *)&p_tal, PV_NONE,
2537#else
2538 (char_u *)NULL, PV_NONE,
2539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002541 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2542#ifdef FEAT_WINDOWS
2543 (char_u *)&p_tpm, PV_NONE,
2544#else
2545 (char_u *)NULL, PV_NONE,
2546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2549 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2552 (char_u *)&p_tbs, PV_NONE,
2553#ifdef VMS /* binary searching doesn't appear to work on VMS */
2554 {(char_u *)0L, (char_u *)0L}
2555#else
2556 {(char_u *)TRUE, (char_u *)0L}
2557#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {"taglength", "tl", P_NUM|P_VI_DEF,
2560 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 {"tagrelative", "tr", P_BOOL|P_VIM,
2563 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002566 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {
2568#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2569 (char_u *)"./tags,./TAGS,tags,TAGS",
2570#else
2571 (char_u *)"./tags,tags",
2572#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002573 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2575 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2578 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2581#ifdef FEAT_ARABIC
2582 (char_u *)&p_tbidi, PV_NONE,
2583#else
2584 (char_u *)NULL, PV_NONE,
2585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2588#ifdef FEAT_MBYTE
2589 (char_u *)&p_tenc, PV_NONE,
2590 {(char_u *)"", (char_u *)0L}
2591#else
2592 (char_u *)NULL, PV_NONE,
2593 {(char_u *)0L, (char_u *)0L}
2594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002595 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596 {"terse", NULL, P_BOOL|P_VI_DEF,
2597 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"textauto", "ta", P_BOOL|P_VIM,
2600 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002601 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2602 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2604 (char_u *)&p_tx, PV_TX,
2605 {
2606#ifdef USE_CRNL
2607 (char_u *)TRUE,
2608#else
2609 (char_u *)FALSE,
2610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002611 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002612 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2616#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002617 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618#else
2619 (char_u *)NULL, PV_NONE,
2620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002621 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2623 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 {"timeout", "to", P_BOOL|P_VI_DEF,
2626 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2629 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002630 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 {"title", NULL, P_BOOL|P_VI_DEF,
2632#ifdef FEAT_TITLE
2633 (char_u *)&p_title, PV_NONE,
2634#else
2635 (char_u *)NULL, PV_NONE,
2636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 {"titlelen", NULL, P_NUM|P_VI_DEF,
2639#ifdef FEAT_TITLE
2640 (char_u *)&p_titlelen, PV_NONE,
2641#else
2642 (char_u *)NULL, PV_NONE,
2643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002645 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646#ifdef FEAT_TITLE
2647 (char_u *)&p_titleold, PV_NONE,
2648 {(char_u *)N_("Thanks for flying Vim"),
2649 (char_u *)0L}
2650#else
2651 (char_u *)NULL, PV_NONE,
2652 {(char_u *)0L, (char_u *)0L}
2653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"titlestring", NULL, P_STRING|P_VI_DEF,
2656#ifdef FEAT_TITLE
2657 (char_u *)&p_titlestring, PV_NONE,
2658#else
2659 (char_u *)NULL, PV_NONE,
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
2663 {"toolbar", "tb", P_STRING|P_COMMA|P_VI_DEF|P_NODUP,
2664 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 {(char_u *)"icons,tooltips", (char_u *)0L}
2666 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002668#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2670 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672#endif
2673 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2674 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002676 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2677 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2680 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002681 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2683 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2686#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2687 (char_u *)&p_ttym, PV_NONE,
2688#else
2689 (char_u *)NULL, PV_NONE,
2690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2693 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2696 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002698 {"undodir", "udir", P_STRING|P_EXPAND|P_COMMA|P_NODUP|P_SECURE|P_VI_DEF,
2699#ifdef FEAT_PERSISTENT_UNDO
2700 (char_u *)&p_udir, PV_NONE,
2701 {(char_u *)".", (char_u *)0L}
2702#else
2703 (char_u *)NULL, PV_NONE,
2704 {(char_u *)0L, (char_u *)0L}
2705#endif
2706 SCRIPTID_INIT},
2707 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2708#ifdef FEAT_PERSISTENT_UNDO
2709 (char_u *)&p_udf, PV_UDF,
2710#else
2711 (char_u *)NULL, PV_NONE,
2712#endif
2713 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002715 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {
2717#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2718 (char_u *)1000L,
2719#else
2720 (char_u *)100L,
2721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002723 {"undoreload", "ur", P_NUM|P_VI_DEF,
2724 (char_u *)&p_ur, PV_NONE,
2725 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726 {"updatecount", "uc", P_NUM|P_VI_DEF,
2727 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {"updatetime", "ut", P_NUM|P_VI_DEF,
2730 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"verbose", "vbs", P_NUM|P_VI_DEF,
2733 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002735 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2736 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002737 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2739#ifdef FEAT_SESSION
2740 (char_u *)&p_vdir, PV_NONE,
2741 {(char_u *)DFLT_VDIR, (char_u *)0L}
2742#else
2743 (char_u *)NULL, PV_NONE,
2744 {(char_u *)0L, (char_u *)0L}
2745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002746 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2748#ifdef FEAT_SESSION
2749 (char_u *)&p_vop, PV_NONE,
2750 {(char_u *)"folds,options,cursor", (char_u *)0L}
2751#else
2752 (char_u *)NULL, PV_NONE,
2753 {(char_u *)0L, (char_u *)0L}
2754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"viminfo", "vi", P_STRING|P_COMMA|P_NODUP|P_SECURE,
2757#ifdef FEAT_VIMINFO
2758 (char_u *)&p_viminfo, PV_NONE,
2759#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002760 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761#else
2762# ifdef AMIGA
2763 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002764 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002766 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767# endif
2768#endif
2769#else
2770 (char_u *)NULL, PV_NONE,
2771 {(char_u *)0L, (char_u *)0L}
2772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02002774 {"virtualedit", "ve", P_STRING|P_COMMA|P_NODUP|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775#ifdef FEAT_VIRTUALEDIT
2776 (char_u *)&p_ve, PV_NONE,
2777 {(char_u *)"", (char_u *)""}
2778#else
2779 (char_u *)NULL, PV_NONE,
2780 {(char_u *)0L, (char_u *)0L}
2781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2784 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {"w300", NULL, P_NUM|P_VI_DEF,
2787 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 {"w1200", NULL, P_NUM|P_VI_DEF,
2790 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002791 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 {"w9600", NULL, P_NUM|P_VI_DEF,
2793 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 {"warn", NULL, P_BOOL|P_VI_DEF,
2796 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2799 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002800 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801 {"whichwrap", "ww", P_STRING|P_VIM|P_COMMA|P_FLAGLIST,
2802 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002803 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804 {"wildchar", "wc", P_NUM|P_VIM,
2805 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2807 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002808 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002810 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811 {"wildignore", "wig", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2812#ifdef FEAT_WILDIGN
2813 (char_u *)&p_wig, PV_NONE,
2814#else
2815 (char_u *)NULL, PV_NONE,
2816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002817 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002818 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2819 (char_u *)&p_wic, PV_NONE,
2820 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2822#ifdef FEAT_WILDMENU
2823 (char_u *)&p_wmnu, PV_NONE,
2824#else
2825 (char_u *)NULL, PV_NONE,
2826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002827 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 {"wildmode", "wim", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2829 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002830 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002831 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2832#ifdef FEAT_CMDL_COMPL
2833 (char_u *)&p_wop, PV_NONE,
2834 {(char_u *)"", (char_u *)0L}
2835#else
2836 (char_u *)NULL, PV_NONE,
2837 {(char_u *)NULL, (char_u *)0L}
2838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2841#ifdef FEAT_WAK
2842 (char_u *)&p_wak, PV_NONE,
2843 {(char_u *)"menu", (char_u *)0L}
2844#else
2845 (char_u *)NULL, PV_NONE,
2846 {(char_u *)NULL, (char_u *)0L}
2847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002848 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002850 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002851 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 {"winheight", "wh", P_NUM|P_VI_DEF,
2853#ifdef FEAT_WINDOWS
2854 (char_u *)&p_wh, PV_NONE,
2855#else
2856 (char_u *)NULL, PV_NONE,
2857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002860#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 (char_u *)VAR_WIN, PV_WFH,
2862#else
2863 (char_u *)NULL, PV_NONE,
2864#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002865 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002866 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2867#ifdef FEAT_VERTSPLIT
2868 (char_u *)VAR_WIN, PV_WFW,
2869#else
2870 (char_u *)NULL, PV_NONE,
2871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2874#ifdef FEAT_WINDOWS
2875 (char_u *)&p_wmh, PV_NONE,
2876#else
2877 (char_u *)NULL, PV_NONE,
2878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2881#ifdef FEAT_VERTSPLIT
2882 (char_u *)&p_wmw, PV_NONE,
2883#else
2884 (char_u *)NULL, PV_NONE,
2885#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2888#ifdef FEAT_VERTSPLIT
2889 (char_u *)&p_wiw, PV_NONE,
2890#else
2891 (char_u *)NULL, PV_NONE,
2892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2895 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002896 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2898 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002899 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2901 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002902 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903 {"write", NULL, P_BOOL|P_VI_DEF,
2904 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"writeany", "wa", P_BOOL|P_VI_DEF,
2907 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002908 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2910 (char_u *)&p_wb, PV_NONE,
2911 {
2912#ifdef FEAT_WRITEBACKUP
2913 (char_u *)TRUE,
2914#else
2915 (char_u *)FALSE,
2916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 {"writedelay", "wd", P_NUM|P_VI_DEF,
2919 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921
2922/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002923#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926
2927 p_term("t_AB", T_CAB)
2928 p_term("t_AF", T_CAF)
2929 p_term("t_AL", T_CAL)
2930 p_term("t_al", T_AL)
2931 p_term("t_bc", T_BC)
2932 p_term("t_cd", T_CD)
2933 p_term("t_ce", T_CE)
2934 p_term("t_cl", T_CL)
2935 p_term("t_cm", T_CM)
2936 p_term("t_Co", T_CCO)
2937 p_term("t_CS", T_CCS)
2938 p_term("t_cs", T_CS)
2939#ifdef FEAT_VERTSPLIT
2940 p_term("t_CV", T_CSV)
2941#endif
2942 p_term("t_ut", T_UT)
2943 p_term("t_da", T_DA)
2944 p_term("t_db", T_DB)
2945 p_term("t_DL", T_CDL)
2946 p_term("t_dl", T_DL)
2947 p_term("t_fs", T_FS)
2948 p_term("t_IE", T_CIE)
2949 p_term("t_IS", T_CIS)
2950 p_term("t_ke", T_KE)
2951 p_term("t_ks", T_KS)
2952 p_term("t_le", T_LE)
2953 p_term("t_mb", T_MB)
2954 p_term("t_md", T_MD)
2955 p_term("t_me", T_ME)
2956 p_term("t_mr", T_MR)
2957 p_term("t_ms", T_MS)
2958 p_term("t_nd", T_ND)
2959 p_term("t_op", T_OP)
2960 p_term("t_RI", T_CRI)
2961 p_term("t_RV", T_CRV)
Bram Moolenaar9584b312013-03-13 19:29:28 +01002962 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963 p_term("t_Sb", T_CSB)
2964 p_term("t_Sf", T_CSF)
2965 p_term("t_se", T_SE)
2966 p_term("t_so", T_SO)
2967 p_term("t_sr", T_SR)
2968 p_term("t_ts", T_TS)
2969 p_term("t_te", T_TE)
2970 p_term("t_ti", T_TI)
2971 p_term("t_ue", T_UE)
2972 p_term("t_us", T_US)
2973 p_term("t_vb", T_VB)
2974 p_term("t_ve", T_VE)
2975 p_term("t_vi", T_VI)
2976 p_term("t_vs", T_VS)
2977 p_term("t_WP", T_CWP)
2978 p_term("t_WS", T_CWS)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002979 p_term("t_SI", T_CSI)
2980 p_term("t_EI", T_CEI)
Bram Moolenaar494838a2015-02-10 19:20:37 +01002981 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 p_term("t_xs", T_XS)
2983 p_term("t_ZH", T_CZH)
2984 p_term("t_ZR", T_CZR)
2985
2986/* terminal key codes are not in here */
2987
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002988 /* end marker */
2989 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990};
2991
2992#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
2993
2994#ifdef FEAT_MBYTE
2995static char *(p_ambw_values[]) = {"single", "double", NULL};
2996#endif
2997static char *(p_bg_values[]) = {"light", "dark", NULL};
2998static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
2999static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003000#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003001static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003002#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003003#ifdef FEAT_CMDL_COMPL
3004static char *(p_wop_values[]) = {"tagfile", NULL};
3005#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006#ifdef FEAT_WAK
3007static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3008#endif
3009static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003010static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3011static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013#ifdef FEAT_BROWSE
3014static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3015#endif
3016#ifdef FEAT_SCROLLBIND
3017static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3018#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003019static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020#ifdef FEAT_VERTSPLIT
3021static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3022#endif
3023#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003024# ifdef FEAT_AUTOCMD
3025static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3026# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003028# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3030#endif
3031static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3032#ifdef FEAT_FOLDING
3033static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003034# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003036# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037 NULL};
3038static char *(p_fcl_values[]) = {"all", NULL};
3039#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003040#ifdef FEAT_INS_EXPAND
Bram Moolenaarc270d802006-03-11 21:29:41 +00003041static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003042#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043
3044static void set_option_default __ARGS((int, int opt_flags, int compatible));
3045static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003046static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003047static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048static char_u *illegal_char __ARGS((char_u *, int));
3049static int string_to_key __ARGS((char_u *arg));
3050#ifdef FEAT_CMDWIN
3051static char_u *check_cedit __ARGS((void));
3052#endif
3053#ifdef FEAT_TITLE
3054static void did_set_title __ARGS((int icon));
3055#endif
3056static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3057static void didset_options __ARGS((void));
3058static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003059#if defined(FEAT_EVAL) || defined(PROTO)
3060static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3061#else
3062# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3063#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003065static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066static 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));
3067static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003068#ifdef FEAT_SYN_HL
3069static int int_cmp __ARGS((const void *a, const void *b));
3070#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071#ifdef FEAT_CLIPBOARD
3072static char_u *check_clipboard_option __ARGS((void));
3073#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003074#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003075static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003076#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003077#ifdef FEAT_EVAL
3078static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3079#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003081static 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 +00003082static void check_redraw __ARGS((long_u flags));
3083static int findoption __ARGS((char_u *));
3084static int find_key_option __ARGS((char_u *));
3085static void showoptions __ARGS((int all, int opt_flags));
3086static int optval_default __ARGS((struct vimoption *, char_u *varp));
3087static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3088static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3089static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3090static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3091static int istermoption __ARGS((struct vimoption *));
3092static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3093static char_u *get_varp __ARGS((struct vimoption *));
3094static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003095static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3097#ifdef FEAT_LANGMAP
3098static void langmap_init __ARGS((void));
3099static void langmap_set __ARGS((void));
3100#endif
3101static void paste_option_changed __ARGS((void));
3102static void compatible_set __ARGS((void));
3103#ifdef FEAT_LINEBREAK
3104static void fill_breakat_flags __ARGS((void));
3105#endif
3106static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3107static int check_opt_strings __ARGS((char_u *val, char **values, int));
3108static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003109#ifdef FEAT_LINEBREAK
3110static int briopt_check __ARGS((win_T *wp));
3111#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112
3113/*
3114 * Initialize the options, first part.
3115 *
3116 * Called only once from main(), just after creating the first buffer.
3117 */
3118 void
3119set_init_1()
3120{
3121 char_u *p;
3122 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003123 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124
3125#ifdef FEAT_LANGMAP
3126 langmap_init();
3127#endif
3128
3129 /* Be Vi compatible by default */
3130 p_cp = TRUE;
3131
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003132 /* Use POSIX compatibility when $VIM_POSIX is set. */
3133 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003134 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003135 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003136 set_string_default("shm", (char_u *)"A");
3137 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003138
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 /*
3140 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003141 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003143 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3145# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003146 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003148 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003150 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151# endif
3152#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003153 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154 set_string_default("sh", p);
3155
3156#ifdef FEAT_WILDIGN
3157 /*
3158 * Set the default for 'backupskip' to include environment variables for
3159 * temp files.
3160 */
3161 {
3162# ifdef UNIX
3163 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3164# else
3165 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3166# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003167 int len;
3168 garray_T ga;
3169 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170
3171 ga_init2(&ga, 1, 100);
3172 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3173 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003174 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175# ifdef UNIX
3176 if (*names[n] == NUL)
3177 p = (char_u *)"/tmp";
3178 else
3179# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003180 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 if (p != NULL && *p != NUL)
3182 {
3183 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003184 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 if (ga_grow(&ga, len) == OK)
3186 {
3187 if (ga.ga_len > 0)
3188 STRCAT(ga.ga_data, ",");
3189 STRCAT(ga.ga_data, p);
3190 add_pathsep(ga.ga_data);
3191 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192 ga.ga_len += len;
3193 }
3194 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003195 if (mustfree)
3196 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 }
3198 if (ga.ga_data != NULL)
3199 {
3200 set_string_default("bsk", ga.ga_data);
3201 vim_free(ga.ga_data);
3202 }
3203 }
3204#endif
3205
3206 /*
3207 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3208 */
3209 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003210 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003212#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3213 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3214#endif
3215 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003217 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003218 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219#else
3220# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003221 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003222 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003224 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225# endif
3226#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003228 opt_idx = findoption((char_u *)"maxmem");
3229 if (opt_idx >= 0)
3230 {
3231#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar427d51c2013-06-16 16:01:25 +02003232 if ((long)options[opt_idx].def_val[VI_DEFAULT] > (long)n
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003233 || (long)options[opt_idx].def_val[VI_DEFAULT] == 0L)
3234#endif
3235 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3236 }
3237 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 }
3239
3240#ifdef FEAT_GUI_W32
3241 /* force 'shortname' for Win32s */
3242 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003243 {
3244 opt_idx = findoption((char_u *)"shortname");
3245 if (opt_idx >= 0)
3246 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3247 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248#endif
3249
3250#ifdef FEAT_SEARCHPATH
3251 {
3252 char_u *cdpath;
3253 char_u *buf;
3254 int i;
3255 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003256 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257
3258 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003259 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260 if (cdpath != NULL)
3261 {
3262 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3263 if (buf != NULL)
3264 {
3265 buf[0] = ','; /* start with ",", current dir first */
3266 j = 1;
3267 for (i = 0; cdpath[i] != NUL; ++i)
3268 {
3269 if (vim_ispathlistsep(cdpath[i]))
3270 buf[j++] = ',';
3271 else
3272 {
3273 if (cdpath[i] == ' ' || cdpath[i] == ',')
3274 buf[j++] = '\\';
3275 buf[j++] = cdpath[i];
3276 }
3277 }
3278 buf[j] = NUL;
3279 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003280 if (opt_idx >= 0)
3281 {
3282 options[opt_idx].def_val[VI_DEFAULT] = buf;
3283 options[opt_idx].flags |= P_DEF_ALLOCED;
3284 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003285 else
3286 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003288 if (mustfree)
3289 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003290 }
3291 }
3292#endif
3293
3294#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3295 /* Set print encoding on platforms that don't default to latin1 */
3296 set_string_default("penc",
3297# if defined(MSWIN) || defined(OS2)
3298 (char_u *)"cp1252"
3299# else
3300# ifdef VMS
3301 (char_u *)"dec-mcs"
3302# else
3303# ifdef EBCDIC
3304 (char_u *)"ebcdic-uk"
3305# else
3306# ifdef MAC
3307 (char_u *)"mac-roman"
3308# else /* HPUX */
3309 (char_u *)"hp-roman8"
3310# endif
3311# endif
3312# endif
3313# endif
3314 );
3315#endif
3316
3317#ifdef FEAT_POSTSCRIPT
3318 /* 'printexpr' must be allocated to be able to evaluate it. */
3319 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003320# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3321 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322# else
3323# ifdef VMS
3324 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3325
3326# else
3327 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3328# endif
3329# endif
3330 );
3331#endif
3332
3333 /*
3334 * Set all the options (except the terminal options) to their default
3335 * value. Also set the global value for local options.
3336 */
3337 set_options_default(0);
3338
3339#ifdef FEAT_GUI
3340 if (found_reverse_arg)
3341 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3342#endif
3343
3344 curbuf->b_p_initialized = TRUE;
3345 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003346 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 check_buf_options(curbuf);
3348 check_win_options(curwin);
3349 check_options();
3350
3351 /* Must be before option_expand(), because that one needs vim_isIDc() */
3352 didset_options();
3353
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003354#ifdef FEAT_SPELL
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003355 /* Use the current chartab for the generic chartab. */
3356 init_spell_chartab();
3357#endif
3358
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359#ifdef FEAT_LINEBREAK
3360 /*
3361 * initialize the table for 'breakat'.
3362 */
3363 fill_breakat_flags();
3364#endif
3365
3366 /*
3367 * Expand environment variables and things like "~" for the defaults.
3368 * If option_expand() returns non-NULL the variable is expanded. This can
3369 * only happen for non-indirect options.
3370 * Also set the default to the expanded value, so ":set" does not list
3371 * them.
3372 * Don't set the P_ALLOCED flag, because we don't want to free the
3373 * default.
3374 */
3375 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3376 {
3377 if ((options[opt_idx].flags & P_GETTEXT)
3378 && options[opt_idx].var != NULL)
3379 p = (char_u *)_(*(char **)options[opt_idx].var);
3380 else
3381 p = option_expand(opt_idx, NULL);
3382 if (p != NULL && (p = vim_strsave(p)) != NULL)
3383 {
3384 *(char_u **)options[opt_idx].var = p;
3385 /* VIMEXP
3386 * Defaults for all expanded options are currently the same for Vi
3387 * and Vim. When this changes, add some code here! Also need to
3388 * split P_DEF_ALLOCED in two.
3389 */
3390 if (options[opt_idx].flags & P_DEF_ALLOCED)
3391 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3392 options[opt_idx].def_val[VI_DEFAULT] = p;
3393 options[opt_idx].flags |= P_DEF_ALLOCED;
3394 }
3395 }
3396
3397 /* Initialize the highlight_attr[] table. */
3398 highlight_changed();
3399
3400 save_file_ff(curbuf); /* Buffer is unchanged */
3401
3402 /* Parse default for 'wildmode' */
3403 check_opt_wim();
3404
3405#if defined(FEAT_ARABIC)
3406 /* Detect use of mlterm.
3407 * Mlterm is a terminal emulator akin to xterm that has some special
3408 * abilities (bidi namely).
3409 * NOTE: mlterm's author is being asked to 'set' a variable
3410 * instead of an environment variable due to inheritance.
3411 */
3412 if (mch_getenv((char_u *)"MLTERM") != NULL)
3413 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3414#endif
3415
3416#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
3417 /* Parse default for 'fillchars'. */
3418 (void)set_chars_option(&p_fcs);
3419#endif
3420
3421#ifdef FEAT_CLIPBOARD
3422 /* Parse default for 'clipboard' */
3423 (void)check_clipboard_option();
3424#endif
3425
3426#ifdef FEAT_MBYTE
3427# if defined(WIN3264) && defined(FEAT_GETTEXT)
3428 /*
3429 * If $LANG isn't set, try to get a good value for it. This makes the
3430 * right language be used automatically. Don't do this for English.
3431 */
3432 if (mch_getenv((char_u *)"LANG") == NULL)
3433 {
3434 char buf[20];
3435
3436 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3437 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3438 * only the first two. */
3439 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3440 (LPTSTR)buf, 20);
3441 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3442 {
3443 /* There are a few exceptions (probably more) */
3444 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3445 STRCPY(buf, "zh_TW");
3446 else if (STRNICMP(buf, "chs", 3) == 0
3447 || STRNICMP(buf, "zhc", 3) == 0)
3448 STRCPY(buf, "zh_CN");
3449 else if (STRNICMP(buf, "jp", 2) == 0)
3450 STRCPY(buf, "ja");
3451 else
3452 buf[2] = NUL; /* truncate to two-letter code */
3453 vim_setenv("LANG", buf);
3454 }
3455 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003456# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003457# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003458 /* Moved to os_mac_conv.c to avoid dependency problems. */
3459 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003460# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461# endif
3462
3463 /* enc_locale() will try to find the encoding of the current locale. */
3464 p = enc_locale();
3465 if (p != NULL)
3466 {
3467 char_u *save_enc;
3468
3469 /* Try setting 'encoding' and check if the value is valid.
3470 * If not, go back to the default "latin1". */
3471 save_enc = p_enc;
3472 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003473 if (STRCMP(p_enc, "gb18030") == 0)
3474 {
3475 /* We don't support "gb18030", but "cp936" is a good substitute
3476 * for practical purposes, thus use that. It's not an alias to
3477 * still support conversion between gb18030 and utf-8. */
3478 p_enc = vim_strsave((char_u *)"cp936");
3479 vim_free(p);
3480 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003481 if (mb_init() == NULL)
3482 {
3483 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003484 if (opt_idx >= 0)
3485 {
3486 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3487 options[opt_idx].flags |= P_DEF_ALLOCED;
3488 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003489
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003490#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3491 || defined(VMS)
3492 if (STRCMP(p_enc, "latin1") == 0
3493# ifdef FEAT_MBYTE
3494 || enc_utf8
3495# endif
3496 )
3497 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003498 /* Adjust the default for 'isprint' and 'iskeyword' to match
3499 * latin1. Also set the defaults for when 'nocompatible' is
3500 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003501 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003502 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003503 set_string_option_direct((char_u *)"isk", -1,
3504 ISK_LATIN1, OPT_FREE, SID_NONE);
3505 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003506 if (opt_idx >= 0)
3507 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003508 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003509 if (opt_idx >= 0)
3510 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003511 (void)init_chartab();
3512 }
3513#endif
3514
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515# if defined(WIN3264) && !defined(FEAT_GUI)
3516 /* Win32 console: When GetACP() returns a different value from
3517 * GetConsoleCP() set 'termencoding'. */
3518 if (GetACP() != GetConsoleCP())
3519 {
3520 char buf[50];
3521
3522 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3523 p_tenc = vim_strsave((char_u *)buf);
3524 if (p_tenc != NULL)
3525 {
3526 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003527 if (opt_idx >= 0)
3528 {
3529 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3530 options[opt_idx].flags |= P_DEF_ALLOCED;
3531 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003532 convert_setup(&input_conv, p_tenc, p_enc);
3533 convert_setup(&output_conv, p_enc, p_tenc);
3534 }
3535 else
3536 p_tenc = empty_option;
3537 }
3538# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003539# if defined(WIN3264) && defined(FEAT_MBYTE)
3540 /* $HOME may have characters in active code page. */
3541 init_homedir();
3542# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003543 }
3544 else
3545 {
3546 vim_free(p_enc);
3547 p_enc = save_enc;
3548 }
3549 }
3550#endif
3551
3552#ifdef FEAT_MULTI_LANG
3553 /* Set the default for 'helplang'. */
3554 set_helplang_default(get_mess_lang());
3555#endif
3556}
3557
3558/*
3559 * Set an option to its default value.
3560 * This does not take care of side effects!
3561 */
3562 static void
3563set_option_default(opt_idx, opt_flags, compatible)
3564 int opt_idx;
3565 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3566 int compatible; /* use Vi default value */
3567{
3568 char_u *varp; /* pointer to variable for current option */
3569 int dvi; /* index in def_val[] */
3570 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003571 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3573
3574 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3575 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003576 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003577 {
3578 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3579 if (flags & P_STRING)
3580 {
3581 /* Use set_string_option_direct() for local options to handle
3582 * freeing and allocating the value. */
3583 if (options[opt_idx].indir != PV_NONE)
3584 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003585 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586 else
3587 {
3588 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3589 free_string_option(*(char_u **)(varp));
3590 *(char_u **)varp = options[opt_idx].def_val[dvi];
3591 options[opt_idx].flags &= ~P_ALLOCED;
3592 }
3593 }
3594 else if (flags & P_NUM)
3595 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003596 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003597 win_comp_scroll(curwin);
3598 else
3599 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003600 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 /* May also set global value for local option. */
3602 if (both)
3603 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3604 *(long *)varp;
3605 }
3606 }
3607 else /* P_BOOL */
3608 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003609 /* the cast to long is required for Manx C, long_i is needed for
3610 * MSVC */
3611 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003612#ifdef UNIX
3613 /* 'modeline' defaults to off for root */
3614 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3615 *(int *)varp = FALSE;
3616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003617 /* May also set global value for local option. */
3618 if (both)
3619 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3620 *(int *)varp;
3621 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003622
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003623 /* The default value is not insecure. */
3624 flagsp = insecure_flag(opt_idx, opt_flags);
3625 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626 }
3627
3628#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003629 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630#endif
3631}
3632
3633/*
3634 * Set all options (except terminal options) to their default value.
3635 */
3636 static void
3637set_options_default(opt_flags)
3638 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3639{
3640 int i;
3641#ifdef FEAT_WINDOWS
3642 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003643 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003644#endif
3645
3646 for (i = 0; !istermoption(&options[i]); i++)
3647 if (!(options[i].flags & P_NODEFAULT))
3648 set_option_default(i, opt_flags, p_cp);
3649
3650#ifdef FEAT_WINDOWS
3651 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003652 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653 win_comp_scroll(wp);
3654#else
3655 win_comp_scroll(curwin);
3656#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003657#ifdef FEAT_CINDENT
3658 parse_cino(curbuf);
3659#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003660}
3661
3662/*
3663 * Set the Vi-default value of a string option.
3664 * Used for 'sh', 'backupskip' and 'term'.
3665 */
3666 void
3667set_string_default(name, val)
3668 char *name;
3669 char_u *val;
3670{
3671 char_u *p;
3672 int opt_idx;
3673
3674 p = vim_strsave(val);
3675 if (p != NULL) /* we don't want a NULL */
3676 {
3677 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003678 if (opt_idx >= 0)
3679 {
3680 if (options[opt_idx].flags & P_DEF_ALLOCED)
3681 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3682 options[opt_idx].def_val[VI_DEFAULT] = p;
3683 options[opt_idx].flags |= P_DEF_ALLOCED;
3684 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685 }
3686}
3687
3688/*
3689 * Set the Vi-default value of a number option.
3690 * Used for 'lines' and 'columns'.
3691 */
3692 void
3693set_number_default(name, val)
3694 char *name;
3695 long val;
3696{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003697 int opt_idx;
3698
3699 opt_idx = findoption((char_u *)name);
3700 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003701 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003702}
3703
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003704#if defined(EXITFREE) || defined(PROTO)
3705/*
3706 * Free all options.
3707 */
3708 void
3709free_all_options()
3710{
3711 int i;
3712
3713 for (i = 0; !istermoption(&options[i]); i++)
3714 {
3715 if (options[i].indir == PV_NONE)
3716 {
3717 /* global option: free value and default value. */
3718 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3719 free_string_option(*(char_u **)options[i].var);
3720 if (options[i].flags & P_DEF_ALLOCED)
3721 free_string_option(options[i].def_val[VI_DEFAULT]);
3722 }
3723 else if (options[i].var != VAR_WIN
3724 && (options[i].flags & P_STRING))
3725 /* buffer-local option: free global value */
3726 free_string_option(*(char_u **)options[i].var);
3727 }
3728}
3729#endif
3730
3731
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732/*
3733 * Initialize the options, part two: After getting Rows and Columns and
3734 * setting 'term'.
3735 */
3736 void
3737set_init_2()
3738{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003739 int idx;
3740
Bram Moolenaar071d4272004-06-13 20:20:40 +00003741 /*
3742 * 'scroll' defaults to half the window height. Note that this default is
3743 * wrong when the window height changes.
3744 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003745 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003746 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003747 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003748 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749 comp_col();
3750
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003751 /*
3752 * 'window' is only for backwards compatibility with Vi.
3753 * Default is Rows - 1.
3754 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003755 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003756 p_window = Rows - 1;
3757 set_number_default("window", Rows - 1);
3758
Bram Moolenaarf740b292006-02-16 22:11:02 +00003759 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003760#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003761 /*
3762 * If 'background' wasn't set by the user, try guessing the value,
3763 * depending on the terminal name. Only need to check for terminals
3764 * with a dark background, that can handle color.
3765 */
3766 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003767 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3768 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003770 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003771 /* don't mark it as set, when starting the GUI it may be
3772 * changed again */
3773 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003774 }
3775#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003776
3777#ifdef CURSOR_SHAPE
3778 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3779#endif
3780#ifdef FEAT_MOUSESHAPE
3781 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3782#endif
3783#ifdef FEAT_PRINTER
3784 (void)parse_printoptions(); /* parse 'printoptions' default value */
3785#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003786}
3787
3788/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003789 * Return "dark" or "light" depending on the kind of terminal.
3790 * This is just guessing! Recognized are:
3791 * "linux" Linux console
3792 * "screen.linux" Linux console with screen
3793 * "cygwin" Cygwin shell
3794 * "putty" Putty program
3795 * We also check the COLORFGBG environment variable, which is set by
3796 * rxvt and derivatives. This variable contains either two or three
3797 * values separated by semicolons; we want the last value in either
3798 * case. If this value is 0-6 or 8, our background is dark.
3799 */
3800 static char_u *
3801term_bg_default()
3802{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003803#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3804 /* DOS console nearly always black */
3805 return (char_u *)"dark";
3806#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003807 char_u *p;
3808
Bram Moolenaarf740b292006-02-16 22:11:02 +00003809 if (STRCMP(T_NAME, "linux") == 0
3810 || STRCMP(T_NAME, "screen.linux") == 0
3811 || STRCMP(T_NAME, "cygwin") == 0
3812 || STRCMP(T_NAME, "putty") == 0
3813 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3814 && (p = vim_strrchr(p, ';')) != NULL
3815 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3816 && p[2] == NUL))
3817 return (char_u *)"dark";
3818 return (char_u *)"light";
3819#endif
3820}
3821
3822/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823 * Initialize the options, part three: After reading the .vimrc
3824 */
3825 void
3826set_init_3()
3827{
3828#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3829/*
3830 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3831 * This is done after other initializations, where 'shell' might have been
3832 * set, but only if they have not been set before.
3833 */
3834 char_u *p;
3835 int idx_srr;
3836 int do_srr;
3837#ifdef FEAT_QUICKFIX
3838 int idx_sp;
3839 int do_sp;
3840#endif
3841
3842 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003843 if (idx_srr < 0)
3844 do_srr = FALSE;
3845 else
3846 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847#ifdef FEAT_QUICKFIX
3848 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003849 if (idx_sp < 0)
3850 do_sp = FALSE;
3851 else
3852 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003854 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855 if (p != NULL)
3856 {
3857 /*
3858 * Default for p_sp is "| tee", for p_srr is ">".
3859 * For known shells it is changed here to include stderr.
3860 */
3861 if ( fnamecmp(p, "csh") == 0
3862 || fnamecmp(p, "tcsh") == 0
3863# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3864 || fnamecmp(p, "csh.exe") == 0
3865 || fnamecmp(p, "tcsh.exe") == 0
3866# endif
3867 )
3868 {
3869#if defined(FEAT_QUICKFIX)
3870 if (do_sp)
3871 {
3872# ifdef WIN3264
3873 p_sp = (char_u *)">&";
3874# else
3875 p_sp = (char_u *)"|& tee";
3876# endif
3877 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3878 }
3879#endif
3880 if (do_srr)
3881 {
3882 p_srr = (char_u *)">&";
3883 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3884 }
3885 }
3886 else
3887# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3888 if ( fnamecmp(p, "sh") == 0
3889 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003890 || fnamecmp(p, "mksh") == 0
3891 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003893 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003895 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896# ifdef WIN3264
3897 || fnamecmp(p, "cmd") == 0
3898 || fnamecmp(p, "sh.exe") == 0
3899 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003900 || fnamecmp(p, "mksh.exe") == 0
3901 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003903 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904 || fnamecmp(p, "bash.exe") == 0
3905 || fnamecmp(p, "cmd.exe") == 0
3906# endif
3907 )
3908# endif
3909 {
3910#if defined(FEAT_QUICKFIX)
3911 if (do_sp)
3912 {
3913# ifdef WIN3264
3914 p_sp = (char_u *)">%s 2>&1";
3915# else
3916 p_sp = (char_u *)"2>&1| tee";
3917# endif
3918 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3919 }
3920#endif
3921 if (do_srr)
3922 {
3923 p_srr = (char_u *)">%s 2>&1";
3924 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3925 }
3926 }
3927 vim_free(p);
3928 }
3929#endif
3930
3931#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3932 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003933 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3934 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 * This is done after other initializations, where 'shell' might have been
3936 * set, but only if they have not been set before. Default for p_shcf is
3937 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3938 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3939 * command.com. And for Win32 we need to set p_sxq instead.
3940 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003941 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 {
3943 int idx3;
3944
3945 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003946 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947 {
3948 p_shcf = (char_u *)"-c";
3949 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3950 }
3951
3952# ifndef DJGPP
3953# ifdef WIN3264
3954 /* Somehow Win32 requires the quotes around the redirection too */
3955 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003956 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003957 {
3958 p_sxq = (char_u *)"\"";
3959 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3960 }
3961# else
3962 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003963 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 {
3965 p_shq = (char_u *)"\"";
3966 options[idx3].def_val[VI_DEFAULT] = p_shq;
3967 }
3968# endif
3969# endif
3970 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01003971 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
3972 {
3973 int idx3;
3974
3975 /*
3976 * cmd.exe on Windows will strip the first and last double quote given
3977 * on the command line, e.g. most of the time things like:
3978 * cmd /c "my path/to/echo" "my args to echo"
3979 * become:
3980 * my path/to/echo" "my args to echo
3981 * when executed.
3982 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01003983 * To avoid this, set shellxquote to surround the command in
3984 * parenthesis. This appears to make most commands work, without
3985 * breaking commands that worked previously, such as
3986 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01003987 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01003988 idx3 = findoption((char_u *)"sxq");
3989 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3990 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003991 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003992 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3993 }
3994
Bram Moolenaara64ba222012-02-12 23:23:31 +01003995 idx3 = findoption((char_u *)"shcf");
3996 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
3997 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01003998 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01003999 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4000 }
4001 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004002#endif
4003
4004#ifdef FEAT_TITLE
4005 set_title_defaults();
4006#endif
4007}
4008
4009#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4010/*
4011 * When 'helplang' is still at its default value, set it to "lang".
4012 * Only the first two characters of "lang" are used.
4013 */
4014 void
4015set_helplang_default(lang)
4016 char_u *lang;
4017{
4018 int idx;
4019
4020 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4021 return;
4022 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004023 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004024 {
4025 if (options[idx].flags & P_ALLOCED)
4026 free_string_option(p_hlg);
4027 p_hlg = vim_strsave(lang);
4028 if (p_hlg == NULL)
4029 p_hlg = empty_option;
4030 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004031 {
4032 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4033 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4034 {
4035 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4036 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4037 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004038 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004039 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 options[idx].flags |= P_ALLOCED;
4041 }
4042}
4043#endif
4044
4045#ifdef FEAT_GUI
4046static char_u *gui_bg_default __ARGS((void));
4047
4048 static char_u *
4049gui_bg_default()
4050{
4051 if (gui_get_lightness(gui.back_pixel) < 127)
4052 return (char_u *)"dark";
4053 return (char_u *)"light";
4054}
4055
4056/*
4057 * Option initializations that can only be done after opening the GUI window.
4058 */
4059 void
4060init_gui_options()
4061{
4062 /* Set the 'background' option according to the lightness of the
4063 * background color, unless the user has set it already. */
4064 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4065 {
4066 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4067 highlight_changed();
4068 }
4069}
4070#endif
4071
4072#ifdef FEAT_TITLE
4073/*
4074 * 'title' and 'icon' only default to true if they have not been set or reset
4075 * in .vimrc and we can read the old value.
4076 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4077 * they can be reset. This reduces startup time when using X on a remote
4078 * machine.
4079 */
4080 void
4081set_title_defaults()
4082{
4083 int idx1;
4084 long val;
4085
4086 /*
4087 * If GUI is (going to be) used, we can always set the window title and
4088 * icon name. Saves a bit of time, because the X11 display server does
4089 * not need to be contacted.
4090 */
4091 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004092 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 {
4094#ifdef FEAT_GUI
4095 if (gui.starting || gui.in_use)
4096 val = TRUE;
4097 else
4098#endif
4099 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004100 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 p_title = val;
4102 }
4103 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004104 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 {
4106#ifdef FEAT_GUI
4107 if (gui.starting || gui.in_use)
4108 val = TRUE;
4109 else
4110#endif
4111 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004112 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 p_icon = val;
4114 }
4115}
4116#endif
4117
4118/*
4119 * Parse 'arg' for option settings.
4120 *
4121 * 'arg' may be IObuff, but only when no errors can be present and option
4122 * does not need to be expanded with option_expand().
4123 * "opt_flags":
4124 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004125 * OPT_GLOBAL for ":setglobal"
4126 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004128 * OPT_WINONLY to only set window-local options
4129 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 *
4131 * returns FAIL if an error is detected, OK otherwise
4132 */
4133 int
4134do_set(arg, opt_flags)
4135 char_u *arg; /* option string (may be written to!) */
4136 int opt_flags;
4137{
4138 int opt_idx;
4139 char_u *errmsg;
4140 char_u errbuf[80];
4141 char_u *startarg;
4142 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4143 int nextchar; /* next non-white char after option name */
4144 int afterchar; /* character just after option name */
4145 int len;
4146 int i;
4147 long value;
4148 int key;
4149 long_u flags; /* flags for current option */
4150 char_u *varp = NULL; /* pointer to variable for current option */
4151 int did_show = FALSE; /* already showed one value */
4152 int adding; /* "opt+=arg" */
4153 int prepending; /* "opt^=arg" */
4154 int removing; /* "opt-=arg" */
4155 int cp_val = 0;
4156 char_u key_name[2];
4157
4158 if (*arg == NUL)
4159 {
4160 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004161 did_show = TRUE;
4162 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 }
4164
4165 while (*arg != NUL) /* loop to process all options */
4166 {
4167 errmsg = NULL;
4168 startarg = arg; /* remember for error message */
4169
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004170 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4171 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 {
4173 /*
4174 * ":set all" show all options.
4175 * ":set all&" set all options to their default value.
4176 */
4177 arg += 3;
4178 if (*arg == '&')
4179 {
4180 ++arg;
4181 /* Only for :set command set global value of local options. */
4182 set_options_default(OPT_FREE | opt_flags);
4183 }
4184 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004185 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004187 did_show = TRUE;
4188 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004189 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004190 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 {
4192 showoptions(2, opt_flags);
4193 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004194 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004195 arg += 7;
4196 }
4197 else
4198 {
4199 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004200 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201 {
4202 prefix = 0;
4203 arg += 2;
4204 }
4205 else if (STRNCMP(arg, "inv", 3) == 0)
4206 {
4207 prefix = 2;
4208 arg += 3;
4209 }
4210
4211 /* find end of name */
4212 key = 0;
4213 if (*arg == '<')
4214 {
4215 nextchar = 0;
4216 opt_idx = -1;
4217 /* look out for <t_>;> */
4218 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4219 len = 5;
4220 else
4221 {
4222 len = 1;
4223 while (arg[len] != NUL && arg[len] != '>')
4224 ++len;
4225 }
4226 if (arg[len] != '>')
4227 {
4228 errmsg = e_invarg;
4229 goto skip;
4230 }
4231 arg[len] = NUL; /* put NUL after name */
4232 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4233 opt_idx = findoption(arg + 1);
4234 arg[len++] = '>'; /* restore '>' */
4235 if (opt_idx == -1)
4236 key = find_key_option(arg + 1);
4237 }
4238 else
4239 {
4240 len = 0;
4241 /*
4242 * The two characters after "t_" may not be alphanumeric.
4243 */
4244 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4245 len = 4;
4246 else
4247 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4248 ++len;
4249 nextchar = arg[len];
4250 arg[len] = NUL; /* put NUL after name */
4251 opt_idx = findoption(arg);
4252 arg[len] = nextchar; /* restore nextchar */
4253 if (opt_idx == -1)
4254 key = find_key_option(arg);
4255 }
4256
4257 /* remember character after option name */
4258 afterchar = arg[len];
4259
4260 /* skip white space, allow ":set ai ?" */
4261 while (vim_iswhite(arg[len]))
4262 ++len;
4263
4264 adding = FALSE;
4265 prepending = FALSE;
4266 removing = FALSE;
4267 if (arg[len] != NUL && arg[len + 1] == '=')
4268 {
4269 if (arg[len] == '+')
4270 {
4271 adding = TRUE; /* "+=" */
4272 ++len;
4273 }
4274 else if (arg[len] == '^')
4275 {
4276 prepending = TRUE; /* "^=" */
4277 ++len;
4278 }
4279 else if (arg[len] == '-')
4280 {
4281 removing = TRUE; /* "-=" */
4282 ++len;
4283 }
4284 }
4285 nextchar = arg[len];
4286
4287 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4288 {
4289 errmsg = (char_u *)N_("E518: Unknown option");
4290 goto skip;
4291 }
4292
4293 if (opt_idx >= 0)
4294 {
4295 if (options[opt_idx].var == NULL) /* hidden option: skip */
4296 {
4297 /* Only give an error message when requesting the value of
4298 * a hidden option, ignore setting it. */
4299 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4300 && (!(options[opt_idx].flags & P_BOOL)
4301 || nextchar == '?'))
4302 errmsg = (char_u *)N_("E519: Option not supported");
4303 goto skip;
4304 }
4305
4306 flags = options[opt_idx].flags;
4307 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4308 }
4309 else
4310 {
4311 flags = P_STRING;
4312 if (key < 0)
4313 {
4314 key_name[0] = KEY2TERMCAP0(key);
4315 key_name[1] = KEY2TERMCAP1(key);
4316 }
4317 else
4318 {
4319 key_name[0] = KS_KEY;
4320 key_name[1] = (key & 0xff);
4321 }
4322 }
4323
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004324 /* Skip all options that are not window-local (used when showing
4325 * an already loaded buffer in a window). */
4326 if ((opt_flags & OPT_WINONLY)
4327 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4328 goto skip;
4329
Bram Moolenaara3227e22006-03-08 21:32:40 +00004330 /* Skip all options that are window-local (used for :vimgrep). */
4331 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4332 && options[opt_idx].var == VAR_WIN)
4333 goto skip;
4334
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004335 /* Disallow changing some options from modelines. */
4336 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004337 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004338 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004339 {
4340 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4341 goto skip;
4342 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004343#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004344 /* In diff mode some options are overruled. This avoids that
4345 * 'foldmethod' becomes "marker" instead of "diff" and that
4346 * "wrap" gets set. */
4347 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004348 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004349 && (options[opt_idx].indir == PV_FDM
4350 || options[opt_idx].indir == PV_WRAP))
4351 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004353 }
4354
4355#ifdef HAVE_SANDBOX
4356 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004357 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004358 {
4359 errmsg = (char_u *)_(e_sandbox);
4360 goto skip;
4361 }
4362#endif
4363
4364 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4365 {
4366 arg += len;
4367 cp_val = p_cp;
4368 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4369 {
4370 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4371 {
4372 cp_val = FALSE;
4373 arg += 3;
4374 }
4375 else /* "opt&vi": set to Vi default */
4376 {
4377 cp_val = TRUE;
4378 arg += 2;
4379 }
4380 }
4381 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4382 && arg[1] != NUL && !vim_iswhite(arg[1]))
4383 {
4384 errmsg = e_trailing;
4385 goto skip;
4386 }
4387 }
4388
4389 /*
4390 * allow '=' and ':' as MSDOS command.com allows only one
4391 * '=' character per "set" command line. grrr. (jw)
4392 */
4393 if (nextchar == '?'
4394 || (prefix == 1
4395 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4396 && !(flags & P_BOOL)))
4397 {
4398 /*
4399 * print value
4400 */
4401 if (did_show)
4402 msg_putchar('\n'); /* cursor below last one */
4403 else
4404 {
4405 gotocmdline(TRUE); /* cursor at status line */
4406 did_show = TRUE; /* remember that we did a line */
4407 }
4408 if (opt_idx >= 0)
4409 {
4410 showoneopt(&options[opt_idx], opt_flags);
4411#ifdef FEAT_EVAL
4412 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004413 {
4414 /* Mention where the option was last set. */
4415 if (varp == options[opt_idx].var)
4416 last_set_msg(options[opt_idx].scriptID);
4417 else if ((int)options[opt_idx].indir & PV_WIN)
4418 last_set_msg(curwin->w_p_scriptID[
4419 (int)options[opt_idx].indir & PV_MASK]);
4420 else if ((int)options[opt_idx].indir & PV_BUF)
4421 last_set_msg(curbuf->b_p_scriptID[
4422 (int)options[opt_idx].indir & PV_MASK]);
4423 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004424#endif
4425 }
4426 else
4427 {
4428 char_u *p;
4429
4430 p = find_termcode(key_name);
4431 if (p == NULL)
4432 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004433 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004434 goto skip;
4435 }
4436 else
4437 (void)show_one_termcode(key_name, p, TRUE);
4438 }
4439 if (nextchar != '?'
4440 && nextchar != NUL && !vim_iswhite(afterchar))
4441 errmsg = e_trailing;
4442 }
4443 else
4444 {
4445 if (flags & P_BOOL) /* boolean */
4446 {
4447 if (nextchar == '=' || nextchar == ':')
4448 {
4449 errmsg = e_invarg;
4450 goto skip;
4451 }
4452
4453 /*
4454 * ":set opt!": invert
4455 * ":set opt&": reset to default value
4456 * ":set opt<": reset to global value
4457 */
4458 if (nextchar == '!')
4459 value = *(int *)(varp) ^ 1;
4460 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004461 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004462 ((flags & P_VI_DEF) || cp_val)
4463 ? VI_DEFAULT : VIM_DEFAULT];
4464 else if (nextchar == '<')
4465 {
4466 /* For 'autoread' -1 means to use global value. */
4467 if ((int *)varp == &curbuf->b_p_ar
4468 && opt_flags == OPT_LOCAL)
4469 value = -1;
4470 else
4471 value = *(int *)get_varp_scope(&(options[opt_idx]),
4472 OPT_GLOBAL);
4473 }
4474 else
4475 {
4476 /*
4477 * ":set invopt": invert
4478 * ":set opt" or ":set noopt": set or reset
4479 */
4480 if (nextchar != NUL && !vim_iswhite(afterchar))
4481 {
4482 errmsg = e_trailing;
4483 goto skip;
4484 }
4485 if (prefix == 2) /* inv */
4486 value = *(int *)(varp) ^ 1;
4487 else
4488 value = prefix;
4489 }
4490
4491 errmsg = set_bool_option(opt_idx, varp, (int)value,
4492 opt_flags);
4493 }
4494 else /* numeric or string */
4495 {
4496 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4497 || prefix != 1)
4498 {
4499 errmsg = e_invarg;
4500 goto skip;
4501 }
4502
4503 if (flags & P_NUM) /* numeric */
4504 {
4505 /*
4506 * Different ways to set a number option:
4507 * & set to default value
4508 * < set to global value
4509 * <xx> accept special key codes for 'wildchar'
4510 * c accept any non-digit for 'wildchar'
4511 * [-]0-9 set number
4512 * other error
4513 */
4514 ++arg;
4515 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004516 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004517 ((flags & P_VI_DEF) || cp_val)
4518 ? VI_DEFAULT : VIM_DEFAULT];
4519 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004520 {
4521 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4522 * use the global value. */
4523 if ((long *)varp == &curbuf->b_p_ul
4524 && opt_flags == OPT_LOCAL)
4525 value = NO_LOCAL_UNDOLEVEL;
4526 else
4527 value = *(long *)get_varp_scope(
4528 &(options[opt_idx]), OPT_GLOBAL);
4529 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004530 else if (((long *)varp == &p_wc
4531 || (long *)varp == &p_wcm)
4532 && (*arg == '<'
4533 || *arg == '^'
4534 || ((!arg[1] || vim_iswhite(arg[1]))
4535 && !VIM_ISDIGIT(*arg))))
4536 {
4537 value = string_to_key(arg);
4538 if (value == 0 && (long *)varp != &p_wcm)
4539 {
4540 errmsg = e_invarg;
4541 goto skip;
4542 }
4543 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004544 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4545 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004546 /* Allow negative (for 'undolevels'), octal and
4547 * hex numbers. */
4548 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004549 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4550 {
4551 errmsg = e_invarg;
4552 goto skip;
4553 }
4554 }
4555 else
4556 {
4557 errmsg = (char_u *)N_("E521: Number required after =");
4558 goto skip;
4559 }
4560
4561 if (adding)
4562 value = *(long *)varp + value;
4563 if (prepending)
4564 value = *(long *)varp * value;
4565 if (removing)
4566 value = *(long *)varp - value;
4567 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004568 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004569 }
4570 else if (opt_idx >= 0) /* string */
4571 {
4572 char_u *save_arg = NULL;
4573 char_u *s = NULL;
4574 char_u *oldval; /* previous value if *varp */
4575 char_u *newval;
4576 char_u *origval;
4577 unsigned newlen;
4578 int comma;
4579 int bs;
4580 int new_value_alloced; /* new string option
4581 was allocated */
4582
4583 /* When using ":set opt=val" for a global option
4584 * with a local value the local value will be
4585 * reset, use the global value here. */
4586 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004587 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004588 varp = options[opt_idx].var;
4589
4590 /* The old value is kept until we are sure that the
4591 * new value is valid. */
4592 oldval = *(char_u **)varp;
4593 if (nextchar == '&') /* set to default val */
4594 {
4595 newval = options[opt_idx].def_val[
4596 ((flags & P_VI_DEF) || cp_val)
4597 ? VI_DEFAULT : VIM_DEFAULT];
4598 if ((char_u **)varp == &p_bg)
4599 {
4600 /* guess the value of 'background' */
4601#ifdef FEAT_GUI
4602 if (gui.in_use)
4603 newval = gui_bg_default();
4604 else
4605#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004606 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004607 }
4608
4609 /* expand environment variables and ~ (since the
4610 * default value was already expanded, only
4611 * required when an environment variable was set
4612 * later */
4613 if (newval == NULL)
4614 newval = empty_option;
4615 else
4616 {
4617 s = option_expand(opt_idx, newval);
4618 if (s == NULL)
4619 s = newval;
4620 newval = vim_strsave(s);
4621 }
4622 new_value_alloced = TRUE;
4623 }
4624 else if (nextchar == '<') /* set to global val */
4625 {
4626 newval = vim_strsave(*(char_u **)get_varp_scope(
4627 &(options[opt_idx]), OPT_GLOBAL));
4628 new_value_alloced = TRUE;
4629 }
4630 else
4631 {
4632 ++arg; /* jump to after the '=' or ':' */
4633
4634 /*
4635 * Set 'keywordprg' to ":help" if an empty
4636 * value was passed to :set by the user.
4637 * Misuse errbuf[] for the resulting string.
4638 */
4639 if (varp == (char_u *)&p_kp
4640 && (*arg == NUL || *arg == ' '))
4641 {
4642 STRCPY(errbuf, ":help");
4643 save_arg = arg;
4644 arg = errbuf;
4645 }
4646 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004647 * Convert 'backspace' number to string, for
4648 * adding, prepending and removing string.
4649 */
4650 else if (varp == (char_u *)&p_bs
4651 && VIM_ISDIGIT(**(char_u **)varp))
4652 {
4653 i = getdigits((char_u **)varp);
4654 switch (i)
4655 {
4656 case 0:
4657 *(char_u **)varp = empty_option;
4658 break;
4659 case 1:
4660 *(char_u **)varp = vim_strsave(
4661 (char_u *)"indent,eol");
4662 break;
4663 case 2:
4664 *(char_u **)varp = vim_strsave(
4665 (char_u *)"indent,eol,start");
4666 break;
4667 }
4668 vim_free(oldval);
4669 oldval = *(char_u **)varp;
4670 }
4671 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004672 * Convert 'whichwrap' number to string, for
4673 * backwards compatibility with Vim 3.0.
4674 * Misuse errbuf[] for the resulting string.
4675 */
4676 else if (varp == (char_u *)&p_ww
4677 && VIM_ISDIGIT(*arg))
4678 {
4679 *errbuf = NUL;
4680 i = getdigits(&arg);
4681 if (i & 1)
4682 STRCAT(errbuf, "b,");
4683 if (i & 2)
4684 STRCAT(errbuf, "s,");
4685 if (i & 4)
4686 STRCAT(errbuf, "h,l,");
4687 if (i & 8)
4688 STRCAT(errbuf, "<,>,");
4689 if (i & 16)
4690 STRCAT(errbuf, "[,],");
4691 if (*errbuf != NUL) /* remove trailing , */
4692 errbuf[STRLEN(errbuf) - 1] = NUL;
4693 save_arg = arg;
4694 arg = errbuf;
4695 }
4696 /*
4697 * Remove '>' before 'dir' and 'bdir', for
4698 * backwards compatibility with version 3.0
4699 */
4700 else if ( *arg == '>'
4701 && (varp == (char_u *)&p_dir
4702 || varp == (char_u *)&p_bdir))
4703 {
4704 ++arg;
4705 }
4706
4707 /* When setting the local value of a global
4708 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004709 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004710 && (opt_flags & OPT_LOCAL))
4711 origval = *(char_u **)get_varp(
4712 &options[opt_idx]);
4713 else
4714 origval = oldval;
4715
4716 /*
4717 * Copy the new string into allocated memory.
4718 * Can't use set_string_option_direct(), because
4719 * we need to remove the backslashes.
4720 */
4721 /* get a bit too much */
4722 newlen = (unsigned)STRLEN(arg) + 1;
4723 if (adding || prepending || removing)
4724 newlen += (unsigned)STRLEN(origval) + 1;
4725 newval = alloc(newlen);
4726 if (newval == NULL) /* out of mem, don't change */
4727 break;
4728 s = newval;
4729
4730 /*
4731 * Copy the string, skip over escaped chars.
4732 * For MS-DOS and WIN32 backslashes before normal
4733 * file name characters are not removed, and keep
4734 * backslash at start, for "\\machine\path", but
4735 * do remove it for "\\\\machine\\path".
4736 * The reverse is found in ExpandOldSetting().
4737 */
4738 while (*arg && !vim_iswhite(*arg))
4739 {
4740 if (*arg == '\\' && arg[1] != NUL
4741#ifdef BACKSLASH_IN_FILENAME
4742 && !((flags & P_EXPAND)
4743 && vim_isfilec(arg[1])
4744 && (arg[1] != '\\'
4745 || (s == newval
4746 && arg[2] != '\\')))
4747#endif
4748 )
4749 ++arg; /* remove backslash */
4750#ifdef FEAT_MBYTE
4751 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004752 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004753 {
4754 /* copy multibyte char */
4755 mch_memmove(s, arg, (size_t)i);
4756 arg += i;
4757 s += i;
4758 }
4759 else
4760#endif
4761 *s++ = *arg++;
4762 }
4763 *s = NUL;
4764
4765 /*
4766 * Expand environment variables and ~.
4767 * Don't do it when adding without inserting a
4768 * comma.
4769 */
4770 if (!(adding || prepending || removing)
4771 || (flags & P_COMMA))
4772 {
4773 s = option_expand(opt_idx, newval);
4774 if (s != NULL)
4775 {
4776 vim_free(newval);
4777 newlen = (unsigned)STRLEN(s) + 1;
4778 if (adding || prepending || removing)
4779 newlen += (unsigned)STRLEN(origval) + 1;
4780 newval = alloc(newlen);
4781 if (newval == NULL)
4782 break;
4783 STRCPY(newval, s);
4784 }
4785 }
4786
4787 /* locate newval[] in origval[] when removing it
4788 * and when adding to avoid duplicates */
4789 i = 0; /* init for GCC */
4790 if (removing || (flags & P_NODUP))
4791 {
4792 i = (int)STRLEN(newval);
4793 bs = 0;
4794 for (s = origval; *s; ++s)
4795 {
4796 if ((!(flags & P_COMMA)
4797 || s == origval
4798 || (s[-1] == ',' && !(bs & 1)))
4799 && STRNCMP(s, newval, i) == 0
4800 && (!(flags & P_COMMA)
4801 || s[i] == ','
4802 || s[i] == NUL))
4803 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004804 /* Count backslashes. Only a comma with an
4805 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004806 * recognized as a separator */
4807 if (s > origval && s[-1] == '\\')
4808 ++bs;
4809 else
4810 bs = 0;
4811 }
4812
4813 /* do not add if already there */
4814 if ((adding || prepending) && *s)
4815 {
4816 prepending = FALSE;
4817 adding = FALSE;
4818 STRCPY(newval, origval);
4819 }
4820 }
4821
4822 /* concatenate the two strings; add a ',' if
4823 * needed */
4824 if (adding || prepending)
4825 {
4826 comma = ((flags & P_COMMA) && *origval != NUL
4827 && *newval != NUL);
4828 if (adding)
4829 {
4830 i = (int)STRLEN(origval);
4831 mch_memmove(newval + i + comma, newval,
4832 STRLEN(newval) + 1);
4833 mch_memmove(newval, origval, (size_t)i);
4834 }
4835 else
4836 {
4837 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004838 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004839 }
4840 if (comma)
4841 newval[i] = ',';
4842 }
4843
4844 /* Remove newval[] from origval[]. (Note: "i" has
4845 * been set above and is used here). */
4846 if (removing)
4847 {
4848 STRCPY(newval, origval);
4849 if (*s)
4850 {
4851 /* may need to remove a comma */
4852 if (flags & P_COMMA)
4853 {
4854 if (s == origval)
4855 {
4856 /* include comma after string */
4857 if (s[i] == ',')
4858 ++i;
4859 }
4860 else
4861 {
4862 /* include comma before string */
4863 --s;
4864 ++i;
4865 }
4866 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004867 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004868 }
4869 }
4870
4871 if (flags & P_FLAGLIST)
4872 {
4873 /* Remove flags that appear twice. */
4874 for (s = newval; *s; ++s)
4875 if ((!(flags & P_COMMA) || *s != ',')
4876 && vim_strchr(s + 1, *s) != NULL)
4877 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004878 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004879 --s;
4880 }
4881 }
4882
4883 if (save_arg != NULL) /* number for 'whichwrap' */
4884 arg = save_arg;
4885 new_value_alloced = TRUE;
4886 }
4887
4888 /* Set the new value. */
4889 *(char_u **)(varp) = newval;
4890
4891 /* Handle side effects, and set the global value for
4892 * ":set" on local options. */
4893 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4894 new_value_alloced, oldval, errbuf, opt_flags);
4895
4896 /* If error detected, print the error message. */
4897 if (errmsg != NULL)
4898 goto skip;
4899 }
4900 else /* key code option */
4901 {
4902 char_u *p;
4903
4904 if (nextchar == '&')
4905 {
4906 if (add_termcap_entry(key_name, TRUE) == FAIL)
4907 errmsg = (char_u *)N_("E522: Not found in termcap");
4908 }
4909 else
4910 {
4911 ++arg; /* jump to after the '=' or ':' */
4912 for (p = arg; *p && !vim_iswhite(*p); ++p)
4913 if (*p == '\\' && p[1] != NUL)
4914 ++p;
4915 nextchar = *p;
4916 *p = NUL;
4917 add_termcode(key_name, arg, FALSE);
4918 *p = nextchar;
4919 }
4920 if (full_screen)
4921 ttest(FALSE);
4922 redraw_all_later(CLEAR);
4923 }
4924 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004925
Bram Moolenaar071d4272004-06-13 20:20:40 +00004926 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004927 did_set_option(opt_idx, opt_flags,
4928 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004929 }
4930
4931skip:
4932 /*
4933 * Advance to next argument.
4934 * - skip until a blank found, taking care of backslashes
4935 * - skip blanks
4936 * - skip one "=val" argument (for hidden options ":set gfn =xx")
4937 */
4938 for (i = 0; i < 2 ; ++i)
4939 {
4940 while (*arg != NUL && !vim_iswhite(*arg))
4941 if (*arg++ == '\\' && *arg != NUL)
4942 ++arg;
4943 arg = skipwhite(arg);
4944 if (*arg != '=')
4945 break;
4946 }
4947 }
4948
4949 if (errmsg != NULL)
4950 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00004951 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00004952 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004953 if (i + (arg - startarg) < IOSIZE)
4954 {
4955 /* append the argument with the error */
4956 STRCAT(IObuff, ": ");
4957 mch_memmove(IObuff + i, startarg, (arg - startarg));
4958 IObuff[i + (arg - startarg)] = NUL;
4959 }
4960 /* make sure all characters are printable */
4961 trans_characters(IObuff, IOSIZE);
4962
4963 ++no_wait_return; /* wait_return done later */
4964 emsg(IObuff); /* show error highlighted */
4965 --no_wait_return;
4966
4967 return FAIL;
4968 }
4969
4970 arg = skipwhite(arg);
4971 }
4972
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004973theend:
4974 if (silent_mode && did_show)
4975 {
4976 /* After displaying option values in silent mode. */
4977 silent_mode = FALSE;
4978 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
4979 msg_putchar('\n');
4980 cursor_on(); /* msg_start() switches it off */
4981 out_flush();
4982 silent_mode = TRUE;
4983 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
4984 }
4985
Bram Moolenaar071d4272004-06-13 20:20:40 +00004986 return OK;
4987}
4988
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004989/*
4990 * Call this when an option has been given a new value through a user command.
4991 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
4992 */
4993 static void
4994did_set_option(opt_idx, opt_flags, new_value)
4995 int opt_idx;
4996 int opt_flags; /* possibly with OPT_MODELINE */
4997 int new_value; /* value was replaced completely */
4998{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004999 long_u *p;
5000
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005001 options[opt_idx].flags |= P_WAS_SET;
5002
5003 /* When an option is set in the sandbox, from a modeline or in secure mode
5004 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005005 * flag. */
5006 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005007 if (secure
5008#ifdef HAVE_SANDBOX
5009 || sandbox != 0
5010#endif
5011 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005012 *p = *p | P_INSECURE;
5013 else if (new_value)
5014 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005015}
5016
Bram Moolenaar071d4272004-06-13 20:20:40 +00005017 static char_u *
5018illegal_char(errbuf, c)
5019 char_u *errbuf;
5020 int c;
5021{
5022 if (errbuf == NULL)
5023 return (char_u *)"";
5024 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005025 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005026 return errbuf;
5027}
5028
5029/*
5030 * Convert a key name or string into a key value.
5031 * Used for 'wildchar' and 'cedit' options.
5032 */
5033 static int
5034string_to_key(arg)
5035 char_u *arg;
5036{
5037 if (*arg == '<')
5038 return find_key_option(arg + 1);
5039 if (*arg == '^')
5040 return Ctrl_chr(arg[1]);
5041 return *arg;
5042}
5043
5044#ifdef FEAT_CMDWIN
5045/*
5046 * Check value of 'cedit' and set cedit_key.
5047 * Returns NULL if value is OK, error message otherwise.
5048 */
5049 static char_u *
5050check_cedit()
5051{
5052 int n;
5053
5054 if (*p_cedit == NUL)
5055 cedit_key = -1;
5056 else
5057 {
5058 n = string_to_key(p_cedit);
5059 if (vim_isprintc(n))
5060 return e_invarg;
5061 cedit_key = n;
5062 }
5063 return NULL;
5064}
5065#endif
5066
5067#ifdef FEAT_TITLE
5068/*
5069 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5070 * maketitle() to create and display it.
5071 * When switching the title or icon off, call mch_restore_title() to get
5072 * the old value back.
5073 */
5074 static void
5075did_set_title(icon)
5076 int icon; /* Did set icon instead of title */
5077{
5078 if (starting != NO_SCREEN
5079#ifdef FEAT_GUI
5080 && !gui.starting
5081#endif
5082 )
5083 {
5084 maketitle();
5085 if (icon)
5086 {
5087 if (!p_icon)
5088 mch_restore_title(2);
5089 }
5090 else
5091 {
5092 if (!p_title)
5093 mch_restore_title(1);
5094 }
5095 }
5096}
5097#endif
5098
5099/*
5100 * set_options_bin - called when 'bin' changes value.
5101 */
5102 void
5103set_options_bin(oldval, newval, opt_flags)
5104 int oldval;
5105 int newval;
5106 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5107{
5108 /*
5109 * The option values that are changed when 'bin' changes are
5110 * copied when 'bin is set and restored when 'bin' is reset.
5111 */
5112 if (newval)
5113 {
5114 if (!oldval) /* switched on */
5115 {
5116 if (!(opt_flags & OPT_GLOBAL))
5117 {
5118 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5119 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5120 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5121 curbuf->b_p_et_nobin = curbuf->b_p_et;
5122 }
5123 if (!(opt_flags & OPT_LOCAL))
5124 {
5125 p_tw_nobin = p_tw;
5126 p_wm_nobin = p_wm;
5127 p_ml_nobin = p_ml;
5128 p_et_nobin = p_et;
5129 }
5130 }
5131
5132 if (!(opt_flags & OPT_GLOBAL))
5133 {
5134 curbuf->b_p_tw = 0; /* no automatic line wrap */
5135 curbuf->b_p_wm = 0; /* no automatic line wrap */
5136 curbuf->b_p_ml = 0; /* no modelines */
5137 curbuf->b_p_et = 0; /* no expandtab */
5138 }
5139 if (!(opt_flags & OPT_LOCAL))
5140 {
5141 p_tw = 0;
5142 p_wm = 0;
5143 p_ml = FALSE;
5144 p_et = FALSE;
5145 p_bin = TRUE; /* needed when called for the "-b" argument */
5146 }
5147 }
5148 else if (oldval) /* switched off */
5149 {
5150 if (!(opt_flags & OPT_GLOBAL))
5151 {
5152 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5153 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5154 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5155 curbuf->b_p_et = curbuf->b_p_et_nobin;
5156 }
5157 if (!(opt_flags & OPT_LOCAL))
5158 {
5159 p_tw = p_tw_nobin;
5160 p_wm = p_wm_nobin;
5161 p_ml = p_ml_nobin;
5162 p_et = p_et_nobin;
5163 }
5164 }
5165}
5166
5167#ifdef FEAT_VIMINFO
5168/*
5169 * Find the parameter represented by the given character (eg ', :, ", or /),
5170 * and return its associated value in the 'viminfo' string.
5171 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005172 * If the parameter is not specified in the string or there is no following
5173 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005174 */
5175 int
5176get_viminfo_parameter(type)
5177 int type;
5178{
5179 char_u *p;
5180
5181 p = find_viminfo_parameter(type);
5182 if (p != NULL && VIM_ISDIGIT(*p))
5183 return atoi((char *)p);
5184 return -1;
5185}
5186
5187/*
5188 * Find the parameter represented by the given character (eg ''', ':', '"', or
5189 * '/') in the 'viminfo' option and return a pointer to the string after it.
5190 * Return NULL if the parameter is not specified in the string.
5191 */
5192 char_u *
5193find_viminfo_parameter(type)
5194 int type;
5195{
5196 char_u *p;
5197
5198 for (p = p_viminfo; *p; ++p)
5199 {
5200 if (*p == type)
5201 return p + 1;
5202 if (*p == 'n') /* 'n' is always the last one */
5203 break;
5204 p = vim_strchr(p, ','); /* skip until next ',' */
5205 if (p == NULL) /* hit the end without finding parameter */
5206 break;
5207 }
5208 return NULL;
5209}
5210#endif
5211
5212/*
5213 * Expand environment variables for some string options.
5214 * These string options cannot be indirect!
5215 * If "val" is NULL expand the current value of the option.
5216 * Return pointer to NameBuff, or NULL when not expanded.
5217 */
5218 static char_u *
5219option_expand(opt_idx, val)
5220 int opt_idx;
5221 char_u *val;
5222{
5223 /* if option doesn't need expansion nothing to do */
5224 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5225 return NULL;
5226
5227 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5228 * expand_env() would truncate the string. */
5229 if (val != NULL && STRLEN(val) > MAXPATHL)
5230 return NULL;
5231
5232 if (val == NULL)
5233 val = *(char_u **)options[opt_idx].var;
5234
5235 /*
5236 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5237 * Escape spaces when expanding 'tags', they are used to separate file
5238 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005239 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005240 */
5241 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005242 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005243#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005244 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5245#endif
5246 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005247 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5248 return NULL;
5249
5250 return NameBuff;
5251}
5252
5253/*
5254 * After setting various option values: recompute variables that depend on
5255 * option values.
5256 */
5257 static void
5258didset_options()
5259{
5260 /* initialize the table for 'iskeyword' et.al. */
5261 (void)init_chartab();
5262
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005263#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005264 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005265#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005266 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
5267#ifdef FEAT_SESSION
5268 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5269 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5270#endif
5271#ifdef FEAT_FOLDING
5272 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5273#endif
5274 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
5275#ifdef FEAT_VIRTUALEDIT
5276 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5277#endif
5278#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5279 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5280#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005281#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005282 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005283 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005284 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005285#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005286#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5287 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5288#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005289#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5291#endif
5292#ifdef FEAT_CMDWIN
5293 /* set cedit_key */
5294 (void)check_cedit();
5295#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005296#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005297 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005298#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005299}
5300
5301/*
5302 * Check for string options that are NULL (normally only termcap options).
5303 */
5304 void
5305check_options()
5306{
5307 int opt_idx;
5308
5309 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5310 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5311 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5312}
5313
5314/*
5315 * Check string options in a buffer for NULL value.
5316 */
5317 void
5318check_buf_options(buf)
5319 buf_T *buf;
5320{
5321#if defined(FEAT_QUICKFIX)
5322 check_string_option(&buf->b_p_bh);
5323 check_string_option(&buf->b_p_bt);
5324#endif
5325#ifdef FEAT_MBYTE
5326 check_string_option(&buf->b_p_fenc);
5327#endif
5328 check_string_option(&buf->b_p_ff);
5329#ifdef FEAT_FIND_ID
5330 check_string_option(&buf->b_p_def);
5331 check_string_option(&buf->b_p_inc);
5332# ifdef FEAT_EVAL
5333 check_string_option(&buf->b_p_inex);
5334# endif
5335#endif
5336#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5337 check_string_option(&buf->b_p_inde);
5338 check_string_option(&buf->b_p_indk);
5339#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005340#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5341 check_string_option(&buf->b_p_bexpr);
5342#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005343#if defined(FEAT_CRYPT)
5344 check_string_option(&buf->b_p_cm);
5345#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005346#if defined(FEAT_EVAL)
5347 check_string_option(&buf->b_p_fex);
5348#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349#ifdef FEAT_CRYPT
5350 check_string_option(&buf->b_p_key);
5351#endif
5352 check_string_option(&buf->b_p_kp);
5353 check_string_option(&buf->b_p_mps);
5354 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005355 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005356 check_string_option(&buf->b_p_isk);
5357#ifdef FEAT_COMMENTS
5358 check_string_option(&buf->b_p_com);
5359#endif
5360#ifdef FEAT_FOLDING
5361 check_string_option(&buf->b_p_cms);
5362#endif
5363 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005364#ifdef FEAT_TEXTOBJ
5365 check_string_option(&buf->b_p_qe);
5366#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005367#ifdef FEAT_SYN_HL
5368 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005369#endif
5370#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005371 check_string_option(&buf->b_s.b_p_spc);
5372 check_string_option(&buf->b_s.b_p_spf);
5373 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374#endif
5375#ifdef FEAT_SEARCHPATH
5376 check_string_option(&buf->b_p_sua);
5377#endif
5378#ifdef FEAT_CINDENT
5379 check_string_option(&buf->b_p_cink);
5380 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005381 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005382#endif
5383#ifdef FEAT_AUTOCMD
5384 check_string_option(&buf->b_p_ft);
5385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005386#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5387 check_string_option(&buf->b_p_cinw);
5388#endif
5389#ifdef FEAT_INS_EXPAND
5390 check_string_option(&buf->b_p_cpt);
5391#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005392#ifdef FEAT_COMPL_FUNC
5393 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005394 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005396#ifdef FEAT_KEYMAP
5397 check_string_option(&buf->b_p_keymap);
5398#endif
5399#ifdef FEAT_QUICKFIX
5400 check_string_option(&buf->b_p_gp);
5401 check_string_option(&buf->b_p_mp);
5402 check_string_option(&buf->b_p_efm);
5403#endif
5404 check_string_option(&buf->b_p_ep);
5405 check_string_option(&buf->b_p_path);
5406 check_string_option(&buf->b_p_tags);
5407#ifdef FEAT_INS_EXPAND
5408 check_string_option(&buf->b_p_dict);
5409 check_string_option(&buf->b_p_tsr);
5410#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005411#ifdef FEAT_LISP
5412 check_string_option(&buf->b_p_lw);
5413#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005414 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005415}
5416
5417/*
5418 * Free the string allocated for an option.
5419 * Checks for the string being empty_option. This may happen if we're out of
5420 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5421 * check_options().
5422 * Does NOT check for P_ALLOCED flag!
5423 */
5424 void
5425free_string_option(p)
5426 char_u *p;
5427{
5428 if (p != empty_option)
5429 vim_free(p);
5430}
5431
5432 void
5433clear_string_option(pp)
5434 char_u **pp;
5435{
5436 if (*pp != empty_option)
5437 vim_free(*pp);
5438 *pp = empty_option;
5439}
5440
5441 static void
5442check_string_option(pp)
5443 char_u **pp;
5444{
5445 if (*pp == NULL)
5446 *pp = empty_option;
5447}
5448
5449/*
5450 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5451 */
5452 void
5453set_term_option_alloced(p)
5454 char_u **p;
5455{
5456 int opt_idx;
5457
5458 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5459 if (options[opt_idx].var == (char_u *)p)
5460 {
5461 options[opt_idx].flags |= P_ALLOCED;
5462 return;
5463 }
5464 return; /* cannot happen: didn't find it! */
5465}
5466
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005467#if defined(FEAT_EVAL) || defined(PROTO)
5468/*
5469 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5470 * Return FALSE when it wasn't.
5471 * Return -1 for an unknown option.
5472 */
5473 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005474was_set_insecurely(opt, opt_flags)
5475 char_u *opt;
5476 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005477{
5478 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005479 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005480
5481 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005482 {
5483 flagp = insecure_flag(idx, opt_flags);
5484 return (*flagp & P_INSECURE) != 0;
5485 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005486 EMSG2(_(e_intern2), "was_set_insecurely()");
5487 return -1;
5488}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005489
5490/*
5491 * Get a pointer to the flags used for the P_INSECURE flag of option
5492 * "opt_idx". For some local options a local flags field is used.
5493 */
5494 static long_u *
5495insecure_flag(opt_idx, opt_flags)
5496 int opt_idx;
5497 int opt_flags;
5498{
5499 if (opt_flags & OPT_LOCAL)
5500 switch ((int)options[opt_idx].indir)
5501 {
5502#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005503 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005504#endif
5505#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005506# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005507 case PV_FDE: return &curwin->w_p_fde_flags;
5508 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005509# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005510# ifdef FEAT_BEVAL
5511 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5512# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005513# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005514 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005515# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005516 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005517# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005518 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005519# endif
5520#endif
5521 }
5522
5523 /* Nothing special, return global flags field. */
5524 return &options[opt_idx].flags;
5525}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005526#endif
5527
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005528#ifdef FEAT_TITLE
5529static void redraw_titles __ARGS((void));
5530
5531/*
5532 * Redraw the window title and/or tab page text later.
5533 */
5534static void redraw_titles()
5535{
5536 need_maketitle = TRUE;
5537# ifdef FEAT_WINDOWS
5538 redraw_tabline = TRUE;
5539# endif
5540}
5541#endif
5542
Bram Moolenaar071d4272004-06-13 20:20:40 +00005543/*
5544 * Set a string option to a new value (without checking the effect).
5545 * The string is copied into allocated memory.
5546 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005547 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005548 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549 */
5550 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005551set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005552 char_u *name;
5553 int opt_idx;
5554 char_u *val;
5555 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005556 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005557{
5558 char_u *s;
5559 char_u **varp;
5560 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005561 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005562
Bram Moolenaar89d40322006-08-29 15:30:07 +00005563 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005565 idx = findoption(name);
5566 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005567 {
5568 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005569 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005570 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005571 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005572 }
5573
Bram Moolenaar89d40322006-08-29 15:30:07 +00005574 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575 return;
5576
5577 s = vim_strsave(val);
5578 if (s != NULL)
5579 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005580 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005582 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583 free_string_option(*varp);
5584 *varp = s;
5585
5586 /* For buffer/window local option may also set the global value. */
5587 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005588 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589
Bram Moolenaar89d40322006-08-29 15:30:07 +00005590 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591
5592 /* When setting both values of a global option with a local value,
5593 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005594 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005595 {
5596 free_string_option(*varp);
5597 *varp = empty_option;
5598 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005599# ifdef FEAT_EVAL
5600 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005601 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005602 set_sid == 0 ? current_SID : set_sid);
5603# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005604 }
5605}
5606
5607/*
5608 * Set global value for string option when it's a local option.
5609 */
5610 static void
5611set_string_option_global(opt_idx, varp)
5612 int opt_idx; /* option index */
5613 char_u **varp; /* pointer to option variable */
5614{
5615 char_u **p, *s;
5616
5617 /* the global value is always allocated */
5618 if (options[opt_idx].var == VAR_WIN)
5619 p = (char_u **)GLOBAL_WO(varp);
5620 else
5621 p = (char_u **)options[opt_idx].var;
5622 if (options[opt_idx].indir != PV_NONE
5623 && p != varp
5624 && (s = vim_strsave(*varp)) != NULL)
5625 {
5626 free_string_option(*p);
5627 *p = s;
5628 }
5629}
5630
5631/*
5632 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005633 *
5634 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005635 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005636 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005637set_string_option(opt_idx, value, opt_flags)
5638 int opt_idx;
5639 char_u *value;
5640 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5641{
5642 char_u *s;
5643 char_u **varp;
5644 char_u *oldval;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005645 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005646
5647 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005648 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649
5650 s = vim_strsave(value);
5651 if (s != NULL)
5652 {
5653 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5654 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005655 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005656 ? OPT_GLOBAL : OPT_LOCAL)
5657 : opt_flags);
5658 oldval = *varp;
5659 *varp = s;
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005660 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5661 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005662 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005664 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665}
5666
5667/*
5668 * Handle string options that need some action to perform when changed.
5669 * Returns NULL for success, or an error message for an error.
5670 */
5671 static char_u *
5672did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5673 opt_flags)
5674 int opt_idx; /* index in options[] table */
5675 char_u **varp; /* pointer to the option variable */
5676 int new_value_alloced; /* new value was allocated */
5677 char_u *oldval; /* previous value of the option */
5678 char_u *errbuf; /* buffer for errors, or NULL */
5679 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5680{
5681 char_u *errmsg = NULL;
5682 char_u *s, *p;
5683 int did_chartab = FALSE;
5684 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005685 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005686#ifdef FEAT_GUI
5687 /* set when changing an option that only requires a redraw in the GUI */
5688 int redraw_gui_only = FALSE;
5689#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690
5691 /* Get the global option to compare with, otherwise we would have to check
5692 * two values for all local options. */
5693 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5694
5695 /* Disallow changing some options from secure mode */
5696 if ((secure
5697#ifdef HAVE_SANDBOX
5698 || sandbox != 0
5699#endif
5700 ) && (options[opt_idx].flags & P_SECURE))
5701 {
5702 errmsg = e_secure;
5703 }
5704
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005705 /* Check for a "normal" file name in some options. Disallow a path
5706 * separator (slash and/or backslash), wildcards and characters that are
5707 * often illegal in a file name. */
5708 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005709 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005710 {
5711 errmsg = e_invarg;
5712 }
5713
Bram Moolenaar071d4272004-06-13 20:20:40 +00005714 /* 'term' */
5715 else if (varp == &T_NAME)
5716 {
5717 if (T_NAME[0] == NUL)
5718 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5719#ifdef FEAT_GUI
5720 if (gui.in_use)
5721 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5722 else if (term_is_gui(T_NAME))
5723 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5724#endif
5725 else if (set_termname(T_NAME) == FAIL)
5726 errmsg = (char_u *)N_("E522: Not found in termcap");
5727 else
5728 /* Screen colors may have changed. */
5729 redraw_later_clear();
5730 }
5731
5732 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005733 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005734 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005735 char_u *bkc = p_bkc;
5736 unsigned int *flags = &bkc_flags;
5737
5738 if (opt_flags & OPT_LOCAL)
5739 {
5740 bkc = curbuf->b_p_bkc;
5741 flags = &curbuf->b_bkc_flags;
5742 }
5743
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005744 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5745 /* make the local value empty: use the global value */
5746 *flags = 0;
5747 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005748 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005749 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5750 errmsg = e_invarg;
5751 if ((((int)*flags & BKC_AUTO) != 0)
5752 + (((int)*flags & BKC_YES) != 0)
5753 + (((int)*flags & BKC_NO) != 0) != 1)
5754 {
5755 /* Must have exactly one of "auto", "yes" and "no". */
5756 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5757 errmsg = e_invarg;
5758 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005759 }
5760 }
5761
5762 /* 'backupext' and 'patchmode' */
5763 else if (varp == &p_bex || varp == &p_pm)
5764 {
5765 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5766 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5767 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5768 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005769#ifdef FEAT_LINEBREAK
5770 /* 'breakindentopt' */
5771 else if (varp == &curwin->w_p_briopt)
5772 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005773 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005774 errmsg = e_invarg;
5775 }
5776#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005777
5778 /*
5779 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5780 * If the new option is invalid, use old value. 'lisp' option: refill
5781 * chartab[] for '-' char
5782 */
5783 else if ( varp == &p_isi
5784 || varp == &(curbuf->b_p_isk)
5785 || varp == &p_isp
5786 || varp == &p_isf)
5787 {
5788 if (init_chartab() == FAIL)
5789 {
5790 did_chartab = TRUE; /* need to restore it below */
5791 errmsg = e_invarg; /* error in value */
5792 }
5793 }
5794
5795 /* 'helpfile' */
5796 else if (varp == &p_hf)
5797 {
5798 /* May compute new values for $VIM and $VIMRUNTIME */
5799 if (didset_vim)
5800 {
5801 vim_setenv((char_u *)"VIM", (char_u *)"");
5802 didset_vim = FALSE;
5803 }
5804 if (didset_vimruntime)
5805 {
5806 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5807 didset_vimruntime = FALSE;
5808 }
5809 }
5810
Bram Moolenaar1a384422010-07-14 19:53:30 +02005811#ifdef FEAT_SYN_HL
5812 /* 'colorcolumn' */
5813 else if (varp == &curwin->w_p_cc)
5814 errmsg = check_colorcolumn(curwin);
5815#endif
5816
Bram Moolenaar071d4272004-06-13 20:20:40 +00005817#ifdef FEAT_MULTI_LANG
5818 /* 'helplang' */
5819 else if (varp == &p_hlg)
5820 {
5821 /* Check for "", "ab", "ab,cd", etc. */
5822 for (s = p_hlg; *s != NUL; s += 3)
5823 {
5824 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5825 {
5826 errmsg = e_invarg;
5827 break;
5828 }
5829 if (s[2] == NUL)
5830 break;
5831 }
5832 }
5833#endif
5834
5835 /* 'highlight' */
5836 else if (varp == &p_hl)
5837 {
5838 if (highlight_changed() == FAIL)
5839 errmsg = e_invarg; /* invalid flags */
5840 }
5841
5842 /* 'nrformats' */
5843 else if (gvarp == &p_nf)
5844 {
5845 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5846 errmsg = e_invarg;
5847 }
5848
5849#ifdef FEAT_SESSION
5850 /* 'sessionoptions' */
5851 else if (varp == &p_ssop)
5852 {
5853 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5854 errmsg = e_invarg;
5855 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5856 {
5857 /* Don't allow both "sesdir" and "curdir". */
5858 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5859 errmsg = e_invarg;
5860 }
5861 }
5862 /* 'viewoptions' */
5863 else if (varp == &p_vop)
5864 {
5865 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5866 errmsg = e_invarg;
5867 }
5868#endif
5869
5870 /* 'scrollopt' */
5871#ifdef FEAT_SCROLLBIND
5872 else if (varp == &p_sbo)
5873 {
5874 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
5875 errmsg = e_invarg;
5876 }
5877#endif
5878
5879 /* 'ambiwidth' */
5880#ifdef FEAT_MBYTE
5881 else if (varp == &p_ambw)
5882 {
5883 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
5884 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02005885 else if (set_chars_option(&p_lcs) != NULL)
5886 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
5887# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5888 else if (set_chars_option(&p_fcs) != NULL)
5889 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
5890# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891 }
5892#endif
5893
5894 /* 'background' */
5895 else if (varp == &p_bg)
5896 {
5897 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
5898 {
5899#ifdef FEAT_EVAL
5900 int dark = (*p_bg == 'd');
5901#endif
5902
5903 init_highlight(FALSE, FALSE);
5904
5905#ifdef FEAT_EVAL
5906 if (dark != (*p_bg == 'd')
5907 && get_var_value((char_u *)"g:colors_name") != NULL)
5908 {
5909 /* The color scheme must have set 'background' back to another
5910 * value, that's not what we want here. Disable the color
5911 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00005912 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913 free_string_option(p_bg);
5914 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
5915 check_string_option(&p_bg);
5916 init_highlight(FALSE, FALSE);
5917 }
5918#endif
5919 }
5920 else
5921 errmsg = e_invarg;
5922 }
5923
5924 /* 'wildmode' */
5925 else if (varp == &p_wim)
5926 {
5927 if (check_opt_wim() == FAIL)
5928 errmsg = e_invarg;
5929 }
5930
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00005931#ifdef FEAT_CMDL_COMPL
5932 /* 'wildoptions' */
5933 else if (varp == &p_wop)
5934 {
5935 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
5936 errmsg = e_invarg;
5937 }
5938#endif
5939
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940#ifdef FEAT_WAK
5941 /* 'winaltkeys' */
5942 else if (varp == &p_wak)
5943 {
5944 if (*p_wak == NUL
5945 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
5946 errmsg = e_invarg;
5947# ifdef FEAT_MENU
5948# ifdef FEAT_GUI_MOTIF
5949 else if (gui.in_use)
5950 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5951# else
5952# ifdef FEAT_GUI_GTK
5953 else if (gui.in_use)
5954 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
5955# endif
5956# endif
5957# endif
5958 }
5959#endif
5960
5961#ifdef FEAT_AUTOCMD
5962 /* 'eventignore' */
5963 else if (varp == &p_ei)
5964 {
5965 if (check_ei() == FAIL)
5966 errmsg = e_invarg;
5967 }
5968#endif
5969
5970#ifdef FEAT_MBYTE
5971 /* 'encoding' and 'fileencoding' */
5972 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
5973 {
5974 if (gvarp == &p_fenc)
5975 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00005976 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977 errmsg = e_modifiable;
5978 else if (vim_strchr(*varp, ',') != NULL)
5979 /* No comma allowed in 'fileencoding'; catches confusing it
5980 * with 'fileencodings'. */
5981 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005982 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005983 {
5984# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005985 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005986 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005987# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005988 /* Add 'fileencoding' to the swap file. */
5989 ml_setflags(curbuf);
5990 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 }
5992 if (errmsg == NULL)
5993 {
5994 /* canonize the value, so that STRCMP() can be used on it */
5995 p = enc_canonize(*varp);
5996 if (p != NULL)
5997 {
5998 vim_free(*varp);
5999 *varp = p;
6000 }
6001 if (varp == &p_enc)
6002 {
6003 errmsg = mb_init();
6004# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006005 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006# endif
6007 }
6008 }
6009
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006010# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006011 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6012 {
6013 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6014 if (STRCMP(p_tenc, "utf-8") != 0)
6015 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6016 }
6017# endif
6018
6019 if (errmsg == NULL)
6020 {
6021# ifdef FEAT_KEYMAP
6022 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6023 * (with another encoding). */
6024 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6025 (void)keymap_init();
6026# endif
6027
6028 /* When 'termencoding' is not empty and 'encoding' changes or when
6029 * 'termencoding' changes, need to setup for keyboard input and
6030 * display output conversion. */
6031 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6032 {
6033 convert_setup(&input_conv, p_tenc, p_enc);
6034 convert_setup(&output_conv, p_enc, p_tenc);
6035 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006036
6037# if defined(WIN3264) && defined(FEAT_MBYTE)
6038 /* $HOME may have characters in active code page. */
6039 if (varp == &p_enc)
6040 init_homedir();
6041# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006042 }
6043 }
6044#endif
6045
6046#if defined(FEAT_POSTSCRIPT)
6047 else if (varp == &p_penc)
6048 {
6049 /* Canonize printencoding if VIM standard one */
6050 p = enc_canonize(p_penc);
6051 if (p != NULL)
6052 {
6053 vim_free(p_penc);
6054 p_penc = p;
6055 }
6056 else
6057 {
6058 /* Ensure lower case and '-' for '_' */
6059 for (s = p_penc; *s != NUL; s++)
6060 {
6061 if (*s == '_')
6062 *s = '-';
6063 else
6064 *s = TOLOWER_ASC(*s);
6065 }
6066 }
6067 }
6068#endif
6069
Bram Moolenaar9372a112005-12-06 19:59:18 +00006070#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006071 else if (varp == &p_imak)
6072 {
6073 if (gui.in_use && !im_xim_isvalid_imactivate())
6074 errmsg = e_invarg;
6075 }
6076#endif
6077
6078#ifdef FEAT_KEYMAP
6079 else if (varp == &curbuf->b_p_keymap)
6080 {
6081 /* load or unload key mapping tables */
6082 errmsg = keymap_init();
6083
Bram Moolenaarfab06232009-03-04 03:13:35 +00006084 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006085 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006086 if (*curbuf->b_p_keymap != NUL)
6087 {
6088 /* Installed a new keymap, switch on using it. */
6089 curbuf->b_p_iminsert = B_IMODE_LMAP;
6090 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6091 curbuf->b_p_imsearch = B_IMODE_LMAP;
6092 }
6093 else
6094 {
6095 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6096 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6097 curbuf->b_p_iminsert = B_IMODE_NONE;
6098 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6099 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6100 }
6101 if ((opt_flags & OPT_LOCAL) == 0)
6102 {
6103 set_iminsert_global();
6104 set_imsearch_global();
6105 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006106# ifdef FEAT_WINDOWS
6107 status_redraw_curbuf();
6108# endif
6109 }
6110 }
6111#endif
6112
6113 /* 'fileformat' */
6114 else if (gvarp == &p_ff)
6115 {
6116 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6117 errmsg = e_modifiable;
6118 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6119 errmsg = e_invarg;
6120 else
6121 {
6122 /* may also change 'textmode' */
6123 if (get_fileformat(curbuf) == EOL_DOS)
6124 curbuf->b_p_tx = TRUE;
6125 else
6126 curbuf->b_p_tx = FALSE;
6127#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006128 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006129#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006130 /* update flag in swap file */
6131 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006132 /* Redraw needed when switching to/from "mac": a CR in the text
6133 * will be displayed differently. */
6134 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6135 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006136 }
6137 }
6138
6139 /* 'fileformats' */
6140 else if (varp == &p_ffs)
6141 {
6142 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6143 errmsg = e_invarg;
6144 else
6145 {
6146 /* also change 'textauto' */
6147 if (*p_ffs == NUL)
6148 p_ta = FALSE;
6149 else
6150 p_ta = TRUE;
6151 }
6152 }
6153
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006154#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006155 /* 'cryptkey' */
6156 else if (gvarp == &p_key)
6157 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006158# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006159 /* Make sure the ":set" command doesn't show the new value in the
6160 * history. */
6161 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006162# endif
6163 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6164 /* Need to update the swapfile. */
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006165 ml_set_crypt_key(curbuf, oldval, crypt_get_method_nr(curbuf));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006166 }
6167
6168 else if (gvarp == &p_cm)
6169 {
6170 if (opt_flags & OPT_LOCAL)
6171 p = curbuf->b_p_cm;
6172 else
6173 p = p_cm;
6174 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6175 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006176 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006177 errmsg = e_invarg;
6178 else
6179 {
6180 /* When setting the global value to empty, make it "zip". */
6181 if (*p_cm == NUL)
6182 {
6183 if (new_value_alloced)
6184 free_string_option(p_cm);
6185 p_cm = vim_strsave((char_u *)"zip");
6186 new_value_alloced = TRUE;
6187 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006188 /* When using ":set cm=name" the local value is going to be empty.
6189 * Do that here, otherwise the crypt functions will still use the
6190 * local value. */
6191 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6192 {
6193 free_string_option(curbuf->b_p_cm);
6194 curbuf->b_p_cm = empty_option;
6195 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006196
6197 /* Need to update the swapfile when the effective method changed.
6198 * Set "s" to the effective old value, "p" to the effective new
6199 * method and compare. */
6200 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6201 s = p_cm; /* was previously using the global value */
6202 else
6203 s = oldval;
6204 if (*curbuf->b_p_cm == NUL)
6205 p = p_cm; /* is now using the global value */
6206 else
6207 p = curbuf->b_p_cm;
6208 if (STRCMP(s, p) != 0)
6209 ml_set_crypt_key(curbuf, curbuf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006210 crypt_method_nr_from_name(s));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006211
6212 /* If the global value changes need to update the swapfile for all
6213 * buffers using that value. */
6214 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6215 {
6216 buf_T *buf;
6217
6218 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6219 if (buf != curbuf && *buf->b_p_cm == NUL)
6220 ml_set_crypt_key(buf, buf->b_p_key,
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006221 crypt_method_nr_from_name(oldval));
Bram Moolenaar49771f42010-07-20 17:32:38 +02006222 }
6223 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006224 }
6225#endif
6226
6227 /* 'matchpairs' */
6228 else if (gvarp == &p_mps)
6229 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006230#ifdef FEAT_MBYTE
6231 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006232 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006233 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006234 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006235 int x2 = -1;
6236 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006237
6238 if (*p != NUL)
6239 p += mb_ptr2len(p);
6240 if (*p != NUL)
6241 x2 = *p++;
6242 if (*p != NUL)
6243 {
6244 x3 = mb_ptr2char(p);
6245 p += mb_ptr2len(p);
6246 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006247 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006248 {
6249 errmsg = e_invarg;
6250 break;
6251 }
6252 if (*p == NUL)
6253 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006254 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006255 }
6256 else
6257#endif
6258 {
6259 /* Check for "x:y,x:y" */
6260 for (p = *varp; *p != NUL; p += 4)
6261 {
6262 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6263 {
6264 errmsg = e_invarg;
6265 break;
6266 }
6267 if (p[3] == NUL)
6268 break;
6269 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006270 }
6271 }
6272
6273#ifdef FEAT_COMMENTS
6274 /* 'comments' */
6275 else if (gvarp == &p_com)
6276 {
6277 for (s = *varp; *s; )
6278 {
6279 while (*s && *s != ':')
6280 {
6281 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6282 && !VIM_ISDIGIT(*s) && *s != '-')
6283 {
6284 errmsg = illegal_char(errbuf, *s);
6285 break;
6286 }
6287 ++s;
6288 }
6289 if (*s++ == NUL)
6290 errmsg = (char_u *)N_("E524: Missing colon");
6291 else if (*s == ',' || *s == NUL)
6292 errmsg = (char_u *)N_("E525: Zero length string");
6293 if (errmsg != NULL)
6294 break;
6295 while (*s && *s != ',')
6296 {
6297 if (*s == '\\' && s[1] != NUL)
6298 ++s;
6299 ++s;
6300 }
6301 s = skip_to_option_part(s);
6302 }
6303 }
6304#endif
6305
6306 /* 'listchars' */
6307 else if (varp == &p_lcs)
6308 {
6309 errmsg = set_chars_option(varp);
6310 }
6311
6312#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6313 /* 'fillchars' */
6314 else if (varp == &p_fcs)
6315 {
6316 errmsg = set_chars_option(varp);
6317 }
6318#endif
6319
6320#ifdef FEAT_CMDWIN
6321 /* 'cedit' */
6322 else if (varp == &p_cedit)
6323 {
6324 errmsg = check_cedit();
6325 }
6326#endif
6327
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006328 /* 'verbosefile' */
6329 else if (varp == &p_vfile)
6330 {
6331 verbose_stop();
6332 if (*p_vfile != NUL && verbose_open() == FAIL)
6333 errmsg = e_invarg;
6334 }
6335
Bram Moolenaar071d4272004-06-13 20:20:40 +00006336#ifdef FEAT_VIMINFO
6337 /* 'viminfo' */
6338 else if (varp == &p_viminfo)
6339 {
6340 for (s = p_viminfo; *s;)
6341 {
6342 /* Check it's a valid character */
6343 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6344 {
6345 errmsg = illegal_char(errbuf, *s);
6346 break;
6347 }
6348 if (*s == 'n') /* name is always last one */
6349 {
6350 break;
6351 }
6352 else if (*s == 'r') /* skip until next ',' */
6353 {
6354 while (*++s && *s != ',')
6355 ;
6356 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006357 else if (*s == '%')
6358 {
6359 /* optional number */
6360 while (vim_isdigit(*++s))
6361 ;
6362 }
6363 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006364 ++s; /* no extra chars */
6365 else /* must have a number */
6366 {
6367 while (vim_isdigit(*++s))
6368 ;
6369
6370 if (!VIM_ISDIGIT(*(s - 1)))
6371 {
6372 if (errbuf != NULL)
6373 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006374 sprintf((char *)errbuf,
6375 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006376 transchar_byte(*(s - 1)));
6377 errmsg = errbuf;
6378 }
6379 else
6380 errmsg = (char_u *)"";
6381 break;
6382 }
6383 }
6384 if (*s == ',')
6385 ++s;
6386 else if (*s)
6387 {
6388 if (errbuf != NULL)
6389 errmsg = (char_u *)N_("E527: Missing comma");
6390 else
6391 errmsg = (char_u *)"";
6392 break;
6393 }
6394 }
6395 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6396 errmsg = (char_u *)N_("E528: Must specify a ' value");
6397 }
6398#endif /* FEAT_VIMINFO */
6399
6400 /* terminal options */
6401 else if (istermoption(&options[opt_idx]) && full_screen)
6402 {
6403 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6404 if (varp == &T_CCO)
6405 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006406 int colors = atoi((char *)T_CCO);
6407
6408 /* Only reinitialize colors if t_Co value has really changed to
6409 * avoid expensive reload of colorscheme if t_Co is set to the
6410 * same value multiple times. */
6411 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006412 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006413 t_colors = colors;
6414 if (t_colors <= 1)
6415 {
6416 if (new_value_alloced)
6417 vim_free(T_CCO);
6418 T_CCO = empty_option;
6419 }
6420 /* We now have a different color setup, initialize it again. */
6421 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006422 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006423 }
6424 ttest(FALSE);
6425 if (varp == &T_ME)
6426 {
6427 out_str(T_ME);
6428 redraw_later(CLEAR);
6429#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6430 /* Since t_me has been set, this probably means that the user
6431 * wants to use this as default colors. Need to reset default
6432 * background/foreground colors. */
6433 mch_set_normal_colors();
6434#endif
6435 }
6436 }
6437
6438#ifdef FEAT_LINEBREAK
6439 /* 'showbreak' */
6440 else if (varp == &p_sbr)
6441 {
6442 for (s = p_sbr; *s; )
6443 {
6444 if (ptr2cells(s) != 1)
6445 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006446 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006447 }
6448 }
6449#endif
6450
6451#ifdef FEAT_GUI
6452 /* 'guifont' */
6453 else if (varp == &p_guifont)
6454 {
6455 if (gui.in_use)
6456 {
6457 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006458# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006459 /*
6460 * Put up a font dialog and let the user select a new value.
6461 * If this is cancelled go back to the old value but don't
6462 * give an error message.
6463 */
6464 if (STRCMP(p, "*") == 0)
6465 {
6466 p = gui_mch_font_dialog(oldval);
6467
6468 if (new_value_alloced)
6469 free_string_option(p_guifont);
6470
6471 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6472 new_value_alloced = TRUE;
6473 }
6474# endif
6475 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6476 {
6477# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6478 if (STRCMP(p_guifont, "*") == 0)
6479 {
6480 /* Dialog was cancelled: Keep the old value without giving
6481 * an error message. */
6482 if (new_value_alloced)
6483 free_string_option(p_guifont);
6484 p_guifont = vim_strsave(oldval);
6485 new_value_alloced = TRUE;
6486 }
6487 else
6488# endif
6489 errmsg = (char_u *)N_("E596: Invalid font(s)");
6490 }
6491 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006492 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006493 }
6494# ifdef FEAT_XFONTSET
6495 else if (varp == &p_guifontset)
6496 {
6497 if (STRCMP(p_guifontset, "*") == 0)
6498 errmsg = (char_u *)N_("E597: can't select fontset");
6499 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6500 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006501 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006502 }
6503# endif
6504# ifdef FEAT_MBYTE
6505 else if (varp == &p_guifontwide)
6506 {
6507 if (STRCMP(p_guifontwide, "*") == 0)
6508 errmsg = (char_u *)N_("E533: can't select wide font");
6509 else if (gui_get_wide_font() == FAIL)
6510 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006511 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006512 }
6513# endif
6514#endif
6515
6516#ifdef CURSOR_SHAPE
6517 /* 'guicursor' */
6518 else if (varp == &p_guicursor)
6519 errmsg = parse_shape_opt(SHAPE_CURSOR);
6520#endif
6521
6522#ifdef FEAT_MOUSESHAPE
6523 /* 'mouseshape' */
6524 else if (varp == &p_mouseshape)
6525 {
6526 errmsg = parse_shape_opt(SHAPE_MOUSE);
6527 update_mouseshape(-1);
6528 }
6529#endif
6530
6531#ifdef FEAT_PRINTER
6532 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006533 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006534# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006535 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006536 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006537# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006538#endif
6539
6540#ifdef FEAT_LANGMAP
6541 /* 'langmap' */
6542 else if (varp == &p_langmap)
6543 langmap_set();
6544#endif
6545
6546#ifdef FEAT_LINEBREAK
6547 /* 'breakat' */
6548 else if (varp == &p_breakat)
6549 fill_breakat_flags();
6550#endif
6551
6552#ifdef FEAT_TITLE
6553 /* 'titlestring' and 'iconstring' */
6554 else if (varp == &p_titlestring || varp == &p_iconstring)
6555 {
6556# ifdef FEAT_STL_OPT
6557 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6558
6559 /* NULL => statusline syntax */
6560 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6561 stl_syntax |= flagval;
6562 else
6563 stl_syntax &= ~flagval;
6564# endif
6565 did_set_title(varp == &p_iconstring);
6566
6567 }
6568#endif
6569
6570#ifdef FEAT_GUI
6571 /* 'guioptions' */
6572 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006573 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006574 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006575 redraw_gui_only = TRUE;
6576 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006577#endif
6578
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006579#if defined(FEAT_GUI_TABLINE)
6580 /* 'guitablabel' */
6581 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006582 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006583 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006584 redraw_gui_only = TRUE;
6585 }
6586 /* 'guitabtooltip' */
6587 else if (varp == &p_gtt)
6588 {
6589 redraw_gui_only = TRUE;
6590 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006591#endif
6592
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6594 /* 'ttymouse' */
6595 else if (varp == &p_ttym)
6596 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006597 /* Switch the mouse off before changing the escape sequences used for
6598 * that. */
6599 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006600 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6601 errmsg = e_invarg;
6602 else
6603 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006604 if (termcap_active)
6605 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606 }
6607#endif
6608
Bram Moolenaar071d4272004-06-13 20:20:40 +00006609 /* 'selection' */
6610 else if (varp == &p_sel)
6611 {
6612 if (*p_sel == NUL
6613 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6614 errmsg = e_invarg;
6615 }
6616
6617 /* 'selectmode' */
6618 else if (varp == &p_slm)
6619 {
6620 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6621 errmsg = e_invarg;
6622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006623
6624#ifdef FEAT_BROWSE
6625 /* 'browsedir' */
6626 else if (varp == &p_bsdir)
6627 {
6628 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6629 && !mch_isdir(p_bsdir))
6630 errmsg = e_invarg;
6631 }
6632#endif
6633
Bram Moolenaar071d4272004-06-13 20:20:40 +00006634 /* 'keymodel' */
6635 else if (varp == &p_km)
6636 {
6637 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6638 errmsg = e_invarg;
6639 else
6640 {
6641 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6642 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6643 }
6644 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006645
6646 /* 'mousemodel' */
6647 else if (varp == &p_mousem)
6648 {
6649 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6650 errmsg = e_invarg;
6651#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6652 else if (*p_mousem != *oldval)
6653 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6654 * to create or delete the popup menus. */
6655 gui_motif_update_mousemodel(root_menu);
6656#endif
6657 }
6658
6659 /* 'switchbuf' */
6660 else if (varp == &p_swb)
6661 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006662 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006663 errmsg = e_invarg;
6664 }
6665
6666 /* 'debug' */
6667 else if (varp == &p_debug)
6668 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006669 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006670 errmsg = e_invarg;
6671 }
6672
6673 /* 'display' */
6674 else if (varp == &p_dy)
6675 {
6676 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6677 errmsg = e_invarg;
6678 else
6679 (void)init_chartab();
6680
6681 }
6682
6683#ifdef FEAT_VERTSPLIT
6684 /* 'eadirection' */
6685 else if (varp == &p_ead)
6686 {
6687 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6688 errmsg = e_invarg;
6689 }
6690#endif
6691
6692#ifdef FEAT_CLIPBOARD
6693 /* 'clipboard' */
6694 else if (varp == &p_cb)
6695 errmsg = check_clipboard_option();
6696#endif
6697
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006698#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006699 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6700 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006701 else if (varp == &(curwin->w_s->b_p_spl)
6702 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006703 {
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006704 win_T *wp;
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006705 int l;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006706
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006707 if (varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006708 {
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006709 l = (int)STRLEN(curwin->w_s->b_p_spf);
6710 if (l > 0 && (l < 4 || STRCMP(curwin->w_s->b_p_spf + l - 4,
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006711 ".add") != 0))
6712 errmsg = e_invarg;
6713 }
6714
6715 if (errmsg == NULL)
6716 {
6717 FOR_ALL_WINDOWS(wp)
6718 if (wp->w_buffer == curbuf && wp->w_p_spell)
6719 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006720 errmsg = did_set_spelllang(wp);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006721# ifdef FEAT_WINDOWS
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006722 break;
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00006723# endif
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006724 }
6725 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006726 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006727 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006728 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006729 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006730 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006731 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006732 /* 'spellsuggest' */
6733 else if (varp == &p_sps)
6734 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006735 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006736 errmsg = e_invarg;
6737 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006738 /* 'mkspellmem' */
6739 else if (varp == &p_msm)
6740 {
6741 if (spell_check_msm() != OK)
6742 errmsg = e_invarg;
6743 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006744#endif
6745
Bram Moolenaar071d4272004-06-13 20:20:40 +00006746#ifdef FEAT_QUICKFIX
6747 /* When 'bufhidden' is set, check for valid value. */
6748 else if (gvarp == &p_bh)
6749 {
6750 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6751 errmsg = e_invarg;
6752 }
6753
6754 /* When 'buftype' is set, check for valid value. */
6755 else if (gvarp == &p_bt)
6756 {
6757 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6758 errmsg = e_invarg;
6759 else
6760 {
6761# ifdef FEAT_WINDOWS
6762 if (curwin->w_status_height)
6763 {
6764 curwin->w_redr_status = TRUE;
6765 redraw_later(VALID);
6766 }
6767# endif
6768 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006769# ifdef FEAT_TITLE
6770 redraw_titles();
6771# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006772 }
6773 }
6774#endif
6775
6776#ifdef FEAT_STL_OPT
6777 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006778 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006779 {
6780 int wid;
6781
6782 if (varp == &p_ruf) /* reset ru_wid first */
6783 ru_wid = 0;
6784 s = *varp;
6785 if (varp == &p_ruf && *s == '%')
6786 {
6787 /* set ru_wid if 'ruf' starts with "%99(" */
6788 if (*++s == '-') /* ignore a '-' */
6789 s++;
6790 wid = getdigits(&s);
6791 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6792 ru_wid = wid;
6793 else
6794 errmsg = check_stl_option(p_ruf);
6795 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006796 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006797 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006798 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006799 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006800 comp_col();
6801 }
6802#endif
6803
6804#ifdef FEAT_INS_EXPAND
6805 /* check if it is a valid value for 'complete' -- Acevedo */
6806 else if (gvarp == &p_cpt)
6807 {
6808 for (s = *varp; *s;)
6809 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006810 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006811 s++;
6812 if (!*s)
6813 break;
6814 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6815 {
6816 errmsg = illegal_char(errbuf, *s);
6817 break;
6818 }
6819 if (*++s != NUL && *s != ',' && *s != ' ')
6820 {
6821 if (s[-1] == 'k' || s[-1] == 's')
6822 {
6823 /* skip optional filename after 'k' and 's' */
6824 while (*s && *s != ',' && *s != ' ')
6825 {
6826 if (*s == '\\')
6827 ++s;
6828 ++s;
6829 }
6830 }
6831 else
6832 {
6833 if (errbuf != NULL)
6834 {
6835 sprintf((char *)errbuf,
6836 _("E535: Illegal character after <%c>"),
6837 *--s);
6838 errmsg = errbuf;
6839 }
6840 else
6841 errmsg = (char_u *)"";
6842 break;
6843 }
6844 }
6845 }
6846 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006847
6848 /* 'completeopt' */
6849 else if (varp == &p_cot)
6850 {
6851 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6852 errmsg = e_invarg;
6853 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006854#endif /* FEAT_INS_EXPAND */
6855
6856
6857#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6858 else if (varp == &p_toolbar)
6859 {
6860 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6861 &toolbar_flags, TRUE) != OK)
6862 errmsg = e_invarg;
6863 else
6864 {
6865 out_flush();
6866 gui_mch_show_toolbar((toolbar_flags &
6867 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6868 }
6869 }
6870#endif
6871
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006872#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873 /* 'toolbariconsize': GTK+ 2 only */
6874 else if (varp == &p_tbis)
6875 {
6876 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6877 errmsg = e_invarg;
6878 else
6879 {
6880 out_flush();
6881 gui_mch_show_toolbar((toolbar_flags &
6882 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6883 }
6884 }
6885#endif
6886
6887 /* 'pastetoggle': translate key codes like in a mapping */
6888 else if (varp == &p_pt)
6889 {
6890 if (*p_pt)
6891 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006892 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006893 if (p != NULL)
6894 {
6895 if (new_value_alloced)
6896 free_string_option(p_pt);
6897 p_pt = p;
6898 new_value_alloced = TRUE;
6899 }
6900 }
6901 }
6902
6903 /* 'backspace' */
6904 else if (varp == &p_bs)
6905 {
6906 if (VIM_ISDIGIT(*p_bs))
6907 {
6908 if (*p_bs >'2' || p_bs[1] != NUL)
6909 errmsg = e_invarg;
6910 }
6911 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
6912 errmsg = e_invarg;
6913 }
6914
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006915#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006916 /* 'casemap' */
6917 else if (varp == &p_cmp)
6918 {
6919 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
6920 errmsg = e_invarg;
6921 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00006922#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006923
6924#ifdef FEAT_DIFF
6925 /* 'diffopt' */
6926 else if (varp == &p_dip)
6927 {
6928 if (diffopt_changed() == FAIL)
6929 errmsg = e_invarg;
6930 }
6931#endif
6932
6933#ifdef FEAT_FOLDING
6934 /* 'foldmethod' */
6935 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
6936 {
6937 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
6938 || *curwin->w_p_fdm == NUL)
6939 errmsg = e_invarg;
6940 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006941 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006942 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01006943 if (foldmethodIsDiff(curwin))
6944 newFoldLevel();
6945 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 }
6947# ifdef FEAT_EVAL
6948 /* 'foldexpr' */
6949 else if (varp == &curwin->w_p_fde)
6950 {
6951 if (foldmethodIsExpr(curwin))
6952 foldUpdateAll(curwin);
6953 }
6954# endif
6955 /* 'foldmarker' */
6956 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
6957 {
6958 p = vim_strchr(*varp, ',');
6959 if (p == NULL)
6960 errmsg = (char_u *)N_("E536: comma required");
6961 else if (p == *varp || p[1] == NUL)
6962 errmsg = e_invarg;
6963 else if (foldmethodIsMarker(curwin))
6964 foldUpdateAll(curwin);
6965 }
6966 /* 'commentstring' */
6967 else if (gvarp == &p_cms)
6968 {
6969 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
6970 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
6971 }
6972 /* 'foldopen' */
6973 else if (varp == &p_fdo)
6974 {
6975 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
6976 errmsg = e_invarg;
6977 }
6978 /* 'foldclose' */
6979 else if (varp == &p_fcl)
6980 {
6981 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
6982 errmsg = e_invarg;
6983 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00006984 /* 'foldignore' */
6985 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
6986 {
6987 if (foldmethodIsIndent(curwin))
6988 foldUpdateAll(curwin);
6989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006990#endif
6991
6992#ifdef FEAT_VIRTUALEDIT
6993 /* 'virtualedit' */
6994 else if (varp == &p_ve)
6995 {
6996 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
6997 errmsg = e_invarg;
6998 else if (STRCMP(p_ve, oldval) != 0)
6999 {
7000 /* Recompute cursor position in case the new 've' setting
7001 * changes something. */
7002 validate_virtcol();
7003 coladvance(curwin->w_virtcol);
7004 }
7005 }
7006#endif
7007
7008#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7009 else if (varp == &p_csqf)
7010 {
7011 if (p_csqf != NULL)
7012 {
7013 p = p_csqf;
7014 while (*p != NUL)
7015 {
7016 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7017 || p[1] == NUL
7018 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7019 || (p[2] != NUL && p[2] != ','))
7020 {
7021 errmsg = e_invarg;
7022 break;
7023 }
7024 else if (p[2] == NUL)
7025 break;
7026 else
7027 p += 3;
7028 }
7029 }
7030 }
7031#endif
7032
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007033#ifdef FEAT_CINDENT
7034 /* 'cinoptions' */
7035 else if (gvarp == &p_cino)
7036 {
7037 /* TODO: recognize errors */
7038 parse_cino(curbuf);
7039 }
7040#endif
7041
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007042#if defined(FEAT_RENDER_OPTIONS)
7043 else if (varp == &p_rop && gui.in_use)
7044 {
7045 if (!gui_mch_set_rendering_options(p_rop))
7046 errmsg = e_invarg;
7047 }
7048#endif
7049
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050 /* Options that are a list of flags. */
7051 else
7052 {
7053 p = NULL;
7054 if (varp == &p_ww)
7055 p = (char_u *)WW_ALL;
7056 if (varp == &p_shm)
7057 p = (char_u *)SHM_ALL;
7058 else if (varp == &(p_cpo))
7059 p = (char_u *)CPO_ALL;
7060 else if (varp == &(curbuf->b_p_fo))
7061 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007062#ifdef FEAT_CONCEAL
7063 else if (varp == &curwin->w_p_cocu)
7064 p = (char_u *)COCU_ALL;
7065#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007066 else if (varp == &p_mouse)
7067 {
7068#ifdef FEAT_MOUSE
7069 p = (char_u *)MOUSE_ALL;
7070#else
7071 if (*p_mouse != NUL)
7072 errmsg = (char_u *)N_("E538: No mouse support");
7073#endif
7074 }
7075#if defined(FEAT_GUI)
7076 else if (varp == &p_go)
7077 p = (char_u *)GO_ALL;
7078#endif
7079 if (p != NULL)
7080 {
7081 for (s = *varp; *s; ++s)
7082 if (vim_strchr(p, *s) == NULL)
7083 {
7084 errmsg = illegal_char(errbuf, *s);
7085 break;
7086 }
7087 }
7088 }
7089
7090 /*
7091 * If error detected, restore the previous value.
7092 */
7093 if (errmsg != NULL)
7094 {
7095 if (new_value_alloced)
7096 free_string_option(*varp);
7097 *varp = oldval;
7098 /*
7099 * When resetting some values, need to act on it.
7100 */
7101 if (did_chartab)
7102 (void)init_chartab();
7103 if (varp == &p_hl)
7104 (void)highlight_changed();
7105 }
7106 else
7107 {
7108#ifdef FEAT_EVAL
7109 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007110 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007111#endif
7112 /*
7113 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007114 * Use "free_oldval", because recursiveness may change the flags under
7115 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007116 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007117 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007118 free_string_option(oldval);
7119 if (new_value_alloced)
7120 options[opt_idx].flags |= P_ALLOCED;
7121 else
7122 options[opt_idx].flags &= ~P_ALLOCED;
7123
7124 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007125 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007126 {
7127 /* global option with local value set to use global value; free
7128 * the local value and make it empty */
7129 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7130 free_string_option(*(char_u **)p);
7131 *(char_u **)p = empty_option;
7132 }
7133
7134 /* May set global value for local option. */
7135 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7136 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007137
7138#ifdef FEAT_AUTOCMD
7139 /*
7140 * Trigger the autocommand only after setting the flags.
7141 */
7142# ifdef FEAT_SYN_HL
7143 /* When 'syntax' is set, load the syntax of that name */
7144 if (varp == &(curbuf->b_p_syn))
7145 {
7146 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7147 curbuf->b_fname, TRUE, curbuf);
7148 }
7149# endif
7150 else if (varp == &(curbuf->b_p_ft))
7151 {
7152 /* 'filetype' is set, trigger the FileType autocommand */
7153 did_filetype = TRUE;
7154 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7155 curbuf->b_fname, TRUE, curbuf);
7156 }
7157#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007158#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007159 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007160 {
7161 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007162 char_u *q = curwin->w_s->b_p_spl;
7163
7164 /* Skip the first name if it is "cjk". */
7165 if (STRNCMP(q, "cjk,", 4) == 0)
7166 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007167
7168 /*
7169 * Source the spell/LANG.vim in 'runtimepath'.
7170 * They could set 'spellcapcheck' depending on the language.
7171 * Use the first name in 'spelllang' up to '_region' or
7172 * '.encoding'.
7173 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007174 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007175 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7176 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007177 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007178 source_runtime(fname, TRUE);
7179 }
7180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 }
7182
7183#ifdef FEAT_MOUSE
7184 if (varp == &p_mouse)
7185 {
7186# ifdef FEAT_MOUSE_TTY
7187 if (*p_mouse == NUL)
7188 mch_setmouse(FALSE); /* switch mouse off */
7189 else
7190# endif
7191 setmouse(); /* in case 'mouse' changed */
7192 }
7193#endif
7194
Bram Moolenaar913077c2012-03-28 19:59:04 +02007195 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007196 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007197 curwin->w_set_curswant = TRUE;
7198
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007199#ifdef FEAT_GUI
7200 /* check redraw when it's not a GUI option or the GUI is active. */
7201 if (!redraw_gui_only || gui.in_use)
7202#endif
7203 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007204
7205 return errmsg;
7206}
7207
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007208#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007209/*
7210 * Simple int comparison function for use with qsort()
7211 */
7212 static int
7213int_cmp(a, b)
7214 const void *a;
7215 const void *b;
7216{
7217 return *(const int *)a - *(const int *)b;
7218}
7219
7220/*
7221 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7222 * Returns error message, NULL if it's OK.
7223 */
7224 char_u *
7225check_colorcolumn(wp)
7226 win_T *wp;
7227{
7228 char_u *s;
7229 int col;
7230 int count = 0;
7231 int color_cols[256];
7232 int i;
7233 int j = 0;
7234
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007235 if (wp->w_buffer == NULL)
7236 return NULL; /* buffer was closed */
7237
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007238 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007239 {
7240 if (*s == '-' || *s == '+')
7241 {
7242 /* -N and +N: add to 'textwidth' */
7243 col = (*s == '-') ? -1 : 1;
7244 ++s;
7245 if (!VIM_ISDIGIT(*s))
7246 return e_invarg;
7247 col = col * getdigits(&s);
7248 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007249 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007250 col += wp->w_buffer->b_p_tw;
7251 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007252 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007253 }
7254 else if (VIM_ISDIGIT(*s))
7255 col = getdigits(&s);
7256 else
7257 return e_invarg;
7258 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007259skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007260 if (*s == NUL)
7261 break;
7262 if (*s != ',')
7263 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007264 if (*++s == NUL)
7265 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007266 }
7267
7268 vim_free(wp->w_p_cc_cols);
7269 if (count == 0)
7270 wp->w_p_cc_cols = NULL;
7271 else
7272 {
7273 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7274 if (wp->w_p_cc_cols != NULL)
7275 {
7276 /* sort the columns for faster usage on screen redraw inside
7277 * win_line() */
7278 qsort(color_cols, count, sizeof(int), int_cmp);
7279
7280 for (i = 0; i < count; ++i)
7281 /* skip duplicates */
7282 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7283 wp->w_p_cc_cols[j++] = color_cols[i];
7284 wp->w_p_cc_cols[j] = -1; /* end marker */
7285 }
7286 }
7287
7288 return NULL; /* no error */
7289}
7290#endif
7291
Bram Moolenaar071d4272004-06-13 20:20:40 +00007292/*
7293 * Handle setting 'listchars' or 'fillchars'.
7294 * Returns error message, NULL if it's OK.
7295 */
7296 static char_u *
7297set_chars_option(varp)
7298 char_u **varp;
7299{
7300 int round, i, len, entries;
7301 char_u *p, *s;
7302 int c1, c2 = 0;
7303 struct charstab
7304 {
7305 int *cp;
7306 char *name;
7307 };
7308#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7309 static struct charstab filltab[] =
7310 {
7311 {&fill_stl, "stl"},
7312 {&fill_stlnc, "stlnc"},
7313 {&fill_vert, "vert"},
7314 {&fill_fold, "fold"},
7315 {&fill_diff, "diff"},
7316 };
7317#endif
7318 static struct charstab lcstab[] =
7319 {
7320 {&lcs_eol, "eol"},
7321 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007322 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007323 {&lcs_prec, "precedes"},
7324 {&lcs_tab2, "tab"},
7325 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007326#ifdef FEAT_CONCEAL
7327 {&lcs_conceal, "conceal"},
7328#else
7329 {NULL, "conceal"},
7330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007331 };
7332 struct charstab *tab;
7333
7334#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7335 if (varp == &p_lcs)
7336#endif
7337 {
7338 tab = lcstab;
7339 entries = sizeof(lcstab) / sizeof(struct charstab);
7340 }
7341#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7342 else
7343 {
7344 tab = filltab;
7345 entries = sizeof(filltab) / sizeof(struct charstab);
7346 }
7347#endif
7348
7349 /* first round: check for valid value, second round: assign values */
7350 for (round = 0; round <= 1; ++round)
7351 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007352 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007353 {
7354 /* After checking that the value is valid: set defaults: space for
7355 * 'fillchars', NUL for 'listchars' */
7356 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007357 if (tab[i].cp != NULL)
7358 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007359 if (varp == &p_lcs)
7360 lcs_tab1 = NUL;
7361#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7362 else
7363 fill_diff = '-';
7364#endif
7365 }
7366 p = *varp;
7367 while (*p)
7368 {
7369 for (i = 0; i < entries; ++i)
7370 {
7371 len = (int)STRLEN(tab[i].name);
7372 if (STRNCMP(p, tab[i].name, len) == 0
7373 && p[len] == ':'
7374 && p[len + 1] != NUL)
7375 {
7376 s = p + len + 1;
7377#ifdef FEAT_MBYTE
7378 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007379 if (mb_char2cells(c1) > 1)
7380 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007381#else
7382 c1 = *s++;
7383#endif
7384 if (tab[i].cp == &lcs_tab2)
7385 {
7386 if (*s == NUL)
7387 continue;
7388#ifdef FEAT_MBYTE
7389 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007390 if (mb_char2cells(c2) > 1)
7391 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007392#else
7393 c2 = *s++;
7394#endif
7395 }
7396 if (*s == ',' || *s == NUL)
7397 {
7398 if (round)
7399 {
7400 if (tab[i].cp == &lcs_tab2)
7401 {
7402 lcs_tab1 = c1;
7403 lcs_tab2 = c2;
7404 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007405 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007406 *(tab[i].cp) = c1;
7407
7408 }
7409 p = s;
7410 break;
7411 }
7412 }
7413 }
7414
7415 if (i == entries)
7416 return e_invarg;
7417 if (*p == ',')
7418 ++p;
7419 }
7420 }
7421
7422 return NULL; /* no error */
7423}
7424
7425#ifdef FEAT_STL_OPT
7426/*
7427 * Check validity of options with the 'statusline' format.
7428 * Return error message or NULL.
7429 */
7430 char_u *
7431check_stl_option(s)
7432 char_u *s;
7433{
7434 int itemcnt = 0;
7435 int groupdepth = 0;
7436 static char_u errbuf[80];
7437
7438 while (*s && itemcnt < STL_MAX_ITEM)
7439 {
7440 /* Check for valid keys after % sequences */
7441 while (*s && *s != '%')
7442 s++;
7443 if (!*s)
7444 break;
7445 s++;
7446 if (*s != '%' && *s != ')')
7447 ++itemcnt;
7448 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7449 {
7450 s++;
7451 continue;
7452 }
7453 if (*s == ')')
7454 {
7455 s++;
7456 if (--groupdepth < 0)
7457 break;
7458 continue;
7459 }
7460 if (*s == '-')
7461 s++;
7462 while (VIM_ISDIGIT(*s))
7463 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007464 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007465 continue;
7466 if (*s == '.')
7467 {
7468 s++;
7469 while (*s && VIM_ISDIGIT(*s))
7470 s++;
7471 }
7472 if (*s == '(')
7473 {
7474 groupdepth++;
7475 continue;
7476 }
7477 if (vim_strchr(STL_ALL, *s) == NULL)
7478 {
7479 return illegal_char(errbuf, *s);
7480 }
7481 if (*s == '{')
7482 {
7483 s++;
7484 while (*s != '}' && *s)
7485 s++;
7486 if (*s != '}')
7487 return (char_u *)N_("E540: Unclosed expression sequence");
7488 }
7489 }
7490 if (itemcnt >= STL_MAX_ITEM)
7491 return (char_u *)N_("E541: too many items");
7492 if (groupdepth != 0)
7493 return (char_u *)N_("E542: unbalanced groups");
7494 return NULL;
7495}
7496#endif
7497
7498#ifdef FEAT_CLIPBOARD
7499/*
7500 * Extract the items in the 'clipboard' option and set global values.
7501 */
7502 static char_u *
7503check_clipboard_option()
7504{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007505 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007506 int new_autoselect_star = FALSE;
7507 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007508 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007509 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510 regprog_T *new_exclude_prog = NULL;
7511 char_u *errmsg = NULL;
7512 char_u *p;
7513
7514 for (p = p_cb; *p != NUL; )
7515 {
7516 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7517 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007518 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007519 p += 7;
7520 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007521 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007522 && (p[11] == ',' || p[11] == NUL))
7523 {
7524 new_unnamed |= CLIP_UNNAMED_PLUS;
7525 p += 11;
7526 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007528 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007529 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007530 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007531 p += 10;
7532 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007533 else if (STRNCMP(p, "autoselectplus", 14) == 0
7534 && (p[14] == ',' || p[14] == NUL))
7535 {
7536 new_autoselect_plus = TRUE;
7537 p += 14;
7538 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007539 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007540 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007541 {
7542 new_autoselectml = TRUE;
7543 p += 12;
7544 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007545 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7546 {
7547 new_html = TRUE;
7548 p += 4;
7549 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007550 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7551 {
7552 p += 8;
7553 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7554 if (new_exclude_prog == NULL)
7555 errmsg = e_invarg;
7556 break;
7557 }
7558 else
7559 {
7560 errmsg = e_invarg;
7561 break;
7562 }
7563 if (*p == ',')
7564 ++p;
7565 }
7566 if (errmsg == NULL)
7567 {
7568 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007569 clip_autoselect_star = new_autoselect_star;
7570 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007571 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007572 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007573 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007574 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007575#ifdef FEAT_GUI_GTK
7576 if (gui.in_use)
7577 {
7578 gui_gtk_set_selection_targets();
7579 gui_gtk_set_dnd_targets();
7580 }
7581#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007582 }
7583 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007584 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007585
7586 return errmsg;
7587}
7588#endif
7589
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007590#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007591/*
7592 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7593 * Return error message when failed, NULL when OK.
7594 */
7595 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007596compile_cap_prog(synblock)
7597 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007598{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007599 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007600 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007601
Bram Moolenaar860cae12010-06-05 23:22:07 +02007602 if (*synblock->b_p_spc == NUL)
7603 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007604 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007605 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007606 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007607 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007608 if (re != NULL)
7609 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007610 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007611 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007612 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007613 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007614 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007615 return e_invarg;
7616 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007617 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007618 }
7619
Bram Moolenaar473de612013-06-08 18:19:48 +02007620 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007621 return NULL;
7622}
7623#endif
7624
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007625#if defined(FEAT_EVAL) || defined(PROTO)
7626/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007627 * Set the scriptID for an option, taking care of setting the buffer- or
7628 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007629 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007630 static void
7631set_option_scriptID_idx(opt_idx, opt_flags, id)
7632 int opt_idx;
7633 int opt_flags;
7634 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007635{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007636 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7637 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007638
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007639 /* Remember where the option was set. For local options need to do that
7640 * in the buffer or window structure. */
7641 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007642 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007643 if (both || (opt_flags & OPT_LOCAL))
7644 {
7645 if (indir & PV_BUF)
7646 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7647 else if (indir & PV_WIN)
7648 curwin->w_p_scriptID[indir & PV_MASK] = id;
7649 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007650}
7651#endif
7652
Bram Moolenaar071d4272004-06-13 20:20:40 +00007653/*
7654 * Set the value of a boolean option, and take care of side effects.
7655 * Returns NULL for success, or an error message for an error.
7656 */
7657 static char_u *
7658set_bool_option(opt_idx, varp, value, opt_flags)
7659 int opt_idx; /* index in options[] table */
7660 char_u *varp; /* pointer to the option variable */
7661 int value; /* new value */
7662 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7663{
7664 int old_value = *(int *)varp;
7665
Bram Moolenaar071d4272004-06-13 20:20:40 +00007666 /* Disallow changing some options from secure mode */
7667 if ((secure
7668#ifdef HAVE_SANDBOX
7669 || sandbox != 0
7670#endif
7671 ) && (options[opt_idx].flags & P_SECURE))
7672 return e_secure;
7673
7674 *(int *)varp = value; /* set the new value */
7675#ifdef FEAT_EVAL
7676 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007677 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007678#endif
7679
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007680#ifdef FEAT_GUI
7681 need_mouse_correct = TRUE;
7682#endif
7683
Bram Moolenaar071d4272004-06-13 20:20:40 +00007684 /* May set global value for local option. */
7685 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7686 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7687
7688 /*
7689 * Handle side effects of changing a bool option.
7690 */
7691
7692 /* 'compatible' */
7693 if ((int *)varp == &p_cp)
7694 {
7695 compatible_set();
7696 }
7697
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007698#ifdef FEAT_PERSISTENT_UNDO
7699 /* 'undofile' */
7700 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7701 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007702 /* Only take action when the option was set. When reset we do not
7703 * delete the undo file, the option may be set again without making
7704 * any changes in between. */
7705 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007706 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007707 char_u hash[UNDO_HASH_SIZE];
7708 buf_T *save_curbuf = curbuf;
7709
7710 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007711 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007712 /* When 'undofile' is set globally: for every buffer, otherwise
7713 * only for the current buffer: Try to read in the undofile,
7714 * if one exists, the buffer wasn't changed and the buffer was
7715 * loaded */
7716 if ((curbuf == save_curbuf
7717 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7718 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7719 {
7720 u_compute_hash(hash);
7721 u_read_undo(NULL, hash, curbuf->b_fname);
7722 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007723 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007724 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007725 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007726 }
7727#endif
7728
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729 else if ((int *)varp == &curbuf->b_p_ro)
7730 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007731 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007732 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7733 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007734
7735 /* when 'readonly' is set may give W10 again */
7736 if (curbuf->b_p_ro)
7737 curbuf->b_did_warn = FALSE;
7738
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007740 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007741#endif
7742 }
7743
Bram Moolenaar9c449722010-07-20 18:44:27 +02007744#ifdef FEAT_GUI
7745 else if ((int *)varp == &p_mh)
7746 {
7747 if (!p_mh)
7748 gui_mch_mousehide(FALSE);
7749 }
7750#endif
7751
Bram Moolenaara539df02010-08-01 14:35:05 +02007752#ifdef FEAT_TITLE
7753 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007754 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007755 {
7756 redraw_titles();
7757 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 /* when 'endofline' is changed, redraw the window title */
7759 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007760 {
7761 redraw_titles();
7762 }
7763# ifdef FEAT_MBYTE
7764 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007765 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007766 {
7767 redraw_titles();
7768 }
7769# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007770#endif
7771
7772 /* when 'bin' is set also set some other options */
7773 else if ((int *)varp == &curbuf->b_p_bin)
7774 {
7775 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7776#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007777 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778#endif
7779 }
7780
7781#ifdef FEAT_AUTOCMD
7782 /* when 'buflisted' changes, trigger autocommands */
7783 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7784 {
7785 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7786 NULL, NULL, TRUE, curbuf);
7787 }
7788#endif
7789
7790 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7791 else if ((int *)varp == &curbuf->b_p_swf)
7792 {
7793 if (curbuf->b_p_swf && p_uc)
7794 ml_open_file(curbuf); /* create the swap file */
7795 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007796 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7797 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798 mf_close_file(curbuf, TRUE); /* remove the swap file */
7799 }
7800
7801 /* when 'terse' is set change 'shortmess' */
7802 else if ((int *)varp == &p_terse)
7803 {
7804 char_u *p;
7805
7806 p = vim_strchr(p_shm, SHM_SEARCH);
7807
7808 /* insert 's' in p_shm */
7809 if (p_terse && p == NULL)
7810 {
7811 STRCPY(IObuff, p_shm);
7812 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007813 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007814 }
7815 /* remove 's' from p_shm */
7816 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007817 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818 }
7819
7820 /* when 'paste' is set or reset also change other options */
7821 else if ((int *)varp == &p_paste)
7822 {
7823 paste_option_changed();
7824 }
7825
7826 /* when 'insertmode' is set from an autocommand need to do work here */
7827 else if ((int *)varp == &p_im)
7828 {
7829 if (p_im)
7830 {
7831 if ((State & INSERT) == 0)
7832 need_start_insertmode = TRUE;
7833 stop_insert_mode = FALSE;
7834 }
7835 else
7836 {
7837 need_start_insertmode = FALSE;
7838 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00007839 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007840 clear_cmdline = TRUE; /* remove "(insert)" */
7841 restart_edit = 0;
7842 }
7843 }
7844
7845 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
7846 else if ((int *)varp == &p_ic && p_hls)
7847 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007848 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849 }
7850
7851#ifdef FEAT_SEARCH_EXTRA
7852 /* when 'hlsearch' is set or reset: reset no_hlsearch */
7853 else if ((int *)varp == &p_hls)
7854 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01007855 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007856 }
7857#endif
7858
7859#ifdef FEAT_SCROLLBIND
7860 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
7861 * at the end of normal_cmd() */
7862 else if ((int *)varp == &curwin->w_p_scb)
7863 {
7864 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007865 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007866 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02007867 curwin->w_scbind_pos = curwin->w_topline;
7868 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869 }
7870#endif
7871
7872#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
7873 /* There can be only one window with 'previewwindow' set. */
7874 else if ((int *)varp == &curwin->w_p_pvw)
7875 {
7876 if (curwin->w_p_pvw)
7877 {
7878 win_T *win;
7879
7880 for (win = firstwin; win != NULL; win = win->w_next)
7881 if (win->w_p_pvw && win != curwin)
7882 {
7883 curwin->w_p_pvw = FALSE;
7884 return (char_u *)N_("E590: A preview window already exists");
7885 }
7886 }
7887 }
7888#endif
7889
7890 /* when 'textmode' is set or reset also change 'fileformat' */
7891 else if ((int *)varp == &curbuf->b_p_tx)
7892 {
7893 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
7894 }
7895
7896 /* when 'textauto' is set or reset also change 'fileformats' */
7897 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898 set_string_option_direct((char_u *)"ffs", -1,
7899 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007900 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901
7902 /*
7903 * When 'lisp' option changes include/exclude '-' in
7904 * keyword characters.
7905 */
7906#ifdef FEAT_LISP
7907 else if (varp == (char_u *)&(curbuf->b_p_lisp))
7908 {
7909 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
7910 }
7911#endif
7912
7913#ifdef FEAT_TITLE
7914 /* when 'title' changed, may need to change the title; same for 'icon' */
7915 else if ((int *)varp == &p_title)
7916 {
7917 did_set_title(FALSE);
7918 }
7919
7920 else if ((int *)varp == &p_icon)
7921 {
7922 did_set_title(TRUE);
7923 }
7924#endif
7925
7926 else if ((int *)varp == &curbuf->b_changed)
7927 {
7928 if (!value)
7929 save_file_ff(curbuf); /* Buffer is unchanged */
7930#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007931 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007932#endif
7933#ifdef FEAT_AUTOCMD
7934 modified_was_set = value;
7935#endif
7936 }
7937
7938#ifdef BACKSLASH_IN_FILENAME
7939 else if ((int *)varp == &p_ssl)
7940 {
7941 if (p_ssl)
7942 {
7943 psepc = '/';
7944 psepcN = '\\';
7945 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946 }
7947 else
7948 {
7949 psepc = '\\';
7950 psepcN = '/';
7951 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007952 }
7953
7954 /* need to adjust the file name arguments and buffer names. */
7955 buflist_slash_adjust();
7956 alist_slash_adjust();
7957# ifdef FEAT_EVAL
7958 scriptnames_slash_adjust();
7959# endif
7960 }
7961#endif
7962
7963 /* If 'wrap' is set, set w_leftcol to zero. */
7964 else if ((int *)varp == &curwin->w_p_wrap)
7965 {
7966 if (curwin->w_p_wrap)
7967 curwin->w_leftcol = 0;
7968 }
7969
7970#ifdef FEAT_WINDOWS
7971 else if ((int *)varp == &p_ea)
7972 {
7973 if (p_ea && !old_value)
7974 win_equal(curwin, FALSE, 0);
7975 }
7976#endif
7977
7978 else if ((int *)varp == &p_wiv)
7979 {
7980 /*
7981 * When 'weirdinvert' changed, set/reset 't_xs'.
7982 * Then set 'weirdinvert' according to value of 't_xs'.
7983 */
7984 if (p_wiv && !old_value)
7985 T_XS = (char_u *)"y";
7986 else if (!p_wiv && old_value)
7987 T_XS = empty_option;
7988 p_wiv = (*T_XS != NUL);
7989 }
7990
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007991#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00007992 else if ((int *)varp == &p_beval)
7993 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007994 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007995 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01007996 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007997 gui_mch_disable_beval_area(balloonEval);
7998 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00007999#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008000
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008001#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 else if ((int *)varp == &p_acd)
8003 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008004 /* Change directories when the 'acd' option is set now. */
8005 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008006 }
8007#endif
8008
8009#ifdef FEAT_DIFF
8010 /* 'diff' */
8011 else if ((int *)varp == &curwin->w_p_diff)
8012 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008013 /* May add or remove the buffer from the list of diff buffers. */
8014 diff_buf_adjust(curwin);
8015# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 if (foldmethodIsDiff(curwin))
8017 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008018# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008019 }
8020#endif
8021
8022#ifdef USE_IM_CONTROL
8023 /* 'imdisable' */
8024 else if ((int *)varp == &p_imdisable)
8025 {
8026 /* Only de-activate it here, it will be enabled when changing mode. */
8027 if (p_imdisable)
8028 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008029 else if (State & INSERT)
8030 /* When the option is set from an autocommand, it may need to take
8031 * effect right away. */
8032 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008033 }
8034#endif
8035
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008036#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008037 /* 'spell' */
8038 else if ((int *)varp == &curwin->w_p_spell)
8039 {
8040 if (curwin->w_p_spell)
8041 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008042 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008043 if (errmsg != NULL)
8044 EMSG(_(errmsg));
8045 }
8046 }
8047#endif
8048
Bram Moolenaar071d4272004-06-13 20:20:40 +00008049#ifdef FEAT_FKMAP
8050 else if ((int *)varp == &p_altkeymap)
8051 {
8052 if (old_value != p_altkeymap)
8053 {
8054 if (!p_altkeymap)
8055 {
8056 p_hkmap = p_fkmap;
8057 p_fkmap = 0;
8058 }
8059 else
8060 {
8061 p_fkmap = p_hkmap;
8062 p_hkmap = 0;
8063 }
8064 (void)init_chartab();
8065 }
8066 }
8067
8068 /*
8069 * In case some second language keymapping options have changed, check
8070 * and correct the setting in a consistent way.
8071 */
8072
8073 /*
8074 * If hkmap or fkmap are set, reset Arabic keymapping.
8075 */
8076 if ((p_hkmap || p_fkmap) && p_altkeymap)
8077 {
8078 p_altkeymap = p_fkmap;
8079# ifdef FEAT_ARABIC
8080 curwin->w_p_arab = FALSE;
8081# endif
8082 (void)init_chartab();
8083 }
8084
8085 /*
8086 * If hkmap set, reset Farsi keymapping.
8087 */
8088 if (p_hkmap && p_altkeymap)
8089 {
8090 p_altkeymap = 0;
8091 p_fkmap = 0;
8092# ifdef FEAT_ARABIC
8093 curwin->w_p_arab = FALSE;
8094# endif
8095 (void)init_chartab();
8096 }
8097
8098 /*
8099 * If fkmap set, reset Hebrew keymapping.
8100 */
8101 if (p_fkmap && !p_altkeymap)
8102 {
8103 p_altkeymap = 1;
8104 p_hkmap = 0;
8105# ifdef FEAT_ARABIC
8106 curwin->w_p_arab = FALSE;
8107# endif
8108 (void)init_chartab();
8109 }
8110#endif
8111
8112#ifdef FEAT_ARABIC
8113 if ((int *)varp == &curwin->w_p_arab)
8114 {
8115 if (curwin->w_p_arab)
8116 {
8117 /*
8118 * 'arabic' is set, handle various sub-settings.
8119 */
8120 if (!p_tbidi)
8121 {
8122 /* set rightleft mode */
8123 if (!curwin->w_p_rl)
8124 {
8125 curwin->w_p_rl = TRUE;
8126 changed_window_setting();
8127 }
8128
8129 /* Enable Arabic shaping (major part of what Arabic requires) */
8130 if (!p_arshape)
8131 {
8132 p_arshape = TRUE;
8133 redraw_later_clear();
8134 }
8135 }
8136
8137 /* Arabic requires a utf-8 encoding, inform the user if its not
8138 * set. */
8139 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008140 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008141 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8142
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008143 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008144 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8145#ifdef FEAT_EVAL
8146 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8147#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149
8150# ifdef FEAT_MBYTE
8151 /* set 'delcombine' */
8152 p_deco = TRUE;
8153# endif
8154
8155# ifdef FEAT_KEYMAP
8156 /* Force-set the necessary keymap for arabic */
8157 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8158 OPT_LOCAL);
8159# endif
8160# ifdef FEAT_FKMAP
8161 p_altkeymap = 0;
8162 p_hkmap = 0;
8163 p_fkmap = 0;
8164 (void)init_chartab();
8165# endif
8166 }
8167 else
8168 {
8169 /*
8170 * 'arabic' is reset, handle various sub-settings.
8171 */
8172 if (!p_tbidi)
8173 {
8174 /* reset rightleft mode */
8175 if (curwin->w_p_rl)
8176 {
8177 curwin->w_p_rl = FALSE;
8178 changed_window_setting();
8179 }
8180
8181 /* 'arabicshape' isn't reset, it is a global option and
8182 * another window may still need it "on". */
8183 }
8184
8185 /* 'delcombine' isn't reset, it is a global option and another
8186 * window may still want it "on". */
8187
8188# ifdef FEAT_KEYMAP
8189 /* Revert to the default keymap */
8190 curbuf->b_p_iminsert = B_IMODE_NONE;
8191 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8192# endif
8193 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008194 }
8195
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008196#endif
8197
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198 /*
8199 * End of handling side effects for bool options.
8200 */
8201
8202 options[opt_idx].flags |= P_WAS_SET;
8203
8204 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008205 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008206 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008207 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008208 check_redraw(options[opt_idx].flags);
8209
8210 return NULL;
8211}
8212
8213/*
8214 * Set the value of a number option, and take care of side effects.
8215 * Returns NULL for success, or an error message for an error.
8216 */
8217 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008218set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008219 int opt_idx; /* index in options[] table */
8220 char_u *varp; /* pointer to the option variable */
8221 long value; /* new value */
8222 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008223 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008224 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8225 OPT_MODELINE */
8226{
8227 char_u *errmsg = NULL;
8228 long old_value = *(long *)varp;
8229 long old_Rows = Rows; /* remember old Rows */
8230 long old_Columns = Columns; /* remember old Columns */
8231 long *pp = (long *)varp;
8232
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008233 /* Disallow changing some options from secure mode. */
8234 if ((secure
8235#ifdef HAVE_SANDBOX
8236 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008237#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008238 ) && (options[opt_idx].flags & P_SECURE))
8239 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008240
8241 *pp = value;
8242#ifdef FEAT_EVAL
8243 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008244 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008246#ifdef FEAT_GUI
8247 need_mouse_correct = TRUE;
8248#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008249
Bram Moolenaar14f24742012-08-08 18:01:05 +02008250 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251 {
8252 errmsg = e_positive;
8253 curbuf->b_p_sw = curbuf->b_p_ts;
8254 }
8255
8256 /*
8257 * Number options that need some action when changed
8258 */
8259#ifdef FEAT_WINDOWS
8260 if (pp == &p_wh || pp == &p_hh)
8261 {
8262 if (p_wh < 1)
8263 {
8264 errmsg = e_positive;
8265 p_wh = 1;
8266 }
8267 if (p_wmh > p_wh)
8268 {
8269 errmsg = e_winheight;
8270 p_wh = p_wmh;
8271 }
8272 if (p_hh < 0)
8273 {
8274 errmsg = e_positive;
8275 p_hh = 0;
8276 }
8277
8278 /* Change window height NOW */
8279 if (lastwin != firstwin)
8280 {
8281 if (pp == &p_wh && curwin->w_height < p_wh)
8282 win_setheight((int)p_wh);
8283 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8284 win_setheight((int)p_hh);
8285 }
8286 }
8287
8288 /* 'winminheight' */
8289 else if (pp == &p_wmh)
8290 {
8291 if (p_wmh < 0)
8292 {
8293 errmsg = e_positive;
8294 p_wmh = 0;
8295 }
8296 if (p_wmh > p_wh)
8297 {
8298 errmsg = e_winheight;
8299 p_wmh = p_wh;
8300 }
8301 win_setminheight();
8302 }
8303
8304# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008305 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 {
8307 if (p_wiw < 1)
8308 {
8309 errmsg = e_positive;
8310 p_wiw = 1;
8311 }
8312 if (p_wmw > p_wiw)
8313 {
8314 errmsg = e_winwidth;
8315 p_wiw = p_wmw;
8316 }
8317
8318 /* Change window width NOW */
8319 if (lastwin != firstwin && curwin->w_width < p_wiw)
8320 win_setwidth((int)p_wiw);
8321 }
8322
8323 /* 'winminwidth' */
8324 else if (pp == &p_wmw)
8325 {
8326 if (p_wmw < 0)
8327 {
8328 errmsg = e_positive;
8329 p_wmw = 0;
8330 }
8331 if (p_wmw > p_wiw)
8332 {
8333 errmsg = e_winwidth;
8334 p_wmw = p_wiw;
8335 }
8336 win_setminheight();
8337 }
8338# endif
8339
8340#endif
8341
8342#ifdef FEAT_WINDOWS
8343 /* (re)set last window status line */
8344 else if (pp == &p_ls)
8345 {
8346 last_status(FALSE);
8347 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008348
8349 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008350 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008351 {
8352 shell_new_rows(); /* recompute window positions and heights */
8353 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008354#endif
8355
8356#ifdef FEAT_GUI
8357 else if (pp == &p_linespace)
8358 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008359 /* Recompute gui.char_height and resize the Vim window to keep the
8360 * same number of lines. */
8361 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008362 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363 }
8364#endif
8365
8366#ifdef FEAT_FOLDING
8367 /* 'foldlevel' */
8368 else if (pp == &curwin->w_p_fdl)
8369 {
8370 if (curwin->w_p_fdl < 0)
8371 curwin->w_p_fdl = 0;
8372 newFoldLevel();
8373 }
8374
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008375 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008376 else if (pp == &curwin->w_p_fml)
8377 {
8378 foldUpdateAll(curwin);
8379 }
8380
8381 /* 'foldnestmax' */
8382 else if (pp == &curwin->w_p_fdn)
8383 {
8384 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8385 foldUpdateAll(curwin);
8386 }
8387
8388 /* 'foldcolumn' */
8389 else if (pp == &curwin->w_p_fdc)
8390 {
8391 if (curwin->w_p_fdc < 0)
8392 {
8393 errmsg = e_positive;
8394 curwin->w_p_fdc = 0;
8395 }
8396 else if (curwin->w_p_fdc > 12)
8397 {
8398 errmsg = e_invarg;
8399 curwin->w_p_fdc = 12;
8400 }
8401 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008402#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008404#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405 /* 'shiftwidth' or 'tabstop' */
8406 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8407 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008408# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409 if (foldmethodIsIndent(curwin))
8410 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008411# endif
8412# ifdef FEAT_CINDENT
8413 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8414 * parse 'cinoptions'. */
8415 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8416 parse_cino(curbuf);
8417# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008420
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008421#ifdef FEAT_MBYTE
8422 /* 'maxcombine' */
8423 else if (pp == &p_mco)
8424 {
8425 if (p_mco > MAX_MCO)
8426 p_mco = MAX_MCO;
8427 else if (p_mco < 0)
8428 p_mco = 0;
8429 screenclear(); /* will re-allocate the screen */
8430 }
8431#endif
8432
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433 else if (pp == &curbuf->b_p_iminsert)
8434 {
8435 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8436 {
8437 errmsg = e_invarg;
8438 curbuf->b_p_iminsert = B_IMODE_NONE;
8439 }
8440 p_iminsert = curbuf->b_p_iminsert;
8441 if (termcap_active) /* don't do this in the alternate screen */
8442 showmode();
8443#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8444 /* Show/unshow value of 'keymap' in status lines. */
8445 status_redraw_curbuf();
8446#endif
8447 }
8448
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008449 else if (pp == &p_window)
8450 {
8451 if (p_window < 1)
8452 p_window = 1;
8453 else if (p_window >= Rows)
8454 p_window = Rows - 1;
8455 }
8456
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457 else if (pp == &curbuf->b_p_imsearch)
8458 {
8459 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8460 {
8461 errmsg = e_invarg;
8462 curbuf->b_p_imsearch = B_IMODE_NONE;
8463 }
8464 p_imsearch = curbuf->b_p_imsearch;
8465 }
8466
8467#ifdef FEAT_TITLE
8468 /* if 'titlelen' has changed, redraw the title */
8469 else if (pp == &p_titlelen)
8470 {
8471 if (p_titlelen < 0)
8472 {
8473 errmsg = e_positive;
8474 p_titlelen = 85;
8475 }
8476 if (starting != NO_SCREEN && old_value != p_titlelen)
8477 need_maketitle = TRUE;
8478 }
8479#endif
8480
8481 /* if p_ch changed value, change the command line height */
8482 else if (pp == &p_ch)
8483 {
8484 if (p_ch < 1)
8485 {
8486 errmsg = e_positive;
8487 p_ch = 1;
8488 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008489 if (p_ch > Rows - min_rows() + 1)
8490 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008491
8492 /* Only compute the new window layout when startup has been
8493 * completed. Otherwise the frame sizes may be wrong. */
8494 if (p_ch != old_value && full_screen
8495#ifdef FEAT_GUI
8496 && !gui.starting
8497#endif
8498 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008499 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500 }
8501
8502 /* when 'updatecount' changes from zero to non-zero, open swap files */
8503 else if (pp == &p_uc)
8504 {
8505 if (p_uc < 0)
8506 {
8507 errmsg = e_positive;
8508 p_uc = 100;
8509 }
8510 if (p_uc && !old_value)
8511 ml_open_files();
8512 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008513#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008514 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008515 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008516 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008517 {
8518 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008519 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008520 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008521 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008522 {
8523 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008524 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008525 }
8526 }
8527#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008528#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008529 else if (pp == &p_mzq)
8530 mzvim_reset_timer();
8531#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532
8533 /* sync undo before 'undolevels' changes */
8534 else if (pp == &p_ul)
8535 {
8536 /* use the old value, otherwise u_sync() may not work properly */
8537 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008538 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008539 p_ul = value;
8540 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008541 else if (pp == &curbuf->b_p_ul)
8542 {
8543 /* use the old value, otherwise u_sync() may not work properly */
8544 curbuf->b_p_ul = old_value;
8545 u_sync(TRUE);
8546 curbuf->b_p_ul = value;
8547 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008548
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008549#ifdef FEAT_LINEBREAK
8550 /* 'numberwidth' must be positive */
8551 else if (pp == &curwin->w_p_nuw)
8552 {
8553 if (curwin->w_p_nuw < 1)
8554 {
8555 errmsg = e_positive;
8556 curwin->w_p_nuw = 1;
8557 }
8558 if (curwin->w_p_nuw > 10)
8559 {
8560 errmsg = e_invarg;
8561 curwin->w_p_nuw = 10;
8562 }
8563 curwin->w_nrwidth_line_count = 0;
8564 }
8565#endif
8566
Bram Moolenaar1a384422010-07-14 19:53:30 +02008567 else if (pp == &curbuf->b_p_tw)
8568 {
8569 if (curbuf->b_p_tw < 0)
8570 {
8571 errmsg = e_positive;
8572 curbuf->b_p_tw = 0;
8573 }
8574#ifdef FEAT_SYN_HL
8575# ifdef FEAT_WINDOWS
8576 {
8577 win_T *wp;
8578 tabpage_T *tp;
8579
8580 FOR_ALL_TAB_WINDOWS(tp, wp)
8581 check_colorcolumn(wp);
8582 }
8583# else
8584 check_colorcolumn(curwin);
8585# endif
8586#endif
8587 }
8588
Bram Moolenaar071d4272004-06-13 20:20:40 +00008589 /*
8590 * Check the bounds for numeric options here
8591 */
8592 if (Rows < min_rows() && full_screen)
8593 {
8594 if (errbuf != NULL)
8595 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008596 vim_snprintf((char *)errbuf, errbuflen,
8597 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008598 errmsg = errbuf;
8599 }
8600 Rows = min_rows();
8601 }
8602 if (Columns < MIN_COLUMNS && full_screen)
8603 {
8604 if (errbuf != NULL)
8605 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008606 vim_snprintf((char *)errbuf, errbuflen,
8607 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008608 errmsg = errbuf;
8609 }
8610 Columns = MIN_COLUMNS;
8611 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008612 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008613
8614#ifdef DJGPP
8615 /* avoid a crash by checking for a too large value of 'columns' */
8616 if (old_Columns != Columns && full_screen && term_console)
8617 mch_check_columns();
8618#endif
8619
8620 /*
8621 * If the screen (shell) height has been changed, assume it is the
8622 * physical screenheight.
8623 */
8624 if (old_Rows != Rows || old_Columns != Columns)
8625 {
8626 /* Changing the screen size is not allowed while updating the screen. */
8627 if (updating_screen)
8628 *pp = old_value;
8629 else if (full_screen
8630#ifdef FEAT_GUI
8631 && !gui.starting
8632#endif
8633 )
8634 set_shellsize((int)Columns, (int)Rows, TRUE);
8635 else
8636 {
8637 /* Postpone the resizing; check the size and cmdline position for
8638 * messages. */
8639 check_shellsize();
8640 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8641 cmdline_row = Rows - p_ch;
8642 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008643 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008644 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008645 }
8646
Bram Moolenaar071d4272004-06-13 20:20:40 +00008647 if (curbuf->b_p_ts <= 0)
8648 {
8649 errmsg = e_positive;
8650 curbuf->b_p_ts = 8;
8651 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652 if (p_tm < 0)
8653 {
8654 errmsg = e_positive;
8655 p_tm = 0;
8656 }
8657 if ((curwin->w_p_scr <= 0
8658 || (curwin->w_p_scr > curwin->w_height
8659 && curwin->w_height > 0))
8660 && full_screen)
8661 {
8662 if (pp == &(curwin->w_p_scr))
8663 {
8664 if (curwin->w_p_scr != 0)
8665 errmsg = e_scroll;
8666 win_comp_scroll(curwin);
8667 }
8668 /* If 'scroll' became invalid because of a side effect silently adjust
8669 * it. */
8670 else if (curwin->w_p_scr <= 0)
8671 curwin->w_p_scr = 1;
8672 else /* curwin->w_p_scr > curwin->w_height */
8673 curwin->w_p_scr = curwin->w_height;
8674 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008675 if (p_hi < 0)
8676 {
8677 errmsg = e_positive;
8678 p_hi = 0;
8679 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008680 else if (p_hi > 10000)
8681 {
8682 errmsg = e_invarg;
8683 p_hi = 10000;
8684 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008685 if (p_re < 0 || p_re > 2)
8686 {
8687 errmsg = e_invarg;
8688 p_re = 0;
8689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008690 if (p_report < 0)
8691 {
8692 errmsg = e_positive;
8693 p_report = 1;
8694 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008695 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008696 {
8697 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8698 p_sj = Rows / 2;
8699 else
8700 {
8701 errmsg = e_scroll;
8702 p_sj = 1;
8703 }
8704 }
8705 if (p_so < 0 && full_screen)
8706 {
8707 errmsg = e_scroll;
8708 p_so = 0;
8709 }
8710 if (p_siso < 0 && full_screen)
8711 {
8712 errmsg = e_positive;
8713 p_siso = 0;
8714 }
8715#ifdef FEAT_CMDWIN
8716 if (p_cwh < 1)
8717 {
8718 errmsg = e_positive;
8719 p_cwh = 1;
8720 }
8721#endif
8722 if (p_ut < 0)
8723 {
8724 errmsg = e_positive;
8725 p_ut = 2000;
8726 }
8727 if (p_ss < 0)
8728 {
8729 errmsg = e_positive;
8730 p_ss = 0;
8731 }
8732
8733 /* May set global value for local option. */
8734 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8735 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8736
8737 options[opt_idx].flags |= P_WAS_SET;
8738
8739 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008740 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008741 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008742 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008743 check_redraw(options[opt_idx].flags);
8744
8745 return errmsg;
8746}
8747
8748/*
8749 * Called after an option changed: check if something needs to be redrawn.
8750 */
8751 static void
8752check_redraw(flags)
8753 long_u flags;
8754{
8755 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008756 int doclear = (flags & P_RCLR) == P_RCLR;
8757 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008758
8759#ifdef FEAT_WINDOWS
8760 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8761 status_redraw_all();
8762#endif
8763
8764 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8765 changed_window_setting();
8766 if (flags & P_RBUF)
8767 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008768 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008769 redraw_all_later(CLEAR);
8770 else if (all)
8771 redraw_all_later(NOT_VALID);
8772}
8773
8774/*
8775 * Find index for option 'arg'.
8776 * Return -1 if not found.
8777 */
8778 static int
8779findoption(arg)
8780 char_u *arg;
8781{
8782 int opt_idx;
8783 char *s, *p;
8784 static short quick_tab[27] = {0, 0}; /* quick access table */
8785 int is_term_opt;
8786
8787 /*
8788 * For first call: Initialize the quick-access table.
8789 * It contains the index for the first option that starts with a certain
8790 * letter. There are 26 letters, plus the first "t_" option.
8791 */
8792 if (quick_tab[1] == 0)
8793 {
8794 p = options[0].fullname;
8795 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8796 {
8797 if (s[0] != p[0])
8798 {
8799 if (s[0] == 't' && s[1] == '_')
8800 quick_tab[26] = opt_idx;
8801 else
8802 quick_tab[CharOrdLow(s[0])] = opt_idx;
8803 }
8804 p = s;
8805 }
8806 }
8807
8808 /*
8809 * Check for name starting with an illegal character.
8810 */
8811#ifdef EBCDIC
8812 if (!islower(arg[0]))
8813#else
8814 if (arg[0] < 'a' || arg[0] > 'z')
8815#endif
8816 return -1;
8817
8818 is_term_opt = (arg[0] == 't' && arg[1] == '_');
8819 if (is_term_opt)
8820 opt_idx = quick_tab[26];
8821 else
8822 opt_idx = quick_tab[CharOrdLow(arg[0])];
8823 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8824 {
8825 if (STRCMP(arg, s) == 0) /* match full name */
8826 break;
8827 }
8828 if (s == NULL && !is_term_opt)
8829 {
8830 opt_idx = quick_tab[CharOrdLow(arg[0])];
8831 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
8832 {
8833 s = options[opt_idx].shortname;
8834 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
8835 break;
8836 s = NULL;
8837 }
8838 }
8839 if (s == NULL)
8840 opt_idx = -1;
8841 return opt_idx;
8842}
8843
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008844#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008845/*
8846 * Get the value for an option.
8847 *
8848 * Returns:
8849 * Number or Toggle option: 1, *numval gets value.
8850 * String option: 0, *stringval gets allocated string.
8851 * Hidden Number or Toggle option: -1.
8852 * hidden String option: -2.
8853 * unknown option: -3.
8854 */
8855 int
8856get_option_value(name, numval, stringval, opt_flags)
8857 char_u *name;
8858 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02008859 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008860 int opt_flags;
8861{
8862 int opt_idx;
8863 char_u *varp;
8864
8865 opt_idx = findoption(name);
8866 if (opt_idx < 0) /* unknown option */
8867 return -3;
8868
8869 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
8870
8871 if (options[opt_idx].flags & P_STRING)
8872 {
8873 if (varp == NULL) /* hidden option */
8874 return -2;
8875 if (stringval != NULL)
8876 {
8877#ifdef FEAT_CRYPT
8878 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008879 if ((char_u **)varp == &curbuf->b_p_key
8880 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008881 *stringval = vim_strsave((char_u *)"*****");
8882 else
8883#endif
8884 *stringval = vim_strsave(*(char_u **)(varp));
8885 }
8886 return 0;
8887 }
8888
8889 if (varp == NULL) /* hidden option */
8890 return -1;
8891 if (options[opt_idx].flags & P_NUM)
8892 *numval = *(long *)varp;
8893 else
8894 {
8895 /* Special case: 'modified' is b_changed, but we also want to consider
8896 * it set when 'ff' or 'fenc' changed. */
8897 if ((int *)varp == &curbuf->b_changed)
8898 *numval = curbufIsChanged();
8899 else
8900 *numval = *(int *)varp;
8901 }
8902 return 1;
8903}
8904#endif
8905
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01008906#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008907/*
8908 * Returns the option attributes and its value. Unlike the above function it
8909 * will return either global value or local value of the option depending on
8910 * what was requested, but it will never return global value if it was
8911 * requested to return local one and vice versa. Neither it will return
8912 * buffer-local value if it was requested to return window-local one.
8913 *
8914 * Pretends that option is absent if it is not present in the requested scope
8915 * (i.e. has no global, window-local or buffer-local value depending on
8916 * opt_type). Uses
8917 *
8918 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02008919 * 0 hidden or unknown option, also option that does not have requested
8920 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008921 * see SOPT_* in vim.h for other flags
8922 *
8923 * Possible opt_type values: see SREQ_* in vim.h
8924 */
8925 int
8926get_option_value_strict(name, numval, stringval, opt_type, from)
8927 char_u *name;
8928 long *numval;
8929 char_u **stringval; /* NULL when only obtaining attributes */
8930 int opt_type;
8931 void *from;
8932{
8933 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02008934 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02008935 struct vimoption *p;
8936 int r = 0;
8937
8938 opt_idx = findoption(name);
8939 if (opt_idx < 0)
8940 return 0;
8941
8942 p = &(options[opt_idx]);
8943
8944 /* Hidden option */
8945 if (p->var == NULL)
8946 return 0;
8947
8948 if (p->flags & P_BOOL)
8949 r |= SOPT_BOOL;
8950 else if (p->flags & P_NUM)
8951 r |= SOPT_NUM;
8952 else if (p->flags & P_STRING)
8953 r |= SOPT_STRING;
8954
8955 if (p->indir == PV_NONE)
8956 {
8957 if (opt_type == SREQ_GLOBAL)
8958 r |= SOPT_GLOBAL;
8959 else
8960 return 0; /* Did not request global-only option */
8961 }
8962 else
8963 {
8964 if (p->indir & PV_BOTH)
8965 r |= SOPT_GLOBAL;
8966 else if (opt_type == SREQ_GLOBAL)
8967 return 0; /* Requested global option */
8968
8969 if (p->indir & PV_WIN)
8970 {
8971 if (opt_type == SREQ_BUF)
8972 return 0; /* Did not request window-local option */
8973 else
8974 r |= SOPT_WIN;
8975 }
8976 else if (p->indir & PV_BUF)
8977 {
8978 if (opt_type == SREQ_WIN)
8979 return 0; /* Did not request buffer-local option */
8980 else
8981 r |= SOPT_BUF;
8982 }
8983 }
8984
8985 if (stringval == NULL)
8986 return r;
8987
8988 if (opt_type == SREQ_GLOBAL)
8989 varp = p->var;
8990 else
8991 {
8992 if (opt_type == SREQ_BUF)
8993 {
8994 /* Special case: 'modified' is b_changed, but we also want to
8995 * consider it set when 'ff' or 'fenc' changed. */
8996 if (p->indir == PV_MOD)
8997 {
8998 *numval = bufIsChanged((buf_T *) from);
8999 varp = NULL;
9000 }
9001#ifdef FEAT_CRYPT
9002 else if (p->indir == PV_KEY)
9003 {
9004 /* never return the value of the crypt key */
9005 *stringval = NULL;
9006 varp = NULL;
9007 }
9008#endif
9009 else
9010 {
9011 aco_save_T aco;
9012 aucmd_prepbuf(&aco, (buf_T *) from);
9013 varp = get_varp(p);
9014 aucmd_restbuf(&aco);
9015 }
9016 }
9017 else if (opt_type == SREQ_WIN)
9018 {
9019 win_T *save_curwin;
9020 save_curwin = curwin;
9021 curwin = (win_T *) from;
9022 curbuf = curwin->w_buffer;
9023 varp = get_varp(p);
9024 curwin = save_curwin;
9025 curbuf = curwin->w_buffer;
9026 }
9027 if (varp == p->var)
9028 return (r | SOPT_UNSET);
9029 }
9030
9031 if (varp != NULL)
9032 {
9033 if (p->flags & P_STRING)
9034 *stringval = vim_strsave(*(char_u **)(varp));
9035 else if (p->flags & P_NUM)
9036 *numval = *(long *) varp;
9037 else
9038 *numval = *(int *)varp;
9039 }
9040
9041 return r;
9042}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009043
9044/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009045 * Iterate over options. First argument is a pointer to a pointer to a
9046 * structure inside options[] array, second is option type like in the above
9047 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009048 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009049 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009050 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009051 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009052 * first argument to NULL.
9053 *
9054 * Returns full option name for current option on each call.
9055 */
9056 char_u *
9057option_iter_next(option, opt_type)
9058 void **option;
9059 int opt_type;
9060{
9061 struct vimoption *ret = NULL;
9062 do
9063 {
9064 if (*option == NULL)
9065 *option = (void *) options;
9066 else if (((struct vimoption *) (*option))->fullname == NULL)
9067 {
9068 *option = NULL;
9069 return NULL;
9070 }
9071 else
9072 *option = (void *) (((struct vimoption *) (*option)) + 1);
9073
9074 ret = ((struct vimoption *) (*option));
9075
9076 /* Hidden option */
9077 if (ret->var == NULL)
9078 {
9079 ret = NULL;
9080 continue;
9081 }
9082
9083 switch (opt_type)
9084 {
9085 case SREQ_GLOBAL:
9086 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9087 ret = NULL;
9088 break;
9089 case SREQ_BUF:
9090 if (!(ret->indir & PV_BUF))
9091 ret = NULL;
9092 break;
9093 case SREQ_WIN:
9094 if (!(ret->indir & PV_WIN))
9095 ret = NULL;
9096 break;
9097 default:
9098 EMSG2(_(e_intern2), "option_iter_next()");
9099 return NULL;
9100 }
9101 }
9102 while (ret == NULL);
9103
9104 return (char_u *)ret->fullname;
9105}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009106#endif
9107
Bram Moolenaar071d4272004-06-13 20:20:40 +00009108/*
9109 * Set the value of option "name".
9110 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009111 *
9112 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009113 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009114 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009115set_option_value(name, number, string, opt_flags)
9116 char_u *name;
9117 long number;
9118 char_u *string;
9119 int opt_flags; /* OPT_LOCAL or 0 (both) */
9120{
9121 int opt_idx;
9122 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009123 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009124
9125 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009126 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009127 EMSG2(_("E355: Unknown option: %s"), name);
9128 else
9129 {
9130 flags = options[opt_idx].flags;
9131#ifdef HAVE_SANDBOX
9132 /* Disallow changing some options in the sandbox */
9133 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009134 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009135 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009136 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009137 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009138#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009139 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009140 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009141 else
9142 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009143 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009144 if (varp != NULL) /* hidden option is not changed */
9145 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009146 if (number == 0 && string != NULL)
9147 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009148 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009149
9150 /* Either we are given a string or we are setting option
9151 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009152 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009153 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009154 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009155 {
9156 /* There's another character after zeros or the string
9157 * is empty. In both cases, we are trying to set a
9158 * num option using a string. */
9159 EMSG3(_("E521: Number required: &%s = '%s'"),
9160 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009161 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009162
9163 }
9164 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009165 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009166 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009167 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009168 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009169 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009170 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009171 }
9172 }
9173 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009174 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009175}
9176
9177/*
9178 * Get the terminal code for a terminal option.
9179 * Returns NULL when not found.
9180 */
9181 char_u *
9182get_term_code(tname)
9183 char_u *tname;
9184{
9185 int opt_idx;
9186 char_u *varp;
9187
9188 if (tname[0] != 't' || tname[1] != '_' ||
9189 tname[2] == NUL || tname[3] == NUL)
9190 return NULL;
9191 if ((opt_idx = findoption(tname)) >= 0)
9192 {
9193 varp = get_varp(&(options[opt_idx]));
9194 if (varp != NULL)
9195 varp = *(char_u **)(varp);
9196 return varp;
9197 }
9198 return find_termcode(tname + 2);
9199}
9200
9201 char_u *
9202get_highlight_default()
9203{
9204 int i;
9205
9206 i = findoption((char_u *)"hl");
9207 if (i >= 0)
9208 return options[i].def_val[VI_DEFAULT];
9209 return (char_u *)NULL;
9210}
9211
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009212#if defined(FEAT_MBYTE) || defined(PROTO)
9213 char_u *
9214get_encoding_default()
9215{
9216 int i;
9217
9218 i = findoption((char_u *)"enc");
9219 if (i >= 0)
9220 return options[i].def_val[VI_DEFAULT];
9221 return (char_u *)NULL;
9222}
9223#endif
9224
Bram Moolenaar071d4272004-06-13 20:20:40 +00009225/*
9226 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9227 */
9228 static int
9229find_key_option(arg)
9230 char_u *arg;
9231{
9232 int key;
9233 int modifiers;
9234
9235 /*
9236 * Don't use get_special_key_code() for t_xx, we don't want it to call
9237 * add_termcap_entry().
9238 */
9239 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9240 key = TERMCAP2KEY(arg[2], arg[3]);
9241 else
9242 {
9243 --arg; /* put arg at the '<' */
9244 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009245 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009246 if (modifiers) /* can't handle modifiers here */
9247 key = 0;
9248 }
9249 return key;
9250}
9251
9252/*
9253 * if 'all' == 0: show changed options
9254 * if 'all' == 1: show all normal options
9255 * if 'all' == 2: show all terminal options
9256 */
9257 static void
9258showoptions(all, opt_flags)
9259 int all;
9260 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9261{
9262 struct vimoption *p;
9263 int col;
9264 int isterm;
9265 char_u *varp;
9266 struct vimoption **items;
9267 int item_count;
9268 int run;
9269 int row, rows;
9270 int cols;
9271 int i;
9272 int len;
9273
9274#define INC 20
9275#define GAP 3
9276
9277 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9278 PARAM_COUNT));
9279 if (items == NULL)
9280 return;
9281
9282 /* Highlight title */
9283 if (all == 2)
9284 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9285 else if (opt_flags & OPT_GLOBAL)
9286 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9287 else if (opt_flags & OPT_LOCAL)
9288 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9289 else
9290 MSG_PUTS_TITLE(_("\n--- Options ---"));
9291
9292 /*
9293 * do the loop two times:
9294 * 1. display the short items
9295 * 2. display the long items (only strings and numbers)
9296 */
9297 for (run = 1; run <= 2 && !got_int; ++run)
9298 {
9299 /*
9300 * collect the items in items[]
9301 */
9302 item_count = 0;
9303 for (p = &options[0]; p->fullname != NULL; p++)
9304 {
9305 varp = NULL;
9306 isterm = istermoption(p);
9307 if (opt_flags != 0)
9308 {
9309 if (p->indir != PV_NONE && !isterm)
9310 varp = get_varp_scope(p, opt_flags);
9311 }
9312 else
9313 varp = get_varp(p);
9314 if (varp != NULL
9315 && ((all == 2 && isterm)
9316 || (all == 1 && !isterm)
9317 || (all == 0 && !optval_default(p, varp))))
9318 {
9319 if (p->flags & P_BOOL)
9320 len = 1; /* a toggle option fits always */
9321 else
9322 {
9323 option_value2string(p, opt_flags);
9324 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9325 }
9326 if ((len <= INC - GAP && run == 1) ||
9327 (len > INC - GAP && run == 2))
9328 items[item_count++] = p;
9329 }
9330 }
9331
9332 /*
9333 * display the items
9334 */
9335 if (run == 1)
9336 {
9337 cols = (Columns + GAP - 3) / INC;
9338 if (cols == 0)
9339 cols = 1;
9340 rows = (item_count + cols - 1) / cols;
9341 }
9342 else /* run == 2 */
9343 rows = item_count;
9344 for (row = 0; row < rows && !got_int; ++row)
9345 {
9346 msg_putchar('\n'); /* go to next line */
9347 if (got_int) /* 'q' typed in more */
9348 break;
9349 col = 0;
9350 for (i = row; i < item_count; i += rows)
9351 {
9352 msg_col = col; /* make columns */
9353 showoneopt(items[i], opt_flags);
9354 col += INC;
9355 }
9356 out_flush();
9357 ui_breakcheck();
9358 }
9359 }
9360 vim_free(items);
9361}
9362
9363/*
9364 * Return TRUE if option "p" has its default value.
9365 */
9366 static int
9367optval_default(p, varp)
9368 struct vimoption *p;
9369 char_u *varp;
9370{
9371 int dvi;
9372
9373 if (varp == NULL)
9374 return TRUE; /* hidden option is always at default */
9375 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9376 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009377 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009378 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009379 /* the cast to long is required for Manx C, long_i is
9380 * needed for MSVC */
9381 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009382 /* P_STRING */
9383 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9384}
9385
9386/*
9387 * showoneopt: show the value of one option
9388 * must not be called with a hidden option!
9389 */
9390 static void
9391showoneopt(p, opt_flags)
9392 struct vimoption *p;
9393 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9394{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009395 char_u *varp;
9396 int save_silent = silent_mode;
9397
9398 silent_mode = FALSE;
9399 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009400
9401 varp = get_varp_scope(p, opt_flags);
9402
9403 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9404 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9405 ? !curbufIsChanged() : !*(int *)varp))
9406 MSG_PUTS("no");
9407 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9408 MSG_PUTS("--");
9409 else
9410 MSG_PUTS(" ");
9411 MSG_PUTS(p->fullname);
9412 if (!(p->flags & P_BOOL))
9413 {
9414 msg_putchar('=');
9415 /* put value string in NameBuff */
9416 option_value2string(p, opt_flags);
9417 msg_outtrans(NameBuff);
9418 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009419
9420 silent_mode = save_silent;
9421 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009422}
9423
9424/*
9425 * Write modified options as ":set" commands to a file.
9426 *
9427 * There are three values for "opt_flags":
9428 * OPT_GLOBAL: Write global option values and fresh values of
9429 * buffer-local options (used for start of a session
9430 * file).
9431 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9432 * curwin (used for a vimrc file).
9433 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9434 * and local values for window-local options of
9435 * curwin. Local values are also written when at the
9436 * default value, because a modeline or autocommand
9437 * may have set them when doing ":edit file" and the
9438 * user has set them back at the default or fresh
9439 * value.
9440 * When "local_only" is TRUE, don't write fresh
9441 * values, only local values (for ":mkview").
9442 * (fresh value = value used for a new buffer or window for a local option).
9443 *
9444 * Return FAIL on error, OK otherwise.
9445 */
9446 int
9447makeset(fd, opt_flags, local_only)
9448 FILE *fd;
9449 int opt_flags;
9450 int local_only;
9451{
9452 struct vimoption *p;
9453 char_u *varp; /* currently used value */
9454 char_u *varp_fresh; /* local value */
9455 char_u *varp_local = NULL; /* fresh value */
9456 char *cmd;
9457 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009458 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009459
9460 /*
9461 * The options that don't have a default (terminal name, columns, lines)
9462 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009463 * Do the loop over "options[]" twice: once for options with the
9464 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009465 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009466 for (pri = 1; pri >= 0; --pri)
9467 {
9468 for (p = &options[0]; !istermoption(p); p++)
9469 if (!(p->flags & P_NO_MKRC)
9470 && !istermoption(p)
9471 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009472 {
9473 /* skip global option when only doing locals */
9474 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9475 continue;
9476
9477 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9478 * file, they are always buffer-specific. */
9479 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9480 continue;
9481
9482 /* Global values are only written when not at the default value. */
9483 varp = get_varp_scope(p, opt_flags);
9484 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9485 continue;
9486
9487 round = 2;
9488 if (p->indir != PV_NONE)
9489 {
9490 if (p->var == VAR_WIN)
9491 {
9492 /* skip window-local option when only doing globals */
9493 if (!(opt_flags & OPT_LOCAL))
9494 continue;
9495 /* When fresh value of window-local option is not at the
9496 * default, need to write it too. */
9497 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9498 {
9499 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9500 if (!optval_default(p, varp_fresh))
9501 {
9502 round = 1;
9503 varp_local = varp;
9504 varp = varp_fresh;
9505 }
9506 }
9507 }
9508 }
9509
9510 /* Round 1: fresh value for window-local options.
9511 * Round 2: other values */
9512 for ( ; round <= 2; varp = varp_local, ++round)
9513 {
9514 if (round == 1 || (opt_flags & OPT_GLOBAL))
9515 cmd = "set";
9516 else
9517 cmd = "setlocal";
9518
9519 if (p->flags & P_BOOL)
9520 {
9521 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9522 return FAIL;
9523 }
9524 else if (p->flags & P_NUM)
9525 {
9526 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9527 return FAIL;
9528 }
9529 else /* P_STRING */
9530 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009531#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9532 int do_endif = FALSE;
9533
Bram Moolenaar071d4272004-06-13 20:20:40 +00009534 /* Don't set 'syntax' and 'filetype' again if the value is
9535 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009536 if (
9537# if defined(FEAT_SYN_HL)
9538 p->indir == PV_SYN
9539# if defined(FEAT_AUTOCMD)
9540 ||
9541# endif
9542# endif
9543# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009544 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009545# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009546 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 {
9548 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9549 *(char_u **)(varp)) < 0
9550 || put_eol(fd) < 0)
9551 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009552 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009553 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009554#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009555 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9556 (p->flags & P_EXPAND) != 0) == FAIL)
9557 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009558#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9559 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009560 {
9561 if (put_line(fd, "endif") == FAIL)
9562 return FAIL;
9563 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009564#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009565 }
9566 }
9567 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009568 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009569 return OK;
9570}
9571
9572#if defined(FEAT_FOLDING) || defined(PROTO)
9573/*
9574 * Generate set commands for the local fold options only. Used when
9575 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9576 */
9577 int
9578makefoldset(fd)
9579 FILE *fd;
9580{
9581 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9582# ifdef FEAT_EVAL
9583 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9584 == FAIL
9585# endif
9586 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9587 == FAIL
9588 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9589 == FAIL
9590 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9591 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9592 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9593 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9594 )
9595 return FAIL;
9596
9597 return OK;
9598}
9599#endif
9600
9601 static int
9602put_setstring(fd, cmd, name, valuep, expand)
9603 FILE *fd;
9604 char *cmd;
9605 char *name;
9606 char_u **valuep;
9607 int expand;
9608{
9609 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009610 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009611
9612 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9613 return FAIL;
9614 if (*valuep != NULL)
9615 {
9616 /* Output 'pastetoggle' as key names. For other
9617 * options some characters have to be escaped with
9618 * CTRL-V or backslash */
9619 if (valuep == &p_pt)
9620 {
9621 s = *valuep;
9622 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009623 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009624 return FAIL;
9625 }
9626 else if (expand)
9627 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009628 buf = alloc(MAXPATHL);
9629 if (buf == NULL)
9630 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009631 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9632 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009633 {
9634 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009635 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009636 }
9637 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009638 }
9639 else if (put_escstr(fd, *valuep, 2) == FAIL)
9640 return FAIL;
9641 }
9642 if (put_eol(fd) < 0)
9643 return FAIL;
9644 return OK;
9645}
9646
9647 static int
9648put_setnum(fd, cmd, name, valuep)
9649 FILE *fd;
9650 char *cmd;
9651 char *name;
9652 long *valuep;
9653{
9654 long wc;
9655
9656 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9657 return FAIL;
9658 if (wc_use_keyname((char_u *)valuep, &wc))
9659 {
9660 /* print 'wildchar' and 'wildcharm' as a key name */
9661 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9662 return FAIL;
9663 }
9664 else if (fprintf(fd, "%ld", *valuep) < 0)
9665 return FAIL;
9666 if (put_eol(fd) < 0)
9667 return FAIL;
9668 return OK;
9669}
9670
9671 static int
9672put_setbool(fd, cmd, name, value)
9673 FILE *fd;
9674 char *cmd;
9675 char *name;
9676 int value;
9677{
Bram Moolenaar893de922007-10-02 18:40:57 +00009678 if (value < 0) /* global/local option using global value */
9679 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009680 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9681 || put_eol(fd) < 0)
9682 return FAIL;
9683 return OK;
9684}
9685
9686/*
9687 * Clear all the terminal options.
9688 * If the option has been allocated, free the memory.
9689 * Terminal options are never hidden or indirect.
9690 */
9691 void
9692clear_termoptions()
9693{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009694 /*
9695 * Reset a few things before clearing the old options. This may cause
9696 * outputting a few things that the terminal doesn't understand, but the
9697 * screen will be cleared later, so this is OK.
9698 */
9699#ifdef FEAT_MOUSE_TTY
9700 mch_setmouse(FALSE); /* switch mouse off */
9701#endif
9702#ifdef FEAT_TITLE
9703 mch_restore_title(3); /* restore window titles */
9704#endif
9705#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9706 /* When starting the GUI close the display opened for the clipboard.
9707 * After restoring the title, because that will need the display. */
9708 if (gui.starting)
9709 clear_xterm_clip();
9710#endif
9711#ifdef WIN3264
9712 /*
9713 * Check if this is allowed now.
9714 */
9715 if (can_end_termcap_mode(FALSE) == TRUE)
9716#endif
9717 stoptermcap(); /* stop termcap mode */
9718
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009719 free_termoptions();
9720}
9721
9722 void
9723free_termoptions()
9724{
9725 struct vimoption *p;
9726
Bram Moolenaar071d4272004-06-13 20:20:40 +00009727 for (p = &options[0]; p->fullname != NULL; p++)
9728 if (istermoption(p))
9729 {
9730 if (p->flags & P_ALLOCED)
9731 free_string_option(*(char_u **)(p->var));
9732 if (p->flags & P_DEF_ALLOCED)
9733 free_string_option(p->def_val[VI_DEFAULT]);
9734 *(char_u **)(p->var) = empty_option;
9735 p->def_val[VI_DEFAULT] = empty_option;
9736 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9737 }
9738 clear_termcodes();
9739}
9740
9741/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009742 * Free the string for one term option, if it was allocated.
9743 * Set the string to empty_option and clear allocated flag.
9744 * "var" points to the option value.
9745 */
9746 void
9747free_one_termoption(var)
9748 char_u *var;
9749{
9750 struct vimoption *p;
9751
9752 for (p = &options[0]; p->fullname != NULL; p++)
9753 if (p->var == var)
9754 {
9755 if (p->flags & P_ALLOCED)
9756 free_string_option(*(char_u **)(p->var));
9757 *(char_u **)(p->var) = empty_option;
9758 p->flags &= ~P_ALLOCED;
9759 break;
9760 }
9761}
9762
9763/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009764 * Set the terminal option defaults to the current value.
9765 * Used after setting the terminal name.
9766 */
9767 void
9768set_term_defaults()
9769{
9770 struct vimoption *p;
9771
9772 for (p = &options[0]; p->fullname != NULL; p++)
9773 {
9774 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9775 {
9776 if (p->flags & P_DEF_ALLOCED)
9777 {
9778 free_string_option(p->def_val[VI_DEFAULT]);
9779 p->flags &= ~P_DEF_ALLOCED;
9780 }
9781 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9782 if (p->flags & P_ALLOCED)
9783 {
9784 p->flags |= P_DEF_ALLOCED;
9785 p->flags &= ~P_ALLOCED; /* don't free the value now */
9786 }
9787 }
9788 }
9789}
9790
9791/*
9792 * return TRUE if 'p' starts with 't_'
9793 */
9794 static int
9795istermoption(p)
9796 struct vimoption *p;
9797{
9798 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9799}
9800
9801/*
9802 * Compute columns for ruler and shown command. 'sc_col' is also used to
9803 * decide what the maximum length of a message on the status line can be.
9804 * If there is a status line for the last window, 'sc_col' is independent
9805 * of 'ru_col'.
9806 */
9807
9808#define COL_RULER 17 /* columns needed by standard ruler */
9809
9810 void
9811comp_col()
9812{
9813#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9814 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9815
9816 sc_col = 0;
9817 ru_col = 0;
9818 if (p_ru)
9819 {
9820#ifdef FEAT_STL_OPT
9821 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
9822#else
9823 ru_col = COL_RULER + 1;
9824#endif
9825 /* no last status line, adjust sc_col */
9826 if (!last_has_status)
9827 sc_col = ru_col;
9828 }
9829 if (p_sc)
9830 {
9831 sc_col += SHOWCMD_COLS;
9832 if (!p_ru || last_has_status) /* no need for separating space */
9833 ++sc_col;
9834 }
9835 sc_col = Columns - sc_col;
9836 ru_col = Columns - ru_col;
9837 if (sc_col <= 0) /* screen too narrow, will become a mess */
9838 sc_col = 1;
9839 if (ru_col <= 0)
9840 ru_col = 1;
9841#else
9842 sc_col = Columns;
9843 ru_col = Columns;
9844#endif
9845}
9846
9847/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009848 * Unset local option value, similar to ":set opt<".
9849 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009850 void
9851unset_global_local_option(name, from)
9852 char_u *name;
9853 void *from;
9854{
9855 struct vimoption *p;
9856 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009857 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009858
9859 opt_idx = findoption(name);
9860 p = &(options[opt_idx]);
9861
9862 switch ((int)p->indir)
9863 {
9864 /* global option with local value: use local value if it's been set */
9865 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009866 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009867 break;
9868 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009869 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009870 break;
9871 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009872 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009873 break;
9874 case PV_AR:
9875 buf->b_p_ar = -1;
9876 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009877 case PV_BKC:
9878 clear_string_option(&buf->b_p_bkc);
9879 buf->b_bkc_flags = 0;
9880 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009881 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009882 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009883 break;
9884#ifdef FEAT_FIND_ID
9885 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009886 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009887 break;
9888 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009889 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009890 break;
9891#endif
9892#ifdef FEAT_INS_EXPAND
9893 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009894 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009895 break;
9896 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009897 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009898 break;
9899#endif
9900#ifdef FEAT_QUICKFIX
9901 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009902 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009903 break;
9904 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009905 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009906 break;
9907 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009908 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009909 break;
9910#endif
9911#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9912 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009913 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009914 break;
9915#endif
9916#if defined(FEAT_CRYPT)
9917 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009918 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009919 break;
9920#endif
9921#ifdef FEAT_STL_OPT
9922 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +02009923 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009924 break;
9925#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009926 case PV_UL:
9927 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
9928 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009929#ifdef FEAT_LISP
9930 case PV_LW:
9931 clear_string_option(&buf->b_p_lw);
9932 break;
9933#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009934 }
9935}
9936
9937/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009938 * Get pointer to option variable, depending on local or global scope.
9939 */
9940 static char_u *
9941get_varp_scope(p, opt_flags)
9942 struct vimoption *p;
9943 int opt_flags;
9944{
9945 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
9946 {
9947 if (p->var == VAR_WIN)
9948 return (char_u *)GLOBAL_WO(get_varp(p));
9949 return p->var;
9950 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009951 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009952 {
9953 switch ((int)p->indir)
9954 {
9955#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009956 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
9957 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
9958 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009960 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
9961 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
9962 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +00009963 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009964 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009966 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
9967 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009968#endif
9969#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009970 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
9971 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009972#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00009973#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
9974 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
9975#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02009976#if defined(FEAT_CRYPT)
9977 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
9978#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009979#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009980 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00009981#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009982 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01009983#ifdef FEAT_LISP
9984 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
9985#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009986 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009987 }
9988 return NULL; /* "cannot happen" */
9989 }
9990 return get_varp(p);
9991}
9992
9993/*
9994 * Get pointer to option variable.
9995 */
9996 static char_u *
9997get_varp(p)
9998 struct vimoption *p;
9999{
10000 /* hidden option, always return NULL */
10001 if (p->var == NULL)
10002 return NULL;
10003
10004 switch ((int)p->indir)
10005 {
10006 case PV_NONE: return p->var;
10007
10008 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010009 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010010 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010011 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010012 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010013 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010014 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010015 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010017 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010018 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010019 case PV_BKC: return *curbuf->b_p_bkc != NUL
10020 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010021#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010022 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010023 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010024 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010025 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10026#endif
10027#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010028 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010029 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010030 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10032#endif
10033#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010034 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010035 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010036 case PV_GP: return *curbuf->b_p_gp != NUL
10037 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10038 case PV_MP: return *curbuf->b_p_mp != NUL
10039 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010041#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10042 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10043 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10044#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010045#if defined(FEAT_CRYPT)
10046 case PV_CM: return *curbuf->b_p_cm != NUL
10047 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10048#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010049#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010050 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010051 ? (char_u *)&(curwin->w_p_stl) : p->var;
10052#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010053 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10054 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010055#ifdef FEAT_LISP
10056 case PV_LW: return *curbuf->b_p_lw != NUL
10057 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10058#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010059
10060#ifdef FEAT_ARABIC
10061 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10062#endif
10063 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010064#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010065 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10066#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010067#ifdef FEAT_SYN_HL
10068 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10069 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010070 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010072#ifdef FEAT_DIFF
10073 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10074#endif
10075#ifdef FEAT_FOLDING
10076 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10077 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10078 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10079 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10080 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10081 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10082 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10083# ifdef FEAT_EVAL
10084 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10085 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10086# endif
10087 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10088#endif
10089 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010090 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010091#ifdef FEAT_LINEBREAK
10092 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10093#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010094#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010095 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10096#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010097#ifdef FEAT_VERTSPLIT
10098 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10099#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010100#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10101 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10102#endif
10103#ifdef FEAT_RIGHTLEFT
10104 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10105 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10106#endif
10107 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10108 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10109#ifdef FEAT_LINEBREAK
10110 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010111 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10112 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010113#endif
10114#ifdef FEAT_SCROLLBIND
10115 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10116#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010117#ifdef FEAT_CURSORBIND
10118 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10119#endif
10120#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010121 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10122 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010123#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124
10125 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10126 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10127#ifdef FEAT_MBYTE
10128 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10129#endif
10130#if defined(FEAT_QUICKFIX)
10131 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10132 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10133#endif
10134 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10135 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10136#ifdef FEAT_CINDENT
10137 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10138 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10139 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10140#endif
10141#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10142 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10143#endif
10144#ifdef FEAT_COMMENTS
10145 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10146#endif
10147#ifdef FEAT_FOLDING
10148 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10149#endif
10150#ifdef FEAT_INS_EXPAND
10151 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10152#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010153#ifdef FEAT_COMPL_FUNC
10154 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010155 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010157 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
10158 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10159#ifdef FEAT_MBYTE
10160 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10161#endif
10162 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10163#ifdef FEAT_AUTOCMD
10164 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10165#endif
10166 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010167 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010168 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10169 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10170 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10171 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10172#ifdef FEAT_FIND_ID
10173# ifdef FEAT_EVAL
10174 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10175# endif
10176#endif
10177#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10178 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10179 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10180#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010181#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010182 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10183#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184#ifdef FEAT_CRYPT
10185 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10186#endif
10187#ifdef FEAT_LISP
10188 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10189#endif
10190 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10191 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10192 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10193 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10194 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010196#ifdef FEAT_TEXTOBJ
10197 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10198#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10200#ifdef FEAT_SMARTINDENT
10201 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10202#endif
10203#ifndef SHORT_FNAME
10204 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10205#endif
10206 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10207#ifdef FEAT_SEARCHPATH
10208 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10209#endif
10210 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10211#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010212 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010213 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10214#endif
10215#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010216 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10217 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10218 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010219#endif
10220 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10221 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10222 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10223 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010224#ifdef FEAT_PERSISTENT_UNDO
10225 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10226#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10228#ifdef FEAT_KEYMAP
10229 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10230#endif
10231 default: EMSG(_("E356: get_varp ERROR"));
10232 }
10233 /* always return a valid pointer to avoid a crash! */
10234 return (char_u *)&(curbuf->b_p_wm);
10235}
10236
10237/*
10238 * Get the value of 'equalprg', either the buffer-local one or the global one.
10239 */
10240 char_u *
10241get_equalprg()
10242{
10243 if (*curbuf->b_p_ep == NUL)
10244 return p_ep;
10245 return curbuf->b_p_ep;
10246}
10247
10248#if defined(FEAT_WINDOWS) || defined(PROTO)
10249/*
10250 * Copy options from one window to another.
10251 * Used when splitting a window.
10252 */
10253 void
10254win_copy_options(wp_from, wp_to)
10255 win_T *wp_from;
10256 win_T *wp_to;
10257{
10258 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10259 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10260# ifdef FEAT_RIGHTLEFT
10261# ifdef FEAT_FKMAP
10262 /* Is this right? */
10263 wp_to->w_farsi = wp_from->w_farsi;
10264# endif
10265# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010266#if defined(FEAT_LINEBREAK)
10267 briopt_check(wp_to);
10268#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269}
10270#endif
10271
10272/*
10273 * Copy the options from one winopt_T to another.
10274 * Doesn't free the old option values in "to", use clear_winopt() for that.
10275 * The 'scroll' option is not copied, because it depends on the window height.
10276 * The 'previewwindow' option is reset, there can be only one preview window.
10277 */
10278 void
10279copy_winopt(from, to)
10280 winopt_T *from;
10281 winopt_T *to;
10282{
10283#ifdef FEAT_ARABIC
10284 to->wo_arab = from->wo_arab;
10285#endif
10286 to->wo_list = from->wo_list;
10287 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010288 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010289#ifdef FEAT_LINEBREAK
10290 to->wo_nuw = from->wo_nuw;
10291#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010292#ifdef FEAT_RIGHTLEFT
10293 to->wo_rl = from->wo_rl;
10294 to->wo_rlc = vim_strsave(from->wo_rlc);
10295#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010296#ifdef FEAT_STL_OPT
10297 to->wo_stl = vim_strsave(from->wo_stl);
10298#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010299 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010300#ifdef FEAT_DIFF
10301 to->wo_wrap_save = from->wo_wrap_save;
10302#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303#ifdef FEAT_LINEBREAK
10304 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010305 to->wo_bri = from->wo_bri;
10306 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307#endif
10308#ifdef FEAT_SCROLLBIND
10309 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010310 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010312#ifdef FEAT_CURSORBIND
10313 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010314 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010315#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010316#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010317 to->wo_spell = from->wo_spell;
10318#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010319#ifdef FEAT_SYN_HL
10320 to->wo_cuc = from->wo_cuc;
10321 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010322 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324#ifdef FEAT_DIFF
10325 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010326 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010327#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010328#ifdef FEAT_CONCEAL
10329 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010330 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010331#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010332#ifdef FEAT_FOLDING
10333 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010334 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010335 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010336 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337 to->wo_fdi = vim_strsave(from->wo_fdi);
10338 to->wo_fml = from->wo_fml;
10339 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010340 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010342 to->wo_fdm_save = from->wo_diff_saved
10343 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344 to->wo_fdn = from->wo_fdn;
10345# ifdef FEAT_EVAL
10346 to->wo_fde = vim_strsave(from->wo_fde);
10347 to->wo_fdt = vim_strsave(from->wo_fdt);
10348# endif
10349 to->wo_fmr = vim_strsave(from->wo_fmr);
10350#endif
10351 check_winopt(to); /* don't want NULL pointers */
10352}
10353
10354/*
10355 * Check string options in a window for a NULL value.
10356 */
10357 void
10358check_win_options(win)
10359 win_T *win;
10360{
10361 check_winopt(&win->w_onebuf_opt);
10362 check_winopt(&win->w_allbuf_opt);
10363}
10364
10365/*
10366 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10367 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010368 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010369check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010370 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010371{
10372#ifdef FEAT_FOLDING
10373 check_string_option(&wop->wo_fdi);
10374 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010375 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010376# ifdef FEAT_EVAL
10377 check_string_option(&wop->wo_fde);
10378 check_string_option(&wop->wo_fdt);
10379# endif
10380 check_string_option(&wop->wo_fmr);
10381#endif
10382#ifdef FEAT_RIGHTLEFT
10383 check_string_option(&wop->wo_rlc);
10384#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010385#ifdef FEAT_STL_OPT
10386 check_string_option(&wop->wo_stl);
10387#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010388#ifdef FEAT_SYN_HL
10389 check_string_option(&wop->wo_cc);
10390#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010391#ifdef FEAT_CONCEAL
10392 check_string_option(&wop->wo_cocu);
10393#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010394#ifdef FEAT_LINEBREAK
10395 check_string_option(&wop->wo_briopt);
10396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010397}
10398
10399/*
10400 * Free the allocated memory inside a winopt_T.
10401 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402 void
10403clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010404 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010405{
10406#ifdef FEAT_FOLDING
10407 clear_string_option(&wop->wo_fdi);
10408 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010409 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010410# ifdef FEAT_EVAL
10411 clear_string_option(&wop->wo_fde);
10412 clear_string_option(&wop->wo_fdt);
10413# endif
10414 clear_string_option(&wop->wo_fmr);
10415#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010416#ifdef FEAT_LINEBREAK
10417 clear_string_option(&wop->wo_briopt);
10418#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010419#ifdef FEAT_RIGHTLEFT
10420 clear_string_option(&wop->wo_rlc);
10421#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010422#ifdef FEAT_STL_OPT
10423 clear_string_option(&wop->wo_stl);
10424#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010425#ifdef FEAT_SYN_HL
10426 clear_string_option(&wop->wo_cc);
10427#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010428#ifdef FEAT_CONCEAL
10429 clear_string_option(&wop->wo_cocu);
10430#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431}
10432
10433/*
10434 * Copy global option values to local options for one buffer.
10435 * Used when creating a new buffer and sometimes when entering a buffer.
10436 * flags:
10437 * BCO_ENTER We will enter the buf buffer.
10438 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10439 * appropriate.
10440 * BCO_NOHELP Don't copy the values to a help buffer.
10441 */
10442 void
10443buf_copy_options(buf, flags)
10444 buf_T *buf;
10445 int flags;
10446{
10447 int should_copy = TRUE;
10448 char_u *save_p_isk = NULL; /* init for GCC */
10449 int dont_do_help;
10450 int did_isk = FALSE;
10451
10452 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010453 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010454 */
10455 if (buf == NULL || !buf_valid(buf))
10456 return;
10457
10458 /*
10459 * Skip this when the option defaults have not been set yet. Happens when
10460 * main() allocates the first buffer.
10461 */
10462 if (p_cpo != NULL)
10463 {
10464 /*
10465 * Always copy when entering and 'cpo' contains 'S'.
10466 * Don't copy when already initialized.
10467 * Don't copy when 'cpo' contains 's' and not entering.
10468 * 'S' BCO_ENTER initialized 's' should_copy
10469 * yes yes X X TRUE
10470 * yes no yes X FALSE
10471 * no X yes X FALSE
10472 * X no no yes FALSE
10473 * X no no no TRUE
10474 * no yes no X TRUE
10475 */
10476 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10477 && (buf->b_p_initialized
10478 || (!(flags & BCO_ENTER)
10479 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10480 should_copy = FALSE;
10481
10482 if (should_copy || (flags & BCO_ALWAYS))
10483 {
10484 /* Don't copy the options specific to a help buffer when
10485 * BCO_NOHELP is given or the options were initialized already
10486 * (jumping back to a help file with CTRL-T or CTRL-O) */
10487 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10488 || buf->b_p_initialized;
10489 if (dont_do_help) /* don't free b_p_isk */
10490 {
10491 save_p_isk = buf->b_p_isk;
10492 buf->b_p_isk = NULL;
10493 }
10494 /*
10495 * Always free the allocated strings.
10496 * If not already initialized, set 'readonly' and copy 'fileformat'.
10497 */
10498 if (!buf->b_p_initialized)
10499 {
10500 free_buf_options(buf, TRUE);
10501 buf->b_p_ro = FALSE; /* don't copy readonly */
10502 buf->b_p_tx = p_tx;
10503#ifdef FEAT_MBYTE
10504 buf->b_p_fenc = vim_strsave(p_fenc);
10505#endif
10506 buf->b_p_ff = vim_strsave(p_ff);
10507#if defined(FEAT_QUICKFIX)
10508 buf->b_p_bh = empty_option;
10509 buf->b_p_bt = empty_option;
10510#endif
10511 }
10512 else
10513 free_buf_options(buf, FALSE);
10514
10515 buf->b_p_ai = p_ai;
10516 buf->b_p_ai_nopaste = p_ai_nopaste;
10517 buf->b_p_sw = p_sw;
10518 buf->b_p_tw = p_tw;
10519 buf->b_p_tw_nopaste = p_tw_nopaste;
10520 buf->b_p_tw_nobin = p_tw_nobin;
10521 buf->b_p_wm = p_wm;
10522 buf->b_p_wm_nopaste = p_wm_nopaste;
10523 buf->b_p_wm_nobin = p_wm_nobin;
10524 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010525#ifdef FEAT_MBYTE
10526 buf->b_p_bomb = p_bomb;
10527#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528 buf->b_p_et = p_et;
10529 buf->b_p_et_nobin = p_et_nobin;
10530 buf->b_p_ml = p_ml;
10531 buf->b_p_ml_nobin = p_ml_nobin;
10532 buf->b_p_inf = p_inf;
10533 buf->b_p_swf = p_swf;
10534#ifdef FEAT_INS_EXPAND
10535 buf->b_p_cpt = vim_strsave(p_cpt);
10536#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010537#ifdef FEAT_COMPL_FUNC
10538 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010539 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010540#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541 buf->b_p_sts = p_sts;
10542 buf->b_p_sts_nopaste = p_sts_nopaste;
10543#ifndef SHORT_FNAME
10544 buf->b_p_sn = p_sn;
10545#endif
10546#ifdef FEAT_COMMENTS
10547 buf->b_p_com = vim_strsave(p_com);
10548#endif
10549#ifdef FEAT_FOLDING
10550 buf->b_p_cms = vim_strsave(p_cms);
10551#endif
10552 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010553 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554 buf->b_p_nf = vim_strsave(p_nf);
10555 buf->b_p_mps = vim_strsave(p_mps);
10556#ifdef FEAT_SMARTINDENT
10557 buf->b_p_si = p_si;
10558#endif
10559 buf->b_p_ci = p_ci;
10560#ifdef FEAT_CINDENT
10561 buf->b_p_cin = p_cin;
10562 buf->b_p_cink = vim_strsave(p_cink);
10563 buf->b_p_cino = vim_strsave(p_cino);
10564#endif
10565#ifdef FEAT_AUTOCMD
10566 /* Don't copy 'filetype', it must be detected */
10567 buf->b_p_ft = empty_option;
10568#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569 buf->b_p_pi = p_pi;
10570#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10571 buf->b_p_cinw = vim_strsave(p_cinw);
10572#endif
10573#ifdef FEAT_LISP
10574 buf->b_p_lisp = p_lisp;
10575#endif
10576#ifdef FEAT_SYN_HL
10577 /* Don't copy 'syntax', it must be set */
10578 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010579 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010580#endif
10581#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010582 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010583 (void)compile_cap_prog(&buf->b_s);
10584 buf->b_s.b_p_spf = vim_strsave(p_spf);
10585 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586#endif
10587#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10588 buf->b_p_inde = vim_strsave(p_inde);
10589 buf->b_p_indk = vim_strsave(p_indk);
10590#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010591#if defined(FEAT_EVAL)
10592 buf->b_p_fex = vim_strsave(p_fex);
10593#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594#ifdef FEAT_CRYPT
10595 buf->b_p_key = vim_strsave(p_key);
10596#endif
10597#ifdef FEAT_SEARCHPATH
10598 buf->b_p_sua = vim_strsave(p_sua);
10599#endif
10600#ifdef FEAT_KEYMAP
10601 buf->b_p_keymap = vim_strsave(p_keymap);
10602 buf->b_kmap_state |= KEYMAP_INIT;
10603#endif
10604 /* This isn't really an option, but copying the langmap and IME
10605 * state from the current buffer is better than resetting it. */
10606 buf->b_p_iminsert = p_iminsert;
10607 buf->b_p_imsearch = p_imsearch;
10608
10609 /* options that are normally global but also have a local value
10610 * are not copied, start using the global value */
10611 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010612 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010613 buf->b_p_bkc = empty_option;
10614 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010615#ifdef FEAT_QUICKFIX
10616 buf->b_p_gp = empty_option;
10617 buf->b_p_mp = empty_option;
10618 buf->b_p_efm = empty_option;
10619#endif
10620 buf->b_p_ep = empty_option;
10621 buf->b_p_kp = empty_option;
10622 buf->b_p_path = empty_option;
10623 buf->b_p_tags = empty_option;
10624#ifdef FEAT_FIND_ID
10625 buf->b_p_def = empty_option;
10626 buf->b_p_inc = empty_option;
10627# ifdef FEAT_EVAL
10628 buf->b_p_inex = vim_strsave(p_inex);
10629# endif
10630#endif
10631#ifdef FEAT_INS_EXPAND
10632 buf->b_p_dict = empty_option;
10633 buf->b_p_tsr = empty_option;
10634#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010635#ifdef FEAT_TEXTOBJ
10636 buf->b_p_qe = vim_strsave(p_qe);
10637#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010638#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10639 buf->b_p_bexpr = empty_option;
10640#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010641#if defined(FEAT_CRYPT)
10642 buf->b_p_cm = empty_option;
10643#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010644#ifdef FEAT_PERSISTENT_UNDO
10645 buf->b_p_udf = p_udf;
10646#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010647#ifdef FEAT_LISP
10648 buf->b_p_lw = empty_option;
10649#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010650
10651 /*
10652 * Don't copy the options set by ex_help(), use the saved values,
10653 * when going from a help buffer to a non-help buffer.
10654 * Don't touch these at all when BCO_NOHELP is used and going from
10655 * or to a help buffer.
10656 */
10657 if (dont_do_help)
10658 buf->b_p_isk = save_p_isk;
10659 else
10660 {
10661 buf->b_p_isk = vim_strsave(p_isk);
10662 did_isk = TRUE;
10663 buf->b_p_ts = p_ts;
10664 buf->b_help = FALSE;
10665#ifdef FEAT_QUICKFIX
10666 if (buf->b_p_bt[0] == 'h')
10667 clear_string_option(&buf->b_p_bt);
10668#endif
10669 buf->b_p_ma = p_ma;
10670 }
10671 }
10672
10673 /*
10674 * When the options should be copied (ignoring BCO_ALWAYS), set the
10675 * flag that indicates that the options have been initialized.
10676 */
10677 if (should_copy)
10678 buf->b_p_initialized = TRUE;
10679 }
10680
10681 check_buf_options(buf); /* make sure we don't have NULLs */
10682 if (did_isk)
10683 (void)buf_init_chartab(buf, FALSE);
10684}
10685
10686/*
10687 * Reset the 'modifiable' option and its default value.
10688 */
10689 void
10690reset_modifiable()
10691{
10692 int opt_idx;
10693
10694 curbuf->b_p_ma = FALSE;
10695 p_ma = FALSE;
10696 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010697 if (opt_idx >= 0)
10698 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699}
10700
10701/*
10702 * Set the global value for 'iminsert' to the local value.
10703 */
10704 void
10705set_iminsert_global()
10706{
10707 p_iminsert = curbuf->b_p_iminsert;
10708}
10709
10710/*
10711 * Set the global value for 'imsearch' to the local value.
10712 */
10713 void
10714set_imsearch_global()
10715{
10716 p_imsearch = curbuf->b_p_imsearch;
10717}
10718
10719#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10720static int expand_option_idx = -1;
10721static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10722static int expand_option_flags = 0;
10723
10724 void
10725set_context_in_set_cmd(xp, arg, opt_flags)
10726 expand_T *xp;
10727 char_u *arg;
10728 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10729{
10730 int nextchar;
10731 long_u flags = 0; /* init for GCC */
10732 int opt_idx = 0; /* init for GCC */
10733 char_u *p;
10734 char_u *s;
10735 int is_term_option = FALSE;
10736 int key;
10737
10738 expand_option_flags = opt_flags;
10739
10740 xp->xp_context = EXPAND_SETTINGS;
10741 if (*arg == NUL)
10742 {
10743 xp->xp_pattern = arg;
10744 return;
10745 }
10746 p = arg + STRLEN(arg) - 1;
10747 if (*p == ' ' && *(p - 1) != '\\')
10748 {
10749 xp->xp_pattern = p + 1;
10750 return;
10751 }
10752 while (p > arg)
10753 {
10754 s = p;
10755 /* count number of backslashes before ' ' or ',' */
10756 if (*p == ' ' || *p == ',')
10757 {
10758 while (s > arg && *(s - 1) == '\\')
10759 --s;
10760 }
10761 /* break at a space with an even number of backslashes */
10762 if (*p == ' ' && ((p - s) & 1) == 0)
10763 {
10764 ++p;
10765 break;
10766 }
10767 --p;
10768 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010769 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770 {
10771 xp->xp_context = EXPAND_BOOL_SETTINGS;
10772 p += 2;
10773 }
10774 if (STRNCMP(p, "inv", 3) == 0)
10775 {
10776 xp->xp_context = EXPAND_BOOL_SETTINGS;
10777 p += 3;
10778 }
10779 xp->xp_pattern = arg = p;
10780 if (*arg == '<')
10781 {
10782 while (*p != '>')
10783 if (*p++ == NUL) /* expand terminal option name */
10784 return;
10785 key = get_special_key_code(arg + 1);
10786 if (key == 0) /* unknown name */
10787 {
10788 xp->xp_context = EXPAND_NOTHING;
10789 return;
10790 }
10791 nextchar = *++p;
10792 is_term_option = TRUE;
10793 expand_option_name[2] = KEY2TERMCAP0(key);
10794 expand_option_name[3] = KEY2TERMCAP1(key);
10795 }
10796 else
10797 {
10798 if (p[0] == 't' && p[1] == '_')
10799 {
10800 p += 2;
10801 if (*p != NUL)
10802 ++p;
10803 if (*p == NUL)
10804 return; /* expand option name */
10805 nextchar = *++p;
10806 is_term_option = TRUE;
10807 expand_option_name[2] = p[-2];
10808 expand_option_name[3] = p[-1];
10809 }
10810 else
10811 {
10812 /* Allow * wildcard */
10813 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10814 p++;
10815 if (*p == NUL)
10816 return;
10817 nextchar = *p;
10818 *p = NUL;
10819 opt_idx = findoption(arg);
10820 *p = nextchar;
10821 if (opt_idx == -1 || options[opt_idx].var == NULL)
10822 {
10823 xp->xp_context = EXPAND_NOTHING;
10824 return;
10825 }
10826 flags = options[opt_idx].flags;
10827 if (flags & P_BOOL)
10828 {
10829 xp->xp_context = EXPAND_NOTHING;
10830 return;
10831 }
10832 }
10833 }
10834 /* handle "-=" and "+=" */
10835 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
10836 {
10837 ++p;
10838 nextchar = '=';
10839 }
10840 if ((nextchar != '=' && nextchar != ':')
10841 || xp->xp_context == EXPAND_BOOL_SETTINGS)
10842 {
10843 xp->xp_context = EXPAND_UNSUCCESSFUL;
10844 return;
10845 }
10846 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
10847 {
10848 xp->xp_context = EXPAND_OLD_SETTING;
10849 if (is_term_option)
10850 expand_option_idx = -1;
10851 else
10852 expand_option_idx = opt_idx;
10853 xp->xp_pattern = p + 1;
10854 return;
10855 }
10856 xp->xp_context = EXPAND_NOTHING;
10857 if (is_term_option || (flags & P_NUM))
10858 return;
10859
10860 xp->xp_pattern = p + 1;
10861
10862 if (flags & P_EXPAND)
10863 {
10864 p = options[opt_idx].var;
10865 if (p == (char_u *)&p_bdir
10866 || p == (char_u *)&p_dir
10867 || p == (char_u *)&p_path
10868 || p == (char_u *)&p_rtp
10869#ifdef FEAT_SEARCHPATH
10870 || p == (char_u *)&p_cdpath
10871#endif
10872#ifdef FEAT_SESSION
10873 || p == (char_u *)&p_vdir
10874#endif
10875 )
10876 {
10877 xp->xp_context = EXPAND_DIRECTORIES;
10878 if (p == (char_u *)&p_path
10879#ifdef FEAT_SEARCHPATH
10880 || p == (char_u *)&p_cdpath
10881#endif
10882 )
10883 xp->xp_backslash = XP_BS_THREE;
10884 else
10885 xp->xp_backslash = XP_BS_ONE;
10886 }
10887 else
10888 {
10889 xp->xp_context = EXPAND_FILES;
10890 /* for 'tags' need three backslashes for a space */
10891 if (p == (char_u *)&p_tags)
10892 xp->xp_backslash = XP_BS_THREE;
10893 else
10894 xp->xp_backslash = XP_BS_ONE;
10895 }
10896 }
10897
10898 /* For an option that is a list of file names, find the start of the
10899 * last file name. */
10900 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
10901 {
10902 /* count number of backslashes before ' ' or ',' */
10903 if (*p == ' ' || *p == ',')
10904 {
10905 s = p;
10906 while (s > xp->xp_pattern && *(s - 1) == '\\')
10907 --s;
10908 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
10909 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
10910 {
10911 xp->xp_pattern = p + 1;
10912 break;
10913 }
10914 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010915
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010916#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000010917 /* for 'spellsuggest' start at "file:" */
10918 if (options[opt_idx].var == (char_u *)&p_sps
10919 && STRNCMP(p, "file:", 5) == 0)
10920 {
10921 xp->xp_pattern = p + 5;
10922 break;
10923 }
10924#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010925 }
10926
10927 return;
10928}
10929
10930 int
10931ExpandSettings(xp, regmatch, num_file, file)
10932 expand_T *xp;
10933 regmatch_T *regmatch;
10934 int *num_file;
10935 char_u ***file;
10936{
10937 int num_normal = 0; /* Nr of matching non-term-code settings */
10938 int num_term = 0; /* Nr of matching terminal code settings */
10939 int opt_idx;
10940 int match;
10941 int count = 0;
10942 char_u *str;
10943 int loop;
10944 int is_term_opt;
10945 char_u name_buf[MAX_KEY_NAME_LEN];
10946 static char *(names[]) = {"all", "termcap"};
10947 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
10948
10949 /* do this loop twice:
10950 * loop == 0: count the number of matching options
10951 * loop == 1: copy the matching options into allocated memory
10952 */
10953 for (loop = 0; loop <= 1; ++loop)
10954 {
10955 regmatch->rm_ic = ic;
10956 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
10957 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000010958 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
10959 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010960 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
10961 {
10962 if (loop == 0)
10963 num_normal++;
10964 else
10965 (*file)[count++] = vim_strsave((char_u *)names[match]);
10966 }
10967 }
10968 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
10969 opt_idx++)
10970 {
10971 if (options[opt_idx].var == NULL)
10972 continue;
10973 if (xp->xp_context == EXPAND_BOOL_SETTINGS
10974 && !(options[opt_idx].flags & P_BOOL))
10975 continue;
10976 is_term_opt = istermoption(&options[opt_idx]);
10977 if (is_term_opt && num_normal > 0)
10978 continue;
10979 match = FALSE;
10980 if (vim_regexec(regmatch, str, (colnr_T)0)
10981 || (options[opt_idx].shortname != NULL
10982 && vim_regexec(regmatch,
10983 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
10984 match = TRUE;
10985 else if (is_term_opt)
10986 {
10987 name_buf[0] = '<';
10988 name_buf[1] = 't';
10989 name_buf[2] = '_';
10990 name_buf[3] = str[2];
10991 name_buf[4] = str[3];
10992 name_buf[5] = '>';
10993 name_buf[6] = NUL;
10994 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
10995 {
10996 match = TRUE;
10997 str = name_buf;
10998 }
10999 }
11000 if (match)
11001 {
11002 if (loop == 0)
11003 {
11004 if (is_term_opt)
11005 num_term++;
11006 else
11007 num_normal++;
11008 }
11009 else
11010 (*file)[count++] = vim_strsave(str);
11011 }
11012 }
11013 /*
11014 * Check terminal key codes, these are not in the option table
11015 */
11016 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11017 {
11018 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11019 {
11020 if (!isprint(str[0]) || !isprint(str[1]))
11021 continue;
11022
11023 name_buf[0] = 't';
11024 name_buf[1] = '_';
11025 name_buf[2] = str[0];
11026 name_buf[3] = str[1];
11027 name_buf[4] = NUL;
11028
11029 match = FALSE;
11030 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11031 match = TRUE;
11032 else
11033 {
11034 name_buf[0] = '<';
11035 name_buf[1] = 't';
11036 name_buf[2] = '_';
11037 name_buf[3] = str[0];
11038 name_buf[4] = str[1];
11039 name_buf[5] = '>';
11040 name_buf[6] = NUL;
11041
11042 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11043 match = TRUE;
11044 }
11045 if (match)
11046 {
11047 if (loop == 0)
11048 num_term++;
11049 else
11050 (*file)[count++] = vim_strsave(name_buf);
11051 }
11052 }
11053
11054 /*
11055 * Check special key names.
11056 */
11057 regmatch->rm_ic = TRUE; /* ignore case here */
11058 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11059 {
11060 name_buf[0] = '<';
11061 STRCPY(name_buf + 1, str);
11062 STRCAT(name_buf, ">");
11063
11064 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11065 {
11066 if (loop == 0)
11067 num_term++;
11068 else
11069 (*file)[count++] = vim_strsave(name_buf);
11070 }
11071 }
11072 }
11073 if (loop == 0)
11074 {
11075 if (num_normal > 0)
11076 *num_file = num_normal;
11077 else if (num_term > 0)
11078 *num_file = num_term;
11079 else
11080 return OK;
11081 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11082 if (*file == NULL)
11083 {
11084 *file = (char_u **)"";
11085 return FAIL;
11086 }
11087 }
11088 }
11089 return OK;
11090}
11091
11092 int
11093ExpandOldSetting(num_file, file)
11094 int *num_file;
11095 char_u ***file;
11096{
11097 char_u *var = NULL; /* init for GCC */
11098 char_u *buf;
11099
11100 *num_file = 0;
11101 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11102 if (*file == NULL)
11103 return FAIL;
11104
11105 /*
11106 * For a terminal key code expand_option_idx is < 0.
11107 */
11108 if (expand_option_idx < 0)
11109 {
11110 var = find_termcode(expand_option_name + 2);
11111 if (var == NULL)
11112 expand_option_idx = findoption(expand_option_name);
11113 }
11114
11115 if (expand_option_idx >= 0)
11116 {
11117 /* put string of option value in NameBuff */
11118 option_value2string(&options[expand_option_idx], expand_option_flags);
11119 var = NameBuff;
11120 }
11121 else if (var == NULL)
11122 var = (char_u *)"";
11123
11124 /* A backslash is required before some characters. This is the reverse of
11125 * what happens in do_set(). */
11126 buf = vim_strsave_escaped(var, escape_chars);
11127
11128 if (buf == NULL)
11129 {
11130 vim_free(*file);
11131 *file = NULL;
11132 return FAIL;
11133 }
11134
11135#ifdef BACKSLASH_IN_FILENAME
11136 /* For MS-Windows et al. we don't double backslashes at the start and
11137 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011138 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011139 if (var[0] == '\\' && var[1] == '\\'
11140 && expand_option_idx >= 0
11141 && (options[expand_option_idx].flags & P_EXPAND)
11142 && vim_isfilec(var[2])
11143 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011144 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145#endif
11146
11147 *file[0] = buf;
11148 *num_file = 1;
11149 return OK;
11150}
11151#endif
11152
11153/*
11154 * Get the value for the numeric or string option *opp in a nice format into
11155 * NameBuff[]. Must not be called with a hidden option!
11156 */
11157 static void
11158option_value2string(opp, opt_flags)
11159 struct vimoption *opp;
11160 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11161{
11162 char_u *varp;
11163
11164 varp = get_varp_scope(opp, opt_flags);
11165
11166 if (opp->flags & P_NUM)
11167 {
11168 long wc = 0;
11169
11170 if (wc_use_keyname(varp, &wc))
11171 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11172 else if (wc != 0)
11173 STRCPY(NameBuff, transchar((int)wc));
11174 else
11175 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11176 }
11177 else /* P_STRING */
11178 {
11179 varp = *(char_u **)(varp);
11180 if (varp == NULL) /* just in case */
11181 NameBuff[0] = NUL;
11182#ifdef FEAT_CRYPT
11183 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011184 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185 STRCPY(NameBuff, "*****");
11186#endif
11187 else if (opp->flags & P_EXPAND)
11188 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11189 /* Translate 'pastetoggle' into special key names */
11190 else if ((char_u **)opp->var == &p_pt)
11191 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11192 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011193 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011194 }
11195}
11196
11197/*
11198 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11199 * printed as a keyname.
11200 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11201 */
11202 static int
11203wc_use_keyname(varp, wcp)
11204 char_u *varp;
11205 long *wcp;
11206{
11207 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11208 {
11209 *wcp = *(long *)varp;
11210 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11211 return TRUE;
11212 }
11213 return FALSE;
11214}
11215
Bram Moolenaar01615492015-02-03 13:00:38 +010011216#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011218 * Any character has an equivalent 'langmap' character. This is used for
11219 * keyboards that have a special language mode that sends characters above
11220 * 128 (although other characters can be translated too). The "to" field is a
11221 * Vim command character. This avoids having to switch the keyboard back to
11222 * ASCII mode when leaving Insert mode.
11223 *
11224 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11225 * commands.
11226 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11227 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11228 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011229 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011230# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011231/*
11232 * With multi-byte support use growarray for 'langmap' chars >= 256
11233 */
11234typedef struct
11235{
11236 int from;
11237 int to;
11238} langmap_entry_T;
11239
11240static garray_T langmap_mapga;
11241static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011242
11243/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011244 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11245 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011246 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011247 static void
11248langmap_set_entry(from, to)
11249 int from;
11250 int to;
11251{
11252 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011253 int a = 0;
11254 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011255
11256 /* Do a binary search for an existing entry. */
11257 while (a != b)
11258 {
11259 int i = (a + b) / 2;
11260 int d = entries[i].from - from;
11261
11262 if (d == 0)
11263 {
11264 entries[i].to = to;
11265 return;
11266 }
11267 if (d < 0)
11268 a = i + 1;
11269 else
11270 b = i;
11271 }
11272
11273 if (ga_grow(&langmap_mapga, 1) != OK)
11274 return; /* out of memory */
11275
11276 /* insert new entry at position "a" */
11277 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11278 mch_memmove(entries + 1, entries,
11279 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11280 ++langmap_mapga.ga_len;
11281 entries[0].from = from;
11282 entries[0].to = to;
11283}
11284
11285/*
11286 * Apply 'langmap' to multi-byte character "c" and return the result.
11287 */
11288 int
11289langmap_adjust_mb(c)
11290 int c;
11291{
11292 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11293 int a = 0;
11294 int b = langmap_mapga.ga_len;
11295
11296 while (a != b)
11297 {
11298 int i = (a + b) / 2;
11299 int d = entries[i].from - c;
11300
11301 if (d == 0)
11302 return entries[i].to; /* found matching entry */
11303 if (d < 0)
11304 a = i + 1;
11305 else
11306 b = i;
11307 }
11308 return c; /* no entry found, return "c" unmodified */
11309}
11310# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011311
11312 static void
11313langmap_init()
11314{
11315 int i;
11316
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011317 for (i = 0; i < 256; i++)
11318 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11319# ifdef FEAT_MBYTE
11320 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11321# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011322}
11323
11324/*
11325 * Called when langmap option is set; the language map can be
11326 * changed at any time!
11327 */
11328 static void
11329langmap_set()
11330{
11331 char_u *p;
11332 char_u *p2;
11333 int from, to;
11334
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011335#ifdef FEAT_MBYTE
11336 ga_clear(&langmap_mapga); /* clear the previous map first */
11337#endif
11338 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011339
11340 for (p = p_langmap; p[0] != NUL; )
11341 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011342 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11343 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011344 {
11345 if (p2[0] == '\\' && p2[1] != NUL)
11346 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011347 }
11348 if (p2[0] == ';')
11349 ++p2; /* abcd;ABCD form, p2 points to A */
11350 else
11351 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11352 while (p[0])
11353 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011354 if (p[0] == ',')
11355 {
11356 ++p;
11357 break;
11358 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011359 if (p[0] == '\\' && p[1] != NUL)
11360 ++p;
11361#ifdef FEAT_MBYTE
11362 from = (*mb_ptr2char)(p);
11363#else
11364 from = p[0];
11365#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011366 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011367 if (p2 == NULL)
11368 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011369 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011370 if (p[0] != ',')
11371 {
11372 if (p[0] == '\\')
11373 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011374#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011375 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011377 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011378#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011379 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011380 }
11381 else
11382 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011383 if (p2[0] != ',')
11384 {
11385 if (p2[0] == '\\')
11386 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011388 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011389#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011390 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011391#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011392 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011393 }
11394 if (to == NUL)
11395 {
11396 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11397 transchar(from));
11398 return;
11399 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011400
11401#ifdef FEAT_MBYTE
11402 if (from >= 256)
11403 langmap_set_entry(from, to);
11404 else
11405#endif
11406 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011407
11408 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011409 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011410 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011411 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011412 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011413 if (*p == ';')
11414 {
11415 p = p2;
11416 if (p[0] != NUL)
11417 {
11418 if (p[0] != ',')
11419 {
11420 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11421 return;
11422 }
11423 ++p;
11424 }
11425 break;
11426 }
11427 }
11428 }
11429 }
11430}
11431#endif
11432
11433/*
11434 * Return TRUE if format option 'x' is in effect.
11435 * Take care of no formatting when 'paste' is set.
11436 */
11437 int
11438has_format_option(x)
11439 int x;
11440{
11441 if (p_paste)
11442 return FALSE;
11443 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11444}
11445
11446/*
11447 * Return TRUE if "x" is present in 'shortmess' option, or
11448 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11449 */
11450 int
11451shortmess(x)
11452 int x;
11453{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011454 return p_shm != NULL &&
11455 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011456 || (vim_strchr(p_shm, 'a') != NULL
11457 && vim_strchr((char_u *)SHM_A, x) != NULL));
11458}
11459
11460/*
11461 * paste_option_changed() - Called after p_paste was set or reset.
11462 */
11463 static void
11464paste_option_changed()
11465{
11466 static int old_p_paste = FALSE;
11467 static int save_sm = 0;
11468#ifdef FEAT_CMDL_INFO
11469 static int save_ru = 0;
11470#endif
11471#ifdef FEAT_RIGHTLEFT
11472 static int save_ri = 0;
11473 static int save_hkmap = 0;
11474#endif
11475 buf_T *buf;
11476
11477 if (p_paste)
11478 {
11479 /*
11480 * Paste switched from off to on.
11481 * Save the current values, so they can be restored later.
11482 */
11483 if (!old_p_paste)
11484 {
11485 /* save options for each buffer */
11486 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11487 {
11488 buf->b_p_tw_nopaste = buf->b_p_tw;
11489 buf->b_p_wm_nopaste = buf->b_p_wm;
11490 buf->b_p_sts_nopaste = buf->b_p_sts;
11491 buf->b_p_ai_nopaste = buf->b_p_ai;
11492 }
11493
11494 /* save global options */
11495 save_sm = p_sm;
11496#ifdef FEAT_CMDL_INFO
11497 save_ru = p_ru;
11498#endif
11499#ifdef FEAT_RIGHTLEFT
11500 save_ri = p_ri;
11501 save_hkmap = p_hkmap;
11502#endif
11503 /* save global values for local buffer options */
11504 p_tw_nopaste = p_tw;
11505 p_wm_nopaste = p_wm;
11506 p_sts_nopaste = p_sts;
11507 p_ai_nopaste = p_ai;
11508 }
11509
11510 /*
11511 * Always set the option values, also when 'paste' is set when it is
11512 * already on.
11513 */
11514 /* set options for each buffer */
11515 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11516 {
11517 buf->b_p_tw = 0; /* textwidth is 0 */
11518 buf->b_p_wm = 0; /* wrapmargin is 0 */
11519 buf->b_p_sts = 0; /* softtabstop is 0 */
11520 buf->b_p_ai = 0; /* no auto-indent */
11521 }
11522
11523 /* set global options */
11524 p_sm = 0; /* no showmatch */
11525#ifdef FEAT_CMDL_INFO
11526# ifdef FEAT_WINDOWS
11527 if (p_ru)
11528 status_redraw_all(); /* redraw to remove the ruler */
11529# endif
11530 p_ru = 0; /* no ruler */
11531#endif
11532#ifdef FEAT_RIGHTLEFT
11533 p_ri = 0; /* no reverse insert */
11534 p_hkmap = 0; /* no Hebrew keyboard */
11535#endif
11536 /* set global values for local buffer options */
11537 p_tw = 0;
11538 p_wm = 0;
11539 p_sts = 0;
11540 p_ai = 0;
11541 }
11542
11543 /*
11544 * Paste switched from on to off: Restore saved values.
11545 */
11546 else if (old_p_paste)
11547 {
11548 /* restore options for each buffer */
11549 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11550 {
11551 buf->b_p_tw = buf->b_p_tw_nopaste;
11552 buf->b_p_wm = buf->b_p_wm_nopaste;
11553 buf->b_p_sts = buf->b_p_sts_nopaste;
11554 buf->b_p_ai = buf->b_p_ai_nopaste;
11555 }
11556
11557 /* restore global options */
11558 p_sm = save_sm;
11559#ifdef FEAT_CMDL_INFO
11560# ifdef FEAT_WINDOWS
11561 if (p_ru != save_ru)
11562 status_redraw_all(); /* redraw to draw the ruler */
11563# endif
11564 p_ru = save_ru;
11565#endif
11566#ifdef FEAT_RIGHTLEFT
11567 p_ri = save_ri;
11568 p_hkmap = save_hkmap;
11569#endif
11570 /* set global values for local buffer options */
11571 p_tw = p_tw_nopaste;
11572 p_wm = p_wm_nopaste;
11573 p_sts = p_sts_nopaste;
11574 p_ai = p_ai_nopaste;
11575 }
11576
11577 old_p_paste = p_paste;
11578}
11579
11580/*
11581 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11582 *
11583 * Reset 'compatible' and set the values for options that didn't get set yet
11584 * to the Vim defaults.
11585 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011586 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011587 */
11588 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011589vimrc_found(fname, envname)
11590 char_u *fname;
11591 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011592{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011593 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011594 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011595 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011596
11597 if (!option_was_set((char_u *)"cp"))
11598 {
11599 p_cp = FALSE;
11600 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11601 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11602 set_option_default(opt_idx, OPT_FREE, FALSE);
11603 didset_options();
11604 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011605
11606 if (fname != NULL)
11607 {
11608 p = vim_getenv(envname, &dofree);
11609 if (p == NULL)
11610 {
11611 /* Set $MYVIMRC to the first vimrc file found. */
11612 p = FullName_save(fname, FALSE);
11613 if (p != NULL)
11614 {
11615 vim_setenv(envname, p);
11616 vim_free(p);
11617 }
11618 }
11619 else if (dofree)
11620 vim_free(p);
11621 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011622}
11623
11624/*
11625 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11626 */
11627 void
11628change_compatible(on)
11629 int on;
11630{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011631 int opt_idx;
11632
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633 if (p_cp != on)
11634 {
11635 p_cp = on;
11636 compatible_set();
11637 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011638 opt_idx = findoption((char_u *)"cp");
11639 if (opt_idx >= 0)
11640 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011641}
11642
11643/*
11644 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011645 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011646 */
11647 int
11648option_was_set(name)
11649 char_u *name;
11650{
11651 int idx;
11652
11653 idx = findoption(name);
11654 if (idx < 0) /* unknown option */
11655 return FALSE;
11656 if (options[idx].flags & P_WAS_SET)
11657 return TRUE;
11658 return FALSE;
11659}
11660
11661/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011662 * Reset the flag indicating option "name" was set.
11663 */
11664 void
11665reset_option_was_set(name)
11666 char_u *name;
11667{
11668 int idx = findoption(name);
11669
11670 if (idx >= 0)
11671 options[idx].flags &= ~P_WAS_SET;
11672}
11673
11674/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011675 * compatible_set() - Called when 'compatible' has been set or unset.
11676 *
11677 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11678 * flag) to a Vi compatible value.
11679 * When 'compatible' is unset: Set all options that have a different default
11680 * for Vim (without the P_VI_DEF flag) to that default.
11681 */
11682 static void
11683compatible_set()
11684{
11685 int opt_idx;
11686
11687 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11688 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11689 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11690 set_option_default(opt_idx, OPT_FREE, p_cp);
11691 didset_options();
11692}
11693
11694#ifdef FEAT_LINEBREAK
11695
11696# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11697 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011698 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011699# endif
11700
11701/*
11702 * fill_breakat_flags() -- called when 'breakat' changes value.
11703 */
11704 static void
11705fill_breakat_flags()
11706{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011707 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011708 int i;
11709
11710 for (i = 0; i < 256; i++)
11711 breakat_flags[i] = FALSE;
11712
11713 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011714 for (p = p_breakat; *p; p++)
11715 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011716}
11717
11718# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011719 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011720# endif
11721
11722#endif
11723
11724/*
11725 * Check an option that can be a range of string values.
11726 *
11727 * Return OK for correct value, FAIL otherwise.
11728 * Empty is always OK.
11729 */
11730 static int
11731check_opt_strings(val, values, list)
11732 char_u *val;
11733 char **values;
11734 int list; /* when TRUE: accept a list of values */
11735{
11736 return opt_strings_flags(val, values, NULL, list);
11737}
11738
11739/*
11740 * Handle an option that can be a range of string values.
11741 * Set a flag in "*flagp" for each string present.
11742 *
11743 * Return OK for correct value, FAIL otherwise.
11744 * Empty is always OK.
11745 */
11746 static int
11747opt_strings_flags(val, values, flagp, list)
11748 char_u *val; /* new value */
11749 char **values; /* array of valid string values */
11750 unsigned *flagp;
11751 int list; /* when TRUE: accept a list of values */
11752{
11753 int i;
11754 int len;
11755 unsigned new_flags = 0;
11756
11757 while (*val)
11758 {
11759 for (i = 0; ; ++i)
11760 {
11761 if (values[i] == NULL) /* val not found in values[] */
11762 return FAIL;
11763
11764 len = (int)STRLEN(values[i]);
11765 if (STRNCMP(values[i], val, len) == 0
11766 && ((list && val[len] == ',') || val[len] == NUL))
11767 {
11768 val += len + (val[len] == ',');
11769 new_flags |= (1 << i);
11770 break; /* check next item in val list */
11771 }
11772 }
11773 }
11774 if (flagp != NULL)
11775 *flagp = new_flags;
11776
11777 return OK;
11778}
11779
11780/*
11781 * Read the 'wildmode' option, fill wim_flags[].
11782 */
11783 static int
11784check_opt_wim()
11785{
11786 char_u new_wim_flags[4];
11787 char_u *p;
11788 int i;
11789 int idx = 0;
11790
11791 for (i = 0; i < 4; ++i)
11792 new_wim_flags[i] = 0;
11793
11794 for (p = p_wim; *p; ++p)
11795 {
11796 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11797 ;
11798 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11799 return FAIL;
11800 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11801 new_wim_flags[idx] |= WIM_LONGEST;
11802 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11803 new_wim_flags[idx] |= WIM_FULL;
11804 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11805 new_wim_flags[idx] |= WIM_LIST;
11806 else
11807 return FAIL;
11808 p += i;
11809 if (*p == NUL)
11810 break;
11811 if (*p == ',')
11812 {
11813 if (idx == 3)
11814 return FAIL;
11815 ++idx;
11816 }
11817 }
11818
11819 /* fill remaining entries with last flag */
11820 while (idx < 3)
11821 {
11822 new_wim_flags[idx + 1] = new_wim_flags[idx];
11823 ++idx;
11824 }
11825
11826 /* only when there are no errors, wim_flags[] is changed */
11827 for (i = 0; i < 4; ++i)
11828 wim_flags[i] = new_wim_flags[i];
11829 return OK;
11830}
11831
11832/*
11833 * Check if backspacing over something is allowed.
11834 */
11835 int
11836can_bs(what)
11837 int what; /* BS_INDENT, BS_EOL or BS_START */
11838{
11839 switch (*p_bs)
11840 {
11841 case '2': return TRUE;
11842 case '1': return (what != BS_START);
11843 case '0': return FALSE;
11844 }
11845 return vim_strchr(p_bs, what) != NULL;
11846}
11847
11848/*
11849 * Save the current values of 'fileformat' and 'fileencoding', so that we know
11850 * the file must be considered changed when the value is different.
11851 */
11852 void
11853save_file_ff(buf)
11854 buf_T *buf;
11855{
11856 buf->b_start_ffc = *buf->b_p_ff;
11857 buf->b_start_eol = buf->b_p_eol;
11858#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011859 buf->b_start_bomb = buf->b_p_bomb;
11860
Bram Moolenaar071d4272004-06-13 20:20:40 +000011861 /* Only use free/alloc when necessary, they take time. */
11862 if (buf->b_start_fenc == NULL
11863 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
11864 {
11865 vim_free(buf->b_start_fenc);
11866 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
11867 }
11868#endif
11869}
11870
11871/*
11872 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
11873 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011874 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
11875 * changed and 'binary' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011876 * When "ignore_empty" is true don't consider a new, empty buffer to be
11877 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011878 */
11879 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011880file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011882 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000011884 /* In a buffer that was never loaded the options are not valid. */
11885 if (buf->b_flags & BF_NEVERLOADED)
11886 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010011887 if (ignore_empty
11888 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889 && buf->b_ml.ml_line_count == 1
11890 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
11891 return FALSE;
11892 if (buf->b_start_ffc != *buf->b_p_ff)
11893 return TRUE;
11894 if (buf->b_p_bin && buf->b_start_eol != buf->b_p_eol)
11895 return TRUE;
11896#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000011897 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
11898 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011899 if (buf->b_start_fenc == NULL)
11900 return (*buf->b_p_fenc != NUL);
11901 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
11902#else
11903 return FALSE;
11904#endif
11905}
11906
11907/*
11908 * return OK if "p" is a valid fileformat name, FAIL otherwise.
11909 */
11910 int
11911check_ff_value(p)
11912 char_u *p;
11913{
11914 return check_opt_strings(p, p_ff_values, FALSE);
11915}
Bram Moolenaar14f24742012-08-08 18:01:05 +020011916
11917/*
11918 * Return the effective shiftwidth value for current buffer, using the
11919 * 'tabstop' value when 'shiftwidth' is zero.
11920 */
11921 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011922get_sw_value(buf)
11923 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011924{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011925 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020011926}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011927
11928/*
11929 * Return the effective softtabstop value for the current buffer, using the
11930 * 'tabstop' value when 'softtabstop' is negative.
11931 */
11932 long
11933get_sts_value()
11934{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010011935 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020011936}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010011937
11938/*
11939 * Check matchpairs option for "*initc".
11940 * If there is a match set "*initc" to the matching character and "*findc" to
11941 * the opposite character. Set "*backwards" to the direction.
11942 * When "switchit" is TRUE swap the direction.
11943 */
11944 void
11945find_mps_values(initc, findc, backwards, switchit)
11946 int *initc;
11947 int *findc;
11948 int *backwards;
11949 int switchit;
11950{
11951 char_u *ptr;
11952
11953 ptr = curbuf->b_p_mps;
11954 while (*ptr != NUL)
11955 {
11956#ifdef FEAT_MBYTE
11957 if (has_mbyte)
11958 {
11959 char_u *prev;
11960
11961 if (mb_ptr2char(ptr) == *initc)
11962 {
11963 if (switchit)
11964 {
11965 *findc = *initc;
11966 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11967 *backwards = TRUE;
11968 }
11969 else
11970 {
11971 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
11972 *backwards = FALSE;
11973 }
11974 return;
11975 }
11976 prev = ptr;
11977 ptr += mb_ptr2len(ptr) + 1;
11978 if (mb_ptr2char(ptr) == *initc)
11979 {
11980 if (switchit)
11981 {
11982 *findc = *initc;
11983 *initc = mb_ptr2char(prev);
11984 *backwards = FALSE;
11985 }
11986 else
11987 {
11988 *findc = mb_ptr2char(prev);
11989 *backwards = TRUE;
11990 }
11991 return;
11992 }
11993 ptr += mb_ptr2len(ptr);
11994 }
11995 else
11996#endif
11997 {
11998 if (*ptr == *initc)
11999 {
12000 if (switchit)
12001 {
12002 *backwards = TRUE;
12003 *findc = *initc;
12004 *initc = ptr[2];
12005 }
12006 else
12007 {
12008 *backwards = FALSE;
12009 *findc = ptr[2];
12010 }
12011 return;
12012 }
12013 ptr += 2;
12014 if (*ptr == *initc)
12015 {
12016 if (switchit)
12017 {
12018 *backwards = FALSE;
12019 *findc = *initc;
12020 *initc = ptr[-2];
12021 }
12022 else
12023 {
12024 *backwards = TRUE;
12025 *findc = ptr[-2];
12026 }
12027 return;
12028 }
12029 ++ptr;
12030 }
12031 if (*ptr == ',')
12032 ++ptr;
12033 }
12034}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012035
12036#if defined(FEAT_LINEBREAK) || defined(PROTO)
12037/*
12038 * This is called when 'breakindentopt' is changed and when a window is
12039 * initialized.
12040 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012041 static int
12042briopt_check(wp)
12043 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012044{
12045 char_u *p;
12046 int bri_shift = 0;
12047 long bri_min = 20;
12048 int bri_sbr = FALSE;
12049
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012050 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012051 while (*p != NUL)
12052 {
12053 if (STRNCMP(p, "shift:", 6) == 0
12054 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12055 {
12056 p += 6;
12057 bri_shift = getdigits(&p);
12058 }
12059 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12060 {
12061 p += 4;
12062 bri_min = getdigits(&p);
12063 }
12064 else if (STRNCMP(p, "sbr", 3) == 0)
12065 {
12066 p += 3;
12067 bri_sbr = TRUE;
12068 }
12069 if (*p != ',' && *p != NUL)
12070 return FAIL;
12071 if (*p == ',')
12072 ++p;
12073 }
12074
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012075 wp->w_p_brishift = bri_shift;
12076 wp->w_p_brimin = bri_min;
12077 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012078
12079 return OK;
12080}
12081#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012082
12083/*
12084 * Get the local or global value of 'backupcopy'.
12085 */
12086 unsigned int
12087get_bkc_value(buf)
12088 buf_T *buf;
12089{
12090 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12091}