blob: 35732114480c3ba81d90e0c7688ec401238e01b0 [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 Moolenaar887c1fe2016-01-02 17:56:35 +01001943 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 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 Moolenaar071d4272004-06-13 20:20:40 +00002300 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002301# endif
2302# endif
2303# endif
2304#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002305 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2307 (char_u *)&p_shcf, PV_NONE,
2308 {
2309#if defined(MSDOS) || defined(MSWIN)
2310 (char_u *)"/c",
2311#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2316#ifdef FEAT_QUICKFIX
2317 (char_u *)&p_sp, PV_NONE,
2318 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002319#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321#else
2322 (char_u *)">",
2323#endif
2324 (char_u *)0L}
2325#else
2326 (char_u *)NULL, PV_NONE,
2327 {(char_u *)0L, (char_u *)0L}
2328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2331 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2334 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2337#ifdef BACKSLASH_IN_FILENAME
2338 (char_u *)&p_ssl, PV_NONE,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002343 {"shelltemp", "stmp", P_BOOL,
2344 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002345 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"shelltype", "st", P_NUM|P_VI_DEF,
2347#ifdef AMIGA
2348 (char_u *)&p_st, PV_NONE,
2349#else
2350 (char_u *)NULL, PV_NONE,
2351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2354 (char_u *)&p_sxq, PV_NONE,
2355 {
2356#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2357 (char_u *)"\"",
2358#else
2359 (char_u *)"",
2360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002362 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2363 (char_u *)&p_sxe, PV_NONE,
2364 {
2365#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2366 (char_u *)"\"&|<>()@^",
2367#else
2368 (char_u *)"",
2369#endif
2370 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2372 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2375 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002376 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2378 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002379 {(char_u *)"", (char_u *)"filnxtToO"}
2380 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"shortname", "sn", P_BOOL|P_VI_DEF,
2382#ifdef SHORT_FNAME
2383 (char_u *)NULL, PV_NONE,
2384#else
2385 (char_u *)&p_sn, PV_SN,
2386#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2389#ifdef FEAT_LINEBREAK
2390 (char_u *)&p_sbr, PV_NONE,
2391#else
2392 (char_u *)NULL, PV_NONE,
2393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"showcmd", "sc", P_BOOL|P_VIM,
2396#ifdef FEAT_CMDL_INFO
2397 (char_u *)&p_sc, PV_NONE,
2398#else
2399 (char_u *)NULL, PV_NONE,
2400#endif
2401 {(char_u *)FALSE,
2402#ifdef UNIX
2403 (char_u *)FALSE
2404#else
2405 (char_u *)TRUE
2406#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2409 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2412 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"showmode", "smd", P_BOOL|P_VIM,
2415 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002417 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2418#ifdef FEAT_WINDOWS
2419 (char_u *)&p_stal, PV_NONE,
2420#else
2421 (char_u *)NULL, PV_NONE,
2422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2425 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002426 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2428 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2431 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2434 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002435 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2437#ifdef FEAT_SMARTINDENT
2438 (char_u *)&p_si, PV_SI,
2439#else
2440 (char_u *)NULL, PV_NONE,
2441#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2444 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2447 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2450 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002452 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002453#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002454 (char_u *)VAR_WIN, PV_SPELL,
2455#else
2456 (char_u *)NULL, PV_NONE,
2457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002459 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002460#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002461 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002462 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002463#else
2464 (char_u *)NULL, PV_NONE,
2465 {(char_u *)0L, (char_u *)0L}
2466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002467 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002468 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2469 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002470#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002471 (char_u *)&p_spf, PV_SPF,
2472 {(char_u *)"", (char_u *)0L}
2473#else
2474 (char_u *)NULL, PV_NONE,
2475 {(char_u *)0L, (char_u *)0L}
2476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002477 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002478 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2479 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002480#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002481 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002482 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002483#else
2484 (char_u *)NULL, PV_NONE,
2485 {(char_u *)0L, (char_u *)0L}
2486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002487 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002488 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002489#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002490 (char_u *)&p_sps, PV_NONE,
2491 {(char_u *)"best", (char_u *)0L}
2492#else
2493 (char_u *)NULL, PV_NONE,
2494 {(char_u *)0L, (char_u *)0L}
2495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2498#ifdef FEAT_WINDOWS
2499 (char_u *)&p_sb, PV_NONE,
2500#else
2501 (char_u *)NULL, PV_NONE,
2502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"splitright", "spr", P_BOOL|P_VI_DEF,
2505#ifdef FEAT_VERTSPLIT
2506 (char_u *)&p_spr, PV_NONE,
2507#else
2508 (char_u *)NULL, PV_NONE,
2509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2512 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002513 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2515#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002516 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517#else
2518 (char_u *)NULL, PV_NONE,
2519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002521 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 (char_u *)&p_su, PV_NONE,
2523 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002524 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002525 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002526#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 (char_u *)&p_sua, PV_SUA,
2528 {(char_u *)"", (char_u *)0L}
2529#else
2530 (char_u *)NULL, PV_NONE,
2531 {(char_u *)0L, (char_u *)0L}
2532#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2535 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002537 {"swapsync", "sws", P_STRING|P_VI_DEF,
2538 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002540 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002542 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002543 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2544#ifdef FEAT_SYN_HL
2545 (char_u *)&p_smc, PV_SMC,
2546 {(char_u *)3000L, (char_u *)0L}
2547#else
2548 (char_u *)NULL, PV_NONE,
2549 {(char_u *)0L, (char_u *)0L}
2550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002551 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002552 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002553#ifdef FEAT_SYN_HL
2554 (char_u *)&p_syn, PV_SYN,
2555 {(char_u *)"", (char_u *)0L}
2556#else
2557 (char_u *)NULL, PV_NONE,
2558 {(char_u *)0L, (char_u *)0L}
2559#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002561 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2562#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002563 (char_u *)&p_tal, PV_NONE,
2564#else
2565 (char_u *)NULL, PV_NONE,
2566#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002567 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002568 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2569#ifdef FEAT_WINDOWS
2570 (char_u *)&p_tpm, PV_NONE,
2571#else
2572 (char_u *)NULL, PV_NONE,
2573#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2576 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2579 (char_u *)&p_tbs, PV_NONE,
2580#ifdef VMS /* binary searching doesn't appear to work on VMS */
2581 {(char_u *)0L, (char_u *)0L}
2582#else
2583 {(char_u *)TRUE, (char_u *)0L}
2584#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002585 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002586 {"tagcase", "tc", P_STRING|P_VIM,
2587 (char_u *)&p_tc, PV_TC,
2588 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589 {"taglength", "tl", P_NUM|P_VI_DEF,
2590 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 {"tagrelative", "tr", P_BOOL|P_VIM,
2593 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002595 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002596 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {
2598#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2599 (char_u *)"./tags,./TAGS,tags,TAGS",
2600#else
2601 (char_u *)"./tags,tags",
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2605 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002606 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2608 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002609 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2611#ifdef FEAT_ARABIC
2612 (char_u *)&p_tbidi, PV_NONE,
2613#else
2614 (char_u *)NULL, PV_NONE,
2615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2618#ifdef FEAT_MBYTE
2619 (char_u *)&p_tenc, PV_NONE,
2620 {(char_u *)"", (char_u *)0L}
2621#else
2622 (char_u *)NULL, PV_NONE,
2623 {(char_u *)0L, (char_u *)0L}
2624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002625 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 {"terse", NULL, P_BOOL|P_VI_DEF,
2627 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 {"textauto", "ta", P_BOOL|P_VIM,
2630 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2632 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2634 (char_u *)&p_tx, PV_TX,
2635 {
2636#ifdef USE_CRNL
2637 (char_u *)TRUE,
2638#else
2639 (char_u *)FALSE,
2640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002641 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002642 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002645 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002647 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648#else
2649 (char_u *)NULL, PV_NONE,
2650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2653 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"timeout", "to", P_BOOL|P_VI_DEF,
2656 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2659 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"title", NULL, P_BOOL|P_VI_DEF,
2662#ifdef FEAT_TITLE
2663 (char_u *)&p_title, PV_NONE,
2664#else
2665 (char_u *)NULL, PV_NONE,
2666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"titlelen", NULL, P_NUM|P_VI_DEF,
2669#ifdef FEAT_TITLE
2670 (char_u *)&p_titlelen, PV_NONE,
2671#else
2672 (char_u *)NULL, PV_NONE,
2673#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002674 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002675 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002676#ifdef FEAT_TITLE
2677 (char_u *)&p_titleold, PV_NONE,
2678 {(char_u *)N_("Thanks for flying Vim"),
2679 (char_u *)0L}
2680#else
2681 (char_u *)NULL, PV_NONE,
2682 {(char_u *)0L, (char_u *)0L}
2683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 {"titlestring", NULL, P_STRING|P_VI_DEF,
2686#ifdef FEAT_TITLE
2687 (char_u *)&p_titlestring, PV_NONE,
2688#else
2689 (char_u *)NULL, PV_NONE,
2690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002693 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002695 {(char_u *)"icons,tooltips", (char_u *)0L}
2696 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002698#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2700 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702#endif
2703 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2704 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002705 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2707 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2710 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2713 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2716#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2717 (char_u *)&p_ttym, PV_NONE,
2718#else
2719 (char_u *)NULL, PV_NONE,
2720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2723 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2726 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002728 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2729 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002730#ifdef FEAT_PERSISTENT_UNDO
2731 (char_u *)&p_udir, PV_NONE,
2732 {(char_u *)".", (char_u *)0L}
2733#else
2734 (char_u *)NULL, PV_NONE,
2735 {(char_u *)0L, (char_u *)0L}
2736#endif
2737 SCRIPTID_INIT},
2738 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2739#ifdef FEAT_PERSISTENT_UNDO
2740 (char_u *)&p_udf, PV_UDF,
2741#else
2742 (char_u *)NULL, PV_NONE,
2743#endif
2744 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002746 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002748#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002749 (char_u *)1000L,
2750#else
2751 (char_u *)100L,
2752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002753 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002754 {"undoreload", "ur", P_NUM|P_VI_DEF,
2755 (char_u *)&p_ur, PV_NONE,
2756 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {"updatecount", "uc", P_NUM|P_VI_DEF,
2758 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002759 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"updatetime", "ut", P_NUM|P_VI_DEF,
2761 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002762 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"verbose", "vbs", P_NUM|P_VI_DEF,
2764 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002765 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002766 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2767 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002768 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2770#ifdef FEAT_SESSION
2771 (char_u *)&p_vdir, PV_NONE,
2772 {(char_u *)DFLT_VDIR, (char_u *)0L}
2773#else
2774 (char_u *)NULL, PV_NONE,
2775 {(char_u *)0L, (char_u *)0L}
2776#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002778 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779#ifdef FEAT_SESSION
2780 (char_u *)&p_vop, PV_NONE,
2781 {(char_u *)"folds,options,cursor", (char_u *)0L}
2782#else
2783 (char_u *)NULL, PV_NONE,
2784 {(char_u *)0L, (char_u *)0L}
2785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002787 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788#ifdef FEAT_VIMINFO
2789 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002790#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002791 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792#else
2793# ifdef AMIGA
2794 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002795 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002797 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798# endif
2799#endif
2800#else
2801 (char_u *)NULL, PV_NONE,
2802 {(char_u *)0L, (char_u *)0L}
2803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002805 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2806 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807#ifdef FEAT_VIRTUALEDIT
2808 (char_u *)&p_ve, PV_NONE,
2809 {(char_u *)"", (char_u *)""}
2810#else
2811 (char_u *)NULL, PV_NONE,
2812 {(char_u *)0L, (char_u *)0L}
2813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002814 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2816 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002817 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {"w300", NULL, P_NUM|P_VI_DEF,
2819 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002820 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"w1200", NULL, P_NUM|P_VI_DEF,
2822 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002823 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"w9600", NULL, P_NUM|P_VI_DEF,
2825 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"warn", NULL, P_BOOL|P_VI_DEF,
2828 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2831 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002833 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002835 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 {"wildchar", "wc", P_NUM|P_VIM,
2837 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2839 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002840 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002843 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844#ifdef FEAT_WILDIGN
2845 (char_u *)&p_wig, PV_NONE,
2846#else
2847 (char_u *)NULL, PV_NONE,
2848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002850 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2851 (char_u *)&p_wic, PV_NONE,
2852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2854#ifdef FEAT_WILDMENU
2855 (char_u *)&p_wmnu, PV_NONE,
2856#else
2857 (char_u *)NULL, PV_NONE,
2858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002860 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002863 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2864#ifdef FEAT_CMDL_COMPL
2865 (char_u *)&p_wop, PV_NONE,
2866 {(char_u *)"", (char_u *)0L}
2867#else
2868 (char_u *)NULL, PV_NONE,
2869 {(char_u *)NULL, (char_u *)0L}
2870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002871 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2873#ifdef FEAT_WAK
2874 (char_u *)&p_wak, PV_NONE,
2875 {(char_u *)"menu", (char_u *)0L}
2876#else
2877 (char_u *)NULL, PV_NONE,
2878 {(char_u *)NULL, (char_u *)0L}
2879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002880 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002882 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002883 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 {"winheight", "wh", P_NUM|P_VI_DEF,
2885#ifdef FEAT_WINDOWS
2886 (char_u *)&p_wh, PV_NONE,
2887#else
2888 (char_u *)NULL, PV_NONE,
2889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002890 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002892#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893 (char_u *)VAR_WIN, PV_WFH,
2894#else
2895 (char_u *)NULL, PV_NONE,
2896#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002898 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2899#ifdef FEAT_VERTSPLIT
2900 (char_u *)VAR_WIN, PV_WFW,
2901#else
2902 (char_u *)NULL, PV_NONE,
2903#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002904 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002905 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2906#ifdef FEAT_WINDOWS
2907 (char_u *)&p_wmh, PV_NONE,
2908#else
2909 (char_u *)NULL, PV_NONE,
2910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002911 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2913#ifdef FEAT_VERTSPLIT
2914 (char_u *)&p_wmw, PV_NONE,
2915#else
2916 (char_u *)NULL, PV_NONE,
2917#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002918 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2920#ifdef FEAT_VERTSPLIT
2921 (char_u *)&p_wiw, PV_NONE,
2922#else
2923 (char_u *)NULL, PV_NONE,
2924#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2927 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002928 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2930 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002931 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2933 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935 {"write", NULL, P_BOOL|P_VI_DEF,
2936 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002937 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938 {"writeany", "wa", P_BOOL|P_VI_DEF,
2939 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002940 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2942 (char_u *)&p_wb, PV_NONE,
2943 {
2944#ifdef FEAT_WRITEBACKUP
2945 (char_u *)TRUE,
2946#else
2947 (char_u *)FALSE,
2948#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002949 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950 {"writedelay", "wd", P_NUM|P_VI_DEF,
2951 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002952 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953
2954/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002955#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958
2959 p_term("t_AB", T_CAB)
2960 p_term("t_AF", T_CAF)
2961 p_term("t_AL", T_CAL)
2962 p_term("t_al", T_AL)
2963 p_term("t_bc", T_BC)
2964 p_term("t_cd", T_CD)
2965 p_term("t_ce", T_CE)
2966 p_term("t_cl", T_CL)
2967 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002968 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 p_term("t_Co", T_CCO)
2970 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002971 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 p_term("t_cs", T_CS)
2973#ifdef FEAT_VERTSPLIT
2974 p_term("t_CV", T_CSV)
2975#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 p_term("t_da", T_DA)
2977 p_term("t_db", T_DB)
2978 p_term("t_DL", T_CDL)
2979 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002980 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981 p_term("t_fs", T_FS)
2982 p_term("t_IE", T_CIE)
2983 p_term("t_IS", T_CIS)
2984 p_term("t_ke", T_KE)
2985 p_term("t_ks", T_KS)
2986 p_term("t_le", T_LE)
2987 p_term("t_mb", T_MB)
2988 p_term("t_md", T_MD)
2989 p_term("t_me", T_ME)
2990 p_term("t_mr", T_MR)
2991 p_term("t_ms", T_MS)
2992 p_term("t_nd", T_ND)
2993 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002994 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 p_term("t_RI", T_CRI)
2996 p_term("t_RV", T_CRV)
2997 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02002999 p_term("t_Sf", T_CSF)
3000 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003002 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 p_term("t_te", T_TE)
3005 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003006 p_term("t_ts", T_TS)
3007 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 p_term("t_ue", T_UE)
3009 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003010 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_vb", T_VB)
3012 p_term("t_ve", T_VE)
3013 p_term("t_vi", T_VI)
3014 p_term("t_vs", T_VS)
3015 p_term("t_WP", T_CWP)
3016 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003017 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 p_term("t_xs", T_XS)
3019 p_term("t_ZH", T_CZH)
3020 p_term("t_ZR", T_CZR)
3021
3022/* terminal key codes are not in here */
3023
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003024 /* end marker */
3025 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026};
3027
3028#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3029
3030#ifdef FEAT_MBYTE
3031static char *(p_ambw_values[]) = {"single", "double", NULL};
3032#endif
3033static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003034static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003036#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003037static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003038#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003039#ifdef FEAT_CMDL_COMPL
3040static char *(p_wop_values[]) = {"tagfile", NULL};
3041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042#ifdef FEAT_WAK
3043static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3044#endif
3045static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3047static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049#ifdef FEAT_BROWSE
3050static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3051#endif
3052#ifdef FEAT_SCROLLBIND
3053static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3054#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003055static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056#ifdef FEAT_VERTSPLIT
3057static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3058#endif
3059#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003060# ifdef FEAT_AUTOCMD
3061static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3062# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003064# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3066#endif
3067static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3068#ifdef FEAT_FOLDING
3069static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003070# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003072# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 NULL};
3074static char *(p_fcl_values[]) = {"all", NULL};
3075#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003076#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003077static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003078#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079
3080static void set_option_default __ARGS((int, int opt_flags, int compatible));
3081static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003082static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003083static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084static char_u *illegal_char __ARGS((char_u *, int));
3085static int string_to_key __ARGS((char_u *arg));
3086#ifdef FEAT_CMDWIN
3087static char_u *check_cedit __ARGS((void));
3088#endif
3089#ifdef FEAT_TITLE
3090static void did_set_title __ARGS((int icon));
3091#endif
3092static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3093static void didset_options __ARGS((void));
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003094static void didset_options2 __ARGS((void));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003096#if defined(FEAT_EVAL) || defined(PROTO)
3097static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3098#else
3099# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003102static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103static 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));
3104static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003105#ifdef FEAT_SYN_HL
3106static int int_cmp __ARGS((const void *a, const void *b));
3107#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108#ifdef FEAT_CLIPBOARD
3109static char_u *check_clipboard_option __ARGS((void));
3110#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003111#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003112static char_u *did_set_spell_option __ARGS((int is_spellfile));
Bram Moolenaar860cae12010-06-05 23:22:07 +02003113static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003114#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003115#ifdef FEAT_EVAL
3116static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3117#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003119static 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 +00003120static void check_redraw __ARGS((long_u flags));
3121static int findoption __ARGS((char_u *));
3122static int find_key_option __ARGS((char_u *));
3123static void showoptions __ARGS((int all, int opt_flags));
3124static int optval_default __ARGS((struct vimoption *, char_u *varp));
3125static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3126static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3127static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3128static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3129static int istermoption __ARGS((struct vimoption *));
3130static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3131static char_u *get_varp __ARGS((struct vimoption *));
3132static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003133static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3135#ifdef FEAT_LANGMAP
3136static void langmap_init __ARGS((void));
3137static void langmap_set __ARGS((void));
3138#endif
3139static void paste_option_changed __ARGS((void));
3140static void compatible_set __ARGS((void));
3141#ifdef FEAT_LINEBREAK
3142static void fill_breakat_flags __ARGS((void));
3143#endif
3144static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3145static int check_opt_strings __ARGS((char_u *val, char **values, int));
3146static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003147#ifdef FEAT_LINEBREAK
3148static int briopt_check __ARGS((win_T *wp));
3149#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150
3151/*
3152 * Initialize the options, first part.
3153 *
3154 * Called only once from main(), just after creating the first buffer.
3155 */
3156 void
3157set_init_1()
3158{
3159 char_u *p;
3160 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003161 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162
3163#ifdef FEAT_LANGMAP
3164 langmap_init();
3165#endif
3166
3167 /* Be Vi compatible by default */
3168 p_cp = TRUE;
3169
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003170 /* Use POSIX compatibility when $VIM_POSIX is set. */
3171 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003172 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003173 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003174 set_string_default("shm", (char_u *)"A");
3175 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003176
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 /*
3178 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003179 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003181 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003182#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003184 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003186 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003188 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189# endif
3190#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003191 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192 set_string_default("sh", p);
3193
3194#ifdef FEAT_WILDIGN
3195 /*
3196 * Set the default for 'backupskip' to include environment variables for
3197 * temp files.
3198 */
3199 {
3200# ifdef UNIX
3201 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3202# else
3203 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3204# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003205 int len;
3206 garray_T ga;
3207 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208
3209 ga_init2(&ga, 1, 100);
3210 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3211 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003212 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213# ifdef UNIX
3214 if (*names[n] == NUL)
3215 p = (char_u *)"/tmp";
3216 else
3217# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003218 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 if (p != NULL && *p != NUL)
3220 {
3221 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003222 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 if (ga_grow(&ga, len) == OK)
3224 {
3225 if (ga.ga_len > 0)
3226 STRCAT(ga.ga_data, ",");
3227 STRCAT(ga.ga_data, p);
3228 add_pathsep(ga.ga_data);
3229 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230 ga.ga_len += len;
3231 }
3232 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003233 if (mustfree)
3234 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235 }
3236 if (ga.ga_data != NULL)
3237 {
3238 set_string_default("bsk", ga.ga_data);
3239 vim_free(ga.ga_data);
3240 }
3241 }
3242#endif
3243
3244 /*
3245 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3246 */
3247 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003248 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003250#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3251 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3252#endif
3253 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003255 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003256 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257#else
3258# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003259 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003260 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003262 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263# endif
3264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003266 opt_idx = findoption((char_u *)"maxmem");
3267 if (opt_idx >= 0)
3268 {
3269#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003270 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3271 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003272#endif
3273 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3274 }
3275 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276 }
3277
3278#ifdef FEAT_GUI_W32
3279 /* force 'shortname' for Win32s */
3280 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003281 {
3282 opt_idx = findoption((char_u *)"shortname");
3283 if (opt_idx >= 0)
3284 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3285 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286#endif
3287
3288#ifdef FEAT_SEARCHPATH
3289 {
3290 char_u *cdpath;
3291 char_u *buf;
3292 int i;
3293 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003294 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295
3296 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003297 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298 if (cdpath != NULL)
3299 {
3300 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3301 if (buf != NULL)
3302 {
3303 buf[0] = ','; /* start with ",", current dir first */
3304 j = 1;
3305 for (i = 0; cdpath[i] != NUL; ++i)
3306 {
3307 if (vim_ispathlistsep(cdpath[i]))
3308 buf[j++] = ',';
3309 else
3310 {
3311 if (cdpath[i] == ' ' || cdpath[i] == ',')
3312 buf[j++] = '\\';
3313 buf[j++] = cdpath[i];
3314 }
3315 }
3316 buf[j] = NUL;
3317 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003318 if (opt_idx >= 0)
3319 {
3320 options[opt_idx].def_val[VI_DEFAULT] = buf;
3321 options[opt_idx].flags |= P_DEF_ALLOCED;
3322 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003323 else
3324 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003326 if (mustfree)
3327 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328 }
3329 }
3330#endif
3331
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003332#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 /* Set print encoding on platforms that don't default to latin1 */
3334 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003335# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 (char_u *)"cp1252"
3337# else
3338# ifdef VMS
3339 (char_u *)"dec-mcs"
3340# else
3341# ifdef EBCDIC
3342 (char_u *)"ebcdic-uk"
3343# else
3344# ifdef MAC
3345 (char_u *)"mac-roman"
3346# else /* HPUX */
3347 (char_u *)"hp-roman8"
3348# endif
3349# endif
3350# endif
3351# endif
3352 );
3353#endif
3354
3355#ifdef FEAT_POSTSCRIPT
3356 /* 'printexpr' must be allocated to be able to evaluate it. */
3357 set_string_default("pexpr",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003358# if defined(MSWIN) || defined(MSDOS)
Bram Moolenaared203462004-06-16 11:19:22 +00003359 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360# else
3361# ifdef VMS
3362 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3363
3364# else
3365 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3366# endif
3367# endif
3368 );
3369#endif
3370
3371 /*
3372 * Set all the options (except the terminal options) to their default
3373 * value. Also set the global value for local options.
3374 */
3375 set_options_default(0);
3376
3377#ifdef FEAT_GUI
3378 if (found_reverse_arg)
3379 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3380#endif
3381
3382 curbuf->b_p_initialized = TRUE;
3383 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003384 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385 check_buf_options(curbuf);
3386 check_win_options(curwin);
3387 check_options();
3388
3389 /* Must be before option_expand(), because that one needs vim_isIDc() */
3390 didset_options();
3391
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003392#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003393 /* Use the current chartab for the generic chartab. This is not in
3394 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003395 init_spell_chartab();
3396#endif
3397
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398 /*
3399 * Expand environment variables and things like "~" for the defaults.
3400 * If option_expand() returns non-NULL the variable is expanded. This can
3401 * only happen for non-indirect options.
3402 * Also set the default to the expanded value, so ":set" does not list
3403 * them.
3404 * Don't set the P_ALLOCED flag, because we don't want to free the
3405 * default.
3406 */
3407 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3408 {
3409 if ((options[opt_idx].flags & P_GETTEXT)
3410 && options[opt_idx].var != NULL)
3411 p = (char_u *)_(*(char **)options[opt_idx].var);
3412 else
3413 p = option_expand(opt_idx, NULL);
3414 if (p != NULL && (p = vim_strsave(p)) != NULL)
3415 {
3416 *(char_u **)options[opt_idx].var = p;
3417 /* VIMEXP
3418 * Defaults for all expanded options are currently the same for Vi
3419 * and Vim. When this changes, add some code here! Also need to
3420 * split P_DEF_ALLOCED in two.
3421 */
3422 if (options[opt_idx].flags & P_DEF_ALLOCED)
3423 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3424 options[opt_idx].def_val[VI_DEFAULT] = p;
3425 options[opt_idx].flags |= P_DEF_ALLOCED;
3426 }
3427 }
3428
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 save_file_ff(curbuf); /* Buffer is unchanged */
3430
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431#if defined(FEAT_ARABIC)
3432 /* Detect use of mlterm.
3433 * Mlterm is a terminal emulator akin to xterm that has some special
3434 * abilities (bidi namely).
3435 * NOTE: mlterm's author is being asked to 'set' a variable
3436 * instead of an environment variable due to inheritance.
3437 */
3438 if (mch_getenv((char_u *)"MLTERM") != NULL)
3439 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3440#endif
3441
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003442 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443
3444#ifdef FEAT_MBYTE
3445# if defined(WIN3264) && defined(FEAT_GETTEXT)
3446 /*
3447 * If $LANG isn't set, try to get a good value for it. This makes the
3448 * right language be used automatically. Don't do this for English.
3449 */
3450 if (mch_getenv((char_u *)"LANG") == NULL)
3451 {
3452 char buf[20];
3453
3454 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3455 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3456 * only the first two. */
3457 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3458 (LPTSTR)buf, 20);
3459 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3460 {
3461 /* There are a few exceptions (probably more) */
3462 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3463 STRCPY(buf, "zh_TW");
3464 else if (STRNICMP(buf, "chs", 3) == 0
3465 || STRNICMP(buf, "zhc", 3) == 0)
3466 STRCPY(buf, "zh_CN");
3467 else if (STRNICMP(buf, "jp", 2) == 0)
3468 STRCPY(buf, "ja");
3469 else
3470 buf[2] = NUL; /* truncate to two-letter code */
3471 vim_setenv("LANG", buf);
3472 }
3473 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003474# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003475# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003476 /* Moved to os_mac_conv.c to avoid dependency problems. */
3477 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003478# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479# endif
3480
3481 /* enc_locale() will try to find the encoding of the current locale. */
3482 p = enc_locale();
3483 if (p != NULL)
3484 {
3485 char_u *save_enc;
3486
3487 /* Try setting 'encoding' and check if the value is valid.
3488 * If not, go back to the default "latin1". */
3489 save_enc = p_enc;
3490 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003491 if (STRCMP(p_enc, "gb18030") == 0)
3492 {
3493 /* We don't support "gb18030", but "cp936" is a good substitute
3494 * for practical purposes, thus use that. It's not an alias to
3495 * still support conversion between gb18030 and utf-8. */
3496 p_enc = vim_strsave((char_u *)"cp936");
3497 vim_free(p);
3498 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003499 if (mb_init() == NULL)
3500 {
3501 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003502 if (opt_idx >= 0)
3503 {
3504 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3505 options[opt_idx].flags |= P_DEF_ALLOCED;
3506 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003508#if defined(MSDOS) || defined(MSWIN) || defined(MACOS) \
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003509 || defined(VMS)
3510 if (STRCMP(p_enc, "latin1") == 0
3511# ifdef FEAT_MBYTE
3512 || enc_utf8
3513# endif
3514 )
3515 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003516 /* Adjust the default for 'isprint' and 'iskeyword' to match
3517 * latin1. Also set the defaults for when 'nocompatible' is
3518 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003519 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003520 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003521 set_string_option_direct((char_u *)"isk", -1,
3522 ISK_LATIN1, OPT_FREE, SID_NONE);
3523 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003524 if (opt_idx >= 0)
3525 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003526 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003527 if (opt_idx >= 0)
3528 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003529 (void)init_chartab();
3530 }
3531#endif
3532
Bram Moolenaar071d4272004-06-13 20:20:40 +00003533# if defined(WIN3264) && !defined(FEAT_GUI)
3534 /* Win32 console: When GetACP() returns a different value from
3535 * GetConsoleCP() set 'termencoding'. */
3536 if (GetACP() != GetConsoleCP())
3537 {
3538 char buf[50];
3539
3540 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3541 p_tenc = vim_strsave((char_u *)buf);
3542 if (p_tenc != NULL)
3543 {
3544 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003545 if (opt_idx >= 0)
3546 {
3547 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3548 options[opt_idx].flags |= P_DEF_ALLOCED;
3549 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003550 convert_setup(&input_conv, p_tenc, p_enc);
3551 convert_setup(&output_conv, p_enc, p_tenc);
3552 }
3553 else
3554 p_tenc = empty_option;
3555 }
3556# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003557# if defined(WIN3264) && defined(FEAT_MBYTE)
3558 /* $HOME may have characters in active code page. */
3559 init_homedir();
3560# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561 }
3562 else
3563 {
3564 vim_free(p_enc);
3565 p_enc = save_enc;
3566 }
3567 }
3568#endif
3569
3570#ifdef FEAT_MULTI_LANG
3571 /* Set the default for 'helplang'. */
3572 set_helplang_default(get_mess_lang());
3573#endif
3574}
3575
3576/*
3577 * Set an option to its default value.
3578 * This does not take care of side effects!
3579 */
3580 static void
3581set_option_default(opt_idx, opt_flags, compatible)
3582 int opt_idx;
3583 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3584 int compatible; /* use Vi default value */
3585{
3586 char_u *varp; /* pointer to variable for current option */
3587 int dvi; /* index in def_val[] */
3588 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003589 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003590 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3591
3592 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3593 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003594 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003595 {
3596 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3597 if (flags & P_STRING)
3598 {
3599 /* Use set_string_option_direct() for local options to handle
3600 * freeing and allocating the value. */
3601 if (options[opt_idx].indir != PV_NONE)
3602 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003603 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003604 else
3605 {
3606 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3607 free_string_option(*(char_u **)(varp));
3608 *(char_u **)varp = options[opt_idx].def_val[dvi];
3609 options[opt_idx].flags &= ~P_ALLOCED;
3610 }
3611 }
3612 else if (flags & P_NUM)
3613 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003614 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615 win_comp_scroll(curwin);
3616 else
3617 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003618 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003619 /* May also set global value for local option. */
3620 if (both)
3621 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3622 *(long *)varp;
3623 }
3624 }
3625 else /* P_BOOL */
3626 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003627 /* the cast to long is required for Manx C, long_i is needed for
3628 * MSVC */
3629 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003630#ifdef UNIX
3631 /* 'modeline' defaults to off for root */
3632 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3633 *(int *)varp = FALSE;
3634#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003635 /* May also set global value for local option. */
3636 if (both)
3637 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3638 *(int *)varp;
3639 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003640
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003641 /* The default value is not insecure. */
3642 flagsp = insecure_flag(opt_idx, opt_flags);
3643 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003644 }
3645
3646#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003647 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003648#endif
3649}
3650
3651/*
3652 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003653 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 */
3655 static void
3656set_options_default(opt_flags)
3657 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3658{
3659 int i;
3660#ifdef FEAT_WINDOWS
3661 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003662 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003663#endif
3664
3665 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003666 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003667#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003668 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003669 || (TRUE
3670# if defined(FEAT_MBYTE)
3671 && options[i].var != (char_u *)&p_enc
3672# endif
3673# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003674 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003675 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003676# endif
3677 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003678#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003679 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680 set_option_default(i, opt_flags, p_cp);
3681
3682#ifdef FEAT_WINDOWS
3683 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003684 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685 win_comp_scroll(wp);
3686#else
3687 win_comp_scroll(curwin);
3688#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003689#ifdef FEAT_CINDENT
3690 parse_cino(curbuf);
3691#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692}
3693
3694/*
3695 * Set the Vi-default value of a string option.
3696 * Used for 'sh', 'backupskip' and 'term'.
3697 */
3698 void
3699set_string_default(name, val)
3700 char *name;
3701 char_u *val;
3702{
3703 char_u *p;
3704 int opt_idx;
3705
3706 p = vim_strsave(val);
3707 if (p != NULL) /* we don't want a NULL */
3708 {
3709 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003710 if (opt_idx >= 0)
3711 {
3712 if (options[opt_idx].flags & P_DEF_ALLOCED)
3713 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3714 options[opt_idx].def_val[VI_DEFAULT] = p;
3715 options[opt_idx].flags |= P_DEF_ALLOCED;
3716 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717 }
3718}
3719
3720/*
3721 * Set the Vi-default value of a number option.
3722 * Used for 'lines' and 'columns'.
3723 */
3724 void
3725set_number_default(name, val)
3726 char *name;
3727 long val;
3728{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003729 int opt_idx;
3730
3731 opt_idx = findoption((char_u *)name);
3732 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003733 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734}
3735
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003736#if defined(EXITFREE) || defined(PROTO)
3737/*
3738 * Free all options.
3739 */
3740 void
3741free_all_options()
3742{
3743 int i;
3744
3745 for (i = 0; !istermoption(&options[i]); i++)
3746 {
3747 if (options[i].indir == PV_NONE)
3748 {
3749 /* global option: free value and default value. */
3750 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3751 free_string_option(*(char_u **)options[i].var);
3752 if (options[i].flags & P_DEF_ALLOCED)
3753 free_string_option(options[i].def_val[VI_DEFAULT]);
3754 }
3755 else if (options[i].var != VAR_WIN
3756 && (options[i].flags & P_STRING))
3757 /* buffer-local option: free global value */
3758 free_string_option(*(char_u **)options[i].var);
3759 }
3760}
3761#endif
3762
3763
Bram Moolenaar071d4272004-06-13 20:20:40 +00003764/*
3765 * Initialize the options, part two: After getting Rows and Columns and
3766 * setting 'term'.
3767 */
3768 void
3769set_init_2()
3770{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003771 int idx;
3772
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 /*
3774 * 'scroll' defaults to half the window height. Note that this default is
3775 * wrong when the window height changes.
3776 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003777 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003778 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003779 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003780 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781 comp_col();
3782
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003783 /*
3784 * 'window' is only for backwards compatibility with Vi.
3785 * Default is Rows - 1.
3786 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003787 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003788 p_window = Rows - 1;
3789 set_number_default("window", Rows - 1);
3790
Bram Moolenaarf740b292006-02-16 22:11:02 +00003791 /* For DOS console the default is always black. */
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003792#if !((defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003793 /*
3794 * If 'background' wasn't set by the user, try guessing the value,
3795 * depending on the terminal name. Only need to check for terminals
3796 * with a dark background, that can handle color.
3797 */
3798 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003799 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3800 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003802 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003803 /* don't mark it as set, when starting the GUI it may be
3804 * changed again */
3805 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806 }
3807#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003808
3809#ifdef CURSOR_SHAPE
3810 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3811#endif
3812#ifdef FEAT_MOUSESHAPE
3813 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3814#endif
3815#ifdef FEAT_PRINTER
3816 (void)parse_printoptions(); /* parse 'printoptions' default value */
3817#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003818}
3819
3820/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003821 * Return "dark" or "light" depending on the kind of terminal.
3822 * This is just guessing! Recognized are:
3823 * "linux" Linux console
3824 * "screen.linux" Linux console with screen
3825 * "cygwin" Cygwin shell
3826 * "putty" Putty program
3827 * We also check the COLORFGBG environment variable, which is set by
3828 * rxvt and derivatives. This variable contains either two or three
3829 * values separated by semicolons; we want the last value in either
3830 * case. If this value is 0-6 or 8, our background is dark.
3831 */
3832 static char_u *
3833term_bg_default()
3834{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003835#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003836 /* DOS console nearly always black */
3837 return (char_u *)"dark";
3838#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003839 char_u *p;
3840
Bram Moolenaarf740b292006-02-16 22:11:02 +00003841 if (STRCMP(T_NAME, "linux") == 0
3842 || STRCMP(T_NAME, "screen.linux") == 0
3843 || STRCMP(T_NAME, "cygwin") == 0
3844 || STRCMP(T_NAME, "putty") == 0
3845 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3846 && (p = vim_strrchr(p, ';')) != NULL
3847 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3848 && p[2] == NUL))
3849 return (char_u *)"dark";
3850 return (char_u *)"light";
3851#endif
3852}
3853
3854/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855 * Initialize the options, part three: After reading the .vimrc
3856 */
3857 void
3858set_init_3()
3859{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003860#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861/*
3862 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3863 * This is done after other initializations, where 'shell' might have been
3864 * set, but only if they have not been set before.
3865 */
3866 char_u *p;
3867 int idx_srr;
3868 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003869# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870 int idx_sp;
3871 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003872# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873
3874 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003875 if (idx_srr < 0)
3876 do_srr = FALSE;
3877 else
3878 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003879# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003881 if (idx_sp < 0)
3882 do_sp = FALSE;
3883 else
3884 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003885# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003886 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 if (p != NULL)
3888 {
3889 /*
3890 * Default for p_sp is "| tee", for p_srr is ">".
3891 * For known shells it is changed here to include stderr.
3892 */
3893 if ( fnamecmp(p, "csh") == 0
3894 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003895# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896 || fnamecmp(p, "csh.exe") == 0
3897 || fnamecmp(p, "tcsh.exe") == 0
3898# endif
3899 )
3900 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003901# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902 if (do_sp)
3903 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003904# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003905 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003906# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003908# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3910 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003911# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 if (do_srr)
3913 {
3914 p_srr = (char_u *)">&";
3915 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3916 }
3917 }
3918 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003919 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920 if ( fnamecmp(p, "sh") == 0
3921 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003922 || fnamecmp(p, "mksh") == 0
3923 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003925 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003926 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003927 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003928# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929 || fnamecmp(p, "cmd") == 0
3930 || fnamecmp(p, "sh.exe") == 0
3931 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003932 || fnamecmp(p, "mksh.exe") == 0
3933 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003935 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003936 || fnamecmp(p, "bash.exe") == 0
3937 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003939 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003941# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 if (do_sp)
3943 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003944# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003946# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003948# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3950 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003951# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 if (do_srr)
3953 {
3954 p_srr = (char_u *)">%s 2>&1";
3955 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3956 }
3957 }
3958 vim_free(p);
3959 }
3960#endif
3961
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003962#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003964 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3965 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 * This is done after other initializations, where 'shell' might have been
3967 * set, but only if they have not been set before. Default for p_shcf is
3968 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3969 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3970 * command.com. And for Win32 we need to set p_sxq instead.
3971 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003972 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003973 {
3974 int idx3;
3975
3976 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003977 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 {
3979 p_shcf = (char_u *)"-c";
3980 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3981 }
3982
3983# ifndef DJGPP
3984# ifdef WIN3264
3985 /* Somehow Win32 requires the quotes around the redirection too */
3986 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003987 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988 {
3989 p_sxq = (char_u *)"\"";
3990 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3991 }
3992# else
3993 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003994 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995 {
3996 p_shq = (char_u *)"\"";
3997 options[idx3].def_val[VI_DEFAULT] = p_shq;
3998 }
3999# endif
4000# endif
4001 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004002 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4003 {
4004 int idx3;
4005
4006 /*
4007 * cmd.exe on Windows will strip the first and last double quote given
4008 * on the command line, e.g. most of the time things like:
4009 * cmd /c "my path/to/echo" "my args to echo"
4010 * become:
4011 * my path/to/echo" "my args to echo
4012 * when executed.
4013 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004014 * To avoid this, set shellxquote to surround the command in
4015 * parenthesis. This appears to make most commands work, without
4016 * breaking commands that worked previously, such as
4017 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004018 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004019 idx3 = findoption((char_u *)"sxq");
4020 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4021 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004022 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004023 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4024 }
4025
Bram Moolenaara64ba222012-02-12 23:23:31 +01004026 idx3 = findoption((char_u *)"shcf");
4027 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4028 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004029 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004030 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4031 }
4032 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033#endif
4034
4035#ifdef FEAT_TITLE
4036 set_title_defaults();
4037#endif
4038}
4039
4040#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4041/*
4042 * When 'helplang' is still at its default value, set it to "lang".
4043 * Only the first two characters of "lang" are used.
4044 */
4045 void
4046set_helplang_default(lang)
4047 char_u *lang;
4048{
4049 int idx;
4050
4051 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4052 return;
4053 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004054 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 {
4056 if (options[idx].flags & P_ALLOCED)
4057 free_string_option(p_hlg);
4058 p_hlg = vim_strsave(lang);
4059 if (p_hlg == NULL)
4060 p_hlg = empty_option;
4061 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004062 {
4063 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4064 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4065 {
4066 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4067 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4068 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004070 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 options[idx].flags |= P_ALLOCED;
4072 }
4073}
4074#endif
4075
4076#ifdef FEAT_GUI
4077static char_u *gui_bg_default __ARGS((void));
4078
4079 static char_u *
4080gui_bg_default()
4081{
4082 if (gui_get_lightness(gui.back_pixel) < 127)
4083 return (char_u *)"dark";
4084 return (char_u *)"light";
4085}
4086
4087/*
4088 * Option initializations that can only be done after opening the GUI window.
4089 */
4090 void
4091init_gui_options()
4092{
4093 /* Set the 'background' option according to the lightness of the
4094 * background color, unless the user has set it already. */
4095 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4096 {
4097 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4098 highlight_changed();
4099 }
4100}
4101#endif
4102
4103#ifdef FEAT_TITLE
4104/*
4105 * 'title' and 'icon' only default to true if they have not been set or reset
4106 * in .vimrc and we can read the old value.
4107 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4108 * they can be reset. This reduces startup time when using X on a remote
4109 * machine.
4110 */
4111 void
4112set_title_defaults()
4113{
4114 int idx1;
4115 long val;
4116
4117 /*
4118 * If GUI is (going to be) used, we can always set the window title and
4119 * icon name. Saves a bit of time, because the X11 display server does
4120 * not need to be contacted.
4121 */
4122 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004123 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 {
4125#ifdef FEAT_GUI
4126 if (gui.starting || gui.in_use)
4127 val = TRUE;
4128 else
4129#endif
4130 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004131 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 p_title = val;
4133 }
4134 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004135 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 {
4137#ifdef FEAT_GUI
4138 if (gui.starting || gui.in_use)
4139 val = TRUE;
4140 else
4141#endif
4142 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004143 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 p_icon = val;
4145 }
4146}
4147#endif
4148
4149/*
4150 * Parse 'arg' for option settings.
4151 *
4152 * 'arg' may be IObuff, but only when no errors can be present and option
4153 * does not need to be expanded with option_expand().
4154 * "opt_flags":
4155 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004156 * OPT_GLOBAL for ":setglobal"
4157 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004158 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004159 * OPT_WINONLY to only set window-local options
4160 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161 *
4162 * returns FAIL if an error is detected, OK otherwise
4163 */
4164 int
4165do_set(arg, opt_flags)
4166 char_u *arg; /* option string (may be written to!) */
4167 int opt_flags;
4168{
4169 int opt_idx;
4170 char_u *errmsg;
4171 char_u errbuf[80];
4172 char_u *startarg;
4173 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4174 int nextchar; /* next non-white char after option name */
4175 int afterchar; /* character just after option name */
4176 int len;
4177 int i;
4178 long value;
4179 int key;
4180 long_u flags; /* flags for current option */
4181 char_u *varp = NULL; /* pointer to variable for current option */
4182 int did_show = FALSE; /* already showed one value */
4183 int adding; /* "opt+=arg" */
4184 int prepending; /* "opt^=arg" */
4185 int removing; /* "opt-=arg" */
4186 int cp_val = 0;
4187 char_u key_name[2];
4188
4189 if (*arg == NUL)
4190 {
4191 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004192 did_show = TRUE;
4193 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194 }
4195
4196 while (*arg != NUL) /* loop to process all options */
4197 {
4198 errmsg = NULL;
4199 startarg = arg; /* remember for error message */
4200
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004201 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4202 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203 {
4204 /*
4205 * ":set all" show all options.
4206 * ":set all&" set all options to their default value.
4207 */
4208 arg += 3;
4209 if (*arg == '&')
4210 {
4211 ++arg;
4212 /* Only for :set command set global value of local options. */
4213 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004214 didset_options();
4215 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004216 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004217 }
4218 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004219 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004220 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004221 did_show = TRUE;
4222 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004223 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004224 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004225 {
4226 showoptions(2, opt_flags);
4227 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004228 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229 arg += 7;
4230 }
4231 else
4232 {
4233 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004234 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235 {
4236 prefix = 0;
4237 arg += 2;
4238 }
4239 else if (STRNCMP(arg, "inv", 3) == 0)
4240 {
4241 prefix = 2;
4242 arg += 3;
4243 }
4244
4245 /* find end of name */
4246 key = 0;
4247 if (*arg == '<')
4248 {
4249 nextchar = 0;
4250 opt_idx = -1;
4251 /* look out for <t_>;> */
4252 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4253 len = 5;
4254 else
4255 {
4256 len = 1;
4257 while (arg[len] != NUL && arg[len] != '>')
4258 ++len;
4259 }
4260 if (arg[len] != '>')
4261 {
4262 errmsg = e_invarg;
4263 goto skip;
4264 }
4265 arg[len] = NUL; /* put NUL after name */
4266 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4267 opt_idx = findoption(arg + 1);
4268 arg[len++] = '>'; /* restore '>' */
4269 if (opt_idx == -1)
4270 key = find_key_option(arg + 1);
4271 }
4272 else
4273 {
4274 len = 0;
4275 /*
4276 * The two characters after "t_" may not be alphanumeric.
4277 */
4278 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4279 len = 4;
4280 else
4281 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4282 ++len;
4283 nextchar = arg[len];
4284 arg[len] = NUL; /* put NUL after name */
4285 opt_idx = findoption(arg);
4286 arg[len] = nextchar; /* restore nextchar */
4287 if (opt_idx == -1)
4288 key = find_key_option(arg);
4289 }
4290
4291 /* remember character after option name */
4292 afterchar = arg[len];
4293
4294 /* skip white space, allow ":set ai ?" */
4295 while (vim_iswhite(arg[len]))
4296 ++len;
4297
4298 adding = FALSE;
4299 prepending = FALSE;
4300 removing = FALSE;
4301 if (arg[len] != NUL && arg[len + 1] == '=')
4302 {
4303 if (arg[len] == '+')
4304 {
4305 adding = TRUE; /* "+=" */
4306 ++len;
4307 }
4308 else if (arg[len] == '^')
4309 {
4310 prepending = TRUE; /* "^=" */
4311 ++len;
4312 }
4313 else if (arg[len] == '-')
4314 {
4315 removing = TRUE; /* "-=" */
4316 ++len;
4317 }
4318 }
4319 nextchar = arg[len];
4320
4321 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4322 {
4323 errmsg = (char_u *)N_("E518: Unknown option");
4324 goto skip;
4325 }
4326
4327 if (opt_idx >= 0)
4328 {
4329 if (options[opt_idx].var == NULL) /* hidden option: skip */
4330 {
4331 /* Only give an error message when requesting the value of
4332 * a hidden option, ignore setting it. */
4333 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4334 && (!(options[opt_idx].flags & P_BOOL)
4335 || nextchar == '?'))
4336 errmsg = (char_u *)N_("E519: Option not supported");
4337 goto skip;
4338 }
4339
4340 flags = options[opt_idx].flags;
4341 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4342 }
4343 else
4344 {
4345 flags = P_STRING;
4346 if (key < 0)
4347 {
4348 key_name[0] = KEY2TERMCAP0(key);
4349 key_name[1] = KEY2TERMCAP1(key);
4350 }
4351 else
4352 {
4353 key_name[0] = KS_KEY;
4354 key_name[1] = (key & 0xff);
4355 }
4356 }
4357
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004358 /* Skip all options that are not window-local (used when showing
4359 * an already loaded buffer in a window). */
4360 if ((opt_flags & OPT_WINONLY)
4361 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4362 goto skip;
4363
Bram Moolenaara3227e22006-03-08 21:32:40 +00004364 /* Skip all options that are window-local (used for :vimgrep). */
4365 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4366 && options[opt_idx].var == VAR_WIN)
4367 goto skip;
4368
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004369 /* Disallow changing some options from modelines. */
4370 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004371 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004372 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004373 {
4374 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4375 goto skip;
4376 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004377#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004378 /* In diff mode some options are overruled. This avoids that
4379 * 'foldmethod' becomes "marker" instead of "diff" and that
4380 * "wrap" gets set. */
4381 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004382 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004383 && (options[opt_idx].indir == PV_FDM
4384 || options[opt_idx].indir == PV_WRAP))
4385 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004387 }
4388
4389#ifdef HAVE_SANDBOX
4390 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004391 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004392 {
4393 errmsg = (char_u *)_(e_sandbox);
4394 goto skip;
4395 }
4396#endif
4397
4398 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4399 {
4400 arg += len;
4401 cp_val = p_cp;
4402 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4403 {
4404 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4405 {
4406 cp_val = FALSE;
4407 arg += 3;
4408 }
4409 else /* "opt&vi": set to Vi default */
4410 {
4411 cp_val = TRUE;
4412 arg += 2;
4413 }
4414 }
4415 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4416 && arg[1] != NUL && !vim_iswhite(arg[1]))
4417 {
4418 errmsg = e_trailing;
4419 goto skip;
4420 }
4421 }
4422
4423 /*
4424 * allow '=' and ':' as MSDOS command.com allows only one
4425 * '=' character per "set" command line. grrr. (jw)
4426 */
4427 if (nextchar == '?'
4428 || (prefix == 1
4429 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4430 && !(flags & P_BOOL)))
4431 {
4432 /*
4433 * print value
4434 */
4435 if (did_show)
4436 msg_putchar('\n'); /* cursor below last one */
4437 else
4438 {
4439 gotocmdline(TRUE); /* cursor at status line */
4440 did_show = TRUE; /* remember that we did a line */
4441 }
4442 if (opt_idx >= 0)
4443 {
4444 showoneopt(&options[opt_idx], opt_flags);
4445#ifdef FEAT_EVAL
4446 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004447 {
4448 /* Mention where the option was last set. */
4449 if (varp == options[opt_idx].var)
4450 last_set_msg(options[opt_idx].scriptID);
4451 else if ((int)options[opt_idx].indir & PV_WIN)
4452 last_set_msg(curwin->w_p_scriptID[
4453 (int)options[opt_idx].indir & PV_MASK]);
4454 else if ((int)options[opt_idx].indir & PV_BUF)
4455 last_set_msg(curbuf->b_p_scriptID[
4456 (int)options[opt_idx].indir & PV_MASK]);
4457 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004458#endif
4459 }
4460 else
4461 {
4462 char_u *p;
4463
4464 p = find_termcode(key_name);
4465 if (p == NULL)
4466 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004467 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004468 goto skip;
4469 }
4470 else
4471 (void)show_one_termcode(key_name, p, TRUE);
4472 }
4473 if (nextchar != '?'
4474 && nextchar != NUL && !vim_iswhite(afterchar))
4475 errmsg = e_trailing;
4476 }
4477 else
4478 {
4479 if (flags & P_BOOL) /* boolean */
4480 {
4481 if (nextchar == '=' || nextchar == ':')
4482 {
4483 errmsg = e_invarg;
4484 goto skip;
4485 }
4486
4487 /*
4488 * ":set opt!": invert
4489 * ":set opt&": reset to default value
4490 * ":set opt<": reset to global value
4491 */
4492 if (nextchar == '!')
4493 value = *(int *)(varp) ^ 1;
4494 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004495 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004496 ((flags & P_VI_DEF) || cp_val)
4497 ? VI_DEFAULT : VIM_DEFAULT];
4498 else if (nextchar == '<')
4499 {
4500 /* For 'autoread' -1 means to use global value. */
4501 if ((int *)varp == &curbuf->b_p_ar
4502 && opt_flags == OPT_LOCAL)
4503 value = -1;
4504 else
4505 value = *(int *)get_varp_scope(&(options[opt_idx]),
4506 OPT_GLOBAL);
4507 }
4508 else
4509 {
4510 /*
4511 * ":set invopt": invert
4512 * ":set opt" or ":set noopt": set or reset
4513 */
4514 if (nextchar != NUL && !vim_iswhite(afterchar))
4515 {
4516 errmsg = e_trailing;
4517 goto skip;
4518 }
4519 if (prefix == 2) /* inv */
4520 value = *(int *)(varp) ^ 1;
4521 else
4522 value = prefix;
4523 }
4524
4525 errmsg = set_bool_option(opt_idx, varp, (int)value,
4526 opt_flags);
4527 }
4528 else /* numeric or string */
4529 {
4530 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4531 || prefix != 1)
4532 {
4533 errmsg = e_invarg;
4534 goto skip;
4535 }
4536
4537 if (flags & P_NUM) /* numeric */
4538 {
4539 /*
4540 * Different ways to set a number option:
4541 * & set to default value
4542 * < set to global value
4543 * <xx> accept special key codes for 'wildchar'
4544 * c accept any non-digit for 'wildchar'
4545 * [-]0-9 set number
4546 * other error
4547 */
4548 ++arg;
4549 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004550 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004551 ((flags & P_VI_DEF) || cp_val)
4552 ? VI_DEFAULT : VIM_DEFAULT];
4553 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004554 {
4555 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4556 * use the global value. */
4557 if ((long *)varp == &curbuf->b_p_ul
4558 && opt_flags == OPT_LOCAL)
4559 value = NO_LOCAL_UNDOLEVEL;
4560 else
4561 value = *(long *)get_varp_scope(
4562 &(options[opt_idx]), OPT_GLOBAL);
4563 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004564 else if (((long *)varp == &p_wc
4565 || (long *)varp == &p_wcm)
4566 && (*arg == '<'
4567 || *arg == '^'
4568 || ((!arg[1] || vim_iswhite(arg[1]))
4569 && !VIM_ISDIGIT(*arg))))
4570 {
4571 value = string_to_key(arg);
4572 if (value == 0 && (long *)varp != &p_wcm)
4573 {
4574 errmsg = e_invarg;
4575 goto skip;
4576 }
4577 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004578 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4579 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004580 /* Allow negative (for 'undolevels'), octal and
4581 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004582 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4583 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004584 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4585 {
4586 errmsg = e_invarg;
4587 goto skip;
4588 }
4589 }
4590 else
4591 {
4592 errmsg = (char_u *)N_("E521: Number required after =");
4593 goto skip;
4594 }
4595
4596 if (adding)
4597 value = *(long *)varp + value;
4598 if (prepending)
4599 value = *(long *)varp * value;
4600 if (removing)
4601 value = *(long *)varp - value;
4602 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004603 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004604 }
4605 else if (opt_idx >= 0) /* string */
4606 {
4607 char_u *save_arg = NULL;
4608 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004609 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004610 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004611 char_u *origval = NULL;
4612#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4613 char_u *saved_origval = NULL;
4614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615 unsigned newlen;
4616 int comma;
4617 int bs;
4618 int new_value_alloced; /* new string option
4619 was allocated */
4620
4621 /* When using ":set opt=val" for a global option
4622 * with a local value the local value will be
4623 * reset, use the global value here. */
4624 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004625 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004626 varp = options[opt_idx].var;
4627
4628 /* The old value is kept until we are sure that the
4629 * new value is valid. */
4630 oldval = *(char_u **)varp;
4631 if (nextchar == '&') /* set to default val */
4632 {
4633 newval = options[opt_idx].def_val[
4634 ((flags & P_VI_DEF) || cp_val)
4635 ? VI_DEFAULT : VIM_DEFAULT];
4636 if ((char_u **)varp == &p_bg)
4637 {
4638 /* guess the value of 'background' */
4639#ifdef FEAT_GUI
4640 if (gui.in_use)
4641 newval = gui_bg_default();
4642 else
4643#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004644 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004645 }
4646
4647 /* expand environment variables and ~ (since the
4648 * default value was already expanded, only
4649 * required when an environment variable was set
4650 * later */
4651 if (newval == NULL)
4652 newval = empty_option;
4653 else
4654 {
4655 s = option_expand(opt_idx, newval);
4656 if (s == NULL)
4657 s = newval;
4658 newval = vim_strsave(s);
4659 }
4660 new_value_alloced = TRUE;
4661 }
4662 else if (nextchar == '<') /* set to global val */
4663 {
4664 newval = vim_strsave(*(char_u **)get_varp_scope(
4665 &(options[opt_idx]), OPT_GLOBAL));
4666 new_value_alloced = TRUE;
4667 }
4668 else
4669 {
4670 ++arg; /* jump to after the '=' or ':' */
4671
4672 /*
4673 * Set 'keywordprg' to ":help" if an empty
4674 * value was passed to :set by the user.
4675 * Misuse errbuf[] for the resulting string.
4676 */
4677 if (varp == (char_u *)&p_kp
4678 && (*arg == NUL || *arg == ' '))
4679 {
4680 STRCPY(errbuf, ":help");
4681 save_arg = arg;
4682 arg = errbuf;
4683 }
4684 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004685 * Convert 'backspace' number to string, for
4686 * adding, prepending and removing string.
4687 */
4688 else if (varp == (char_u *)&p_bs
4689 && VIM_ISDIGIT(**(char_u **)varp))
4690 {
4691 i = getdigits((char_u **)varp);
4692 switch (i)
4693 {
4694 case 0:
4695 *(char_u **)varp = empty_option;
4696 break;
4697 case 1:
4698 *(char_u **)varp = vim_strsave(
4699 (char_u *)"indent,eol");
4700 break;
4701 case 2:
4702 *(char_u **)varp = vim_strsave(
4703 (char_u *)"indent,eol,start");
4704 break;
4705 }
4706 vim_free(oldval);
4707 oldval = *(char_u **)varp;
4708 }
4709 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004710 * Convert 'whichwrap' number to string, for
4711 * backwards compatibility with Vim 3.0.
4712 * Misuse errbuf[] for the resulting string.
4713 */
4714 else if (varp == (char_u *)&p_ww
4715 && VIM_ISDIGIT(*arg))
4716 {
4717 *errbuf = NUL;
4718 i = getdigits(&arg);
4719 if (i & 1)
4720 STRCAT(errbuf, "b,");
4721 if (i & 2)
4722 STRCAT(errbuf, "s,");
4723 if (i & 4)
4724 STRCAT(errbuf, "h,l,");
4725 if (i & 8)
4726 STRCAT(errbuf, "<,>,");
4727 if (i & 16)
4728 STRCAT(errbuf, "[,],");
4729 if (*errbuf != NUL) /* remove trailing , */
4730 errbuf[STRLEN(errbuf) - 1] = NUL;
4731 save_arg = arg;
4732 arg = errbuf;
4733 }
4734 /*
4735 * Remove '>' before 'dir' and 'bdir', for
4736 * backwards compatibility with version 3.0
4737 */
4738 else if ( *arg == '>'
4739 && (varp == (char_u *)&p_dir
4740 || varp == (char_u *)&p_bdir))
4741 {
4742 ++arg;
4743 }
4744
4745 /* When setting the local value of a global
4746 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004747 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004748 && (opt_flags & OPT_LOCAL))
4749 origval = *(char_u **)get_varp(
4750 &options[opt_idx]);
4751 else
4752 origval = oldval;
4753
4754 /*
4755 * Copy the new string into allocated memory.
4756 * Can't use set_string_option_direct(), because
4757 * we need to remove the backslashes.
4758 */
4759 /* get a bit too much */
4760 newlen = (unsigned)STRLEN(arg) + 1;
4761 if (adding || prepending || removing)
4762 newlen += (unsigned)STRLEN(origval) + 1;
4763 newval = alloc(newlen);
4764 if (newval == NULL) /* out of mem, don't change */
4765 break;
4766 s = newval;
4767
4768 /*
4769 * Copy the string, skip over escaped chars.
4770 * For MS-DOS and WIN32 backslashes before normal
4771 * file name characters are not removed, and keep
4772 * backslash at start, for "\\machine\path", but
4773 * do remove it for "\\\\machine\\path".
4774 * The reverse is found in ExpandOldSetting().
4775 */
4776 while (*arg && !vim_iswhite(*arg))
4777 {
4778 if (*arg == '\\' && arg[1] != NUL
4779#ifdef BACKSLASH_IN_FILENAME
4780 && !((flags & P_EXPAND)
4781 && vim_isfilec(arg[1])
4782 && (arg[1] != '\\'
4783 || (s == newval
4784 && arg[2] != '\\')))
4785#endif
4786 )
4787 ++arg; /* remove backslash */
4788#ifdef FEAT_MBYTE
4789 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004790 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004791 {
4792 /* copy multibyte char */
4793 mch_memmove(s, arg, (size_t)i);
4794 arg += i;
4795 s += i;
4796 }
4797 else
4798#endif
4799 *s++ = *arg++;
4800 }
4801 *s = NUL;
4802
4803 /*
4804 * Expand environment variables and ~.
4805 * Don't do it when adding without inserting a
4806 * comma.
4807 */
4808 if (!(adding || prepending || removing)
4809 || (flags & P_COMMA))
4810 {
4811 s = option_expand(opt_idx, newval);
4812 if (s != NULL)
4813 {
4814 vim_free(newval);
4815 newlen = (unsigned)STRLEN(s) + 1;
4816 if (adding || prepending || removing)
4817 newlen += (unsigned)STRLEN(origval) + 1;
4818 newval = alloc(newlen);
4819 if (newval == NULL)
4820 break;
4821 STRCPY(newval, s);
4822 }
4823 }
4824
4825 /* locate newval[] in origval[] when removing it
4826 * and when adding to avoid duplicates */
4827 i = 0; /* init for GCC */
4828 if (removing || (flags & P_NODUP))
4829 {
4830 i = (int)STRLEN(newval);
4831 bs = 0;
4832 for (s = origval; *s; ++s)
4833 {
4834 if ((!(flags & P_COMMA)
4835 || s == origval
4836 || (s[-1] == ',' && !(bs & 1)))
4837 && STRNCMP(s, newval, i) == 0
4838 && (!(flags & P_COMMA)
4839 || s[i] == ','
4840 || s[i] == NUL))
4841 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004842 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004843 * even number of backslashes or a single
4844 * backslash preceded by a comma before it
4845 * is recognized as a separator */
4846 if ((s > origval + 1
4847 && s[-1] == '\\'
4848 && s[-2] != ',')
4849 || (s == origval + 1
4850 && s[-1] == '\\'))
4851
Bram Moolenaar071d4272004-06-13 20:20:40 +00004852 ++bs;
4853 else
4854 bs = 0;
4855 }
4856
4857 /* do not add if already there */
4858 if ((adding || prepending) && *s)
4859 {
4860 prepending = FALSE;
4861 adding = FALSE;
4862 STRCPY(newval, origval);
4863 }
4864 }
4865
4866 /* concatenate the two strings; add a ',' if
4867 * needed */
4868 if (adding || prepending)
4869 {
4870 comma = ((flags & P_COMMA) && *origval != NUL
4871 && *newval != NUL);
4872 if (adding)
4873 {
4874 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004875 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004876 if (comma && i > 1
4877 && (flags & P_ONECOMMA) == P_ONECOMMA
4878 && origval[i - 1] == ','
4879 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004880 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004881 mch_memmove(newval + i + comma, newval,
4882 STRLEN(newval) + 1);
4883 mch_memmove(newval, origval, (size_t)i);
4884 }
4885 else
4886 {
4887 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004888 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004889 }
4890 if (comma)
4891 newval[i] = ',';
4892 }
4893
4894 /* Remove newval[] from origval[]. (Note: "i" has
4895 * been set above and is used here). */
4896 if (removing)
4897 {
4898 STRCPY(newval, origval);
4899 if (*s)
4900 {
4901 /* may need to remove a comma */
4902 if (flags & P_COMMA)
4903 {
4904 if (s == origval)
4905 {
4906 /* include comma after string */
4907 if (s[i] == ',')
4908 ++i;
4909 }
4910 else
4911 {
4912 /* include comma before string */
4913 --s;
4914 ++i;
4915 }
4916 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004917 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004918 }
4919 }
4920
4921 if (flags & P_FLAGLIST)
4922 {
4923 /* Remove flags that appear twice. */
4924 for (s = newval; *s; ++s)
4925 if ((!(flags & P_COMMA) || *s != ',')
4926 && vim_strchr(s + 1, *s) != NULL)
4927 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004928 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004929 --s;
4930 }
4931 }
4932
4933 if (save_arg != NULL) /* number for 'whichwrap' */
4934 arg = save_arg;
4935 new_value_alloced = TRUE;
4936 }
4937
4938 /* Set the new value. */
4939 *(char_u **)(varp) = newval;
4940
Bram Moolenaar53744302015-07-17 17:38:22 +02004941#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004942 if (!starting
4943# ifdef FEAT_CRYPT
4944 && options[opt_idx].indir != PV_KEY
4945# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004946 && origval != NULL)
4947 /* origval may be freed by
4948 * did_set_string_option(), make a copy. */
4949 saved_origval = vim_strsave(origval);
4950#endif
4951
Bram Moolenaar071d4272004-06-13 20:20:40 +00004952 /* Handle side effects, and set the global value for
4953 * ":set" on local options. */
4954 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4955 new_value_alloced, oldval, errbuf, opt_flags);
4956
4957 /* If error detected, print the error message. */
4958 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004959 {
4960#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4961 vim_free(saved_origval);
4962#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004963 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004964 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004965#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4966 if (saved_origval != NULL)
4967 {
4968 char_u buf_type[7];
4969
4970 sprintf((char *)buf_type, "%s",
4971 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004972 set_vim_var_string(VV_OPTION_NEW,
4973 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004974 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4975 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4976 apply_autocmds(EVENT_OPTIONSET,
4977 (char_u *)options[opt_idx].fullname,
4978 NULL, FALSE, NULL);
4979 reset_v_option_vars();
4980 vim_free(saved_origval);
4981 }
4982#endif
4983
Bram Moolenaar071d4272004-06-13 20:20:40 +00004984 }
4985 else /* key code option */
4986 {
4987 char_u *p;
4988
4989 if (nextchar == '&')
4990 {
4991 if (add_termcap_entry(key_name, TRUE) == FAIL)
4992 errmsg = (char_u *)N_("E522: Not found in termcap");
4993 }
4994 else
4995 {
4996 ++arg; /* jump to after the '=' or ':' */
4997 for (p = arg; *p && !vim_iswhite(*p); ++p)
4998 if (*p == '\\' && p[1] != NUL)
4999 ++p;
5000 nextchar = *p;
5001 *p = NUL;
5002 add_termcode(key_name, arg, FALSE);
5003 *p = nextchar;
5004 }
5005 if (full_screen)
5006 ttest(FALSE);
5007 redraw_all_later(CLEAR);
5008 }
5009 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005010
Bram Moolenaar071d4272004-06-13 20:20:40 +00005011 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005012 did_set_option(opt_idx, opt_flags,
5013 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005014 }
5015
5016skip:
5017 /*
5018 * Advance to next argument.
5019 * - skip until a blank found, taking care of backslashes
5020 * - skip blanks
5021 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5022 */
5023 for (i = 0; i < 2 ; ++i)
5024 {
5025 while (*arg != NUL && !vim_iswhite(*arg))
5026 if (*arg++ == '\\' && *arg != NUL)
5027 ++arg;
5028 arg = skipwhite(arg);
5029 if (*arg != '=')
5030 break;
5031 }
5032 }
5033
5034 if (errmsg != NULL)
5035 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005036 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005037 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005038 if (i + (arg - startarg) < IOSIZE)
5039 {
5040 /* append the argument with the error */
5041 STRCAT(IObuff, ": ");
5042 mch_memmove(IObuff + i, startarg, (arg - startarg));
5043 IObuff[i + (arg - startarg)] = NUL;
5044 }
5045 /* make sure all characters are printable */
5046 trans_characters(IObuff, IOSIZE);
5047
5048 ++no_wait_return; /* wait_return done later */
5049 emsg(IObuff); /* show error highlighted */
5050 --no_wait_return;
5051
5052 return FAIL;
5053 }
5054
5055 arg = skipwhite(arg);
5056 }
5057
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005058theend:
5059 if (silent_mode && did_show)
5060 {
5061 /* After displaying option values in silent mode. */
5062 silent_mode = FALSE;
5063 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5064 msg_putchar('\n');
5065 cursor_on(); /* msg_start() switches it off */
5066 out_flush();
5067 silent_mode = TRUE;
5068 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5069 }
5070
Bram Moolenaar071d4272004-06-13 20:20:40 +00005071 return OK;
5072}
5073
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005074/*
5075 * Call this when an option has been given a new value through a user command.
5076 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5077 */
5078 static void
5079did_set_option(opt_idx, opt_flags, new_value)
5080 int opt_idx;
5081 int opt_flags; /* possibly with OPT_MODELINE */
5082 int new_value; /* value was replaced completely */
5083{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005084 long_u *p;
5085
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005086 options[opt_idx].flags |= P_WAS_SET;
5087
5088 /* When an option is set in the sandbox, from a modeline or in secure mode
5089 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005090 * flag. */
5091 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005092 if (secure
5093#ifdef HAVE_SANDBOX
5094 || sandbox != 0
5095#endif
5096 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005097 *p = *p | P_INSECURE;
5098 else if (new_value)
5099 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005100}
5101
Bram Moolenaar071d4272004-06-13 20:20:40 +00005102 static char_u *
5103illegal_char(errbuf, c)
5104 char_u *errbuf;
5105 int c;
5106{
5107 if (errbuf == NULL)
5108 return (char_u *)"";
5109 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005110 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 return errbuf;
5112}
5113
5114/*
5115 * Convert a key name or string into a key value.
5116 * Used for 'wildchar' and 'cedit' options.
5117 */
5118 static int
5119string_to_key(arg)
5120 char_u *arg;
5121{
5122 if (*arg == '<')
5123 return find_key_option(arg + 1);
5124 if (*arg == '^')
5125 return Ctrl_chr(arg[1]);
5126 return *arg;
5127}
5128
5129#ifdef FEAT_CMDWIN
5130/*
5131 * Check value of 'cedit' and set cedit_key.
5132 * Returns NULL if value is OK, error message otherwise.
5133 */
5134 static char_u *
5135check_cedit()
5136{
5137 int n;
5138
5139 if (*p_cedit == NUL)
5140 cedit_key = -1;
5141 else
5142 {
5143 n = string_to_key(p_cedit);
5144 if (vim_isprintc(n))
5145 return e_invarg;
5146 cedit_key = n;
5147 }
5148 return NULL;
5149}
5150#endif
5151
5152#ifdef FEAT_TITLE
5153/*
5154 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5155 * maketitle() to create and display it.
5156 * When switching the title or icon off, call mch_restore_title() to get
5157 * the old value back.
5158 */
5159 static void
5160did_set_title(icon)
5161 int icon; /* Did set icon instead of title */
5162{
5163 if (starting != NO_SCREEN
5164#ifdef FEAT_GUI
5165 && !gui.starting
5166#endif
5167 )
5168 {
5169 maketitle();
5170 if (icon)
5171 {
5172 if (!p_icon)
5173 mch_restore_title(2);
5174 }
5175 else
5176 {
5177 if (!p_title)
5178 mch_restore_title(1);
5179 }
5180 }
5181}
5182#endif
5183
5184/*
5185 * set_options_bin - called when 'bin' changes value.
5186 */
5187 void
5188set_options_bin(oldval, newval, opt_flags)
5189 int oldval;
5190 int newval;
5191 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5192{
5193 /*
5194 * The option values that are changed when 'bin' changes are
5195 * copied when 'bin is set and restored when 'bin' is reset.
5196 */
5197 if (newval)
5198 {
5199 if (!oldval) /* switched on */
5200 {
5201 if (!(opt_flags & OPT_GLOBAL))
5202 {
5203 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5204 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5205 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5206 curbuf->b_p_et_nobin = curbuf->b_p_et;
5207 }
5208 if (!(opt_flags & OPT_LOCAL))
5209 {
5210 p_tw_nobin = p_tw;
5211 p_wm_nobin = p_wm;
5212 p_ml_nobin = p_ml;
5213 p_et_nobin = p_et;
5214 }
5215 }
5216
5217 if (!(opt_flags & OPT_GLOBAL))
5218 {
5219 curbuf->b_p_tw = 0; /* no automatic line wrap */
5220 curbuf->b_p_wm = 0; /* no automatic line wrap */
5221 curbuf->b_p_ml = 0; /* no modelines */
5222 curbuf->b_p_et = 0; /* no expandtab */
5223 }
5224 if (!(opt_flags & OPT_LOCAL))
5225 {
5226 p_tw = 0;
5227 p_wm = 0;
5228 p_ml = FALSE;
5229 p_et = FALSE;
5230 p_bin = TRUE; /* needed when called for the "-b" argument */
5231 }
5232 }
5233 else if (oldval) /* switched off */
5234 {
5235 if (!(opt_flags & OPT_GLOBAL))
5236 {
5237 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5238 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5239 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5240 curbuf->b_p_et = curbuf->b_p_et_nobin;
5241 }
5242 if (!(opt_flags & OPT_LOCAL))
5243 {
5244 p_tw = p_tw_nobin;
5245 p_wm = p_wm_nobin;
5246 p_ml = p_ml_nobin;
5247 p_et = p_et_nobin;
5248 }
5249 }
5250}
5251
5252#ifdef FEAT_VIMINFO
5253/*
5254 * Find the parameter represented by the given character (eg ', :, ", or /),
5255 * and return its associated value in the 'viminfo' string.
5256 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005257 * If the parameter is not specified in the string or there is no following
5258 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005259 */
5260 int
5261get_viminfo_parameter(type)
5262 int type;
5263{
5264 char_u *p;
5265
5266 p = find_viminfo_parameter(type);
5267 if (p != NULL && VIM_ISDIGIT(*p))
5268 return atoi((char *)p);
5269 return -1;
5270}
5271
5272/*
5273 * Find the parameter represented by the given character (eg ''', ':', '"', or
5274 * '/') in the 'viminfo' option and return a pointer to the string after it.
5275 * Return NULL if the parameter is not specified in the string.
5276 */
5277 char_u *
5278find_viminfo_parameter(type)
5279 int type;
5280{
5281 char_u *p;
5282
5283 for (p = p_viminfo; *p; ++p)
5284 {
5285 if (*p == type)
5286 return p + 1;
5287 if (*p == 'n') /* 'n' is always the last one */
5288 break;
5289 p = vim_strchr(p, ','); /* skip until next ',' */
5290 if (p == NULL) /* hit the end without finding parameter */
5291 break;
5292 }
5293 return NULL;
5294}
5295#endif
5296
5297/*
5298 * Expand environment variables for some string options.
5299 * These string options cannot be indirect!
5300 * If "val" is NULL expand the current value of the option.
5301 * Return pointer to NameBuff, or NULL when not expanded.
5302 */
5303 static char_u *
5304option_expand(opt_idx, val)
5305 int opt_idx;
5306 char_u *val;
5307{
5308 /* if option doesn't need expansion nothing to do */
5309 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5310 return NULL;
5311
5312 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5313 * expand_env() would truncate the string. */
5314 if (val != NULL && STRLEN(val) > MAXPATHL)
5315 return NULL;
5316
5317 if (val == NULL)
5318 val = *(char_u **)options[opt_idx].var;
5319
5320 /*
5321 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5322 * Escape spaces when expanding 'tags', they are used to separate file
5323 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005324 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325 */
5326 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005327 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005328#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005329 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5330#endif
5331 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005332 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5333 return NULL;
5334
5335 return NameBuff;
5336}
5337
5338/*
5339 * After setting various option values: recompute variables that depend on
5340 * option values.
5341 */
5342 static void
5343didset_options()
5344{
5345 /* initialize the table for 'iskeyword' et.al. */
5346 (void)init_chartab();
5347
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005348#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005352 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353#ifdef FEAT_SESSION
5354 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5355 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5356#endif
5357#ifdef FEAT_FOLDING
5358 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5359#endif
5360 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005361 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362#ifdef FEAT_VIRTUALEDIT
5363 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5364#endif
5365#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5366 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5367#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005368#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005369 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005370 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005371 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005372 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5375 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5376#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005377#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005378 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5379#endif
5380#ifdef FEAT_CMDWIN
5381 /* set cedit_key */
5382 (void)check_cedit();
5383#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005384#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005385 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005386#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005387#ifdef FEAT_LINEBREAK
5388 /* initialize the table for 'breakat'. */
5389 fill_breakat_flags();
5390#endif
5391
5392}
5393
5394/*
5395 * More side effects of setting options.
5396 */
5397 static void
5398didset_options2()
5399{
5400 /* Initialize the highlight_attr[] table. */
5401 (void)highlight_changed();
5402
5403 /* Parse default for 'wildmode' */
5404 check_opt_wim();
5405
5406 (void)set_chars_option(&p_lcs);
5407#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5408 /* Parse default for 'fillchars'. */
5409 (void)set_chars_option(&p_fcs);
5410#endif
5411
5412#ifdef FEAT_CLIPBOARD
5413 /* Parse default for 'clipboard' */
5414 (void)check_clipboard_option();
5415#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005416}
5417
5418/*
5419 * Check for string options that are NULL (normally only termcap options).
5420 */
5421 void
5422check_options()
5423{
5424 int opt_idx;
5425
5426 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5427 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5428 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5429}
5430
5431/*
5432 * Check string options in a buffer for NULL value.
5433 */
5434 void
5435check_buf_options(buf)
5436 buf_T *buf;
5437{
5438#if defined(FEAT_QUICKFIX)
5439 check_string_option(&buf->b_p_bh);
5440 check_string_option(&buf->b_p_bt);
5441#endif
5442#ifdef FEAT_MBYTE
5443 check_string_option(&buf->b_p_fenc);
5444#endif
5445 check_string_option(&buf->b_p_ff);
5446#ifdef FEAT_FIND_ID
5447 check_string_option(&buf->b_p_def);
5448 check_string_option(&buf->b_p_inc);
5449# ifdef FEAT_EVAL
5450 check_string_option(&buf->b_p_inex);
5451# endif
5452#endif
5453#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5454 check_string_option(&buf->b_p_inde);
5455 check_string_option(&buf->b_p_indk);
5456#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005457#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5458 check_string_option(&buf->b_p_bexpr);
5459#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005460#if defined(FEAT_CRYPT)
5461 check_string_option(&buf->b_p_cm);
5462#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005463#if defined(FEAT_EVAL)
5464 check_string_option(&buf->b_p_fex);
5465#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005466#ifdef FEAT_CRYPT
5467 check_string_option(&buf->b_p_key);
5468#endif
5469 check_string_option(&buf->b_p_kp);
5470 check_string_option(&buf->b_p_mps);
5471 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005472 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005473 check_string_option(&buf->b_p_isk);
5474#ifdef FEAT_COMMENTS
5475 check_string_option(&buf->b_p_com);
5476#endif
5477#ifdef FEAT_FOLDING
5478 check_string_option(&buf->b_p_cms);
5479#endif
5480 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005481#ifdef FEAT_TEXTOBJ
5482 check_string_option(&buf->b_p_qe);
5483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005484#ifdef FEAT_SYN_HL
5485 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005486#endif
5487#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005488 check_string_option(&buf->b_s.b_p_spc);
5489 check_string_option(&buf->b_s.b_p_spf);
5490 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005491#endif
5492#ifdef FEAT_SEARCHPATH
5493 check_string_option(&buf->b_p_sua);
5494#endif
5495#ifdef FEAT_CINDENT
5496 check_string_option(&buf->b_p_cink);
5497 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005498 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499#endif
5500#ifdef FEAT_AUTOCMD
5501 check_string_option(&buf->b_p_ft);
5502#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005503#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5504 check_string_option(&buf->b_p_cinw);
5505#endif
5506#ifdef FEAT_INS_EXPAND
5507 check_string_option(&buf->b_p_cpt);
5508#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005509#ifdef FEAT_COMPL_FUNC
5510 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005511 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005512#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513#ifdef FEAT_KEYMAP
5514 check_string_option(&buf->b_p_keymap);
5515#endif
5516#ifdef FEAT_QUICKFIX
5517 check_string_option(&buf->b_p_gp);
5518 check_string_option(&buf->b_p_mp);
5519 check_string_option(&buf->b_p_efm);
5520#endif
5521 check_string_option(&buf->b_p_ep);
5522 check_string_option(&buf->b_p_path);
5523 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005524 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005525#ifdef FEAT_INS_EXPAND
5526 check_string_option(&buf->b_p_dict);
5527 check_string_option(&buf->b_p_tsr);
5528#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005529#ifdef FEAT_LISP
5530 check_string_option(&buf->b_p_lw);
5531#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005532 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533}
5534
5535/*
5536 * Free the string allocated for an option.
5537 * Checks for the string being empty_option. This may happen if we're out of
5538 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5539 * check_options().
5540 * Does NOT check for P_ALLOCED flag!
5541 */
5542 void
5543free_string_option(p)
5544 char_u *p;
5545{
5546 if (p != empty_option)
5547 vim_free(p);
5548}
5549
5550 void
5551clear_string_option(pp)
5552 char_u **pp;
5553{
5554 if (*pp != empty_option)
5555 vim_free(*pp);
5556 *pp = empty_option;
5557}
5558
5559 static void
5560check_string_option(pp)
5561 char_u **pp;
5562{
5563 if (*pp == NULL)
5564 *pp = empty_option;
5565}
5566
5567/*
5568 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5569 */
5570 void
5571set_term_option_alloced(p)
5572 char_u **p;
5573{
5574 int opt_idx;
5575
5576 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5577 if (options[opt_idx].var == (char_u *)p)
5578 {
5579 options[opt_idx].flags |= P_ALLOCED;
5580 return;
5581 }
5582 return; /* cannot happen: didn't find it! */
5583}
5584
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005585#if defined(FEAT_EVAL) || defined(PROTO)
5586/*
5587 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5588 * Return FALSE when it wasn't.
5589 * Return -1 for an unknown option.
5590 */
5591 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005592was_set_insecurely(opt, opt_flags)
5593 char_u *opt;
5594 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005595{
5596 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005597 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005598
5599 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005600 {
5601 flagp = insecure_flag(idx, opt_flags);
5602 return (*flagp & P_INSECURE) != 0;
5603 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005604 EMSG2(_(e_intern2), "was_set_insecurely()");
5605 return -1;
5606}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005607
5608/*
5609 * Get a pointer to the flags used for the P_INSECURE flag of option
5610 * "opt_idx". For some local options a local flags field is used.
5611 */
5612 static long_u *
5613insecure_flag(opt_idx, opt_flags)
5614 int opt_idx;
5615 int opt_flags;
5616{
5617 if (opt_flags & OPT_LOCAL)
5618 switch ((int)options[opt_idx].indir)
5619 {
5620#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005621 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005622#endif
5623#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005624# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005625 case PV_FDE: return &curwin->w_p_fde_flags;
5626 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005627# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005628# ifdef FEAT_BEVAL
5629 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5630# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005631# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005632 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005633# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005634 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005635# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005636 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005637# endif
5638#endif
5639 }
5640
5641 /* Nothing special, return global flags field. */
5642 return &options[opt_idx].flags;
5643}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005644#endif
5645
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005646#ifdef FEAT_TITLE
5647static void redraw_titles __ARGS((void));
5648
5649/*
5650 * Redraw the window title and/or tab page text later.
5651 */
5652static void redraw_titles()
5653{
5654 need_maketitle = TRUE;
5655# ifdef FEAT_WINDOWS
5656 redraw_tabline = TRUE;
5657# endif
5658}
5659#endif
5660
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661/*
5662 * Set a string option to a new value (without checking the effect).
5663 * The string is copied into allocated memory.
5664 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005665 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005666 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667 */
5668 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005669set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670 char_u *name;
5671 int opt_idx;
5672 char_u *val;
5673 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005674 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675{
5676 char_u *s;
5677 char_u **varp;
5678 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005679 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680
Bram Moolenaar89d40322006-08-29 15:30:07 +00005681 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005683 idx = findoption(name);
5684 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005685 {
5686 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005687 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005688 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690 }
5691
Bram Moolenaar89d40322006-08-29 15:30:07 +00005692 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693 return;
5694
5695 s = vim_strsave(val);
5696 if (s != NULL)
5697 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005698 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005700 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701 free_string_option(*varp);
5702 *varp = s;
5703
5704 /* For buffer/window local option may also set the global value. */
5705 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005706 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707
Bram Moolenaar89d40322006-08-29 15:30:07 +00005708 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005709
5710 /* When setting both values of a global option with a local value,
5711 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005712 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713 {
5714 free_string_option(*varp);
5715 *varp = empty_option;
5716 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005717# ifdef FEAT_EVAL
5718 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005719 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005720 set_sid == 0 ? current_SID : set_sid);
5721# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005722 }
5723}
5724
5725/*
5726 * Set global value for string option when it's a local option.
5727 */
5728 static void
5729set_string_option_global(opt_idx, varp)
5730 int opt_idx; /* option index */
5731 char_u **varp; /* pointer to option variable */
5732{
5733 char_u **p, *s;
5734
5735 /* the global value is always allocated */
5736 if (options[opt_idx].var == VAR_WIN)
5737 p = (char_u **)GLOBAL_WO(varp);
5738 else
5739 p = (char_u **)options[opt_idx].var;
5740 if (options[opt_idx].indir != PV_NONE
5741 && p != varp
5742 && (s = vim_strsave(*varp)) != NULL)
5743 {
5744 free_string_option(*p);
5745 *p = s;
5746 }
5747}
5748
5749/*
5750 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005751 *
5752 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005754 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005755set_string_option(opt_idx, value, opt_flags)
5756 int opt_idx;
5757 char_u *value;
5758 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5759{
5760 char_u *s;
5761 char_u **varp;
5762 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005763#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5764 char_u *saved_oldval = NULL;
5765#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005766 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005767
5768 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005769 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005770
5771 s = vim_strsave(value);
5772 if (s != NULL)
5773 {
5774 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5775 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005776 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005777 ? OPT_GLOBAL : OPT_LOCAL)
5778 : opt_flags);
5779 oldval = *varp;
5780 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005781
5782#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005783 if (!starting
5784# ifdef FEAT_CRYPT
5785 && options[opt_idx].indir != PV_KEY
5786# endif
5787 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005788 saved_oldval = vim_strsave(oldval);
5789#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005790 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5791 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005792 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005793
5794 /* call autocomamnd after handling side effects */
5795#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5796 if (saved_oldval != NULL)
5797 {
5798 char_u buf_type[7];
5799 sprintf((char *)buf_type, "%s",
5800 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005801 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5802 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005803 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5804 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5805 reset_v_option_vars();
5806 vim_free(saved_oldval);
5807 }
5808#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005809 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005810 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005811}
5812
5813/*
5814 * Handle string options that need some action to perform when changed.
5815 * Returns NULL for success, or an error message for an error.
5816 */
5817 static char_u *
5818did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5819 opt_flags)
5820 int opt_idx; /* index in options[] table */
5821 char_u **varp; /* pointer to the option variable */
5822 int new_value_alloced; /* new value was allocated */
5823 char_u *oldval; /* previous value of the option */
5824 char_u *errbuf; /* buffer for errors, or NULL */
5825 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5826{
5827 char_u *errmsg = NULL;
5828 char_u *s, *p;
5829 int did_chartab = FALSE;
5830 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005831 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005832#ifdef FEAT_GUI
5833 /* set when changing an option that only requires a redraw in the GUI */
5834 int redraw_gui_only = FALSE;
5835#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005836
5837 /* Get the global option to compare with, otherwise we would have to check
5838 * two values for all local options. */
5839 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5840
5841 /* Disallow changing some options from secure mode */
5842 if ((secure
5843#ifdef HAVE_SANDBOX
5844 || sandbox != 0
5845#endif
5846 ) && (options[opt_idx].flags & P_SECURE))
5847 {
5848 errmsg = e_secure;
5849 }
5850
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005851 /* Check for a "normal" file name in some options. Disallow a path
5852 * separator (slash and/or backslash), wildcards and characters that are
5853 * often illegal in a file name. */
5854 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005855 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005856 {
5857 errmsg = e_invarg;
5858 }
5859
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 /* 'term' */
5861 else if (varp == &T_NAME)
5862 {
5863 if (T_NAME[0] == NUL)
5864 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5865#ifdef FEAT_GUI
5866 if (gui.in_use)
5867 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5868 else if (term_is_gui(T_NAME))
5869 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5870#endif
5871 else if (set_termname(T_NAME) == FAIL)
5872 errmsg = (char_u *)N_("E522: Not found in termcap");
5873 else
5874 /* Screen colors may have changed. */
5875 redraw_later_clear();
5876 }
5877
5878 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005879 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005881 char_u *bkc = p_bkc;
5882 unsigned int *flags = &bkc_flags;
5883
5884 if (opt_flags & OPT_LOCAL)
5885 {
5886 bkc = curbuf->b_p_bkc;
5887 flags = &curbuf->b_bkc_flags;
5888 }
5889
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005890 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5891 /* make the local value empty: use the global value */
5892 *flags = 0;
5893 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005895 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5896 errmsg = e_invarg;
5897 if ((((int)*flags & BKC_AUTO) != 0)
5898 + (((int)*flags & BKC_YES) != 0)
5899 + (((int)*flags & BKC_NO) != 0) != 1)
5900 {
5901 /* Must have exactly one of "auto", "yes" and "no". */
5902 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5903 errmsg = e_invarg;
5904 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905 }
5906 }
5907
5908 /* 'backupext' and 'patchmode' */
5909 else if (varp == &p_bex || varp == &p_pm)
5910 {
5911 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5912 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5913 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5914 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005915#ifdef FEAT_LINEBREAK
5916 /* 'breakindentopt' */
5917 else if (varp == &curwin->w_p_briopt)
5918 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005919 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005920 errmsg = e_invarg;
5921 }
5922#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005923
5924 /*
5925 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5926 * If the new option is invalid, use old value. 'lisp' option: refill
5927 * chartab[] for '-' char
5928 */
5929 else if ( varp == &p_isi
5930 || varp == &(curbuf->b_p_isk)
5931 || varp == &p_isp
5932 || varp == &p_isf)
5933 {
5934 if (init_chartab() == FAIL)
5935 {
5936 did_chartab = TRUE; /* need to restore it below */
5937 errmsg = e_invarg; /* error in value */
5938 }
5939 }
5940
5941 /* 'helpfile' */
5942 else if (varp == &p_hf)
5943 {
5944 /* May compute new values for $VIM and $VIMRUNTIME */
5945 if (didset_vim)
5946 {
5947 vim_setenv((char_u *)"VIM", (char_u *)"");
5948 didset_vim = FALSE;
5949 }
5950 if (didset_vimruntime)
5951 {
5952 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5953 didset_vimruntime = FALSE;
5954 }
5955 }
5956
Bram Moolenaar1a384422010-07-14 19:53:30 +02005957#ifdef FEAT_SYN_HL
5958 /* 'colorcolumn' */
5959 else if (varp == &curwin->w_p_cc)
5960 errmsg = check_colorcolumn(curwin);
5961#endif
5962
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963#ifdef FEAT_MULTI_LANG
5964 /* 'helplang' */
5965 else if (varp == &p_hlg)
5966 {
5967 /* Check for "", "ab", "ab,cd", etc. */
5968 for (s = p_hlg; *s != NUL; s += 3)
5969 {
5970 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5971 {
5972 errmsg = e_invarg;
5973 break;
5974 }
5975 if (s[2] == NUL)
5976 break;
5977 }
5978 }
5979#endif
5980
5981 /* 'highlight' */
5982 else if (varp == &p_hl)
5983 {
5984 if (highlight_changed() == FAIL)
5985 errmsg = e_invarg; /* invalid flags */
5986 }
5987
5988 /* 'nrformats' */
5989 else if (gvarp == &p_nf)
5990 {
5991 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5992 errmsg = e_invarg;
5993 }
5994
5995#ifdef FEAT_SESSION
5996 /* 'sessionoptions' */
5997 else if (varp == &p_ssop)
5998 {
5999 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6000 errmsg = e_invarg;
6001 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6002 {
6003 /* Don't allow both "sesdir" and "curdir". */
6004 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6005 errmsg = e_invarg;
6006 }
6007 }
6008 /* 'viewoptions' */
6009 else if (varp == &p_vop)
6010 {
6011 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6012 errmsg = e_invarg;
6013 }
6014#endif
6015
6016 /* 'scrollopt' */
6017#ifdef FEAT_SCROLLBIND
6018 else if (varp == &p_sbo)
6019 {
6020 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6021 errmsg = e_invarg;
6022 }
6023#endif
6024
6025 /* 'ambiwidth' */
6026#ifdef FEAT_MBYTE
6027 else if (varp == &p_ambw)
6028 {
6029 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6030 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006031 else if (set_chars_option(&p_lcs) != NULL)
6032 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6033# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6034 else if (set_chars_option(&p_fcs) != NULL)
6035 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6036# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037 }
6038#endif
6039
6040 /* 'background' */
6041 else if (varp == &p_bg)
6042 {
6043 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6044 {
6045#ifdef FEAT_EVAL
6046 int dark = (*p_bg == 'd');
6047#endif
6048
6049 init_highlight(FALSE, FALSE);
6050
6051#ifdef FEAT_EVAL
6052 if (dark != (*p_bg == 'd')
6053 && get_var_value((char_u *)"g:colors_name") != NULL)
6054 {
6055 /* The color scheme must have set 'background' back to another
6056 * value, that's not what we want here. Disable the color
6057 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006058 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006059 free_string_option(p_bg);
6060 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6061 check_string_option(&p_bg);
6062 init_highlight(FALSE, FALSE);
6063 }
6064#endif
6065 }
6066 else
6067 errmsg = e_invarg;
6068 }
6069
6070 /* 'wildmode' */
6071 else if (varp == &p_wim)
6072 {
6073 if (check_opt_wim() == FAIL)
6074 errmsg = e_invarg;
6075 }
6076
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006077#ifdef FEAT_CMDL_COMPL
6078 /* 'wildoptions' */
6079 else if (varp == &p_wop)
6080 {
6081 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6082 errmsg = e_invarg;
6083 }
6084#endif
6085
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086#ifdef FEAT_WAK
6087 /* 'winaltkeys' */
6088 else if (varp == &p_wak)
6089 {
6090 if (*p_wak == NUL
6091 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6092 errmsg = e_invarg;
6093# ifdef FEAT_MENU
6094# ifdef FEAT_GUI_MOTIF
6095 else if (gui.in_use)
6096 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6097# else
6098# ifdef FEAT_GUI_GTK
6099 else if (gui.in_use)
6100 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6101# endif
6102# endif
6103# endif
6104 }
6105#endif
6106
6107#ifdef FEAT_AUTOCMD
6108 /* 'eventignore' */
6109 else if (varp == &p_ei)
6110 {
6111 if (check_ei() == FAIL)
6112 errmsg = e_invarg;
6113 }
6114#endif
6115
6116#ifdef FEAT_MBYTE
6117 /* 'encoding' and 'fileencoding' */
6118 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6119 {
6120 if (gvarp == &p_fenc)
6121 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006122 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006123 errmsg = e_modifiable;
6124 else if (vim_strchr(*varp, ',') != NULL)
6125 /* No comma allowed in 'fileencoding'; catches confusing it
6126 * with 'fileencodings'. */
6127 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006128 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006129 {
6130# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006131 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006132 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006133# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006134 /* Add 'fileencoding' to the swap file. */
6135 ml_setflags(curbuf);
6136 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 }
6138 if (errmsg == NULL)
6139 {
6140 /* canonize the value, so that STRCMP() can be used on it */
6141 p = enc_canonize(*varp);
6142 if (p != NULL)
6143 {
6144 vim_free(*varp);
6145 *varp = p;
6146 }
6147 if (varp == &p_enc)
6148 {
6149 errmsg = mb_init();
6150# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006151 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006152# endif
6153 }
6154 }
6155
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006156# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006157 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6158 {
6159 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6160 if (STRCMP(p_tenc, "utf-8") != 0)
6161 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6162 }
6163# endif
6164
6165 if (errmsg == NULL)
6166 {
6167# ifdef FEAT_KEYMAP
6168 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6169 * (with another encoding). */
6170 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6171 (void)keymap_init();
6172# endif
6173
6174 /* When 'termencoding' is not empty and 'encoding' changes or when
6175 * 'termencoding' changes, need to setup for keyboard input and
6176 * display output conversion. */
6177 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6178 {
6179 convert_setup(&input_conv, p_tenc, p_enc);
6180 convert_setup(&output_conv, p_enc, p_tenc);
6181 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006182
6183# if defined(WIN3264) && defined(FEAT_MBYTE)
6184 /* $HOME may have characters in active code page. */
6185 if (varp == &p_enc)
6186 init_homedir();
6187# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188 }
6189 }
6190#endif
6191
6192#if defined(FEAT_POSTSCRIPT)
6193 else if (varp == &p_penc)
6194 {
6195 /* Canonize printencoding if VIM standard one */
6196 p = enc_canonize(p_penc);
6197 if (p != NULL)
6198 {
6199 vim_free(p_penc);
6200 p_penc = p;
6201 }
6202 else
6203 {
6204 /* Ensure lower case and '-' for '_' */
6205 for (s = p_penc; *s != NUL; s++)
6206 {
6207 if (*s == '_')
6208 *s = '-';
6209 else
6210 *s = TOLOWER_ASC(*s);
6211 }
6212 }
6213 }
6214#endif
6215
Bram Moolenaar9372a112005-12-06 19:59:18 +00006216#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006217 else if (varp == &p_imak)
6218 {
6219 if (gui.in_use && !im_xim_isvalid_imactivate())
6220 errmsg = e_invarg;
6221 }
6222#endif
6223
6224#ifdef FEAT_KEYMAP
6225 else if (varp == &curbuf->b_p_keymap)
6226 {
6227 /* load or unload key mapping tables */
6228 errmsg = keymap_init();
6229
Bram Moolenaarfab06232009-03-04 03:13:35 +00006230 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006231 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006232 if (*curbuf->b_p_keymap != NUL)
6233 {
6234 /* Installed a new keymap, switch on using it. */
6235 curbuf->b_p_iminsert = B_IMODE_LMAP;
6236 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6237 curbuf->b_p_imsearch = B_IMODE_LMAP;
6238 }
6239 else
6240 {
6241 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6242 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6243 curbuf->b_p_iminsert = B_IMODE_NONE;
6244 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6245 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6246 }
6247 if ((opt_flags & OPT_LOCAL) == 0)
6248 {
6249 set_iminsert_global();
6250 set_imsearch_global();
6251 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006252# ifdef FEAT_WINDOWS
6253 status_redraw_curbuf();
6254# endif
6255 }
6256 }
6257#endif
6258
6259 /* 'fileformat' */
6260 else if (gvarp == &p_ff)
6261 {
6262 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6263 errmsg = e_modifiable;
6264 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6265 errmsg = e_invarg;
6266 else
6267 {
6268 /* may also change 'textmode' */
6269 if (get_fileformat(curbuf) == EOL_DOS)
6270 curbuf->b_p_tx = TRUE;
6271 else
6272 curbuf->b_p_tx = FALSE;
6273#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006274 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006275#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006276 /* update flag in swap file */
6277 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006278 /* Redraw needed when switching to/from "mac": a CR in the text
6279 * will be displayed differently. */
6280 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6281 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006282 }
6283 }
6284
6285 /* 'fileformats' */
6286 else if (varp == &p_ffs)
6287 {
6288 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6289 errmsg = e_invarg;
6290 else
6291 {
6292 /* also change 'textauto' */
6293 if (*p_ffs == NUL)
6294 p_ta = FALSE;
6295 else
6296 p_ta = TRUE;
6297 }
6298 }
6299
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006300#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006301 /* 'cryptkey' */
6302 else if (gvarp == &p_key)
6303 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006304# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006305 /* Make sure the ":set" command doesn't show the new value in the
6306 * history. */
6307 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006308# endif
6309 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6310 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006311 ml_set_crypt_key(curbuf, oldval,
6312 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006313 }
6314
6315 else if (gvarp == &p_cm)
6316 {
6317 if (opt_flags & OPT_LOCAL)
6318 p = curbuf->b_p_cm;
6319 else
6320 p = p_cm;
6321 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6322 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006323 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006324 errmsg = e_invarg;
6325 else
6326 {
6327 /* When setting the global value to empty, make it "zip". */
6328 if (*p_cm == NUL)
6329 {
6330 if (new_value_alloced)
6331 free_string_option(p_cm);
6332 p_cm = vim_strsave((char_u *)"zip");
6333 new_value_alloced = TRUE;
6334 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006335 /* When using ":set cm=name" the local value is going to be empty.
6336 * Do that here, otherwise the crypt functions will still use the
6337 * local value. */
6338 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6339 {
6340 free_string_option(curbuf->b_p_cm);
6341 curbuf->b_p_cm = empty_option;
6342 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006343
6344 /* Need to update the swapfile when the effective method changed.
6345 * Set "s" to the effective old value, "p" to the effective new
6346 * method and compare. */
6347 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6348 s = p_cm; /* was previously using the global value */
6349 else
6350 s = oldval;
6351 if (*curbuf->b_p_cm == NUL)
6352 p = p_cm; /* is now using the global value */
6353 else
6354 p = curbuf->b_p_cm;
6355 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006356 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006357
6358 /* If the global value changes need to update the swapfile for all
6359 * buffers using that value. */
6360 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6361 {
6362 buf_T *buf;
6363
6364 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6365 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006366 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006367 }
6368 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006369 }
6370#endif
6371
6372 /* 'matchpairs' */
6373 else if (gvarp == &p_mps)
6374 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006375#ifdef FEAT_MBYTE
6376 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006378 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006379 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006380 int x2 = -1;
6381 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006382
6383 if (*p != NUL)
6384 p += mb_ptr2len(p);
6385 if (*p != NUL)
6386 x2 = *p++;
6387 if (*p != NUL)
6388 {
6389 x3 = mb_ptr2char(p);
6390 p += mb_ptr2len(p);
6391 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006392 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006393 {
6394 errmsg = e_invarg;
6395 break;
6396 }
6397 if (*p == NUL)
6398 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006399 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006400 }
6401 else
6402#endif
6403 {
6404 /* Check for "x:y,x:y" */
6405 for (p = *varp; *p != NUL; p += 4)
6406 {
6407 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6408 {
6409 errmsg = e_invarg;
6410 break;
6411 }
6412 if (p[3] == NUL)
6413 break;
6414 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006415 }
6416 }
6417
6418#ifdef FEAT_COMMENTS
6419 /* 'comments' */
6420 else if (gvarp == &p_com)
6421 {
6422 for (s = *varp; *s; )
6423 {
6424 while (*s && *s != ':')
6425 {
6426 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6427 && !VIM_ISDIGIT(*s) && *s != '-')
6428 {
6429 errmsg = illegal_char(errbuf, *s);
6430 break;
6431 }
6432 ++s;
6433 }
6434 if (*s++ == NUL)
6435 errmsg = (char_u *)N_("E524: Missing colon");
6436 else if (*s == ',' || *s == NUL)
6437 errmsg = (char_u *)N_("E525: Zero length string");
6438 if (errmsg != NULL)
6439 break;
6440 while (*s && *s != ',')
6441 {
6442 if (*s == '\\' && s[1] != NUL)
6443 ++s;
6444 ++s;
6445 }
6446 s = skip_to_option_part(s);
6447 }
6448 }
6449#endif
6450
6451 /* 'listchars' */
6452 else if (varp == &p_lcs)
6453 {
6454 errmsg = set_chars_option(varp);
6455 }
6456
6457#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6458 /* 'fillchars' */
6459 else if (varp == &p_fcs)
6460 {
6461 errmsg = set_chars_option(varp);
6462 }
6463#endif
6464
6465#ifdef FEAT_CMDWIN
6466 /* 'cedit' */
6467 else if (varp == &p_cedit)
6468 {
6469 errmsg = check_cedit();
6470 }
6471#endif
6472
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006473 /* 'verbosefile' */
6474 else if (varp == &p_vfile)
6475 {
6476 verbose_stop();
6477 if (*p_vfile != NUL && verbose_open() == FAIL)
6478 errmsg = e_invarg;
6479 }
6480
Bram Moolenaar071d4272004-06-13 20:20:40 +00006481#ifdef FEAT_VIMINFO
6482 /* 'viminfo' */
6483 else if (varp == &p_viminfo)
6484 {
6485 for (s = p_viminfo; *s;)
6486 {
6487 /* Check it's a valid character */
6488 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6489 {
6490 errmsg = illegal_char(errbuf, *s);
6491 break;
6492 }
6493 if (*s == 'n') /* name is always last one */
6494 {
6495 break;
6496 }
6497 else if (*s == 'r') /* skip until next ',' */
6498 {
6499 while (*++s && *s != ',')
6500 ;
6501 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006502 else if (*s == '%')
6503 {
6504 /* optional number */
6505 while (vim_isdigit(*++s))
6506 ;
6507 }
6508 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006509 ++s; /* no extra chars */
6510 else /* must have a number */
6511 {
6512 while (vim_isdigit(*++s))
6513 ;
6514
6515 if (!VIM_ISDIGIT(*(s - 1)))
6516 {
6517 if (errbuf != NULL)
6518 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006519 sprintf((char *)errbuf,
6520 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006521 transchar_byte(*(s - 1)));
6522 errmsg = errbuf;
6523 }
6524 else
6525 errmsg = (char_u *)"";
6526 break;
6527 }
6528 }
6529 if (*s == ',')
6530 ++s;
6531 else if (*s)
6532 {
6533 if (errbuf != NULL)
6534 errmsg = (char_u *)N_("E527: Missing comma");
6535 else
6536 errmsg = (char_u *)"";
6537 break;
6538 }
6539 }
6540 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6541 errmsg = (char_u *)N_("E528: Must specify a ' value");
6542 }
6543#endif /* FEAT_VIMINFO */
6544
6545 /* terminal options */
6546 else if (istermoption(&options[opt_idx]) && full_screen)
6547 {
6548 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6549 if (varp == &T_CCO)
6550 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006551 int colors = atoi((char *)T_CCO);
6552
6553 /* Only reinitialize colors if t_Co value has really changed to
6554 * avoid expensive reload of colorscheme if t_Co is set to the
6555 * same value multiple times. */
6556 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006558 t_colors = colors;
6559 if (t_colors <= 1)
6560 {
6561 if (new_value_alloced)
6562 vim_free(T_CCO);
6563 T_CCO = empty_option;
6564 }
6565 /* We now have a different color setup, initialize it again. */
6566 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006567 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568 }
6569 ttest(FALSE);
6570 if (varp == &T_ME)
6571 {
6572 out_str(T_ME);
6573 redraw_later(CLEAR);
6574#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6575 /* Since t_me has been set, this probably means that the user
6576 * wants to use this as default colors. Need to reset default
6577 * background/foreground colors. */
6578 mch_set_normal_colors();
6579#endif
6580 }
6581 }
6582
6583#ifdef FEAT_LINEBREAK
6584 /* 'showbreak' */
6585 else if (varp == &p_sbr)
6586 {
6587 for (s = p_sbr; *s; )
6588 {
6589 if (ptr2cells(s) != 1)
6590 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006591 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006592 }
6593 }
6594#endif
6595
6596#ifdef FEAT_GUI
6597 /* 'guifont' */
6598 else if (varp == &p_guifont)
6599 {
6600 if (gui.in_use)
6601 {
6602 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006603# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604 /*
6605 * Put up a font dialog and let the user select a new value.
6606 * If this is cancelled go back to the old value but don't
6607 * give an error message.
6608 */
6609 if (STRCMP(p, "*") == 0)
6610 {
6611 p = gui_mch_font_dialog(oldval);
6612
6613 if (new_value_alloced)
6614 free_string_option(p_guifont);
6615
6616 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6617 new_value_alloced = TRUE;
6618 }
6619# endif
6620 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6621 {
6622# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6623 if (STRCMP(p_guifont, "*") == 0)
6624 {
6625 /* Dialog was cancelled: Keep the old value without giving
6626 * an error message. */
6627 if (new_value_alloced)
6628 free_string_option(p_guifont);
6629 p_guifont = vim_strsave(oldval);
6630 new_value_alloced = TRUE;
6631 }
6632 else
6633# endif
6634 errmsg = (char_u *)N_("E596: Invalid font(s)");
6635 }
6636 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006637 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006638 }
6639# ifdef FEAT_XFONTSET
6640 else if (varp == &p_guifontset)
6641 {
6642 if (STRCMP(p_guifontset, "*") == 0)
6643 errmsg = (char_u *)N_("E597: can't select fontset");
6644 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6645 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006646 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006647 }
6648# endif
6649# ifdef FEAT_MBYTE
6650 else if (varp == &p_guifontwide)
6651 {
6652 if (STRCMP(p_guifontwide, "*") == 0)
6653 errmsg = (char_u *)N_("E533: can't select wide font");
6654 else if (gui_get_wide_font() == FAIL)
6655 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006656 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006657 }
6658# endif
6659#endif
6660
6661#ifdef CURSOR_SHAPE
6662 /* 'guicursor' */
6663 else if (varp == &p_guicursor)
6664 errmsg = parse_shape_opt(SHAPE_CURSOR);
6665#endif
6666
6667#ifdef FEAT_MOUSESHAPE
6668 /* 'mouseshape' */
6669 else if (varp == &p_mouseshape)
6670 {
6671 errmsg = parse_shape_opt(SHAPE_MOUSE);
6672 update_mouseshape(-1);
6673 }
6674#endif
6675
6676#ifdef FEAT_PRINTER
6677 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006678 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006679# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006680 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006681 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006682# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006683#endif
6684
6685#ifdef FEAT_LANGMAP
6686 /* 'langmap' */
6687 else if (varp == &p_langmap)
6688 langmap_set();
6689#endif
6690
6691#ifdef FEAT_LINEBREAK
6692 /* 'breakat' */
6693 else if (varp == &p_breakat)
6694 fill_breakat_flags();
6695#endif
6696
6697#ifdef FEAT_TITLE
6698 /* 'titlestring' and 'iconstring' */
6699 else if (varp == &p_titlestring || varp == &p_iconstring)
6700 {
6701# ifdef FEAT_STL_OPT
6702 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6703
6704 /* NULL => statusline syntax */
6705 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6706 stl_syntax |= flagval;
6707 else
6708 stl_syntax &= ~flagval;
6709# endif
6710 did_set_title(varp == &p_iconstring);
6711
6712 }
6713#endif
6714
6715#ifdef FEAT_GUI
6716 /* 'guioptions' */
6717 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006718 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006720 redraw_gui_only = TRUE;
6721 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722#endif
6723
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006724#if defined(FEAT_GUI_TABLINE)
6725 /* 'guitablabel' */
6726 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006727 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006728 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006729 redraw_gui_only = TRUE;
6730 }
6731 /* 'guitabtooltip' */
6732 else if (varp == &p_gtt)
6733 {
6734 redraw_gui_only = TRUE;
6735 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006736#endif
6737
Bram Moolenaar071d4272004-06-13 20:20:40 +00006738#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6739 /* 'ttymouse' */
6740 else if (varp == &p_ttym)
6741 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006742 /* Switch the mouse off before changing the escape sequences used for
6743 * that. */
6744 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006745 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6746 errmsg = e_invarg;
6747 else
6748 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006749 if (termcap_active)
6750 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006751 }
6752#endif
6753
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754 /* 'selection' */
6755 else if (varp == &p_sel)
6756 {
6757 if (*p_sel == NUL
6758 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6759 errmsg = e_invarg;
6760 }
6761
6762 /* 'selectmode' */
6763 else if (varp == &p_slm)
6764 {
6765 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6766 errmsg = e_invarg;
6767 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006768
6769#ifdef FEAT_BROWSE
6770 /* 'browsedir' */
6771 else if (varp == &p_bsdir)
6772 {
6773 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6774 && !mch_isdir(p_bsdir))
6775 errmsg = e_invarg;
6776 }
6777#endif
6778
Bram Moolenaar071d4272004-06-13 20:20:40 +00006779 /* 'keymodel' */
6780 else if (varp == &p_km)
6781 {
6782 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6783 errmsg = e_invarg;
6784 else
6785 {
6786 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6787 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6788 }
6789 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790
6791 /* 'mousemodel' */
6792 else if (varp == &p_mousem)
6793 {
6794 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6795 errmsg = e_invarg;
6796#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6797 else if (*p_mousem != *oldval)
6798 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6799 * to create or delete the popup menus. */
6800 gui_motif_update_mousemodel(root_menu);
6801#endif
6802 }
6803
6804 /* 'switchbuf' */
6805 else if (varp == &p_swb)
6806 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006807 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006808 errmsg = e_invarg;
6809 }
6810
6811 /* 'debug' */
6812 else if (varp == &p_debug)
6813 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006814 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006815 errmsg = e_invarg;
6816 }
6817
6818 /* 'display' */
6819 else if (varp == &p_dy)
6820 {
6821 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6822 errmsg = e_invarg;
6823 else
6824 (void)init_chartab();
6825
6826 }
6827
6828#ifdef FEAT_VERTSPLIT
6829 /* 'eadirection' */
6830 else if (varp == &p_ead)
6831 {
6832 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6833 errmsg = e_invarg;
6834 }
6835#endif
6836
6837#ifdef FEAT_CLIPBOARD
6838 /* 'clipboard' */
6839 else if (varp == &p_cb)
6840 errmsg = check_clipboard_option();
6841#endif
6842
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006843#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006844 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6845 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006846 else if (varp == &(curwin->w_s->b_p_spl)
6847 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006848 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006849 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006850 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006851 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006852 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006853 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006854 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006855 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006856 /* 'spellsuggest' */
6857 else if (varp == &p_sps)
6858 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006859 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006860 errmsg = e_invarg;
6861 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006862 /* 'mkspellmem' */
6863 else if (varp == &p_msm)
6864 {
6865 if (spell_check_msm() != OK)
6866 errmsg = e_invarg;
6867 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006868#endif
6869
Bram Moolenaar071d4272004-06-13 20:20:40 +00006870#ifdef FEAT_QUICKFIX
6871 /* When 'bufhidden' is set, check for valid value. */
6872 else if (gvarp == &p_bh)
6873 {
6874 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6875 errmsg = e_invarg;
6876 }
6877
6878 /* When 'buftype' is set, check for valid value. */
6879 else if (gvarp == &p_bt)
6880 {
6881 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6882 errmsg = e_invarg;
6883 else
6884 {
6885# ifdef FEAT_WINDOWS
6886 if (curwin->w_status_height)
6887 {
6888 curwin->w_redr_status = TRUE;
6889 redraw_later(VALID);
6890 }
6891# endif
6892 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006893# ifdef FEAT_TITLE
6894 redraw_titles();
6895# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006896 }
6897 }
6898#endif
6899
6900#ifdef FEAT_STL_OPT
6901 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006902 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903 {
6904 int wid;
6905
6906 if (varp == &p_ruf) /* reset ru_wid first */
6907 ru_wid = 0;
6908 s = *varp;
6909 if (varp == &p_ruf && *s == '%')
6910 {
6911 /* set ru_wid if 'ruf' starts with "%99(" */
6912 if (*++s == '-') /* ignore a '-' */
6913 s++;
6914 wid = getdigits(&s);
6915 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6916 ru_wid = wid;
6917 else
6918 errmsg = check_stl_option(p_ruf);
6919 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006920 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006921 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006922 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006923 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006924 comp_col();
6925 }
6926#endif
6927
6928#ifdef FEAT_INS_EXPAND
6929 /* check if it is a valid value for 'complete' -- Acevedo */
6930 else if (gvarp == &p_cpt)
6931 {
6932 for (s = *varp; *s;)
6933 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006934 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006935 s++;
6936 if (!*s)
6937 break;
6938 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6939 {
6940 errmsg = illegal_char(errbuf, *s);
6941 break;
6942 }
6943 if (*++s != NUL && *s != ',' && *s != ' ')
6944 {
6945 if (s[-1] == 'k' || s[-1] == 's')
6946 {
6947 /* skip optional filename after 'k' and 's' */
6948 while (*s && *s != ',' && *s != ' ')
6949 {
6950 if (*s == '\\')
6951 ++s;
6952 ++s;
6953 }
6954 }
6955 else
6956 {
6957 if (errbuf != NULL)
6958 {
6959 sprintf((char *)errbuf,
6960 _("E535: Illegal character after <%c>"),
6961 *--s);
6962 errmsg = errbuf;
6963 }
6964 else
6965 errmsg = (char_u *)"";
6966 break;
6967 }
6968 }
6969 }
6970 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006971
6972 /* 'completeopt' */
6973 else if (varp == &p_cot)
6974 {
6975 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6976 errmsg = e_invarg;
6977 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006978#endif /* FEAT_INS_EXPAND */
6979
6980
6981#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6982 else if (varp == &p_toolbar)
6983 {
6984 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6985 &toolbar_flags, TRUE) != OK)
6986 errmsg = e_invarg;
6987 else
6988 {
6989 out_flush();
6990 gui_mch_show_toolbar((toolbar_flags &
6991 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6992 }
6993 }
6994#endif
6995
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006996#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006997 /* 'toolbariconsize': GTK+ 2 only */
6998 else if (varp == &p_tbis)
6999 {
7000 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7001 errmsg = e_invarg;
7002 else
7003 {
7004 out_flush();
7005 gui_mch_show_toolbar((toolbar_flags &
7006 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7007 }
7008 }
7009#endif
7010
7011 /* 'pastetoggle': translate key codes like in a mapping */
7012 else if (varp == &p_pt)
7013 {
7014 if (*p_pt)
7015 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007016 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 if (p != NULL)
7018 {
7019 if (new_value_alloced)
7020 free_string_option(p_pt);
7021 p_pt = p;
7022 new_value_alloced = TRUE;
7023 }
7024 }
7025 }
7026
7027 /* 'backspace' */
7028 else if (varp == &p_bs)
7029 {
7030 if (VIM_ISDIGIT(*p_bs))
7031 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007032 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007033 errmsg = e_invarg;
7034 }
7035 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7036 errmsg = e_invarg;
7037 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007038 else if (varp == &p_bo)
7039 {
7040 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7041 errmsg = e_invarg;
7042 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007043
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007044 /* 'tagcase' */
7045 else if (gvarp == &p_tc)
7046 {
7047 unsigned int *flags;
7048
7049 if (opt_flags & OPT_LOCAL)
7050 {
7051 p = curbuf->b_p_tc;
7052 flags = &curbuf->b_tc_flags;
7053 }
7054 else
7055 {
7056 p = p_tc;
7057 flags = &tc_flags;
7058 }
7059
7060 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7061 /* make the local value empty: use the global value */
7062 *flags = 0;
7063 else if (*p == NUL
7064 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7065 errmsg = e_invarg;
7066 }
7067
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007068#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007069 /* 'casemap' */
7070 else if (varp == &p_cmp)
7071 {
7072 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7073 errmsg = e_invarg;
7074 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007075#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007076
7077#ifdef FEAT_DIFF
7078 /* 'diffopt' */
7079 else if (varp == &p_dip)
7080 {
7081 if (diffopt_changed() == FAIL)
7082 errmsg = e_invarg;
7083 }
7084#endif
7085
7086#ifdef FEAT_FOLDING
7087 /* 'foldmethod' */
7088 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7089 {
7090 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7091 || *curwin->w_p_fdm == NUL)
7092 errmsg = e_invarg;
7093 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007094 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007095 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007096 if (foldmethodIsDiff(curwin))
7097 newFoldLevel();
7098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007099 }
7100# ifdef FEAT_EVAL
7101 /* 'foldexpr' */
7102 else if (varp == &curwin->w_p_fde)
7103 {
7104 if (foldmethodIsExpr(curwin))
7105 foldUpdateAll(curwin);
7106 }
7107# endif
7108 /* 'foldmarker' */
7109 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7110 {
7111 p = vim_strchr(*varp, ',');
7112 if (p == NULL)
7113 errmsg = (char_u *)N_("E536: comma required");
7114 else if (p == *varp || p[1] == NUL)
7115 errmsg = e_invarg;
7116 else if (foldmethodIsMarker(curwin))
7117 foldUpdateAll(curwin);
7118 }
7119 /* 'commentstring' */
7120 else if (gvarp == &p_cms)
7121 {
7122 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7123 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7124 }
7125 /* 'foldopen' */
7126 else if (varp == &p_fdo)
7127 {
7128 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7129 errmsg = e_invarg;
7130 }
7131 /* 'foldclose' */
7132 else if (varp == &p_fcl)
7133 {
7134 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7135 errmsg = e_invarg;
7136 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007137 /* 'foldignore' */
7138 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7139 {
7140 if (foldmethodIsIndent(curwin))
7141 foldUpdateAll(curwin);
7142 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007143#endif
7144
7145#ifdef FEAT_VIRTUALEDIT
7146 /* 'virtualedit' */
7147 else if (varp == &p_ve)
7148 {
7149 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7150 errmsg = e_invarg;
7151 else if (STRCMP(p_ve, oldval) != 0)
7152 {
7153 /* Recompute cursor position in case the new 've' setting
7154 * changes something. */
7155 validate_virtcol();
7156 coladvance(curwin->w_virtcol);
7157 }
7158 }
7159#endif
7160
7161#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7162 else if (varp == &p_csqf)
7163 {
7164 if (p_csqf != NULL)
7165 {
7166 p = p_csqf;
7167 while (*p != NUL)
7168 {
7169 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7170 || p[1] == NUL
7171 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7172 || (p[2] != NUL && p[2] != ','))
7173 {
7174 errmsg = e_invarg;
7175 break;
7176 }
7177 else if (p[2] == NUL)
7178 break;
7179 else
7180 p += 3;
7181 }
7182 }
7183 }
7184#endif
7185
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007186#ifdef FEAT_CINDENT
7187 /* 'cinoptions' */
7188 else if (gvarp == &p_cino)
7189 {
7190 /* TODO: recognize errors */
7191 parse_cino(curbuf);
7192 }
7193#endif
7194
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007195#if defined(FEAT_RENDER_OPTIONS)
7196 else if (varp == &p_rop && gui.in_use)
7197 {
7198 if (!gui_mch_set_rendering_options(p_rop))
7199 errmsg = e_invarg;
7200 }
7201#endif
7202
Bram Moolenaar071d4272004-06-13 20:20:40 +00007203 /* Options that are a list of flags. */
7204 else
7205 {
7206 p = NULL;
7207 if (varp == &p_ww)
7208 p = (char_u *)WW_ALL;
7209 if (varp == &p_shm)
7210 p = (char_u *)SHM_ALL;
7211 else if (varp == &(p_cpo))
7212 p = (char_u *)CPO_ALL;
7213 else if (varp == &(curbuf->b_p_fo))
7214 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007215#ifdef FEAT_CONCEAL
7216 else if (varp == &curwin->w_p_cocu)
7217 p = (char_u *)COCU_ALL;
7218#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007219 else if (varp == &p_mouse)
7220 {
7221#ifdef FEAT_MOUSE
7222 p = (char_u *)MOUSE_ALL;
7223#else
7224 if (*p_mouse != NUL)
7225 errmsg = (char_u *)N_("E538: No mouse support");
7226#endif
7227 }
7228#if defined(FEAT_GUI)
7229 else if (varp == &p_go)
7230 p = (char_u *)GO_ALL;
7231#endif
7232 if (p != NULL)
7233 {
7234 for (s = *varp; *s; ++s)
7235 if (vim_strchr(p, *s) == NULL)
7236 {
7237 errmsg = illegal_char(errbuf, *s);
7238 break;
7239 }
7240 }
7241 }
7242
7243 /*
7244 * If error detected, restore the previous value.
7245 */
7246 if (errmsg != NULL)
7247 {
7248 if (new_value_alloced)
7249 free_string_option(*varp);
7250 *varp = oldval;
7251 /*
7252 * When resetting some values, need to act on it.
7253 */
7254 if (did_chartab)
7255 (void)init_chartab();
7256 if (varp == &p_hl)
7257 (void)highlight_changed();
7258 }
7259 else
7260 {
7261#ifdef FEAT_EVAL
7262 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007263 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007264#endif
7265 /*
7266 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007267 * Use "free_oldval", because recursiveness may change the flags under
7268 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007269 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007270 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007271 free_string_option(oldval);
7272 if (new_value_alloced)
7273 options[opt_idx].flags |= P_ALLOCED;
7274 else
7275 options[opt_idx].flags &= ~P_ALLOCED;
7276
7277 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007278 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007279 {
7280 /* global option with local value set to use global value; free
7281 * the local value and make it empty */
7282 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7283 free_string_option(*(char_u **)p);
7284 *(char_u **)p = empty_option;
7285 }
7286
7287 /* May set global value for local option. */
7288 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7289 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007290
7291#ifdef FEAT_AUTOCMD
7292 /*
7293 * Trigger the autocommand only after setting the flags.
7294 */
7295# ifdef FEAT_SYN_HL
7296 /* When 'syntax' is set, load the syntax of that name */
7297 if (varp == &(curbuf->b_p_syn))
7298 {
7299 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7300 curbuf->b_fname, TRUE, curbuf);
7301 }
7302# endif
7303 else if (varp == &(curbuf->b_p_ft))
7304 {
7305 /* 'filetype' is set, trigger the FileType autocommand */
7306 did_filetype = TRUE;
7307 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7308 curbuf->b_fname, TRUE, curbuf);
7309 }
7310#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007311#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007312 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007313 {
7314 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007315 char_u *q = curwin->w_s->b_p_spl;
7316
7317 /* Skip the first name if it is "cjk". */
7318 if (STRNCMP(q, "cjk,", 4) == 0)
7319 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007320
7321 /*
7322 * Source the spell/LANG.vim in 'runtimepath'.
7323 * They could set 'spellcapcheck' depending on the language.
7324 * Use the first name in 'spelllang' up to '_region' or
7325 * '.encoding'.
7326 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007327 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007328 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7329 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007330 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007331 source_runtime(fname, TRUE);
7332 }
7333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007334 }
7335
7336#ifdef FEAT_MOUSE
7337 if (varp == &p_mouse)
7338 {
7339# ifdef FEAT_MOUSE_TTY
7340 if (*p_mouse == NUL)
7341 mch_setmouse(FALSE); /* switch mouse off */
7342 else
7343# endif
7344 setmouse(); /* in case 'mouse' changed */
7345 }
7346#endif
7347
Bram Moolenaar913077c2012-03-28 19:59:04 +02007348 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007349 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007350 curwin->w_set_curswant = TRUE;
7351
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007352#ifdef FEAT_GUI
7353 /* check redraw when it's not a GUI option or the GUI is active. */
7354 if (!redraw_gui_only || gui.in_use)
7355#endif
7356 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007357
7358 return errmsg;
7359}
7360
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007361#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007362/*
7363 * Simple int comparison function for use with qsort()
7364 */
7365 static int
7366int_cmp(a, b)
7367 const void *a;
7368 const void *b;
7369{
7370 return *(const int *)a - *(const int *)b;
7371}
7372
7373/*
7374 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7375 * Returns error message, NULL if it's OK.
7376 */
7377 char_u *
7378check_colorcolumn(wp)
7379 win_T *wp;
7380{
7381 char_u *s;
7382 int col;
7383 int count = 0;
7384 int color_cols[256];
7385 int i;
7386 int j = 0;
7387
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007388 if (wp->w_buffer == NULL)
7389 return NULL; /* buffer was closed */
7390
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007391 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007392 {
7393 if (*s == '-' || *s == '+')
7394 {
7395 /* -N and +N: add to 'textwidth' */
7396 col = (*s == '-') ? -1 : 1;
7397 ++s;
7398 if (!VIM_ISDIGIT(*s))
7399 return e_invarg;
7400 col = col * getdigits(&s);
7401 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007402 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007403 col += wp->w_buffer->b_p_tw;
7404 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007405 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007406 }
7407 else if (VIM_ISDIGIT(*s))
7408 col = getdigits(&s);
7409 else
7410 return e_invarg;
7411 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007412skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007413 if (*s == NUL)
7414 break;
7415 if (*s != ',')
7416 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007417 if (*++s == NUL)
7418 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007419 }
7420
7421 vim_free(wp->w_p_cc_cols);
7422 if (count == 0)
7423 wp->w_p_cc_cols = NULL;
7424 else
7425 {
7426 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7427 if (wp->w_p_cc_cols != NULL)
7428 {
7429 /* sort the columns for faster usage on screen redraw inside
7430 * win_line() */
7431 qsort(color_cols, count, sizeof(int), int_cmp);
7432
7433 for (i = 0; i < count; ++i)
7434 /* skip duplicates */
7435 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7436 wp->w_p_cc_cols[j++] = color_cols[i];
7437 wp->w_p_cc_cols[j] = -1; /* end marker */
7438 }
7439 }
7440
7441 return NULL; /* no error */
7442}
7443#endif
7444
Bram Moolenaar071d4272004-06-13 20:20:40 +00007445/*
7446 * Handle setting 'listchars' or 'fillchars'.
7447 * Returns error message, NULL if it's OK.
7448 */
7449 static char_u *
7450set_chars_option(varp)
7451 char_u **varp;
7452{
7453 int round, i, len, entries;
7454 char_u *p, *s;
7455 int c1, c2 = 0;
7456 struct charstab
7457 {
7458 int *cp;
7459 char *name;
7460 };
7461#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7462 static struct charstab filltab[] =
7463 {
7464 {&fill_stl, "stl"},
7465 {&fill_stlnc, "stlnc"},
7466 {&fill_vert, "vert"},
7467 {&fill_fold, "fold"},
7468 {&fill_diff, "diff"},
7469 };
7470#endif
7471 static struct charstab lcstab[] =
7472 {
7473 {&lcs_eol, "eol"},
7474 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007475 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007476 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007477 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007478 {&lcs_tab2, "tab"},
7479 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007480#ifdef FEAT_CONCEAL
7481 {&lcs_conceal, "conceal"},
7482#else
7483 {NULL, "conceal"},
7484#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007485 };
7486 struct charstab *tab;
7487
7488#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7489 if (varp == &p_lcs)
7490#endif
7491 {
7492 tab = lcstab;
7493 entries = sizeof(lcstab) / sizeof(struct charstab);
7494 }
7495#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7496 else
7497 {
7498 tab = filltab;
7499 entries = sizeof(filltab) / sizeof(struct charstab);
7500 }
7501#endif
7502
7503 /* first round: check for valid value, second round: assign values */
7504 for (round = 0; round <= 1; ++round)
7505 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007506 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007507 {
7508 /* After checking that the value is valid: set defaults: space for
7509 * 'fillchars', NUL for 'listchars' */
7510 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007511 if (tab[i].cp != NULL)
7512 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513 if (varp == &p_lcs)
7514 lcs_tab1 = NUL;
7515#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7516 else
7517 fill_diff = '-';
7518#endif
7519 }
7520 p = *varp;
7521 while (*p)
7522 {
7523 for (i = 0; i < entries; ++i)
7524 {
7525 len = (int)STRLEN(tab[i].name);
7526 if (STRNCMP(p, tab[i].name, len) == 0
7527 && p[len] == ':'
7528 && p[len + 1] != NUL)
7529 {
7530 s = p + len + 1;
7531#ifdef FEAT_MBYTE
7532 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007533 if (mb_char2cells(c1) > 1)
7534 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007535#else
7536 c1 = *s++;
7537#endif
7538 if (tab[i].cp == &lcs_tab2)
7539 {
7540 if (*s == NUL)
7541 continue;
7542#ifdef FEAT_MBYTE
7543 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007544 if (mb_char2cells(c2) > 1)
7545 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546#else
7547 c2 = *s++;
7548#endif
7549 }
7550 if (*s == ',' || *s == NUL)
7551 {
7552 if (round)
7553 {
7554 if (tab[i].cp == &lcs_tab2)
7555 {
7556 lcs_tab1 = c1;
7557 lcs_tab2 = c2;
7558 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007559 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007560 *(tab[i].cp) = c1;
7561
7562 }
7563 p = s;
7564 break;
7565 }
7566 }
7567 }
7568
7569 if (i == entries)
7570 return e_invarg;
7571 if (*p == ',')
7572 ++p;
7573 }
7574 }
7575
7576 return NULL; /* no error */
7577}
7578
7579#ifdef FEAT_STL_OPT
7580/*
7581 * Check validity of options with the 'statusline' format.
7582 * Return error message or NULL.
7583 */
7584 char_u *
7585check_stl_option(s)
7586 char_u *s;
7587{
7588 int itemcnt = 0;
7589 int groupdepth = 0;
7590 static char_u errbuf[80];
7591
7592 while (*s && itemcnt < STL_MAX_ITEM)
7593 {
7594 /* Check for valid keys after % sequences */
7595 while (*s && *s != '%')
7596 s++;
7597 if (!*s)
7598 break;
7599 s++;
7600 if (*s != '%' && *s != ')')
7601 ++itemcnt;
7602 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7603 {
7604 s++;
7605 continue;
7606 }
7607 if (*s == ')')
7608 {
7609 s++;
7610 if (--groupdepth < 0)
7611 break;
7612 continue;
7613 }
7614 if (*s == '-')
7615 s++;
7616 while (VIM_ISDIGIT(*s))
7617 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007618 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007619 continue;
7620 if (*s == '.')
7621 {
7622 s++;
7623 while (*s && VIM_ISDIGIT(*s))
7624 s++;
7625 }
7626 if (*s == '(')
7627 {
7628 groupdepth++;
7629 continue;
7630 }
7631 if (vim_strchr(STL_ALL, *s) == NULL)
7632 {
7633 return illegal_char(errbuf, *s);
7634 }
7635 if (*s == '{')
7636 {
7637 s++;
7638 while (*s != '}' && *s)
7639 s++;
7640 if (*s != '}')
7641 return (char_u *)N_("E540: Unclosed expression sequence");
7642 }
7643 }
7644 if (itemcnt >= STL_MAX_ITEM)
7645 return (char_u *)N_("E541: too many items");
7646 if (groupdepth != 0)
7647 return (char_u *)N_("E542: unbalanced groups");
7648 return NULL;
7649}
7650#endif
7651
7652#ifdef FEAT_CLIPBOARD
7653/*
7654 * Extract the items in the 'clipboard' option and set global values.
7655 */
7656 static char_u *
7657check_clipboard_option()
7658{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007659 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007660 int new_autoselect_star = FALSE;
7661 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007662 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007663 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007664 regprog_T *new_exclude_prog = NULL;
7665 char_u *errmsg = NULL;
7666 char_u *p;
7667
7668 for (p = p_cb; *p != NUL; )
7669 {
7670 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7671 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007672 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007673 p += 7;
7674 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007675 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007676 && (p[11] == ',' || p[11] == NUL))
7677 {
7678 new_unnamed |= CLIP_UNNAMED_PLUS;
7679 p += 11;
7680 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007681 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007682 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007683 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007684 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007685 p += 10;
7686 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007687 else if (STRNCMP(p, "autoselectplus", 14) == 0
7688 && (p[14] == ',' || p[14] == NUL))
7689 {
7690 new_autoselect_plus = TRUE;
7691 p += 14;
7692 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007693 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007694 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007695 {
7696 new_autoselectml = TRUE;
7697 p += 12;
7698 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007699 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7700 {
7701 new_html = TRUE;
7702 p += 4;
7703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7705 {
7706 p += 8;
7707 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7708 if (new_exclude_prog == NULL)
7709 errmsg = e_invarg;
7710 break;
7711 }
7712 else
7713 {
7714 errmsg = e_invarg;
7715 break;
7716 }
7717 if (*p == ',')
7718 ++p;
7719 }
7720 if (errmsg == NULL)
7721 {
7722 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007723 clip_autoselect_star = new_autoselect_star;
7724 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007725 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007726 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007727 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007728 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007729#ifdef FEAT_GUI_GTK
7730 if (gui.in_use)
7731 {
7732 gui_gtk_set_selection_targets();
7733 gui_gtk_set_dnd_targets();
7734 }
7735#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736 }
7737 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007738 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739
7740 return errmsg;
7741}
7742#endif
7743
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007744#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007745 static char_u *
7746did_set_spell_option(is_spellfile)
7747 int is_spellfile;
7748{
7749 char_u *errmsg = NULL;
7750 win_T *wp;
7751 int l;
7752
7753 if (is_spellfile)
7754 {
7755 l = (int)STRLEN(curwin->w_s->b_p_spf);
7756 if (l > 0 && (l < 4
7757 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7758 errmsg = e_invarg;
7759 }
7760
7761 if (errmsg == NULL)
7762 {
7763 FOR_ALL_WINDOWS(wp)
7764 if (wp->w_buffer == curbuf && wp->w_p_spell)
7765 {
7766 errmsg = did_set_spelllang(wp);
7767# ifdef FEAT_WINDOWS
7768 break;
7769# endif
7770 }
7771 }
7772 return errmsg;
7773}
7774
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007775/*
7776 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7777 * Return error message when failed, NULL when OK.
7778 */
7779 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007780compile_cap_prog(synblock)
7781 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007782{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007783 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007784 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007785
Bram Moolenaar860cae12010-06-05 23:22:07 +02007786 if (*synblock->b_p_spc == NUL)
7787 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007788 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007789 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007790 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007791 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007792 if (re != NULL)
7793 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007794 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007795 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007796 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007797 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007798 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007799 return e_invarg;
7800 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007801 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007802 }
7803
Bram Moolenaar473de612013-06-08 18:19:48 +02007804 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007805 return NULL;
7806}
7807#endif
7808
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007809#if defined(FEAT_EVAL) || defined(PROTO)
7810/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007811 * Set the scriptID for an option, taking care of setting the buffer- or
7812 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007813 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007814 static void
7815set_option_scriptID_idx(opt_idx, opt_flags, id)
7816 int opt_idx;
7817 int opt_flags;
7818 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007819{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007820 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7821 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007822
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007823 /* Remember where the option was set. For local options need to do that
7824 * in the buffer or window structure. */
7825 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007826 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007827 if (both || (opt_flags & OPT_LOCAL))
7828 {
7829 if (indir & PV_BUF)
7830 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7831 else if (indir & PV_WIN)
7832 curwin->w_p_scriptID[indir & PV_MASK] = id;
7833 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007834}
7835#endif
7836
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837/*
7838 * Set the value of a boolean option, and take care of side effects.
7839 * Returns NULL for success, or an error message for an error.
7840 */
7841 static char_u *
7842set_bool_option(opt_idx, varp, value, opt_flags)
7843 int opt_idx; /* index in options[] table */
7844 char_u *varp; /* pointer to the option variable */
7845 int value; /* new value */
7846 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7847{
7848 int old_value = *(int *)varp;
7849
Bram Moolenaar071d4272004-06-13 20:20:40 +00007850 /* Disallow changing some options from secure mode */
7851 if ((secure
7852#ifdef HAVE_SANDBOX
7853 || sandbox != 0
7854#endif
7855 ) && (options[opt_idx].flags & P_SECURE))
7856 return e_secure;
7857
7858 *(int *)varp = value; /* set the new value */
7859#ifdef FEAT_EVAL
7860 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007861 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007862#endif
7863
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007864#ifdef FEAT_GUI
7865 need_mouse_correct = TRUE;
7866#endif
7867
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868 /* May set global value for local option. */
7869 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7870 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7871
7872 /*
7873 * Handle side effects of changing a bool option.
7874 */
7875
7876 /* 'compatible' */
7877 if ((int *)varp == &p_cp)
7878 {
7879 compatible_set();
7880 }
7881
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007882#ifdef FEAT_PERSISTENT_UNDO
7883 /* 'undofile' */
7884 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7885 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007886 /* Only take action when the option was set. When reset we do not
7887 * delete the undo file, the option may be set again without making
7888 * any changes in between. */
7889 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007890 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007891 char_u hash[UNDO_HASH_SIZE];
7892 buf_T *save_curbuf = curbuf;
7893
7894 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007895 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007896 /* When 'undofile' is set globally: for every buffer, otherwise
7897 * only for the current buffer: Try to read in the undofile,
7898 * if one exists, the buffer wasn't changed and the buffer was
7899 * loaded */
7900 if ((curbuf == save_curbuf
7901 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7902 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7903 {
7904 u_compute_hash(hash);
7905 u_read_undo(NULL, hash, curbuf->b_fname);
7906 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007907 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007908 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007909 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007910 }
7911#endif
7912
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913 else if ((int *)varp == &curbuf->b_p_ro)
7914 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007915 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007916 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7917 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007918
7919 /* when 'readonly' is set may give W10 again */
7920 if (curbuf->b_p_ro)
7921 curbuf->b_did_warn = FALSE;
7922
Bram Moolenaar071d4272004-06-13 20:20:40 +00007923#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007924 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925#endif
7926 }
7927
Bram Moolenaar9c449722010-07-20 18:44:27 +02007928#ifdef FEAT_GUI
7929 else if ((int *)varp == &p_mh)
7930 {
7931 if (!p_mh)
7932 gui_mch_mousehide(FALSE);
7933 }
7934#endif
7935
Bram Moolenaara539df02010-08-01 14:35:05 +02007936#ifdef FEAT_TITLE
7937 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007939 {
7940 redraw_titles();
7941 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007942 /* when 'endofline' is changed, redraw the window title */
7943 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007944 {
7945 redraw_titles();
7946 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007947 /* when 'fixeol' is changed, redraw the window title */
7948 else if ((int *)varp == &curbuf->b_p_fixeol)
7949 {
7950 redraw_titles();
7951 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007952# ifdef FEAT_MBYTE
7953 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007954 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007955 {
7956 redraw_titles();
7957 }
7958# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007959#endif
7960
7961 /* when 'bin' is set also set some other options */
7962 else if ((int *)varp == &curbuf->b_p_bin)
7963 {
7964 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7965#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007966 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967#endif
7968 }
7969
7970#ifdef FEAT_AUTOCMD
7971 /* when 'buflisted' changes, trigger autocommands */
7972 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7973 {
7974 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7975 NULL, NULL, TRUE, curbuf);
7976 }
7977#endif
7978
7979 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7980 else if ((int *)varp == &curbuf->b_p_swf)
7981 {
7982 if (curbuf->b_p_swf && p_uc)
7983 ml_open_file(curbuf); /* create the swap file */
7984 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007985 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7986 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007987 mf_close_file(curbuf, TRUE); /* remove the swap file */
7988 }
7989
7990 /* when 'terse' is set change 'shortmess' */
7991 else if ((int *)varp == &p_terse)
7992 {
7993 char_u *p;
7994
7995 p = vim_strchr(p_shm, SHM_SEARCH);
7996
7997 /* insert 's' in p_shm */
7998 if (p_terse && p == NULL)
7999 {
8000 STRCPY(IObuff, p_shm);
8001 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008002 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003 }
8004 /* remove 's' from p_shm */
8005 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008006 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 }
8008
8009 /* when 'paste' is set or reset also change other options */
8010 else if ((int *)varp == &p_paste)
8011 {
8012 paste_option_changed();
8013 }
8014
8015 /* when 'insertmode' is set from an autocommand need to do work here */
8016 else if ((int *)varp == &p_im)
8017 {
8018 if (p_im)
8019 {
8020 if ((State & INSERT) == 0)
8021 need_start_insertmode = TRUE;
8022 stop_insert_mode = FALSE;
8023 }
8024 else
8025 {
8026 need_start_insertmode = FALSE;
8027 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008028 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008029 clear_cmdline = TRUE; /* remove "(insert)" */
8030 restart_edit = 0;
8031 }
8032 }
8033
8034 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8035 else if ((int *)varp == &p_ic && p_hls)
8036 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008037 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008038 }
8039
8040#ifdef FEAT_SEARCH_EXTRA
8041 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8042 else if ((int *)varp == &p_hls)
8043 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008044 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045 }
8046#endif
8047
8048#ifdef FEAT_SCROLLBIND
8049 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8050 * at the end of normal_cmd() */
8051 else if ((int *)varp == &curwin->w_p_scb)
8052 {
8053 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008054 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008055 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008056 curwin->w_scbind_pos = curwin->w_topline;
8057 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008058 }
8059#endif
8060
8061#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8062 /* There can be only one window with 'previewwindow' set. */
8063 else if ((int *)varp == &curwin->w_p_pvw)
8064 {
8065 if (curwin->w_p_pvw)
8066 {
8067 win_T *win;
8068
8069 for (win = firstwin; win != NULL; win = win->w_next)
8070 if (win->w_p_pvw && win != curwin)
8071 {
8072 curwin->w_p_pvw = FALSE;
8073 return (char_u *)N_("E590: A preview window already exists");
8074 }
8075 }
8076 }
8077#endif
8078
8079 /* when 'textmode' is set or reset also change 'fileformat' */
8080 else if ((int *)varp == &curbuf->b_p_tx)
8081 {
8082 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8083 }
8084
8085 /* when 'textauto' is set or reset also change 'fileformats' */
8086 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008087 set_string_option_direct((char_u *)"ffs", -1,
8088 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008089 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008090
8091 /*
8092 * When 'lisp' option changes include/exclude '-' in
8093 * keyword characters.
8094 */
8095#ifdef FEAT_LISP
8096 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8097 {
8098 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8099 }
8100#endif
8101
8102#ifdef FEAT_TITLE
8103 /* when 'title' changed, may need to change the title; same for 'icon' */
8104 else if ((int *)varp == &p_title)
8105 {
8106 did_set_title(FALSE);
8107 }
8108
8109 else if ((int *)varp == &p_icon)
8110 {
8111 did_set_title(TRUE);
8112 }
8113#endif
8114
8115 else if ((int *)varp == &curbuf->b_changed)
8116 {
8117 if (!value)
8118 save_file_ff(curbuf); /* Buffer is unchanged */
8119#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008120 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008121#endif
8122#ifdef FEAT_AUTOCMD
8123 modified_was_set = value;
8124#endif
8125 }
8126
8127#ifdef BACKSLASH_IN_FILENAME
8128 else if ((int *)varp == &p_ssl)
8129 {
8130 if (p_ssl)
8131 {
8132 psepc = '/';
8133 psepcN = '\\';
8134 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 }
8136 else
8137 {
8138 psepc = '\\';
8139 psepcN = '/';
8140 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008141 }
8142
8143 /* need to adjust the file name arguments and buffer names. */
8144 buflist_slash_adjust();
8145 alist_slash_adjust();
8146# ifdef FEAT_EVAL
8147 scriptnames_slash_adjust();
8148# endif
8149 }
8150#endif
8151
8152 /* If 'wrap' is set, set w_leftcol to zero. */
8153 else if ((int *)varp == &curwin->w_p_wrap)
8154 {
8155 if (curwin->w_p_wrap)
8156 curwin->w_leftcol = 0;
8157 }
8158
8159#ifdef FEAT_WINDOWS
8160 else if ((int *)varp == &p_ea)
8161 {
8162 if (p_ea && !old_value)
8163 win_equal(curwin, FALSE, 0);
8164 }
8165#endif
8166
8167 else if ((int *)varp == &p_wiv)
8168 {
8169 /*
8170 * When 'weirdinvert' changed, set/reset 't_xs'.
8171 * Then set 'weirdinvert' according to value of 't_xs'.
8172 */
8173 if (p_wiv && !old_value)
8174 T_XS = (char_u *)"y";
8175 else if (!p_wiv && old_value)
8176 T_XS = empty_option;
8177 p_wiv = (*T_XS != NUL);
8178 }
8179
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008180#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181 else if ((int *)varp == &p_beval)
8182 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008183 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008185 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008186 gui_mch_disable_beval_area(balloonEval);
8187 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008190#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008191 else if ((int *)varp == &p_acd)
8192 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008193 /* Change directories when the 'acd' option is set now. */
8194 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195 }
8196#endif
8197
8198#ifdef FEAT_DIFF
8199 /* 'diff' */
8200 else if ((int *)varp == &curwin->w_p_diff)
8201 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008202 /* May add or remove the buffer from the list of diff buffers. */
8203 diff_buf_adjust(curwin);
8204# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 if (foldmethodIsDiff(curwin))
8206 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008207# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008208 }
8209#endif
8210
8211#ifdef USE_IM_CONTROL
8212 /* 'imdisable' */
8213 else if ((int *)varp == &p_imdisable)
8214 {
8215 /* Only de-activate it here, it will be enabled when changing mode. */
8216 if (p_imdisable)
8217 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008218 else if (State & INSERT)
8219 /* When the option is set from an autocommand, it may need to take
8220 * effect right away. */
8221 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222 }
8223#endif
8224
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008225#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008226 /* 'spell' */
8227 else if ((int *)varp == &curwin->w_p_spell)
8228 {
8229 if (curwin->w_p_spell)
8230 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008231 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008232 if (errmsg != NULL)
8233 EMSG(_(errmsg));
8234 }
8235 }
8236#endif
8237
Bram Moolenaar071d4272004-06-13 20:20:40 +00008238#ifdef FEAT_FKMAP
8239 else if ((int *)varp == &p_altkeymap)
8240 {
8241 if (old_value != p_altkeymap)
8242 {
8243 if (!p_altkeymap)
8244 {
8245 p_hkmap = p_fkmap;
8246 p_fkmap = 0;
8247 }
8248 else
8249 {
8250 p_fkmap = p_hkmap;
8251 p_hkmap = 0;
8252 }
8253 (void)init_chartab();
8254 }
8255 }
8256
8257 /*
8258 * In case some second language keymapping options have changed, check
8259 * and correct the setting in a consistent way.
8260 */
8261
8262 /*
8263 * If hkmap or fkmap are set, reset Arabic keymapping.
8264 */
8265 if ((p_hkmap || p_fkmap) && p_altkeymap)
8266 {
8267 p_altkeymap = p_fkmap;
8268# ifdef FEAT_ARABIC
8269 curwin->w_p_arab = FALSE;
8270# endif
8271 (void)init_chartab();
8272 }
8273
8274 /*
8275 * If hkmap set, reset Farsi keymapping.
8276 */
8277 if (p_hkmap && p_altkeymap)
8278 {
8279 p_altkeymap = 0;
8280 p_fkmap = 0;
8281# ifdef FEAT_ARABIC
8282 curwin->w_p_arab = FALSE;
8283# endif
8284 (void)init_chartab();
8285 }
8286
8287 /*
8288 * If fkmap set, reset Hebrew keymapping.
8289 */
8290 if (p_fkmap && !p_altkeymap)
8291 {
8292 p_altkeymap = 1;
8293 p_hkmap = 0;
8294# ifdef FEAT_ARABIC
8295 curwin->w_p_arab = FALSE;
8296# endif
8297 (void)init_chartab();
8298 }
8299#endif
8300
8301#ifdef FEAT_ARABIC
8302 if ((int *)varp == &curwin->w_p_arab)
8303 {
8304 if (curwin->w_p_arab)
8305 {
8306 /*
8307 * 'arabic' is set, handle various sub-settings.
8308 */
8309 if (!p_tbidi)
8310 {
8311 /* set rightleft mode */
8312 if (!curwin->w_p_rl)
8313 {
8314 curwin->w_p_rl = TRUE;
8315 changed_window_setting();
8316 }
8317
8318 /* Enable Arabic shaping (major part of what Arabic requires) */
8319 if (!p_arshape)
8320 {
8321 p_arshape = TRUE;
8322 redraw_later_clear();
8323 }
8324 }
8325
8326 /* Arabic requires a utf-8 encoding, inform the user if its not
8327 * set. */
8328 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008329 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008330 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8331
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008332 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008333 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8334#ifdef FEAT_EVAL
8335 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8336#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008337 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008338
8339# ifdef FEAT_MBYTE
8340 /* set 'delcombine' */
8341 p_deco = TRUE;
8342# endif
8343
8344# ifdef FEAT_KEYMAP
8345 /* Force-set the necessary keymap for arabic */
8346 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8347 OPT_LOCAL);
8348# endif
8349# ifdef FEAT_FKMAP
8350 p_altkeymap = 0;
8351 p_hkmap = 0;
8352 p_fkmap = 0;
8353 (void)init_chartab();
8354# endif
8355 }
8356 else
8357 {
8358 /*
8359 * 'arabic' is reset, handle various sub-settings.
8360 */
8361 if (!p_tbidi)
8362 {
8363 /* reset rightleft mode */
8364 if (curwin->w_p_rl)
8365 {
8366 curwin->w_p_rl = FALSE;
8367 changed_window_setting();
8368 }
8369
8370 /* 'arabicshape' isn't reset, it is a global option and
8371 * another window may still need it "on". */
8372 }
8373
8374 /* 'delcombine' isn't reset, it is a global option and another
8375 * window may still want it "on". */
8376
8377# ifdef FEAT_KEYMAP
8378 /* Revert to the default keymap */
8379 curbuf->b_p_iminsert = B_IMODE_NONE;
8380 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8381# endif
8382 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008383 }
8384
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008385#endif
8386
Bram Moolenaar071d4272004-06-13 20:20:40 +00008387 /*
8388 * End of handling side effects for bool options.
8389 */
8390
Bram Moolenaar53744302015-07-17 17:38:22 +02008391 /* after handling side effects, call autocommand */
8392
Bram Moolenaar071d4272004-06-13 20:20:40 +00008393 options[opt_idx].flags |= P_WAS_SET;
8394
Bram Moolenaar53744302015-07-17 17:38:22 +02008395#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8396 if (!starting)
8397 {
8398 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008399 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8400 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8401 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008402 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8403 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8404 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8405 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8406 reset_v_option_vars();
8407 }
8408#endif
8409
Bram Moolenaar071d4272004-06-13 20:20:40 +00008410 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008411 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008412 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008413 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008414 check_redraw(options[opt_idx].flags);
8415
8416 return NULL;
8417}
8418
8419/*
8420 * Set the value of a number option, and take care of side effects.
8421 * Returns NULL for success, or an error message for an error.
8422 */
8423 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008424set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008425 int opt_idx; /* index in options[] table */
8426 char_u *varp; /* pointer to the option variable */
8427 long value; /* new value */
8428 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008429 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8431 OPT_MODELINE */
8432{
8433 char_u *errmsg = NULL;
8434 long old_value = *(long *)varp;
8435 long old_Rows = Rows; /* remember old Rows */
8436 long old_Columns = Columns; /* remember old Columns */
8437 long *pp = (long *)varp;
8438
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008439 /* Disallow changing some options from secure mode. */
8440 if ((secure
8441#ifdef HAVE_SANDBOX
8442 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008444 ) && (options[opt_idx].flags & P_SECURE))
8445 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008446
8447 *pp = value;
8448#ifdef FEAT_EVAL
8449 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008450 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008452#ifdef FEAT_GUI
8453 need_mouse_correct = TRUE;
8454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008455
Bram Moolenaar14f24742012-08-08 18:01:05 +02008456 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457 {
8458 errmsg = e_positive;
8459 curbuf->b_p_sw = curbuf->b_p_ts;
8460 }
8461
8462 /*
8463 * Number options that need some action when changed
8464 */
8465#ifdef FEAT_WINDOWS
8466 if (pp == &p_wh || pp == &p_hh)
8467 {
8468 if (p_wh < 1)
8469 {
8470 errmsg = e_positive;
8471 p_wh = 1;
8472 }
8473 if (p_wmh > p_wh)
8474 {
8475 errmsg = e_winheight;
8476 p_wh = p_wmh;
8477 }
8478 if (p_hh < 0)
8479 {
8480 errmsg = e_positive;
8481 p_hh = 0;
8482 }
8483
8484 /* Change window height NOW */
8485 if (lastwin != firstwin)
8486 {
8487 if (pp == &p_wh && curwin->w_height < p_wh)
8488 win_setheight((int)p_wh);
8489 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8490 win_setheight((int)p_hh);
8491 }
8492 }
8493
8494 /* 'winminheight' */
8495 else if (pp == &p_wmh)
8496 {
8497 if (p_wmh < 0)
8498 {
8499 errmsg = e_positive;
8500 p_wmh = 0;
8501 }
8502 if (p_wmh > p_wh)
8503 {
8504 errmsg = e_winheight;
8505 p_wmh = p_wh;
8506 }
8507 win_setminheight();
8508 }
8509
8510# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008511 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008512 {
8513 if (p_wiw < 1)
8514 {
8515 errmsg = e_positive;
8516 p_wiw = 1;
8517 }
8518 if (p_wmw > p_wiw)
8519 {
8520 errmsg = e_winwidth;
8521 p_wiw = p_wmw;
8522 }
8523
8524 /* Change window width NOW */
8525 if (lastwin != firstwin && curwin->w_width < p_wiw)
8526 win_setwidth((int)p_wiw);
8527 }
8528
8529 /* 'winminwidth' */
8530 else if (pp == &p_wmw)
8531 {
8532 if (p_wmw < 0)
8533 {
8534 errmsg = e_positive;
8535 p_wmw = 0;
8536 }
8537 if (p_wmw > p_wiw)
8538 {
8539 errmsg = e_winwidth;
8540 p_wmw = p_wiw;
8541 }
8542 win_setminheight();
8543 }
8544# endif
8545
8546#endif
8547
8548#ifdef FEAT_WINDOWS
8549 /* (re)set last window status line */
8550 else if (pp == &p_ls)
8551 {
8552 last_status(FALSE);
8553 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008554
8555 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008556 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008557 {
8558 shell_new_rows(); /* recompute window positions and heights */
8559 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560#endif
8561
8562#ifdef FEAT_GUI
8563 else if (pp == &p_linespace)
8564 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008565 /* Recompute gui.char_height and resize the Vim window to keep the
8566 * same number of lines. */
8567 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008568 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008569 }
8570#endif
8571
8572#ifdef FEAT_FOLDING
8573 /* 'foldlevel' */
8574 else if (pp == &curwin->w_p_fdl)
8575 {
8576 if (curwin->w_p_fdl < 0)
8577 curwin->w_p_fdl = 0;
8578 newFoldLevel();
8579 }
8580
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008581 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008582 else if (pp == &curwin->w_p_fml)
8583 {
8584 foldUpdateAll(curwin);
8585 }
8586
8587 /* 'foldnestmax' */
8588 else if (pp == &curwin->w_p_fdn)
8589 {
8590 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8591 foldUpdateAll(curwin);
8592 }
8593
8594 /* 'foldcolumn' */
8595 else if (pp == &curwin->w_p_fdc)
8596 {
8597 if (curwin->w_p_fdc < 0)
8598 {
8599 errmsg = e_positive;
8600 curwin->w_p_fdc = 0;
8601 }
8602 else if (curwin->w_p_fdc > 12)
8603 {
8604 errmsg = e_invarg;
8605 curwin->w_p_fdc = 12;
8606 }
8607 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008608#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008609
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008610#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008611 /* 'shiftwidth' or 'tabstop' */
8612 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8613 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008614# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008615 if (foldmethodIsIndent(curwin))
8616 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008617# endif
8618# ifdef FEAT_CINDENT
8619 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8620 * parse 'cinoptions'. */
8621 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8622 parse_cino(curbuf);
8623# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008625#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008626
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008627#ifdef FEAT_MBYTE
8628 /* 'maxcombine' */
8629 else if (pp == &p_mco)
8630 {
8631 if (p_mco > MAX_MCO)
8632 p_mco = MAX_MCO;
8633 else if (p_mco < 0)
8634 p_mco = 0;
8635 screenclear(); /* will re-allocate the screen */
8636 }
8637#endif
8638
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639 else if (pp == &curbuf->b_p_iminsert)
8640 {
8641 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8642 {
8643 errmsg = e_invarg;
8644 curbuf->b_p_iminsert = B_IMODE_NONE;
8645 }
8646 p_iminsert = curbuf->b_p_iminsert;
8647 if (termcap_active) /* don't do this in the alternate screen */
8648 showmode();
8649#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8650 /* Show/unshow value of 'keymap' in status lines. */
8651 status_redraw_curbuf();
8652#endif
8653 }
8654
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008655 else if (pp == &p_window)
8656 {
8657 if (p_window < 1)
8658 p_window = 1;
8659 else if (p_window >= Rows)
8660 p_window = Rows - 1;
8661 }
8662
Bram Moolenaar071d4272004-06-13 20:20:40 +00008663 else if (pp == &curbuf->b_p_imsearch)
8664 {
8665 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8666 {
8667 errmsg = e_invarg;
8668 curbuf->b_p_imsearch = B_IMODE_NONE;
8669 }
8670 p_imsearch = curbuf->b_p_imsearch;
8671 }
8672
8673#ifdef FEAT_TITLE
8674 /* if 'titlelen' has changed, redraw the title */
8675 else if (pp == &p_titlelen)
8676 {
8677 if (p_titlelen < 0)
8678 {
8679 errmsg = e_positive;
8680 p_titlelen = 85;
8681 }
8682 if (starting != NO_SCREEN && old_value != p_titlelen)
8683 need_maketitle = TRUE;
8684 }
8685#endif
8686
8687 /* if p_ch changed value, change the command line height */
8688 else if (pp == &p_ch)
8689 {
8690 if (p_ch < 1)
8691 {
8692 errmsg = e_positive;
8693 p_ch = 1;
8694 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008695 if (p_ch > Rows - min_rows() + 1)
8696 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697
8698 /* Only compute the new window layout when startup has been
8699 * completed. Otherwise the frame sizes may be wrong. */
8700 if (p_ch != old_value && full_screen
8701#ifdef FEAT_GUI
8702 && !gui.starting
8703#endif
8704 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008705 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706 }
8707
8708 /* when 'updatecount' changes from zero to non-zero, open swap files */
8709 else if (pp == &p_uc)
8710 {
8711 if (p_uc < 0)
8712 {
8713 errmsg = e_positive;
8714 p_uc = 100;
8715 }
8716 if (p_uc && !old_value)
8717 ml_open_files();
8718 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008719#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008720 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008721 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008722 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008723 {
8724 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008725 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008726 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008727 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008728 {
8729 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008730 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008731 }
8732 }
8733#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008734#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008735 else if (pp == &p_mzq)
8736 mzvim_reset_timer();
8737#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008738
8739 /* sync undo before 'undolevels' changes */
8740 else if (pp == &p_ul)
8741 {
8742 /* use the old value, otherwise u_sync() may not work properly */
8743 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008744 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008745 p_ul = value;
8746 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008747 else if (pp == &curbuf->b_p_ul)
8748 {
8749 /* use the old value, otherwise u_sync() may not work properly */
8750 curbuf->b_p_ul = old_value;
8751 u_sync(TRUE);
8752 curbuf->b_p_ul = value;
8753 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008754
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008755#ifdef FEAT_LINEBREAK
8756 /* 'numberwidth' must be positive */
8757 else if (pp == &curwin->w_p_nuw)
8758 {
8759 if (curwin->w_p_nuw < 1)
8760 {
8761 errmsg = e_positive;
8762 curwin->w_p_nuw = 1;
8763 }
8764 if (curwin->w_p_nuw > 10)
8765 {
8766 errmsg = e_invarg;
8767 curwin->w_p_nuw = 10;
8768 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008769 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008770 }
8771#endif
8772
Bram Moolenaar1a384422010-07-14 19:53:30 +02008773 else if (pp == &curbuf->b_p_tw)
8774 {
8775 if (curbuf->b_p_tw < 0)
8776 {
8777 errmsg = e_positive;
8778 curbuf->b_p_tw = 0;
8779 }
8780#ifdef FEAT_SYN_HL
8781# ifdef FEAT_WINDOWS
8782 {
8783 win_T *wp;
8784 tabpage_T *tp;
8785
8786 FOR_ALL_TAB_WINDOWS(tp, wp)
8787 check_colorcolumn(wp);
8788 }
8789# else
8790 check_colorcolumn(curwin);
8791# endif
8792#endif
8793 }
8794
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795 /*
8796 * Check the bounds for numeric options here
8797 */
8798 if (Rows < min_rows() && full_screen)
8799 {
8800 if (errbuf != NULL)
8801 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008802 vim_snprintf((char *)errbuf, errbuflen,
8803 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 errmsg = errbuf;
8805 }
8806 Rows = min_rows();
8807 }
8808 if (Columns < MIN_COLUMNS && full_screen)
8809 {
8810 if (errbuf != NULL)
8811 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008812 vim_snprintf((char *)errbuf, errbuflen,
8813 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008814 errmsg = errbuf;
8815 }
8816 Columns = MIN_COLUMNS;
8817 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008818 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008819
8820#ifdef DJGPP
8821 /* avoid a crash by checking for a too large value of 'columns' */
8822 if (old_Columns != Columns && full_screen && term_console)
8823 mch_check_columns();
8824#endif
8825
8826 /*
8827 * If the screen (shell) height has been changed, assume it is the
8828 * physical screenheight.
8829 */
8830 if (old_Rows != Rows || old_Columns != Columns)
8831 {
8832 /* Changing the screen size is not allowed while updating the screen. */
8833 if (updating_screen)
8834 *pp = old_value;
8835 else if (full_screen
8836#ifdef FEAT_GUI
8837 && !gui.starting
8838#endif
8839 )
8840 set_shellsize((int)Columns, (int)Rows, TRUE);
8841 else
8842 {
8843 /* Postpone the resizing; check the size and cmdline position for
8844 * messages. */
8845 check_shellsize();
8846 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8847 cmdline_row = Rows - p_ch;
8848 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008849 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008850 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 }
8852
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853 if (curbuf->b_p_ts <= 0)
8854 {
8855 errmsg = e_positive;
8856 curbuf->b_p_ts = 8;
8857 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858 if (p_tm < 0)
8859 {
8860 errmsg = e_positive;
8861 p_tm = 0;
8862 }
8863 if ((curwin->w_p_scr <= 0
8864 || (curwin->w_p_scr > curwin->w_height
8865 && curwin->w_height > 0))
8866 && full_screen)
8867 {
8868 if (pp == &(curwin->w_p_scr))
8869 {
8870 if (curwin->w_p_scr != 0)
8871 errmsg = e_scroll;
8872 win_comp_scroll(curwin);
8873 }
8874 /* If 'scroll' became invalid because of a side effect silently adjust
8875 * it. */
8876 else if (curwin->w_p_scr <= 0)
8877 curwin->w_p_scr = 1;
8878 else /* curwin->w_p_scr > curwin->w_height */
8879 curwin->w_p_scr = curwin->w_height;
8880 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008881 if (p_hi < 0)
8882 {
8883 errmsg = e_positive;
8884 p_hi = 0;
8885 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008886 else if (p_hi > 10000)
8887 {
8888 errmsg = e_invarg;
8889 p_hi = 10000;
8890 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008891 if (p_re < 0 || p_re > 2)
8892 {
8893 errmsg = e_invarg;
8894 p_re = 0;
8895 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008896 if (p_report < 0)
8897 {
8898 errmsg = e_positive;
8899 p_report = 1;
8900 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008901 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008902 {
8903 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8904 p_sj = Rows / 2;
8905 else
8906 {
8907 errmsg = e_scroll;
8908 p_sj = 1;
8909 }
8910 }
8911 if (p_so < 0 && full_screen)
8912 {
8913 errmsg = e_scroll;
8914 p_so = 0;
8915 }
8916 if (p_siso < 0 && full_screen)
8917 {
8918 errmsg = e_positive;
8919 p_siso = 0;
8920 }
8921#ifdef FEAT_CMDWIN
8922 if (p_cwh < 1)
8923 {
8924 errmsg = e_positive;
8925 p_cwh = 1;
8926 }
8927#endif
8928 if (p_ut < 0)
8929 {
8930 errmsg = e_positive;
8931 p_ut = 2000;
8932 }
8933 if (p_ss < 0)
8934 {
8935 errmsg = e_positive;
8936 p_ss = 0;
8937 }
8938
8939 /* May set global value for local option. */
8940 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8941 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8942
8943 options[opt_idx].flags |= P_WAS_SET;
8944
Bram Moolenaar53744302015-07-17 17:38:22 +02008945#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8946 if (!starting && errmsg == NULL)
8947 {
8948 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008949 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8950 vim_snprintf((char *)buf_new, 10, "%ld", value);
8951 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008952 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8953 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8954 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8955 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8956 reset_v_option_vars();
8957 }
8958#endif
8959
Bram Moolenaar071d4272004-06-13 20:20:40 +00008960 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008961 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008962 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008963 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008964 check_redraw(options[opt_idx].flags);
8965
8966 return errmsg;
8967}
8968
8969/*
8970 * Called after an option changed: check if something needs to be redrawn.
8971 */
8972 static void
8973check_redraw(flags)
8974 long_u flags;
8975{
8976 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008977 int doclear = (flags & P_RCLR) == P_RCLR;
8978 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008979
8980#ifdef FEAT_WINDOWS
8981 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8982 status_redraw_all();
8983#endif
8984
8985 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8986 changed_window_setting();
8987 if (flags & P_RBUF)
8988 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008989 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008990 redraw_all_later(CLEAR);
8991 else if (all)
8992 redraw_all_later(NOT_VALID);
8993}
8994
8995/*
8996 * Find index for option 'arg'.
8997 * Return -1 if not found.
8998 */
8999 static int
9000findoption(arg)
9001 char_u *arg;
9002{
9003 int opt_idx;
9004 char *s, *p;
9005 static short quick_tab[27] = {0, 0}; /* quick access table */
9006 int is_term_opt;
9007
9008 /*
9009 * For first call: Initialize the quick-access table.
9010 * It contains the index for the first option that starts with a certain
9011 * letter. There are 26 letters, plus the first "t_" option.
9012 */
9013 if (quick_tab[1] == 0)
9014 {
9015 p = options[0].fullname;
9016 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9017 {
9018 if (s[0] != p[0])
9019 {
9020 if (s[0] == 't' && s[1] == '_')
9021 quick_tab[26] = opt_idx;
9022 else
9023 quick_tab[CharOrdLow(s[0])] = opt_idx;
9024 }
9025 p = s;
9026 }
9027 }
9028
9029 /*
9030 * Check for name starting with an illegal character.
9031 */
9032#ifdef EBCDIC
9033 if (!islower(arg[0]))
9034#else
9035 if (arg[0] < 'a' || arg[0] > 'z')
9036#endif
9037 return -1;
9038
9039 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9040 if (is_term_opt)
9041 opt_idx = quick_tab[26];
9042 else
9043 opt_idx = quick_tab[CharOrdLow(arg[0])];
9044 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9045 {
9046 if (STRCMP(arg, s) == 0) /* match full name */
9047 break;
9048 }
9049 if (s == NULL && !is_term_opt)
9050 {
9051 opt_idx = quick_tab[CharOrdLow(arg[0])];
9052 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9053 {
9054 s = options[opt_idx].shortname;
9055 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9056 break;
9057 s = NULL;
9058 }
9059 }
9060 if (s == NULL)
9061 opt_idx = -1;
9062 return opt_idx;
9063}
9064
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009065#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009066/*
9067 * Get the value for an option.
9068 *
9069 * Returns:
9070 * Number or Toggle option: 1, *numval gets value.
9071 * String option: 0, *stringval gets allocated string.
9072 * Hidden Number or Toggle option: -1.
9073 * hidden String option: -2.
9074 * unknown option: -3.
9075 */
9076 int
9077get_option_value(name, numval, stringval, opt_flags)
9078 char_u *name;
9079 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02009080 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009081 int opt_flags;
9082{
9083 int opt_idx;
9084 char_u *varp;
9085
9086 opt_idx = findoption(name);
9087 if (opt_idx < 0) /* unknown option */
9088 return -3;
9089
9090 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9091
9092 if (options[opt_idx].flags & P_STRING)
9093 {
9094 if (varp == NULL) /* hidden option */
9095 return -2;
9096 if (stringval != NULL)
9097 {
9098#ifdef FEAT_CRYPT
9099 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009100 if ((char_u **)varp == &curbuf->b_p_key
9101 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009102 *stringval = vim_strsave((char_u *)"*****");
9103 else
9104#endif
9105 *stringval = vim_strsave(*(char_u **)(varp));
9106 }
9107 return 0;
9108 }
9109
9110 if (varp == NULL) /* hidden option */
9111 return -1;
9112 if (options[opt_idx].flags & P_NUM)
9113 *numval = *(long *)varp;
9114 else
9115 {
9116 /* Special case: 'modified' is b_changed, but we also want to consider
9117 * it set when 'ff' or 'fenc' changed. */
9118 if ((int *)varp == &curbuf->b_changed)
9119 *numval = curbufIsChanged();
9120 else
9121 *numval = *(int *)varp;
9122 }
9123 return 1;
9124}
9125#endif
9126
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009127#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009128/*
9129 * Returns the option attributes and its value. Unlike the above function it
9130 * will return either global value or local value of the option depending on
9131 * what was requested, but it will never return global value if it was
9132 * requested to return local one and vice versa. Neither it will return
9133 * buffer-local value if it was requested to return window-local one.
9134 *
9135 * Pretends that option is absent if it is not present in the requested scope
9136 * (i.e. has no global, window-local or buffer-local value depending on
9137 * opt_type). Uses
9138 *
9139 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009140 * 0 hidden or unknown option, also option that does not have requested
9141 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009142 * see SOPT_* in vim.h for other flags
9143 *
9144 * Possible opt_type values: see SREQ_* in vim.h
9145 */
9146 int
9147get_option_value_strict(name, numval, stringval, opt_type, from)
9148 char_u *name;
9149 long *numval;
9150 char_u **stringval; /* NULL when only obtaining attributes */
9151 int opt_type;
9152 void *from;
9153{
9154 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009155 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009156 struct vimoption *p;
9157 int r = 0;
9158
9159 opt_idx = findoption(name);
9160 if (opt_idx < 0)
9161 return 0;
9162
9163 p = &(options[opt_idx]);
9164
9165 /* Hidden option */
9166 if (p->var == NULL)
9167 return 0;
9168
9169 if (p->flags & P_BOOL)
9170 r |= SOPT_BOOL;
9171 else if (p->flags & P_NUM)
9172 r |= SOPT_NUM;
9173 else if (p->flags & P_STRING)
9174 r |= SOPT_STRING;
9175
9176 if (p->indir == PV_NONE)
9177 {
9178 if (opt_type == SREQ_GLOBAL)
9179 r |= SOPT_GLOBAL;
9180 else
9181 return 0; /* Did not request global-only option */
9182 }
9183 else
9184 {
9185 if (p->indir & PV_BOTH)
9186 r |= SOPT_GLOBAL;
9187 else if (opt_type == SREQ_GLOBAL)
9188 return 0; /* Requested global option */
9189
9190 if (p->indir & PV_WIN)
9191 {
9192 if (opt_type == SREQ_BUF)
9193 return 0; /* Did not request window-local option */
9194 else
9195 r |= SOPT_WIN;
9196 }
9197 else if (p->indir & PV_BUF)
9198 {
9199 if (opt_type == SREQ_WIN)
9200 return 0; /* Did not request buffer-local option */
9201 else
9202 r |= SOPT_BUF;
9203 }
9204 }
9205
9206 if (stringval == NULL)
9207 return r;
9208
9209 if (opt_type == SREQ_GLOBAL)
9210 varp = p->var;
9211 else
9212 {
9213 if (opt_type == SREQ_BUF)
9214 {
9215 /* Special case: 'modified' is b_changed, but we also want to
9216 * consider it set when 'ff' or 'fenc' changed. */
9217 if (p->indir == PV_MOD)
9218 {
9219 *numval = bufIsChanged((buf_T *) from);
9220 varp = NULL;
9221 }
9222#ifdef FEAT_CRYPT
9223 else if (p->indir == PV_KEY)
9224 {
9225 /* never return the value of the crypt key */
9226 *stringval = NULL;
9227 varp = NULL;
9228 }
9229#endif
9230 else
9231 {
9232 aco_save_T aco;
9233 aucmd_prepbuf(&aco, (buf_T *) from);
9234 varp = get_varp(p);
9235 aucmd_restbuf(&aco);
9236 }
9237 }
9238 else if (opt_type == SREQ_WIN)
9239 {
9240 win_T *save_curwin;
9241 save_curwin = curwin;
9242 curwin = (win_T *) from;
9243 curbuf = curwin->w_buffer;
9244 varp = get_varp(p);
9245 curwin = save_curwin;
9246 curbuf = curwin->w_buffer;
9247 }
9248 if (varp == p->var)
9249 return (r | SOPT_UNSET);
9250 }
9251
9252 if (varp != NULL)
9253 {
9254 if (p->flags & P_STRING)
9255 *stringval = vim_strsave(*(char_u **)(varp));
9256 else if (p->flags & P_NUM)
9257 *numval = *(long *) varp;
9258 else
9259 *numval = *(int *)varp;
9260 }
9261
9262 return r;
9263}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009264
9265/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009266 * Iterate over options. First argument is a pointer to a pointer to a
9267 * structure inside options[] array, second is option type like in the above
9268 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009269 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009270 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009271 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009272 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009273 * first argument to NULL.
9274 *
9275 * Returns full option name for current option on each call.
9276 */
9277 char_u *
9278option_iter_next(option, opt_type)
9279 void **option;
9280 int opt_type;
9281{
9282 struct vimoption *ret = NULL;
9283 do
9284 {
9285 if (*option == NULL)
9286 *option = (void *) options;
9287 else if (((struct vimoption *) (*option))->fullname == NULL)
9288 {
9289 *option = NULL;
9290 return NULL;
9291 }
9292 else
9293 *option = (void *) (((struct vimoption *) (*option)) + 1);
9294
9295 ret = ((struct vimoption *) (*option));
9296
9297 /* Hidden option */
9298 if (ret->var == NULL)
9299 {
9300 ret = NULL;
9301 continue;
9302 }
9303
9304 switch (opt_type)
9305 {
9306 case SREQ_GLOBAL:
9307 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9308 ret = NULL;
9309 break;
9310 case SREQ_BUF:
9311 if (!(ret->indir & PV_BUF))
9312 ret = NULL;
9313 break;
9314 case SREQ_WIN:
9315 if (!(ret->indir & PV_WIN))
9316 ret = NULL;
9317 break;
9318 default:
9319 EMSG2(_(e_intern2), "option_iter_next()");
9320 return NULL;
9321 }
9322 }
9323 while (ret == NULL);
9324
9325 return (char_u *)ret->fullname;
9326}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009327#endif
9328
Bram Moolenaar071d4272004-06-13 20:20:40 +00009329/*
9330 * Set the value of option "name".
9331 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009332 *
9333 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009334 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009335 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336set_option_value(name, number, string, opt_flags)
9337 char_u *name;
9338 long number;
9339 char_u *string;
9340 int opt_flags; /* OPT_LOCAL or 0 (both) */
9341{
9342 int opt_idx;
9343 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009344 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345
9346 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009347 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009348 EMSG2(_("E355: Unknown option: %s"), name);
9349 else
9350 {
9351 flags = options[opt_idx].flags;
9352#ifdef HAVE_SANDBOX
9353 /* Disallow changing some options in the sandbox */
9354 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009355 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009356 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009357 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009358 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009359#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009360 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009361 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362 else
9363 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009364 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009365 if (varp != NULL) /* hidden option is not changed */
9366 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009367 if (number == 0 && string != NULL)
9368 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009369 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009370
9371 /* Either we are given a string or we are setting option
9372 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009373 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009374 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009375 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009376 {
9377 /* There's another character after zeros or the string
9378 * is empty. In both cases, we are trying to set a
9379 * num option using a string. */
9380 EMSG3(_("E521: Number required: &%s = '%s'"),
9381 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009382 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009383
9384 }
9385 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009386 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009387 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009388 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009389 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009390 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009391 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009392 }
9393 }
9394 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009395 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396}
9397
9398/*
9399 * Get the terminal code for a terminal option.
9400 * Returns NULL when not found.
9401 */
9402 char_u *
9403get_term_code(tname)
9404 char_u *tname;
9405{
9406 int opt_idx;
9407 char_u *varp;
9408
9409 if (tname[0] != 't' || tname[1] != '_' ||
9410 tname[2] == NUL || tname[3] == NUL)
9411 return NULL;
9412 if ((opt_idx = findoption(tname)) >= 0)
9413 {
9414 varp = get_varp(&(options[opt_idx]));
9415 if (varp != NULL)
9416 varp = *(char_u **)(varp);
9417 return varp;
9418 }
9419 return find_termcode(tname + 2);
9420}
9421
9422 char_u *
9423get_highlight_default()
9424{
9425 int i;
9426
9427 i = findoption((char_u *)"hl");
9428 if (i >= 0)
9429 return options[i].def_val[VI_DEFAULT];
9430 return (char_u *)NULL;
9431}
9432
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009433#if defined(FEAT_MBYTE) || defined(PROTO)
9434 char_u *
9435get_encoding_default()
9436{
9437 int i;
9438
9439 i = findoption((char_u *)"enc");
9440 if (i >= 0)
9441 return options[i].def_val[VI_DEFAULT];
9442 return (char_u *)NULL;
9443}
9444#endif
9445
Bram Moolenaar071d4272004-06-13 20:20:40 +00009446/*
9447 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9448 */
9449 static int
9450find_key_option(arg)
9451 char_u *arg;
9452{
9453 int key;
9454 int modifiers;
9455
9456 /*
9457 * Don't use get_special_key_code() for t_xx, we don't want it to call
9458 * add_termcap_entry().
9459 */
9460 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9461 key = TERMCAP2KEY(arg[2], arg[3]);
9462 else
9463 {
9464 --arg; /* put arg at the '<' */
9465 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009466 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009467 if (modifiers) /* can't handle modifiers here */
9468 key = 0;
9469 }
9470 return key;
9471}
9472
9473/*
9474 * if 'all' == 0: show changed options
9475 * if 'all' == 1: show all normal options
9476 * if 'all' == 2: show all terminal options
9477 */
9478 static void
9479showoptions(all, opt_flags)
9480 int all;
9481 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9482{
9483 struct vimoption *p;
9484 int col;
9485 int isterm;
9486 char_u *varp;
9487 struct vimoption **items;
9488 int item_count;
9489 int run;
9490 int row, rows;
9491 int cols;
9492 int i;
9493 int len;
9494
9495#define INC 20
9496#define GAP 3
9497
9498 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9499 PARAM_COUNT));
9500 if (items == NULL)
9501 return;
9502
9503 /* Highlight title */
9504 if (all == 2)
9505 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9506 else if (opt_flags & OPT_GLOBAL)
9507 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9508 else if (opt_flags & OPT_LOCAL)
9509 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9510 else
9511 MSG_PUTS_TITLE(_("\n--- Options ---"));
9512
9513 /*
9514 * do the loop two times:
9515 * 1. display the short items
9516 * 2. display the long items (only strings and numbers)
9517 */
9518 for (run = 1; run <= 2 && !got_int; ++run)
9519 {
9520 /*
9521 * collect the items in items[]
9522 */
9523 item_count = 0;
9524 for (p = &options[0]; p->fullname != NULL; p++)
9525 {
9526 varp = NULL;
9527 isterm = istermoption(p);
9528 if (opt_flags != 0)
9529 {
9530 if (p->indir != PV_NONE && !isterm)
9531 varp = get_varp_scope(p, opt_flags);
9532 }
9533 else
9534 varp = get_varp(p);
9535 if (varp != NULL
9536 && ((all == 2 && isterm)
9537 || (all == 1 && !isterm)
9538 || (all == 0 && !optval_default(p, varp))))
9539 {
9540 if (p->flags & P_BOOL)
9541 len = 1; /* a toggle option fits always */
9542 else
9543 {
9544 option_value2string(p, opt_flags);
9545 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9546 }
9547 if ((len <= INC - GAP && run == 1) ||
9548 (len > INC - GAP && run == 2))
9549 items[item_count++] = p;
9550 }
9551 }
9552
9553 /*
9554 * display the items
9555 */
9556 if (run == 1)
9557 {
9558 cols = (Columns + GAP - 3) / INC;
9559 if (cols == 0)
9560 cols = 1;
9561 rows = (item_count + cols - 1) / cols;
9562 }
9563 else /* run == 2 */
9564 rows = item_count;
9565 for (row = 0; row < rows && !got_int; ++row)
9566 {
9567 msg_putchar('\n'); /* go to next line */
9568 if (got_int) /* 'q' typed in more */
9569 break;
9570 col = 0;
9571 for (i = row; i < item_count; i += rows)
9572 {
9573 msg_col = col; /* make columns */
9574 showoneopt(items[i], opt_flags);
9575 col += INC;
9576 }
9577 out_flush();
9578 ui_breakcheck();
9579 }
9580 }
9581 vim_free(items);
9582}
9583
9584/*
9585 * Return TRUE if option "p" has its default value.
9586 */
9587 static int
9588optval_default(p, varp)
9589 struct vimoption *p;
9590 char_u *varp;
9591{
9592 int dvi;
9593
9594 if (varp == NULL)
9595 return TRUE; /* hidden option is always at default */
9596 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9597 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009598 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009599 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009600 /* the cast to long is required for Manx C, long_i is
9601 * needed for MSVC */
9602 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009603 /* P_STRING */
9604 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9605}
9606
9607/*
9608 * showoneopt: show the value of one option
9609 * must not be called with a hidden option!
9610 */
9611 static void
9612showoneopt(p, opt_flags)
9613 struct vimoption *p;
9614 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9615{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009616 char_u *varp;
9617 int save_silent = silent_mode;
9618
9619 silent_mode = FALSE;
9620 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009621
9622 varp = get_varp_scope(p, opt_flags);
9623
9624 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9625 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9626 ? !curbufIsChanged() : !*(int *)varp))
9627 MSG_PUTS("no");
9628 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9629 MSG_PUTS("--");
9630 else
9631 MSG_PUTS(" ");
9632 MSG_PUTS(p->fullname);
9633 if (!(p->flags & P_BOOL))
9634 {
9635 msg_putchar('=');
9636 /* put value string in NameBuff */
9637 option_value2string(p, opt_flags);
9638 msg_outtrans(NameBuff);
9639 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009640
9641 silent_mode = save_silent;
9642 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009643}
9644
9645/*
9646 * Write modified options as ":set" commands to a file.
9647 *
9648 * There are three values for "opt_flags":
9649 * OPT_GLOBAL: Write global option values and fresh values of
9650 * buffer-local options (used for start of a session
9651 * file).
9652 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9653 * curwin (used for a vimrc file).
9654 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9655 * and local values for window-local options of
9656 * curwin. Local values are also written when at the
9657 * default value, because a modeline or autocommand
9658 * may have set them when doing ":edit file" and the
9659 * user has set them back at the default or fresh
9660 * value.
9661 * When "local_only" is TRUE, don't write fresh
9662 * values, only local values (for ":mkview").
9663 * (fresh value = value used for a new buffer or window for a local option).
9664 *
9665 * Return FAIL on error, OK otherwise.
9666 */
9667 int
9668makeset(fd, opt_flags, local_only)
9669 FILE *fd;
9670 int opt_flags;
9671 int local_only;
9672{
9673 struct vimoption *p;
9674 char_u *varp; /* currently used value */
9675 char_u *varp_fresh; /* local value */
9676 char_u *varp_local = NULL; /* fresh value */
9677 char *cmd;
9678 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009679 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009680
9681 /*
9682 * The options that don't have a default (terminal name, columns, lines)
9683 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009684 * Do the loop over "options[]" twice: once for options with the
9685 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009686 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009687 for (pri = 1; pri >= 0; --pri)
9688 {
9689 for (p = &options[0]; !istermoption(p); p++)
9690 if (!(p->flags & P_NO_MKRC)
9691 && !istermoption(p)
9692 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009693 {
9694 /* skip global option when only doing locals */
9695 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9696 continue;
9697
9698 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9699 * file, they are always buffer-specific. */
9700 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9701 continue;
9702
9703 /* Global values are only written when not at the default value. */
9704 varp = get_varp_scope(p, opt_flags);
9705 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9706 continue;
9707
9708 round = 2;
9709 if (p->indir != PV_NONE)
9710 {
9711 if (p->var == VAR_WIN)
9712 {
9713 /* skip window-local option when only doing globals */
9714 if (!(opt_flags & OPT_LOCAL))
9715 continue;
9716 /* When fresh value of window-local option is not at the
9717 * default, need to write it too. */
9718 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9719 {
9720 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9721 if (!optval_default(p, varp_fresh))
9722 {
9723 round = 1;
9724 varp_local = varp;
9725 varp = varp_fresh;
9726 }
9727 }
9728 }
9729 }
9730
9731 /* Round 1: fresh value for window-local options.
9732 * Round 2: other values */
9733 for ( ; round <= 2; varp = varp_local, ++round)
9734 {
9735 if (round == 1 || (opt_flags & OPT_GLOBAL))
9736 cmd = "set";
9737 else
9738 cmd = "setlocal";
9739
9740 if (p->flags & P_BOOL)
9741 {
9742 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9743 return FAIL;
9744 }
9745 else if (p->flags & P_NUM)
9746 {
9747 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9748 return FAIL;
9749 }
9750 else /* P_STRING */
9751 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009752#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9753 int do_endif = FALSE;
9754
Bram Moolenaar071d4272004-06-13 20:20:40 +00009755 /* Don't set 'syntax' and 'filetype' again if the value is
9756 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009757 if (
9758# if defined(FEAT_SYN_HL)
9759 p->indir == PV_SYN
9760# if defined(FEAT_AUTOCMD)
9761 ||
9762# endif
9763# endif
9764# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009765 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009766# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009767 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009768 {
9769 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9770 *(char_u **)(varp)) < 0
9771 || put_eol(fd) < 0)
9772 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009773 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009774 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009775#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009776 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9777 (p->flags & P_EXPAND) != 0) == FAIL)
9778 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009779#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9780 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009781 {
9782 if (put_line(fd, "endif") == FAIL)
9783 return FAIL;
9784 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009785#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009786 }
9787 }
9788 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009789 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790 return OK;
9791}
9792
9793#if defined(FEAT_FOLDING) || defined(PROTO)
9794/*
9795 * Generate set commands for the local fold options only. Used when
9796 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9797 */
9798 int
9799makefoldset(fd)
9800 FILE *fd;
9801{
9802 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9803# ifdef FEAT_EVAL
9804 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9805 == FAIL
9806# endif
9807 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9808 == FAIL
9809 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9810 == FAIL
9811 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9812 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9813 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9814 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9815 )
9816 return FAIL;
9817
9818 return OK;
9819}
9820#endif
9821
9822 static int
9823put_setstring(fd, cmd, name, valuep, expand)
9824 FILE *fd;
9825 char *cmd;
9826 char *name;
9827 char_u **valuep;
9828 int expand;
9829{
9830 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009831 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009832
9833 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9834 return FAIL;
9835 if (*valuep != NULL)
9836 {
9837 /* Output 'pastetoggle' as key names. For other
9838 * options some characters have to be escaped with
9839 * CTRL-V or backslash */
9840 if (valuep == &p_pt)
9841 {
9842 s = *valuep;
9843 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009844 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009845 return FAIL;
9846 }
9847 else if (expand)
9848 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009849 buf = alloc(MAXPATHL);
9850 if (buf == NULL)
9851 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009852 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9853 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009854 {
9855 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009856 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009857 }
9858 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009859 }
9860 else if (put_escstr(fd, *valuep, 2) == FAIL)
9861 return FAIL;
9862 }
9863 if (put_eol(fd) < 0)
9864 return FAIL;
9865 return OK;
9866}
9867
9868 static int
9869put_setnum(fd, cmd, name, valuep)
9870 FILE *fd;
9871 char *cmd;
9872 char *name;
9873 long *valuep;
9874{
9875 long wc;
9876
9877 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9878 return FAIL;
9879 if (wc_use_keyname((char_u *)valuep, &wc))
9880 {
9881 /* print 'wildchar' and 'wildcharm' as a key name */
9882 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9883 return FAIL;
9884 }
9885 else if (fprintf(fd, "%ld", *valuep) < 0)
9886 return FAIL;
9887 if (put_eol(fd) < 0)
9888 return FAIL;
9889 return OK;
9890}
9891
9892 static int
9893put_setbool(fd, cmd, name, value)
9894 FILE *fd;
9895 char *cmd;
9896 char *name;
9897 int value;
9898{
Bram Moolenaar893de922007-10-02 18:40:57 +00009899 if (value < 0) /* global/local option using global value */
9900 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009901 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9902 || put_eol(fd) < 0)
9903 return FAIL;
9904 return OK;
9905}
9906
9907/*
9908 * Clear all the terminal options.
9909 * If the option has been allocated, free the memory.
9910 * Terminal options are never hidden or indirect.
9911 */
9912 void
9913clear_termoptions()
9914{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915 /*
9916 * Reset a few things before clearing the old options. This may cause
9917 * outputting a few things that the terminal doesn't understand, but the
9918 * screen will be cleared later, so this is OK.
9919 */
9920#ifdef FEAT_MOUSE_TTY
9921 mch_setmouse(FALSE); /* switch mouse off */
9922#endif
9923#ifdef FEAT_TITLE
9924 mch_restore_title(3); /* restore window titles */
9925#endif
9926#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9927 /* When starting the GUI close the display opened for the clipboard.
9928 * After restoring the title, because that will need the display. */
9929 if (gui.starting)
9930 clear_xterm_clip();
9931#endif
9932#ifdef WIN3264
9933 /*
9934 * Check if this is allowed now.
9935 */
9936 if (can_end_termcap_mode(FALSE) == TRUE)
9937#endif
9938 stoptermcap(); /* stop termcap mode */
9939
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009940 free_termoptions();
9941}
9942
9943 void
9944free_termoptions()
9945{
9946 struct vimoption *p;
9947
Bram Moolenaar071d4272004-06-13 20:20:40 +00009948 for (p = &options[0]; p->fullname != NULL; p++)
9949 if (istermoption(p))
9950 {
9951 if (p->flags & P_ALLOCED)
9952 free_string_option(*(char_u **)(p->var));
9953 if (p->flags & P_DEF_ALLOCED)
9954 free_string_option(p->def_val[VI_DEFAULT]);
9955 *(char_u **)(p->var) = empty_option;
9956 p->def_val[VI_DEFAULT] = empty_option;
9957 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9958 }
9959 clear_termcodes();
9960}
9961
9962/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009963 * Free the string for one term option, if it was allocated.
9964 * Set the string to empty_option and clear allocated flag.
9965 * "var" points to the option value.
9966 */
9967 void
9968free_one_termoption(var)
9969 char_u *var;
9970{
9971 struct vimoption *p;
9972
9973 for (p = &options[0]; p->fullname != NULL; p++)
9974 if (p->var == var)
9975 {
9976 if (p->flags & P_ALLOCED)
9977 free_string_option(*(char_u **)(p->var));
9978 *(char_u **)(p->var) = empty_option;
9979 p->flags &= ~P_ALLOCED;
9980 break;
9981 }
9982}
9983
9984/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009985 * Set the terminal option defaults to the current value.
9986 * Used after setting the terminal name.
9987 */
9988 void
9989set_term_defaults()
9990{
9991 struct vimoption *p;
9992
9993 for (p = &options[0]; p->fullname != NULL; p++)
9994 {
9995 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9996 {
9997 if (p->flags & P_DEF_ALLOCED)
9998 {
9999 free_string_option(p->def_val[VI_DEFAULT]);
10000 p->flags &= ~P_DEF_ALLOCED;
10001 }
10002 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10003 if (p->flags & P_ALLOCED)
10004 {
10005 p->flags |= P_DEF_ALLOCED;
10006 p->flags &= ~P_ALLOCED; /* don't free the value now */
10007 }
10008 }
10009 }
10010}
10011
10012/*
10013 * return TRUE if 'p' starts with 't_'
10014 */
10015 static int
10016istermoption(p)
10017 struct vimoption *p;
10018{
10019 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10020}
10021
10022/*
10023 * Compute columns for ruler and shown command. 'sc_col' is also used to
10024 * decide what the maximum length of a message on the status line can be.
10025 * If there is a status line for the last window, 'sc_col' is independent
10026 * of 'ru_col'.
10027 */
10028
10029#define COL_RULER 17 /* columns needed by standard ruler */
10030
10031 void
10032comp_col()
10033{
10034#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10035 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10036
10037 sc_col = 0;
10038 ru_col = 0;
10039 if (p_ru)
10040 {
10041#ifdef FEAT_STL_OPT
10042 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10043#else
10044 ru_col = COL_RULER + 1;
10045#endif
10046 /* no last status line, adjust sc_col */
10047 if (!last_has_status)
10048 sc_col = ru_col;
10049 }
10050 if (p_sc)
10051 {
10052 sc_col += SHOWCMD_COLS;
10053 if (!p_ru || last_has_status) /* no need for separating space */
10054 ++sc_col;
10055 }
10056 sc_col = Columns - sc_col;
10057 ru_col = Columns - ru_col;
10058 if (sc_col <= 0) /* screen too narrow, will become a mess */
10059 sc_col = 1;
10060 if (ru_col <= 0)
10061 ru_col = 1;
10062#else
10063 sc_col = Columns;
10064 ru_col = Columns;
10065#endif
10066}
10067
10068/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010069 * Unset local option value, similar to ":set opt<".
10070 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010071 void
10072unset_global_local_option(name, from)
10073 char_u *name;
10074 void *from;
10075{
10076 struct vimoption *p;
10077 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010078 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010079
10080 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010081 if (opt_idx < 0)
10082 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010083 p = &(options[opt_idx]);
10084
10085 switch ((int)p->indir)
10086 {
10087 /* global option with local value: use local value if it's been set */
10088 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010089 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010090 break;
10091 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010092 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010093 break;
10094 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010095 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010096 break;
10097 case PV_AR:
10098 buf->b_p_ar = -1;
10099 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010100 case PV_BKC:
10101 clear_string_option(&buf->b_p_bkc);
10102 buf->b_bkc_flags = 0;
10103 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010104 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010105 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010106 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010107 case PV_TC:
10108 clear_string_option(&buf->b_p_tc);
10109 buf->b_tc_flags = 0;
10110 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010111#ifdef FEAT_FIND_ID
10112 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010113 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010114 break;
10115 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010116 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010117 break;
10118#endif
10119#ifdef FEAT_INS_EXPAND
10120 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010121 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010122 break;
10123 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010124 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010125 break;
10126#endif
10127#ifdef FEAT_QUICKFIX
10128 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010129 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010130 break;
10131 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010132 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010133 break;
10134 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010135 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010136 break;
10137#endif
10138#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10139 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010140 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010141 break;
10142#endif
10143#if defined(FEAT_CRYPT)
10144 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010145 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010146 break;
10147#endif
10148#ifdef FEAT_STL_OPT
10149 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010150 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010151 break;
10152#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010153 case PV_UL:
10154 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10155 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010156#ifdef FEAT_LISP
10157 case PV_LW:
10158 clear_string_option(&buf->b_p_lw);
10159 break;
10160#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010161 }
10162}
10163
10164/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010165 * Get pointer to option variable, depending on local or global scope.
10166 */
10167 static char_u *
10168get_varp_scope(p, opt_flags)
10169 struct vimoption *p;
10170 int opt_flags;
10171{
10172 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10173 {
10174 if (p->var == VAR_WIN)
10175 return (char_u *)GLOBAL_WO(get_varp(p));
10176 return p->var;
10177 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010178 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179 {
10180 switch ((int)p->indir)
10181 {
10182#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010183 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10184 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10185 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010187 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10188 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10189 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010190 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010191 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010192 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010194 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10195 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196#endif
10197#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010198 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10199 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010201#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10202 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10203#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010204#if defined(FEAT_CRYPT)
10205 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10206#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010207#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010208 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010209#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010210 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010211#ifdef FEAT_LISP
10212 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10213#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010214 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215 }
10216 return NULL; /* "cannot happen" */
10217 }
10218 return get_varp(p);
10219}
10220
10221/*
10222 * Get pointer to option variable.
10223 */
10224 static char_u *
10225get_varp(p)
10226 struct vimoption *p;
10227{
10228 /* hidden option, always return NULL */
10229 if (p->var == NULL)
10230 return NULL;
10231
10232 switch ((int)p->indir)
10233 {
10234 case PV_NONE: return p->var;
10235
10236 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010237 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010238 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010239 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010240 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010241 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010242 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010243 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010244 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010245 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010247 case PV_TC: return *curbuf->b_p_tc != NUL
10248 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010249 case PV_BKC: return *curbuf->b_p_bkc != NUL
10250 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010251#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010252 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010254 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10256#endif
10257#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010258 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010260 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10262#endif
10263#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010264 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010265 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010266 case PV_GP: return *curbuf->b_p_gp != NUL
10267 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10268 case PV_MP: return *curbuf->b_p_mp != NUL
10269 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010271#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10272 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10273 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10274#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010275#if defined(FEAT_CRYPT)
10276 case PV_CM: return *curbuf->b_p_cm != NUL
10277 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10278#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010279#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010280 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010281 ? (char_u *)&(curwin->w_p_stl) : p->var;
10282#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010283 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10284 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010285#ifdef FEAT_LISP
10286 case PV_LW: return *curbuf->b_p_lw != NUL
10287 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10288#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010289
10290#ifdef FEAT_ARABIC
10291 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10292#endif
10293 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010294#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010295 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10296#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010297#ifdef FEAT_SYN_HL
10298 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10299 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010300 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010301#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302#ifdef FEAT_DIFF
10303 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10304#endif
10305#ifdef FEAT_FOLDING
10306 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10307 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10308 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10309 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10310 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10311 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10312 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10313# ifdef FEAT_EVAL
10314 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10315 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10316# endif
10317 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10318#endif
10319 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010320 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010321#ifdef FEAT_LINEBREAK
10322 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10323#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010324#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010325 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10326#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010327#ifdef FEAT_VERTSPLIT
10328 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10331 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10332#endif
10333#ifdef FEAT_RIGHTLEFT
10334 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10335 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10336#endif
10337 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10338 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10339#ifdef FEAT_LINEBREAK
10340 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010341 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10342 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010343#endif
10344#ifdef FEAT_SCROLLBIND
10345 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10346#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010347#ifdef FEAT_CURSORBIND
10348 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10349#endif
10350#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010351 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10352 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010354
10355 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10356 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10357#ifdef FEAT_MBYTE
10358 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10359#endif
10360#if defined(FEAT_QUICKFIX)
10361 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10362 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10363#endif
10364 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10365 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10366#ifdef FEAT_CINDENT
10367 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10368 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10369 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10370#endif
10371#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10372 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10373#endif
10374#ifdef FEAT_COMMENTS
10375 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10376#endif
10377#ifdef FEAT_FOLDING
10378 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10379#endif
10380#ifdef FEAT_INS_EXPAND
10381 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10382#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010383#ifdef FEAT_COMPL_FUNC
10384 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010385 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010387 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010388 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010389 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10390#ifdef FEAT_MBYTE
10391 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10392#endif
10393 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10394#ifdef FEAT_AUTOCMD
10395 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10396#endif
10397 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010398 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10400 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10401 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10402 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10403#ifdef FEAT_FIND_ID
10404# ifdef FEAT_EVAL
10405 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10406# endif
10407#endif
10408#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10409 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10410 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10411#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010412#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010413 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10414#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415#ifdef FEAT_CRYPT
10416 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10417#endif
10418#ifdef FEAT_LISP
10419 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10420#endif
10421 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10422 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10423 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10424 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10425 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010427#ifdef FEAT_TEXTOBJ
10428 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010430 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10431#ifdef FEAT_SMARTINDENT
10432 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10433#endif
10434#ifndef SHORT_FNAME
10435 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10436#endif
10437 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10438#ifdef FEAT_SEARCHPATH
10439 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10440#endif
10441 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10442#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010443 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010444 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10445#endif
10446#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010447 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10448 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10449 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010450#endif
10451 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10452 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10453 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10454 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010455#ifdef FEAT_PERSISTENT_UNDO
10456 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10457#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010458 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10459#ifdef FEAT_KEYMAP
10460 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10461#endif
10462 default: EMSG(_("E356: get_varp ERROR"));
10463 }
10464 /* always return a valid pointer to avoid a crash! */
10465 return (char_u *)&(curbuf->b_p_wm);
10466}
10467
10468/*
10469 * Get the value of 'equalprg', either the buffer-local one or the global one.
10470 */
10471 char_u *
10472get_equalprg()
10473{
10474 if (*curbuf->b_p_ep == NUL)
10475 return p_ep;
10476 return curbuf->b_p_ep;
10477}
10478
10479#if defined(FEAT_WINDOWS) || defined(PROTO)
10480/*
10481 * Copy options from one window to another.
10482 * Used when splitting a window.
10483 */
10484 void
10485win_copy_options(wp_from, wp_to)
10486 win_T *wp_from;
10487 win_T *wp_to;
10488{
10489 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10490 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10491# ifdef FEAT_RIGHTLEFT
10492# ifdef FEAT_FKMAP
10493 /* Is this right? */
10494 wp_to->w_farsi = wp_from->w_farsi;
10495# endif
10496# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010497#if defined(FEAT_LINEBREAK)
10498 briopt_check(wp_to);
10499#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500}
10501#endif
10502
10503/*
10504 * Copy the options from one winopt_T to another.
10505 * Doesn't free the old option values in "to", use clear_winopt() for that.
10506 * The 'scroll' option is not copied, because it depends on the window height.
10507 * The 'previewwindow' option is reset, there can be only one preview window.
10508 */
10509 void
10510copy_winopt(from, to)
10511 winopt_T *from;
10512 winopt_T *to;
10513{
10514#ifdef FEAT_ARABIC
10515 to->wo_arab = from->wo_arab;
10516#endif
10517 to->wo_list = from->wo_list;
10518 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010519 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010520#ifdef FEAT_LINEBREAK
10521 to->wo_nuw = from->wo_nuw;
10522#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523#ifdef FEAT_RIGHTLEFT
10524 to->wo_rl = from->wo_rl;
10525 to->wo_rlc = vim_strsave(from->wo_rlc);
10526#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010527#ifdef FEAT_STL_OPT
10528 to->wo_stl = vim_strsave(from->wo_stl);
10529#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010531#ifdef FEAT_DIFF
10532 to->wo_wrap_save = from->wo_wrap_save;
10533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534#ifdef FEAT_LINEBREAK
10535 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010536 to->wo_bri = from->wo_bri;
10537 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538#endif
10539#ifdef FEAT_SCROLLBIND
10540 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010541 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010543#ifdef FEAT_CURSORBIND
10544 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010545 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010546#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010547#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010548 to->wo_spell = from->wo_spell;
10549#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010550#ifdef FEAT_SYN_HL
10551 to->wo_cuc = from->wo_cuc;
10552 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010553 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010554#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555#ifdef FEAT_DIFF
10556 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010557 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010558#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010559#ifdef FEAT_CONCEAL
10560 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010561 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010562#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563#ifdef FEAT_FOLDING
10564 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010565 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010567 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 to->wo_fdi = vim_strsave(from->wo_fdi);
10569 to->wo_fml = from->wo_fml;
10570 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010571 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010573 to->wo_fdm_save = from->wo_diff_saved
10574 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575 to->wo_fdn = from->wo_fdn;
10576# ifdef FEAT_EVAL
10577 to->wo_fde = vim_strsave(from->wo_fde);
10578 to->wo_fdt = vim_strsave(from->wo_fdt);
10579# endif
10580 to->wo_fmr = vim_strsave(from->wo_fmr);
10581#endif
10582 check_winopt(to); /* don't want NULL pointers */
10583}
10584
10585/*
10586 * Check string options in a window for a NULL value.
10587 */
10588 void
10589check_win_options(win)
10590 win_T *win;
10591{
10592 check_winopt(&win->w_onebuf_opt);
10593 check_winopt(&win->w_allbuf_opt);
10594}
10595
10596/*
10597 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10598 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010599 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010601 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602{
10603#ifdef FEAT_FOLDING
10604 check_string_option(&wop->wo_fdi);
10605 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010606 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010607# ifdef FEAT_EVAL
10608 check_string_option(&wop->wo_fde);
10609 check_string_option(&wop->wo_fdt);
10610# endif
10611 check_string_option(&wop->wo_fmr);
10612#endif
10613#ifdef FEAT_RIGHTLEFT
10614 check_string_option(&wop->wo_rlc);
10615#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010616#ifdef FEAT_STL_OPT
10617 check_string_option(&wop->wo_stl);
10618#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010619#ifdef FEAT_SYN_HL
10620 check_string_option(&wop->wo_cc);
10621#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010622#ifdef FEAT_CONCEAL
10623 check_string_option(&wop->wo_cocu);
10624#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010625#ifdef FEAT_LINEBREAK
10626 check_string_option(&wop->wo_briopt);
10627#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628}
10629
10630/*
10631 * Free the allocated memory inside a winopt_T.
10632 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010633 void
10634clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010635 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636{
10637#ifdef FEAT_FOLDING
10638 clear_string_option(&wop->wo_fdi);
10639 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010640 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010641# ifdef FEAT_EVAL
10642 clear_string_option(&wop->wo_fde);
10643 clear_string_option(&wop->wo_fdt);
10644# endif
10645 clear_string_option(&wop->wo_fmr);
10646#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010647#ifdef FEAT_LINEBREAK
10648 clear_string_option(&wop->wo_briopt);
10649#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010650#ifdef FEAT_RIGHTLEFT
10651 clear_string_option(&wop->wo_rlc);
10652#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010653#ifdef FEAT_STL_OPT
10654 clear_string_option(&wop->wo_stl);
10655#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010656#ifdef FEAT_SYN_HL
10657 clear_string_option(&wop->wo_cc);
10658#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010659#ifdef FEAT_CONCEAL
10660 clear_string_option(&wop->wo_cocu);
10661#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010662}
10663
10664/*
10665 * Copy global option values to local options for one buffer.
10666 * Used when creating a new buffer and sometimes when entering a buffer.
10667 * flags:
10668 * BCO_ENTER We will enter the buf buffer.
10669 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10670 * appropriate.
10671 * BCO_NOHELP Don't copy the values to a help buffer.
10672 */
10673 void
10674buf_copy_options(buf, flags)
10675 buf_T *buf;
10676 int flags;
10677{
10678 int should_copy = TRUE;
10679 char_u *save_p_isk = NULL; /* init for GCC */
10680 int dont_do_help;
10681 int did_isk = FALSE;
10682
10683 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010684 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010685 */
10686 if (buf == NULL || !buf_valid(buf))
10687 return;
10688
10689 /*
10690 * Skip this when the option defaults have not been set yet. Happens when
10691 * main() allocates the first buffer.
10692 */
10693 if (p_cpo != NULL)
10694 {
10695 /*
10696 * Always copy when entering and 'cpo' contains 'S'.
10697 * Don't copy when already initialized.
10698 * Don't copy when 'cpo' contains 's' and not entering.
10699 * 'S' BCO_ENTER initialized 's' should_copy
10700 * yes yes X X TRUE
10701 * yes no yes X FALSE
10702 * no X yes X FALSE
10703 * X no no yes FALSE
10704 * X no no no TRUE
10705 * no yes no X TRUE
10706 */
10707 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10708 && (buf->b_p_initialized
10709 || (!(flags & BCO_ENTER)
10710 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10711 should_copy = FALSE;
10712
10713 if (should_copy || (flags & BCO_ALWAYS))
10714 {
10715 /* Don't copy the options specific to a help buffer when
10716 * BCO_NOHELP is given or the options were initialized already
10717 * (jumping back to a help file with CTRL-T or CTRL-O) */
10718 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10719 || buf->b_p_initialized;
10720 if (dont_do_help) /* don't free b_p_isk */
10721 {
10722 save_p_isk = buf->b_p_isk;
10723 buf->b_p_isk = NULL;
10724 }
10725 /*
10726 * Always free the allocated strings.
10727 * If not already initialized, set 'readonly' and copy 'fileformat'.
10728 */
10729 if (!buf->b_p_initialized)
10730 {
10731 free_buf_options(buf, TRUE);
10732 buf->b_p_ro = FALSE; /* don't copy readonly */
10733 buf->b_p_tx = p_tx;
10734#ifdef FEAT_MBYTE
10735 buf->b_p_fenc = vim_strsave(p_fenc);
10736#endif
10737 buf->b_p_ff = vim_strsave(p_ff);
10738#if defined(FEAT_QUICKFIX)
10739 buf->b_p_bh = empty_option;
10740 buf->b_p_bt = empty_option;
10741#endif
10742 }
10743 else
10744 free_buf_options(buf, FALSE);
10745
10746 buf->b_p_ai = p_ai;
10747 buf->b_p_ai_nopaste = p_ai_nopaste;
10748 buf->b_p_sw = p_sw;
10749 buf->b_p_tw = p_tw;
10750 buf->b_p_tw_nopaste = p_tw_nopaste;
10751 buf->b_p_tw_nobin = p_tw_nobin;
10752 buf->b_p_wm = p_wm;
10753 buf->b_p_wm_nopaste = p_wm_nopaste;
10754 buf->b_p_wm_nobin = p_wm_nobin;
10755 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010756#ifdef FEAT_MBYTE
10757 buf->b_p_bomb = p_bomb;
10758#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010759 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010760 buf->b_p_et = p_et;
10761 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010762 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010763 buf->b_p_ml = p_ml;
10764 buf->b_p_ml_nobin = p_ml_nobin;
10765 buf->b_p_inf = p_inf;
10766 buf->b_p_swf = p_swf;
10767#ifdef FEAT_INS_EXPAND
10768 buf->b_p_cpt = vim_strsave(p_cpt);
10769#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010770#ifdef FEAT_COMPL_FUNC
10771 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010772 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010773#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 buf->b_p_sts = p_sts;
10775 buf->b_p_sts_nopaste = p_sts_nopaste;
10776#ifndef SHORT_FNAME
10777 buf->b_p_sn = p_sn;
10778#endif
10779#ifdef FEAT_COMMENTS
10780 buf->b_p_com = vim_strsave(p_com);
10781#endif
10782#ifdef FEAT_FOLDING
10783 buf->b_p_cms = vim_strsave(p_cms);
10784#endif
10785 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010786 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010787 buf->b_p_nf = vim_strsave(p_nf);
10788 buf->b_p_mps = vim_strsave(p_mps);
10789#ifdef FEAT_SMARTINDENT
10790 buf->b_p_si = p_si;
10791#endif
10792 buf->b_p_ci = p_ci;
10793#ifdef FEAT_CINDENT
10794 buf->b_p_cin = p_cin;
10795 buf->b_p_cink = vim_strsave(p_cink);
10796 buf->b_p_cino = vim_strsave(p_cino);
10797#endif
10798#ifdef FEAT_AUTOCMD
10799 /* Don't copy 'filetype', it must be detected */
10800 buf->b_p_ft = empty_option;
10801#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010802 buf->b_p_pi = p_pi;
10803#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10804 buf->b_p_cinw = vim_strsave(p_cinw);
10805#endif
10806#ifdef FEAT_LISP
10807 buf->b_p_lisp = p_lisp;
10808#endif
10809#ifdef FEAT_SYN_HL
10810 /* Don't copy 'syntax', it must be set */
10811 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010812 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010813#endif
10814#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010815 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010816 (void)compile_cap_prog(&buf->b_s);
10817 buf->b_s.b_p_spf = vim_strsave(p_spf);
10818 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819#endif
10820#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10821 buf->b_p_inde = vim_strsave(p_inde);
10822 buf->b_p_indk = vim_strsave(p_indk);
10823#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010824#if defined(FEAT_EVAL)
10825 buf->b_p_fex = vim_strsave(p_fex);
10826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827#ifdef FEAT_CRYPT
10828 buf->b_p_key = vim_strsave(p_key);
10829#endif
10830#ifdef FEAT_SEARCHPATH
10831 buf->b_p_sua = vim_strsave(p_sua);
10832#endif
10833#ifdef FEAT_KEYMAP
10834 buf->b_p_keymap = vim_strsave(p_keymap);
10835 buf->b_kmap_state |= KEYMAP_INIT;
10836#endif
10837 /* This isn't really an option, but copying the langmap and IME
10838 * state from the current buffer is better than resetting it. */
10839 buf->b_p_iminsert = p_iminsert;
10840 buf->b_p_imsearch = p_imsearch;
10841
10842 /* options that are normally global but also have a local value
10843 * are not copied, start using the global value */
10844 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010845 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010846 buf->b_p_bkc = empty_option;
10847 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848#ifdef FEAT_QUICKFIX
10849 buf->b_p_gp = empty_option;
10850 buf->b_p_mp = empty_option;
10851 buf->b_p_efm = empty_option;
10852#endif
10853 buf->b_p_ep = empty_option;
10854 buf->b_p_kp = empty_option;
10855 buf->b_p_path = empty_option;
10856 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010857 buf->b_p_tc = empty_option;
10858 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010859#ifdef FEAT_FIND_ID
10860 buf->b_p_def = empty_option;
10861 buf->b_p_inc = empty_option;
10862# ifdef FEAT_EVAL
10863 buf->b_p_inex = vim_strsave(p_inex);
10864# endif
10865#endif
10866#ifdef FEAT_INS_EXPAND
10867 buf->b_p_dict = empty_option;
10868 buf->b_p_tsr = empty_option;
10869#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010870#ifdef FEAT_TEXTOBJ
10871 buf->b_p_qe = vim_strsave(p_qe);
10872#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010873#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10874 buf->b_p_bexpr = empty_option;
10875#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010876#if defined(FEAT_CRYPT)
10877 buf->b_p_cm = empty_option;
10878#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010879#ifdef FEAT_PERSISTENT_UNDO
10880 buf->b_p_udf = p_udf;
10881#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010882#ifdef FEAT_LISP
10883 buf->b_p_lw = empty_option;
10884#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010885
10886 /*
10887 * Don't copy the options set by ex_help(), use the saved values,
10888 * when going from a help buffer to a non-help buffer.
10889 * Don't touch these at all when BCO_NOHELP is used and going from
10890 * or to a help buffer.
10891 */
10892 if (dont_do_help)
10893 buf->b_p_isk = save_p_isk;
10894 else
10895 {
10896 buf->b_p_isk = vim_strsave(p_isk);
10897 did_isk = TRUE;
10898 buf->b_p_ts = p_ts;
10899 buf->b_help = FALSE;
10900#ifdef FEAT_QUICKFIX
10901 if (buf->b_p_bt[0] == 'h')
10902 clear_string_option(&buf->b_p_bt);
10903#endif
10904 buf->b_p_ma = p_ma;
10905 }
10906 }
10907
10908 /*
10909 * When the options should be copied (ignoring BCO_ALWAYS), set the
10910 * flag that indicates that the options have been initialized.
10911 */
10912 if (should_copy)
10913 buf->b_p_initialized = TRUE;
10914 }
10915
10916 check_buf_options(buf); /* make sure we don't have NULLs */
10917 if (did_isk)
10918 (void)buf_init_chartab(buf, FALSE);
10919}
10920
10921/*
10922 * Reset the 'modifiable' option and its default value.
10923 */
10924 void
10925reset_modifiable()
10926{
10927 int opt_idx;
10928
10929 curbuf->b_p_ma = FALSE;
10930 p_ma = FALSE;
10931 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010932 if (opt_idx >= 0)
10933 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010934}
10935
10936/*
10937 * Set the global value for 'iminsert' to the local value.
10938 */
10939 void
10940set_iminsert_global()
10941{
10942 p_iminsert = curbuf->b_p_iminsert;
10943}
10944
10945/*
10946 * Set the global value for 'imsearch' to the local value.
10947 */
10948 void
10949set_imsearch_global()
10950{
10951 p_imsearch = curbuf->b_p_imsearch;
10952}
10953
10954#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10955static int expand_option_idx = -1;
10956static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10957static int expand_option_flags = 0;
10958
10959 void
10960set_context_in_set_cmd(xp, arg, opt_flags)
10961 expand_T *xp;
10962 char_u *arg;
10963 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10964{
10965 int nextchar;
10966 long_u flags = 0; /* init for GCC */
10967 int opt_idx = 0; /* init for GCC */
10968 char_u *p;
10969 char_u *s;
10970 int is_term_option = FALSE;
10971 int key;
10972
10973 expand_option_flags = opt_flags;
10974
10975 xp->xp_context = EXPAND_SETTINGS;
10976 if (*arg == NUL)
10977 {
10978 xp->xp_pattern = arg;
10979 return;
10980 }
10981 p = arg + STRLEN(arg) - 1;
10982 if (*p == ' ' && *(p - 1) != '\\')
10983 {
10984 xp->xp_pattern = p + 1;
10985 return;
10986 }
10987 while (p > arg)
10988 {
10989 s = p;
10990 /* count number of backslashes before ' ' or ',' */
10991 if (*p == ' ' || *p == ',')
10992 {
10993 while (s > arg && *(s - 1) == '\\')
10994 --s;
10995 }
10996 /* break at a space with an even number of backslashes */
10997 if (*p == ' ' && ((p - s) & 1) == 0)
10998 {
10999 ++p;
11000 break;
11001 }
11002 --p;
11003 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011004 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011005 {
11006 xp->xp_context = EXPAND_BOOL_SETTINGS;
11007 p += 2;
11008 }
11009 if (STRNCMP(p, "inv", 3) == 0)
11010 {
11011 xp->xp_context = EXPAND_BOOL_SETTINGS;
11012 p += 3;
11013 }
11014 xp->xp_pattern = arg = p;
11015 if (*arg == '<')
11016 {
11017 while (*p != '>')
11018 if (*p++ == NUL) /* expand terminal option name */
11019 return;
11020 key = get_special_key_code(arg + 1);
11021 if (key == 0) /* unknown name */
11022 {
11023 xp->xp_context = EXPAND_NOTHING;
11024 return;
11025 }
11026 nextchar = *++p;
11027 is_term_option = TRUE;
11028 expand_option_name[2] = KEY2TERMCAP0(key);
11029 expand_option_name[3] = KEY2TERMCAP1(key);
11030 }
11031 else
11032 {
11033 if (p[0] == 't' && p[1] == '_')
11034 {
11035 p += 2;
11036 if (*p != NUL)
11037 ++p;
11038 if (*p == NUL)
11039 return; /* expand option name */
11040 nextchar = *++p;
11041 is_term_option = TRUE;
11042 expand_option_name[2] = p[-2];
11043 expand_option_name[3] = p[-1];
11044 }
11045 else
11046 {
11047 /* Allow * wildcard */
11048 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11049 p++;
11050 if (*p == NUL)
11051 return;
11052 nextchar = *p;
11053 *p = NUL;
11054 opt_idx = findoption(arg);
11055 *p = nextchar;
11056 if (opt_idx == -1 || options[opt_idx].var == NULL)
11057 {
11058 xp->xp_context = EXPAND_NOTHING;
11059 return;
11060 }
11061 flags = options[opt_idx].flags;
11062 if (flags & P_BOOL)
11063 {
11064 xp->xp_context = EXPAND_NOTHING;
11065 return;
11066 }
11067 }
11068 }
11069 /* handle "-=" and "+=" */
11070 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11071 {
11072 ++p;
11073 nextchar = '=';
11074 }
11075 if ((nextchar != '=' && nextchar != ':')
11076 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11077 {
11078 xp->xp_context = EXPAND_UNSUCCESSFUL;
11079 return;
11080 }
11081 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11082 {
11083 xp->xp_context = EXPAND_OLD_SETTING;
11084 if (is_term_option)
11085 expand_option_idx = -1;
11086 else
11087 expand_option_idx = opt_idx;
11088 xp->xp_pattern = p + 1;
11089 return;
11090 }
11091 xp->xp_context = EXPAND_NOTHING;
11092 if (is_term_option || (flags & P_NUM))
11093 return;
11094
11095 xp->xp_pattern = p + 1;
11096
11097 if (flags & P_EXPAND)
11098 {
11099 p = options[opt_idx].var;
11100 if (p == (char_u *)&p_bdir
11101 || p == (char_u *)&p_dir
11102 || p == (char_u *)&p_path
11103 || p == (char_u *)&p_rtp
11104#ifdef FEAT_SEARCHPATH
11105 || p == (char_u *)&p_cdpath
11106#endif
11107#ifdef FEAT_SESSION
11108 || p == (char_u *)&p_vdir
11109#endif
11110 )
11111 {
11112 xp->xp_context = EXPAND_DIRECTORIES;
11113 if (p == (char_u *)&p_path
11114#ifdef FEAT_SEARCHPATH
11115 || p == (char_u *)&p_cdpath
11116#endif
11117 )
11118 xp->xp_backslash = XP_BS_THREE;
11119 else
11120 xp->xp_backslash = XP_BS_ONE;
11121 }
11122 else
11123 {
11124 xp->xp_context = EXPAND_FILES;
11125 /* for 'tags' need three backslashes for a space */
11126 if (p == (char_u *)&p_tags)
11127 xp->xp_backslash = XP_BS_THREE;
11128 else
11129 xp->xp_backslash = XP_BS_ONE;
11130 }
11131 }
11132
11133 /* For an option that is a list of file names, find the start of the
11134 * last file name. */
11135 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11136 {
11137 /* count number of backslashes before ' ' or ',' */
11138 if (*p == ' ' || *p == ',')
11139 {
11140 s = p;
11141 while (s > xp->xp_pattern && *(s - 1) == '\\')
11142 --s;
11143 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11144 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11145 {
11146 xp->xp_pattern = p + 1;
11147 break;
11148 }
11149 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011150
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011151#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011152 /* for 'spellsuggest' start at "file:" */
11153 if (options[opt_idx].var == (char_u *)&p_sps
11154 && STRNCMP(p, "file:", 5) == 0)
11155 {
11156 xp->xp_pattern = p + 5;
11157 break;
11158 }
11159#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011160 }
11161
11162 return;
11163}
11164
11165 int
11166ExpandSettings(xp, regmatch, num_file, file)
11167 expand_T *xp;
11168 regmatch_T *regmatch;
11169 int *num_file;
11170 char_u ***file;
11171{
11172 int num_normal = 0; /* Nr of matching non-term-code settings */
11173 int num_term = 0; /* Nr of matching terminal code settings */
11174 int opt_idx;
11175 int match;
11176 int count = 0;
11177 char_u *str;
11178 int loop;
11179 int is_term_opt;
11180 char_u name_buf[MAX_KEY_NAME_LEN];
11181 static char *(names[]) = {"all", "termcap"};
11182 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11183
11184 /* do this loop twice:
11185 * loop == 0: count the number of matching options
11186 * loop == 1: copy the matching options into allocated memory
11187 */
11188 for (loop = 0; loop <= 1; ++loop)
11189 {
11190 regmatch->rm_ic = ic;
11191 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11192 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011193 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11194 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011195 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11196 {
11197 if (loop == 0)
11198 num_normal++;
11199 else
11200 (*file)[count++] = vim_strsave((char_u *)names[match]);
11201 }
11202 }
11203 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11204 opt_idx++)
11205 {
11206 if (options[opt_idx].var == NULL)
11207 continue;
11208 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11209 && !(options[opt_idx].flags & P_BOOL))
11210 continue;
11211 is_term_opt = istermoption(&options[opt_idx]);
11212 if (is_term_opt && num_normal > 0)
11213 continue;
11214 match = FALSE;
11215 if (vim_regexec(regmatch, str, (colnr_T)0)
11216 || (options[opt_idx].shortname != NULL
11217 && vim_regexec(regmatch,
11218 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11219 match = TRUE;
11220 else if (is_term_opt)
11221 {
11222 name_buf[0] = '<';
11223 name_buf[1] = 't';
11224 name_buf[2] = '_';
11225 name_buf[3] = str[2];
11226 name_buf[4] = str[3];
11227 name_buf[5] = '>';
11228 name_buf[6] = NUL;
11229 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11230 {
11231 match = TRUE;
11232 str = name_buf;
11233 }
11234 }
11235 if (match)
11236 {
11237 if (loop == 0)
11238 {
11239 if (is_term_opt)
11240 num_term++;
11241 else
11242 num_normal++;
11243 }
11244 else
11245 (*file)[count++] = vim_strsave(str);
11246 }
11247 }
11248 /*
11249 * Check terminal key codes, these are not in the option table
11250 */
11251 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11252 {
11253 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11254 {
11255 if (!isprint(str[0]) || !isprint(str[1]))
11256 continue;
11257
11258 name_buf[0] = 't';
11259 name_buf[1] = '_';
11260 name_buf[2] = str[0];
11261 name_buf[3] = str[1];
11262 name_buf[4] = NUL;
11263
11264 match = FALSE;
11265 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11266 match = TRUE;
11267 else
11268 {
11269 name_buf[0] = '<';
11270 name_buf[1] = 't';
11271 name_buf[2] = '_';
11272 name_buf[3] = str[0];
11273 name_buf[4] = str[1];
11274 name_buf[5] = '>';
11275 name_buf[6] = NUL;
11276
11277 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11278 match = TRUE;
11279 }
11280 if (match)
11281 {
11282 if (loop == 0)
11283 num_term++;
11284 else
11285 (*file)[count++] = vim_strsave(name_buf);
11286 }
11287 }
11288
11289 /*
11290 * Check special key names.
11291 */
11292 regmatch->rm_ic = TRUE; /* ignore case here */
11293 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11294 {
11295 name_buf[0] = '<';
11296 STRCPY(name_buf + 1, str);
11297 STRCAT(name_buf, ">");
11298
11299 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11300 {
11301 if (loop == 0)
11302 num_term++;
11303 else
11304 (*file)[count++] = vim_strsave(name_buf);
11305 }
11306 }
11307 }
11308 if (loop == 0)
11309 {
11310 if (num_normal > 0)
11311 *num_file = num_normal;
11312 else if (num_term > 0)
11313 *num_file = num_term;
11314 else
11315 return OK;
11316 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11317 if (*file == NULL)
11318 {
11319 *file = (char_u **)"";
11320 return FAIL;
11321 }
11322 }
11323 }
11324 return OK;
11325}
11326
11327 int
11328ExpandOldSetting(num_file, file)
11329 int *num_file;
11330 char_u ***file;
11331{
11332 char_u *var = NULL; /* init for GCC */
11333 char_u *buf;
11334
11335 *num_file = 0;
11336 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11337 if (*file == NULL)
11338 return FAIL;
11339
11340 /*
11341 * For a terminal key code expand_option_idx is < 0.
11342 */
11343 if (expand_option_idx < 0)
11344 {
11345 var = find_termcode(expand_option_name + 2);
11346 if (var == NULL)
11347 expand_option_idx = findoption(expand_option_name);
11348 }
11349
11350 if (expand_option_idx >= 0)
11351 {
11352 /* put string of option value in NameBuff */
11353 option_value2string(&options[expand_option_idx], expand_option_flags);
11354 var = NameBuff;
11355 }
11356 else if (var == NULL)
11357 var = (char_u *)"";
11358
11359 /* A backslash is required before some characters. This is the reverse of
11360 * what happens in do_set(). */
11361 buf = vim_strsave_escaped(var, escape_chars);
11362
11363 if (buf == NULL)
11364 {
11365 vim_free(*file);
11366 *file = NULL;
11367 return FAIL;
11368 }
11369
11370#ifdef BACKSLASH_IN_FILENAME
11371 /* For MS-Windows et al. we don't double backslashes at the start and
11372 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011373 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011374 if (var[0] == '\\' && var[1] == '\\'
11375 && expand_option_idx >= 0
11376 && (options[expand_option_idx].flags & P_EXPAND)
11377 && vim_isfilec(var[2])
11378 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011379 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011380#endif
11381
11382 *file[0] = buf;
11383 *num_file = 1;
11384 return OK;
11385}
11386#endif
11387
11388/*
11389 * Get the value for the numeric or string option *opp in a nice format into
11390 * NameBuff[]. Must not be called with a hidden option!
11391 */
11392 static void
11393option_value2string(opp, opt_flags)
11394 struct vimoption *opp;
11395 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11396{
11397 char_u *varp;
11398
11399 varp = get_varp_scope(opp, opt_flags);
11400
11401 if (opp->flags & P_NUM)
11402 {
11403 long wc = 0;
11404
11405 if (wc_use_keyname(varp, &wc))
11406 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11407 else if (wc != 0)
11408 STRCPY(NameBuff, transchar((int)wc));
11409 else
11410 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11411 }
11412 else /* P_STRING */
11413 {
11414 varp = *(char_u **)(varp);
11415 if (varp == NULL) /* just in case */
11416 NameBuff[0] = NUL;
11417#ifdef FEAT_CRYPT
11418 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011419 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011420 STRCPY(NameBuff, "*****");
11421#endif
11422 else if (opp->flags & P_EXPAND)
11423 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11424 /* Translate 'pastetoggle' into special key names */
11425 else if ((char_u **)opp->var == &p_pt)
11426 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11427 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011428 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011429 }
11430}
11431
11432/*
11433 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11434 * printed as a keyname.
11435 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11436 */
11437 static int
11438wc_use_keyname(varp, wcp)
11439 char_u *varp;
11440 long *wcp;
11441{
11442 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11443 {
11444 *wcp = *(long *)varp;
11445 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11446 return TRUE;
11447 }
11448 return FALSE;
11449}
11450
Bram Moolenaar01615492015-02-03 13:00:38 +010011451#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011452/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011453 * Any character has an equivalent 'langmap' character. This is used for
11454 * keyboards that have a special language mode that sends characters above
11455 * 128 (although other characters can be translated too). The "to" field is a
11456 * Vim command character. This avoids having to switch the keyboard back to
11457 * ASCII mode when leaving Insert mode.
11458 *
11459 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11460 * commands.
11461 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11462 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11463 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011464 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011465# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011466/*
11467 * With multi-byte support use growarray for 'langmap' chars >= 256
11468 */
11469typedef struct
11470{
11471 int from;
11472 int to;
11473} langmap_entry_T;
11474
11475static garray_T langmap_mapga;
11476static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011477
11478/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011479 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11480 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011481 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011482 static void
11483langmap_set_entry(from, to)
11484 int from;
11485 int to;
11486{
11487 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011488 int a = 0;
11489 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011490
11491 /* Do a binary search for an existing entry. */
11492 while (a != b)
11493 {
11494 int i = (a + b) / 2;
11495 int d = entries[i].from - from;
11496
11497 if (d == 0)
11498 {
11499 entries[i].to = to;
11500 return;
11501 }
11502 if (d < 0)
11503 a = i + 1;
11504 else
11505 b = i;
11506 }
11507
11508 if (ga_grow(&langmap_mapga, 1) != OK)
11509 return; /* out of memory */
11510
11511 /* insert new entry at position "a" */
11512 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11513 mch_memmove(entries + 1, entries,
11514 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11515 ++langmap_mapga.ga_len;
11516 entries[0].from = from;
11517 entries[0].to = to;
11518}
11519
11520/*
11521 * Apply 'langmap' to multi-byte character "c" and return the result.
11522 */
11523 int
11524langmap_adjust_mb(c)
11525 int c;
11526{
11527 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11528 int a = 0;
11529 int b = langmap_mapga.ga_len;
11530
11531 while (a != b)
11532 {
11533 int i = (a + b) / 2;
11534 int d = entries[i].from - c;
11535
11536 if (d == 0)
11537 return entries[i].to; /* found matching entry */
11538 if (d < 0)
11539 a = i + 1;
11540 else
11541 b = i;
11542 }
11543 return c; /* no entry found, return "c" unmodified */
11544}
11545# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546
11547 static void
11548langmap_init()
11549{
11550 int i;
11551
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011552 for (i = 0; i < 256; i++)
11553 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11554# ifdef FEAT_MBYTE
11555 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11556# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011557}
11558
11559/*
11560 * Called when langmap option is set; the language map can be
11561 * changed at any time!
11562 */
11563 static void
11564langmap_set()
11565{
11566 char_u *p;
11567 char_u *p2;
11568 int from, to;
11569
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011570#ifdef FEAT_MBYTE
11571 ga_clear(&langmap_mapga); /* clear the previous map first */
11572#endif
11573 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011574
11575 for (p = p_langmap; p[0] != NUL; )
11576 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011577 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11578 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011579 {
11580 if (p2[0] == '\\' && p2[1] != NUL)
11581 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011582 }
11583 if (p2[0] == ';')
11584 ++p2; /* abcd;ABCD form, p2 points to A */
11585 else
11586 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11587 while (p[0])
11588 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011589 if (p[0] == ',')
11590 {
11591 ++p;
11592 break;
11593 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011594 if (p[0] == '\\' && p[1] != NUL)
11595 ++p;
11596#ifdef FEAT_MBYTE
11597 from = (*mb_ptr2char)(p);
11598#else
11599 from = p[0];
11600#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011601 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011602 if (p2 == NULL)
11603 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011604 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011605 if (p[0] != ',')
11606 {
11607 if (p[0] == '\\')
11608 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011609#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011610 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011611#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011612 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011613#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011614 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011615 }
11616 else
11617 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011618 if (p2[0] != ',')
11619 {
11620 if (p2[0] == '\\')
11621 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011622#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011623 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011624#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011625 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011626#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011627 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011628 }
11629 if (to == NUL)
11630 {
11631 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11632 transchar(from));
11633 return;
11634 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011635
11636#ifdef FEAT_MBYTE
11637 if (from >= 256)
11638 langmap_set_entry(from, to);
11639 else
11640#endif
11641 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011642
11643 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011644 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011645 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011646 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011647 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011648 if (*p == ';')
11649 {
11650 p = p2;
11651 if (p[0] != NUL)
11652 {
11653 if (p[0] != ',')
11654 {
11655 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11656 return;
11657 }
11658 ++p;
11659 }
11660 break;
11661 }
11662 }
11663 }
11664 }
11665}
11666#endif
11667
11668/*
11669 * Return TRUE if format option 'x' is in effect.
11670 * Take care of no formatting when 'paste' is set.
11671 */
11672 int
11673has_format_option(x)
11674 int x;
11675{
11676 if (p_paste)
11677 return FALSE;
11678 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11679}
11680
11681/*
11682 * Return TRUE if "x" is present in 'shortmess' option, or
11683 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11684 */
11685 int
11686shortmess(x)
11687 int x;
11688{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011689 return p_shm != NULL &&
11690 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011691 || (vim_strchr(p_shm, 'a') != NULL
11692 && vim_strchr((char_u *)SHM_A, x) != NULL));
11693}
11694
11695/*
11696 * paste_option_changed() - Called after p_paste was set or reset.
11697 */
11698 static void
11699paste_option_changed()
11700{
11701 static int old_p_paste = FALSE;
11702 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011703 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011704#ifdef FEAT_CMDL_INFO
11705 static int save_ru = 0;
11706#endif
11707#ifdef FEAT_RIGHTLEFT
11708 static int save_ri = 0;
11709 static int save_hkmap = 0;
11710#endif
11711 buf_T *buf;
11712
11713 if (p_paste)
11714 {
11715 /*
11716 * Paste switched from off to on.
11717 * Save the current values, so they can be restored later.
11718 */
11719 if (!old_p_paste)
11720 {
11721 /* save options for each buffer */
11722 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11723 {
11724 buf->b_p_tw_nopaste = buf->b_p_tw;
11725 buf->b_p_wm_nopaste = buf->b_p_wm;
11726 buf->b_p_sts_nopaste = buf->b_p_sts;
11727 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011728 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011729 }
11730
11731 /* save global options */
11732 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011733 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011734#ifdef FEAT_CMDL_INFO
11735 save_ru = p_ru;
11736#endif
11737#ifdef FEAT_RIGHTLEFT
11738 save_ri = p_ri;
11739 save_hkmap = p_hkmap;
11740#endif
11741 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011742 p_ai_nopaste = p_ai;
11743 p_et_nopaste = p_et;
11744 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011745 p_tw_nopaste = p_tw;
11746 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011747 }
11748
11749 /*
11750 * Always set the option values, also when 'paste' is set when it is
11751 * already on.
11752 */
11753 /* set options for each buffer */
11754 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11755 {
11756 buf->b_p_tw = 0; /* textwidth is 0 */
11757 buf->b_p_wm = 0; /* wrapmargin is 0 */
11758 buf->b_p_sts = 0; /* softtabstop is 0 */
11759 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011760 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 }
11762
11763 /* set global options */
11764 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011765 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011766#ifdef FEAT_CMDL_INFO
11767# ifdef FEAT_WINDOWS
11768 if (p_ru)
11769 status_redraw_all(); /* redraw to remove the ruler */
11770# endif
11771 p_ru = 0; /* no ruler */
11772#endif
11773#ifdef FEAT_RIGHTLEFT
11774 p_ri = 0; /* no reverse insert */
11775 p_hkmap = 0; /* no Hebrew keyboard */
11776#endif
11777 /* set global values for local buffer options */
11778 p_tw = 0;
11779 p_wm = 0;
11780 p_sts = 0;
11781 p_ai = 0;
11782 }
11783
11784 /*
11785 * Paste switched from on to off: Restore saved values.
11786 */
11787 else if (old_p_paste)
11788 {
11789 /* restore options for each buffer */
11790 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11791 {
11792 buf->b_p_tw = buf->b_p_tw_nopaste;
11793 buf->b_p_wm = buf->b_p_wm_nopaste;
11794 buf->b_p_sts = buf->b_p_sts_nopaste;
11795 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011796 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011797 }
11798
11799 /* restore global options */
11800 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011801 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011802#ifdef FEAT_CMDL_INFO
11803# ifdef FEAT_WINDOWS
11804 if (p_ru != save_ru)
11805 status_redraw_all(); /* redraw to draw the ruler */
11806# endif
11807 p_ru = save_ru;
11808#endif
11809#ifdef FEAT_RIGHTLEFT
11810 p_ri = save_ri;
11811 p_hkmap = save_hkmap;
11812#endif
11813 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011814 p_ai = p_ai_nopaste;
11815 p_et = p_et_nopaste;
11816 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011817 p_tw = p_tw_nopaste;
11818 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819 }
11820
11821 old_p_paste = p_paste;
11822}
11823
11824/*
11825 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11826 *
11827 * Reset 'compatible' and set the values for options that didn't get set yet
11828 * to the Vim defaults.
11829 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011830 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011831 */
11832 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011833vimrc_found(fname, envname)
11834 char_u *fname;
11835 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011836{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011837 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011838 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011839 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840
11841 if (!option_was_set((char_u *)"cp"))
11842 {
11843 p_cp = FALSE;
11844 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11845 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11846 set_option_default(opt_idx, OPT_FREE, FALSE);
11847 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011848 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011849 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011850
11851 if (fname != NULL)
11852 {
11853 p = vim_getenv(envname, &dofree);
11854 if (p == NULL)
11855 {
11856 /* Set $MYVIMRC to the first vimrc file found. */
11857 p = FullName_save(fname, FALSE);
11858 if (p != NULL)
11859 {
11860 vim_setenv(envname, p);
11861 vim_free(p);
11862 }
11863 }
11864 else if (dofree)
11865 vim_free(p);
11866 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011867}
11868
11869/*
11870 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11871 */
11872 void
11873change_compatible(on)
11874 int on;
11875{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011876 int opt_idx;
11877
Bram Moolenaar071d4272004-06-13 20:20:40 +000011878 if (p_cp != on)
11879 {
11880 p_cp = on;
11881 compatible_set();
11882 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011883 opt_idx = findoption((char_u *)"cp");
11884 if (opt_idx >= 0)
11885 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011886}
11887
11888/*
11889 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011890 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011891 */
11892 int
11893option_was_set(name)
11894 char_u *name;
11895{
11896 int idx;
11897
11898 idx = findoption(name);
11899 if (idx < 0) /* unknown option */
11900 return FALSE;
11901 if (options[idx].flags & P_WAS_SET)
11902 return TRUE;
11903 return FALSE;
11904}
11905
11906/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011907 * Reset the flag indicating option "name" was set.
11908 */
11909 void
11910reset_option_was_set(name)
11911 char_u *name;
11912{
11913 int idx = findoption(name);
11914
11915 if (idx >= 0)
11916 options[idx].flags &= ~P_WAS_SET;
11917}
11918
11919/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011920 * compatible_set() - Called when 'compatible' has been set or unset.
11921 *
11922 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11923 * flag) to a Vi compatible value.
11924 * When 'compatible' is unset: Set all options that have a different default
11925 * for Vim (without the P_VI_DEF flag) to that default.
11926 */
11927 static void
11928compatible_set()
11929{
11930 int opt_idx;
11931
11932 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11933 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11934 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11935 set_option_default(opt_idx, OPT_FREE, p_cp);
11936 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011937 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011938}
11939
11940#ifdef FEAT_LINEBREAK
11941
11942# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11943 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011944 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011945# endif
11946
11947/*
11948 * fill_breakat_flags() -- called when 'breakat' changes value.
11949 */
11950 static void
11951fill_breakat_flags()
11952{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011953 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011954 int i;
11955
11956 for (i = 0; i < 256; i++)
11957 breakat_flags[i] = FALSE;
11958
11959 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011960 for (p = p_breakat; *p; p++)
11961 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011962}
11963
11964# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011965 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011966# endif
11967
11968#endif
11969
11970/*
11971 * Check an option that can be a range of string values.
11972 *
11973 * Return OK for correct value, FAIL otherwise.
11974 * Empty is always OK.
11975 */
11976 static int
11977check_opt_strings(val, values, list)
11978 char_u *val;
11979 char **values;
11980 int list; /* when TRUE: accept a list of values */
11981{
11982 return opt_strings_flags(val, values, NULL, list);
11983}
11984
11985/*
11986 * Handle an option that can be a range of string values.
11987 * Set a flag in "*flagp" for each string present.
11988 *
11989 * Return OK for correct value, FAIL otherwise.
11990 * Empty is always OK.
11991 */
11992 static int
11993opt_strings_flags(val, values, flagp, list)
11994 char_u *val; /* new value */
11995 char **values; /* array of valid string values */
11996 unsigned *flagp;
11997 int list; /* when TRUE: accept a list of values */
11998{
11999 int i;
12000 int len;
12001 unsigned new_flags = 0;
12002
12003 while (*val)
12004 {
12005 for (i = 0; ; ++i)
12006 {
12007 if (values[i] == NULL) /* val not found in values[] */
12008 return FAIL;
12009
12010 len = (int)STRLEN(values[i]);
12011 if (STRNCMP(values[i], val, len) == 0
12012 && ((list && val[len] == ',') || val[len] == NUL))
12013 {
12014 val += len + (val[len] == ',');
12015 new_flags |= (1 << i);
12016 break; /* check next item in val list */
12017 }
12018 }
12019 }
12020 if (flagp != NULL)
12021 *flagp = new_flags;
12022
12023 return OK;
12024}
12025
12026/*
12027 * Read the 'wildmode' option, fill wim_flags[].
12028 */
12029 static int
12030check_opt_wim()
12031{
12032 char_u new_wim_flags[4];
12033 char_u *p;
12034 int i;
12035 int idx = 0;
12036
12037 for (i = 0; i < 4; ++i)
12038 new_wim_flags[i] = 0;
12039
12040 for (p = p_wim; *p; ++p)
12041 {
12042 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12043 ;
12044 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12045 return FAIL;
12046 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12047 new_wim_flags[idx] |= WIM_LONGEST;
12048 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12049 new_wim_flags[idx] |= WIM_FULL;
12050 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12051 new_wim_flags[idx] |= WIM_LIST;
12052 else
12053 return FAIL;
12054 p += i;
12055 if (*p == NUL)
12056 break;
12057 if (*p == ',')
12058 {
12059 if (idx == 3)
12060 return FAIL;
12061 ++idx;
12062 }
12063 }
12064
12065 /* fill remaining entries with last flag */
12066 while (idx < 3)
12067 {
12068 new_wim_flags[idx + 1] = new_wim_flags[idx];
12069 ++idx;
12070 }
12071
12072 /* only when there are no errors, wim_flags[] is changed */
12073 for (i = 0; i < 4; ++i)
12074 wim_flags[i] = new_wim_flags[i];
12075 return OK;
12076}
12077
12078/*
12079 * Check if backspacing over something is allowed.
12080 */
12081 int
12082can_bs(what)
12083 int what; /* BS_INDENT, BS_EOL or BS_START */
12084{
12085 switch (*p_bs)
12086 {
12087 case '2': return TRUE;
12088 case '1': return (what != BS_START);
12089 case '0': return FALSE;
12090 }
12091 return vim_strchr(p_bs, what) != NULL;
12092}
12093
12094/*
12095 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12096 * the file must be considered changed when the value is different.
12097 */
12098 void
12099save_file_ff(buf)
12100 buf_T *buf;
12101{
12102 buf->b_start_ffc = *buf->b_p_ff;
12103 buf->b_start_eol = buf->b_p_eol;
12104#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012105 buf->b_start_bomb = buf->b_p_bomb;
12106
Bram Moolenaar071d4272004-06-13 20:20:40 +000012107 /* Only use free/alloc when necessary, they take time. */
12108 if (buf->b_start_fenc == NULL
12109 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12110 {
12111 vim_free(buf->b_start_fenc);
12112 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12113 }
12114#endif
12115}
12116
12117/*
12118 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12119 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012120 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12121 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012122 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012123 * When "ignore_empty" is true don't consider a new, empty buffer to be
12124 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012125 */
12126 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012127file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012128 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012129 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012130{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012131 /* In a buffer that was never loaded the options are not valid. */
12132 if (buf->b_flags & BF_NEVERLOADED)
12133 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012134 if (ignore_empty
12135 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136 && buf->b_ml.ml_line_count == 1
12137 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12138 return FALSE;
12139 if (buf->b_start_ffc != *buf->b_p_ff)
12140 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012141 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012142 return TRUE;
12143#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012144 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12145 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146 if (buf->b_start_fenc == NULL)
12147 return (*buf->b_p_fenc != NUL);
12148 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12149#else
12150 return FALSE;
12151#endif
12152}
12153
12154/*
12155 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12156 */
12157 int
12158check_ff_value(p)
12159 char_u *p;
12160{
12161 return check_opt_strings(p, p_ff_values, FALSE);
12162}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012163
12164/*
12165 * Return the effective shiftwidth value for current buffer, using the
12166 * 'tabstop' value when 'shiftwidth' is zero.
12167 */
12168 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012169get_sw_value(buf)
12170 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012171{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012172 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012173}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012174
12175/*
12176 * Return the effective softtabstop value for the current buffer, using the
12177 * 'tabstop' value when 'softtabstop' is negative.
12178 */
12179 long
12180get_sts_value()
12181{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012182 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012183}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012184
12185/*
12186 * Check matchpairs option for "*initc".
12187 * If there is a match set "*initc" to the matching character and "*findc" to
12188 * the opposite character. Set "*backwards" to the direction.
12189 * When "switchit" is TRUE swap the direction.
12190 */
12191 void
12192find_mps_values(initc, findc, backwards, switchit)
12193 int *initc;
12194 int *findc;
12195 int *backwards;
12196 int switchit;
12197{
12198 char_u *ptr;
12199
12200 ptr = curbuf->b_p_mps;
12201 while (*ptr != NUL)
12202 {
12203#ifdef FEAT_MBYTE
12204 if (has_mbyte)
12205 {
12206 char_u *prev;
12207
12208 if (mb_ptr2char(ptr) == *initc)
12209 {
12210 if (switchit)
12211 {
12212 *findc = *initc;
12213 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12214 *backwards = TRUE;
12215 }
12216 else
12217 {
12218 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12219 *backwards = FALSE;
12220 }
12221 return;
12222 }
12223 prev = ptr;
12224 ptr += mb_ptr2len(ptr) + 1;
12225 if (mb_ptr2char(ptr) == *initc)
12226 {
12227 if (switchit)
12228 {
12229 *findc = *initc;
12230 *initc = mb_ptr2char(prev);
12231 *backwards = FALSE;
12232 }
12233 else
12234 {
12235 *findc = mb_ptr2char(prev);
12236 *backwards = TRUE;
12237 }
12238 return;
12239 }
12240 ptr += mb_ptr2len(ptr);
12241 }
12242 else
12243#endif
12244 {
12245 if (*ptr == *initc)
12246 {
12247 if (switchit)
12248 {
12249 *backwards = TRUE;
12250 *findc = *initc;
12251 *initc = ptr[2];
12252 }
12253 else
12254 {
12255 *backwards = FALSE;
12256 *findc = ptr[2];
12257 }
12258 return;
12259 }
12260 ptr += 2;
12261 if (*ptr == *initc)
12262 {
12263 if (switchit)
12264 {
12265 *backwards = FALSE;
12266 *findc = *initc;
12267 *initc = ptr[-2];
12268 }
12269 else
12270 {
12271 *backwards = TRUE;
12272 *findc = ptr[-2];
12273 }
12274 return;
12275 }
12276 ++ptr;
12277 }
12278 if (*ptr == ',')
12279 ++ptr;
12280 }
12281}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012282
12283#if defined(FEAT_LINEBREAK) || defined(PROTO)
12284/*
12285 * This is called when 'breakindentopt' is changed and when a window is
12286 * initialized.
12287 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012288 static int
12289briopt_check(wp)
12290 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012291{
12292 char_u *p;
12293 int bri_shift = 0;
12294 long bri_min = 20;
12295 int bri_sbr = FALSE;
12296
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012297 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012298 while (*p != NUL)
12299 {
12300 if (STRNCMP(p, "shift:", 6) == 0
12301 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12302 {
12303 p += 6;
12304 bri_shift = getdigits(&p);
12305 }
12306 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12307 {
12308 p += 4;
12309 bri_min = getdigits(&p);
12310 }
12311 else if (STRNCMP(p, "sbr", 3) == 0)
12312 {
12313 p += 3;
12314 bri_sbr = TRUE;
12315 }
12316 if (*p != ',' && *p != NUL)
12317 return FAIL;
12318 if (*p == ',')
12319 ++p;
12320 }
12321
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012322 wp->w_p_brishift = bri_shift;
12323 wp->w_p_brimin = bri_min;
12324 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012325
12326 return OK;
12327}
12328#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012329
12330/*
12331 * Get the local or global value of 'backupcopy'.
12332 */
12333 unsigned int
12334get_bkc_value(buf)
12335 buf_T *buf;
12336{
12337 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12338}