blob: dae2054f57a70f0eca9740a715b22fe696d075ee [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)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000110#ifdef FEAT_EVAL
111# define PV_FEX OPT_BUF(BV_FEX)
112#endif
113#define PV_FF OPT_BUF(BV_FF)
114#define PV_FLP OPT_BUF(BV_FLP)
115#define PV_FO OPT_BUF(BV_FO)
116#ifdef FEAT_AUTOCMD
117# define PV_FT OPT_BUF(BV_FT)
118#endif
119#define PV_IMI OPT_BUF(BV_IMI)
120#define PV_IMS OPT_BUF(BV_IMS)
121#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
122# define PV_INDE OPT_BUF(BV_INDE)
123# define PV_INDK OPT_BUF(BV_INDK)
124#endif
125#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
126# define PV_INEX OPT_BUF(BV_INEX)
127#endif
128#define PV_INF OPT_BUF(BV_INF)
129#define PV_ISK OPT_BUF(BV_ISK)
130#ifdef FEAT_CRYPT
131# define PV_KEY OPT_BUF(BV_KEY)
132#endif
133#ifdef FEAT_KEYMAP
134# define PV_KMAP OPT_BUF(BV_KMAP)
135#endif
136#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
137#ifdef FEAT_LISP
138# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100139# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000140#endif
141#define PV_MA OPT_BUF(BV_MA)
142#define PV_ML OPT_BUF(BV_ML)
143#define PV_MOD OPT_BUF(BV_MOD)
144#define PV_MPS OPT_BUF(BV_MPS)
145#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
158#ifndef SHORT_FNAME
159# define PV_SN OPT_BUF(BV_SN)
160#endif
161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100177#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_TS OPT_BUF(BV_TS)
179#define PV_TW OPT_BUF(BV_TW)
180#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200181#ifdef FEAT_PERSISTENT_UNDO
182# define PV_UDF OPT_BUF(BV_UDF)
183#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185
186/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000187 * Definition of the PV_ values for window-local options.
188 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190#define PV_LIST OPT_WIN(WV_LIST)
191#ifdef FEAT_ARABIC
192# define PV_ARAB OPT_WIN(WV_ARAB)
193#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200194#ifdef FEAT_LINEBREAK
195# define PV_BRI OPT_WIN(WV_BRI)
196# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
197#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000198#ifdef FEAT_DIFF
199# define PV_DIFF OPT_WIN(WV_DIFF)
200#endif
201#ifdef FEAT_FOLDING
202# define PV_FDC OPT_WIN(WV_FDC)
203# define PV_FEN OPT_WIN(WV_FEN)
204# define PV_FDI OPT_WIN(WV_FDI)
205# define PV_FDL OPT_WIN(WV_FDL)
206# define PV_FDM OPT_WIN(WV_FDM)
207# define PV_FML OPT_WIN(WV_FML)
208# define PV_FDN OPT_WIN(WV_FDN)
209# ifdef FEAT_EVAL
210# define PV_FDE OPT_WIN(WV_FDE)
211# define PV_FDT OPT_WIN(WV_FDT)
212# endif
213# define PV_FMR OPT_WIN(WV_FMR)
214#endif
215#ifdef FEAT_LINEBREAK
216# define PV_LBR OPT_WIN(WV_LBR)
217#endif
218#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200219#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000220#ifdef FEAT_LINEBREAK
221# define PV_NUW OPT_WIN(WV_NUW)
222#endif
223#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
224# define PV_PVW OPT_WIN(WV_PVW)
225#endif
226#ifdef FEAT_RIGHTLEFT
227# define PV_RL OPT_WIN(WV_RL)
228# define PV_RLC OPT_WIN(WV_RLC)
229#endif
230#ifdef FEAT_SCROLLBIND
231# define PV_SCBIND OPT_WIN(WV_SCBIND)
232#endif
233#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000234#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000235# define PV_SPELL OPT_WIN(WV_SPELL)
236#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000237#ifdef FEAT_SYN_HL
238# define PV_CUC OPT_WIN(WV_CUC)
239# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200240# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000241#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000242#ifdef FEAT_STL_OPT
243# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
244#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100245#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#ifdef FEAT_WINDOWS
247# define PV_WFH OPT_WIN(WV_WFH)
248#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249#ifdef FEAT_VERTSPLIT
250# define PV_WFW OPT_WIN(WV_WFW)
251#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000252#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CURSORBIND
254# define PV_CRBIND OPT_WIN(WV_CRBIND)
255#endif
256#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200257# define PV_COCU OPT_WIN(WV_COCU)
258# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000260
261/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262typedef enum
263{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000264 PV_NONE = 0,
265 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266} idopt_T;
267
268/*
269 * Options local to a window have a value local to a buffer and global to all
270 * buffers. Indicate this by setting "var" to VAR_WIN.
271 */
272#define VAR_WIN ((char_u *)-1)
273
274/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000275 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 * Only to be used in option.c!
277 */
278static int p_ai;
279static int p_bin;
280#ifdef FEAT_MBYTE
281static int p_bomb;
282#endif
283#if defined(FEAT_QUICKFIX)
284static char_u *p_bh;
285static char_u *p_bt;
286#endif
287static int p_bl;
288static int p_ci;
289#ifdef FEAT_CINDENT
290static int p_cin;
291static char_u *p_cink;
292static char_u *p_cino;
293#endif
294#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
295static char_u *p_cinw;
296#endif
297#ifdef FEAT_COMMENTS
298static char_u *p_com;
299#endif
300#ifdef FEAT_FOLDING
301static char_u *p_cms;
302#endif
303#ifdef FEAT_INS_EXPAND
304static char_u *p_cpt;
305#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#ifdef FEAT_COMPL_FUNC
307static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000308static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200311static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312static int p_et;
313#ifdef FEAT_MBYTE
314static char_u *p_fenc;
315#endif
316static char_u *p_ff;
317static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000318static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319#ifdef FEAT_AUTOCMD
320static char_u *p_ft;
321#endif
322static long p_iminsert;
323static long p_imsearch;
324#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
325static char_u *p_inex;
326#endif
327#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
328static char_u *p_inde;
329static char_u *p_indk;
330#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000331#if defined(FEAT_EVAL)
332static char_u *p_fex;
333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334static int p_inf;
335static char_u *p_isk;
336#ifdef FEAT_CRYPT
337static char_u *p_key;
338#endif
339#ifdef FEAT_LISP
340static int p_lisp;
341#endif
342static int p_ml;
343static int p_ma;
344static int p_mod;
345static char_u *p_mps;
346static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000348#ifdef FEAT_TEXTOBJ
349static char_u *p_qe;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_ro;
352#ifdef FEAT_SMARTINDENT
353static int p_si;
354#endif
355#ifndef SHORT_FNAME
356static int p_sn;
357#endif
358static long p_sts;
359#if defined(FEAT_SEARCHPATH)
360static char_u *p_sua;
361#endif
362static long p_sw;
363static int p_swf;
364#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000365static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000367#endif
368#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000369static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000370static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000371static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000372#endif
373static long p_ts;
374static long p_tw;
375static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200376#ifdef FEAT_PERSISTENT_UNDO
377static int p_udf;
378#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000379static long p_wm;
380#ifdef FEAT_KEYMAP
381static char_u *p_keymap;
382#endif
383
384/* Saved values for when 'bin' is set. */
385static int p_et_nobin;
386static int p_ml_nobin;
387static long p_tw_nobin;
388static long p_wm_nobin;
389
390/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200391static int p_ai_nopaste;
392static int p_et_nopaste;
393static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394static long p_tw_nopaste;
395static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396
397struct vimoption
398{
399 char *fullname; /* full option name */
400 char *shortname; /* permissible abbreviation */
401 long_u flags; /* see below */
402 char_u *var; /* global option: pointer to variable;
403 * window-local option: VAR_WIN;
404 * buffer-local option: global value */
405 idopt_T indir; /* global option: PV_NONE;
406 * local option: indirect option index */
407 char_u *def_val[2]; /* default values for variable (vi and vim) */
408#ifdef FEAT_EVAL
409 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000410# define SCRIPTID_INIT , 0
411#else
412# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413#endif
414};
415
416#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
417#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
418
419/*
420 * Flags
421 */
422#define P_BOOL 0x01 /* the option is boolean */
423#define P_NUM 0x02 /* the option is numeric */
424#define P_STRING 0x04 /* the option is a string */
425#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000426 must use free_string_option() when
427 assigning new value. Not set if default is
428 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000429#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
430 never be used for local or hidden options! */
431#define P_NODEFAULT 0x40 /* don't set to default value */
432#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
433 use vim_free() when assigning new value */
434#define P_WAS_SET 0x100 /* option has been set/reset */
435#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
436#define P_VI_DEF 0x400 /* Use Vi default for Vim */
437#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
438
439 /* when option changed, what to display: */
440#define P_RSTAT 0x1000 /* redraw status lines */
441#define P_RWIN 0x2000 /* redraw current window */
442#define P_RBUF 0x4000 /* redraw current buffer */
443#define P_RALL 0x6000 /* redraw all windows */
444#define P_RCLR 0x7000 /* clear and redraw all */
445
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200446#define P_COMMA 0x8000 /* comma separated list */
447#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
448 * commas */
449#define P_NODUP 0x20000L /* don't allow duplicate strings */
450#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200452#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
453#define P_GETTEXT 0x100000L /* expand default value with _() */
454#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
455#define P_NFNAME 0x400000L /* only normal file name chars allowed */
456#define P_INSECURE 0x800000L /* option was set from a modeline */
457#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000458 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200459#define P_NO_ML 0x2000000L /* not allowed in modeline */
460#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200461 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000462
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000463#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
464
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000465/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
466 * for the currency sign. */
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100467#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000468# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000469#else
470# define ISP_LATIN1 (char_u *)"@,161-255"
471#endif
472
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000473/* The 16 bit MS-DOS version is low on space, make the string as short as
474 * possible when compiling with few features. */
475#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
476 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200477 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100478# 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 +0000479#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100480# 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 +0000481#endif
482
Bram Moolenaar071d4272004-06-13 20:20:40 +0000483/*
484 * options[] is initialized here.
485 * The order of the options MUST be alphabetic for ":set all" and findoption().
486 * All option names MUST start with a lowercase letter (for findoption()).
487 * Exception: "t_" options are at the end.
488 * The options with a NULL variable are 'hidden': a set command for them is
489 * ignored and they are not printed.
490 */
491static struct vimoption
492#ifdef FEAT_GUI_W16
493 _far
494#endif
495 options[] =
496{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200497 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498#ifdef FEAT_RIGHTLEFT
499 (char_u *)&p_aleph, PV_NONE,
500#else
501 (char_u *)NULL, PV_NONE,
502#endif
503 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100504#if (defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505 (char_u *)128L,
506#else
507 (char_u *)224L,
508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000509 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
511#if defined(FEAT_GUI) && defined(MACOS_X)
512 (char_u *)&p_antialias, PV_NONE,
513 {(char_u *)FALSE, (char_u *)FALSE}
514#else
515 (char_u *)NULL, PV_NONE,
516 {(char_u *)FALSE, (char_u *)FALSE}
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200519 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520#ifdef FEAT_ARABIC
521 (char_u *)VAR_WIN, PV_ARAB,
522#else
523 (char_u *)NULL, PV_NONE,
524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000525 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
527#ifdef FEAT_ARABIC
528 (char_u *)&p_arshape, PV_NONE,
529#else
530 (char_u *)NULL, PV_NONE,
531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000532 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
534#ifdef FEAT_RIGHTLEFT
535 (char_u *)&p_ari, PV_NONE,
536#else
537 (char_u *)NULL, PV_NONE,
538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000540 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
541#ifdef FEAT_FKMAP
542 (char_u *)&p_altkeymap, PV_NONE,
543#else
544 (char_u *)NULL, PV_NONE,
545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
548#if defined(FEAT_MBYTE)
549 (char_u *)&p_ambw, PV_NONE,
550 {(char_u *)"single", (char_u *)0L}
551#else
552 (char_u *)NULL, PV_NONE,
553 {(char_u *)0L, (char_u *)0L}
554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000556#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autochdir", "acd", P_BOOL|P_VI_DEF,
558 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560#endif
561 {"autoindent", "ai", P_BOOL|P_VI_DEF,
562 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564 {"autoprint", "ap", P_BOOL|P_VI_DEF,
565 (char_u *)NULL, 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 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000568 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autowrite", "aw", P_BOOL|P_VI_DEF,
571 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autowriteall","awa", P_BOOL|P_VI_DEF,
574 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
577 (char_u *)&p_bg, PV_NONE,
578 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100579#if (defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 (char_u *)"dark",
581#else
582 (char_u *)"light",
583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000584 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200585 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000587 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
589 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200592 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593#ifdef UNIX
594 {(char_u *)"yes", (char_u *)"auto"}
595#else
596 {(char_u *)"auto", (char_u *)"auto"}
597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000598 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200599 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
600 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000602 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000603 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 (char_u *)&p_bex, PV_NONE,
605 {
606#ifdef VMS
607 (char_u *)"_",
608#else
609 (char_u *)"~",
610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000611 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200612 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613#ifdef FEAT_WILDIGN
614 (char_u *)&p_bsk, PV_NONE,
615 {(char_u *)"", (char_u *)0L}
616#else
617 (char_u *)NULL, PV_NONE,
618 {(char_u *)0L, (char_u *)0L}
619#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621#ifdef FEAT_BEVAL
622 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
623 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
626 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000628# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000629 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000630 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000632# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633#endif
634 {"beautify", "bf", P_BOOL|P_VI_DEF,
635 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200637 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
638 (char_u *)&p_bo, PV_NONE,
639 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
641 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000642 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000643 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
644#ifdef MSDOS
645 (char_u *)&p_biosk, PV_NONE,
646#else
647 (char_u *)NULL, PV_NONE,
648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000650 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
651#ifdef FEAT_MBYTE
652 (char_u *)&p_bomb, PV_BOMB,
653#else
654 (char_u *)NULL, PV_NONE,
655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000656 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000657 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
658#ifdef FEAT_LINEBREAK
659 (char_u *)&p_breakat, PV_NONE,
660 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
661#else
662 (char_u *)NULL, PV_NONE,
663 {(char_u *)0L, (char_u *)0L}
664#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200666 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
667#ifdef FEAT_LINEBREAK
668 (char_u *)VAR_WIN, PV_BRI,
669 {(char_u *)FALSE, (char_u *)0L}
670#else
671 (char_u *)NULL, PV_NONE,
672 {(char_u *)0L, (char_u *)0L}
673#endif
674 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200675 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
676 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200677#ifdef FEAT_LINEBREAK
678 (char_u *)VAR_WIN, PV_BRIOPT,
679 {(char_u *)"", (char_u *)NULL}
680#else
681 (char_u *)NULL, PV_NONE,
682 {(char_u *)"", (char_u *)NULL}
683#endif
684 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000685 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
686#ifdef FEAT_BROWSE
687 (char_u *)&p_bsdir, PV_NONE,
688 {(char_u *)"last", (char_u *)0L}
689#else
690 (char_u *)NULL, PV_NONE,
691 {(char_u *)0L, (char_u *)0L}
692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000693 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000694 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
695#if defined(FEAT_QUICKFIX)
696 (char_u *)&p_bh, PV_BH,
697 {(char_u *)"", (char_u *)0L}
698#else
699 (char_u *)NULL, PV_NONE,
700 {(char_u *)0L, (char_u *)0L}
701#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000702 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
704 (char_u *)&p_bl, PV_BL,
705 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000706 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
708#if defined(FEAT_QUICKFIX)
709 (char_u *)&p_bt, PV_BT,
710 {(char_u *)"", (char_u *)0L}
711#else
712 (char_u *)NULL, PV_NONE,
713 {(char_u *)0L, (char_u *)0L}
714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000715 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200716 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000717#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 (char_u *)&p_cmp, PV_NONE,
719 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000720#else
721 (char_u *)NULL, PV_NONE,
722 {(char_u *)0L, (char_u *)0L}
723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
726#ifdef FEAT_SEARCHPATH
727 (char_u *)&p_cdpath, PV_NONE,
728 {(char_u *)",,", (char_u *)0L}
729#else
730 (char_u *)NULL, PV_NONE,
731 {(char_u *)0L, (char_u *)0L}
732#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000733 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734 {"cedit", NULL, P_STRING,
735#ifdef FEAT_CMDWIN
736 (char_u *)&p_cedit, PV_NONE,
737 {(char_u *)"", (char_u *)CTRL_F_STR}
738#else
739 (char_u *)NULL, PV_NONE,
740 {(char_u *)0L, (char_u *)0L}
741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000742 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000743 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
744#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
745 (char_u *)&p_ccv, PV_NONE,
746 {(char_u *)"", (char_u *)0L}
747#else
748 (char_u *)NULL, PV_NONE,
749 {(char_u *)0L, (char_u *)0L}
750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000751 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000752 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
753#ifdef FEAT_CINDENT
754 (char_u *)&p_cin, PV_CIN,
755#else
756 (char_u *)NULL, PV_NONE,
757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000758 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200759 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760#ifdef FEAT_CINDENT
761 (char_u *)&p_cink, PV_CINK,
762 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
763#else
764 (char_u *)NULL, PV_NONE,
765 {(char_u *)0L, (char_u *)0L}
766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000767 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200768 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769#ifdef FEAT_CINDENT
770 (char_u *)&p_cino, PV_CINO,
771#else
772 (char_u *)NULL, PV_NONE,
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200775 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
777 (char_u *)&p_cinw, PV_CINW,
778 {(char_u *)"if,else,while,do,for,switch",
779 (char_u *)0L}
780#else
781 (char_u *)NULL, PV_NONE,
782 {(char_u *)0L, (char_u *)0L}
783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000784 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200785 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786#ifdef FEAT_CLIPBOARD
787 (char_u *)&p_cb, PV_NONE,
788# ifdef FEAT_XCLIPBOARD
789 {(char_u *)"autoselect,exclude:cons\\|linux",
790 (char_u *)0L}
791# else
792 {(char_u *)"", (char_u *)0L}
793# endif
794#else
795 (char_u *)NULL, PV_NONE,
796 {(char_u *)"", (char_u *)0L}
797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000798 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000799 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
800 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000801 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000802 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
803#ifdef FEAT_CMDWIN
804 (char_u *)&p_cwh, PV_NONE,
805#else
806 (char_u *)NULL, PV_NONE,
807#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000808 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200809 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200810#ifdef FEAT_SYN_HL
811 (char_u *)VAR_WIN, PV_CC,
812#else
813 (char_u *)NULL, PV_NONE,
814#endif
815 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
817 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000818 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200819 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
820 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000821#ifdef FEAT_COMMENTS
822 (char_u *)&p_com, PV_COM,
823 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
824 (char_u *)0L}
825#else
826 (char_u *)NULL, PV_NONE,
827 {(char_u *)0L, (char_u *)0L}
828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000829 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200830 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831#ifdef FEAT_FOLDING
832 (char_u *)&p_cms, PV_CMS,
833 {(char_u *)"/*%s*/", (char_u *)0L}
834#else
835 (char_u *)NULL, PV_NONE,
836 {(char_u *)0L, (char_u *)0L}
837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000838 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000839 /* P_PRI_MKRC isn't needed here, optval_default()
840 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841 {"compatible", "cp", P_BOOL|P_RALL,
842 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000843 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200844 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000845#ifdef FEAT_INS_EXPAND
846 (char_u *)&p_cpt, PV_CPT,
847 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
848#else
849 (char_u *)NULL, PV_NONE,
850 {(char_u *)0L, (char_u *)0L}
851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000852 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200853 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200854#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200855 (char_u *)VAR_WIN, PV_COCU,
856 {(char_u *)"", (char_u *)NULL}
857#else
858 (char_u *)NULL, PV_NONE,
859 {(char_u *)NULL, (char_u *)0L}
860#endif
861 SCRIPTID_INIT},
862 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
863#ifdef FEAT_CONCEAL
864 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200865#else
866 (char_u *)NULL, PV_NONE,
867#endif
868 {(char_u *)0L, (char_u *)0L}
869 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000870 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
871#ifdef FEAT_COMPL_FUNC
872 (char_u *)&p_cfu, PV_CFU,
873 {(char_u *)"", (char_u *)0L}
874#else
875 (char_u *)NULL, PV_NONE,
876 {(char_u *)0L, (char_u *)0L}
877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000878 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200879 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000880#ifdef FEAT_INS_EXPAND
881 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000882 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000883#else
884 (char_u *)NULL, PV_NONE,
885 {(char_u *)0L, (char_u *)0L}
886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000887 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000888 {"confirm", "cf", P_BOOL|P_VI_DEF,
889#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
890 (char_u *)&p_confirm, PV_NONE,
891#else
892 (char_u *)NULL, PV_NONE,
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"conskey", "consk",P_BOOL|P_VI_DEF,
896#ifdef MSDOS
897 (char_u *)&p_consk, PV_NONE,
898#else
899 (char_u *)NULL, PV_NONE,
900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
903 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
906 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
908 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200909 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200910#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200911 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200912 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200913#else
914 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200915 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200916#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
919#ifdef FEAT_CSCOPE
920 (char_u *)&p_cspc, PV_NONE,
921#else
922 (char_u *)NULL, PV_NONE,
923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000924 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
926#ifdef FEAT_CSCOPE
927 (char_u *)&p_csprg, PV_NONE,
928 {(char_u *)"cscope", (char_u *)0L}
929#else
930 (char_u *)NULL, PV_NONE,
931 {(char_u *)0L, (char_u *)0L}
932#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000933 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200934 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000935#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
936 (char_u *)&p_csqf, PV_NONE,
937 {(char_u *)"", (char_u *)0L}
938#else
939 (char_u *)NULL, PV_NONE,
940 {(char_u *)0L, (char_u *)0L}
941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000942 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200943 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
944#ifdef FEAT_CSCOPE
945 (char_u *)&p_csre, PV_NONE,
946#else
947 (char_u *)NULL, PV_NONE,
948#endif
949 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000950 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
951#ifdef FEAT_CSCOPE
952 (char_u *)&p_cst, PV_NONE,
953#else
954 (char_u *)NULL, PV_NONE,
955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000956 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
958#ifdef FEAT_CSCOPE
959 (char_u *)&p_csto, PV_NONE,
960#else
961 (char_u *)NULL, PV_NONE,
962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000963 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
965#ifdef FEAT_CSCOPE
966 (char_u *)&p_csverbose, PV_NONE,
967#else
968 (char_u *)NULL, PV_NONE,
969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000970 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200971 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
972#ifdef FEAT_CURSORBIND
973 (char_u *)VAR_WIN, PV_CRBIND,
974#else
975 (char_u *)NULL, PV_NONE,
976#endif
977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000978 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
979#ifdef FEAT_SYN_HL
980 (char_u *)VAR_WIN, PV_CUC,
981#else
982 (char_u *)NULL, PV_NONE,
983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000985 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
986#ifdef FEAT_SYN_HL
987 (char_u *)VAR_WIN, PV_CUL,
988#else
989 (char_u *)NULL, PV_NONE,
990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992 {"debug", NULL, P_STRING|P_VI_DEF,
993 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000994 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200995 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000997 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000998 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999#else
1000 (char_u *)NULL, PV_NONE,
1001 {(char_u *)NULL, (char_u *)0L}
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1005#ifdef FEAT_MBYTE
1006 (char_u *)&p_deco, PV_NONE,
1007#else
1008 (char_u *)NULL, PV_NONE,
1009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001011 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001013 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#else
1015 (char_u *)NULL, PV_NONE,
1016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1019#ifdef FEAT_DIFF
1020 (char_u *)VAR_WIN, PV_DIFF,
1021#else
1022 (char_u *)NULL, PV_NONE,
1023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001024 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001025 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1027 (char_u *)&p_dex, PV_NONE,
1028 {(char_u *)"", (char_u *)0L}
1029#else
1030 (char_u *)NULL, PV_NONE,
1031 {(char_u *)0L, (char_u *)0L}
1032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001033 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001034 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1035 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036#ifdef FEAT_DIFF
1037 (char_u *)&p_dip, PV_NONE,
1038 {(char_u *)"filler", (char_u *)NULL}
1039#else
1040 (char_u *)NULL, PV_NONE,
1041 {(char_u *)"", (char_u *)NULL}
1042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1045#ifdef FEAT_DIGRAPHS
1046 (char_u *)&p_dg, PV_NONE,
1047#else
1048 (char_u *)NULL, PV_NONE,
1049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001051 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1052 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001054 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001055 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001057 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 {"eadirection", "ead", P_STRING|P_VI_DEF,
1059#ifdef FEAT_VERTSPLIT
1060 (char_u *)&p_ead, PV_NONE,
1061 {(char_u *)"both", (char_u *)0L}
1062#else
1063 (char_u *)NULL, PV_NONE,
1064 {(char_u *)NULL, (char_u *)0L}
1065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1068 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001070 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071#ifdef FEAT_MBYTE
1072 (char_u *)&p_enc, PV_NONE,
1073 {(char_u *)ENC_DFLT, (char_u *)0L}
1074#else
1075 (char_u *)NULL, PV_NONE,
1076 {(char_u *)0L, (char_u *)0L}
1077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001078 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001079 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1080 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1083 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001086 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1089 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1092#ifdef FEAT_QUICKFIX
1093 (char_u *)&p_ef, PV_NONE,
1094 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1095#else
1096 (char_u *)NULL, PV_NONE,
1097 {(char_u *)NULL, (char_u *)0L}
1098#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001100 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001102 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104#else
1105 (char_u *)NULL, PV_NONE,
1106 {(char_u *)NULL, (char_u *)0L}
1107#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"esckeys", "ek", P_BOOL|P_VIM,
1110 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001112 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113#ifdef FEAT_AUTOCMD
1114 (char_u *)&p_ei, PV_NONE,
1115#else
1116 (char_u *)NULL, PV_NONE,
1117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1120 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1123 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001125 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1126 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001127#ifdef FEAT_MBYTE
1128 (char_u *)&p_fenc, PV_FENC,
1129 {(char_u *)"", (char_u *)0L}
1130#else
1131 (char_u *)NULL, PV_NONE,
1132 {(char_u *)0L, (char_u *)0L}
1133#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001134 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001135 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136#ifdef FEAT_MBYTE
1137 (char_u *)&p_fencs, PV_NONE,
1138 {(char_u *)"ucs-bom", (char_u *)0L}
1139#else
1140 (char_u *)NULL, PV_NONE,
1141 {(char_u *)0L, (char_u *)0L}
1142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001144 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1145 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001147 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001148 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1151 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001152 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1153 (char_u *)&p_fic, PV_NONE,
1154 {
1155#ifdef CASE_INSENSITIVE_FILENAME
1156 (char_u *)TRUE,
1157#else
1158 (char_u *)FALSE,
1159#endif
1160 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001161 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162#ifdef FEAT_AUTOCMD
1163 (char_u *)&p_ft, PV_FT,
1164 {(char_u *)"", (char_u *)0L}
1165#else
1166 (char_u *)NULL, PV_NONE,
1167 {(char_u *)0L, (char_u *)0L}
1168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001170 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1172 (char_u *)&p_fcs, PV_NONE,
1173 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1174#else
1175 (char_u *)NULL, PV_NONE,
1176 {(char_u *)"", (char_u *)0L}
1177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001179 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1180 (char_u *)&p_fixeol, PV_FIXEOL,
1181 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1183#ifdef FEAT_FKMAP
1184 (char_u *)&p_fkmap, PV_NONE,
1185#else
1186 (char_u *)NULL, PV_NONE,
1187#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"flash", "fl", P_BOOL|P_VI_DEF,
1190 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001193 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001195 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1197 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1200 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001202 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1203# ifdef FEAT_EVAL
1204 (char_u *)VAR_WIN, PV_FDE,
1205 {(char_u *)"0", (char_u *)NULL}
1206# else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
1209# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1212 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1215 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001217 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001221 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)"{{{,}}}", (char_u *)NULL}
1224 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1226 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001227 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1229 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1232 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001233 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001234 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001235 (char_u *)&p_fdo, PV_NONE,
1236 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1239# ifdef FEAT_EVAL
1240 (char_u *)VAR_WIN, PV_FDT,
1241 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001242# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001245# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001248 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001249#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001250 (char_u *)&p_fex, PV_FEX,
1251 {(char_u *)"", (char_u *)0L}
1252#else
1253 (char_u *)NULL, PV_NONE,
1254 {(char_u *)0L, (char_u *)0L}
1255#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001257 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1258 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001259 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1260 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001261 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1262 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1264 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1266 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001267 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001268 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1269#ifdef HAVE_FSYNC
1270 (char_u *)&p_fs, PV_NONE,
1271 {(char_u *)TRUE, (char_u *)0L}
1272#else
1273 (char_u *)NULL, PV_NONE,
1274 {(char_u *)FALSE, (char_u *)0L}
1275#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1278 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001279 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 {"graphic", "gr", P_BOOL|P_VI_DEF,
1281 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001282 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001283 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001284#ifdef FEAT_QUICKFIX
1285 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001286 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287#else
1288 (char_u *)NULL, PV_NONE,
1289 {(char_u *)NULL, (char_u *)0L}
1290#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001291 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001292 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1293#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001294 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295 {
1296# ifdef WIN3264
1297 /* may be changed to "grep -n" in os_win32.c */
1298 (char_u *)"findstr /n",
1299# else
1300# ifdef UNIX
1301 /* Add an extra file name so that grep will always
1302 * insert a file name in the match line. */
1303 (char_u *)"grep -n $* /dev/null",
1304# else
1305# ifdef VMS
1306 (char_u *)"SEARCH/NUMBERS ",
1307# else
1308 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001309# endif
1310# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313#else
1314 (char_u *)NULL, PV_NONE,
1315 {(char_u *)NULL, (char_u *)0L}
1316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001317 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001318 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319#ifdef CURSOR_SHAPE
1320 (char_u *)&p_guicursor, PV_NONE,
1321 {
1322# ifdef FEAT_GUI
1323 (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",
1324# else /* MSDOS or Win32 console */
1325 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1326# endif
1327 (char_u *)0L}
1328#else
1329 (char_u *)NULL, PV_NONE,
1330 {(char_u *)NULL, (char_u *)0L}
1331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001332 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001333 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334#ifdef FEAT_GUI
1335 (char_u *)&p_guifont, PV_NONE,
1336 {(char_u *)"", (char_u *)0L}
1337#else
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)NULL, (char_u *)0L}
1340#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001341 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001342 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1344 (char_u *)&p_guifontset, PV_NONE,
1345 {(char_u *)"", (char_u *)0L}
1346#else
1347 (char_u *)NULL, PV_NONE,
1348 {(char_u *)NULL, (char_u *)0L}
1349#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001351 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1353 (char_u *)&p_guifontwide, PV_NONE,
1354 {(char_u *)"", (char_u *)0L}
1355#else
1356 (char_u *)NULL, PV_NONE,
1357 {(char_u *)NULL, (char_u *)0L}
1358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001361#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 (char_u *)&p_ghr, PV_NONE,
1363#else
1364 (char_u *)NULL, PV_NONE,
1365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001366 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001368#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 (char_u *)&p_go, PV_NONE,
1370# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001371 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001373 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001374# endif
1375#else
1376 (char_u *)NULL, PV_NONE,
1377 {(char_u *)NULL, (char_u *)0L}
1378#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001379 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {"guipty", NULL, P_BOOL|P_VI_DEF,
1381#if defined(FEAT_GUI)
1382 (char_u *)&p_guipty, PV_NONE,
1383#else
1384 (char_u *)NULL, PV_NONE,
1385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001386 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001387 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001388#if defined(FEAT_GUI_TABLINE)
1389 (char_u *)&p_gtl, PV_NONE,
1390 {(char_u *)"", (char_u *)0L}
1391#else
1392 (char_u *)NULL, PV_NONE,
1393 {(char_u *)NULL, (char_u *)0L}
1394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001395 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001396 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001397#if defined(FEAT_GUI_TABLINE)
1398 (char_u *)&p_gtt, PV_NONE,
1399 {(char_u *)"", (char_u *)0L}
1400#else
1401 (char_u *)NULL, PV_NONE,
1402 {(char_u *)NULL, (char_u *)0L}
1403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001404 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1406 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001407 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1409 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001410 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"helpheight", "hh", P_NUM|P_VI_DEF,
1413#ifdef FEAT_WINDOWS
1414 (char_u *)&p_hh, PV_NONE,
1415#else
1416 (char_u *)NULL, PV_NONE,
1417#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001418 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001419 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420#ifdef FEAT_MULTI_LANG
1421 (char_u *)&p_hlg, PV_NONE,
1422 {(char_u *)"", (char_u *)0L}
1423#else
1424 (char_u *)NULL, PV_NONE,
1425 {(char_u *)0L, (char_u *)0L}
1426#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001427 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"hidden", "hid", P_BOOL|P_VI_DEF,
1429 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001430 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001431 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001433 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1434 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"history", "hi", P_NUM|P_VIM,
1436 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001437 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1439#ifdef FEAT_RIGHTLEFT
1440 (char_u *)&p_hkmap, PV_NONE,
1441#else
1442 (char_u *)NULL, PV_NONE,
1443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1446#ifdef FEAT_RIGHTLEFT
1447 (char_u *)&p_hkmapp, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1453 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001454 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"icon", NULL, P_BOOL|P_VI_DEF,
1456#ifdef FEAT_TITLE
1457 (char_u *)&p_icon, PV_NONE,
1458#else
1459 (char_u *)NULL, PV_NONE,
1460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"iconstring", NULL, P_STRING|P_VI_DEF,
1463#ifdef FEAT_TITLE
1464 (char_u *)&p_iconstring, 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 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1470 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001472 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1473# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1474 (char_u *)&p_imaf, PV_NONE,
1475 {(char_u *)"", (char_u *)NULL}
1476# else
1477 (char_u *)NULL, PV_NONE,
1478 {(char_u *)NULL, (char_u *)0L}
1479# endif
1480 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001482#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483 (char_u *)&p_imak, PV_NONE,
1484#else
1485 (char_u *)NULL, PV_NONE,
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1489#ifdef USE_IM_CONTROL
1490 (char_u *)&p_imcmdline, PV_NONE,
1491#else
1492 (char_u *)NULL, PV_NONE,
1493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001494 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1496#ifdef USE_IM_CONTROL
1497 (char_u *)&p_imdisable, PV_NONE,
1498#else
1499 (char_u *)NULL, PV_NONE,
1500#endif
1501#ifdef __sgi
1502 {(char_u *)TRUE, (char_u *)0L}
1503#else
1504 {(char_u *)FALSE, (char_u *)0L}
1505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001506 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"iminsert", "imi", P_NUM|P_VI_DEF,
1508 (char_u *)&p_iminsert, PV_IMI,
1509#ifdef B_IMODE_IM
1510 {(char_u *)B_IMODE_IM, (char_u *)0L}
1511#else
1512 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001514 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {"imsearch", "ims", P_NUM|P_VI_DEF,
1516 (char_u *)&p_imsearch, PV_IMS,
1517#ifdef B_IMODE_IM
1518 {(char_u *)B_IMODE_IM, (char_u *)0L}
1519#else
1520 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001522 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001523 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001524# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1525 (char_u *)&p_imsf, PV_NONE,
1526 {(char_u *)"", (char_u *)NULL}
1527# else
1528 (char_u *)NULL, PV_NONE,
1529 {(char_u *)NULL, (char_u *)0L}
1530# endif
1531 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1533#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001534 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001535 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1536#else
1537 (char_u *)NULL, PV_NONE,
1538 {(char_u *)0L, (char_u *)0L}
1539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001540 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1542#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1543 (char_u *)&p_inex, PV_INEX,
1544 {(char_u *)"", (char_u *)0L}
1545#else
1546 (char_u *)NULL, PV_NONE,
1547 {(char_u *)0L, (char_u *)0L}
1548#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001549 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1551 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1554#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1555 (char_u *)&p_inde, PV_INDE,
1556 {(char_u *)"", (char_u *)0L}
1557#else
1558 (char_u *)NULL, PV_NONE,
1559 {(char_u *)0L, (char_u *)0L}
1560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001561 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001562 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001563#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1564 (char_u *)&p_indk, PV_INDK,
1565 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1566#else
1567 (char_u *)NULL, PV_NONE,
1568 {(char_u *)0L, (char_u *)0L}
1569#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 {"infercase", "inf", P_BOOL|P_VI_DEF,
1572 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1575 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1578 (char_u *)&p_isf, PV_NONE,
1579 {
1580#ifdef BACKSLASH_IN_FILENAME
1581 /* Excluded are: & and ^ are special in cmd.exe
1582 * ( and ) are used in text separating fnames */
1583 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1584#else
1585# ifdef AMIGA
1586 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1587# else
1588# ifdef VMS
1589 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1590# else /* UNIX et al. */
1591# ifdef EBCDIC
1592 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1593# else
1594 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1595# endif
1596# endif
1597# endif
1598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001599 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1601 (char_u *)&p_isi, PV_NONE,
1602 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001603#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001604 (char_u *)"@,48-57,_,128-167,224-235",
1605#else
1606# ifdef EBCDIC
1607 /* TODO: EBCDIC Check this! @ == isalpha()*/
1608 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1609 "112-120,128,140-142,156,158,172,"
1610 "174,186,191,203-207,219-225,235-239,"
1611 "251-254",
1612# else
1613 (char_u *)"@,48-57,_,192-255",
1614# endif
1615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001616 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1618 (char_u *)&p_isk, PV_ISK,
1619 {
1620#ifdef EBCDIC
1621 (char_u *)"@,240-249,_",
1622 /* TODO: EBCDIC Check this! @ == isalpha()*/
1623 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1624 "112-120,128,140-142,156,158,172,"
1625 "174,186,191,203-207,219-225,235-239,"
1626 "251-254",
1627#else
1628 (char_u *)"@,48-57,_",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001629# if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 (char_u *)"@,48-57,_,128-167,224-235"
1631# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001632 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633# endif
1634#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001635 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1637 (char_u *)&p_isp, PV_NONE,
1638 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001639#if defined(MSDOS) || defined(MSWIN) \
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001640 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 || defined(VMS)
1642 (char_u *)"@,~-255",
1643#else
1644# ifdef EBCDIC
1645 /* all chars above 63 are printable */
1646 (char_u *)"63-255",
1647# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001648 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649# endif
1650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001651 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001652 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1653 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001654 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1656#ifdef FEAT_CRYPT
1657 (char_u *)&p_key, PV_KEY,
1658 {(char_u *)"", (char_u *)0L}
1659#else
1660 (char_u *)NULL, PV_NONE,
1661 {(char_u *)0L, (char_u *)0L}
1662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001663 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001664 {"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 +00001665#ifdef FEAT_KEYMAP
1666 (char_u *)&p_keymap, PV_KMAP,
1667 {(char_u *)"", (char_u *)0L}
1668#else
1669 (char_u *)NULL, PV_NONE,
1670 {(char_u *)"", (char_u *)0L}
1671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001672 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001673 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001675 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001676 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001677 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {
1679#if defined(MSDOS) || defined(MSWIN)
1680 (char_u *)":help",
1681#else
1682#ifdef VMS
1683 (char_u *)"help",
1684#else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001685# ifdef USEMAN_S
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 (char_u *)"man -s",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001687# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 (char_u *)"man",
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689# endif
1690#endif
1691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001693 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694#ifdef FEAT_LANGMAP
1695 (char_u *)&p_langmap, PV_NONE,
1696 {(char_u *)"", /* unmatched } */
1697#else
1698 (char_u *)NULL, PV_NONE,
1699 {(char_u *)NULL,
1700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001701 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001702 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1704 (char_u *)&p_lm, PV_NONE,
1705#else
1706 (char_u *)NULL, PV_NONE,
1707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001708 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001709 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1710#ifdef FEAT_LANGMAP
1711 (char_u *)&p_lnr, PV_NONE,
1712#else
1713 (char_u *)NULL, PV_NONE,
1714#endif
1715 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1717#ifdef FEAT_WINDOWS
1718 (char_u *)&p_ls, PV_NONE,
1719#else
1720 (char_u *)NULL, PV_NONE,
1721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1724 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001725 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1727#ifdef FEAT_LINEBREAK
1728 (char_u *)VAR_WIN, PV_LBR,
1729#else
1730 (char_u *)NULL, PV_NONE,
1731#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001732 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1734 (char_u *)&Rows, PV_NONE,
1735 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001736#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 (char_u *)25L,
1738#else
1739 (char_u *)24L,
1740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1743#ifdef FEAT_GUI
1744 (char_u *)&p_linespace, PV_NONE,
1745#else
1746 (char_u *)NULL, PV_NONE,
1747#endif
1748#ifdef FEAT_GUI_W32
1749 {(char_u *)1L, (char_u *)0L}
1750#else
1751 {(char_u *)0L, (char_u *)0L}
1752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001753 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754 {"lisp", NULL, P_BOOL|P_VI_DEF,
1755#ifdef FEAT_LISP
1756 (char_u *)&p_lisp, PV_LISP,
1757#else
1758 (char_u *)NULL, PV_NONE,
1759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001761 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001763 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1765#else
1766 (char_u *)NULL, PV_NONE,
1767 {(char_u *)"", (char_u *)0L}
1768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001769 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1771 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001773 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001775 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1777 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001778 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001779#if defined(DYNAMIC_LUA) && !defined(WIN3264)
1780 {"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1781 (char_u *)&p_luadll, PV_NONE,
1782 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1783#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001784#ifdef FEAT_GUI_MAC
1785 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1786 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001787 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001788#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"magic", NULL, P_BOOL|P_VI_DEF,
1790 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001792 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793#ifdef FEAT_QUICKFIX
1794 (char_u *)&p_mef, PV_NONE,
1795 {(char_u *)"", (char_u *)0L}
1796#else
1797 (char_u *)NULL, PV_NONE,
1798 {(char_u *)NULL, (char_u *)0L}
1799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001800 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001801 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1802#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001803 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804# ifdef VMS
1805 {(char_u *)"MMS", (char_u *)0L}
1806# else
1807 {(char_u *)"make", (char_u *)0L}
1808# endif
1809#else
1810 (char_u *)NULL, PV_NONE,
1811 {(char_u *)NULL, (char_u *)0L}
1812#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001814 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1817 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 {"matchtime", "mat", P_NUM|P_VI_DEF,
1819 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001821 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001822#ifdef FEAT_MBYTE
1823 (char_u *)&p_mco, PV_NONE,
1824#else
1825 (char_u *)NULL, PV_NONE,
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1829#ifdef FEAT_EVAL
1830 (char_u *)&p_mfd, PV_NONE,
1831#else
1832 (char_u *)NULL, PV_NONE,
1833#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1836 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001838 {"maxmem", "mm", P_NUM|P_VI_DEF,
1839 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1841 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001842 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1843 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1846 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1848 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"menuitems", "mis", P_NUM|P_VI_DEF,
1850#ifdef FEAT_MENU
1851 (char_u *)&p_mis, PV_NONE,
1852#else
1853 (char_u *)NULL, PV_NONE,
1854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856 {"mesg", NULL, P_BOOL|P_VI_DEF,
1857 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001859 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001860#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001861 (char_u *)&p_msm, PV_NONE,
1862 {(char_u *)"460000,2000,500", (char_u *)0L}
1863#else
1864 (char_u *)NULL, PV_NONE,
1865 {(char_u *)0L, (char_u *)0L}
1866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"modeline", "ml", P_BOOL|P_VIM,
1869 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"modelines", "mls", P_NUM|P_VI_DEF,
1872 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001873 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1875 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1878 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"more", NULL, P_BOOL|P_VIM,
1881 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001882 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1884 (char_u *)&p_mouse, PV_NONE,
1885 {
1886#if defined(MSDOS) || defined(WIN3264)
1887 (char_u *)"a",
1888#else
1889 (char_u *)"",
1890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001891 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001892 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1893#ifdef FEAT_GUI
1894 (char_u *)&p_mousef, PV_NONE,
1895#else
1896 (char_u *)NULL, PV_NONE,
1897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1900#ifdef FEAT_GUI
1901 (char_u *)&p_mh, PV_NONE,
1902#else
1903 (char_u *)NULL, PV_NONE,
1904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1907 (char_u *)&p_mousem, PV_NONE,
1908 {
1909#if defined(MSDOS) || defined(MSWIN)
1910 (char_u *)"popup",
1911#else
1912# if defined(MACOS)
1913 (char_u *)"popup_setpos",
1914# else
1915 (char_u *)"extend",
1916# endif
1917#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001918 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001919 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920#ifdef FEAT_MOUSESHAPE
1921 (char_u *)&p_mouseshape, PV_NONE,
1922 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1923#else
1924 (char_u *)NULL, PV_NONE,
1925 {(char_u *)NULL, (char_u *)0L}
1926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001928 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1929 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001931 {"mzquantum", "mzq", P_NUM,
1932#ifdef FEAT_MZSCHEME
1933 (char_u *)&p_mzq, PV_NONE,
1934#else
1935 (char_u *)NULL, PV_NONE,
1936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 {"novice", NULL, P_BOOL|P_VI_DEF,
1939 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001941 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)"octal,hex", (char_u *)0L}
1944 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1946 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001948 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1949#ifdef FEAT_LINEBREAK
1950 (char_u *)VAR_WIN, PV_NUW,
1951#else
1952 (char_u *)NULL, PV_NONE,
1953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001955 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001956#ifdef FEAT_COMPL_FUNC
1957 (char_u *)&p_ofu, PV_OFU,
1958 {(char_u *)"", (char_u *)0L}
1959#else
1960 (char_u *)NULL, PV_NONE,
1961 {(char_u *)0L, (char_u *)0L}
1962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001964 {"open", NULL, P_BOOL|P_VI_DEF,
1965 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001966 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001967 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001968#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001969 (char_u *)&p_odev, PV_NONE,
1970#else
1971 (char_u *)NULL, PV_NONE,
1972#endif
1973 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001975 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1976 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"optimize", "opt", P_BOOL|P_VI_DEF,
1979 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001980 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001983 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 {"paragraphs", "para", P_STRING|P_VI_DEF,
1985 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001986 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001988 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1992 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1995#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1996 (char_u *)&p_pex, PV_NONE,
1997 {(char_u *)"", (char_u *)0L}
1998#else
1999 (char_u *)NULL, PV_NONE,
2000 {(char_u *)0L, (char_u *)0L}
2001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002002 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002003 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002007 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 {
2009#if defined AMIGA || defined MSDOS || defined MSWIN
2010 (char_u *)".,,",
2011#else
2012# if defined(__EMX__)
2013 (char_u *)".,/emx/include,,",
2014# else /* Unix, probably */
2015 (char_u *)".,/usr/include,,",
2016# endif
2017#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002018 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002019#if defined(DYNAMIC_PERL) && !defined(WIN3264)
2020 {"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2021 (char_u *)&p_perldll, PV_NONE,
2022 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2023#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2025 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002026 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002027 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2029 (char_u *)&p_pvh, PV_NONE,
2030#else
2031 (char_u *)NULL, PV_NONE,
2032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2035#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2036 (char_u *)VAR_WIN, PV_PVW,
2037#else
2038 (char_u *)NULL, PV_NONE,
2039#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002040 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002041 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042#ifdef FEAT_PRINTER
2043 (char_u *)&p_pdev, PV_NONE,
2044 {(char_u *)"", (char_u *)0L}
2045#else
2046 (char_u *)NULL, PV_NONE,
2047 {(char_u *)NULL, (char_u *)0L}
2048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002049 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050 {"printencoding", "penc", P_STRING|P_VI_DEF,
2051#ifdef FEAT_POSTSCRIPT
2052 (char_u *)&p_penc, PV_NONE,
2053 {(char_u *)"", (char_u *)0L}
2054#else
2055 (char_u *)NULL, PV_NONE,
2056 {(char_u *)NULL, (char_u *)0L}
2057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002058 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2060#ifdef FEAT_POSTSCRIPT
2061 (char_u *)&p_pexpr, PV_NONE,
2062 {(char_u *)"", (char_u *)0L}
2063#else
2064 (char_u *)NULL, PV_NONE,
2065 {(char_u *)NULL, (char_u *)0L}
2066#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002067 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002068 {"printfont", "pfn", P_STRING|P_VI_DEF,
2069#ifdef FEAT_PRINTER
2070 (char_u *)&p_pfn, PV_NONE,
2071 {
2072# ifdef MSWIN
2073 (char_u *)"Courier_New:h10",
2074# else
2075 (char_u *)"courier",
2076# endif
2077 (char_u *)0L}
2078#else
2079 (char_u *)NULL, PV_NONE,
2080 {(char_u *)NULL, (char_u *)0L}
2081#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002082 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2084#ifdef FEAT_PRINTER
2085 (char_u *)&p_header, PV_NONE,
2086 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2087#else
2088 (char_u *)NULL, PV_NONE,
2089 {(char_u *)NULL, (char_u *)0L}
2090#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002092 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2093#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2094 (char_u *)&p_pmcs, PV_NONE,
2095 {(char_u *)"", (char_u *)0L}
2096#else
2097 (char_u *)NULL, PV_NONE,
2098 {(char_u *)NULL, (char_u *)0L}
2099#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002100 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002101 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2102#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2103 (char_u *)&p_pmfn, PV_NONE,
2104 {(char_u *)"", (char_u *)0L}
2105#else
2106 (char_u *)NULL, PV_NONE,
2107 {(char_u *)NULL, (char_u *)0L}
2108#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002109 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002110 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111#ifdef FEAT_PRINTER
2112 (char_u *)&p_popt, PV_NONE,
2113 {(char_u *)"", (char_u *)0L}
2114#else
2115 (char_u *)NULL, PV_NONE,
2116 {(char_u *)NULL, (char_u *)0L}
2117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002118 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002120 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002122 {"pumheight", "ph", P_NUM|P_VI_DEF,
2123#ifdef FEAT_INS_EXPAND
2124 (char_u *)&p_ph, PV_NONE,
2125#else
2126 (char_u *)NULL, PV_NONE,
2127#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002128 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002129#if defined(DYNAMIC_PYTHON3) && !defined(WIN3264)
Bram Moolenaar0796c062015-11-10 19:41:37 +01002130 {"pythonthreedll", NULL, P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002131 (char_u *)&p_py3dll, PV_NONE,
2132 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2133#endif
2134#if defined(DYNAMIC_PYTHON) && !defined(WIN3264)
2135 {"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2136 (char_u *)&p_pydll, PV_NONE,
2137 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2138#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002139 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2140#ifdef FEAT_TEXTOBJ
2141 (char_u *)&p_qe, PV_QE,
2142 {(char_u *)"\\", (char_u *)0L}
2143#else
2144 (char_u *)NULL, PV_NONE,
2145 {(char_u *)NULL, (char_u *)0L}
2146#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002147 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2149 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002150 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151 {"redraw", NULL, P_BOOL|P_VI_DEF,
2152 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002153 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002154 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2155#ifdef FEAT_RELTIME
2156 (char_u *)&p_rdt, PV_NONE,
2157#else
2158 (char_u *)NULL, PV_NONE,
2159#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002161 {"regexpengine", "re", P_NUM|P_VI_DEF,
2162 (char_u *)&p_re, PV_NONE,
2163 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002164 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2165 (char_u *)VAR_WIN, PV_RNU,
2166 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002167 {"remap", NULL, P_BOOL|P_VI_DEF,
2168 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002170 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002171#ifdef FEAT_RENDER_OPTIONS
2172 (char_u *)&p_rop, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)NULL, (char_u *)0L}
2177#endif
2178 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"report", NULL, P_NUM|P_VI_DEF,
2180 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002181 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2183#ifdef WIN3264
2184 (char_u *)&p_rs, PV_NONE,
2185#else
2186 (char_u *)NULL, PV_NONE,
2187#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002188 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002189 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2190#ifdef FEAT_RIGHTLEFT
2191 (char_u *)&p_ri, PV_NONE,
2192#else
2193 (char_u *)NULL, PV_NONE,
2194#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002195 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002196 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2197#ifdef FEAT_RIGHTLEFT
2198 (char_u *)VAR_WIN, PV_RL,
2199#else
2200 (char_u *)NULL, PV_NONE,
2201#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002202 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2204#ifdef FEAT_RIGHTLEFT
2205 (char_u *)VAR_WIN, PV_RLC,
2206 {(char_u *)"search", (char_u *)NULL}
2207#else
2208 (char_u *)NULL, PV_NONE,
2209 {(char_u *)NULL, (char_u *)0L}
2210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002211 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002212#if defined(DYNAMIC_RUBY) && !defined(WIN3264)
2213 {"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2214 (char_u *)&p_rubydll, PV_NONE,
2215 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2216#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002217 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2218#ifdef FEAT_CMDL_INFO
2219 (char_u *)&p_ru, PV_NONE,
2220#else
2221 (char_u *)NULL, PV_NONE,
2222#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002223 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002224 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2225#ifdef FEAT_STL_OPT
2226 (char_u *)&p_ruf, PV_NONE,
2227#else
2228 (char_u *)NULL, PV_NONE,
2229#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002230 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002231 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2232 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002233 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002234 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2235 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002236 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2237 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002238 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002239 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2240#ifdef FEAT_SCROLLBIND
2241 (char_u *)VAR_WIN, PV_SCBIND,
2242#else
2243 (char_u *)NULL, PV_NONE,
2244#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002245 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002246 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2247 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002248 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002249 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2250 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002251 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002252 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002253#ifdef FEAT_SCROLLBIND
2254 (char_u *)&p_sbo, PV_NONE,
2255 {(char_u *)"ver,jump", (char_u *)0L}
2256#else
2257 (char_u *)NULL, PV_NONE,
2258 {(char_u *)0L, (char_u *)0L}
2259#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002260 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002261 {"sections", "sect", P_STRING|P_VI_DEF,
2262 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002263 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2264 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2266 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002267 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002270 {(char_u *)"inclusive", (char_u *)0L}
2271 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002272 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002274 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002275 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002276#ifdef FEAT_SESSION
2277 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002278 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 (char_u *)0L}
2280#else
2281 (char_u *)NULL, PV_NONE,
2282 {(char_u *)0L, (char_u *)0L}
2283#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002284 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2286 (char_u *)&p_sh, PV_NONE,
2287 {
2288#ifdef VMS
2289 (char_u *)"-",
2290#else
2291# if defined(MSDOS)
2292 (char_u *)"command",
2293# else
2294# if defined(WIN16)
2295 (char_u *)"command.com",
2296# else
2297# if defined(WIN3264)
2298 (char_u *)"", /* set in set_init_1() */
2299# else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002300# if defined(ARCHIE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301 (char_u *)"gos",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002302# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304# endif
2305# endif
2306# endif
2307# endif
2308#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2311 (char_u *)&p_shcf, PV_NONE,
2312 {
2313#if defined(MSDOS) || defined(MSWIN)
2314 (char_u *)"/c",
2315#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002318 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2320#ifdef FEAT_QUICKFIX
2321 (char_u *)&p_sp, PV_NONE,
2322 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002323#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324# ifdef ARCHIE
2325 (char_u *)"2>",
2326# else
2327 (char_u *)"| tee",
2328# endif
2329#else
2330 (char_u *)">",
2331#endif
2332 (char_u *)0L}
2333#else
2334 (char_u *)NULL, PV_NONE,
2335 {(char_u *)0L, (char_u *)0L}
2336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2339 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002340 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2342 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2345#ifdef BACKSLASH_IN_FILENAME
2346 (char_u *)&p_ssl, PV_NONE,
2347#else
2348 (char_u *)NULL, PV_NONE,
2349#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002350 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002351 {"shelltemp", "stmp", P_BOOL,
2352 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002353 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 {"shelltype", "st", P_NUM|P_VI_DEF,
2355#ifdef AMIGA
2356 (char_u *)&p_st, PV_NONE,
2357#else
2358 (char_u *)NULL, PV_NONE,
2359#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002360 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2362 (char_u *)&p_sxq, PV_NONE,
2363 {
2364#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2365 (char_u *)"\"",
2366#else
2367 (char_u *)"",
2368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002370 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2371 (char_u *)&p_sxe, PV_NONE,
2372 {
2373#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2374 (char_u *)"\"&|<>()@^",
2375#else
2376 (char_u *)"",
2377#endif
2378 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2380 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2383 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2386 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)"", (char_u *)"filnxtToO"}
2388 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"shortname", "sn", P_BOOL|P_VI_DEF,
2390#ifdef SHORT_FNAME
2391 (char_u *)NULL, PV_NONE,
2392#else
2393 (char_u *)&p_sn, PV_SN,
2394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2397#ifdef FEAT_LINEBREAK
2398 (char_u *)&p_sbr, PV_NONE,
2399#else
2400 (char_u *)NULL, PV_NONE,
2401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"showcmd", "sc", P_BOOL|P_VIM,
2404#ifdef FEAT_CMDL_INFO
2405 (char_u *)&p_sc, PV_NONE,
2406#else
2407 (char_u *)NULL, PV_NONE,
2408#endif
2409 {(char_u *)FALSE,
2410#ifdef UNIX
2411 (char_u *)FALSE
2412#else
2413 (char_u *)TRUE
2414#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002415 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2417 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2420 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002421 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422 {"showmode", "smd", P_BOOL|P_VIM,
2423 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002424 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002425 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2426#ifdef FEAT_WINDOWS
2427 (char_u *)&p_stal, PV_NONE,
2428#else
2429 (char_u *)NULL, PV_NONE,
2430#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2433 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002434 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2436 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2439 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002440 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2442 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002443 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2445#ifdef FEAT_SMARTINDENT
2446 (char_u *)&p_si, PV_SI,
2447#else
2448 (char_u *)NULL, PV_NONE,
2449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2452 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2455 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002456 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2458 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002460 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002461#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002462 (char_u *)VAR_WIN, PV_SPELL,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002467 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002468#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002469 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002470 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002471#else
2472 (char_u *)NULL, PV_NONE,
2473 {(char_u *)0L, (char_u *)0L}
2474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002476 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2477 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002478#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002479 (char_u *)&p_spf, PV_SPF,
2480 {(char_u *)"", (char_u *)0L}
2481#else
2482 (char_u *)NULL, PV_NONE,
2483 {(char_u *)0L, (char_u *)0L}
2484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002486 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2487 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002488#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002489 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002490 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002491#else
2492 (char_u *)NULL, PV_NONE,
2493 {(char_u *)0L, (char_u *)0L}
2494#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002495 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002496 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002497#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002498 (char_u *)&p_sps, PV_NONE,
2499 {(char_u *)"best", (char_u *)0L}
2500#else
2501 (char_u *)NULL, PV_NONE,
2502 {(char_u *)0L, (char_u *)0L}
2503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2506#ifdef FEAT_WINDOWS
2507 (char_u *)&p_sb, PV_NONE,
2508#else
2509 (char_u *)NULL, PV_NONE,
2510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"splitright", "spr", P_BOOL|P_VI_DEF,
2513#ifdef FEAT_VERTSPLIT
2514 (char_u *)&p_spr, PV_NONE,
2515#else
2516 (char_u *)NULL, PV_NONE,
2517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2520 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2523#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002524 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525#else
2526 (char_u *)NULL, PV_NONE,
2527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002529 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 (char_u *)&p_su, PV_NONE,
2531 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002532 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002533 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002534#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 (char_u *)&p_sua, PV_SUA,
2536 {(char_u *)"", (char_u *)0L}
2537#else
2538 (char_u *)NULL, PV_NONE,
2539 {(char_u *)0L, (char_u *)0L}
2540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2543 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002545 {"swapsync", "sws", P_STRING|P_VI_DEF,
2546 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002548 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002549 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002551 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2552#ifdef FEAT_SYN_HL
2553 (char_u *)&p_smc, PV_SMC,
2554 {(char_u *)3000L, (char_u *)0L}
2555#else
2556 (char_u *)NULL, PV_NONE,
2557 {(char_u *)0L, (char_u *)0L}
2558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002560 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561#ifdef FEAT_SYN_HL
2562 (char_u *)&p_syn, PV_SYN,
2563 {(char_u *)"", (char_u *)0L}
2564#else
2565 (char_u *)NULL, PV_NONE,
2566 {(char_u *)0L, (char_u *)0L}
2567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002569 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2570#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002571 (char_u *)&p_tal, PV_NONE,
2572#else
2573 (char_u *)NULL, PV_NONE,
2574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002576 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2577#ifdef FEAT_WINDOWS
2578 (char_u *)&p_tpm, PV_NONE,
2579#else
2580 (char_u *)NULL, PV_NONE,
2581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2584 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002585 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2587 (char_u *)&p_tbs, PV_NONE,
2588#ifdef VMS /* binary searching doesn't appear to work on VMS */
2589 {(char_u *)0L, (char_u *)0L}
2590#else
2591 {(char_u *)TRUE, (char_u *)0L}
2592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002593 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002594 {"tagcase", "tc", P_STRING|P_VIM,
2595 (char_u *)&p_tc, PV_TC,
2596 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"taglength", "tl", P_NUM|P_VI_DEF,
2598 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002599 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 {"tagrelative", "tr", P_BOOL|P_VIM,
2601 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002602 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002603 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002604 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 {
2606#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2607 (char_u *)"./tags,./TAGS,tags,TAGS",
2608#else
2609 (char_u *)"./tags,tags",
2610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002611 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002612 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2613 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2616 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002617 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2619#ifdef FEAT_ARABIC
2620 (char_u *)&p_tbidi, PV_NONE,
2621#else
2622 (char_u *)NULL, PV_NONE,
2623#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002624 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2626#ifdef FEAT_MBYTE
2627 (char_u *)&p_tenc, PV_NONE,
2628 {(char_u *)"", (char_u *)0L}
2629#else
2630 (char_u *)NULL, PV_NONE,
2631 {(char_u *)0L, (char_u *)0L}
2632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002633 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 {"terse", NULL, P_BOOL|P_VI_DEF,
2635 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"textauto", "ta", P_BOOL|P_VIM,
2638 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2642 (char_u *)&p_tx, PV_TX,
2643 {
2644#ifdef USE_CRNL
2645 (char_u *)TRUE,
2646#else
2647 (char_u *)FALSE,
2648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002650 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002652 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002653 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002655 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656#else
2657 (char_u *)NULL, PV_NONE,
2658#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2661 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002662 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 {"timeout", "to", P_BOOL|P_VI_DEF,
2664 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2667 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002668 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002669 {"title", NULL, P_BOOL|P_VI_DEF,
2670#ifdef FEAT_TITLE
2671 (char_u *)&p_title, PV_NONE,
2672#else
2673 (char_u *)NULL, PV_NONE,
2674#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002676 {"titlelen", NULL, P_NUM|P_VI_DEF,
2677#ifdef FEAT_TITLE
2678 (char_u *)&p_titlelen, PV_NONE,
2679#else
2680 (char_u *)NULL, PV_NONE,
2681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002682 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002683 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002684#ifdef FEAT_TITLE
2685 (char_u *)&p_titleold, PV_NONE,
2686 {(char_u *)N_("Thanks for flying Vim"),
2687 (char_u *)0L}
2688#else
2689 (char_u *)NULL, PV_NONE,
2690 {(char_u *)0L, (char_u *)0L}
2691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002692 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002693 {"titlestring", NULL, P_STRING|P_VI_DEF,
2694#ifdef FEAT_TITLE
2695 (char_u *)&p_titlestring, PV_NONE,
2696#else
2697 (char_u *)NULL, PV_NONE,
2698#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002701 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)"icons,tooltips", (char_u *)0L}
2704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002706#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2708 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002709 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002710#endif
2711 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2712 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2715 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002716 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2718 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002719 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002720 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2721 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002722 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002723 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2724#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2725 (char_u *)&p_ttym, PV_NONE,
2726#else
2727 (char_u *)NULL, PV_NONE,
2728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002729 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2731 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2734 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002736 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2737 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002738#ifdef FEAT_PERSISTENT_UNDO
2739 (char_u *)&p_udir, PV_NONE,
2740 {(char_u *)".", (char_u *)0L}
2741#else
2742 (char_u *)NULL, PV_NONE,
2743 {(char_u *)0L, (char_u *)0L}
2744#endif
2745 SCRIPTID_INIT},
2746 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2747#ifdef FEAT_PERSISTENT_UNDO
2748 (char_u *)&p_udf, PV_UDF,
2749#else
2750 (char_u *)NULL, PV_NONE,
2751#endif
2752 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002754 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002756#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 (char_u *)1000L,
2758#else
2759 (char_u *)100L,
2760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002762 {"undoreload", "ur", P_NUM|P_VI_DEF,
2763 (char_u *)&p_ur, PV_NONE,
2764 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"updatecount", "uc", P_NUM|P_VI_DEF,
2766 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"updatetime", "ut", P_NUM|P_VI_DEF,
2769 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"verbose", "vbs", P_NUM|P_VI_DEF,
2772 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002774 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2775 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002776 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2778#ifdef FEAT_SESSION
2779 (char_u *)&p_vdir, PV_NONE,
2780 {(char_u *)DFLT_VDIR, (char_u *)0L}
2781#else
2782 (char_u *)NULL, PV_NONE,
2783 {(char_u *)0L, (char_u *)0L}
2784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002786 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787#ifdef FEAT_SESSION
2788 (char_u *)&p_vop, PV_NONE,
2789 {(char_u *)"folds,options,cursor", (char_u *)0L}
2790#else
2791 (char_u *)NULL, PV_NONE,
2792 {(char_u *)0L, (char_u *)0L}
2793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002795 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796#ifdef FEAT_VIMINFO
2797 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002798#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002799 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800#else
2801# ifdef AMIGA
2802 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002803 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002805 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806# endif
2807#endif
2808#else
2809 (char_u *)NULL, PV_NONE,
2810 {(char_u *)0L, (char_u *)0L}
2811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002813 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2814 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815#ifdef FEAT_VIRTUALEDIT
2816 (char_u *)&p_ve, PV_NONE,
2817 {(char_u *)"", (char_u *)""}
2818#else
2819 (char_u *)NULL, PV_NONE,
2820 {(char_u *)0L, (char_u *)0L}
2821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2824 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"w300", NULL, P_NUM|P_VI_DEF,
2827 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"w1200", NULL, P_NUM|P_VI_DEF,
2830 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"w9600", NULL, P_NUM|P_VI_DEF,
2833 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"warn", NULL, P_BOOL|P_VI_DEF,
2836 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2839 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002841 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"wildchar", "wc", P_NUM|P_VIM,
2845 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2847 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002848 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002850 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002851 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852#ifdef FEAT_WILDIGN
2853 (char_u *)&p_wig, PV_NONE,
2854#else
2855 (char_u *)NULL, PV_NONE,
2856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002858 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2859 (char_u *)&p_wic, PV_NONE,
2860 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2862#ifdef FEAT_WILDMENU
2863 (char_u *)&p_wmnu, PV_NONE,
2864#else
2865 (char_u *)NULL, PV_NONE,
2866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002867 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002868 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002871 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2872#ifdef FEAT_CMDL_COMPL
2873 (char_u *)&p_wop, PV_NONE,
2874 {(char_u *)"", (char_u *)0L}
2875#else
2876 (char_u *)NULL, PV_NONE,
2877 {(char_u *)NULL, (char_u *)0L}
2878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2881#ifdef FEAT_WAK
2882 (char_u *)&p_wak, PV_NONE,
2883 {(char_u *)"menu", (char_u *)0L}
2884#else
2885 (char_u *)NULL, PV_NONE,
2886 {(char_u *)NULL, (char_u *)0L}
2887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002890 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"winheight", "wh", P_NUM|P_VI_DEF,
2893#ifdef FEAT_WINDOWS
2894 (char_u *)&p_wh, PV_NONE,
2895#else
2896 (char_u *)NULL, PV_NONE,
2897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002898 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002900#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 (char_u *)VAR_WIN, PV_WFH,
2902#else
2903 (char_u *)NULL, PV_NONE,
2904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002906 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2907#ifdef FEAT_VERTSPLIT
2908 (char_u *)VAR_WIN, PV_WFW,
2909#else
2910 (char_u *)NULL, PV_NONE,
2911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2914#ifdef FEAT_WINDOWS
2915 (char_u *)&p_wmh, PV_NONE,
2916#else
2917 (char_u *)NULL, PV_NONE,
2918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002919 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2921#ifdef FEAT_VERTSPLIT
2922 (char_u *)&p_wmw, PV_NONE,
2923#else
2924 (char_u *)NULL, PV_NONE,
2925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2928#ifdef FEAT_VERTSPLIT
2929 (char_u *)&p_wiw, PV_NONE,
2930#else
2931 (char_u *)NULL, PV_NONE,
2932#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002933 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2935 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002936 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2938 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002939 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2941 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002942 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002943 {"write", NULL, P_BOOL|P_VI_DEF,
2944 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002945 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946 {"writeany", "wa", P_BOOL|P_VI_DEF,
2947 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2950 (char_u *)&p_wb, PV_NONE,
2951 {
2952#ifdef FEAT_WRITEBACKUP
2953 (char_u *)TRUE,
2954#else
2955 (char_u *)FALSE,
2956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"writedelay", "wd", P_NUM|P_VI_DEF,
2959 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002960 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961
2962/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002963#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002965 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966
2967 p_term("t_AB", T_CAB)
2968 p_term("t_AF", T_CAF)
2969 p_term("t_AL", T_CAL)
2970 p_term("t_al", T_AL)
2971 p_term("t_bc", T_BC)
2972 p_term("t_cd", T_CD)
2973 p_term("t_ce", T_CE)
2974 p_term("t_cl", T_CL)
2975 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002976 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 p_term("t_Co", T_CCO)
2978 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002979 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 p_term("t_cs", T_CS)
2981#ifdef FEAT_VERTSPLIT
2982 p_term("t_CV", T_CSV)
2983#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984 p_term("t_da", T_DA)
2985 p_term("t_db", T_DB)
2986 p_term("t_DL", T_CDL)
2987 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002988 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 p_term("t_fs", T_FS)
2990 p_term("t_IE", T_CIE)
2991 p_term("t_IS", T_CIS)
2992 p_term("t_ke", T_KE)
2993 p_term("t_ks", T_KS)
2994 p_term("t_le", T_LE)
2995 p_term("t_mb", T_MB)
2996 p_term("t_md", T_MD)
2997 p_term("t_me", T_ME)
2998 p_term("t_mr", T_MR)
2999 p_term("t_ms", T_MS)
3000 p_term("t_nd", T_ND)
3001 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003002 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 p_term("t_RI", T_CRI)
3004 p_term("t_RV", T_CRV)
3005 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003007 p_term("t_Sf", T_CSF)
3008 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003010 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 p_term("t_te", T_TE)
3013 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003014 p_term("t_ts", T_TS)
3015 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 p_term("t_ue", T_UE)
3017 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003018 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 p_term("t_vb", T_VB)
3020 p_term("t_ve", T_VE)
3021 p_term("t_vi", T_VI)
3022 p_term("t_vs", T_VS)
3023 p_term("t_WP", T_CWP)
3024 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003025 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 p_term("t_xs", T_XS)
3027 p_term("t_ZH", T_CZH)
3028 p_term("t_ZR", T_CZR)
3029
3030/* terminal key codes are not in here */
3031
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003032 /* end marker */
3033 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034};
3035
3036#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3037
3038#ifdef FEAT_MBYTE
3039static char *(p_ambw_values[]) = {"single", "double", NULL};
3040#endif
3041static char *(p_bg_values[]) = {"light", "dark", NULL};
3042static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
3043static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003044#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003045static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003046#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003047#ifdef FEAT_CMDL_COMPL
3048static char *(p_wop_values[]) = {"tagfile", NULL};
3049#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050#ifdef FEAT_WAK
3051static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3052#endif
3053static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3055static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057#ifdef FEAT_BROWSE
3058static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3059#endif
3060#ifdef FEAT_SCROLLBIND
3061static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3062#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003063static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064#ifdef FEAT_VERTSPLIT
3065static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3066#endif
3067#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003068# ifdef FEAT_AUTOCMD
3069static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3070# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003072# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3074#endif
3075static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3076#ifdef FEAT_FOLDING
3077static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003078# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003080# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 NULL};
3082static char *(p_fcl_values[]) = {"all", NULL};
3083#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003084#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003085static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003086#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087
3088static void set_option_default __ARGS((int, int opt_flags, int compatible));
3089static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003090static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003091static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092static char_u *illegal_char __ARGS((char_u *, int));
3093static int string_to_key __ARGS((char_u *arg));
3094#ifdef FEAT_CMDWIN
3095static char_u *check_cedit __ARGS((void));
3096#endif
3097#ifdef FEAT_TITLE
3098static void did_set_title __ARGS((int icon));
3099#endif
3100static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3101static void didset_options __ARGS((void));
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003102static void didset_options2 __ARGS((void));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003104#if defined(FEAT_EVAL) || defined(PROTO)
3105static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3106#else
3107# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3108#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003110static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111static 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));
3112static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003113#ifdef FEAT_SYN_HL
3114static int int_cmp __ARGS((const void *a, const void *b));
3115#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116#ifdef FEAT_CLIPBOARD
3117static char_u *check_clipboard_option __ARGS((void));
3118#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003119#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003120static char_u *did_set_spell_option __ARGS((int is_spellfile));
Bram Moolenaar860cae12010-06-05 23:22:07 +02003121static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003122#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003123#ifdef FEAT_EVAL
3124static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3125#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003127static 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 +00003128static void check_redraw __ARGS((long_u flags));
3129static int findoption __ARGS((char_u *));
3130static int find_key_option __ARGS((char_u *));
3131static void showoptions __ARGS((int all, int opt_flags));
3132static int optval_default __ARGS((struct vimoption *, char_u *varp));
3133static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3134static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3135static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3136static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3137static int istermoption __ARGS((struct vimoption *));
3138static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3139static char_u *get_varp __ARGS((struct vimoption *));
3140static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003141static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3143#ifdef FEAT_LANGMAP
3144static void langmap_init __ARGS((void));
3145static void langmap_set __ARGS((void));
3146#endif
3147static void paste_option_changed __ARGS((void));
3148static void compatible_set __ARGS((void));
3149#ifdef FEAT_LINEBREAK
3150static void fill_breakat_flags __ARGS((void));
3151#endif
3152static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3153static int check_opt_strings __ARGS((char_u *val, char **values, int));
3154static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003155#ifdef FEAT_LINEBREAK
3156static int briopt_check __ARGS((win_T *wp));
3157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158
3159/*
3160 * Initialize the options, first part.
3161 *
3162 * Called only once from main(), just after creating the first buffer.
3163 */
3164 void
3165set_init_1()
3166{
3167 char_u *p;
3168 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003169 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170
3171#ifdef FEAT_LANGMAP
3172 langmap_init();
3173#endif
3174
3175 /* Be Vi compatible by default */
3176 p_cp = TRUE;
3177
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003178 /* Use POSIX compatibility when $VIM_POSIX is set. */
3179 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003180 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003181 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003182 set_string_default("shm", (char_u *)"A");
3183 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003184
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 /*
3186 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003187 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003189 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003190#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003192 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003194 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003196 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197# endif
3198#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003199 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 set_string_default("sh", p);
3201
3202#ifdef FEAT_WILDIGN
3203 /*
3204 * Set the default for 'backupskip' to include environment variables for
3205 * temp files.
3206 */
3207 {
3208# ifdef UNIX
3209 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3210# else
3211 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3212# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003213 int len;
3214 garray_T ga;
3215 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216
3217 ga_init2(&ga, 1, 100);
3218 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3219 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003220 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221# ifdef UNIX
3222 if (*names[n] == NUL)
3223 p = (char_u *)"/tmp";
3224 else
3225# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003226 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227 if (p != NULL && *p != NUL)
3228 {
3229 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003230 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231 if (ga_grow(&ga, len) == OK)
3232 {
3233 if (ga.ga_len > 0)
3234 STRCAT(ga.ga_data, ",");
3235 STRCAT(ga.ga_data, p);
3236 add_pathsep(ga.ga_data);
3237 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 ga.ga_len += len;
3239 }
3240 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003241 if (mustfree)
3242 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243 }
3244 if (ga.ga_data != NULL)
3245 {
3246 set_string_default("bsk", ga.ga_data);
3247 vim_free(ga.ga_data);
3248 }
3249 }
3250#endif
3251
3252 /*
3253 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3254 */
3255 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003256 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003258#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3259 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3260#endif
3261 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003263 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003264 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265#else
3266# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003267 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003268 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003270 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003271# endif
3272#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003274 opt_idx = findoption((char_u *)"maxmem");
3275 if (opt_idx >= 0)
3276 {
3277#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003278 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3279 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003280#endif
3281 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3282 }
3283 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003284 }
3285
3286#ifdef FEAT_GUI_W32
3287 /* force 'shortname' for Win32s */
3288 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003289 {
3290 opt_idx = findoption((char_u *)"shortname");
3291 if (opt_idx >= 0)
3292 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3293 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294#endif
3295
3296#ifdef FEAT_SEARCHPATH
3297 {
3298 char_u *cdpath;
3299 char_u *buf;
3300 int i;
3301 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003302 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303
3304 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003305 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306 if (cdpath != NULL)
3307 {
3308 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3309 if (buf != NULL)
3310 {
3311 buf[0] = ','; /* start with ",", current dir first */
3312 j = 1;
3313 for (i = 0; cdpath[i] != NUL; ++i)
3314 {
3315 if (vim_ispathlistsep(cdpath[i]))
3316 buf[j++] = ',';
3317 else
3318 {
3319 if (cdpath[i] == ' ' || cdpath[i] == ',')
3320 buf[j++] = '\\';
3321 buf[j++] = cdpath[i];
3322 }
3323 }
3324 buf[j] = NUL;
3325 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003326 if (opt_idx >= 0)
3327 {
3328 options[opt_idx].def_val[VI_DEFAULT] = buf;
3329 options[opt_idx].flags |= P_DEF_ALLOCED;
3330 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003331 else
3332 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003334 if (mustfree)
3335 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 }
3337 }
3338#endif
3339
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003340#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341 /* Set print encoding on platforms that don't default to latin1 */
3342 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003343# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344 (char_u *)"cp1252"
3345# else
3346# ifdef VMS
3347 (char_u *)"dec-mcs"
3348# else
3349# ifdef EBCDIC
3350 (char_u *)"ebcdic-uk"
3351# else
3352# ifdef MAC
3353 (char_u *)"mac-roman"
3354# else /* HPUX */
3355 (char_u *)"hp-roman8"
3356# endif
3357# endif
3358# endif
3359# endif
3360 );
3361#endif
3362
3363#ifdef FEAT_POSTSCRIPT
3364 /* 'printexpr' must be allocated to be able to evaluate it. */
3365 set_string_default("pexpr",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003366# if defined(MSWIN) || defined(MSDOS)
Bram Moolenaared203462004-06-16 11:19:22 +00003367 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368# else
3369# ifdef VMS
3370 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3371
3372# else
3373 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3374# endif
3375# endif
3376 );
3377#endif
3378
3379 /*
3380 * Set all the options (except the terminal options) to their default
3381 * value. Also set the global value for local options.
3382 */
3383 set_options_default(0);
3384
3385#ifdef FEAT_GUI
3386 if (found_reverse_arg)
3387 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3388#endif
3389
3390 curbuf->b_p_initialized = TRUE;
3391 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003392 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393 check_buf_options(curbuf);
3394 check_win_options(curwin);
3395 check_options();
3396
3397 /* Must be before option_expand(), because that one needs vim_isIDc() */
3398 didset_options();
3399
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003400#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003401 /* Use the current chartab for the generic chartab. This is not in
3402 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003403 init_spell_chartab();
3404#endif
3405
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406 /*
3407 * Expand environment variables and things like "~" for the defaults.
3408 * If option_expand() returns non-NULL the variable is expanded. This can
3409 * only happen for non-indirect options.
3410 * Also set the default to the expanded value, so ":set" does not list
3411 * them.
3412 * Don't set the P_ALLOCED flag, because we don't want to free the
3413 * default.
3414 */
3415 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3416 {
3417 if ((options[opt_idx].flags & P_GETTEXT)
3418 && options[opt_idx].var != NULL)
3419 p = (char_u *)_(*(char **)options[opt_idx].var);
3420 else
3421 p = option_expand(opt_idx, NULL);
3422 if (p != NULL && (p = vim_strsave(p)) != NULL)
3423 {
3424 *(char_u **)options[opt_idx].var = p;
3425 /* VIMEXP
3426 * Defaults for all expanded options are currently the same for Vi
3427 * and Vim. When this changes, add some code here! Also need to
3428 * split P_DEF_ALLOCED in two.
3429 */
3430 if (options[opt_idx].flags & P_DEF_ALLOCED)
3431 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3432 options[opt_idx].def_val[VI_DEFAULT] = p;
3433 options[opt_idx].flags |= P_DEF_ALLOCED;
3434 }
3435 }
3436
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 save_file_ff(curbuf); /* Buffer is unchanged */
3438
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439#if defined(FEAT_ARABIC)
3440 /* Detect use of mlterm.
3441 * Mlterm is a terminal emulator akin to xterm that has some special
3442 * abilities (bidi namely).
3443 * NOTE: mlterm's author is being asked to 'set' a variable
3444 * instead of an environment variable due to inheritance.
3445 */
3446 if (mch_getenv((char_u *)"MLTERM") != NULL)
3447 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3448#endif
3449
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003450 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003451
3452#ifdef FEAT_MBYTE
3453# if defined(WIN3264) && defined(FEAT_GETTEXT)
3454 /*
3455 * If $LANG isn't set, try to get a good value for it. This makes the
3456 * right language be used automatically. Don't do this for English.
3457 */
3458 if (mch_getenv((char_u *)"LANG") == NULL)
3459 {
3460 char buf[20];
3461
3462 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3463 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3464 * only the first two. */
3465 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3466 (LPTSTR)buf, 20);
3467 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3468 {
3469 /* There are a few exceptions (probably more) */
3470 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3471 STRCPY(buf, "zh_TW");
3472 else if (STRNICMP(buf, "chs", 3) == 0
3473 || STRNICMP(buf, "zhc", 3) == 0)
3474 STRCPY(buf, "zh_CN");
3475 else if (STRNICMP(buf, "jp", 2) == 0)
3476 STRCPY(buf, "ja");
3477 else
3478 buf[2] = NUL; /* truncate to two-letter code */
3479 vim_setenv("LANG", buf);
3480 }
3481 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003482# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003483# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003484 /* Moved to os_mac_conv.c to avoid dependency problems. */
3485 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003486# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003487# endif
3488
3489 /* enc_locale() will try to find the encoding of the current locale. */
3490 p = enc_locale();
3491 if (p != NULL)
3492 {
3493 char_u *save_enc;
3494
3495 /* Try setting 'encoding' and check if the value is valid.
3496 * If not, go back to the default "latin1". */
3497 save_enc = p_enc;
3498 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003499 if (STRCMP(p_enc, "gb18030") == 0)
3500 {
3501 /* We don't support "gb18030", but "cp936" is a good substitute
3502 * for practical purposes, thus use that. It's not an alias to
3503 * still support conversion between gb18030 and utf-8. */
3504 p_enc = vim_strsave((char_u *)"cp936");
3505 vim_free(p);
3506 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507 if (mb_init() == NULL)
3508 {
3509 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003510 if (opt_idx >= 0)
3511 {
3512 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3513 options[opt_idx].flags |= P_DEF_ALLOCED;
3514 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003516#if defined(MSDOS) || defined(MSWIN) || defined(MACOS) \
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003517 || defined(VMS)
3518 if (STRCMP(p_enc, "latin1") == 0
3519# ifdef FEAT_MBYTE
3520 || enc_utf8
3521# endif
3522 )
3523 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003524 /* Adjust the default for 'isprint' and 'iskeyword' to match
3525 * latin1. Also set the defaults for when 'nocompatible' is
3526 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003527 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003528 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003529 set_string_option_direct((char_u *)"isk", -1,
3530 ISK_LATIN1, OPT_FREE, SID_NONE);
3531 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003532 if (opt_idx >= 0)
3533 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003534 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003535 if (opt_idx >= 0)
3536 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003537 (void)init_chartab();
3538 }
3539#endif
3540
Bram Moolenaar071d4272004-06-13 20:20:40 +00003541# if defined(WIN3264) && !defined(FEAT_GUI)
3542 /* Win32 console: When GetACP() returns a different value from
3543 * GetConsoleCP() set 'termencoding'. */
3544 if (GetACP() != GetConsoleCP())
3545 {
3546 char buf[50];
3547
3548 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3549 p_tenc = vim_strsave((char_u *)buf);
3550 if (p_tenc != NULL)
3551 {
3552 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003553 if (opt_idx >= 0)
3554 {
3555 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3556 options[opt_idx].flags |= P_DEF_ALLOCED;
3557 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003558 convert_setup(&input_conv, p_tenc, p_enc);
3559 convert_setup(&output_conv, p_enc, p_tenc);
3560 }
3561 else
3562 p_tenc = empty_option;
3563 }
3564# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003565# if defined(WIN3264) && defined(FEAT_MBYTE)
3566 /* $HOME may have characters in active code page. */
3567 init_homedir();
3568# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003569 }
3570 else
3571 {
3572 vim_free(p_enc);
3573 p_enc = save_enc;
3574 }
3575 }
3576#endif
3577
3578#ifdef FEAT_MULTI_LANG
3579 /* Set the default for 'helplang'. */
3580 set_helplang_default(get_mess_lang());
3581#endif
3582}
3583
3584/*
3585 * Set an option to its default value.
3586 * This does not take care of side effects!
3587 */
3588 static void
3589set_option_default(opt_idx, opt_flags, compatible)
3590 int opt_idx;
3591 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3592 int compatible; /* use Vi default value */
3593{
3594 char_u *varp; /* pointer to variable for current option */
3595 int dvi; /* index in def_val[] */
3596 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003597 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3599
3600 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3601 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003602 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603 {
3604 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3605 if (flags & P_STRING)
3606 {
3607 /* Use set_string_option_direct() for local options to handle
3608 * freeing and allocating the value. */
3609 if (options[opt_idx].indir != PV_NONE)
3610 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003611 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003612 else
3613 {
3614 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3615 free_string_option(*(char_u **)(varp));
3616 *(char_u **)varp = options[opt_idx].def_val[dvi];
3617 options[opt_idx].flags &= ~P_ALLOCED;
3618 }
3619 }
3620 else if (flags & P_NUM)
3621 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003622 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623 win_comp_scroll(curwin);
3624 else
3625 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003626 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 /* May also set global value for local option. */
3628 if (both)
3629 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3630 *(long *)varp;
3631 }
3632 }
3633 else /* P_BOOL */
3634 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003635 /* the cast to long is required for Manx C, long_i is needed for
3636 * MSVC */
3637 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003638#ifdef UNIX
3639 /* 'modeline' defaults to off for root */
3640 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3641 *(int *)varp = FALSE;
3642#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003643 /* May also set global value for local option. */
3644 if (both)
3645 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3646 *(int *)varp;
3647 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003648
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003649 /* The default value is not insecure. */
3650 flagsp = insecure_flag(opt_idx, opt_flags);
3651 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652 }
3653
3654#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003655 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003656#endif
3657}
3658
3659/*
3660 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003661 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662 */
3663 static void
3664set_options_default(opt_flags)
3665 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3666{
3667 int i;
3668#ifdef FEAT_WINDOWS
3669 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003670 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671#endif
3672
3673 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003674 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003675#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003676 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003677 || (TRUE
3678# if defined(FEAT_MBYTE)
3679 && options[i].var != (char_u *)&p_enc
3680# endif
3681# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003682 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003683 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003684# endif
3685 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003686#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003687 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003688 set_option_default(i, opt_flags, p_cp);
3689
3690#ifdef FEAT_WINDOWS
3691 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003692 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003693 win_comp_scroll(wp);
3694#else
3695 win_comp_scroll(curwin);
3696#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003697#ifdef FEAT_CINDENT
3698 parse_cino(curbuf);
3699#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700}
3701
3702/*
3703 * Set the Vi-default value of a string option.
3704 * Used for 'sh', 'backupskip' and 'term'.
3705 */
3706 void
3707set_string_default(name, val)
3708 char *name;
3709 char_u *val;
3710{
3711 char_u *p;
3712 int opt_idx;
3713
3714 p = vim_strsave(val);
3715 if (p != NULL) /* we don't want a NULL */
3716 {
3717 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003718 if (opt_idx >= 0)
3719 {
3720 if (options[opt_idx].flags & P_DEF_ALLOCED)
3721 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3722 options[opt_idx].def_val[VI_DEFAULT] = p;
3723 options[opt_idx].flags |= P_DEF_ALLOCED;
3724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003725 }
3726}
3727
3728/*
3729 * Set the Vi-default value of a number option.
3730 * Used for 'lines' and 'columns'.
3731 */
3732 void
3733set_number_default(name, val)
3734 char *name;
3735 long val;
3736{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003737 int opt_idx;
3738
3739 opt_idx = findoption((char_u *)name);
3740 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003741 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742}
3743
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003744#if defined(EXITFREE) || defined(PROTO)
3745/*
3746 * Free all options.
3747 */
3748 void
3749free_all_options()
3750{
3751 int i;
3752
3753 for (i = 0; !istermoption(&options[i]); i++)
3754 {
3755 if (options[i].indir == PV_NONE)
3756 {
3757 /* global option: free value and default value. */
3758 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3759 free_string_option(*(char_u **)options[i].var);
3760 if (options[i].flags & P_DEF_ALLOCED)
3761 free_string_option(options[i].def_val[VI_DEFAULT]);
3762 }
3763 else if (options[i].var != VAR_WIN
3764 && (options[i].flags & P_STRING))
3765 /* buffer-local option: free global value */
3766 free_string_option(*(char_u **)options[i].var);
3767 }
3768}
3769#endif
3770
3771
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772/*
3773 * Initialize the options, part two: After getting Rows and Columns and
3774 * setting 'term'.
3775 */
3776 void
3777set_init_2()
3778{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003779 int idx;
3780
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781 /*
3782 * 'scroll' defaults to half the window height. Note that this default is
3783 * wrong when the window height changes.
3784 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003785 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003786 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003787 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003788 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 comp_col();
3790
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003791 /*
3792 * 'window' is only for backwards compatibility with Vi.
3793 * Default is Rows - 1.
3794 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003795 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003796 p_window = Rows - 1;
3797 set_number_default("window", Rows - 1);
3798
Bram Moolenaarf740b292006-02-16 22:11:02 +00003799 /* For DOS console the default is always black. */
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003800#if !((defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003801 /*
3802 * If 'background' wasn't set by the user, try guessing the value,
3803 * depending on the terminal name. Only need to check for terminals
3804 * with a dark background, that can handle color.
3805 */
3806 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003807 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3808 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003810 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003811 /* don't mark it as set, when starting the GUI it may be
3812 * changed again */
3813 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003814 }
3815#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003816
3817#ifdef CURSOR_SHAPE
3818 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3819#endif
3820#ifdef FEAT_MOUSESHAPE
3821 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3822#endif
3823#ifdef FEAT_PRINTER
3824 (void)parse_printoptions(); /* parse 'printoptions' default value */
3825#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826}
3827
3828/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003829 * Return "dark" or "light" depending on the kind of terminal.
3830 * This is just guessing! Recognized are:
3831 * "linux" Linux console
3832 * "screen.linux" Linux console with screen
3833 * "cygwin" Cygwin shell
3834 * "putty" Putty program
3835 * We also check the COLORFGBG environment variable, which is set by
3836 * rxvt and derivatives. This variable contains either two or three
3837 * values separated by semicolons; we want the last value in either
3838 * case. If this value is 0-6 or 8, our background is dark.
3839 */
3840 static char_u *
3841term_bg_default()
3842{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003843#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003844 /* DOS console nearly always black */
3845 return (char_u *)"dark";
3846#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003847 char_u *p;
3848
Bram Moolenaarf740b292006-02-16 22:11:02 +00003849 if (STRCMP(T_NAME, "linux") == 0
3850 || STRCMP(T_NAME, "screen.linux") == 0
3851 || STRCMP(T_NAME, "cygwin") == 0
3852 || STRCMP(T_NAME, "putty") == 0
3853 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3854 && (p = vim_strrchr(p, ';')) != NULL
3855 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3856 && p[2] == NUL))
3857 return (char_u *)"dark";
3858 return (char_u *)"light";
3859#endif
3860}
3861
3862/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003863 * Initialize the options, part three: After reading the .vimrc
3864 */
3865 void
3866set_init_3()
3867{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003868#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869/*
3870 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3871 * This is done after other initializations, where 'shell' might have been
3872 * set, but only if they have not been set before.
3873 */
3874 char_u *p;
3875 int idx_srr;
3876 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003877# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878 int idx_sp;
3879 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003880# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003881
3882 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003883 if (idx_srr < 0)
3884 do_srr = FALSE;
3885 else
3886 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003887# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003889 if (idx_sp < 0)
3890 do_sp = FALSE;
3891 else
3892 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003893# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003894 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 if (p != NULL)
3896 {
3897 /*
3898 * Default for p_sp is "| tee", for p_srr is ">".
3899 * For known shells it is changed here to include stderr.
3900 */
3901 if ( fnamecmp(p, "csh") == 0
3902 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003903# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904 || fnamecmp(p, "csh.exe") == 0
3905 || fnamecmp(p, "tcsh.exe") == 0
3906# endif
3907 )
3908 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003909# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910 if (do_sp)
3911 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003912# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003914# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003916# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3918 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003919# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920 if (do_srr)
3921 {
3922 p_srr = (char_u *)">&";
3923 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3924 }
3925 }
3926 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003927 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 if ( fnamecmp(p, "sh") == 0
3929 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003930 || fnamecmp(p, "mksh") == 0
3931 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003933 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003935 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003936# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 || fnamecmp(p, "cmd") == 0
3938 || fnamecmp(p, "sh.exe") == 0
3939 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003940 || fnamecmp(p, "mksh.exe") == 0
3941 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003943 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944 || fnamecmp(p, "bash.exe") == 0
3945 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003947 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003949# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 if (do_sp)
3951 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003952# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003953 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003954# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003956# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003957 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3958 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003959# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960 if (do_srr)
3961 {
3962 p_srr = (char_u *)">%s 2>&1";
3963 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3964 }
3965 }
3966 vim_free(p);
3967 }
3968#endif
3969
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003970#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003972 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3973 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003974 * This is done after other initializations, where 'shell' might have been
3975 * set, but only if they have not been set before. Default for p_shcf is
3976 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3977 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3978 * command.com. And for Win32 we need to set p_sxq instead.
3979 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003980 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 {
3982 int idx3;
3983
3984 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003985 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986 {
3987 p_shcf = (char_u *)"-c";
3988 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3989 }
3990
3991# ifndef DJGPP
3992# ifdef WIN3264
3993 /* Somehow Win32 requires the quotes around the redirection too */
3994 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003995 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003996 {
3997 p_sxq = (char_u *)"\"";
3998 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3999 }
4000# else
4001 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004002 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 {
4004 p_shq = (char_u *)"\"";
4005 options[idx3].def_val[VI_DEFAULT] = p_shq;
4006 }
4007# endif
4008# endif
4009 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004010 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4011 {
4012 int idx3;
4013
4014 /*
4015 * cmd.exe on Windows will strip the first and last double quote given
4016 * on the command line, e.g. most of the time things like:
4017 * cmd /c "my path/to/echo" "my args to echo"
4018 * become:
4019 * my path/to/echo" "my args to echo
4020 * when executed.
4021 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004022 * To avoid this, set shellxquote to surround the command in
4023 * parenthesis. This appears to make most commands work, without
4024 * breaking commands that worked previously, such as
4025 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004026 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004027 idx3 = findoption((char_u *)"sxq");
4028 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4029 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004030 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004031 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4032 }
4033
Bram Moolenaara64ba222012-02-12 23:23:31 +01004034 idx3 = findoption((char_u *)"shcf");
4035 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4036 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004037 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004038 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4039 }
4040 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041#endif
4042
4043#ifdef FEAT_TITLE
4044 set_title_defaults();
4045#endif
4046}
4047
4048#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4049/*
4050 * When 'helplang' is still at its default value, set it to "lang".
4051 * Only the first two characters of "lang" are used.
4052 */
4053 void
4054set_helplang_default(lang)
4055 char_u *lang;
4056{
4057 int idx;
4058
4059 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4060 return;
4061 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004062 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 {
4064 if (options[idx].flags & P_ALLOCED)
4065 free_string_option(p_hlg);
4066 p_hlg = vim_strsave(lang);
4067 if (p_hlg == NULL)
4068 p_hlg = empty_option;
4069 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004070 {
4071 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4072 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4073 {
4074 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4075 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4076 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004078 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 options[idx].flags |= P_ALLOCED;
4080 }
4081}
4082#endif
4083
4084#ifdef FEAT_GUI
4085static char_u *gui_bg_default __ARGS((void));
4086
4087 static char_u *
4088gui_bg_default()
4089{
4090 if (gui_get_lightness(gui.back_pixel) < 127)
4091 return (char_u *)"dark";
4092 return (char_u *)"light";
4093}
4094
4095/*
4096 * Option initializations that can only be done after opening the GUI window.
4097 */
4098 void
4099init_gui_options()
4100{
4101 /* Set the 'background' option according to the lightness of the
4102 * background color, unless the user has set it already. */
4103 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4104 {
4105 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4106 highlight_changed();
4107 }
4108}
4109#endif
4110
4111#ifdef FEAT_TITLE
4112/*
4113 * 'title' and 'icon' only default to true if they have not been set or reset
4114 * in .vimrc and we can read the old value.
4115 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4116 * they can be reset. This reduces startup time when using X on a remote
4117 * machine.
4118 */
4119 void
4120set_title_defaults()
4121{
4122 int idx1;
4123 long val;
4124
4125 /*
4126 * If GUI is (going to be) used, we can always set the window title and
4127 * icon name. Saves a bit of time, because the X11 display server does
4128 * not need to be contacted.
4129 */
4130 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004131 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 {
4133#ifdef FEAT_GUI
4134 if (gui.starting || gui.in_use)
4135 val = TRUE;
4136 else
4137#endif
4138 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004139 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140 p_title = val;
4141 }
4142 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004143 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 {
4145#ifdef FEAT_GUI
4146 if (gui.starting || gui.in_use)
4147 val = TRUE;
4148 else
4149#endif
4150 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004151 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004152 p_icon = val;
4153 }
4154}
4155#endif
4156
4157/*
4158 * Parse 'arg' for option settings.
4159 *
4160 * 'arg' may be IObuff, but only when no errors can be present and option
4161 * does not need to be expanded with option_expand().
4162 * "opt_flags":
4163 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004164 * OPT_GLOBAL for ":setglobal"
4165 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004167 * OPT_WINONLY to only set window-local options
4168 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169 *
4170 * returns FAIL if an error is detected, OK otherwise
4171 */
4172 int
4173do_set(arg, opt_flags)
4174 char_u *arg; /* option string (may be written to!) */
4175 int opt_flags;
4176{
4177 int opt_idx;
4178 char_u *errmsg;
4179 char_u errbuf[80];
4180 char_u *startarg;
4181 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4182 int nextchar; /* next non-white char after option name */
4183 int afterchar; /* character just after option name */
4184 int len;
4185 int i;
4186 long value;
4187 int key;
4188 long_u flags; /* flags for current option */
4189 char_u *varp = NULL; /* pointer to variable for current option */
4190 int did_show = FALSE; /* already showed one value */
4191 int adding; /* "opt+=arg" */
4192 int prepending; /* "opt^=arg" */
4193 int removing; /* "opt-=arg" */
4194 int cp_val = 0;
4195 char_u key_name[2];
4196
4197 if (*arg == NUL)
4198 {
4199 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004200 did_show = TRUE;
4201 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004202 }
4203
4204 while (*arg != NUL) /* loop to process all options */
4205 {
4206 errmsg = NULL;
4207 startarg = arg; /* remember for error message */
4208
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004209 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4210 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004211 {
4212 /*
4213 * ":set all" show all options.
4214 * ":set all&" set all options to their default value.
4215 */
4216 arg += 3;
4217 if (*arg == '&')
4218 {
4219 ++arg;
4220 /* Only for :set command set global value of local options. */
4221 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004222 didset_options();
4223 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004224 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004225 }
4226 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004227 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004228 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004229 did_show = TRUE;
4230 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004231 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004232 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233 {
4234 showoptions(2, opt_flags);
4235 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004236 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004237 arg += 7;
4238 }
4239 else
4240 {
4241 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004242 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004243 {
4244 prefix = 0;
4245 arg += 2;
4246 }
4247 else if (STRNCMP(arg, "inv", 3) == 0)
4248 {
4249 prefix = 2;
4250 arg += 3;
4251 }
4252
4253 /* find end of name */
4254 key = 0;
4255 if (*arg == '<')
4256 {
4257 nextchar = 0;
4258 opt_idx = -1;
4259 /* look out for <t_>;> */
4260 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4261 len = 5;
4262 else
4263 {
4264 len = 1;
4265 while (arg[len] != NUL && arg[len] != '>')
4266 ++len;
4267 }
4268 if (arg[len] != '>')
4269 {
4270 errmsg = e_invarg;
4271 goto skip;
4272 }
4273 arg[len] = NUL; /* put NUL after name */
4274 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4275 opt_idx = findoption(arg + 1);
4276 arg[len++] = '>'; /* restore '>' */
4277 if (opt_idx == -1)
4278 key = find_key_option(arg + 1);
4279 }
4280 else
4281 {
4282 len = 0;
4283 /*
4284 * The two characters after "t_" may not be alphanumeric.
4285 */
4286 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4287 len = 4;
4288 else
4289 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4290 ++len;
4291 nextchar = arg[len];
4292 arg[len] = NUL; /* put NUL after name */
4293 opt_idx = findoption(arg);
4294 arg[len] = nextchar; /* restore nextchar */
4295 if (opt_idx == -1)
4296 key = find_key_option(arg);
4297 }
4298
4299 /* remember character after option name */
4300 afterchar = arg[len];
4301
4302 /* skip white space, allow ":set ai ?" */
4303 while (vim_iswhite(arg[len]))
4304 ++len;
4305
4306 adding = FALSE;
4307 prepending = FALSE;
4308 removing = FALSE;
4309 if (arg[len] != NUL && arg[len + 1] == '=')
4310 {
4311 if (arg[len] == '+')
4312 {
4313 adding = TRUE; /* "+=" */
4314 ++len;
4315 }
4316 else if (arg[len] == '^')
4317 {
4318 prepending = TRUE; /* "^=" */
4319 ++len;
4320 }
4321 else if (arg[len] == '-')
4322 {
4323 removing = TRUE; /* "-=" */
4324 ++len;
4325 }
4326 }
4327 nextchar = arg[len];
4328
4329 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4330 {
4331 errmsg = (char_u *)N_("E518: Unknown option");
4332 goto skip;
4333 }
4334
4335 if (opt_idx >= 0)
4336 {
4337 if (options[opt_idx].var == NULL) /* hidden option: skip */
4338 {
4339 /* Only give an error message when requesting the value of
4340 * a hidden option, ignore setting it. */
4341 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4342 && (!(options[opt_idx].flags & P_BOOL)
4343 || nextchar == '?'))
4344 errmsg = (char_u *)N_("E519: Option not supported");
4345 goto skip;
4346 }
4347
4348 flags = options[opt_idx].flags;
4349 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4350 }
4351 else
4352 {
4353 flags = P_STRING;
4354 if (key < 0)
4355 {
4356 key_name[0] = KEY2TERMCAP0(key);
4357 key_name[1] = KEY2TERMCAP1(key);
4358 }
4359 else
4360 {
4361 key_name[0] = KS_KEY;
4362 key_name[1] = (key & 0xff);
4363 }
4364 }
4365
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004366 /* Skip all options that are not window-local (used when showing
4367 * an already loaded buffer in a window). */
4368 if ((opt_flags & OPT_WINONLY)
4369 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4370 goto skip;
4371
Bram Moolenaara3227e22006-03-08 21:32:40 +00004372 /* Skip all options that are window-local (used for :vimgrep). */
4373 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4374 && options[opt_idx].var == VAR_WIN)
4375 goto skip;
4376
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004377 /* Disallow changing some options from modelines. */
4378 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004380 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004381 {
4382 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4383 goto skip;
4384 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004385#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004386 /* In diff mode some options are overruled. This avoids that
4387 * 'foldmethod' becomes "marker" instead of "diff" and that
4388 * "wrap" gets set. */
4389 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004390 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004391 && (options[opt_idx].indir == PV_FDM
4392 || options[opt_idx].indir == PV_WRAP))
4393 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004394#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004395 }
4396
4397#ifdef HAVE_SANDBOX
4398 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004399 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004400 {
4401 errmsg = (char_u *)_(e_sandbox);
4402 goto skip;
4403 }
4404#endif
4405
4406 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4407 {
4408 arg += len;
4409 cp_val = p_cp;
4410 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4411 {
4412 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4413 {
4414 cp_val = FALSE;
4415 arg += 3;
4416 }
4417 else /* "opt&vi": set to Vi default */
4418 {
4419 cp_val = TRUE;
4420 arg += 2;
4421 }
4422 }
4423 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4424 && arg[1] != NUL && !vim_iswhite(arg[1]))
4425 {
4426 errmsg = e_trailing;
4427 goto skip;
4428 }
4429 }
4430
4431 /*
4432 * allow '=' and ':' as MSDOS command.com allows only one
4433 * '=' character per "set" command line. grrr. (jw)
4434 */
4435 if (nextchar == '?'
4436 || (prefix == 1
4437 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4438 && !(flags & P_BOOL)))
4439 {
4440 /*
4441 * print value
4442 */
4443 if (did_show)
4444 msg_putchar('\n'); /* cursor below last one */
4445 else
4446 {
4447 gotocmdline(TRUE); /* cursor at status line */
4448 did_show = TRUE; /* remember that we did a line */
4449 }
4450 if (opt_idx >= 0)
4451 {
4452 showoneopt(&options[opt_idx], opt_flags);
4453#ifdef FEAT_EVAL
4454 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004455 {
4456 /* Mention where the option was last set. */
4457 if (varp == options[opt_idx].var)
4458 last_set_msg(options[opt_idx].scriptID);
4459 else if ((int)options[opt_idx].indir & PV_WIN)
4460 last_set_msg(curwin->w_p_scriptID[
4461 (int)options[opt_idx].indir & PV_MASK]);
4462 else if ((int)options[opt_idx].indir & PV_BUF)
4463 last_set_msg(curbuf->b_p_scriptID[
4464 (int)options[opt_idx].indir & PV_MASK]);
4465 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004466#endif
4467 }
4468 else
4469 {
4470 char_u *p;
4471
4472 p = find_termcode(key_name);
4473 if (p == NULL)
4474 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004475 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004476 goto skip;
4477 }
4478 else
4479 (void)show_one_termcode(key_name, p, TRUE);
4480 }
4481 if (nextchar != '?'
4482 && nextchar != NUL && !vim_iswhite(afterchar))
4483 errmsg = e_trailing;
4484 }
4485 else
4486 {
4487 if (flags & P_BOOL) /* boolean */
4488 {
4489 if (nextchar == '=' || nextchar == ':')
4490 {
4491 errmsg = e_invarg;
4492 goto skip;
4493 }
4494
4495 /*
4496 * ":set opt!": invert
4497 * ":set opt&": reset to default value
4498 * ":set opt<": reset to global value
4499 */
4500 if (nextchar == '!')
4501 value = *(int *)(varp) ^ 1;
4502 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004503 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004504 ((flags & P_VI_DEF) || cp_val)
4505 ? VI_DEFAULT : VIM_DEFAULT];
4506 else if (nextchar == '<')
4507 {
4508 /* For 'autoread' -1 means to use global value. */
4509 if ((int *)varp == &curbuf->b_p_ar
4510 && opt_flags == OPT_LOCAL)
4511 value = -1;
4512 else
4513 value = *(int *)get_varp_scope(&(options[opt_idx]),
4514 OPT_GLOBAL);
4515 }
4516 else
4517 {
4518 /*
4519 * ":set invopt": invert
4520 * ":set opt" or ":set noopt": set or reset
4521 */
4522 if (nextchar != NUL && !vim_iswhite(afterchar))
4523 {
4524 errmsg = e_trailing;
4525 goto skip;
4526 }
4527 if (prefix == 2) /* inv */
4528 value = *(int *)(varp) ^ 1;
4529 else
4530 value = prefix;
4531 }
4532
4533 errmsg = set_bool_option(opt_idx, varp, (int)value,
4534 opt_flags);
4535 }
4536 else /* numeric or string */
4537 {
4538 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4539 || prefix != 1)
4540 {
4541 errmsg = e_invarg;
4542 goto skip;
4543 }
4544
4545 if (flags & P_NUM) /* numeric */
4546 {
4547 /*
4548 * Different ways to set a number option:
4549 * & set to default value
4550 * < set to global value
4551 * <xx> accept special key codes for 'wildchar'
4552 * c accept any non-digit for 'wildchar'
4553 * [-]0-9 set number
4554 * other error
4555 */
4556 ++arg;
4557 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004558 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004559 ((flags & P_VI_DEF) || cp_val)
4560 ? VI_DEFAULT : VIM_DEFAULT];
4561 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004562 {
4563 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4564 * use the global value. */
4565 if ((long *)varp == &curbuf->b_p_ul
4566 && opt_flags == OPT_LOCAL)
4567 value = NO_LOCAL_UNDOLEVEL;
4568 else
4569 value = *(long *)get_varp_scope(
4570 &(options[opt_idx]), OPT_GLOBAL);
4571 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004572 else if (((long *)varp == &p_wc
4573 || (long *)varp == &p_wcm)
4574 && (*arg == '<'
4575 || *arg == '^'
4576 || ((!arg[1] || vim_iswhite(arg[1]))
4577 && !VIM_ISDIGIT(*arg))))
4578 {
4579 value = string_to_key(arg);
4580 if (value == 0 && (long *)varp != &p_wcm)
4581 {
4582 errmsg = e_invarg;
4583 goto skip;
4584 }
4585 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004586 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4587 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004588 /* Allow negative (for 'undolevels'), octal and
4589 * hex numbers. */
Bram Moolenaar5d1bc782015-07-17 13:03:48 +02004590 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004591 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4592 {
4593 errmsg = e_invarg;
4594 goto skip;
4595 }
4596 }
4597 else
4598 {
4599 errmsg = (char_u *)N_("E521: Number required after =");
4600 goto skip;
4601 }
4602
4603 if (adding)
4604 value = *(long *)varp + value;
4605 if (prepending)
4606 value = *(long *)varp * value;
4607 if (removing)
4608 value = *(long *)varp - value;
4609 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004610 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004611 }
4612 else if (opt_idx >= 0) /* string */
4613 {
4614 char_u *save_arg = NULL;
4615 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004616 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004617 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004618 char_u *origval = NULL;
4619#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4620 char_u *saved_origval = NULL;
4621#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004622 unsigned newlen;
4623 int comma;
4624 int bs;
4625 int new_value_alloced; /* new string option
4626 was allocated */
4627
4628 /* When using ":set opt=val" for a global option
4629 * with a local value the local value will be
4630 * reset, use the global value here. */
4631 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004632 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004633 varp = options[opt_idx].var;
4634
4635 /* The old value is kept until we are sure that the
4636 * new value is valid. */
4637 oldval = *(char_u **)varp;
4638 if (nextchar == '&') /* set to default val */
4639 {
4640 newval = options[opt_idx].def_val[
4641 ((flags & P_VI_DEF) || cp_val)
4642 ? VI_DEFAULT : VIM_DEFAULT];
4643 if ((char_u **)varp == &p_bg)
4644 {
4645 /* guess the value of 'background' */
4646#ifdef FEAT_GUI
4647 if (gui.in_use)
4648 newval = gui_bg_default();
4649 else
4650#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004651 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652 }
4653
4654 /* expand environment variables and ~ (since the
4655 * default value was already expanded, only
4656 * required when an environment variable was set
4657 * later */
4658 if (newval == NULL)
4659 newval = empty_option;
4660 else
4661 {
4662 s = option_expand(opt_idx, newval);
4663 if (s == NULL)
4664 s = newval;
4665 newval = vim_strsave(s);
4666 }
4667 new_value_alloced = TRUE;
4668 }
4669 else if (nextchar == '<') /* set to global val */
4670 {
4671 newval = vim_strsave(*(char_u **)get_varp_scope(
4672 &(options[opt_idx]), OPT_GLOBAL));
4673 new_value_alloced = TRUE;
4674 }
4675 else
4676 {
4677 ++arg; /* jump to after the '=' or ':' */
4678
4679 /*
4680 * Set 'keywordprg' to ":help" if an empty
4681 * value was passed to :set by the user.
4682 * Misuse errbuf[] for the resulting string.
4683 */
4684 if (varp == (char_u *)&p_kp
4685 && (*arg == NUL || *arg == ' '))
4686 {
4687 STRCPY(errbuf, ":help");
4688 save_arg = arg;
4689 arg = errbuf;
4690 }
4691 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004692 * Convert 'backspace' number to string, for
4693 * adding, prepending and removing string.
4694 */
4695 else if (varp == (char_u *)&p_bs
4696 && VIM_ISDIGIT(**(char_u **)varp))
4697 {
4698 i = getdigits((char_u **)varp);
4699 switch (i)
4700 {
4701 case 0:
4702 *(char_u **)varp = empty_option;
4703 break;
4704 case 1:
4705 *(char_u **)varp = vim_strsave(
4706 (char_u *)"indent,eol");
4707 break;
4708 case 2:
4709 *(char_u **)varp = vim_strsave(
4710 (char_u *)"indent,eol,start");
4711 break;
4712 }
4713 vim_free(oldval);
4714 oldval = *(char_u **)varp;
4715 }
4716 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004717 * Convert 'whichwrap' number to string, for
4718 * backwards compatibility with Vim 3.0.
4719 * Misuse errbuf[] for the resulting string.
4720 */
4721 else if (varp == (char_u *)&p_ww
4722 && VIM_ISDIGIT(*arg))
4723 {
4724 *errbuf = NUL;
4725 i = getdigits(&arg);
4726 if (i & 1)
4727 STRCAT(errbuf, "b,");
4728 if (i & 2)
4729 STRCAT(errbuf, "s,");
4730 if (i & 4)
4731 STRCAT(errbuf, "h,l,");
4732 if (i & 8)
4733 STRCAT(errbuf, "<,>,");
4734 if (i & 16)
4735 STRCAT(errbuf, "[,],");
4736 if (*errbuf != NUL) /* remove trailing , */
4737 errbuf[STRLEN(errbuf) - 1] = NUL;
4738 save_arg = arg;
4739 arg = errbuf;
4740 }
4741 /*
4742 * Remove '>' before 'dir' and 'bdir', for
4743 * backwards compatibility with version 3.0
4744 */
4745 else if ( *arg == '>'
4746 && (varp == (char_u *)&p_dir
4747 || varp == (char_u *)&p_bdir))
4748 {
4749 ++arg;
4750 }
4751
4752 /* When setting the local value of a global
4753 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004754 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004755 && (opt_flags & OPT_LOCAL))
4756 origval = *(char_u **)get_varp(
4757 &options[opt_idx]);
4758 else
4759 origval = oldval;
4760
4761 /*
4762 * Copy the new string into allocated memory.
4763 * Can't use set_string_option_direct(), because
4764 * we need to remove the backslashes.
4765 */
4766 /* get a bit too much */
4767 newlen = (unsigned)STRLEN(arg) + 1;
4768 if (adding || prepending || removing)
4769 newlen += (unsigned)STRLEN(origval) + 1;
4770 newval = alloc(newlen);
4771 if (newval == NULL) /* out of mem, don't change */
4772 break;
4773 s = newval;
4774
4775 /*
4776 * Copy the string, skip over escaped chars.
4777 * For MS-DOS and WIN32 backslashes before normal
4778 * file name characters are not removed, and keep
4779 * backslash at start, for "\\machine\path", but
4780 * do remove it for "\\\\machine\\path".
4781 * The reverse is found in ExpandOldSetting().
4782 */
4783 while (*arg && !vim_iswhite(*arg))
4784 {
4785 if (*arg == '\\' && arg[1] != NUL
4786#ifdef BACKSLASH_IN_FILENAME
4787 && !((flags & P_EXPAND)
4788 && vim_isfilec(arg[1])
4789 && (arg[1] != '\\'
4790 || (s == newval
4791 && arg[2] != '\\')))
4792#endif
4793 )
4794 ++arg; /* remove backslash */
4795#ifdef FEAT_MBYTE
4796 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004797 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004798 {
4799 /* copy multibyte char */
4800 mch_memmove(s, arg, (size_t)i);
4801 arg += i;
4802 s += i;
4803 }
4804 else
4805#endif
4806 *s++ = *arg++;
4807 }
4808 *s = NUL;
4809
4810 /*
4811 * Expand environment variables and ~.
4812 * Don't do it when adding without inserting a
4813 * comma.
4814 */
4815 if (!(adding || prepending || removing)
4816 || (flags & P_COMMA))
4817 {
4818 s = option_expand(opt_idx, newval);
4819 if (s != NULL)
4820 {
4821 vim_free(newval);
4822 newlen = (unsigned)STRLEN(s) + 1;
4823 if (adding || prepending || removing)
4824 newlen += (unsigned)STRLEN(origval) + 1;
4825 newval = alloc(newlen);
4826 if (newval == NULL)
4827 break;
4828 STRCPY(newval, s);
4829 }
4830 }
4831
4832 /* locate newval[] in origval[] when removing it
4833 * and when adding to avoid duplicates */
4834 i = 0; /* init for GCC */
4835 if (removing || (flags & P_NODUP))
4836 {
4837 i = (int)STRLEN(newval);
4838 bs = 0;
4839 for (s = origval; *s; ++s)
4840 {
4841 if ((!(flags & P_COMMA)
4842 || s == origval
4843 || (s[-1] == ',' && !(bs & 1)))
4844 && STRNCMP(s, newval, i) == 0
4845 && (!(flags & P_COMMA)
4846 || s[i] == ','
4847 || s[i] == NUL))
4848 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004849 /* Count backslashes. Only a comma with an
4850 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004851 * recognized as a separator */
4852 if (s > origval && s[-1] == '\\')
4853 ++bs;
4854 else
4855 bs = 0;
4856 }
4857
4858 /* do not add if already there */
4859 if ((adding || prepending) && *s)
4860 {
4861 prepending = FALSE;
4862 adding = FALSE;
4863 STRCPY(newval, origval);
4864 }
4865 }
4866
4867 /* concatenate the two strings; add a ',' if
4868 * needed */
4869 if (adding || prepending)
4870 {
4871 comma = ((flags & P_COMMA) && *origval != NUL
4872 && *newval != NUL);
4873 if (adding)
4874 {
4875 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004876 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004877 if (comma && i > 1
4878 && (flags & P_ONECOMMA) == P_ONECOMMA
4879 && origval[i - 1] == ','
4880 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004881 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004882 mch_memmove(newval + i + comma, newval,
4883 STRLEN(newval) + 1);
4884 mch_memmove(newval, origval, (size_t)i);
4885 }
4886 else
4887 {
4888 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004889 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004890 }
4891 if (comma)
4892 newval[i] = ',';
4893 }
4894
4895 /* Remove newval[] from origval[]. (Note: "i" has
4896 * been set above and is used here). */
4897 if (removing)
4898 {
4899 STRCPY(newval, origval);
4900 if (*s)
4901 {
4902 /* may need to remove a comma */
4903 if (flags & P_COMMA)
4904 {
4905 if (s == origval)
4906 {
4907 /* include comma after string */
4908 if (s[i] == ',')
4909 ++i;
4910 }
4911 else
4912 {
4913 /* include comma before string */
4914 --s;
4915 ++i;
4916 }
4917 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004918 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004919 }
4920 }
4921
4922 if (flags & P_FLAGLIST)
4923 {
4924 /* Remove flags that appear twice. */
4925 for (s = newval; *s; ++s)
4926 if ((!(flags & P_COMMA) || *s != ',')
4927 && vim_strchr(s + 1, *s) != NULL)
4928 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004929 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004930 --s;
4931 }
4932 }
4933
4934 if (save_arg != NULL) /* number for 'whichwrap' */
4935 arg = save_arg;
4936 new_value_alloced = TRUE;
4937 }
4938
4939 /* Set the new value. */
4940 *(char_u **)(varp) = newval;
4941
Bram Moolenaar53744302015-07-17 17:38:22 +02004942#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004943 if (!starting
4944# ifdef FEAT_CRYPT
4945 && options[opt_idx].indir != PV_KEY
4946# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004947 && origval != NULL)
4948 /* origval may be freed by
4949 * did_set_string_option(), make a copy. */
4950 saved_origval = vim_strsave(origval);
4951#endif
4952
Bram Moolenaar071d4272004-06-13 20:20:40 +00004953 /* Handle side effects, and set the global value for
4954 * ":set" on local options. */
4955 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4956 new_value_alloced, oldval, errbuf, opt_flags);
4957
4958 /* If error detected, print the error message. */
4959 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004960 {
4961#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4962 vim_free(saved_origval);
4963#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004964 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004965 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004966#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4967 if (saved_origval != NULL)
4968 {
4969 char_u buf_type[7];
4970
4971 sprintf((char *)buf_type, "%s",
4972 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004973 set_vim_var_string(VV_OPTION_NEW,
4974 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004975 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4976 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4977 apply_autocmds(EVENT_OPTIONSET,
4978 (char_u *)options[opt_idx].fullname,
4979 NULL, FALSE, NULL);
4980 reset_v_option_vars();
4981 vim_free(saved_origval);
4982 }
4983#endif
4984
Bram Moolenaar071d4272004-06-13 20:20:40 +00004985 }
4986 else /* key code option */
4987 {
4988 char_u *p;
4989
4990 if (nextchar == '&')
4991 {
4992 if (add_termcap_entry(key_name, TRUE) == FAIL)
4993 errmsg = (char_u *)N_("E522: Not found in termcap");
4994 }
4995 else
4996 {
4997 ++arg; /* jump to after the '=' or ':' */
4998 for (p = arg; *p && !vim_iswhite(*p); ++p)
4999 if (*p == '\\' && p[1] != NUL)
5000 ++p;
5001 nextchar = *p;
5002 *p = NUL;
5003 add_termcode(key_name, arg, FALSE);
5004 *p = nextchar;
5005 }
5006 if (full_screen)
5007 ttest(FALSE);
5008 redraw_all_later(CLEAR);
5009 }
5010 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005011
Bram Moolenaar071d4272004-06-13 20:20:40 +00005012 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005013 did_set_option(opt_idx, opt_flags,
5014 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005015 }
5016
5017skip:
5018 /*
5019 * Advance to next argument.
5020 * - skip until a blank found, taking care of backslashes
5021 * - skip blanks
5022 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5023 */
5024 for (i = 0; i < 2 ; ++i)
5025 {
5026 while (*arg != NUL && !vim_iswhite(*arg))
5027 if (*arg++ == '\\' && *arg != NUL)
5028 ++arg;
5029 arg = skipwhite(arg);
5030 if (*arg != '=')
5031 break;
5032 }
5033 }
5034
5035 if (errmsg != NULL)
5036 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005037 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005038 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005039 if (i + (arg - startarg) < IOSIZE)
5040 {
5041 /* append the argument with the error */
5042 STRCAT(IObuff, ": ");
5043 mch_memmove(IObuff + i, startarg, (arg - startarg));
5044 IObuff[i + (arg - startarg)] = NUL;
5045 }
5046 /* make sure all characters are printable */
5047 trans_characters(IObuff, IOSIZE);
5048
5049 ++no_wait_return; /* wait_return done later */
5050 emsg(IObuff); /* show error highlighted */
5051 --no_wait_return;
5052
5053 return FAIL;
5054 }
5055
5056 arg = skipwhite(arg);
5057 }
5058
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005059theend:
5060 if (silent_mode && did_show)
5061 {
5062 /* After displaying option values in silent mode. */
5063 silent_mode = FALSE;
5064 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5065 msg_putchar('\n');
5066 cursor_on(); /* msg_start() switches it off */
5067 out_flush();
5068 silent_mode = TRUE;
5069 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5070 }
5071
Bram Moolenaar071d4272004-06-13 20:20:40 +00005072 return OK;
5073}
5074
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005075/*
5076 * Call this when an option has been given a new value through a user command.
5077 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5078 */
5079 static void
5080did_set_option(opt_idx, opt_flags, new_value)
5081 int opt_idx;
5082 int opt_flags; /* possibly with OPT_MODELINE */
5083 int new_value; /* value was replaced completely */
5084{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005085 long_u *p;
5086
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005087 options[opt_idx].flags |= P_WAS_SET;
5088
5089 /* When an option is set in the sandbox, from a modeline or in secure mode
5090 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005091 * flag. */
5092 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005093 if (secure
5094#ifdef HAVE_SANDBOX
5095 || sandbox != 0
5096#endif
5097 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005098 *p = *p | P_INSECURE;
5099 else if (new_value)
5100 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005101}
5102
Bram Moolenaar071d4272004-06-13 20:20:40 +00005103 static char_u *
5104illegal_char(errbuf, c)
5105 char_u *errbuf;
5106 int c;
5107{
5108 if (errbuf == NULL)
5109 return (char_u *)"";
5110 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005111 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005112 return errbuf;
5113}
5114
5115/*
5116 * Convert a key name or string into a key value.
5117 * Used for 'wildchar' and 'cedit' options.
5118 */
5119 static int
5120string_to_key(arg)
5121 char_u *arg;
5122{
5123 if (*arg == '<')
5124 return find_key_option(arg + 1);
5125 if (*arg == '^')
5126 return Ctrl_chr(arg[1]);
5127 return *arg;
5128}
5129
5130#ifdef FEAT_CMDWIN
5131/*
5132 * Check value of 'cedit' and set cedit_key.
5133 * Returns NULL if value is OK, error message otherwise.
5134 */
5135 static char_u *
5136check_cedit()
5137{
5138 int n;
5139
5140 if (*p_cedit == NUL)
5141 cedit_key = -1;
5142 else
5143 {
5144 n = string_to_key(p_cedit);
5145 if (vim_isprintc(n))
5146 return e_invarg;
5147 cedit_key = n;
5148 }
5149 return NULL;
5150}
5151#endif
5152
5153#ifdef FEAT_TITLE
5154/*
5155 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5156 * maketitle() to create and display it.
5157 * When switching the title or icon off, call mch_restore_title() to get
5158 * the old value back.
5159 */
5160 static void
5161did_set_title(icon)
5162 int icon; /* Did set icon instead of title */
5163{
5164 if (starting != NO_SCREEN
5165#ifdef FEAT_GUI
5166 && !gui.starting
5167#endif
5168 )
5169 {
5170 maketitle();
5171 if (icon)
5172 {
5173 if (!p_icon)
5174 mch_restore_title(2);
5175 }
5176 else
5177 {
5178 if (!p_title)
5179 mch_restore_title(1);
5180 }
5181 }
5182}
5183#endif
5184
5185/*
5186 * set_options_bin - called when 'bin' changes value.
5187 */
5188 void
5189set_options_bin(oldval, newval, opt_flags)
5190 int oldval;
5191 int newval;
5192 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5193{
5194 /*
5195 * The option values that are changed when 'bin' changes are
5196 * copied when 'bin is set and restored when 'bin' is reset.
5197 */
5198 if (newval)
5199 {
5200 if (!oldval) /* switched on */
5201 {
5202 if (!(opt_flags & OPT_GLOBAL))
5203 {
5204 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5205 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5206 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5207 curbuf->b_p_et_nobin = curbuf->b_p_et;
5208 }
5209 if (!(opt_flags & OPT_LOCAL))
5210 {
5211 p_tw_nobin = p_tw;
5212 p_wm_nobin = p_wm;
5213 p_ml_nobin = p_ml;
5214 p_et_nobin = p_et;
5215 }
5216 }
5217
5218 if (!(opt_flags & OPT_GLOBAL))
5219 {
5220 curbuf->b_p_tw = 0; /* no automatic line wrap */
5221 curbuf->b_p_wm = 0; /* no automatic line wrap */
5222 curbuf->b_p_ml = 0; /* no modelines */
5223 curbuf->b_p_et = 0; /* no expandtab */
5224 }
5225 if (!(opt_flags & OPT_LOCAL))
5226 {
5227 p_tw = 0;
5228 p_wm = 0;
5229 p_ml = FALSE;
5230 p_et = FALSE;
5231 p_bin = TRUE; /* needed when called for the "-b" argument */
5232 }
5233 }
5234 else if (oldval) /* switched off */
5235 {
5236 if (!(opt_flags & OPT_GLOBAL))
5237 {
5238 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5239 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5240 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5241 curbuf->b_p_et = curbuf->b_p_et_nobin;
5242 }
5243 if (!(opt_flags & OPT_LOCAL))
5244 {
5245 p_tw = p_tw_nobin;
5246 p_wm = p_wm_nobin;
5247 p_ml = p_ml_nobin;
5248 p_et = p_et_nobin;
5249 }
5250 }
5251}
5252
5253#ifdef FEAT_VIMINFO
5254/*
5255 * Find the parameter represented by the given character (eg ', :, ", or /),
5256 * and return its associated value in the 'viminfo' string.
5257 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005258 * If the parameter is not specified in the string or there is no following
5259 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005260 */
5261 int
5262get_viminfo_parameter(type)
5263 int type;
5264{
5265 char_u *p;
5266
5267 p = find_viminfo_parameter(type);
5268 if (p != NULL && VIM_ISDIGIT(*p))
5269 return atoi((char *)p);
5270 return -1;
5271}
5272
5273/*
5274 * Find the parameter represented by the given character (eg ''', ':', '"', or
5275 * '/') in the 'viminfo' option and return a pointer to the string after it.
5276 * Return NULL if the parameter is not specified in the string.
5277 */
5278 char_u *
5279find_viminfo_parameter(type)
5280 int type;
5281{
5282 char_u *p;
5283
5284 for (p = p_viminfo; *p; ++p)
5285 {
5286 if (*p == type)
5287 return p + 1;
5288 if (*p == 'n') /* 'n' is always the last one */
5289 break;
5290 p = vim_strchr(p, ','); /* skip until next ',' */
5291 if (p == NULL) /* hit the end without finding parameter */
5292 break;
5293 }
5294 return NULL;
5295}
5296#endif
5297
5298/*
5299 * Expand environment variables for some string options.
5300 * These string options cannot be indirect!
5301 * If "val" is NULL expand the current value of the option.
5302 * Return pointer to NameBuff, or NULL when not expanded.
5303 */
5304 static char_u *
5305option_expand(opt_idx, val)
5306 int opt_idx;
5307 char_u *val;
5308{
5309 /* if option doesn't need expansion nothing to do */
5310 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5311 return NULL;
5312
5313 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5314 * expand_env() would truncate the string. */
5315 if (val != NULL && STRLEN(val) > MAXPATHL)
5316 return NULL;
5317
5318 if (val == NULL)
5319 val = *(char_u **)options[opt_idx].var;
5320
5321 /*
5322 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5323 * Escape spaces when expanding 'tags', they are used to separate file
5324 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005325 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326 */
5327 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005328 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005329#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005330 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5331#endif
5332 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5334 return NULL;
5335
5336 return NameBuff;
5337}
5338
5339/*
5340 * After setting various option values: recompute variables that depend on
5341 * option values.
5342 */
5343 static void
5344didset_options()
5345{
5346 /* initialize the table for 'iskeyword' et.al. */
5347 (void)init_chartab();
5348
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005349#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005350 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005351#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005353 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354#ifdef FEAT_SESSION
5355 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5356 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5357#endif
5358#ifdef FEAT_FOLDING
5359 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5360#endif
5361 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005362 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363#ifdef FEAT_VIRTUALEDIT
5364 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5365#endif
5366#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5367 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5368#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005369#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005370 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005371 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005372 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005373 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005375#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5376 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5377#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005378#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5380#endif
5381#ifdef FEAT_CMDWIN
5382 /* set cedit_key */
5383 (void)check_cedit();
5384#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005385#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005386 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005387#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005388#ifdef FEAT_LINEBREAK
5389 /* initialize the table for 'breakat'. */
5390 fill_breakat_flags();
5391#endif
5392
5393}
5394
5395/*
5396 * More side effects of setting options.
5397 */
5398 static void
5399didset_options2()
5400{
5401 /* Initialize the highlight_attr[] table. */
5402 (void)highlight_changed();
5403
5404 /* Parse default for 'wildmode' */
5405 check_opt_wim();
5406
5407 (void)set_chars_option(&p_lcs);
5408#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5409 /* Parse default for 'fillchars'. */
5410 (void)set_chars_option(&p_fcs);
5411#endif
5412
5413#ifdef FEAT_CLIPBOARD
5414 /* Parse default for 'clipboard' */
5415 (void)check_clipboard_option();
5416#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005417}
5418
5419/*
5420 * Check for string options that are NULL (normally only termcap options).
5421 */
5422 void
5423check_options()
5424{
5425 int opt_idx;
5426
5427 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5428 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5429 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5430}
5431
5432/*
5433 * Check string options in a buffer for NULL value.
5434 */
5435 void
5436check_buf_options(buf)
5437 buf_T *buf;
5438{
5439#if defined(FEAT_QUICKFIX)
5440 check_string_option(&buf->b_p_bh);
5441 check_string_option(&buf->b_p_bt);
5442#endif
5443#ifdef FEAT_MBYTE
5444 check_string_option(&buf->b_p_fenc);
5445#endif
5446 check_string_option(&buf->b_p_ff);
5447#ifdef FEAT_FIND_ID
5448 check_string_option(&buf->b_p_def);
5449 check_string_option(&buf->b_p_inc);
5450# ifdef FEAT_EVAL
5451 check_string_option(&buf->b_p_inex);
5452# endif
5453#endif
5454#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5455 check_string_option(&buf->b_p_inde);
5456 check_string_option(&buf->b_p_indk);
5457#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005458#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5459 check_string_option(&buf->b_p_bexpr);
5460#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005461#if defined(FEAT_CRYPT)
5462 check_string_option(&buf->b_p_cm);
5463#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005464#if defined(FEAT_EVAL)
5465 check_string_option(&buf->b_p_fex);
5466#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005467#ifdef FEAT_CRYPT
5468 check_string_option(&buf->b_p_key);
5469#endif
5470 check_string_option(&buf->b_p_kp);
5471 check_string_option(&buf->b_p_mps);
5472 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005473 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005474 check_string_option(&buf->b_p_isk);
5475#ifdef FEAT_COMMENTS
5476 check_string_option(&buf->b_p_com);
5477#endif
5478#ifdef FEAT_FOLDING
5479 check_string_option(&buf->b_p_cms);
5480#endif
5481 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005482#ifdef FEAT_TEXTOBJ
5483 check_string_option(&buf->b_p_qe);
5484#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005485#ifdef FEAT_SYN_HL
5486 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005487#endif
5488#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005489 check_string_option(&buf->b_s.b_p_spc);
5490 check_string_option(&buf->b_s.b_p_spf);
5491 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492#endif
5493#ifdef FEAT_SEARCHPATH
5494 check_string_option(&buf->b_p_sua);
5495#endif
5496#ifdef FEAT_CINDENT
5497 check_string_option(&buf->b_p_cink);
5498 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005499 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005500#endif
5501#ifdef FEAT_AUTOCMD
5502 check_string_option(&buf->b_p_ft);
5503#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5505 check_string_option(&buf->b_p_cinw);
5506#endif
5507#ifdef FEAT_INS_EXPAND
5508 check_string_option(&buf->b_p_cpt);
5509#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005510#ifdef FEAT_COMPL_FUNC
5511 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005512 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005513#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514#ifdef FEAT_KEYMAP
5515 check_string_option(&buf->b_p_keymap);
5516#endif
5517#ifdef FEAT_QUICKFIX
5518 check_string_option(&buf->b_p_gp);
5519 check_string_option(&buf->b_p_mp);
5520 check_string_option(&buf->b_p_efm);
5521#endif
5522 check_string_option(&buf->b_p_ep);
5523 check_string_option(&buf->b_p_path);
5524 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005525 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005526#ifdef FEAT_INS_EXPAND
5527 check_string_option(&buf->b_p_dict);
5528 check_string_option(&buf->b_p_tsr);
5529#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005530#ifdef FEAT_LISP
5531 check_string_option(&buf->b_p_lw);
5532#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005533 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005534}
5535
5536/*
5537 * Free the string allocated for an option.
5538 * Checks for the string being empty_option. This may happen if we're out of
5539 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5540 * check_options().
5541 * Does NOT check for P_ALLOCED flag!
5542 */
5543 void
5544free_string_option(p)
5545 char_u *p;
5546{
5547 if (p != empty_option)
5548 vim_free(p);
5549}
5550
5551 void
5552clear_string_option(pp)
5553 char_u **pp;
5554{
5555 if (*pp != empty_option)
5556 vim_free(*pp);
5557 *pp = empty_option;
5558}
5559
5560 static void
5561check_string_option(pp)
5562 char_u **pp;
5563{
5564 if (*pp == NULL)
5565 *pp = empty_option;
5566}
5567
5568/*
5569 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5570 */
5571 void
5572set_term_option_alloced(p)
5573 char_u **p;
5574{
5575 int opt_idx;
5576
5577 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5578 if (options[opt_idx].var == (char_u *)p)
5579 {
5580 options[opt_idx].flags |= P_ALLOCED;
5581 return;
5582 }
5583 return; /* cannot happen: didn't find it! */
5584}
5585
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005586#if defined(FEAT_EVAL) || defined(PROTO)
5587/*
5588 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5589 * Return FALSE when it wasn't.
5590 * Return -1 for an unknown option.
5591 */
5592 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005593was_set_insecurely(opt, opt_flags)
5594 char_u *opt;
5595 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005596{
5597 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005598 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005599
5600 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005601 {
5602 flagp = insecure_flag(idx, opt_flags);
5603 return (*flagp & P_INSECURE) != 0;
5604 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005605 EMSG2(_(e_intern2), "was_set_insecurely()");
5606 return -1;
5607}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005608
5609/*
5610 * Get a pointer to the flags used for the P_INSECURE flag of option
5611 * "opt_idx". For some local options a local flags field is used.
5612 */
5613 static long_u *
5614insecure_flag(opt_idx, opt_flags)
5615 int opt_idx;
5616 int opt_flags;
5617{
5618 if (opt_flags & OPT_LOCAL)
5619 switch ((int)options[opt_idx].indir)
5620 {
5621#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005622 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005623#endif
5624#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005625# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005626 case PV_FDE: return &curwin->w_p_fde_flags;
5627 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005628# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005629# ifdef FEAT_BEVAL
5630 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5631# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005632# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005633 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005634# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005635 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005636# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005637 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005638# endif
5639#endif
5640 }
5641
5642 /* Nothing special, return global flags field. */
5643 return &options[opt_idx].flags;
5644}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005645#endif
5646
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005647#ifdef FEAT_TITLE
5648static void redraw_titles __ARGS((void));
5649
5650/*
5651 * Redraw the window title and/or tab page text later.
5652 */
5653static void redraw_titles()
5654{
5655 need_maketitle = TRUE;
5656# ifdef FEAT_WINDOWS
5657 redraw_tabline = TRUE;
5658# endif
5659}
5660#endif
5661
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662/*
5663 * Set a string option to a new value (without checking the effect).
5664 * The string is copied into allocated memory.
5665 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005666 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005667 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668 */
5669 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005670set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671 char_u *name;
5672 int opt_idx;
5673 char_u *val;
5674 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005675 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676{
5677 char_u *s;
5678 char_u **varp;
5679 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005680 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681
Bram Moolenaar89d40322006-08-29 15:30:07 +00005682 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005684 idx = findoption(name);
5685 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005686 {
5687 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005688 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005690 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691 }
5692
Bram Moolenaar89d40322006-08-29 15:30:07 +00005693 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694 return;
5695
5696 s = vim_strsave(val);
5697 if (s != NULL)
5698 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005699 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005700 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005701 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702 free_string_option(*varp);
5703 *varp = s;
5704
5705 /* For buffer/window local option may also set the global value. */
5706 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005707 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708
Bram Moolenaar89d40322006-08-29 15:30:07 +00005709 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710
5711 /* When setting both values of a global option with a local value,
5712 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005713 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005714 {
5715 free_string_option(*varp);
5716 *varp = empty_option;
5717 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005718# ifdef FEAT_EVAL
5719 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005720 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005721 set_sid == 0 ? current_SID : set_sid);
5722# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005723 }
5724}
5725
5726/*
5727 * Set global value for string option when it's a local option.
5728 */
5729 static void
5730set_string_option_global(opt_idx, varp)
5731 int opt_idx; /* option index */
5732 char_u **varp; /* pointer to option variable */
5733{
5734 char_u **p, *s;
5735
5736 /* the global value is always allocated */
5737 if (options[opt_idx].var == VAR_WIN)
5738 p = (char_u **)GLOBAL_WO(varp);
5739 else
5740 p = (char_u **)options[opt_idx].var;
5741 if (options[opt_idx].indir != PV_NONE
5742 && p != varp
5743 && (s = vim_strsave(*varp)) != NULL)
5744 {
5745 free_string_option(*p);
5746 *p = s;
5747 }
5748}
5749
5750/*
5751 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005752 *
5753 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005755 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005756set_string_option(opt_idx, value, opt_flags)
5757 int opt_idx;
5758 char_u *value;
5759 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5760{
5761 char_u *s;
5762 char_u **varp;
5763 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005764#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5765 char_u *saved_oldval = NULL;
5766#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005767 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005768
5769 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005770 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005771
5772 s = vim_strsave(value);
5773 if (s != NULL)
5774 {
5775 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5776 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005777 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005778 ? OPT_GLOBAL : OPT_LOCAL)
5779 : opt_flags);
5780 oldval = *varp;
5781 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005782
5783#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005784 if (!starting
5785# ifdef FEAT_CRYPT
5786 && options[opt_idx].indir != PV_KEY
5787# endif
5788 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005789 saved_oldval = vim_strsave(oldval);
5790#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005791 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5792 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005793 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005794
5795 /* call autocomamnd after handling side effects */
5796#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5797 if (saved_oldval != NULL)
5798 {
5799 char_u buf_type[7];
5800 sprintf((char *)buf_type, "%s",
5801 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005802 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5803 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005804 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5805 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5806 reset_v_option_vars();
5807 vim_free(saved_oldval);
5808 }
5809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005810 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005811 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005812}
5813
5814/*
5815 * Handle string options that need some action to perform when changed.
5816 * Returns NULL for success, or an error message for an error.
5817 */
5818 static char_u *
5819did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5820 opt_flags)
5821 int opt_idx; /* index in options[] table */
5822 char_u **varp; /* pointer to the option variable */
5823 int new_value_alloced; /* new value was allocated */
5824 char_u *oldval; /* previous value of the option */
5825 char_u *errbuf; /* buffer for errors, or NULL */
5826 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5827{
5828 char_u *errmsg = NULL;
5829 char_u *s, *p;
5830 int did_chartab = FALSE;
5831 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005832 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005833#ifdef FEAT_GUI
5834 /* set when changing an option that only requires a redraw in the GUI */
5835 int redraw_gui_only = FALSE;
5836#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005837
5838 /* Get the global option to compare with, otherwise we would have to check
5839 * two values for all local options. */
5840 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5841
5842 /* Disallow changing some options from secure mode */
5843 if ((secure
5844#ifdef HAVE_SANDBOX
5845 || sandbox != 0
5846#endif
5847 ) && (options[opt_idx].flags & P_SECURE))
5848 {
5849 errmsg = e_secure;
5850 }
5851
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005852 /* Check for a "normal" file name in some options. Disallow a path
5853 * separator (slash and/or backslash), wildcards and characters that are
5854 * often illegal in a file name. */
5855 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005856 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005857 {
5858 errmsg = e_invarg;
5859 }
5860
Bram Moolenaar071d4272004-06-13 20:20:40 +00005861 /* 'term' */
5862 else if (varp == &T_NAME)
5863 {
5864 if (T_NAME[0] == NUL)
5865 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5866#ifdef FEAT_GUI
5867 if (gui.in_use)
5868 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5869 else if (term_is_gui(T_NAME))
5870 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5871#endif
5872 else if (set_termname(T_NAME) == FAIL)
5873 errmsg = (char_u *)N_("E522: Not found in termcap");
5874 else
5875 /* Screen colors may have changed. */
5876 redraw_later_clear();
5877 }
5878
5879 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005880 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005881 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005882 char_u *bkc = p_bkc;
5883 unsigned int *flags = &bkc_flags;
5884
5885 if (opt_flags & OPT_LOCAL)
5886 {
5887 bkc = curbuf->b_p_bkc;
5888 flags = &curbuf->b_bkc_flags;
5889 }
5890
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005891 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5892 /* make the local value empty: use the global value */
5893 *flags = 0;
5894 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005895 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005896 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5897 errmsg = e_invarg;
5898 if ((((int)*flags & BKC_AUTO) != 0)
5899 + (((int)*flags & BKC_YES) != 0)
5900 + (((int)*flags & BKC_NO) != 0) != 1)
5901 {
5902 /* Must have exactly one of "auto", "yes" and "no". */
5903 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5904 errmsg = e_invarg;
5905 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906 }
5907 }
5908
5909 /* 'backupext' and 'patchmode' */
5910 else if (varp == &p_bex || varp == &p_pm)
5911 {
5912 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5913 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5914 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5915 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005916#ifdef FEAT_LINEBREAK
5917 /* 'breakindentopt' */
5918 else if (varp == &curwin->w_p_briopt)
5919 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005920 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005921 errmsg = e_invarg;
5922 }
5923#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924
5925 /*
5926 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5927 * If the new option is invalid, use old value. 'lisp' option: refill
5928 * chartab[] for '-' char
5929 */
5930 else if ( varp == &p_isi
5931 || varp == &(curbuf->b_p_isk)
5932 || varp == &p_isp
5933 || varp == &p_isf)
5934 {
5935 if (init_chartab() == FAIL)
5936 {
5937 did_chartab = TRUE; /* need to restore it below */
5938 errmsg = e_invarg; /* error in value */
5939 }
5940 }
5941
5942 /* 'helpfile' */
5943 else if (varp == &p_hf)
5944 {
5945 /* May compute new values for $VIM and $VIMRUNTIME */
5946 if (didset_vim)
5947 {
5948 vim_setenv((char_u *)"VIM", (char_u *)"");
5949 didset_vim = FALSE;
5950 }
5951 if (didset_vimruntime)
5952 {
5953 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5954 didset_vimruntime = FALSE;
5955 }
5956 }
5957
Bram Moolenaar1a384422010-07-14 19:53:30 +02005958#ifdef FEAT_SYN_HL
5959 /* 'colorcolumn' */
5960 else if (varp == &curwin->w_p_cc)
5961 errmsg = check_colorcolumn(curwin);
5962#endif
5963
Bram Moolenaar071d4272004-06-13 20:20:40 +00005964#ifdef FEAT_MULTI_LANG
5965 /* 'helplang' */
5966 else if (varp == &p_hlg)
5967 {
5968 /* Check for "", "ab", "ab,cd", etc. */
5969 for (s = p_hlg; *s != NUL; s += 3)
5970 {
5971 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5972 {
5973 errmsg = e_invarg;
5974 break;
5975 }
5976 if (s[2] == NUL)
5977 break;
5978 }
5979 }
5980#endif
5981
5982 /* 'highlight' */
5983 else if (varp == &p_hl)
5984 {
5985 if (highlight_changed() == FAIL)
5986 errmsg = e_invarg; /* invalid flags */
5987 }
5988
5989 /* 'nrformats' */
5990 else if (gvarp == &p_nf)
5991 {
5992 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5993 errmsg = e_invarg;
5994 }
5995
5996#ifdef FEAT_SESSION
5997 /* 'sessionoptions' */
5998 else if (varp == &p_ssop)
5999 {
6000 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6001 errmsg = e_invarg;
6002 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6003 {
6004 /* Don't allow both "sesdir" and "curdir". */
6005 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6006 errmsg = e_invarg;
6007 }
6008 }
6009 /* 'viewoptions' */
6010 else if (varp == &p_vop)
6011 {
6012 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6013 errmsg = e_invarg;
6014 }
6015#endif
6016
6017 /* 'scrollopt' */
6018#ifdef FEAT_SCROLLBIND
6019 else if (varp == &p_sbo)
6020 {
6021 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6022 errmsg = e_invarg;
6023 }
6024#endif
6025
6026 /* 'ambiwidth' */
6027#ifdef FEAT_MBYTE
6028 else if (varp == &p_ambw)
6029 {
6030 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6031 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006032 else if (set_chars_option(&p_lcs) != NULL)
6033 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6034# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6035 else if (set_chars_option(&p_fcs) != NULL)
6036 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6037# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006038 }
6039#endif
6040
6041 /* 'background' */
6042 else if (varp == &p_bg)
6043 {
6044 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6045 {
6046#ifdef FEAT_EVAL
6047 int dark = (*p_bg == 'd');
6048#endif
6049
6050 init_highlight(FALSE, FALSE);
6051
6052#ifdef FEAT_EVAL
6053 if (dark != (*p_bg == 'd')
6054 && get_var_value((char_u *)"g:colors_name") != NULL)
6055 {
6056 /* The color scheme must have set 'background' back to another
6057 * value, that's not what we want here. Disable the color
6058 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006059 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006060 free_string_option(p_bg);
6061 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6062 check_string_option(&p_bg);
6063 init_highlight(FALSE, FALSE);
6064 }
6065#endif
6066 }
6067 else
6068 errmsg = e_invarg;
6069 }
6070
6071 /* 'wildmode' */
6072 else if (varp == &p_wim)
6073 {
6074 if (check_opt_wim() == FAIL)
6075 errmsg = e_invarg;
6076 }
6077
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006078#ifdef FEAT_CMDL_COMPL
6079 /* 'wildoptions' */
6080 else if (varp == &p_wop)
6081 {
6082 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6083 errmsg = e_invarg;
6084 }
6085#endif
6086
Bram Moolenaar071d4272004-06-13 20:20:40 +00006087#ifdef FEAT_WAK
6088 /* 'winaltkeys' */
6089 else if (varp == &p_wak)
6090 {
6091 if (*p_wak == NUL
6092 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6093 errmsg = e_invarg;
6094# ifdef FEAT_MENU
6095# ifdef FEAT_GUI_MOTIF
6096 else if (gui.in_use)
6097 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6098# else
6099# ifdef FEAT_GUI_GTK
6100 else if (gui.in_use)
6101 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6102# endif
6103# endif
6104# endif
6105 }
6106#endif
6107
6108#ifdef FEAT_AUTOCMD
6109 /* 'eventignore' */
6110 else if (varp == &p_ei)
6111 {
6112 if (check_ei() == FAIL)
6113 errmsg = e_invarg;
6114 }
6115#endif
6116
6117#ifdef FEAT_MBYTE
6118 /* 'encoding' and 'fileencoding' */
6119 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6120 {
6121 if (gvarp == &p_fenc)
6122 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006123 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 errmsg = e_modifiable;
6125 else if (vim_strchr(*varp, ',') != NULL)
6126 /* No comma allowed in 'fileencoding'; catches confusing it
6127 * with 'fileencodings'. */
6128 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006129 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006130 {
6131# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006132 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006133 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006135 /* Add 'fileencoding' to the swap file. */
6136 ml_setflags(curbuf);
6137 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138 }
6139 if (errmsg == NULL)
6140 {
6141 /* canonize the value, so that STRCMP() can be used on it */
6142 p = enc_canonize(*varp);
6143 if (p != NULL)
6144 {
6145 vim_free(*varp);
6146 *varp = p;
6147 }
6148 if (varp == &p_enc)
6149 {
6150 errmsg = mb_init();
6151# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006152 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006153# endif
6154 }
6155 }
6156
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006157# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006158 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6159 {
6160 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6161 if (STRCMP(p_tenc, "utf-8") != 0)
6162 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6163 }
6164# endif
6165
6166 if (errmsg == NULL)
6167 {
6168# ifdef FEAT_KEYMAP
6169 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6170 * (with another encoding). */
6171 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6172 (void)keymap_init();
6173# endif
6174
6175 /* When 'termencoding' is not empty and 'encoding' changes or when
6176 * 'termencoding' changes, need to setup for keyboard input and
6177 * display output conversion. */
6178 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6179 {
6180 convert_setup(&input_conv, p_tenc, p_enc);
6181 convert_setup(&output_conv, p_enc, p_tenc);
6182 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006183
6184# if defined(WIN3264) && defined(FEAT_MBYTE)
6185 /* $HOME may have characters in active code page. */
6186 if (varp == &p_enc)
6187 init_homedir();
6188# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006189 }
6190 }
6191#endif
6192
6193#if defined(FEAT_POSTSCRIPT)
6194 else if (varp == &p_penc)
6195 {
6196 /* Canonize printencoding if VIM standard one */
6197 p = enc_canonize(p_penc);
6198 if (p != NULL)
6199 {
6200 vim_free(p_penc);
6201 p_penc = p;
6202 }
6203 else
6204 {
6205 /* Ensure lower case and '-' for '_' */
6206 for (s = p_penc; *s != NUL; s++)
6207 {
6208 if (*s == '_')
6209 *s = '-';
6210 else
6211 *s = TOLOWER_ASC(*s);
6212 }
6213 }
6214 }
6215#endif
6216
Bram Moolenaar9372a112005-12-06 19:59:18 +00006217#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006218 else if (varp == &p_imak)
6219 {
6220 if (gui.in_use && !im_xim_isvalid_imactivate())
6221 errmsg = e_invarg;
6222 }
6223#endif
6224
6225#ifdef FEAT_KEYMAP
6226 else if (varp == &curbuf->b_p_keymap)
6227 {
6228 /* load or unload key mapping tables */
6229 errmsg = keymap_init();
6230
Bram Moolenaarfab06232009-03-04 03:13:35 +00006231 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006232 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006233 if (*curbuf->b_p_keymap != NUL)
6234 {
6235 /* Installed a new keymap, switch on using it. */
6236 curbuf->b_p_iminsert = B_IMODE_LMAP;
6237 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6238 curbuf->b_p_imsearch = B_IMODE_LMAP;
6239 }
6240 else
6241 {
6242 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6243 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6244 curbuf->b_p_iminsert = B_IMODE_NONE;
6245 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6246 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6247 }
6248 if ((opt_flags & OPT_LOCAL) == 0)
6249 {
6250 set_iminsert_global();
6251 set_imsearch_global();
6252 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006253# ifdef FEAT_WINDOWS
6254 status_redraw_curbuf();
6255# endif
6256 }
6257 }
6258#endif
6259
6260 /* 'fileformat' */
6261 else if (gvarp == &p_ff)
6262 {
6263 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6264 errmsg = e_modifiable;
6265 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6266 errmsg = e_invarg;
6267 else
6268 {
6269 /* may also change 'textmode' */
6270 if (get_fileformat(curbuf) == EOL_DOS)
6271 curbuf->b_p_tx = TRUE;
6272 else
6273 curbuf->b_p_tx = FALSE;
6274#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006275 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006276#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006277 /* update flag in swap file */
6278 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006279 /* Redraw needed when switching to/from "mac": a CR in the text
6280 * will be displayed differently. */
6281 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6282 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006283 }
6284 }
6285
6286 /* 'fileformats' */
6287 else if (varp == &p_ffs)
6288 {
6289 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6290 errmsg = e_invarg;
6291 else
6292 {
6293 /* also change 'textauto' */
6294 if (*p_ffs == NUL)
6295 p_ta = FALSE;
6296 else
6297 p_ta = TRUE;
6298 }
6299 }
6300
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006301#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006302 /* 'cryptkey' */
6303 else if (gvarp == &p_key)
6304 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006305# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006306 /* Make sure the ":set" command doesn't show the new value in the
6307 * history. */
6308 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006309# endif
6310 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6311 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006312 ml_set_crypt_key(curbuf, oldval,
6313 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006314 }
6315
6316 else if (gvarp == &p_cm)
6317 {
6318 if (opt_flags & OPT_LOCAL)
6319 p = curbuf->b_p_cm;
6320 else
6321 p = p_cm;
6322 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6323 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006324 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006325 errmsg = e_invarg;
6326 else
6327 {
6328 /* When setting the global value to empty, make it "zip". */
6329 if (*p_cm == NUL)
6330 {
6331 if (new_value_alloced)
6332 free_string_option(p_cm);
6333 p_cm = vim_strsave((char_u *)"zip");
6334 new_value_alloced = TRUE;
6335 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006336 /* When using ":set cm=name" the local value is going to be empty.
6337 * Do that here, otherwise the crypt functions will still use the
6338 * local value. */
6339 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6340 {
6341 free_string_option(curbuf->b_p_cm);
6342 curbuf->b_p_cm = empty_option;
6343 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006344
6345 /* Need to update the swapfile when the effective method changed.
6346 * Set "s" to the effective old value, "p" to the effective new
6347 * method and compare. */
6348 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6349 s = p_cm; /* was previously using the global value */
6350 else
6351 s = oldval;
6352 if (*curbuf->b_p_cm == NUL)
6353 p = p_cm; /* is now using the global value */
6354 else
6355 p = curbuf->b_p_cm;
6356 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006357 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006358
6359 /* If the global value changes need to update the swapfile for all
6360 * buffers using that value. */
6361 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6362 {
6363 buf_T *buf;
6364
6365 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6366 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006367 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006368 }
6369 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006370 }
6371#endif
6372
6373 /* 'matchpairs' */
6374 else if (gvarp == &p_mps)
6375 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006376#ifdef FEAT_MBYTE
6377 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006378 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006379 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006381 int x2 = -1;
6382 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006383
6384 if (*p != NUL)
6385 p += mb_ptr2len(p);
6386 if (*p != NUL)
6387 x2 = *p++;
6388 if (*p != NUL)
6389 {
6390 x3 = mb_ptr2char(p);
6391 p += mb_ptr2len(p);
6392 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006393 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006394 {
6395 errmsg = e_invarg;
6396 break;
6397 }
6398 if (*p == NUL)
6399 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006400 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006401 }
6402 else
6403#endif
6404 {
6405 /* Check for "x:y,x:y" */
6406 for (p = *varp; *p != NUL; p += 4)
6407 {
6408 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6409 {
6410 errmsg = e_invarg;
6411 break;
6412 }
6413 if (p[3] == NUL)
6414 break;
6415 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006416 }
6417 }
6418
6419#ifdef FEAT_COMMENTS
6420 /* 'comments' */
6421 else if (gvarp == &p_com)
6422 {
6423 for (s = *varp; *s; )
6424 {
6425 while (*s && *s != ':')
6426 {
6427 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6428 && !VIM_ISDIGIT(*s) && *s != '-')
6429 {
6430 errmsg = illegal_char(errbuf, *s);
6431 break;
6432 }
6433 ++s;
6434 }
6435 if (*s++ == NUL)
6436 errmsg = (char_u *)N_("E524: Missing colon");
6437 else if (*s == ',' || *s == NUL)
6438 errmsg = (char_u *)N_("E525: Zero length string");
6439 if (errmsg != NULL)
6440 break;
6441 while (*s && *s != ',')
6442 {
6443 if (*s == '\\' && s[1] != NUL)
6444 ++s;
6445 ++s;
6446 }
6447 s = skip_to_option_part(s);
6448 }
6449 }
6450#endif
6451
6452 /* 'listchars' */
6453 else if (varp == &p_lcs)
6454 {
6455 errmsg = set_chars_option(varp);
6456 }
6457
6458#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6459 /* 'fillchars' */
6460 else if (varp == &p_fcs)
6461 {
6462 errmsg = set_chars_option(varp);
6463 }
6464#endif
6465
6466#ifdef FEAT_CMDWIN
6467 /* 'cedit' */
6468 else if (varp == &p_cedit)
6469 {
6470 errmsg = check_cedit();
6471 }
6472#endif
6473
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006474 /* 'verbosefile' */
6475 else if (varp == &p_vfile)
6476 {
6477 verbose_stop();
6478 if (*p_vfile != NUL && verbose_open() == FAIL)
6479 errmsg = e_invarg;
6480 }
6481
Bram Moolenaar071d4272004-06-13 20:20:40 +00006482#ifdef FEAT_VIMINFO
6483 /* 'viminfo' */
6484 else if (varp == &p_viminfo)
6485 {
6486 for (s = p_viminfo; *s;)
6487 {
6488 /* Check it's a valid character */
6489 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6490 {
6491 errmsg = illegal_char(errbuf, *s);
6492 break;
6493 }
6494 if (*s == 'n') /* name is always last one */
6495 {
6496 break;
6497 }
6498 else if (*s == 'r') /* skip until next ',' */
6499 {
6500 while (*++s && *s != ',')
6501 ;
6502 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006503 else if (*s == '%')
6504 {
6505 /* optional number */
6506 while (vim_isdigit(*++s))
6507 ;
6508 }
6509 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006510 ++s; /* no extra chars */
6511 else /* must have a number */
6512 {
6513 while (vim_isdigit(*++s))
6514 ;
6515
6516 if (!VIM_ISDIGIT(*(s - 1)))
6517 {
6518 if (errbuf != NULL)
6519 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006520 sprintf((char *)errbuf,
6521 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522 transchar_byte(*(s - 1)));
6523 errmsg = errbuf;
6524 }
6525 else
6526 errmsg = (char_u *)"";
6527 break;
6528 }
6529 }
6530 if (*s == ',')
6531 ++s;
6532 else if (*s)
6533 {
6534 if (errbuf != NULL)
6535 errmsg = (char_u *)N_("E527: Missing comma");
6536 else
6537 errmsg = (char_u *)"";
6538 break;
6539 }
6540 }
6541 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6542 errmsg = (char_u *)N_("E528: Must specify a ' value");
6543 }
6544#endif /* FEAT_VIMINFO */
6545
6546 /* terminal options */
6547 else if (istermoption(&options[opt_idx]) && full_screen)
6548 {
6549 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6550 if (varp == &T_CCO)
6551 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006552 int colors = atoi((char *)T_CCO);
6553
6554 /* Only reinitialize colors if t_Co value has really changed to
6555 * avoid expensive reload of colorscheme if t_Co is set to the
6556 * same value multiple times. */
6557 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006558 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006559 t_colors = colors;
6560 if (t_colors <= 1)
6561 {
6562 if (new_value_alloced)
6563 vim_free(T_CCO);
6564 T_CCO = empty_option;
6565 }
6566 /* We now have a different color setup, initialize it again. */
6567 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006569 }
6570 ttest(FALSE);
6571 if (varp == &T_ME)
6572 {
6573 out_str(T_ME);
6574 redraw_later(CLEAR);
6575#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6576 /* Since t_me has been set, this probably means that the user
6577 * wants to use this as default colors. Need to reset default
6578 * background/foreground colors. */
6579 mch_set_normal_colors();
6580#endif
6581 }
6582 }
6583
6584#ifdef FEAT_LINEBREAK
6585 /* 'showbreak' */
6586 else if (varp == &p_sbr)
6587 {
6588 for (s = p_sbr; *s; )
6589 {
6590 if (ptr2cells(s) != 1)
6591 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006592 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593 }
6594 }
6595#endif
6596
6597#ifdef FEAT_GUI
6598 /* 'guifont' */
6599 else if (varp == &p_guifont)
6600 {
6601 if (gui.in_use)
6602 {
6603 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006604# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006605 /*
6606 * Put up a font dialog and let the user select a new value.
6607 * If this is cancelled go back to the old value but don't
6608 * give an error message.
6609 */
6610 if (STRCMP(p, "*") == 0)
6611 {
6612 p = gui_mch_font_dialog(oldval);
6613
6614 if (new_value_alloced)
6615 free_string_option(p_guifont);
6616
6617 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6618 new_value_alloced = TRUE;
6619 }
6620# endif
6621 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6622 {
6623# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6624 if (STRCMP(p_guifont, "*") == 0)
6625 {
6626 /* Dialog was cancelled: Keep the old value without giving
6627 * an error message. */
6628 if (new_value_alloced)
6629 free_string_option(p_guifont);
6630 p_guifont = vim_strsave(oldval);
6631 new_value_alloced = TRUE;
6632 }
6633 else
6634# endif
6635 errmsg = (char_u *)N_("E596: Invalid font(s)");
6636 }
6637 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006638 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006639 }
6640# ifdef FEAT_XFONTSET
6641 else if (varp == &p_guifontset)
6642 {
6643 if (STRCMP(p_guifontset, "*") == 0)
6644 errmsg = (char_u *)N_("E597: can't select fontset");
6645 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6646 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006647 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006648 }
6649# endif
6650# ifdef FEAT_MBYTE
6651 else if (varp == &p_guifontwide)
6652 {
6653 if (STRCMP(p_guifontwide, "*") == 0)
6654 errmsg = (char_u *)N_("E533: can't select wide font");
6655 else if (gui_get_wide_font() == FAIL)
6656 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006657 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006658 }
6659# endif
6660#endif
6661
6662#ifdef CURSOR_SHAPE
6663 /* 'guicursor' */
6664 else if (varp == &p_guicursor)
6665 errmsg = parse_shape_opt(SHAPE_CURSOR);
6666#endif
6667
6668#ifdef FEAT_MOUSESHAPE
6669 /* 'mouseshape' */
6670 else if (varp == &p_mouseshape)
6671 {
6672 errmsg = parse_shape_opt(SHAPE_MOUSE);
6673 update_mouseshape(-1);
6674 }
6675#endif
6676
6677#ifdef FEAT_PRINTER
6678 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006679 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006680# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006681 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006682 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006683# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006684#endif
6685
6686#ifdef FEAT_LANGMAP
6687 /* 'langmap' */
6688 else if (varp == &p_langmap)
6689 langmap_set();
6690#endif
6691
6692#ifdef FEAT_LINEBREAK
6693 /* 'breakat' */
6694 else if (varp == &p_breakat)
6695 fill_breakat_flags();
6696#endif
6697
6698#ifdef FEAT_TITLE
6699 /* 'titlestring' and 'iconstring' */
6700 else if (varp == &p_titlestring || varp == &p_iconstring)
6701 {
6702# ifdef FEAT_STL_OPT
6703 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6704
6705 /* NULL => statusline syntax */
6706 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6707 stl_syntax |= flagval;
6708 else
6709 stl_syntax &= ~flagval;
6710# endif
6711 did_set_title(varp == &p_iconstring);
6712
6713 }
6714#endif
6715
6716#ifdef FEAT_GUI
6717 /* 'guioptions' */
6718 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006719 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006720 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006721 redraw_gui_only = TRUE;
6722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006723#endif
6724
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006725#if defined(FEAT_GUI_TABLINE)
6726 /* 'guitablabel' */
6727 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006728 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006729 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006730 redraw_gui_only = TRUE;
6731 }
6732 /* 'guitabtooltip' */
6733 else if (varp == &p_gtt)
6734 {
6735 redraw_gui_only = TRUE;
6736 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006737#endif
6738
Bram Moolenaar071d4272004-06-13 20:20:40 +00006739#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6740 /* 'ttymouse' */
6741 else if (varp == &p_ttym)
6742 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006743 /* Switch the mouse off before changing the escape sequences used for
6744 * that. */
6745 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006746 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6747 errmsg = e_invarg;
6748 else
6749 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006750 if (termcap_active)
6751 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006752 }
6753#endif
6754
Bram Moolenaar071d4272004-06-13 20:20:40 +00006755 /* 'selection' */
6756 else if (varp == &p_sel)
6757 {
6758 if (*p_sel == NUL
6759 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6760 errmsg = e_invarg;
6761 }
6762
6763 /* 'selectmode' */
6764 else if (varp == &p_slm)
6765 {
6766 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6767 errmsg = e_invarg;
6768 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006769
6770#ifdef FEAT_BROWSE
6771 /* 'browsedir' */
6772 else if (varp == &p_bsdir)
6773 {
6774 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6775 && !mch_isdir(p_bsdir))
6776 errmsg = e_invarg;
6777 }
6778#endif
6779
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780 /* 'keymodel' */
6781 else if (varp == &p_km)
6782 {
6783 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6784 errmsg = e_invarg;
6785 else
6786 {
6787 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6788 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6789 }
6790 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006791
6792 /* 'mousemodel' */
6793 else if (varp == &p_mousem)
6794 {
6795 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6796 errmsg = e_invarg;
6797#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6798 else if (*p_mousem != *oldval)
6799 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6800 * to create or delete the popup menus. */
6801 gui_motif_update_mousemodel(root_menu);
6802#endif
6803 }
6804
6805 /* 'switchbuf' */
6806 else if (varp == &p_swb)
6807 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006808 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006809 errmsg = e_invarg;
6810 }
6811
6812 /* 'debug' */
6813 else if (varp == &p_debug)
6814 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006815 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006816 errmsg = e_invarg;
6817 }
6818
6819 /* 'display' */
6820 else if (varp == &p_dy)
6821 {
6822 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6823 errmsg = e_invarg;
6824 else
6825 (void)init_chartab();
6826
6827 }
6828
6829#ifdef FEAT_VERTSPLIT
6830 /* 'eadirection' */
6831 else if (varp == &p_ead)
6832 {
6833 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6834 errmsg = e_invarg;
6835 }
6836#endif
6837
6838#ifdef FEAT_CLIPBOARD
6839 /* 'clipboard' */
6840 else if (varp == &p_cb)
6841 errmsg = check_clipboard_option();
6842#endif
6843
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006844#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006845 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6846 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006847 else if (varp == &(curwin->w_s->b_p_spl)
6848 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006849 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006850 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006851 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006852 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006853 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006854 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006855 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006856 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006857 /* 'spellsuggest' */
6858 else if (varp == &p_sps)
6859 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006860 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006861 errmsg = e_invarg;
6862 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006863 /* 'mkspellmem' */
6864 else if (varp == &p_msm)
6865 {
6866 if (spell_check_msm() != OK)
6867 errmsg = e_invarg;
6868 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006869#endif
6870
Bram Moolenaar071d4272004-06-13 20:20:40 +00006871#ifdef FEAT_QUICKFIX
6872 /* When 'bufhidden' is set, check for valid value. */
6873 else if (gvarp == &p_bh)
6874 {
6875 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6876 errmsg = e_invarg;
6877 }
6878
6879 /* When 'buftype' is set, check for valid value. */
6880 else if (gvarp == &p_bt)
6881 {
6882 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6883 errmsg = e_invarg;
6884 else
6885 {
6886# ifdef FEAT_WINDOWS
6887 if (curwin->w_status_height)
6888 {
6889 curwin->w_redr_status = TRUE;
6890 redraw_later(VALID);
6891 }
6892# endif
6893 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006894# ifdef FEAT_TITLE
6895 redraw_titles();
6896# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006897 }
6898 }
6899#endif
6900
6901#ifdef FEAT_STL_OPT
6902 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006903 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006904 {
6905 int wid;
6906
6907 if (varp == &p_ruf) /* reset ru_wid first */
6908 ru_wid = 0;
6909 s = *varp;
6910 if (varp == &p_ruf && *s == '%')
6911 {
6912 /* set ru_wid if 'ruf' starts with "%99(" */
6913 if (*++s == '-') /* ignore a '-' */
6914 s++;
6915 wid = getdigits(&s);
6916 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6917 ru_wid = wid;
6918 else
6919 errmsg = check_stl_option(p_ruf);
6920 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006921 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006922 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006923 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006924 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925 comp_col();
6926 }
6927#endif
6928
6929#ifdef FEAT_INS_EXPAND
6930 /* check if it is a valid value for 'complete' -- Acevedo */
6931 else if (gvarp == &p_cpt)
6932 {
6933 for (s = *varp; *s;)
6934 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006935 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936 s++;
6937 if (!*s)
6938 break;
6939 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6940 {
6941 errmsg = illegal_char(errbuf, *s);
6942 break;
6943 }
6944 if (*++s != NUL && *s != ',' && *s != ' ')
6945 {
6946 if (s[-1] == 'k' || s[-1] == 's')
6947 {
6948 /* skip optional filename after 'k' and 's' */
6949 while (*s && *s != ',' && *s != ' ')
6950 {
6951 if (*s == '\\')
6952 ++s;
6953 ++s;
6954 }
6955 }
6956 else
6957 {
6958 if (errbuf != NULL)
6959 {
6960 sprintf((char *)errbuf,
6961 _("E535: Illegal character after <%c>"),
6962 *--s);
6963 errmsg = errbuf;
6964 }
6965 else
6966 errmsg = (char_u *)"";
6967 break;
6968 }
6969 }
6970 }
6971 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006972
6973 /* 'completeopt' */
6974 else if (varp == &p_cot)
6975 {
6976 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6977 errmsg = e_invarg;
6978 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979#endif /* FEAT_INS_EXPAND */
6980
6981
6982#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6983 else if (varp == &p_toolbar)
6984 {
6985 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6986 &toolbar_flags, TRUE) != OK)
6987 errmsg = e_invarg;
6988 else
6989 {
6990 out_flush();
6991 gui_mch_show_toolbar((toolbar_flags &
6992 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6993 }
6994 }
6995#endif
6996
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006997#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006998 /* 'toolbariconsize': GTK+ 2 only */
6999 else if (varp == &p_tbis)
7000 {
7001 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7002 errmsg = e_invarg;
7003 else
7004 {
7005 out_flush();
7006 gui_mch_show_toolbar((toolbar_flags &
7007 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7008 }
7009 }
7010#endif
7011
7012 /* 'pastetoggle': translate key codes like in a mapping */
7013 else if (varp == &p_pt)
7014 {
7015 if (*p_pt)
7016 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007017 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018 if (p != NULL)
7019 {
7020 if (new_value_alloced)
7021 free_string_option(p_pt);
7022 p_pt = p;
7023 new_value_alloced = TRUE;
7024 }
7025 }
7026 }
7027
7028 /* 'backspace' */
7029 else if (varp == &p_bs)
7030 {
7031 if (VIM_ISDIGIT(*p_bs))
7032 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007033 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007034 errmsg = e_invarg;
7035 }
7036 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7037 errmsg = e_invarg;
7038 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007039 else if (varp == &p_bo)
7040 {
7041 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7042 errmsg = e_invarg;
7043 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007045 /* 'tagcase' */
7046 else if (gvarp == &p_tc)
7047 {
7048 unsigned int *flags;
7049
7050 if (opt_flags & OPT_LOCAL)
7051 {
7052 p = curbuf->b_p_tc;
7053 flags = &curbuf->b_tc_flags;
7054 }
7055 else
7056 {
7057 p = p_tc;
7058 flags = &tc_flags;
7059 }
7060
7061 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7062 /* make the local value empty: use the global value */
7063 *flags = 0;
7064 else if (*p == NUL
7065 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7066 errmsg = e_invarg;
7067 }
7068
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007069#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 /* 'casemap' */
7071 else if (varp == &p_cmp)
7072 {
7073 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7074 errmsg = e_invarg;
7075 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007076#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077
7078#ifdef FEAT_DIFF
7079 /* 'diffopt' */
7080 else if (varp == &p_dip)
7081 {
7082 if (diffopt_changed() == FAIL)
7083 errmsg = e_invarg;
7084 }
7085#endif
7086
7087#ifdef FEAT_FOLDING
7088 /* 'foldmethod' */
7089 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7090 {
7091 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7092 || *curwin->w_p_fdm == NUL)
7093 errmsg = e_invarg;
7094 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007095 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007097 if (foldmethodIsDiff(curwin))
7098 newFoldLevel();
7099 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007100 }
7101# ifdef FEAT_EVAL
7102 /* 'foldexpr' */
7103 else if (varp == &curwin->w_p_fde)
7104 {
7105 if (foldmethodIsExpr(curwin))
7106 foldUpdateAll(curwin);
7107 }
7108# endif
7109 /* 'foldmarker' */
7110 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7111 {
7112 p = vim_strchr(*varp, ',');
7113 if (p == NULL)
7114 errmsg = (char_u *)N_("E536: comma required");
7115 else if (p == *varp || p[1] == NUL)
7116 errmsg = e_invarg;
7117 else if (foldmethodIsMarker(curwin))
7118 foldUpdateAll(curwin);
7119 }
7120 /* 'commentstring' */
7121 else if (gvarp == &p_cms)
7122 {
7123 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7124 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7125 }
7126 /* 'foldopen' */
7127 else if (varp == &p_fdo)
7128 {
7129 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7130 errmsg = e_invarg;
7131 }
7132 /* 'foldclose' */
7133 else if (varp == &p_fcl)
7134 {
7135 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7136 errmsg = e_invarg;
7137 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007138 /* 'foldignore' */
7139 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7140 {
7141 if (foldmethodIsIndent(curwin))
7142 foldUpdateAll(curwin);
7143 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144#endif
7145
7146#ifdef FEAT_VIRTUALEDIT
7147 /* 'virtualedit' */
7148 else if (varp == &p_ve)
7149 {
7150 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7151 errmsg = e_invarg;
7152 else if (STRCMP(p_ve, oldval) != 0)
7153 {
7154 /* Recompute cursor position in case the new 've' setting
7155 * changes something. */
7156 validate_virtcol();
7157 coladvance(curwin->w_virtcol);
7158 }
7159 }
7160#endif
7161
7162#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7163 else if (varp == &p_csqf)
7164 {
7165 if (p_csqf != NULL)
7166 {
7167 p = p_csqf;
7168 while (*p != NUL)
7169 {
7170 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7171 || p[1] == NUL
7172 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7173 || (p[2] != NUL && p[2] != ','))
7174 {
7175 errmsg = e_invarg;
7176 break;
7177 }
7178 else if (p[2] == NUL)
7179 break;
7180 else
7181 p += 3;
7182 }
7183 }
7184 }
7185#endif
7186
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007187#ifdef FEAT_CINDENT
7188 /* 'cinoptions' */
7189 else if (gvarp == &p_cino)
7190 {
7191 /* TODO: recognize errors */
7192 parse_cino(curbuf);
7193 }
7194#endif
7195
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007196#if defined(FEAT_RENDER_OPTIONS)
7197 else if (varp == &p_rop && gui.in_use)
7198 {
7199 if (!gui_mch_set_rendering_options(p_rop))
7200 errmsg = e_invarg;
7201 }
7202#endif
7203
Bram Moolenaar071d4272004-06-13 20:20:40 +00007204 /* Options that are a list of flags. */
7205 else
7206 {
7207 p = NULL;
7208 if (varp == &p_ww)
7209 p = (char_u *)WW_ALL;
7210 if (varp == &p_shm)
7211 p = (char_u *)SHM_ALL;
7212 else if (varp == &(p_cpo))
7213 p = (char_u *)CPO_ALL;
7214 else if (varp == &(curbuf->b_p_fo))
7215 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007216#ifdef FEAT_CONCEAL
7217 else if (varp == &curwin->w_p_cocu)
7218 p = (char_u *)COCU_ALL;
7219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007220 else if (varp == &p_mouse)
7221 {
7222#ifdef FEAT_MOUSE
7223 p = (char_u *)MOUSE_ALL;
7224#else
7225 if (*p_mouse != NUL)
7226 errmsg = (char_u *)N_("E538: No mouse support");
7227#endif
7228 }
7229#if defined(FEAT_GUI)
7230 else if (varp == &p_go)
7231 p = (char_u *)GO_ALL;
7232#endif
7233 if (p != NULL)
7234 {
7235 for (s = *varp; *s; ++s)
7236 if (vim_strchr(p, *s) == NULL)
7237 {
7238 errmsg = illegal_char(errbuf, *s);
7239 break;
7240 }
7241 }
7242 }
7243
7244 /*
7245 * If error detected, restore the previous value.
7246 */
7247 if (errmsg != NULL)
7248 {
7249 if (new_value_alloced)
7250 free_string_option(*varp);
7251 *varp = oldval;
7252 /*
7253 * When resetting some values, need to act on it.
7254 */
7255 if (did_chartab)
7256 (void)init_chartab();
7257 if (varp == &p_hl)
7258 (void)highlight_changed();
7259 }
7260 else
7261 {
7262#ifdef FEAT_EVAL
7263 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007264 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007265#endif
7266 /*
7267 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007268 * Use "free_oldval", because recursiveness may change the flags under
7269 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007270 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007271 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007272 free_string_option(oldval);
7273 if (new_value_alloced)
7274 options[opt_idx].flags |= P_ALLOCED;
7275 else
7276 options[opt_idx].flags &= ~P_ALLOCED;
7277
7278 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007279 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007280 {
7281 /* global option with local value set to use global value; free
7282 * the local value and make it empty */
7283 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7284 free_string_option(*(char_u **)p);
7285 *(char_u **)p = empty_option;
7286 }
7287
7288 /* May set global value for local option. */
7289 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7290 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007291
7292#ifdef FEAT_AUTOCMD
7293 /*
7294 * Trigger the autocommand only after setting the flags.
7295 */
7296# ifdef FEAT_SYN_HL
7297 /* When 'syntax' is set, load the syntax of that name */
7298 if (varp == &(curbuf->b_p_syn))
7299 {
7300 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7301 curbuf->b_fname, TRUE, curbuf);
7302 }
7303# endif
7304 else if (varp == &(curbuf->b_p_ft))
7305 {
7306 /* 'filetype' is set, trigger the FileType autocommand */
7307 did_filetype = TRUE;
7308 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7309 curbuf->b_fname, TRUE, curbuf);
7310 }
7311#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007312#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007313 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007314 {
7315 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007316 char_u *q = curwin->w_s->b_p_spl;
7317
7318 /* Skip the first name if it is "cjk". */
7319 if (STRNCMP(q, "cjk,", 4) == 0)
7320 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007321
7322 /*
7323 * Source the spell/LANG.vim in 'runtimepath'.
7324 * They could set 'spellcapcheck' depending on the language.
7325 * Use the first name in 'spelllang' up to '_region' or
7326 * '.encoding'.
7327 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007328 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007329 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7330 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007331 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007332 source_runtime(fname, TRUE);
7333 }
7334#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007335 }
7336
7337#ifdef FEAT_MOUSE
7338 if (varp == &p_mouse)
7339 {
7340# ifdef FEAT_MOUSE_TTY
7341 if (*p_mouse == NUL)
7342 mch_setmouse(FALSE); /* switch mouse off */
7343 else
7344# endif
7345 setmouse(); /* in case 'mouse' changed */
7346 }
7347#endif
7348
Bram Moolenaar913077c2012-03-28 19:59:04 +02007349 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007350 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007351 curwin->w_set_curswant = TRUE;
7352
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007353#ifdef FEAT_GUI
7354 /* check redraw when it's not a GUI option or the GUI is active. */
7355 if (!redraw_gui_only || gui.in_use)
7356#endif
7357 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007358
7359 return errmsg;
7360}
7361
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007362#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007363/*
7364 * Simple int comparison function for use with qsort()
7365 */
7366 static int
7367int_cmp(a, b)
7368 const void *a;
7369 const void *b;
7370{
7371 return *(const int *)a - *(const int *)b;
7372}
7373
7374/*
7375 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7376 * Returns error message, NULL if it's OK.
7377 */
7378 char_u *
7379check_colorcolumn(wp)
7380 win_T *wp;
7381{
7382 char_u *s;
7383 int col;
7384 int count = 0;
7385 int color_cols[256];
7386 int i;
7387 int j = 0;
7388
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007389 if (wp->w_buffer == NULL)
7390 return NULL; /* buffer was closed */
7391
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007392 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007393 {
7394 if (*s == '-' || *s == '+')
7395 {
7396 /* -N and +N: add to 'textwidth' */
7397 col = (*s == '-') ? -1 : 1;
7398 ++s;
7399 if (!VIM_ISDIGIT(*s))
7400 return e_invarg;
7401 col = col * getdigits(&s);
7402 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007403 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007404 col += wp->w_buffer->b_p_tw;
7405 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007406 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007407 }
7408 else if (VIM_ISDIGIT(*s))
7409 col = getdigits(&s);
7410 else
7411 return e_invarg;
7412 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007413skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007414 if (*s == NUL)
7415 break;
7416 if (*s != ',')
7417 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007418 if (*++s == NUL)
7419 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007420 }
7421
7422 vim_free(wp->w_p_cc_cols);
7423 if (count == 0)
7424 wp->w_p_cc_cols = NULL;
7425 else
7426 {
7427 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7428 if (wp->w_p_cc_cols != NULL)
7429 {
7430 /* sort the columns for faster usage on screen redraw inside
7431 * win_line() */
7432 qsort(color_cols, count, sizeof(int), int_cmp);
7433
7434 for (i = 0; i < count; ++i)
7435 /* skip duplicates */
7436 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7437 wp->w_p_cc_cols[j++] = color_cols[i];
7438 wp->w_p_cc_cols[j] = -1; /* end marker */
7439 }
7440 }
7441
7442 return NULL; /* no error */
7443}
7444#endif
7445
Bram Moolenaar071d4272004-06-13 20:20:40 +00007446/*
7447 * Handle setting 'listchars' or 'fillchars'.
7448 * Returns error message, NULL if it's OK.
7449 */
7450 static char_u *
7451set_chars_option(varp)
7452 char_u **varp;
7453{
7454 int round, i, len, entries;
7455 char_u *p, *s;
7456 int c1, c2 = 0;
7457 struct charstab
7458 {
7459 int *cp;
7460 char *name;
7461 };
7462#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7463 static struct charstab filltab[] =
7464 {
7465 {&fill_stl, "stl"},
7466 {&fill_stlnc, "stlnc"},
7467 {&fill_vert, "vert"},
7468 {&fill_fold, "fold"},
7469 {&fill_diff, "diff"},
7470 };
7471#endif
7472 static struct charstab lcstab[] =
7473 {
7474 {&lcs_eol, "eol"},
7475 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007476 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007478 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007479 {&lcs_tab2, "tab"},
7480 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007481#ifdef FEAT_CONCEAL
7482 {&lcs_conceal, "conceal"},
7483#else
7484 {NULL, "conceal"},
7485#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 };
7487 struct charstab *tab;
7488
7489#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7490 if (varp == &p_lcs)
7491#endif
7492 {
7493 tab = lcstab;
7494 entries = sizeof(lcstab) / sizeof(struct charstab);
7495 }
7496#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7497 else
7498 {
7499 tab = filltab;
7500 entries = sizeof(filltab) / sizeof(struct charstab);
7501 }
7502#endif
7503
7504 /* first round: check for valid value, second round: assign values */
7505 for (round = 0; round <= 1; ++round)
7506 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007507 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007508 {
7509 /* After checking that the value is valid: set defaults: space for
7510 * 'fillchars', NUL for 'listchars' */
7511 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007512 if (tab[i].cp != NULL)
7513 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514 if (varp == &p_lcs)
7515 lcs_tab1 = NUL;
7516#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7517 else
7518 fill_diff = '-';
7519#endif
7520 }
7521 p = *varp;
7522 while (*p)
7523 {
7524 for (i = 0; i < entries; ++i)
7525 {
7526 len = (int)STRLEN(tab[i].name);
7527 if (STRNCMP(p, tab[i].name, len) == 0
7528 && p[len] == ':'
7529 && p[len + 1] != NUL)
7530 {
7531 s = p + len + 1;
7532#ifdef FEAT_MBYTE
7533 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007534 if (mb_char2cells(c1) > 1)
7535 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007536#else
7537 c1 = *s++;
7538#endif
7539 if (tab[i].cp == &lcs_tab2)
7540 {
7541 if (*s == NUL)
7542 continue;
7543#ifdef FEAT_MBYTE
7544 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007545 if (mb_char2cells(c2) > 1)
7546 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007547#else
7548 c2 = *s++;
7549#endif
7550 }
7551 if (*s == ',' || *s == NUL)
7552 {
7553 if (round)
7554 {
7555 if (tab[i].cp == &lcs_tab2)
7556 {
7557 lcs_tab1 = c1;
7558 lcs_tab2 = c2;
7559 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007560 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007561 *(tab[i].cp) = c1;
7562
7563 }
7564 p = s;
7565 break;
7566 }
7567 }
7568 }
7569
7570 if (i == entries)
7571 return e_invarg;
7572 if (*p == ',')
7573 ++p;
7574 }
7575 }
7576
7577 return NULL; /* no error */
7578}
7579
7580#ifdef FEAT_STL_OPT
7581/*
7582 * Check validity of options with the 'statusline' format.
7583 * Return error message or NULL.
7584 */
7585 char_u *
7586check_stl_option(s)
7587 char_u *s;
7588{
7589 int itemcnt = 0;
7590 int groupdepth = 0;
7591 static char_u errbuf[80];
7592
7593 while (*s && itemcnt < STL_MAX_ITEM)
7594 {
7595 /* Check for valid keys after % sequences */
7596 while (*s && *s != '%')
7597 s++;
7598 if (!*s)
7599 break;
7600 s++;
7601 if (*s != '%' && *s != ')')
7602 ++itemcnt;
7603 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7604 {
7605 s++;
7606 continue;
7607 }
7608 if (*s == ')')
7609 {
7610 s++;
7611 if (--groupdepth < 0)
7612 break;
7613 continue;
7614 }
7615 if (*s == '-')
7616 s++;
7617 while (VIM_ISDIGIT(*s))
7618 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007619 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007620 continue;
7621 if (*s == '.')
7622 {
7623 s++;
7624 while (*s && VIM_ISDIGIT(*s))
7625 s++;
7626 }
7627 if (*s == '(')
7628 {
7629 groupdepth++;
7630 continue;
7631 }
7632 if (vim_strchr(STL_ALL, *s) == NULL)
7633 {
7634 return illegal_char(errbuf, *s);
7635 }
7636 if (*s == '{')
7637 {
7638 s++;
7639 while (*s != '}' && *s)
7640 s++;
7641 if (*s != '}')
7642 return (char_u *)N_("E540: Unclosed expression sequence");
7643 }
7644 }
7645 if (itemcnt >= STL_MAX_ITEM)
7646 return (char_u *)N_("E541: too many items");
7647 if (groupdepth != 0)
7648 return (char_u *)N_("E542: unbalanced groups");
7649 return NULL;
7650}
7651#endif
7652
7653#ifdef FEAT_CLIPBOARD
7654/*
7655 * Extract the items in the 'clipboard' option and set global values.
7656 */
7657 static char_u *
7658check_clipboard_option()
7659{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007660 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007661 int new_autoselect_star = FALSE;
7662 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007663 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007664 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007665 regprog_T *new_exclude_prog = NULL;
7666 char_u *errmsg = NULL;
7667 char_u *p;
7668
7669 for (p = p_cb; *p != NUL; )
7670 {
7671 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7672 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007673 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007674 p += 7;
7675 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007676 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007677 && (p[11] == ',' || p[11] == NUL))
7678 {
7679 new_unnamed |= CLIP_UNNAMED_PLUS;
7680 p += 11;
7681 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007682 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007683 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007684 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007685 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007686 p += 10;
7687 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007688 else if (STRNCMP(p, "autoselectplus", 14) == 0
7689 && (p[14] == ',' || p[14] == NUL))
7690 {
7691 new_autoselect_plus = TRUE;
7692 p += 14;
7693 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007694 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007695 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007696 {
7697 new_autoselectml = TRUE;
7698 p += 12;
7699 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007700 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7701 {
7702 new_html = TRUE;
7703 p += 4;
7704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7706 {
7707 p += 8;
7708 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7709 if (new_exclude_prog == NULL)
7710 errmsg = e_invarg;
7711 break;
7712 }
7713 else
7714 {
7715 errmsg = e_invarg;
7716 break;
7717 }
7718 if (*p == ',')
7719 ++p;
7720 }
7721 if (errmsg == NULL)
7722 {
7723 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007724 clip_autoselect_star = new_autoselect_star;
7725 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007726 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007727 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007728 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007730#ifdef FEAT_GUI_GTK
7731 if (gui.in_use)
7732 {
7733 gui_gtk_set_selection_targets();
7734 gui_gtk_set_dnd_targets();
7735 }
7736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007737 }
7738 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007739 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007740
7741 return errmsg;
7742}
7743#endif
7744
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007745#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007746 static char_u *
7747did_set_spell_option(is_spellfile)
7748 int is_spellfile;
7749{
7750 char_u *errmsg = NULL;
7751 win_T *wp;
7752 int l;
7753
7754 if (is_spellfile)
7755 {
7756 l = (int)STRLEN(curwin->w_s->b_p_spf);
7757 if (l > 0 && (l < 4
7758 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7759 errmsg = e_invarg;
7760 }
7761
7762 if (errmsg == NULL)
7763 {
7764 FOR_ALL_WINDOWS(wp)
7765 if (wp->w_buffer == curbuf && wp->w_p_spell)
7766 {
7767 errmsg = did_set_spelllang(wp);
7768# ifdef FEAT_WINDOWS
7769 break;
7770# endif
7771 }
7772 }
7773 return errmsg;
7774}
7775
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007776/*
7777 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7778 * Return error message when failed, NULL when OK.
7779 */
7780 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007781compile_cap_prog(synblock)
7782 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007783{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007784 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007785 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007786
Bram Moolenaar860cae12010-06-05 23:22:07 +02007787 if (*synblock->b_p_spc == NUL)
7788 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007789 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007790 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007791 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007792 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007793 if (re != NULL)
7794 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007795 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007796 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007797 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007798 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007799 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007800 return e_invarg;
7801 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007802 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007803 }
7804
Bram Moolenaar473de612013-06-08 18:19:48 +02007805 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007806 return NULL;
7807}
7808#endif
7809
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007810#if defined(FEAT_EVAL) || defined(PROTO)
7811/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007812 * Set the scriptID for an option, taking care of setting the buffer- or
7813 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007814 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007815 static void
7816set_option_scriptID_idx(opt_idx, opt_flags, id)
7817 int opt_idx;
7818 int opt_flags;
7819 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007820{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007821 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7822 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007823
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007824 /* Remember where the option was set. For local options need to do that
7825 * in the buffer or window structure. */
7826 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007827 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007828 if (both || (opt_flags & OPT_LOCAL))
7829 {
7830 if (indir & PV_BUF)
7831 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7832 else if (indir & PV_WIN)
7833 curwin->w_p_scriptID[indir & PV_MASK] = id;
7834 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007835}
7836#endif
7837
Bram Moolenaar071d4272004-06-13 20:20:40 +00007838/*
7839 * Set the value of a boolean option, and take care of side effects.
7840 * Returns NULL for success, or an error message for an error.
7841 */
7842 static char_u *
7843set_bool_option(opt_idx, varp, value, opt_flags)
7844 int opt_idx; /* index in options[] table */
7845 char_u *varp; /* pointer to the option variable */
7846 int value; /* new value */
7847 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7848{
7849 int old_value = *(int *)varp;
7850
Bram Moolenaar071d4272004-06-13 20:20:40 +00007851 /* Disallow changing some options from secure mode */
7852 if ((secure
7853#ifdef HAVE_SANDBOX
7854 || sandbox != 0
7855#endif
7856 ) && (options[opt_idx].flags & P_SECURE))
7857 return e_secure;
7858
7859 *(int *)varp = value; /* set the new value */
7860#ifdef FEAT_EVAL
7861 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007862 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007863#endif
7864
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007865#ifdef FEAT_GUI
7866 need_mouse_correct = TRUE;
7867#endif
7868
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869 /* May set global value for local option. */
7870 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7871 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7872
7873 /*
7874 * Handle side effects of changing a bool option.
7875 */
7876
7877 /* 'compatible' */
7878 if ((int *)varp == &p_cp)
7879 {
7880 compatible_set();
7881 }
7882
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007883#ifdef FEAT_PERSISTENT_UNDO
7884 /* 'undofile' */
7885 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7886 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007887 /* Only take action when the option was set. When reset we do not
7888 * delete the undo file, the option may be set again without making
7889 * any changes in between. */
7890 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007891 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007892 char_u hash[UNDO_HASH_SIZE];
7893 buf_T *save_curbuf = curbuf;
7894
7895 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007896 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007897 /* When 'undofile' is set globally: for every buffer, otherwise
7898 * only for the current buffer: Try to read in the undofile,
7899 * if one exists, the buffer wasn't changed and the buffer was
7900 * loaded */
7901 if ((curbuf == save_curbuf
7902 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7903 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7904 {
7905 u_compute_hash(hash);
7906 u_read_undo(NULL, hash, curbuf->b_fname);
7907 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007908 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007909 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007910 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007911 }
7912#endif
7913
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 else if ((int *)varp == &curbuf->b_p_ro)
7915 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007916 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7918 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007919
7920 /* when 'readonly' is set may give W10 again */
7921 if (curbuf->b_p_ro)
7922 curbuf->b_did_warn = FALSE;
7923
Bram Moolenaar071d4272004-06-13 20:20:40 +00007924#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007925 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926#endif
7927 }
7928
Bram Moolenaar9c449722010-07-20 18:44:27 +02007929#ifdef FEAT_GUI
7930 else if ((int *)varp == &p_mh)
7931 {
7932 if (!p_mh)
7933 gui_mch_mousehide(FALSE);
7934 }
7935#endif
7936
Bram Moolenaara539df02010-08-01 14:35:05 +02007937#ifdef FEAT_TITLE
7938 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007940 {
7941 redraw_titles();
7942 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943 /* when 'endofline' is changed, redraw the window title */
7944 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007945 {
7946 redraw_titles();
7947 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007948 /* when 'fixeol' is changed, redraw the window title */
7949 else if ((int *)varp == &curbuf->b_p_fixeol)
7950 {
7951 redraw_titles();
7952 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007953# ifdef FEAT_MBYTE
7954 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007955 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007956 {
7957 redraw_titles();
7958 }
7959# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007960#endif
7961
7962 /* when 'bin' is set also set some other options */
7963 else if ((int *)varp == &curbuf->b_p_bin)
7964 {
7965 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7966#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007967 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968#endif
7969 }
7970
7971#ifdef FEAT_AUTOCMD
7972 /* when 'buflisted' changes, trigger autocommands */
7973 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7974 {
7975 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7976 NULL, NULL, TRUE, curbuf);
7977 }
7978#endif
7979
7980 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7981 else if ((int *)varp == &curbuf->b_p_swf)
7982 {
7983 if (curbuf->b_p_swf && p_uc)
7984 ml_open_file(curbuf); /* create the swap file */
7985 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007986 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7987 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007988 mf_close_file(curbuf, TRUE); /* remove the swap file */
7989 }
7990
7991 /* when 'terse' is set change 'shortmess' */
7992 else if ((int *)varp == &p_terse)
7993 {
7994 char_u *p;
7995
7996 p = vim_strchr(p_shm, SHM_SEARCH);
7997
7998 /* insert 's' in p_shm */
7999 if (p_terse && p == NULL)
8000 {
8001 STRCPY(IObuff, p_shm);
8002 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008003 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008004 }
8005 /* remove 's' from p_shm */
8006 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008007 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008008 }
8009
8010 /* when 'paste' is set or reset also change other options */
8011 else if ((int *)varp == &p_paste)
8012 {
8013 paste_option_changed();
8014 }
8015
8016 /* when 'insertmode' is set from an autocommand need to do work here */
8017 else if ((int *)varp == &p_im)
8018 {
8019 if (p_im)
8020 {
8021 if ((State & INSERT) == 0)
8022 need_start_insertmode = TRUE;
8023 stop_insert_mode = FALSE;
8024 }
8025 else
8026 {
8027 need_start_insertmode = FALSE;
8028 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008029 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008030 clear_cmdline = TRUE; /* remove "(insert)" */
8031 restart_edit = 0;
8032 }
8033 }
8034
8035 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8036 else if ((int *)varp == &p_ic && p_hls)
8037 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008038 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008039 }
8040
8041#ifdef FEAT_SEARCH_EXTRA
8042 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8043 else if ((int *)varp == &p_hls)
8044 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008045 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008046 }
8047#endif
8048
8049#ifdef FEAT_SCROLLBIND
8050 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8051 * at the end of normal_cmd() */
8052 else if ((int *)varp == &curwin->w_p_scb)
8053 {
8054 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008055 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008057 curwin->w_scbind_pos = curwin->w_topline;
8058 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008059 }
8060#endif
8061
8062#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8063 /* There can be only one window with 'previewwindow' set. */
8064 else if ((int *)varp == &curwin->w_p_pvw)
8065 {
8066 if (curwin->w_p_pvw)
8067 {
8068 win_T *win;
8069
8070 for (win = firstwin; win != NULL; win = win->w_next)
8071 if (win->w_p_pvw && win != curwin)
8072 {
8073 curwin->w_p_pvw = FALSE;
8074 return (char_u *)N_("E590: A preview window already exists");
8075 }
8076 }
8077 }
8078#endif
8079
8080 /* when 'textmode' is set or reset also change 'fileformat' */
8081 else if ((int *)varp == &curbuf->b_p_tx)
8082 {
8083 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8084 }
8085
8086 /* when 'textauto' is set or reset also change 'fileformats' */
8087 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008088 set_string_option_direct((char_u *)"ffs", -1,
8089 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008090 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091
8092 /*
8093 * When 'lisp' option changes include/exclude '-' in
8094 * keyword characters.
8095 */
8096#ifdef FEAT_LISP
8097 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8098 {
8099 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8100 }
8101#endif
8102
8103#ifdef FEAT_TITLE
8104 /* when 'title' changed, may need to change the title; same for 'icon' */
8105 else if ((int *)varp == &p_title)
8106 {
8107 did_set_title(FALSE);
8108 }
8109
8110 else if ((int *)varp == &p_icon)
8111 {
8112 did_set_title(TRUE);
8113 }
8114#endif
8115
8116 else if ((int *)varp == &curbuf->b_changed)
8117 {
8118 if (!value)
8119 save_file_ff(curbuf); /* Buffer is unchanged */
8120#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008121 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008122#endif
8123#ifdef FEAT_AUTOCMD
8124 modified_was_set = value;
8125#endif
8126 }
8127
8128#ifdef BACKSLASH_IN_FILENAME
8129 else if ((int *)varp == &p_ssl)
8130 {
8131 if (p_ssl)
8132 {
8133 psepc = '/';
8134 psepcN = '\\';
8135 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136 }
8137 else
8138 {
8139 psepc = '\\';
8140 psepcN = '/';
8141 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008142 }
8143
8144 /* need to adjust the file name arguments and buffer names. */
8145 buflist_slash_adjust();
8146 alist_slash_adjust();
8147# ifdef FEAT_EVAL
8148 scriptnames_slash_adjust();
8149# endif
8150 }
8151#endif
8152
8153 /* If 'wrap' is set, set w_leftcol to zero. */
8154 else if ((int *)varp == &curwin->w_p_wrap)
8155 {
8156 if (curwin->w_p_wrap)
8157 curwin->w_leftcol = 0;
8158 }
8159
8160#ifdef FEAT_WINDOWS
8161 else if ((int *)varp == &p_ea)
8162 {
8163 if (p_ea && !old_value)
8164 win_equal(curwin, FALSE, 0);
8165 }
8166#endif
8167
8168 else if ((int *)varp == &p_wiv)
8169 {
8170 /*
8171 * When 'weirdinvert' changed, set/reset 't_xs'.
8172 * Then set 'weirdinvert' according to value of 't_xs'.
8173 */
8174 if (p_wiv && !old_value)
8175 T_XS = (char_u *)"y";
8176 else if (!p_wiv && old_value)
8177 T_XS = empty_option;
8178 p_wiv = (*T_XS != NUL);
8179 }
8180
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008181#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008182 else if ((int *)varp == &p_beval)
8183 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008184 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008185 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008186 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008187 gui_mch_disable_beval_area(balloonEval);
8188 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008189#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008191#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192 else if ((int *)varp == &p_acd)
8193 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008194 /* Change directories when the 'acd' option is set now. */
8195 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196 }
8197#endif
8198
8199#ifdef FEAT_DIFF
8200 /* 'diff' */
8201 else if ((int *)varp == &curwin->w_p_diff)
8202 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008203 /* May add or remove the buffer from the list of diff buffers. */
8204 diff_buf_adjust(curwin);
8205# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206 if (foldmethodIsDiff(curwin))
8207 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008208# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209 }
8210#endif
8211
8212#ifdef USE_IM_CONTROL
8213 /* 'imdisable' */
8214 else if ((int *)varp == &p_imdisable)
8215 {
8216 /* Only de-activate it here, it will be enabled when changing mode. */
8217 if (p_imdisable)
8218 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008219 else if (State & INSERT)
8220 /* When the option is set from an autocommand, it may need to take
8221 * effect right away. */
8222 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008223 }
8224#endif
8225
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008226#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008227 /* 'spell' */
8228 else if ((int *)varp == &curwin->w_p_spell)
8229 {
8230 if (curwin->w_p_spell)
8231 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008232 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008233 if (errmsg != NULL)
8234 EMSG(_(errmsg));
8235 }
8236 }
8237#endif
8238
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239#ifdef FEAT_FKMAP
8240 else if ((int *)varp == &p_altkeymap)
8241 {
8242 if (old_value != p_altkeymap)
8243 {
8244 if (!p_altkeymap)
8245 {
8246 p_hkmap = p_fkmap;
8247 p_fkmap = 0;
8248 }
8249 else
8250 {
8251 p_fkmap = p_hkmap;
8252 p_hkmap = 0;
8253 }
8254 (void)init_chartab();
8255 }
8256 }
8257
8258 /*
8259 * In case some second language keymapping options have changed, check
8260 * and correct the setting in a consistent way.
8261 */
8262
8263 /*
8264 * If hkmap or fkmap are set, reset Arabic keymapping.
8265 */
8266 if ((p_hkmap || p_fkmap) && p_altkeymap)
8267 {
8268 p_altkeymap = p_fkmap;
8269# ifdef FEAT_ARABIC
8270 curwin->w_p_arab = FALSE;
8271# endif
8272 (void)init_chartab();
8273 }
8274
8275 /*
8276 * If hkmap set, reset Farsi keymapping.
8277 */
8278 if (p_hkmap && p_altkeymap)
8279 {
8280 p_altkeymap = 0;
8281 p_fkmap = 0;
8282# ifdef FEAT_ARABIC
8283 curwin->w_p_arab = FALSE;
8284# endif
8285 (void)init_chartab();
8286 }
8287
8288 /*
8289 * If fkmap set, reset Hebrew keymapping.
8290 */
8291 if (p_fkmap && !p_altkeymap)
8292 {
8293 p_altkeymap = 1;
8294 p_hkmap = 0;
8295# ifdef FEAT_ARABIC
8296 curwin->w_p_arab = FALSE;
8297# endif
8298 (void)init_chartab();
8299 }
8300#endif
8301
8302#ifdef FEAT_ARABIC
8303 if ((int *)varp == &curwin->w_p_arab)
8304 {
8305 if (curwin->w_p_arab)
8306 {
8307 /*
8308 * 'arabic' is set, handle various sub-settings.
8309 */
8310 if (!p_tbidi)
8311 {
8312 /* set rightleft mode */
8313 if (!curwin->w_p_rl)
8314 {
8315 curwin->w_p_rl = TRUE;
8316 changed_window_setting();
8317 }
8318
8319 /* Enable Arabic shaping (major part of what Arabic requires) */
8320 if (!p_arshape)
8321 {
8322 p_arshape = TRUE;
8323 redraw_later_clear();
8324 }
8325 }
8326
8327 /* Arabic requires a utf-8 encoding, inform the user if its not
8328 * set. */
8329 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008330 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008331 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8332
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008333 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008334 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8335#ifdef FEAT_EVAL
8336 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8337#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008338 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008339
8340# ifdef FEAT_MBYTE
8341 /* set 'delcombine' */
8342 p_deco = TRUE;
8343# endif
8344
8345# ifdef FEAT_KEYMAP
8346 /* Force-set the necessary keymap for arabic */
8347 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8348 OPT_LOCAL);
8349# endif
8350# ifdef FEAT_FKMAP
8351 p_altkeymap = 0;
8352 p_hkmap = 0;
8353 p_fkmap = 0;
8354 (void)init_chartab();
8355# endif
8356 }
8357 else
8358 {
8359 /*
8360 * 'arabic' is reset, handle various sub-settings.
8361 */
8362 if (!p_tbidi)
8363 {
8364 /* reset rightleft mode */
8365 if (curwin->w_p_rl)
8366 {
8367 curwin->w_p_rl = FALSE;
8368 changed_window_setting();
8369 }
8370
8371 /* 'arabicshape' isn't reset, it is a global option and
8372 * another window may still need it "on". */
8373 }
8374
8375 /* 'delcombine' isn't reset, it is a global option and another
8376 * window may still want it "on". */
8377
8378# ifdef FEAT_KEYMAP
8379 /* Revert to the default keymap */
8380 curbuf->b_p_iminsert = B_IMODE_NONE;
8381 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8382# endif
8383 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008384 }
8385
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008386#endif
8387
Bram Moolenaar071d4272004-06-13 20:20:40 +00008388 /*
8389 * End of handling side effects for bool options.
8390 */
8391
Bram Moolenaar53744302015-07-17 17:38:22 +02008392 /* after handling side effects, call autocommand */
8393
Bram Moolenaar071d4272004-06-13 20:20:40 +00008394 options[opt_idx].flags |= P_WAS_SET;
8395
Bram Moolenaar53744302015-07-17 17:38:22 +02008396#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8397 if (!starting)
8398 {
8399 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008400 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8401 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8402 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008403 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8404 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8405 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8406 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8407 reset_v_option_vars();
8408 }
8409#endif
8410
Bram Moolenaar071d4272004-06-13 20:20:40 +00008411 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008412 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008413 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008414 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415 check_redraw(options[opt_idx].flags);
8416
8417 return NULL;
8418}
8419
8420/*
8421 * Set the value of a number option, and take care of side effects.
8422 * Returns NULL for success, or an error message for an error.
8423 */
8424 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008425set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008426 int opt_idx; /* index in options[] table */
8427 char_u *varp; /* pointer to the option variable */
8428 long value; /* new value */
8429 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008430 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008431 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8432 OPT_MODELINE */
8433{
8434 char_u *errmsg = NULL;
8435 long old_value = *(long *)varp;
8436 long old_Rows = Rows; /* remember old Rows */
8437 long old_Columns = Columns; /* remember old Columns */
8438 long *pp = (long *)varp;
8439
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008440 /* Disallow changing some options from secure mode. */
8441 if ((secure
8442#ifdef HAVE_SANDBOX
8443 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008445 ) && (options[opt_idx].flags & P_SECURE))
8446 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447
8448 *pp = value;
8449#ifdef FEAT_EVAL
8450 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008451 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008452#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008453#ifdef FEAT_GUI
8454 need_mouse_correct = TRUE;
8455#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008456
Bram Moolenaar14f24742012-08-08 18:01:05 +02008457 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008458 {
8459 errmsg = e_positive;
8460 curbuf->b_p_sw = curbuf->b_p_ts;
8461 }
8462
8463 /*
8464 * Number options that need some action when changed
8465 */
8466#ifdef FEAT_WINDOWS
8467 if (pp == &p_wh || pp == &p_hh)
8468 {
8469 if (p_wh < 1)
8470 {
8471 errmsg = e_positive;
8472 p_wh = 1;
8473 }
8474 if (p_wmh > p_wh)
8475 {
8476 errmsg = e_winheight;
8477 p_wh = p_wmh;
8478 }
8479 if (p_hh < 0)
8480 {
8481 errmsg = e_positive;
8482 p_hh = 0;
8483 }
8484
8485 /* Change window height NOW */
8486 if (lastwin != firstwin)
8487 {
8488 if (pp == &p_wh && curwin->w_height < p_wh)
8489 win_setheight((int)p_wh);
8490 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8491 win_setheight((int)p_hh);
8492 }
8493 }
8494
8495 /* 'winminheight' */
8496 else if (pp == &p_wmh)
8497 {
8498 if (p_wmh < 0)
8499 {
8500 errmsg = e_positive;
8501 p_wmh = 0;
8502 }
8503 if (p_wmh > p_wh)
8504 {
8505 errmsg = e_winheight;
8506 p_wmh = p_wh;
8507 }
8508 win_setminheight();
8509 }
8510
8511# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008512 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008513 {
8514 if (p_wiw < 1)
8515 {
8516 errmsg = e_positive;
8517 p_wiw = 1;
8518 }
8519 if (p_wmw > p_wiw)
8520 {
8521 errmsg = e_winwidth;
8522 p_wiw = p_wmw;
8523 }
8524
8525 /* Change window width NOW */
8526 if (lastwin != firstwin && curwin->w_width < p_wiw)
8527 win_setwidth((int)p_wiw);
8528 }
8529
8530 /* 'winminwidth' */
8531 else if (pp == &p_wmw)
8532 {
8533 if (p_wmw < 0)
8534 {
8535 errmsg = e_positive;
8536 p_wmw = 0;
8537 }
8538 if (p_wmw > p_wiw)
8539 {
8540 errmsg = e_winwidth;
8541 p_wmw = p_wiw;
8542 }
8543 win_setminheight();
8544 }
8545# endif
8546
8547#endif
8548
8549#ifdef FEAT_WINDOWS
8550 /* (re)set last window status line */
8551 else if (pp == &p_ls)
8552 {
8553 last_status(FALSE);
8554 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008555
8556 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008557 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008558 {
8559 shell_new_rows(); /* recompute window positions and heights */
8560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561#endif
8562
8563#ifdef FEAT_GUI
8564 else if (pp == &p_linespace)
8565 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008566 /* Recompute gui.char_height and resize the Vim window to keep the
8567 * same number of lines. */
8568 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008569 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008570 }
8571#endif
8572
8573#ifdef FEAT_FOLDING
8574 /* 'foldlevel' */
8575 else if (pp == &curwin->w_p_fdl)
8576 {
8577 if (curwin->w_p_fdl < 0)
8578 curwin->w_p_fdl = 0;
8579 newFoldLevel();
8580 }
8581
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008582 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008583 else if (pp == &curwin->w_p_fml)
8584 {
8585 foldUpdateAll(curwin);
8586 }
8587
8588 /* 'foldnestmax' */
8589 else if (pp == &curwin->w_p_fdn)
8590 {
8591 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8592 foldUpdateAll(curwin);
8593 }
8594
8595 /* 'foldcolumn' */
8596 else if (pp == &curwin->w_p_fdc)
8597 {
8598 if (curwin->w_p_fdc < 0)
8599 {
8600 errmsg = e_positive;
8601 curwin->w_p_fdc = 0;
8602 }
8603 else if (curwin->w_p_fdc > 12)
8604 {
8605 errmsg = e_invarg;
8606 curwin->w_p_fdc = 12;
8607 }
8608 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008609#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008610
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008611#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008612 /* 'shiftwidth' or 'tabstop' */
8613 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8614 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008615# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008616 if (foldmethodIsIndent(curwin))
8617 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008618# endif
8619# ifdef FEAT_CINDENT
8620 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8621 * parse 'cinoptions'. */
8622 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8623 parse_cino(curbuf);
8624# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008626#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008627
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008628#ifdef FEAT_MBYTE
8629 /* 'maxcombine' */
8630 else if (pp == &p_mco)
8631 {
8632 if (p_mco > MAX_MCO)
8633 p_mco = MAX_MCO;
8634 else if (p_mco < 0)
8635 p_mco = 0;
8636 screenclear(); /* will re-allocate the screen */
8637 }
8638#endif
8639
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640 else if (pp == &curbuf->b_p_iminsert)
8641 {
8642 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8643 {
8644 errmsg = e_invarg;
8645 curbuf->b_p_iminsert = B_IMODE_NONE;
8646 }
8647 p_iminsert = curbuf->b_p_iminsert;
8648 if (termcap_active) /* don't do this in the alternate screen */
8649 showmode();
8650#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8651 /* Show/unshow value of 'keymap' in status lines. */
8652 status_redraw_curbuf();
8653#endif
8654 }
8655
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008656 else if (pp == &p_window)
8657 {
8658 if (p_window < 1)
8659 p_window = 1;
8660 else if (p_window >= Rows)
8661 p_window = Rows - 1;
8662 }
8663
Bram Moolenaar071d4272004-06-13 20:20:40 +00008664 else if (pp == &curbuf->b_p_imsearch)
8665 {
8666 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8667 {
8668 errmsg = e_invarg;
8669 curbuf->b_p_imsearch = B_IMODE_NONE;
8670 }
8671 p_imsearch = curbuf->b_p_imsearch;
8672 }
8673
8674#ifdef FEAT_TITLE
8675 /* if 'titlelen' has changed, redraw the title */
8676 else if (pp == &p_titlelen)
8677 {
8678 if (p_titlelen < 0)
8679 {
8680 errmsg = e_positive;
8681 p_titlelen = 85;
8682 }
8683 if (starting != NO_SCREEN && old_value != p_titlelen)
8684 need_maketitle = TRUE;
8685 }
8686#endif
8687
8688 /* if p_ch changed value, change the command line height */
8689 else if (pp == &p_ch)
8690 {
8691 if (p_ch < 1)
8692 {
8693 errmsg = e_positive;
8694 p_ch = 1;
8695 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008696 if (p_ch > Rows - min_rows() + 1)
8697 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008698
8699 /* Only compute the new window layout when startup has been
8700 * completed. Otherwise the frame sizes may be wrong. */
8701 if (p_ch != old_value && full_screen
8702#ifdef FEAT_GUI
8703 && !gui.starting
8704#endif
8705 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008706 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008707 }
8708
8709 /* when 'updatecount' changes from zero to non-zero, open swap files */
8710 else if (pp == &p_uc)
8711 {
8712 if (p_uc < 0)
8713 {
8714 errmsg = e_positive;
8715 p_uc = 100;
8716 }
8717 if (p_uc && !old_value)
8718 ml_open_files();
8719 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008720#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008721 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008722 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008723 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008724 {
8725 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008726 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008727 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008728 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008729 {
8730 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008731 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008732 }
8733 }
8734#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008735#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008736 else if (pp == &p_mzq)
8737 mzvim_reset_timer();
8738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008739
8740 /* sync undo before 'undolevels' changes */
8741 else if (pp == &p_ul)
8742 {
8743 /* use the old value, otherwise u_sync() may not work properly */
8744 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008745 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008746 p_ul = value;
8747 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008748 else if (pp == &curbuf->b_p_ul)
8749 {
8750 /* use the old value, otherwise u_sync() may not work properly */
8751 curbuf->b_p_ul = old_value;
8752 u_sync(TRUE);
8753 curbuf->b_p_ul = value;
8754 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008756#ifdef FEAT_LINEBREAK
8757 /* 'numberwidth' must be positive */
8758 else if (pp == &curwin->w_p_nuw)
8759 {
8760 if (curwin->w_p_nuw < 1)
8761 {
8762 errmsg = e_positive;
8763 curwin->w_p_nuw = 1;
8764 }
8765 if (curwin->w_p_nuw > 10)
8766 {
8767 errmsg = e_invarg;
8768 curwin->w_p_nuw = 10;
8769 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008770 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008771 }
8772#endif
8773
Bram Moolenaar1a384422010-07-14 19:53:30 +02008774 else if (pp == &curbuf->b_p_tw)
8775 {
8776 if (curbuf->b_p_tw < 0)
8777 {
8778 errmsg = e_positive;
8779 curbuf->b_p_tw = 0;
8780 }
8781#ifdef FEAT_SYN_HL
8782# ifdef FEAT_WINDOWS
8783 {
8784 win_T *wp;
8785 tabpage_T *tp;
8786
8787 FOR_ALL_TAB_WINDOWS(tp, wp)
8788 check_colorcolumn(wp);
8789 }
8790# else
8791 check_colorcolumn(curwin);
8792# endif
8793#endif
8794 }
8795
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796 /*
8797 * Check the bounds for numeric options here
8798 */
8799 if (Rows < min_rows() && full_screen)
8800 {
8801 if (errbuf != NULL)
8802 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008803 vim_snprintf((char *)errbuf, errbuflen,
8804 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008805 errmsg = errbuf;
8806 }
8807 Rows = min_rows();
8808 }
8809 if (Columns < MIN_COLUMNS && full_screen)
8810 {
8811 if (errbuf != NULL)
8812 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008813 vim_snprintf((char *)errbuf, errbuflen,
8814 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008815 errmsg = errbuf;
8816 }
8817 Columns = MIN_COLUMNS;
8818 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008819 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008820
8821#ifdef DJGPP
8822 /* avoid a crash by checking for a too large value of 'columns' */
8823 if (old_Columns != Columns && full_screen && term_console)
8824 mch_check_columns();
8825#endif
8826
8827 /*
8828 * If the screen (shell) height has been changed, assume it is the
8829 * physical screenheight.
8830 */
8831 if (old_Rows != Rows || old_Columns != Columns)
8832 {
8833 /* Changing the screen size is not allowed while updating the screen. */
8834 if (updating_screen)
8835 *pp = old_value;
8836 else if (full_screen
8837#ifdef FEAT_GUI
8838 && !gui.starting
8839#endif
8840 )
8841 set_shellsize((int)Columns, (int)Rows, TRUE);
8842 else
8843 {
8844 /* Postpone the resizing; check the size and cmdline position for
8845 * messages. */
8846 check_shellsize();
8847 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8848 cmdline_row = Rows - p_ch;
8849 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008850 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008851 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852 }
8853
Bram Moolenaar071d4272004-06-13 20:20:40 +00008854 if (curbuf->b_p_ts <= 0)
8855 {
8856 errmsg = e_positive;
8857 curbuf->b_p_ts = 8;
8858 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008859 if (p_tm < 0)
8860 {
8861 errmsg = e_positive;
8862 p_tm = 0;
8863 }
8864 if ((curwin->w_p_scr <= 0
8865 || (curwin->w_p_scr > curwin->w_height
8866 && curwin->w_height > 0))
8867 && full_screen)
8868 {
8869 if (pp == &(curwin->w_p_scr))
8870 {
8871 if (curwin->w_p_scr != 0)
8872 errmsg = e_scroll;
8873 win_comp_scroll(curwin);
8874 }
8875 /* If 'scroll' became invalid because of a side effect silently adjust
8876 * it. */
8877 else if (curwin->w_p_scr <= 0)
8878 curwin->w_p_scr = 1;
8879 else /* curwin->w_p_scr > curwin->w_height */
8880 curwin->w_p_scr = curwin->w_height;
8881 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008882 if (p_hi < 0)
8883 {
8884 errmsg = e_positive;
8885 p_hi = 0;
8886 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008887 else if (p_hi > 10000)
8888 {
8889 errmsg = e_invarg;
8890 p_hi = 10000;
8891 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008892 if (p_re < 0 || p_re > 2)
8893 {
8894 errmsg = e_invarg;
8895 p_re = 0;
8896 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008897 if (p_report < 0)
8898 {
8899 errmsg = e_positive;
8900 p_report = 1;
8901 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008902 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008903 {
8904 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8905 p_sj = Rows / 2;
8906 else
8907 {
8908 errmsg = e_scroll;
8909 p_sj = 1;
8910 }
8911 }
8912 if (p_so < 0 && full_screen)
8913 {
8914 errmsg = e_scroll;
8915 p_so = 0;
8916 }
8917 if (p_siso < 0 && full_screen)
8918 {
8919 errmsg = e_positive;
8920 p_siso = 0;
8921 }
8922#ifdef FEAT_CMDWIN
8923 if (p_cwh < 1)
8924 {
8925 errmsg = e_positive;
8926 p_cwh = 1;
8927 }
8928#endif
8929 if (p_ut < 0)
8930 {
8931 errmsg = e_positive;
8932 p_ut = 2000;
8933 }
8934 if (p_ss < 0)
8935 {
8936 errmsg = e_positive;
8937 p_ss = 0;
8938 }
8939
8940 /* May set global value for local option. */
8941 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8942 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8943
8944 options[opt_idx].flags |= P_WAS_SET;
8945
Bram Moolenaar53744302015-07-17 17:38:22 +02008946#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8947 if (!starting && errmsg == NULL)
8948 {
8949 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008950 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8951 vim_snprintf((char *)buf_new, 10, "%ld", value);
8952 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008953 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8954 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8955 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8956 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8957 reset_v_option_vars();
8958 }
8959#endif
8960
Bram Moolenaar071d4272004-06-13 20:20:40 +00008961 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008962 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008963 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008964 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965 check_redraw(options[opt_idx].flags);
8966
8967 return errmsg;
8968}
8969
8970/*
8971 * Called after an option changed: check if something needs to be redrawn.
8972 */
8973 static void
8974check_redraw(flags)
8975 long_u flags;
8976{
8977 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008978 int doclear = (flags & P_RCLR) == P_RCLR;
8979 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980
8981#ifdef FEAT_WINDOWS
8982 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8983 status_redraw_all();
8984#endif
8985
8986 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8987 changed_window_setting();
8988 if (flags & P_RBUF)
8989 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008990 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008991 redraw_all_later(CLEAR);
8992 else if (all)
8993 redraw_all_later(NOT_VALID);
8994}
8995
8996/*
8997 * Find index for option 'arg'.
8998 * Return -1 if not found.
8999 */
9000 static int
9001findoption(arg)
9002 char_u *arg;
9003{
9004 int opt_idx;
9005 char *s, *p;
9006 static short quick_tab[27] = {0, 0}; /* quick access table */
9007 int is_term_opt;
9008
9009 /*
9010 * For first call: Initialize the quick-access table.
9011 * It contains the index for the first option that starts with a certain
9012 * letter. There are 26 letters, plus the first "t_" option.
9013 */
9014 if (quick_tab[1] == 0)
9015 {
9016 p = options[0].fullname;
9017 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9018 {
9019 if (s[0] != p[0])
9020 {
9021 if (s[0] == 't' && s[1] == '_')
9022 quick_tab[26] = opt_idx;
9023 else
9024 quick_tab[CharOrdLow(s[0])] = opt_idx;
9025 }
9026 p = s;
9027 }
9028 }
9029
9030 /*
9031 * Check for name starting with an illegal character.
9032 */
9033#ifdef EBCDIC
9034 if (!islower(arg[0]))
9035#else
9036 if (arg[0] < 'a' || arg[0] > 'z')
9037#endif
9038 return -1;
9039
9040 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9041 if (is_term_opt)
9042 opt_idx = quick_tab[26];
9043 else
9044 opt_idx = quick_tab[CharOrdLow(arg[0])];
9045 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9046 {
9047 if (STRCMP(arg, s) == 0) /* match full name */
9048 break;
9049 }
9050 if (s == NULL && !is_term_opt)
9051 {
9052 opt_idx = quick_tab[CharOrdLow(arg[0])];
9053 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9054 {
9055 s = options[opt_idx].shortname;
9056 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9057 break;
9058 s = NULL;
9059 }
9060 }
9061 if (s == NULL)
9062 opt_idx = -1;
9063 return opt_idx;
9064}
9065
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009066#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009067/*
9068 * Get the value for an option.
9069 *
9070 * Returns:
9071 * Number or Toggle option: 1, *numval gets value.
9072 * String option: 0, *stringval gets allocated string.
9073 * Hidden Number or Toggle option: -1.
9074 * hidden String option: -2.
9075 * unknown option: -3.
9076 */
9077 int
9078get_option_value(name, numval, stringval, opt_flags)
9079 char_u *name;
9080 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02009081 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009082 int opt_flags;
9083{
9084 int opt_idx;
9085 char_u *varp;
9086
9087 opt_idx = findoption(name);
9088 if (opt_idx < 0) /* unknown option */
9089 return -3;
9090
9091 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9092
9093 if (options[opt_idx].flags & P_STRING)
9094 {
9095 if (varp == NULL) /* hidden option */
9096 return -2;
9097 if (stringval != NULL)
9098 {
9099#ifdef FEAT_CRYPT
9100 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009101 if ((char_u **)varp == &curbuf->b_p_key
9102 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103 *stringval = vim_strsave((char_u *)"*****");
9104 else
9105#endif
9106 *stringval = vim_strsave(*(char_u **)(varp));
9107 }
9108 return 0;
9109 }
9110
9111 if (varp == NULL) /* hidden option */
9112 return -1;
9113 if (options[opt_idx].flags & P_NUM)
9114 *numval = *(long *)varp;
9115 else
9116 {
9117 /* Special case: 'modified' is b_changed, but we also want to consider
9118 * it set when 'ff' or 'fenc' changed. */
9119 if ((int *)varp == &curbuf->b_changed)
9120 *numval = curbufIsChanged();
9121 else
9122 *numval = *(int *)varp;
9123 }
9124 return 1;
9125}
9126#endif
9127
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009128#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009129/*
9130 * Returns the option attributes and its value. Unlike the above function it
9131 * will return either global value or local value of the option depending on
9132 * what was requested, but it will never return global value if it was
9133 * requested to return local one and vice versa. Neither it will return
9134 * buffer-local value if it was requested to return window-local one.
9135 *
9136 * Pretends that option is absent if it is not present in the requested scope
9137 * (i.e. has no global, window-local or buffer-local value depending on
9138 * opt_type). Uses
9139 *
9140 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009141 * 0 hidden or unknown option, also option that does not have requested
9142 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009143 * see SOPT_* in vim.h for other flags
9144 *
9145 * Possible opt_type values: see SREQ_* in vim.h
9146 */
9147 int
9148get_option_value_strict(name, numval, stringval, opt_type, from)
9149 char_u *name;
9150 long *numval;
9151 char_u **stringval; /* NULL when only obtaining attributes */
9152 int opt_type;
9153 void *from;
9154{
9155 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009156 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009157 struct vimoption *p;
9158 int r = 0;
9159
9160 opt_idx = findoption(name);
9161 if (opt_idx < 0)
9162 return 0;
9163
9164 p = &(options[opt_idx]);
9165
9166 /* Hidden option */
9167 if (p->var == NULL)
9168 return 0;
9169
9170 if (p->flags & P_BOOL)
9171 r |= SOPT_BOOL;
9172 else if (p->flags & P_NUM)
9173 r |= SOPT_NUM;
9174 else if (p->flags & P_STRING)
9175 r |= SOPT_STRING;
9176
9177 if (p->indir == PV_NONE)
9178 {
9179 if (opt_type == SREQ_GLOBAL)
9180 r |= SOPT_GLOBAL;
9181 else
9182 return 0; /* Did not request global-only option */
9183 }
9184 else
9185 {
9186 if (p->indir & PV_BOTH)
9187 r |= SOPT_GLOBAL;
9188 else if (opt_type == SREQ_GLOBAL)
9189 return 0; /* Requested global option */
9190
9191 if (p->indir & PV_WIN)
9192 {
9193 if (opt_type == SREQ_BUF)
9194 return 0; /* Did not request window-local option */
9195 else
9196 r |= SOPT_WIN;
9197 }
9198 else if (p->indir & PV_BUF)
9199 {
9200 if (opt_type == SREQ_WIN)
9201 return 0; /* Did not request buffer-local option */
9202 else
9203 r |= SOPT_BUF;
9204 }
9205 }
9206
9207 if (stringval == NULL)
9208 return r;
9209
9210 if (opt_type == SREQ_GLOBAL)
9211 varp = p->var;
9212 else
9213 {
9214 if (opt_type == SREQ_BUF)
9215 {
9216 /* Special case: 'modified' is b_changed, but we also want to
9217 * consider it set when 'ff' or 'fenc' changed. */
9218 if (p->indir == PV_MOD)
9219 {
9220 *numval = bufIsChanged((buf_T *) from);
9221 varp = NULL;
9222 }
9223#ifdef FEAT_CRYPT
9224 else if (p->indir == PV_KEY)
9225 {
9226 /* never return the value of the crypt key */
9227 *stringval = NULL;
9228 varp = NULL;
9229 }
9230#endif
9231 else
9232 {
9233 aco_save_T aco;
9234 aucmd_prepbuf(&aco, (buf_T *) from);
9235 varp = get_varp(p);
9236 aucmd_restbuf(&aco);
9237 }
9238 }
9239 else if (opt_type == SREQ_WIN)
9240 {
9241 win_T *save_curwin;
9242 save_curwin = curwin;
9243 curwin = (win_T *) from;
9244 curbuf = curwin->w_buffer;
9245 varp = get_varp(p);
9246 curwin = save_curwin;
9247 curbuf = curwin->w_buffer;
9248 }
9249 if (varp == p->var)
9250 return (r | SOPT_UNSET);
9251 }
9252
9253 if (varp != NULL)
9254 {
9255 if (p->flags & P_STRING)
9256 *stringval = vim_strsave(*(char_u **)(varp));
9257 else if (p->flags & P_NUM)
9258 *numval = *(long *) varp;
9259 else
9260 *numval = *(int *)varp;
9261 }
9262
9263 return r;
9264}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009265
9266/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009267 * Iterate over options. First argument is a pointer to a pointer to a
9268 * structure inside options[] array, second is option type like in the above
9269 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009270 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009271 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009272 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009273 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009274 * first argument to NULL.
9275 *
9276 * Returns full option name for current option on each call.
9277 */
9278 char_u *
9279option_iter_next(option, opt_type)
9280 void **option;
9281 int opt_type;
9282{
9283 struct vimoption *ret = NULL;
9284 do
9285 {
9286 if (*option == NULL)
9287 *option = (void *) options;
9288 else if (((struct vimoption *) (*option))->fullname == NULL)
9289 {
9290 *option = NULL;
9291 return NULL;
9292 }
9293 else
9294 *option = (void *) (((struct vimoption *) (*option)) + 1);
9295
9296 ret = ((struct vimoption *) (*option));
9297
9298 /* Hidden option */
9299 if (ret->var == NULL)
9300 {
9301 ret = NULL;
9302 continue;
9303 }
9304
9305 switch (opt_type)
9306 {
9307 case SREQ_GLOBAL:
9308 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9309 ret = NULL;
9310 break;
9311 case SREQ_BUF:
9312 if (!(ret->indir & PV_BUF))
9313 ret = NULL;
9314 break;
9315 case SREQ_WIN:
9316 if (!(ret->indir & PV_WIN))
9317 ret = NULL;
9318 break;
9319 default:
9320 EMSG2(_(e_intern2), "option_iter_next()");
9321 return NULL;
9322 }
9323 }
9324 while (ret == NULL);
9325
9326 return (char_u *)ret->fullname;
9327}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009328#endif
9329
Bram Moolenaar071d4272004-06-13 20:20:40 +00009330/*
9331 * Set the value of option "name".
9332 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009333 *
9334 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009336 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337set_option_value(name, number, string, opt_flags)
9338 char_u *name;
9339 long number;
9340 char_u *string;
9341 int opt_flags; /* OPT_LOCAL or 0 (both) */
9342{
9343 int opt_idx;
9344 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009345 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009346
9347 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009348 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009349 EMSG2(_("E355: Unknown option: %s"), name);
9350 else
9351 {
9352 flags = options[opt_idx].flags;
9353#ifdef HAVE_SANDBOX
9354 /* Disallow changing some options in the sandbox */
9355 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009356 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009357 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009358 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009360#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009361 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009362 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009363 else
9364 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009365 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009366 if (varp != NULL) /* hidden option is not changed */
9367 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009368 if (number == 0 && string != NULL)
9369 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009370 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009371
9372 /* Either we are given a string or we are setting option
9373 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009374 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009375 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009376 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009377 {
9378 /* There's another character after zeros or the string
9379 * is empty. In both cases, we are trying to set a
9380 * num option using a string. */
9381 EMSG3(_("E521: Number required: &%s = '%s'"),
9382 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009383 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009384
9385 }
9386 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009387 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009388 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009389 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009390 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009391 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009392 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009393 }
9394 }
9395 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009396 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009397}
9398
9399/*
9400 * Get the terminal code for a terminal option.
9401 * Returns NULL when not found.
9402 */
9403 char_u *
9404get_term_code(tname)
9405 char_u *tname;
9406{
9407 int opt_idx;
9408 char_u *varp;
9409
9410 if (tname[0] != 't' || tname[1] != '_' ||
9411 tname[2] == NUL || tname[3] == NUL)
9412 return NULL;
9413 if ((opt_idx = findoption(tname)) >= 0)
9414 {
9415 varp = get_varp(&(options[opt_idx]));
9416 if (varp != NULL)
9417 varp = *(char_u **)(varp);
9418 return varp;
9419 }
9420 return find_termcode(tname + 2);
9421}
9422
9423 char_u *
9424get_highlight_default()
9425{
9426 int i;
9427
9428 i = findoption((char_u *)"hl");
9429 if (i >= 0)
9430 return options[i].def_val[VI_DEFAULT];
9431 return (char_u *)NULL;
9432}
9433
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009434#if defined(FEAT_MBYTE) || defined(PROTO)
9435 char_u *
9436get_encoding_default()
9437{
9438 int i;
9439
9440 i = findoption((char_u *)"enc");
9441 if (i >= 0)
9442 return options[i].def_val[VI_DEFAULT];
9443 return (char_u *)NULL;
9444}
9445#endif
9446
Bram Moolenaar071d4272004-06-13 20:20:40 +00009447/*
9448 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9449 */
9450 static int
9451find_key_option(arg)
9452 char_u *arg;
9453{
9454 int key;
9455 int modifiers;
9456
9457 /*
9458 * Don't use get_special_key_code() for t_xx, we don't want it to call
9459 * add_termcap_entry().
9460 */
9461 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9462 key = TERMCAP2KEY(arg[2], arg[3]);
9463 else
9464 {
9465 --arg; /* put arg at the '<' */
9466 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009467 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009468 if (modifiers) /* can't handle modifiers here */
9469 key = 0;
9470 }
9471 return key;
9472}
9473
9474/*
9475 * if 'all' == 0: show changed options
9476 * if 'all' == 1: show all normal options
9477 * if 'all' == 2: show all terminal options
9478 */
9479 static void
9480showoptions(all, opt_flags)
9481 int all;
9482 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9483{
9484 struct vimoption *p;
9485 int col;
9486 int isterm;
9487 char_u *varp;
9488 struct vimoption **items;
9489 int item_count;
9490 int run;
9491 int row, rows;
9492 int cols;
9493 int i;
9494 int len;
9495
9496#define INC 20
9497#define GAP 3
9498
9499 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9500 PARAM_COUNT));
9501 if (items == NULL)
9502 return;
9503
9504 /* Highlight title */
9505 if (all == 2)
9506 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9507 else if (opt_flags & OPT_GLOBAL)
9508 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9509 else if (opt_flags & OPT_LOCAL)
9510 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9511 else
9512 MSG_PUTS_TITLE(_("\n--- Options ---"));
9513
9514 /*
9515 * do the loop two times:
9516 * 1. display the short items
9517 * 2. display the long items (only strings and numbers)
9518 */
9519 for (run = 1; run <= 2 && !got_int; ++run)
9520 {
9521 /*
9522 * collect the items in items[]
9523 */
9524 item_count = 0;
9525 for (p = &options[0]; p->fullname != NULL; p++)
9526 {
9527 varp = NULL;
9528 isterm = istermoption(p);
9529 if (opt_flags != 0)
9530 {
9531 if (p->indir != PV_NONE && !isterm)
9532 varp = get_varp_scope(p, opt_flags);
9533 }
9534 else
9535 varp = get_varp(p);
9536 if (varp != NULL
9537 && ((all == 2 && isterm)
9538 || (all == 1 && !isterm)
9539 || (all == 0 && !optval_default(p, varp))))
9540 {
9541 if (p->flags & P_BOOL)
9542 len = 1; /* a toggle option fits always */
9543 else
9544 {
9545 option_value2string(p, opt_flags);
9546 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9547 }
9548 if ((len <= INC - GAP && run == 1) ||
9549 (len > INC - GAP && run == 2))
9550 items[item_count++] = p;
9551 }
9552 }
9553
9554 /*
9555 * display the items
9556 */
9557 if (run == 1)
9558 {
9559 cols = (Columns + GAP - 3) / INC;
9560 if (cols == 0)
9561 cols = 1;
9562 rows = (item_count + cols - 1) / cols;
9563 }
9564 else /* run == 2 */
9565 rows = item_count;
9566 for (row = 0; row < rows && !got_int; ++row)
9567 {
9568 msg_putchar('\n'); /* go to next line */
9569 if (got_int) /* 'q' typed in more */
9570 break;
9571 col = 0;
9572 for (i = row; i < item_count; i += rows)
9573 {
9574 msg_col = col; /* make columns */
9575 showoneopt(items[i], opt_flags);
9576 col += INC;
9577 }
9578 out_flush();
9579 ui_breakcheck();
9580 }
9581 }
9582 vim_free(items);
9583}
9584
9585/*
9586 * Return TRUE if option "p" has its default value.
9587 */
9588 static int
9589optval_default(p, varp)
9590 struct vimoption *p;
9591 char_u *varp;
9592{
9593 int dvi;
9594
9595 if (varp == NULL)
9596 return TRUE; /* hidden option is always at default */
9597 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9598 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009599 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009600 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009601 /* the cast to long is required for Manx C, long_i is
9602 * needed for MSVC */
9603 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009604 /* P_STRING */
9605 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9606}
9607
9608/*
9609 * showoneopt: show the value of one option
9610 * must not be called with a hidden option!
9611 */
9612 static void
9613showoneopt(p, opt_flags)
9614 struct vimoption *p;
9615 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9616{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009617 char_u *varp;
9618 int save_silent = silent_mode;
9619
9620 silent_mode = FALSE;
9621 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009622
9623 varp = get_varp_scope(p, opt_flags);
9624
9625 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9626 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9627 ? !curbufIsChanged() : !*(int *)varp))
9628 MSG_PUTS("no");
9629 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9630 MSG_PUTS("--");
9631 else
9632 MSG_PUTS(" ");
9633 MSG_PUTS(p->fullname);
9634 if (!(p->flags & P_BOOL))
9635 {
9636 msg_putchar('=');
9637 /* put value string in NameBuff */
9638 option_value2string(p, opt_flags);
9639 msg_outtrans(NameBuff);
9640 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009641
9642 silent_mode = save_silent;
9643 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009644}
9645
9646/*
9647 * Write modified options as ":set" commands to a file.
9648 *
9649 * There are three values for "opt_flags":
9650 * OPT_GLOBAL: Write global option values and fresh values of
9651 * buffer-local options (used for start of a session
9652 * file).
9653 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9654 * curwin (used for a vimrc file).
9655 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9656 * and local values for window-local options of
9657 * curwin. Local values are also written when at the
9658 * default value, because a modeline or autocommand
9659 * may have set them when doing ":edit file" and the
9660 * user has set them back at the default or fresh
9661 * value.
9662 * When "local_only" is TRUE, don't write fresh
9663 * values, only local values (for ":mkview").
9664 * (fresh value = value used for a new buffer or window for a local option).
9665 *
9666 * Return FAIL on error, OK otherwise.
9667 */
9668 int
9669makeset(fd, opt_flags, local_only)
9670 FILE *fd;
9671 int opt_flags;
9672 int local_only;
9673{
9674 struct vimoption *p;
9675 char_u *varp; /* currently used value */
9676 char_u *varp_fresh; /* local value */
9677 char_u *varp_local = NULL; /* fresh value */
9678 char *cmd;
9679 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009680 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009681
9682 /*
9683 * The options that don't have a default (terminal name, columns, lines)
9684 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009685 * Do the loop over "options[]" twice: once for options with the
9686 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009687 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009688 for (pri = 1; pri >= 0; --pri)
9689 {
9690 for (p = &options[0]; !istermoption(p); p++)
9691 if (!(p->flags & P_NO_MKRC)
9692 && !istermoption(p)
9693 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009694 {
9695 /* skip global option when only doing locals */
9696 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9697 continue;
9698
9699 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9700 * file, they are always buffer-specific. */
9701 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9702 continue;
9703
9704 /* Global values are only written when not at the default value. */
9705 varp = get_varp_scope(p, opt_flags);
9706 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9707 continue;
9708
9709 round = 2;
9710 if (p->indir != PV_NONE)
9711 {
9712 if (p->var == VAR_WIN)
9713 {
9714 /* skip window-local option when only doing globals */
9715 if (!(opt_flags & OPT_LOCAL))
9716 continue;
9717 /* When fresh value of window-local option is not at the
9718 * default, need to write it too. */
9719 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9720 {
9721 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9722 if (!optval_default(p, varp_fresh))
9723 {
9724 round = 1;
9725 varp_local = varp;
9726 varp = varp_fresh;
9727 }
9728 }
9729 }
9730 }
9731
9732 /* Round 1: fresh value for window-local options.
9733 * Round 2: other values */
9734 for ( ; round <= 2; varp = varp_local, ++round)
9735 {
9736 if (round == 1 || (opt_flags & OPT_GLOBAL))
9737 cmd = "set";
9738 else
9739 cmd = "setlocal";
9740
9741 if (p->flags & P_BOOL)
9742 {
9743 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9744 return FAIL;
9745 }
9746 else if (p->flags & P_NUM)
9747 {
9748 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9749 return FAIL;
9750 }
9751 else /* P_STRING */
9752 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009753#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9754 int do_endif = FALSE;
9755
Bram Moolenaar071d4272004-06-13 20:20:40 +00009756 /* Don't set 'syntax' and 'filetype' again if the value is
9757 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009758 if (
9759# if defined(FEAT_SYN_HL)
9760 p->indir == PV_SYN
9761# if defined(FEAT_AUTOCMD)
9762 ||
9763# endif
9764# endif
9765# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009766 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009767# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009768 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009769 {
9770 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9771 *(char_u **)(varp)) < 0
9772 || put_eol(fd) < 0)
9773 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009774 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009775 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009776#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009777 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9778 (p->flags & P_EXPAND) != 0) == FAIL)
9779 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009780#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9781 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009782 {
9783 if (put_line(fd, "endif") == FAIL)
9784 return FAIL;
9785 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009786#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009787 }
9788 }
9789 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009790 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009791 return OK;
9792}
9793
9794#if defined(FEAT_FOLDING) || defined(PROTO)
9795/*
9796 * Generate set commands for the local fold options only. Used when
9797 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9798 */
9799 int
9800makefoldset(fd)
9801 FILE *fd;
9802{
9803 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9804# ifdef FEAT_EVAL
9805 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9806 == FAIL
9807# endif
9808 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9809 == FAIL
9810 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9811 == FAIL
9812 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9813 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9814 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9815 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9816 )
9817 return FAIL;
9818
9819 return OK;
9820}
9821#endif
9822
9823 static int
9824put_setstring(fd, cmd, name, valuep, expand)
9825 FILE *fd;
9826 char *cmd;
9827 char *name;
9828 char_u **valuep;
9829 int expand;
9830{
9831 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009832 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009833
9834 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9835 return FAIL;
9836 if (*valuep != NULL)
9837 {
9838 /* Output 'pastetoggle' as key names. For other
9839 * options some characters have to be escaped with
9840 * CTRL-V or backslash */
9841 if (valuep == &p_pt)
9842 {
9843 s = *valuep;
9844 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009845 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009846 return FAIL;
9847 }
9848 else if (expand)
9849 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009850 buf = alloc(MAXPATHL);
9851 if (buf == NULL)
9852 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009853 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9854 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009855 {
9856 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009857 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009858 }
9859 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009860 }
9861 else if (put_escstr(fd, *valuep, 2) == FAIL)
9862 return FAIL;
9863 }
9864 if (put_eol(fd) < 0)
9865 return FAIL;
9866 return OK;
9867}
9868
9869 static int
9870put_setnum(fd, cmd, name, valuep)
9871 FILE *fd;
9872 char *cmd;
9873 char *name;
9874 long *valuep;
9875{
9876 long wc;
9877
9878 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9879 return FAIL;
9880 if (wc_use_keyname((char_u *)valuep, &wc))
9881 {
9882 /* print 'wildchar' and 'wildcharm' as a key name */
9883 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9884 return FAIL;
9885 }
9886 else if (fprintf(fd, "%ld", *valuep) < 0)
9887 return FAIL;
9888 if (put_eol(fd) < 0)
9889 return FAIL;
9890 return OK;
9891}
9892
9893 static int
9894put_setbool(fd, cmd, name, value)
9895 FILE *fd;
9896 char *cmd;
9897 char *name;
9898 int value;
9899{
Bram Moolenaar893de922007-10-02 18:40:57 +00009900 if (value < 0) /* global/local option using global value */
9901 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009902 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9903 || put_eol(fd) < 0)
9904 return FAIL;
9905 return OK;
9906}
9907
9908/*
9909 * Clear all the terminal options.
9910 * If the option has been allocated, free the memory.
9911 * Terminal options are never hidden or indirect.
9912 */
9913 void
9914clear_termoptions()
9915{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009916 /*
9917 * Reset a few things before clearing the old options. This may cause
9918 * outputting a few things that the terminal doesn't understand, but the
9919 * screen will be cleared later, so this is OK.
9920 */
9921#ifdef FEAT_MOUSE_TTY
9922 mch_setmouse(FALSE); /* switch mouse off */
9923#endif
9924#ifdef FEAT_TITLE
9925 mch_restore_title(3); /* restore window titles */
9926#endif
9927#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9928 /* When starting the GUI close the display opened for the clipboard.
9929 * After restoring the title, because that will need the display. */
9930 if (gui.starting)
9931 clear_xterm_clip();
9932#endif
9933#ifdef WIN3264
9934 /*
9935 * Check if this is allowed now.
9936 */
9937 if (can_end_termcap_mode(FALSE) == TRUE)
9938#endif
9939 stoptermcap(); /* stop termcap mode */
9940
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009941 free_termoptions();
9942}
9943
9944 void
9945free_termoptions()
9946{
9947 struct vimoption *p;
9948
Bram Moolenaar071d4272004-06-13 20:20:40 +00009949 for (p = &options[0]; p->fullname != NULL; p++)
9950 if (istermoption(p))
9951 {
9952 if (p->flags & P_ALLOCED)
9953 free_string_option(*(char_u **)(p->var));
9954 if (p->flags & P_DEF_ALLOCED)
9955 free_string_option(p->def_val[VI_DEFAULT]);
9956 *(char_u **)(p->var) = empty_option;
9957 p->def_val[VI_DEFAULT] = empty_option;
9958 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9959 }
9960 clear_termcodes();
9961}
9962
9963/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009964 * Free the string for one term option, if it was allocated.
9965 * Set the string to empty_option and clear allocated flag.
9966 * "var" points to the option value.
9967 */
9968 void
9969free_one_termoption(var)
9970 char_u *var;
9971{
9972 struct vimoption *p;
9973
9974 for (p = &options[0]; p->fullname != NULL; p++)
9975 if (p->var == var)
9976 {
9977 if (p->flags & P_ALLOCED)
9978 free_string_option(*(char_u **)(p->var));
9979 *(char_u **)(p->var) = empty_option;
9980 p->flags &= ~P_ALLOCED;
9981 break;
9982 }
9983}
9984
9985/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009986 * Set the terminal option defaults to the current value.
9987 * Used after setting the terminal name.
9988 */
9989 void
9990set_term_defaults()
9991{
9992 struct vimoption *p;
9993
9994 for (p = &options[0]; p->fullname != NULL; p++)
9995 {
9996 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9997 {
9998 if (p->flags & P_DEF_ALLOCED)
9999 {
10000 free_string_option(p->def_val[VI_DEFAULT]);
10001 p->flags &= ~P_DEF_ALLOCED;
10002 }
10003 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10004 if (p->flags & P_ALLOCED)
10005 {
10006 p->flags |= P_DEF_ALLOCED;
10007 p->flags &= ~P_ALLOCED; /* don't free the value now */
10008 }
10009 }
10010 }
10011}
10012
10013/*
10014 * return TRUE if 'p' starts with 't_'
10015 */
10016 static int
10017istermoption(p)
10018 struct vimoption *p;
10019{
10020 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10021}
10022
10023/*
10024 * Compute columns for ruler and shown command. 'sc_col' is also used to
10025 * decide what the maximum length of a message on the status line can be.
10026 * If there is a status line for the last window, 'sc_col' is independent
10027 * of 'ru_col'.
10028 */
10029
10030#define COL_RULER 17 /* columns needed by standard ruler */
10031
10032 void
10033comp_col()
10034{
10035#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10036 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10037
10038 sc_col = 0;
10039 ru_col = 0;
10040 if (p_ru)
10041 {
10042#ifdef FEAT_STL_OPT
10043 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10044#else
10045 ru_col = COL_RULER + 1;
10046#endif
10047 /* no last status line, adjust sc_col */
10048 if (!last_has_status)
10049 sc_col = ru_col;
10050 }
10051 if (p_sc)
10052 {
10053 sc_col += SHOWCMD_COLS;
10054 if (!p_ru || last_has_status) /* no need for separating space */
10055 ++sc_col;
10056 }
10057 sc_col = Columns - sc_col;
10058 ru_col = Columns - ru_col;
10059 if (sc_col <= 0) /* screen too narrow, will become a mess */
10060 sc_col = 1;
10061 if (ru_col <= 0)
10062 ru_col = 1;
10063#else
10064 sc_col = Columns;
10065 ru_col = Columns;
10066#endif
10067}
10068
10069/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010070 * Unset local option value, similar to ":set opt<".
10071 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010072 void
10073unset_global_local_option(name, from)
10074 char_u *name;
10075 void *from;
10076{
10077 struct vimoption *p;
10078 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010079 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010080
10081 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010082 if (opt_idx < 0)
10083 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010084 p = &(options[opt_idx]);
10085
10086 switch ((int)p->indir)
10087 {
10088 /* global option with local value: use local value if it's been set */
10089 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010090 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010091 break;
10092 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010093 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010094 break;
10095 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010096 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010097 break;
10098 case PV_AR:
10099 buf->b_p_ar = -1;
10100 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010101 case PV_BKC:
10102 clear_string_option(&buf->b_p_bkc);
10103 buf->b_bkc_flags = 0;
10104 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010105 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010106 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010107 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010108 case PV_TC:
10109 clear_string_option(&buf->b_p_tc);
10110 buf->b_tc_flags = 0;
10111 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010112#ifdef FEAT_FIND_ID
10113 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010114 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010115 break;
10116 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010117 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010118 break;
10119#endif
10120#ifdef FEAT_INS_EXPAND
10121 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010122 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010123 break;
10124 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010125 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010126 break;
10127#endif
10128#ifdef FEAT_QUICKFIX
10129 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010130 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010131 break;
10132 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010133 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010134 break;
10135 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010136 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010137 break;
10138#endif
10139#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10140 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010141 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010142 break;
10143#endif
10144#if defined(FEAT_CRYPT)
10145 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010146 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010147 break;
10148#endif
10149#ifdef FEAT_STL_OPT
10150 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010151 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010152 break;
10153#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010154 case PV_UL:
10155 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10156 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010157#ifdef FEAT_LISP
10158 case PV_LW:
10159 clear_string_option(&buf->b_p_lw);
10160 break;
10161#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010162 }
10163}
10164
10165/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166 * Get pointer to option variable, depending on local or global scope.
10167 */
10168 static char_u *
10169get_varp_scope(p, opt_flags)
10170 struct vimoption *p;
10171 int opt_flags;
10172{
10173 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10174 {
10175 if (p->var == VAR_WIN)
10176 return (char_u *)GLOBAL_WO(get_varp(p));
10177 return p->var;
10178 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010179 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180 {
10181 switch ((int)p->indir)
10182 {
10183#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010184 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10185 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10186 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010187#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010188 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10189 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10190 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010191 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010192 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010193 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010195 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10196 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197#endif
10198#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010199 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10200 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010201#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010202#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10203 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10204#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010205#if defined(FEAT_CRYPT)
10206 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10207#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010208#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010209 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010210#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010211 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010212#ifdef FEAT_LISP
10213 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10214#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010215 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010216 }
10217 return NULL; /* "cannot happen" */
10218 }
10219 return get_varp(p);
10220}
10221
10222/*
10223 * Get pointer to option variable.
10224 */
10225 static char_u *
10226get_varp(p)
10227 struct vimoption *p;
10228{
10229 /* hidden option, always return NULL */
10230 if (p->var == NULL)
10231 return NULL;
10232
10233 switch ((int)p->indir)
10234 {
10235 case PV_NONE: return p->var;
10236
10237 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010238 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010240 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010242 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010243 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010244 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010245 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010246 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010248 case PV_TC: return *curbuf->b_p_tc != NUL
10249 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010250 case PV_BKC: return *curbuf->b_p_bkc != NUL
10251 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010253 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010254 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010255 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10257#endif
10258#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010259 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010261 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10263#endif
10264#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010265 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010267 case PV_GP: return *curbuf->b_p_gp != NUL
10268 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10269 case PV_MP: return *curbuf->b_p_mp != NUL
10270 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010272#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10273 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10274 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10275#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010276#if defined(FEAT_CRYPT)
10277 case PV_CM: return *curbuf->b_p_cm != NUL
10278 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10279#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010280#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010281 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010282 ? (char_u *)&(curwin->w_p_stl) : p->var;
10283#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010284 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10285 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010286#ifdef FEAT_LISP
10287 case PV_LW: return *curbuf->b_p_lw != NUL
10288 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290
10291#ifdef FEAT_ARABIC
10292 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10293#endif
10294 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010295#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010296 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10297#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010298#ifdef FEAT_SYN_HL
10299 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10300 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010301 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010302#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303#ifdef FEAT_DIFF
10304 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10305#endif
10306#ifdef FEAT_FOLDING
10307 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10308 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10309 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10310 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10311 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10312 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10313 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10314# ifdef FEAT_EVAL
10315 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10316 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10317# endif
10318 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10319#endif
10320 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010321 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010322#ifdef FEAT_LINEBREAK
10323 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10324#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010325#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10327#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010328#ifdef FEAT_VERTSPLIT
10329 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10332 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10333#endif
10334#ifdef FEAT_RIGHTLEFT
10335 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10336 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10337#endif
10338 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10339 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10340#ifdef FEAT_LINEBREAK
10341 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010342 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10343 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344#endif
10345#ifdef FEAT_SCROLLBIND
10346 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10347#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010348#ifdef FEAT_CURSORBIND
10349 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10350#endif
10351#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010352 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10353 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010355
10356 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10357 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10358#ifdef FEAT_MBYTE
10359 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10360#endif
10361#if defined(FEAT_QUICKFIX)
10362 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10363 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10364#endif
10365 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10366 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10367#ifdef FEAT_CINDENT
10368 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10369 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10370 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10371#endif
10372#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10373 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10374#endif
10375#ifdef FEAT_COMMENTS
10376 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10377#endif
10378#ifdef FEAT_FOLDING
10379 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10380#endif
10381#ifdef FEAT_INS_EXPAND
10382 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10383#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010384#ifdef FEAT_COMPL_FUNC
10385 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010386 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010389 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010390 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10391#ifdef FEAT_MBYTE
10392 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10393#endif
10394 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10395#ifdef FEAT_AUTOCMD
10396 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10397#endif
10398 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010399 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010400 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10401 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10402 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10403 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10404#ifdef FEAT_FIND_ID
10405# ifdef FEAT_EVAL
10406 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10407# endif
10408#endif
10409#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10410 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10411 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10412#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010413#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010414 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10415#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010416#ifdef FEAT_CRYPT
10417 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10418#endif
10419#ifdef FEAT_LISP
10420 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10421#endif
10422 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10423 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10424 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10425 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10426 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010427 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010428#ifdef FEAT_TEXTOBJ
10429 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10430#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10432#ifdef FEAT_SMARTINDENT
10433 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10434#endif
10435#ifndef SHORT_FNAME
10436 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10437#endif
10438 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10439#ifdef FEAT_SEARCHPATH
10440 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10441#endif
10442 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10443#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010444 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010445 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10446#endif
10447#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010448 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10449 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10450 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010451#endif
10452 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10453 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10454 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10455 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010456#ifdef FEAT_PERSISTENT_UNDO
10457 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10460#ifdef FEAT_KEYMAP
10461 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10462#endif
10463 default: EMSG(_("E356: get_varp ERROR"));
10464 }
10465 /* always return a valid pointer to avoid a crash! */
10466 return (char_u *)&(curbuf->b_p_wm);
10467}
10468
10469/*
10470 * Get the value of 'equalprg', either the buffer-local one or the global one.
10471 */
10472 char_u *
10473get_equalprg()
10474{
10475 if (*curbuf->b_p_ep == NUL)
10476 return p_ep;
10477 return curbuf->b_p_ep;
10478}
10479
10480#if defined(FEAT_WINDOWS) || defined(PROTO)
10481/*
10482 * Copy options from one window to another.
10483 * Used when splitting a window.
10484 */
10485 void
10486win_copy_options(wp_from, wp_to)
10487 win_T *wp_from;
10488 win_T *wp_to;
10489{
10490 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10491 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10492# ifdef FEAT_RIGHTLEFT
10493# ifdef FEAT_FKMAP
10494 /* Is this right? */
10495 wp_to->w_farsi = wp_from->w_farsi;
10496# endif
10497# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010498#if defined(FEAT_LINEBREAK)
10499 briopt_check(wp_to);
10500#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501}
10502#endif
10503
10504/*
10505 * Copy the options from one winopt_T to another.
10506 * Doesn't free the old option values in "to", use clear_winopt() for that.
10507 * The 'scroll' option is not copied, because it depends on the window height.
10508 * The 'previewwindow' option is reset, there can be only one preview window.
10509 */
10510 void
10511copy_winopt(from, to)
10512 winopt_T *from;
10513 winopt_T *to;
10514{
10515#ifdef FEAT_ARABIC
10516 to->wo_arab = from->wo_arab;
10517#endif
10518 to->wo_list = from->wo_list;
10519 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010520 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010521#ifdef FEAT_LINEBREAK
10522 to->wo_nuw = from->wo_nuw;
10523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524#ifdef FEAT_RIGHTLEFT
10525 to->wo_rl = from->wo_rl;
10526 to->wo_rlc = vim_strsave(from->wo_rlc);
10527#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010528#ifdef FEAT_STL_OPT
10529 to->wo_stl = vim_strsave(from->wo_stl);
10530#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010531 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010532#ifdef FEAT_DIFF
10533 to->wo_wrap_save = from->wo_wrap_save;
10534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535#ifdef FEAT_LINEBREAK
10536 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010537 to->wo_bri = from->wo_bri;
10538 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539#endif
10540#ifdef FEAT_SCROLLBIND
10541 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010542 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010544#ifdef FEAT_CURSORBIND
10545 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010546 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010547#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010548#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010549 to->wo_spell = from->wo_spell;
10550#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010551#ifdef FEAT_SYN_HL
10552 to->wo_cuc = from->wo_cuc;
10553 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010554 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010555#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556#ifdef FEAT_DIFF
10557 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010558 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010559#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010560#ifdef FEAT_CONCEAL
10561 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010562 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010563#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564#ifdef FEAT_FOLDING
10565 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010566 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010568 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569 to->wo_fdi = vim_strsave(from->wo_fdi);
10570 to->wo_fml = from->wo_fml;
10571 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010572 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010574 to->wo_fdm_save = from->wo_diff_saved
10575 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576 to->wo_fdn = from->wo_fdn;
10577# ifdef FEAT_EVAL
10578 to->wo_fde = vim_strsave(from->wo_fde);
10579 to->wo_fdt = vim_strsave(from->wo_fdt);
10580# endif
10581 to->wo_fmr = vim_strsave(from->wo_fmr);
10582#endif
10583 check_winopt(to); /* don't want NULL pointers */
10584}
10585
10586/*
10587 * Check string options in a window for a NULL value.
10588 */
10589 void
10590check_win_options(win)
10591 win_T *win;
10592{
10593 check_winopt(&win->w_onebuf_opt);
10594 check_winopt(&win->w_allbuf_opt);
10595}
10596
10597/*
10598 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10599 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010600 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010602 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603{
10604#ifdef FEAT_FOLDING
10605 check_string_option(&wop->wo_fdi);
10606 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010607 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608# ifdef FEAT_EVAL
10609 check_string_option(&wop->wo_fde);
10610 check_string_option(&wop->wo_fdt);
10611# endif
10612 check_string_option(&wop->wo_fmr);
10613#endif
10614#ifdef FEAT_RIGHTLEFT
10615 check_string_option(&wop->wo_rlc);
10616#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010617#ifdef FEAT_STL_OPT
10618 check_string_option(&wop->wo_stl);
10619#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010620#ifdef FEAT_SYN_HL
10621 check_string_option(&wop->wo_cc);
10622#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010623#ifdef FEAT_CONCEAL
10624 check_string_option(&wop->wo_cocu);
10625#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010626#ifdef FEAT_LINEBREAK
10627 check_string_option(&wop->wo_briopt);
10628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629}
10630
10631/*
10632 * Free the allocated memory inside a winopt_T.
10633 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634 void
10635clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010636 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010637{
10638#ifdef FEAT_FOLDING
10639 clear_string_option(&wop->wo_fdi);
10640 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010641 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642# ifdef FEAT_EVAL
10643 clear_string_option(&wop->wo_fde);
10644 clear_string_option(&wop->wo_fdt);
10645# endif
10646 clear_string_option(&wop->wo_fmr);
10647#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010648#ifdef FEAT_LINEBREAK
10649 clear_string_option(&wop->wo_briopt);
10650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010651#ifdef FEAT_RIGHTLEFT
10652 clear_string_option(&wop->wo_rlc);
10653#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010654#ifdef FEAT_STL_OPT
10655 clear_string_option(&wop->wo_stl);
10656#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010657#ifdef FEAT_SYN_HL
10658 clear_string_option(&wop->wo_cc);
10659#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010660#ifdef FEAT_CONCEAL
10661 clear_string_option(&wop->wo_cocu);
10662#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010663}
10664
10665/*
10666 * Copy global option values to local options for one buffer.
10667 * Used when creating a new buffer and sometimes when entering a buffer.
10668 * flags:
10669 * BCO_ENTER We will enter the buf buffer.
10670 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10671 * appropriate.
10672 * BCO_NOHELP Don't copy the values to a help buffer.
10673 */
10674 void
10675buf_copy_options(buf, flags)
10676 buf_T *buf;
10677 int flags;
10678{
10679 int should_copy = TRUE;
10680 char_u *save_p_isk = NULL; /* init for GCC */
10681 int dont_do_help;
10682 int did_isk = FALSE;
10683
10684 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010685 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686 */
10687 if (buf == NULL || !buf_valid(buf))
10688 return;
10689
10690 /*
10691 * Skip this when the option defaults have not been set yet. Happens when
10692 * main() allocates the first buffer.
10693 */
10694 if (p_cpo != NULL)
10695 {
10696 /*
10697 * Always copy when entering and 'cpo' contains 'S'.
10698 * Don't copy when already initialized.
10699 * Don't copy when 'cpo' contains 's' and not entering.
10700 * 'S' BCO_ENTER initialized 's' should_copy
10701 * yes yes X X TRUE
10702 * yes no yes X FALSE
10703 * no X yes X FALSE
10704 * X no no yes FALSE
10705 * X no no no TRUE
10706 * no yes no X TRUE
10707 */
10708 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10709 && (buf->b_p_initialized
10710 || (!(flags & BCO_ENTER)
10711 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10712 should_copy = FALSE;
10713
10714 if (should_copy || (flags & BCO_ALWAYS))
10715 {
10716 /* Don't copy the options specific to a help buffer when
10717 * BCO_NOHELP is given or the options were initialized already
10718 * (jumping back to a help file with CTRL-T or CTRL-O) */
10719 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10720 || buf->b_p_initialized;
10721 if (dont_do_help) /* don't free b_p_isk */
10722 {
10723 save_p_isk = buf->b_p_isk;
10724 buf->b_p_isk = NULL;
10725 }
10726 /*
10727 * Always free the allocated strings.
10728 * If not already initialized, set 'readonly' and copy 'fileformat'.
10729 */
10730 if (!buf->b_p_initialized)
10731 {
10732 free_buf_options(buf, TRUE);
10733 buf->b_p_ro = FALSE; /* don't copy readonly */
10734 buf->b_p_tx = p_tx;
10735#ifdef FEAT_MBYTE
10736 buf->b_p_fenc = vim_strsave(p_fenc);
10737#endif
10738 buf->b_p_ff = vim_strsave(p_ff);
10739#if defined(FEAT_QUICKFIX)
10740 buf->b_p_bh = empty_option;
10741 buf->b_p_bt = empty_option;
10742#endif
10743 }
10744 else
10745 free_buf_options(buf, FALSE);
10746
10747 buf->b_p_ai = p_ai;
10748 buf->b_p_ai_nopaste = p_ai_nopaste;
10749 buf->b_p_sw = p_sw;
10750 buf->b_p_tw = p_tw;
10751 buf->b_p_tw_nopaste = p_tw_nopaste;
10752 buf->b_p_tw_nobin = p_tw_nobin;
10753 buf->b_p_wm = p_wm;
10754 buf->b_p_wm_nopaste = p_wm_nopaste;
10755 buf->b_p_wm_nobin = p_wm_nobin;
10756 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010757#ifdef FEAT_MBYTE
10758 buf->b_p_bomb = p_bomb;
10759#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010760 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761 buf->b_p_et = p_et;
10762 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010763 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764 buf->b_p_ml = p_ml;
10765 buf->b_p_ml_nobin = p_ml_nobin;
10766 buf->b_p_inf = p_inf;
10767 buf->b_p_swf = p_swf;
10768#ifdef FEAT_INS_EXPAND
10769 buf->b_p_cpt = vim_strsave(p_cpt);
10770#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010771#ifdef FEAT_COMPL_FUNC
10772 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010773 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010774#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775 buf->b_p_sts = p_sts;
10776 buf->b_p_sts_nopaste = p_sts_nopaste;
10777#ifndef SHORT_FNAME
10778 buf->b_p_sn = p_sn;
10779#endif
10780#ifdef FEAT_COMMENTS
10781 buf->b_p_com = vim_strsave(p_com);
10782#endif
10783#ifdef FEAT_FOLDING
10784 buf->b_p_cms = vim_strsave(p_cms);
10785#endif
10786 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010787 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788 buf->b_p_nf = vim_strsave(p_nf);
10789 buf->b_p_mps = vim_strsave(p_mps);
10790#ifdef FEAT_SMARTINDENT
10791 buf->b_p_si = p_si;
10792#endif
10793 buf->b_p_ci = p_ci;
10794#ifdef FEAT_CINDENT
10795 buf->b_p_cin = p_cin;
10796 buf->b_p_cink = vim_strsave(p_cink);
10797 buf->b_p_cino = vim_strsave(p_cino);
10798#endif
10799#ifdef FEAT_AUTOCMD
10800 /* Don't copy 'filetype', it must be detected */
10801 buf->b_p_ft = empty_option;
10802#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803 buf->b_p_pi = p_pi;
10804#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10805 buf->b_p_cinw = vim_strsave(p_cinw);
10806#endif
10807#ifdef FEAT_LISP
10808 buf->b_p_lisp = p_lisp;
10809#endif
10810#ifdef FEAT_SYN_HL
10811 /* Don't copy 'syntax', it must be set */
10812 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010813 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010814#endif
10815#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010816 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010817 (void)compile_cap_prog(&buf->b_s);
10818 buf->b_s.b_p_spf = vim_strsave(p_spf);
10819 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820#endif
10821#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10822 buf->b_p_inde = vim_strsave(p_inde);
10823 buf->b_p_indk = vim_strsave(p_indk);
10824#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010825#if defined(FEAT_EVAL)
10826 buf->b_p_fex = vim_strsave(p_fex);
10827#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828#ifdef FEAT_CRYPT
10829 buf->b_p_key = vim_strsave(p_key);
10830#endif
10831#ifdef FEAT_SEARCHPATH
10832 buf->b_p_sua = vim_strsave(p_sua);
10833#endif
10834#ifdef FEAT_KEYMAP
10835 buf->b_p_keymap = vim_strsave(p_keymap);
10836 buf->b_kmap_state |= KEYMAP_INIT;
10837#endif
10838 /* This isn't really an option, but copying the langmap and IME
10839 * state from the current buffer is better than resetting it. */
10840 buf->b_p_iminsert = p_iminsert;
10841 buf->b_p_imsearch = p_imsearch;
10842
10843 /* options that are normally global but also have a local value
10844 * are not copied, start using the global value */
10845 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010846 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010847 buf->b_p_bkc = empty_option;
10848 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849#ifdef FEAT_QUICKFIX
10850 buf->b_p_gp = empty_option;
10851 buf->b_p_mp = empty_option;
10852 buf->b_p_efm = empty_option;
10853#endif
10854 buf->b_p_ep = empty_option;
10855 buf->b_p_kp = empty_option;
10856 buf->b_p_path = empty_option;
10857 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010858 buf->b_p_tc = empty_option;
10859 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010860#ifdef FEAT_FIND_ID
10861 buf->b_p_def = empty_option;
10862 buf->b_p_inc = empty_option;
10863# ifdef FEAT_EVAL
10864 buf->b_p_inex = vim_strsave(p_inex);
10865# endif
10866#endif
10867#ifdef FEAT_INS_EXPAND
10868 buf->b_p_dict = empty_option;
10869 buf->b_p_tsr = empty_option;
10870#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010871#ifdef FEAT_TEXTOBJ
10872 buf->b_p_qe = vim_strsave(p_qe);
10873#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010874#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10875 buf->b_p_bexpr = empty_option;
10876#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010877#if defined(FEAT_CRYPT)
10878 buf->b_p_cm = empty_option;
10879#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010880#ifdef FEAT_PERSISTENT_UNDO
10881 buf->b_p_udf = p_udf;
10882#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010883#ifdef FEAT_LISP
10884 buf->b_p_lw = empty_option;
10885#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010886
10887 /*
10888 * Don't copy the options set by ex_help(), use the saved values,
10889 * when going from a help buffer to a non-help buffer.
10890 * Don't touch these at all when BCO_NOHELP is used and going from
10891 * or to a help buffer.
10892 */
10893 if (dont_do_help)
10894 buf->b_p_isk = save_p_isk;
10895 else
10896 {
10897 buf->b_p_isk = vim_strsave(p_isk);
10898 did_isk = TRUE;
10899 buf->b_p_ts = p_ts;
10900 buf->b_help = FALSE;
10901#ifdef FEAT_QUICKFIX
10902 if (buf->b_p_bt[0] == 'h')
10903 clear_string_option(&buf->b_p_bt);
10904#endif
10905 buf->b_p_ma = p_ma;
10906 }
10907 }
10908
10909 /*
10910 * When the options should be copied (ignoring BCO_ALWAYS), set the
10911 * flag that indicates that the options have been initialized.
10912 */
10913 if (should_copy)
10914 buf->b_p_initialized = TRUE;
10915 }
10916
10917 check_buf_options(buf); /* make sure we don't have NULLs */
10918 if (did_isk)
10919 (void)buf_init_chartab(buf, FALSE);
10920}
10921
10922/*
10923 * Reset the 'modifiable' option and its default value.
10924 */
10925 void
10926reset_modifiable()
10927{
10928 int opt_idx;
10929
10930 curbuf->b_p_ma = FALSE;
10931 p_ma = FALSE;
10932 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010933 if (opt_idx >= 0)
10934 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935}
10936
10937/*
10938 * Set the global value for 'iminsert' to the local value.
10939 */
10940 void
10941set_iminsert_global()
10942{
10943 p_iminsert = curbuf->b_p_iminsert;
10944}
10945
10946/*
10947 * Set the global value for 'imsearch' to the local value.
10948 */
10949 void
10950set_imsearch_global()
10951{
10952 p_imsearch = curbuf->b_p_imsearch;
10953}
10954
10955#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10956static int expand_option_idx = -1;
10957static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10958static int expand_option_flags = 0;
10959
10960 void
10961set_context_in_set_cmd(xp, arg, opt_flags)
10962 expand_T *xp;
10963 char_u *arg;
10964 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10965{
10966 int nextchar;
10967 long_u flags = 0; /* init for GCC */
10968 int opt_idx = 0; /* init for GCC */
10969 char_u *p;
10970 char_u *s;
10971 int is_term_option = FALSE;
10972 int key;
10973
10974 expand_option_flags = opt_flags;
10975
10976 xp->xp_context = EXPAND_SETTINGS;
10977 if (*arg == NUL)
10978 {
10979 xp->xp_pattern = arg;
10980 return;
10981 }
10982 p = arg + STRLEN(arg) - 1;
10983 if (*p == ' ' && *(p - 1) != '\\')
10984 {
10985 xp->xp_pattern = p + 1;
10986 return;
10987 }
10988 while (p > arg)
10989 {
10990 s = p;
10991 /* count number of backslashes before ' ' or ',' */
10992 if (*p == ' ' || *p == ',')
10993 {
10994 while (s > arg && *(s - 1) == '\\')
10995 --s;
10996 }
10997 /* break at a space with an even number of backslashes */
10998 if (*p == ' ' && ((p - s) & 1) == 0)
10999 {
11000 ++p;
11001 break;
11002 }
11003 --p;
11004 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011005 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011006 {
11007 xp->xp_context = EXPAND_BOOL_SETTINGS;
11008 p += 2;
11009 }
11010 if (STRNCMP(p, "inv", 3) == 0)
11011 {
11012 xp->xp_context = EXPAND_BOOL_SETTINGS;
11013 p += 3;
11014 }
11015 xp->xp_pattern = arg = p;
11016 if (*arg == '<')
11017 {
11018 while (*p != '>')
11019 if (*p++ == NUL) /* expand terminal option name */
11020 return;
11021 key = get_special_key_code(arg + 1);
11022 if (key == 0) /* unknown name */
11023 {
11024 xp->xp_context = EXPAND_NOTHING;
11025 return;
11026 }
11027 nextchar = *++p;
11028 is_term_option = TRUE;
11029 expand_option_name[2] = KEY2TERMCAP0(key);
11030 expand_option_name[3] = KEY2TERMCAP1(key);
11031 }
11032 else
11033 {
11034 if (p[0] == 't' && p[1] == '_')
11035 {
11036 p += 2;
11037 if (*p != NUL)
11038 ++p;
11039 if (*p == NUL)
11040 return; /* expand option name */
11041 nextchar = *++p;
11042 is_term_option = TRUE;
11043 expand_option_name[2] = p[-2];
11044 expand_option_name[3] = p[-1];
11045 }
11046 else
11047 {
11048 /* Allow * wildcard */
11049 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11050 p++;
11051 if (*p == NUL)
11052 return;
11053 nextchar = *p;
11054 *p = NUL;
11055 opt_idx = findoption(arg);
11056 *p = nextchar;
11057 if (opt_idx == -1 || options[opt_idx].var == NULL)
11058 {
11059 xp->xp_context = EXPAND_NOTHING;
11060 return;
11061 }
11062 flags = options[opt_idx].flags;
11063 if (flags & P_BOOL)
11064 {
11065 xp->xp_context = EXPAND_NOTHING;
11066 return;
11067 }
11068 }
11069 }
11070 /* handle "-=" and "+=" */
11071 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11072 {
11073 ++p;
11074 nextchar = '=';
11075 }
11076 if ((nextchar != '=' && nextchar != ':')
11077 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11078 {
11079 xp->xp_context = EXPAND_UNSUCCESSFUL;
11080 return;
11081 }
11082 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11083 {
11084 xp->xp_context = EXPAND_OLD_SETTING;
11085 if (is_term_option)
11086 expand_option_idx = -1;
11087 else
11088 expand_option_idx = opt_idx;
11089 xp->xp_pattern = p + 1;
11090 return;
11091 }
11092 xp->xp_context = EXPAND_NOTHING;
11093 if (is_term_option || (flags & P_NUM))
11094 return;
11095
11096 xp->xp_pattern = p + 1;
11097
11098 if (flags & P_EXPAND)
11099 {
11100 p = options[opt_idx].var;
11101 if (p == (char_u *)&p_bdir
11102 || p == (char_u *)&p_dir
11103 || p == (char_u *)&p_path
11104 || p == (char_u *)&p_rtp
11105#ifdef FEAT_SEARCHPATH
11106 || p == (char_u *)&p_cdpath
11107#endif
11108#ifdef FEAT_SESSION
11109 || p == (char_u *)&p_vdir
11110#endif
11111 )
11112 {
11113 xp->xp_context = EXPAND_DIRECTORIES;
11114 if (p == (char_u *)&p_path
11115#ifdef FEAT_SEARCHPATH
11116 || p == (char_u *)&p_cdpath
11117#endif
11118 )
11119 xp->xp_backslash = XP_BS_THREE;
11120 else
11121 xp->xp_backslash = XP_BS_ONE;
11122 }
11123 else
11124 {
11125 xp->xp_context = EXPAND_FILES;
11126 /* for 'tags' need three backslashes for a space */
11127 if (p == (char_u *)&p_tags)
11128 xp->xp_backslash = XP_BS_THREE;
11129 else
11130 xp->xp_backslash = XP_BS_ONE;
11131 }
11132 }
11133
11134 /* For an option that is a list of file names, find the start of the
11135 * last file name. */
11136 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11137 {
11138 /* count number of backslashes before ' ' or ',' */
11139 if (*p == ' ' || *p == ',')
11140 {
11141 s = p;
11142 while (s > xp->xp_pattern && *(s - 1) == '\\')
11143 --s;
11144 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11145 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11146 {
11147 xp->xp_pattern = p + 1;
11148 break;
11149 }
11150 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011151
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011152#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011153 /* for 'spellsuggest' start at "file:" */
11154 if (options[opt_idx].var == (char_u *)&p_sps
11155 && STRNCMP(p, "file:", 5) == 0)
11156 {
11157 xp->xp_pattern = p + 5;
11158 break;
11159 }
11160#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011161 }
11162
11163 return;
11164}
11165
11166 int
11167ExpandSettings(xp, regmatch, num_file, file)
11168 expand_T *xp;
11169 regmatch_T *regmatch;
11170 int *num_file;
11171 char_u ***file;
11172{
11173 int num_normal = 0; /* Nr of matching non-term-code settings */
11174 int num_term = 0; /* Nr of matching terminal code settings */
11175 int opt_idx;
11176 int match;
11177 int count = 0;
11178 char_u *str;
11179 int loop;
11180 int is_term_opt;
11181 char_u name_buf[MAX_KEY_NAME_LEN];
11182 static char *(names[]) = {"all", "termcap"};
11183 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11184
11185 /* do this loop twice:
11186 * loop == 0: count the number of matching options
11187 * loop == 1: copy the matching options into allocated memory
11188 */
11189 for (loop = 0; loop <= 1; ++loop)
11190 {
11191 regmatch->rm_ic = ic;
11192 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11193 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011194 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11195 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011196 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11197 {
11198 if (loop == 0)
11199 num_normal++;
11200 else
11201 (*file)[count++] = vim_strsave((char_u *)names[match]);
11202 }
11203 }
11204 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11205 opt_idx++)
11206 {
11207 if (options[opt_idx].var == NULL)
11208 continue;
11209 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11210 && !(options[opt_idx].flags & P_BOOL))
11211 continue;
11212 is_term_opt = istermoption(&options[opt_idx]);
11213 if (is_term_opt && num_normal > 0)
11214 continue;
11215 match = FALSE;
11216 if (vim_regexec(regmatch, str, (colnr_T)0)
11217 || (options[opt_idx].shortname != NULL
11218 && vim_regexec(regmatch,
11219 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11220 match = TRUE;
11221 else if (is_term_opt)
11222 {
11223 name_buf[0] = '<';
11224 name_buf[1] = 't';
11225 name_buf[2] = '_';
11226 name_buf[3] = str[2];
11227 name_buf[4] = str[3];
11228 name_buf[5] = '>';
11229 name_buf[6] = NUL;
11230 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11231 {
11232 match = TRUE;
11233 str = name_buf;
11234 }
11235 }
11236 if (match)
11237 {
11238 if (loop == 0)
11239 {
11240 if (is_term_opt)
11241 num_term++;
11242 else
11243 num_normal++;
11244 }
11245 else
11246 (*file)[count++] = vim_strsave(str);
11247 }
11248 }
11249 /*
11250 * Check terminal key codes, these are not in the option table
11251 */
11252 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11253 {
11254 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11255 {
11256 if (!isprint(str[0]) || !isprint(str[1]))
11257 continue;
11258
11259 name_buf[0] = 't';
11260 name_buf[1] = '_';
11261 name_buf[2] = str[0];
11262 name_buf[3] = str[1];
11263 name_buf[4] = NUL;
11264
11265 match = FALSE;
11266 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11267 match = TRUE;
11268 else
11269 {
11270 name_buf[0] = '<';
11271 name_buf[1] = 't';
11272 name_buf[2] = '_';
11273 name_buf[3] = str[0];
11274 name_buf[4] = str[1];
11275 name_buf[5] = '>';
11276 name_buf[6] = NUL;
11277
11278 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11279 match = TRUE;
11280 }
11281 if (match)
11282 {
11283 if (loop == 0)
11284 num_term++;
11285 else
11286 (*file)[count++] = vim_strsave(name_buf);
11287 }
11288 }
11289
11290 /*
11291 * Check special key names.
11292 */
11293 regmatch->rm_ic = TRUE; /* ignore case here */
11294 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11295 {
11296 name_buf[0] = '<';
11297 STRCPY(name_buf + 1, str);
11298 STRCAT(name_buf, ">");
11299
11300 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11301 {
11302 if (loop == 0)
11303 num_term++;
11304 else
11305 (*file)[count++] = vim_strsave(name_buf);
11306 }
11307 }
11308 }
11309 if (loop == 0)
11310 {
11311 if (num_normal > 0)
11312 *num_file = num_normal;
11313 else if (num_term > 0)
11314 *num_file = num_term;
11315 else
11316 return OK;
11317 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11318 if (*file == NULL)
11319 {
11320 *file = (char_u **)"";
11321 return FAIL;
11322 }
11323 }
11324 }
11325 return OK;
11326}
11327
11328 int
11329ExpandOldSetting(num_file, file)
11330 int *num_file;
11331 char_u ***file;
11332{
11333 char_u *var = NULL; /* init for GCC */
11334 char_u *buf;
11335
11336 *num_file = 0;
11337 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11338 if (*file == NULL)
11339 return FAIL;
11340
11341 /*
11342 * For a terminal key code expand_option_idx is < 0.
11343 */
11344 if (expand_option_idx < 0)
11345 {
11346 var = find_termcode(expand_option_name + 2);
11347 if (var == NULL)
11348 expand_option_idx = findoption(expand_option_name);
11349 }
11350
11351 if (expand_option_idx >= 0)
11352 {
11353 /* put string of option value in NameBuff */
11354 option_value2string(&options[expand_option_idx], expand_option_flags);
11355 var = NameBuff;
11356 }
11357 else if (var == NULL)
11358 var = (char_u *)"";
11359
11360 /* A backslash is required before some characters. This is the reverse of
11361 * what happens in do_set(). */
11362 buf = vim_strsave_escaped(var, escape_chars);
11363
11364 if (buf == NULL)
11365 {
11366 vim_free(*file);
11367 *file = NULL;
11368 return FAIL;
11369 }
11370
11371#ifdef BACKSLASH_IN_FILENAME
11372 /* For MS-Windows et al. we don't double backslashes at the start and
11373 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011374 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011375 if (var[0] == '\\' && var[1] == '\\'
11376 && expand_option_idx >= 0
11377 && (options[expand_option_idx].flags & P_EXPAND)
11378 && vim_isfilec(var[2])
11379 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011380 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011381#endif
11382
11383 *file[0] = buf;
11384 *num_file = 1;
11385 return OK;
11386}
11387#endif
11388
11389/*
11390 * Get the value for the numeric or string option *opp in a nice format into
11391 * NameBuff[]. Must not be called with a hidden option!
11392 */
11393 static void
11394option_value2string(opp, opt_flags)
11395 struct vimoption *opp;
11396 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11397{
11398 char_u *varp;
11399
11400 varp = get_varp_scope(opp, opt_flags);
11401
11402 if (opp->flags & P_NUM)
11403 {
11404 long wc = 0;
11405
11406 if (wc_use_keyname(varp, &wc))
11407 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11408 else if (wc != 0)
11409 STRCPY(NameBuff, transchar((int)wc));
11410 else
11411 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11412 }
11413 else /* P_STRING */
11414 {
11415 varp = *(char_u **)(varp);
11416 if (varp == NULL) /* just in case */
11417 NameBuff[0] = NUL;
11418#ifdef FEAT_CRYPT
11419 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011420 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011421 STRCPY(NameBuff, "*****");
11422#endif
11423 else if (opp->flags & P_EXPAND)
11424 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11425 /* Translate 'pastetoggle' into special key names */
11426 else if ((char_u **)opp->var == &p_pt)
11427 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11428 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011429 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011430 }
11431}
11432
11433/*
11434 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11435 * printed as a keyname.
11436 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11437 */
11438 static int
11439wc_use_keyname(varp, wcp)
11440 char_u *varp;
11441 long *wcp;
11442{
11443 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11444 {
11445 *wcp = *(long *)varp;
11446 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11447 return TRUE;
11448 }
11449 return FALSE;
11450}
11451
Bram Moolenaar01615492015-02-03 13:00:38 +010011452#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011453/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011454 * Any character has an equivalent 'langmap' character. This is used for
11455 * keyboards that have a special language mode that sends characters above
11456 * 128 (although other characters can be translated too). The "to" field is a
11457 * Vim command character. This avoids having to switch the keyboard back to
11458 * ASCII mode when leaving Insert mode.
11459 *
11460 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11461 * commands.
11462 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11463 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11464 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011465 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011466# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011467/*
11468 * With multi-byte support use growarray for 'langmap' chars >= 256
11469 */
11470typedef struct
11471{
11472 int from;
11473 int to;
11474} langmap_entry_T;
11475
11476static garray_T langmap_mapga;
11477static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011478
11479/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011480 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11481 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011482 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011483 static void
11484langmap_set_entry(from, to)
11485 int from;
11486 int to;
11487{
11488 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011489 int a = 0;
11490 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011491
11492 /* Do a binary search for an existing entry. */
11493 while (a != b)
11494 {
11495 int i = (a + b) / 2;
11496 int d = entries[i].from - from;
11497
11498 if (d == 0)
11499 {
11500 entries[i].to = to;
11501 return;
11502 }
11503 if (d < 0)
11504 a = i + 1;
11505 else
11506 b = i;
11507 }
11508
11509 if (ga_grow(&langmap_mapga, 1) != OK)
11510 return; /* out of memory */
11511
11512 /* insert new entry at position "a" */
11513 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11514 mch_memmove(entries + 1, entries,
11515 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11516 ++langmap_mapga.ga_len;
11517 entries[0].from = from;
11518 entries[0].to = to;
11519}
11520
11521/*
11522 * Apply 'langmap' to multi-byte character "c" and return the result.
11523 */
11524 int
11525langmap_adjust_mb(c)
11526 int c;
11527{
11528 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11529 int a = 0;
11530 int b = langmap_mapga.ga_len;
11531
11532 while (a != b)
11533 {
11534 int i = (a + b) / 2;
11535 int d = entries[i].from - c;
11536
11537 if (d == 0)
11538 return entries[i].to; /* found matching entry */
11539 if (d < 0)
11540 a = i + 1;
11541 else
11542 b = i;
11543 }
11544 return c; /* no entry found, return "c" unmodified */
11545}
11546# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011547
11548 static void
11549langmap_init()
11550{
11551 int i;
11552
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011553 for (i = 0; i < 256; i++)
11554 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11555# ifdef FEAT_MBYTE
11556 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11557# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011558}
11559
11560/*
11561 * Called when langmap option is set; the language map can be
11562 * changed at any time!
11563 */
11564 static void
11565langmap_set()
11566{
11567 char_u *p;
11568 char_u *p2;
11569 int from, to;
11570
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011571#ifdef FEAT_MBYTE
11572 ga_clear(&langmap_mapga); /* clear the previous map first */
11573#endif
11574 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011575
11576 for (p = p_langmap; p[0] != NUL; )
11577 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011578 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11579 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580 {
11581 if (p2[0] == '\\' && p2[1] != NUL)
11582 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011583 }
11584 if (p2[0] == ';')
11585 ++p2; /* abcd;ABCD form, p2 points to A */
11586 else
11587 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11588 while (p[0])
11589 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011590 if (p[0] == ',')
11591 {
11592 ++p;
11593 break;
11594 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011595 if (p[0] == '\\' && p[1] != NUL)
11596 ++p;
11597#ifdef FEAT_MBYTE
11598 from = (*mb_ptr2char)(p);
11599#else
11600 from = p[0];
11601#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011602 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011603 if (p2 == NULL)
11604 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011605 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011606 if (p[0] != ',')
11607 {
11608 if (p[0] == '\\')
11609 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011611 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011612#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011613 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011614#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011615 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616 }
11617 else
11618 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011619 if (p2[0] != ',')
11620 {
11621 if (p2[0] == '\\')
11622 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011624 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011625#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011626 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011627#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011628 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011629 }
11630 if (to == NUL)
11631 {
11632 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11633 transchar(from));
11634 return;
11635 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011636
11637#ifdef FEAT_MBYTE
11638 if (from >= 256)
11639 langmap_set_entry(from, to);
11640 else
11641#endif
11642 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011643
11644 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011645 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011646 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011647 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011648 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011649 if (*p == ';')
11650 {
11651 p = p2;
11652 if (p[0] != NUL)
11653 {
11654 if (p[0] != ',')
11655 {
11656 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11657 return;
11658 }
11659 ++p;
11660 }
11661 break;
11662 }
11663 }
11664 }
11665 }
11666}
11667#endif
11668
11669/*
11670 * Return TRUE if format option 'x' is in effect.
11671 * Take care of no formatting when 'paste' is set.
11672 */
11673 int
11674has_format_option(x)
11675 int x;
11676{
11677 if (p_paste)
11678 return FALSE;
11679 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11680}
11681
11682/*
11683 * Return TRUE if "x" is present in 'shortmess' option, or
11684 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11685 */
11686 int
11687shortmess(x)
11688 int x;
11689{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011690 return p_shm != NULL &&
11691 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011692 || (vim_strchr(p_shm, 'a') != NULL
11693 && vim_strchr((char_u *)SHM_A, x) != NULL));
11694}
11695
11696/*
11697 * paste_option_changed() - Called after p_paste was set or reset.
11698 */
11699 static void
11700paste_option_changed()
11701{
11702 static int old_p_paste = FALSE;
11703 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011704 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011705#ifdef FEAT_CMDL_INFO
11706 static int save_ru = 0;
11707#endif
11708#ifdef FEAT_RIGHTLEFT
11709 static int save_ri = 0;
11710 static int save_hkmap = 0;
11711#endif
11712 buf_T *buf;
11713
11714 if (p_paste)
11715 {
11716 /*
11717 * Paste switched from off to on.
11718 * Save the current values, so they can be restored later.
11719 */
11720 if (!old_p_paste)
11721 {
11722 /* save options for each buffer */
11723 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11724 {
11725 buf->b_p_tw_nopaste = buf->b_p_tw;
11726 buf->b_p_wm_nopaste = buf->b_p_wm;
11727 buf->b_p_sts_nopaste = buf->b_p_sts;
11728 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011729 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011730 }
11731
11732 /* save global options */
11733 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011734 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011735#ifdef FEAT_CMDL_INFO
11736 save_ru = p_ru;
11737#endif
11738#ifdef FEAT_RIGHTLEFT
11739 save_ri = p_ri;
11740 save_hkmap = p_hkmap;
11741#endif
11742 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011743 p_ai_nopaste = p_ai;
11744 p_et_nopaste = p_et;
11745 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011746 p_tw_nopaste = p_tw;
11747 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011748 }
11749
11750 /*
11751 * Always set the option values, also when 'paste' is set when it is
11752 * already on.
11753 */
11754 /* set options for each buffer */
11755 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11756 {
11757 buf->b_p_tw = 0; /* textwidth is 0 */
11758 buf->b_p_wm = 0; /* wrapmargin is 0 */
11759 buf->b_p_sts = 0; /* softtabstop is 0 */
11760 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011761 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011762 }
11763
11764 /* set global options */
11765 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011766 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767#ifdef FEAT_CMDL_INFO
11768# ifdef FEAT_WINDOWS
11769 if (p_ru)
11770 status_redraw_all(); /* redraw to remove the ruler */
11771# endif
11772 p_ru = 0; /* no ruler */
11773#endif
11774#ifdef FEAT_RIGHTLEFT
11775 p_ri = 0; /* no reverse insert */
11776 p_hkmap = 0; /* no Hebrew keyboard */
11777#endif
11778 /* set global values for local buffer options */
11779 p_tw = 0;
11780 p_wm = 0;
11781 p_sts = 0;
11782 p_ai = 0;
11783 }
11784
11785 /*
11786 * Paste switched from on to off: Restore saved values.
11787 */
11788 else if (old_p_paste)
11789 {
11790 /* restore options for each buffer */
11791 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11792 {
11793 buf->b_p_tw = buf->b_p_tw_nopaste;
11794 buf->b_p_wm = buf->b_p_wm_nopaste;
11795 buf->b_p_sts = buf->b_p_sts_nopaste;
11796 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011797 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011798 }
11799
11800 /* restore global options */
11801 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011802 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011803#ifdef FEAT_CMDL_INFO
11804# ifdef FEAT_WINDOWS
11805 if (p_ru != save_ru)
11806 status_redraw_all(); /* redraw to draw the ruler */
11807# endif
11808 p_ru = save_ru;
11809#endif
11810#ifdef FEAT_RIGHTLEFT
11811 p_ri = save_ri;
11812 p_hkmap = save_hkmap;
11813#endif
11814 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011815 p_ai = p_ai_nopaste;
11816 p_et = p_et_nopaste;
11817 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011818 p_tw = p_tw_nopaste;
11819 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011820 }
11821
11822 old_p_paste = p_paste;
11823}
11824
11825/*
11826 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11827 *
11828 * Reset 'compatible' and set the values for options that didn't get set yet
11829 * to the Vim defaults.
11830 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011831 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011832 */
11833 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011834vimrc_found(fname, envname)
11835 char_u *fname;
11836 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011837{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011838 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011839 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011840 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011841
11842 if (!option_was_set((char_u *)"cp"))
11843 {
11844 p_cp = FALSE;
11845 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11846 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11847 set_option_default(opt_idx, OPT_FREE, FALSE);
11848 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011849 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011850 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011851
11852 if (fname != NULL)
11853 {
11854 p = vim_getenv(envname, &dofree);
11855 if (p == NULL)
11856 {
11857 /* Set $MYVIMRC to the first vimrc file found. */
11858 p = FullName_save(fname, FALSE);
11859 if (p != NULL)
11860 {
11861 vim_setenv(envname, p);
11862 vim_free(p);
11863 }
11864 }
11865 else if (dofree)
11866 vim_free(p);
11867 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868}
11869
11870/*
11871 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11872 */
11873 void
11874change_compatible(on)
11875 int on;
11876{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011877 int opt_idx;
11878
Bram Moolenaar071d4272004-06-13 20:20:40 +000011879 if (p_cp != on)
11880 {
11881 p_cp = on;
11882 compatible_set();
11883 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011884 opt_idx = findoption((char_u *)"cp");
11885 if (opt_idx >= 0)
11886 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011887}
11888
11889/*
11890 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011891 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011892 */
11893 int
11894option_was_set(name)
11895 char_u *name;
11896{
11897 int idx;
11898
11899 idx = findoption(name);
11900 if (idx < 0) /* unknown option */
11901 return FALSE;
11902 if (options[idx].flags & P_WAS_SET)
11903 return TRUE;
11904 return FALSE;
11905}
11906
11907/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011908 * Reset the flag indicating option "name" was set.
11909 */
11910 void
11911reset_option_was_set(name)
11912 char_u *name;
11913{
11914 int idx = findoption(name);
11915
11916 if (idx >= 0)
11917 options[idx].flags &= ~P_WAS_SET;
11918}
11919
11920/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011921 * compatible_set() - Called when 'compatible' has been set or unset.
11922 *
11923 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11924 * flag) to a Vi compatible value.
11925 * When 'compatible' is unset: Set all options that have a different default
11926 * for Vim (without the P_VI_DEF flag) to that default.
11927 */
11928 static void
11929compatible_set()
11930{
11931 int opt_idx;
11932
11933 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11934 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11935 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11936 set_option_default(opt_idx, OPT_FREE, p_cp);
11937 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011938 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011939}
11940
11941#ifdef FEAT_LINEBREAK
11942
11943# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11944 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011945 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011946# endif
11947
11948/*
11949 * fill_breakat_flags() -- called when 'breakat' changes value.
11950 */
11951 static void
11952fill_breakat_flags()
11953{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011954 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955 int i;
11956
11957 for (i = 0; i < 256; i++)
11958 breakat_flags[i] = FALSE;
11959
11960 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011961 for (p = p_breakat; *p; p++)
11962 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963}
11964
11965# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011966 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011967# endif
11968
11969#endif
11970
11971/*
11972 * Check an option that can be a range of string values.
11973 *
11974 * Return OK for correct value, FAIL otherwise.
11975 * Empty is always OK.
11976 */
11977 static int
11978check_opt_strings(val, values, list)
11979 char_u *val;
11980 char **values;
11981 int list; /* when TRUE: accept a list of values */
11982{
11983 return opt_strings_flags(val, values, NULL, list);
11984}
11985
11986/*
11987 * Handle an option that can be a range of string values.
11988 * Set a flag in "*flagp" for each string present.
11989 *
11990 * Return OK for correct value, FAIL otherwise.
11991 * Empty is always OK.
11992 */
11993 static int
11994opt_strings_flags(val, values, flagp, list)
11995 char_u *val; /* new value */
11996 char **values; /* array of valid string values */
11997 unsigned *flagp;
11998 int list; /* when TRUE: accept a list of values */
11999{
12000 int i;
12001 int len;
12002 unsigned new_flags = 0;
12003
12004 while (*val)
12005 {
12006 for (i = 0; ; ++i)
12007 {
12008 if (values[i] == NULL) /* val not found in values[] */
12009 return FAIL;
12010
12011 len = (int)STRLEN(values[i]);
12012 if (STRNCMP(values[i], val, len) == 0
12013 && ((list && val[len] == ',') || val[len] == NUL))
12014 {
12015 val += len + (val[len] == ',');
12016 new_flags |= (1 << i);
12017 break; /* check next item in val list */
12018 }
12019 }
12020 }
12021 if (flagp != NULL)
12022 *flagp = new_flags;
12023
12024 return OK;
12025}
12026
12027/*
12028 * Read the 'wildmode' option, fill wim_flags[].
12029 */
12030 static int
12031check_opt_wim()
12032{
12033 char_u new_wim_flags[4];
12034 char_u *p;
12035 int i;
12036 int idx = 0;
12037
12038 for (i = 0; i < 4; ++i)
12039 new_wim_flags[i] = 0;
12040
12041 for (p = p_wim; *p; ++p)
12042 {
12043 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12044 ;
12045 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12046 return FAIL;
12047 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12048 new_wim_flags[idx] |= WIM_LONGEST;
12049 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12050 new_wim_flags[idx] |= WIM_FULL;
12051 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12052 new_wim_flags[idx] |= WIM_LIST;
12053 else
12054 return FAIL;
12055 p += i;
12056 if (*p == NUL)
12057 break;
12058 if (*p == ',')
12059 {
12060 if (idx == 3)
12061 return FAIL;
12062 ++idx;
12063 }
12064 }
12065
12066 /* fill remaining entries with last flag */
12067 while (idx < 3)
12068 {
12069 new_wim_flags[idx + 1] = new_wim_flags[idx];
12070 ++idx;
12071 }
12072
12073 /* only when there are no errors, wim_flags[] is changed */
12074 for (i = 0; i < 4; ++i)
12075 wim_flags[i] = new_wim_flags[i];
12076 return OK;
12077}
12078
12079/*
12080 * Check if backspacing over something is allowed.
12081 */
12082 int
12083can_bs(what)
12084 int what; /* BS_INDENT, BS_EOL or BS_START */
12085{
12086 switch (*p_bs)
12087 {
12088 case '2': return TRUE;
12089 case '1': return (what != BS_START);
12090 case '0': return FALSE;
12091 }
12092 return vim_strchr(p_bs, what) != NULL;
12093}
12094
12095/*
12096 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12097 * the file must be considered changed when the value is different.
12098 */
12099 void
12100save_file_ff(buf)
12101 buf_T *buf;
12102{
12103 buf->b_start_ffc = *buf->b_p_ff;
12104 buf->b_start_eol = buf->b_p_eol;
12105#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012106 buf->b_start_bomb = buf->b_p_bomb;
12107
Bram Moolenaar071d4272004-06-13 20:20:40 +000012108 /* Only use free/alloc when necessary, they take time. */
12109 if (buf->b_start_fenc == NULL
12110 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12111 {
12112 vim_free(buf->b_start_fenc);
12113 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12114 }
12115#endif
12116}
12117
12118/*
12119 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12120 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012121 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12122 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012123 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012124 * When "ignore_empty" is true don't consider a new, empty buffer to be
12125 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012126 */
12127 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012128file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012129 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012130 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012131{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012132 /* In a buffer that was never loaded the options are not valid. */
12133 if (buf->b_flags & BF_NEVERLOADED)
12134 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012135 if (ignore_empty
12136 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012137 && buf->b_ml.ml_line_count == 1
12138 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12139 return FALSE;
12140 if (buf->b_start_ffc != *buf->b_p_ff)
12141 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012142 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012143 return TRUE;
12144#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012145 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12146 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012147 if (buf->b_start_fenc == NULL)
12148 return (*buf->b_p_fenc != NUL);
12149 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12150#else
12151 return FALSE;
12152#endif
12153}
12154
12155/*
12156 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12157 */
12158 int
12159check_ff_value(p)
12160 char_u *p;
12161{
12162 return check_opt_strings(p, p_ff_values, FALSE);
12163}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012164
12165/*
12166 * Return the effective shiftwidth value for current buffer, using the
12167 * 'tabstop' value when 'shiftwidth' is zero.
12168 */
12169 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012170get_sw_value(buf)
12171 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012172{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012173 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012174}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012175
12176/*
12177 * Return the effective softtabstop value for the current buffer, using the
12178 * 'tabstop' value when 'softtabstop' is negative.
12179 */
12180 long
12181get_sts_value()
12182{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012183 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012184}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012185
12186/*
12187 * Check matchpairs option for "*initc".
12188 * If there is a match set "*initc" to the matching character and "*findc" to
12189 * the opposite character. Set "*backwards" to the direction.
12190 * When "switchit" is TRUE swap the direction.
12191 */
12192 void
12193find_mps_values(initc, findc, backwards, switchit)
12194 int *initc;
12195 int *findc;
12196 int *backwards;
12197 int switchit;
12198{
12199 char_u *ptr;
12200
12201 ptr = curbuf->b_p_mps;
12202 while (*ptr != NUL)
12203 {
12204#ifdef FEAT_MBYTE
12205 if (has_mbyte)
12206 {
12207 char_u *prev;
12208
12209 if (mb_ptr2char(ptr) == *initc)
12210 {
12211 if (switchit)
12212 {
12213 *findc = *initc;
12214 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12215 *backwards = TRUE;
12216 }
12217 else
12218 {
12219 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12220 *backwards = FALSE;
12221 }
12222 return;
12223 }
12224 prev = ptr;
12225 ptr += mb_ptr2len(ptr) + 1;
12226 if (mb_ptr2char(ptr) == *initc)
12227 {
12228 if (switchit)
12229 {
12230 *findc = *initc;
12231 *initc = mb_ptr2char(prev);
12232 *backwards = FALSE;
12233 }
12234 else
12235 {
12236 *findc = mb_ptr2char(prev);
12237 *backwards = TRUE;
12238 }
12239 return;
12240 }
12241 ptr += mb_ptr2len(ptr);
12242 }
12243 else
12244#endif
12245 {
12246 if (*ptr == *initc)
12247 {
12248 if (switchit)
12249 {
12250 *backwards = TRUE;
12251 *findc = *initc;
12252 *initc = ptr[2];
12253 }
12254 else
12255 {
12256 *backwards = FALSE;
12257 *findc = ptr[2];
12258 }
12259 return;
12260 }
12261 ptr += 2;
12262 if (*ptr == *initc)
12263 {
12264 if (switchit)
12265 {
12266 *backwards = FALSE;
12267 *findc = *initc;
12268 *initc = ptr[-2];
12269 }
12270 else
12271 {
12272 *backwards = TRUE;
12273 *findc = ptr[-2];
12274 }
12275 return;
12276 }
12277 ++ptr;
12278 }
12279 if (*ptr == ',')
12280 ++ptr;
12281 }
12282}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012283
12284#if defined(FEAT_LINEBREAK) || defined(PROTO)
12285/*
12286 * This is called when 'breakindentopt' is changed and when a window is
12287 * initialized.
12288 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012289 static int
12290briopt_check(wp)
12291 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012292{
12293 char_u *p;
12294 int bri_shift = 0;
12295 long bri_min = 20;
12296 int bri_sbr = FALSE;
12297
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012298 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012299 while (*p != NUL)
12300 {
12301 if (STRNCMP(p, "shift:", 6) == 0
12302 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12303 {
12304 p += 6;
12305 bri_shift = getdigits(&p);
12306 }
12307 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12308 {
12309 p += 4;
12310 bri_min = getdigits(&p);
12311 }
12312 else if (STRNCMP(p, "sbr", 3) == 0)
12313 {
12314 p += 3;
12315 bri_sbr = TRUE;
12316 }
12317 if (*p != ',' && *p != NUL)
12318 return FAIL;
12319 if (*p == ',')
12320 ++p;
12321 }
12322
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012323 wp->w_p_brishift = bri_shift;
12324 wp->w_p_brimin = bri_min;
12325 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012326
12327 return OK;
12328}
12329#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012330
12331/*
12332 * Get the local or global value of 'backupcopy'.
12333 */
12334 unsigned int
12335get_bkc_value(buf)
12336 buf_T *buf;
12337{
12338 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12339}