blob: 3f98f47b85356390b40e0d5bb7684cf903bed1a8 [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 Moolenaar4ea8fe12006-03-09 22:32:39 +0000467#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
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 {
504#if (defined(MSDOS) || defined(WIN3264) || defined(OS2)) && !defined(FEAT_GUI_W32)
505 (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 {
579#if (defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI)
580 (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 {
1603#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1604 (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,_",
1629# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1630 (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 Moolenaar293ee4d2004-12-09 21:34:53 +00001639#if defined(MSDOS) || defined(MSWIN) || defined(OS2) \
1640 || (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
1685# if defined(OS2)
1686 (char_u *)"view /",
1687# else
1688# ifdef USEMAN_S
1689 (char_u *)"man -s",
1690# else
1691 (char_u *)"man",
1692# endif
1693# endif
1694#endif
1695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001697 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698#ifdef FEAT_LANGMAP
1699 (char_u *)&p_langmap, PV_NONE,
1700 {(char_u *)"", /* unmatched } */
1701#else
1702 (char_u *)NULL, PV_NONE,
1703 {(char_u *)NULL,
1704#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001705 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001706 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001707#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1708 (char_u *)&p_lm, PV_NONE,
1709#else
1710 (char_u *)NULL, PV_NONE,
1711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001712 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001713 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1714#ifdef FEAT_LANGMAP
1715 (char_u *)&p_lnr, PV_NONE,
1716#else
1717 (char_u *)NULL, PV_NONE,
1718#endif
1719 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1721#ifdef FEAT_WINDOWS
1722 (char_u *)&p_ls, PV_NONE,
1723#else
1724 (char_u *)NULL, PV_NONE,
1725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001726 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1728 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001729 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1731#ifdef FEAT_LINEBREAK
1732 (char_u *)VAR_WIN, PV_LBR,
1733#else
1734 (char_u *)NULL, PV_NONE,
1735#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001736 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1738 (char_u *)&Rows, PV_NONE,
1739 {
1740#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
1741 (char_u *)25L,
1742#else
1743 (char_u *)24L,
1744#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1747#ifdef FEAT_GUI
1748 (char_u *)&p_linespace, PV_NONE,
1749#else
1750 (char_u *)NULL, PV_NONE,
1751#endif
1752#ifdef FEAT_GUI_W32
1753 {(char_u *)1L, (char_u *)0L}
1754#else
1755 {(char_u *)0L, (char_u *)0L}
1756#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001757 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758 {"lisp", NULL, P_BOOL|P_VI_DEF,
1759#ifdef FEAT_LISP
1760 (char_u *)&p_lisp, PV_LISP,
1761#else
1762 (char_u *)NULL, PV_NONE,
1763#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001764 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001765 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001767 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1769#else
1770 (char_u *)NULL, PV_NONE,
1771 {(char_u *)"", (char_u *)0L}
1772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001773 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1775 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001776 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001777 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001779 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1781 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001783#if defined(DYNAMIC_LUA) && !defined(WIN3264)
1784 {"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1785 (char_u *)&p_luadll, PV_NONE,
1786 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
1787#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001788#ifdef FEAT_GUI_MAC
1789 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1790 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001792#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793 {"magic", NULL, P_BOOL|P_VI_DEF,
1794 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001795 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001796 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797#ifdef FEAT_QUICKFIX
1798 (char_u *)&p_mef, PV_NONE,
1799 {(char_u *)"", (char_u *)0L}
1800#else
1801 (char_u *)NULL, PV_NONE,
1802 {(char_u *)NULL, (char_u *)0L}
1803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001804 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1806#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001807 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001808# ifdef VMS
1809 {(char_u *)"MMS", (char_u *)0L}
1810# else
1811 {(char_u *)"make", (char_u *)0L}
1812# endif
1813#else
1814 (char_u *)NULL, PV_NONE,
1815 {(char_u *)NULL, (char_u *)0L}
1816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001818 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001820 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1821 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 {"matchtime", "mat", P_NUM|P_VI_DEF,
1823 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001825 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001826#ifdef FEAT_MBYTE
1827 (char_u *)&p_mco, PV_NONE,
1828#else
1829 (char_u *)NULL, PV_NONE,
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1833#ifdef FEAT_EVAL
1834 (char_u *)&p_mfd, PV_NONE,
1835#else
1836 (char_u *)NULL, PV_NONE,
1837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1840 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"maxmem", "mm", P_NUM|P_VI_DEF,
1843 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1845 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001846 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1847 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1850 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1852 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"menuitems", "mis", P_NUM|P_VI_DEF,
1854#ifdef FEAT_MENU
1855 (char_u *)&p_mis, PV_NONE,
1856#else
1857 (char_u *)NULL, PV_NONE,
1858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"mesg", NULL, P_BOOL|P_VI_DEF,
1861 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001863 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001864#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001865 (char_u *)&p_msm, PV_NONE,
1866 {(char_u *)"460000,2000,500", (char_u *)0L}
1867#else
1868 (char_u *)NULL, PV_NONE,
1869 {(char_u *)0L, (char_u *)0L}
1870#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"modeline", "ml", P_BOOL|P_VIM,
1873 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001874 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001875 {"modelines", "mls", P_NUM|P_VI_DEF,
1876 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1879 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1882 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001883 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884 {"more", NULL, P_BOOL|P_VIM,
1885 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001886 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001887 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1888 (char_u *)&p_mouse, PV_NONE,
1889 {
1890#if defined(MSDOS) || defined(WIN3264)
1891 (char_u *)"a",
1892#else
1893 (char_u *)"",
1894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1897#ifdef FEAT_GUI
1898 (char_u *)&p_mousef, PV_NONE,
1899#else
1900 (char_u *)NULL, PV_NONE,
1901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1904#ifdef FEAT_GUI
1905 (char_u *)&p_mh, PV_NONE,
1906#else
1907 (char_u *)NULL, PV_NONE,
1908#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001909 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001910 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1911 (char_u *)&p_mousem, PV_NONE,
1912 {
1913#if defined(MSDOS) || defined(MSWIN)
1914 (char_u *)"popup",
1915#else
1916# if defined(MACOS)
1917 (char_u *)"popup_setpos",
1918# else
1919 (char_u *)"extend",
1920# endif
1921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001923 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924#ifdef FEAT_MOUSESHAPE
1925 (char_u *)&p_mouseshape, PV_NONE,
1926 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1927#else
1928 (char_u *)NULL, PV_NONE,
1929 {(char_u *)NULL, (char_u *)0L}
1930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001931 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1933 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001935 {"mzquantum", "mzq", P_NUM,
1936#ifdef FEAT_MZSCHEME
1937 (char_u *)&p_mzq, PV_NONE,
1938#else
1939 (char_u *)NULL, PV_NONE,
1940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"novice", NULL, P_BOOL|P_VI_DEF,
1943 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001945 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001946 (char_u *)&p_nf, PV_NF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 {(char_u *)"octal,hex", (char_u *)0L}
1948 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001949 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1950 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001952 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1953#ifdef FEAT_LINEBREAK
1954 (char_u *)VAR_WIN, PV_NUW,
1955#else
1956 (char_u *)NULL, PV_NONE,
1957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001959 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001960#ifdef FEAT_COMPL_FUNC
1961 (char_u *)&p_ofu, PV_OFU,
1962 {(char_u *)"", (char_u *)0L}
1963#else
1964 (char_u *)NULL, PV_NONE,
1965 {(char_u *)0L, (char_u *)0L}
1966#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001968 {"open", NULL, P_BOOL|P_VI_DEF,
1969 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001970 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001971 {"opendevice", "odev", P_BOOL|P_VI_DEF,
1972#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
1973 (char_u *)&p_odev, PV_NONE,
1974#else
1975 (char_u *)NULL, PV_NONE,
1976#endif
1977 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001979 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1980 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"optimize", "opt", P_BOOL|P_VI_DEF,
1983 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001987 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"paragraphs", "para", P_STRING|P_VI_DEF,
1989 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001990 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001992 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001993 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1996 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001997 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1999#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2000 (char_u *)&p_pex, PV_NONE,
2001 {(char_u *)"", (char_u *)0L}
2002#else
2003 (char_u *)NULL, PV_NONE,
2004 {(char_u *)0L, (char_u *)0L}
2005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002007 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002009 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002011 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002012 {
2013#if defined AMIGA || defined MSDOS || defined MSWIN
2014 (char_u *)".,,",
2015#else
2016# if defined(__EMX__)
2017 (char_u *)".,/emx/include,,",
2018# else /* Unix, probably */
2019 (char_u *)".,/usr/include,,",
2020# endif
2021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002023#if defined(DYNAMIC_PERL) && !defined(WIN3264)
2024 {"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2025 (char_u *)&p_perldll, PV_NONE,
2026 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2027#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2029 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002030 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002031 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2033 (char_u *)&p_pvh, PV_NONE,
2034#else
2035 (char_u *)NULL, PV_NONE,
2036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002037 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002038 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2039#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2040 (char_u *)VAR_WIN, PV_PVW,
2041#else
2042 (char_u *)NULL, PV_NONE,
2043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002045 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002046#ifdef FEAT_PRINTER
2047 (char_u *)&p_pdev, PV_NONE,
2048 {(char_u *)"", (char_u *)0L}
2049#else
2050 (char_u *)NULL, PV_NONE,
2051 {(char_u *)NULL, (char_u *)0L}
2052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002053 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {"printencoding", "penc", P_STRING|P_VI_DEF,
2055#ifdef FEAT_POSTSCRIPT
2056 (char_u *)&p_penc, PV_NONE,
2057 {(char_u *)"", (char_u *)0L}
2058#else
2059 (char_u *)NULL, PV_NONE,
2060 {(char_u *)NULL, (char_u *)0L}
2061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002063 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2064#ifdef FEAT_POSTSCRIPT
2065 (char_u *)&p_pexpr, PV_NONE,
2066 {(char_u *)"", (char_u *)0L}
2067#else
2068 (char_u *)NULL, PV_NONE,
2069 {(char_u *)NULL, (char_u *)0L}
2070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002071 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 {"printfont", "pfn", P_STRING|P_VI_DEF,
2073#ifdef FEAT_PRINTER
2074 (char_u *)&p_pfn, PV_NONE,
2075 {
2076# ifdef MSWIN
2077 (char_u *)"Courier_New:h10",
2078# else
2079 (char_u *)"courier",
2080# endif
2081 (char_u *)0L}
2082#else
2083 (char_u *)NULL, PV_NONE,
2084 {(char_u *)NULL, (char_u *)0L}
2085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002086 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2088#ifdef FEAT_PRINTER
2089 (char_u *)&p_header, PV_NONE,
2090 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2091#else
2092 (char_u *)NULL, PV_NONE,
2093 {(char_u *)NULL, (char_u *)0L}
2094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002095 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002096 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2097#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2098 (char_u *)&p_pmcs, PV_NONE,
2099 {(char_u *)"", (char_u *)0L}
2100#else
2101 (char_u *)NULL, PV_NONE,
2102 {(char_u *)NULL, (char_u *)0L}
2103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002104 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002105 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2106#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2107 (char_u *)&p_pmfn, PV_NONE,
2108 {(char_u *)"", (char_u *)0L}
2109#else
2110 (char_u *)NULL, PV_NONE,
2111 {(char_u *)NULL, (char_u *)0L}
2112#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002113 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002114 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115#ifdef FEAT_PRINTER
2116 (char_u *)&p_popt, PV_NONE,
2117 {(char_u *)"", (char_u *)0L}
2118#else
2119 (char_u *)NULL, PV_NONE,
2120 {(char_u *)NULL, (char_u *)0L}
2121#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002122 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002124 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002126 {"pumheight", "ph", P_NUM|P_VI_DEF,
2127#ifdef FEAT_INS_EXPAND
2128 (char_u *)&p_ph, PV_NONE,
2129#else
2130 (char_u *)NULL, PV_NONE,
2131#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002132 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133#if defined(DYNAMIC_PYTHON3) && !defined(WIN3264)
Bram Moolenaar0796c062015-11-10 19:41:37 +01002134 {"pythonthreedll", NULL, P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002135 (char_u *)&p_py3dll, PV_NONE,
2136 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2137#endif
2138#if defined(DYNAMIC_PYTHON) && !defined(WIN3264)
2139 {"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2140 (char_u *)&p_pydll, PV_NONE,
2141 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2142#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002143 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2144#ifdef FEAT_TEXTOBJ
2145 (char_u *)&p_qe, PV_QE,
2146 {(char_u *)"\\", (char_u *)0L}
2147#else
2148 (char_u *)NULL, PV_NONE,
2149 {(char_u *)NULL, (char_u *)0L}
2150#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2153 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002154 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155 {"redraw", NULL, P_BOOL|P_VI_DEF,
2156 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002158 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2159#ifdef FEAT_RELTIME
2160 (char_u *)&p_rdt, PV_NONE,
2161#else
2162 (char_u *)NULL, PV_NONE,
2163#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002164 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002165 {"regexpengine", "re", P_NUM|P_VI_DEF,
2166 (char_u *)&p_re, PV_NONE,
2167 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002168 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2169 (char_u *)VAR_WIN, PV_RNU,
2170 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 {"remap", NULL, P_BOOL|P_VI_DEF,
2172 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002173 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002174 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002175#ifdef FEAT_RENDER_OPTIONS
2176 (char_u *)&p_rop, PV_NONE,
2177 {(char_u *)"", (char_u *)0L}
2178#else
2179 (char_u *)NULL, PV_NONE,
2180 {(char_u *)NULL, (char_u *)0L}
2181#endif
2182 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 {"report", NULL, P_NUM|P_VI_DEF,
2184 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002185 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2187#ifdef WIN3264
2188 (char_u *)&p_rs, PV_NONE,
2189#else
2190 (char_u *)NULL, PV_NONE,
2191#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002192 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2194#ifdef FEAT_RIGHTLEFT
2195 (char_u *)&p_ri, PV_NONE,
2196#else
2197 (char_u *)NULL, PV_NONE,
2198#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002199 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002200 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2201#ifdef FEAT_RIGHTLEFT
2202 (char_u *)VAR_WIN, PV_RL,
2203#else
2204 (char_u *)NULL, PV_NONE,
2205#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002206 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2208#ifdef FEAT_RIGHTLEFT
2209 (char_u *)VAR_WIN, PV_RLC,
2210 {(char_u *)"search", (char_u *)NULL}
2211#else
2212 (char_u *)NULL, PV_NONE,
2213 {(char_u *)NULL, (char_u *)0L}
2214#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002215 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002216#if defined(DYNAMIC_RUBY) && !defined(WIN3264)
2217 {"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2218 (char_u *)&p_rubydll, PV_NONE,
2219 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
2220#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002221 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2222#ifdef FEAT_CMDL_INFO
2223 (char_u *)&p_ru, PV_NONE,
2224#else
2225 (char_u *)NULL, PV_NONE,
2226#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002227 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002228 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2229#ifdef FEAT_STL_OPT
2230 (char_u *)&p_ruf, PV_NONE,
2231#else
2232 (char_u *)NULL, PV_NONE,
2233#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002234 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002235 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2236 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002238 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2239 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002240 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2241 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002242 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2244#ifdef FEAT_SCROLLBIND
2245 (char_u *)VAR_WIN, PV_SCBIND,
2246#else
2247 (char_u *)NULL, PV_NONE,
2248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002249 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2251 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002252 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002253 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2254 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002255 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002256 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002257#ifdef FEAT_SCROLLBIND
2258 (char_u *)&p_sbo, PV_NONE,
2259 {(char_u *)"ver,jump", (char_u *)0L}
2260#else
2261 (char_u *)NULL, PV_NONE,
2262 {(char_u *)0L, (char_u *)0L}
2263#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002264 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"sections", "sect", P_STRING|P_VI_DEF,
2266 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002267 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2268 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2270 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002274 {(char_u *)"inclusive", (char_u *)0L}
2275 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002276 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002278 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002279 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280#ifdef FEAT_SESSION
2281 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002282 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 (char_u *)0L}
2284#else
2285 (char_u *)NULL, PV_NONE,
2286 {(char_u *)0L, (char_u *)0L}
2287#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002288 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2290 (char_u *)&p_sh, PV_NONE,
2291 {
2292#ifdef VMS
2293 (char_u *)"-",
2294#else
2295# if defined(MSDOS)
2296 (char_u *)"command",
2297# else
2298# if defined(WIN16)
2299 (char_u *)"command.com",
2300# else
2301# if defined(WIN3264)
2302 (char_u *)"", /* set in set_init_1() */
2303# else
2304# if defined(OS2)
2305 (char_u *)"cmd.exe",
2306# else
2307# if defined(ARCHIE)
2308 (char_u *)"gos",
2309# else
2310 (char_u *)"sh",
2311# endif
2312# endif
2313# endif
2314# endif
2315# endif
2316#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002317 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2319 (char_u *)&p_shcf, PV_NONE,
2320 {
2321#if defined(MSDOS) || defined(MSWIN)
2322 (char_u *)"/c",
2323#else
2324# if defined(OS2)
2325 (char_u *)"/c",
2326# else
2327 (char_u *)"-c",
2328# endif
2329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2332#ifdef FEAT_QUICKFIX
2333 (char_u *)&p_sp, PV_NONE,
2334 {
2335#if defined(UNIX) || defined(OS2)
2336# ifdef ARCHIE
2337 (char_u *)"2>",
2338# else
2339 (char_u *)"| tee",
2340# endif
2341#else
2342 (char_u *)">",
2343#endif
2344 (char_u *)0L}
2345#else
2346 (char_u *)NULL, PV_NONE,
2347 {(char_u *)0L, (char_u *)0L}
2348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2351 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2354 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002355 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2357#ifdef BACKSLASH_IN_FILENAME
2358 (char_u *)&p_ssl, PV_NONE,
2359#else
2360 (char_u *)NULL, PV_NONE,
2361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002363 {"shelltemp", "stmp", P_BOOL,
2364 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002365 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"shelltype", "st", P_NUM|P_VI_DEF,
2367#ifdef AMIGA
2368 (char_u *)&p_st, PV_NONE,
2369#else
2370 (char_u *)NULL, PV_NONE,
2371#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002372 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2374 (char_u *)&p_sxq, PV_NONE,
2375 {
2376#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2377 (char_u *)"\"",
2378#else
2379 (char_u *)"",
2380#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002381 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002382 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2383 (char_u *)&p_sxe, PV_NONE,
2384 {
2385#if defined(MSDOS) || defined(WIN16) || defined(WIN3264)
2386 (char_u *)"\"&|<>()@^",
2387#else
2388 (char_u *)"",
2389#endif
2390 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2392 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002393 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2395 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002396 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2398 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)"", (char_u *)"filnxtToO"}
2400 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 {"shortname", "sn", P_BOOL|P_VI_DEF,
2402#ifdef SHORT_FNAME
2403 (char_u *)NULL, PV_NONE,
2404#else
2405 (char_u *)&p_sn, PV_SN,
2406#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2409#ifdef FEAT_LINEBREAK
2410 (char_u *)&p_sbr, PV_NONE,
2411#else
2412 (char_u *)NULL, PV_NONE,
2413#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002414 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415 {"showcmd", "sc", P_BOOL|P_VIM,
2416#ifdef FEAT_CMDL_INFO
2417 (char_u *)&p_sc, PV_NONE,
2418#else
2419 (char_u *)NULL, PV_NONE,
2420#endif
2421 {(char_u *)FALSE,
2422#ifdef UNIX
2423 (char_u *)FALSE
2424#else
2425 (char_u *)TRUE
2426#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002427 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2429 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2432 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002433 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 {"showmode", "smd", P_BOOL|P_VIM,
2435 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002437 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2438#ifdef FEAT_WINDOWS
2439 (char_u *)&p_stal, PV_NONE,
2440#else
2441 (char_u *)NULL, PV_NONE,
2442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002443 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2445 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002446 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2448 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2451 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2454 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002455 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2457#ifdef FEAT_SMARTINDENT
2458 (char_u *)&p_si, PV_SI,
2459#else
2460 (char_u *)NULL, PV_NONE,
2461#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002462 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002463 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2464 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002465 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002466 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2467 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2470 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002471 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002472 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002473#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002474 (char_u *)VAR_WIN, PV_SPELL,
2475#else
2476 (char_u *)NULL, PV_NONE,
2477#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002479 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002480#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002481 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002482 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +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 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2489 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002490#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002491 (char_u *)&p_spf, PV_SPF,
2492 {(char_u *)"", (char_u *)0L}
2493#else
2494 (char_u *)NULL, PV_NONE,
2495 {(char_u *)0L, (char_u *)0L}
2496#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002498 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2499 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002500#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002501 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002502 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002503#else
2504 (char_u *)NULL, PV_NONE,
2505 {(char_u *)0L, (char_u *)0L}
2506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002508 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002509#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002510 (char_u *)&p_sps, PV_NONE,
2511 {(char_u *)"best", (char_u *)0L}
2512#else
2513 (char_u *)NULL, PV_NONE,
2514 {(char_u *)0L, (char_u *)0L}
2515#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002516 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2518#ifdef FEAT_WINDOWS
2519 (char_u *)&p_sb, PV_NONE,
2520#else
2521 (char_u *)NULL, PV_NONE,
2522#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002523 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"splitright", "spr", P_BOOL|P_VI_DEF,
2525#ifdef FEAT_VERTSPLIT
2526 (char_u *)&p_spr, PV_NONE,
2527#else
2528 (char_u *)NULL, PV_NONE,
2529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002530 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2532 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2535#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002536 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002537#else
2538 (char_u *)NULL, PV_NONE,
2539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002541 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 (char_u *)&p_su, PV_NONE,
2543 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002545 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002546#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 (char_u *)&p_sua, PV_SUA,
2548 {(char_u *)"", (char_u *)0L}
2549#else
2550 (char_u *)NULL, PV_NONE,
2551 {(char_u *)0L, (char_u *)0L}
2552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2555 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"swapsync", "sws", P_STRING|P_VI_DEF,
2558 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002560 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002563 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2564#ifdef FEAT_SYN_HL
2565 (char_u *)&p_smc, PV_SMC,
2566 {(char_u *)3000L, (char_u *)0L}
2567#else
2568 (char_u *)NULL, PV_NONE,
2569 {(char_u *)0L, (char_u *)0L}
2570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002572 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573#ifdef FEAT_SYN_HL
2574 (char_u *)&p_syn, PV_SYN,
2575 {(char_u *)"", (char_u *)0L}
2576#else
2577 (char_u *)NULL, PV_NONE,
2578 {(char_u *)0L, (char_u *)0L}
2579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002580 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002581 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2582#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002583 (char_u *)&p_tal, PV_NONE,
2584#else
2585 (char_u *)NULL, PV_NONE,
2586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002588 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2589#ifdef FEAT_WINDOWS
2590 (char_u *)&p_tpm, PV_NONE,
2591#else
2592 (char_u *)NULL, PV_NONE,
2593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2596 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002597 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2599 (char_u *)&p_tbs, PV_NONE,
2600#ifdef VMS /* binary searching doesn't appear to work on VMS */
2601 {(char_u *)0L, (char_u *)0L}
2602#else
2603 {(char_u *)TRUE, (char_u *)0L}
2604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002606 {"tagcase", "tc", P_STRING|P_VIM,
2607 (char_u *)&p_tc, PV_TC,
2608 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002609 {"taglength", "tl", P_NUM|P_VI_DEF,
2610 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002611 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002612 {"tagrelative", "tr", P_BOOL|P_VIM,
2613 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002614 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002615 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002616 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {
2618#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2619 (char_u *)"./tags,./TAGS,tags,TAGS",
2620#else
2621 (char_u *)"./tags,tags",
2622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2625 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002626 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2628 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2631#ifdef FEAT_ARABIC
2632 (char_u *)&p_tbidi, PV_NONE,
2633#else
2634 (char_u *)NULL, PV_NONE,
2635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2638#ifdef FEAT_MBYTE
2639 (char_u *)&p_tenc, PV_NONE,
2640 {(char_u *)"", (char_u *)0L}
2641#else
2642 (char_u *)NULL, PV_NONE,
2643 {(char_u *)0L, (char_u *)0L}
2644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002645 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 {"terse", NULL, P_BOOL|P_VI_DEF,
2647 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 {"textauto", "ta", P_BOOL|P_VIM,
2650 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2652 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2654 (char_u *)&p_tx, PV_TX,
2655 {
2656#ifdef USE_CRNL
2657 (char_u *)TRUE,
2658#else
2659 (char_u *)FALSE,
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002662 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002665 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002667 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668#else
2669 (char_u *)NULL, PV_NONE,
2670#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2673 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002674 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"timeout", "to", P_BOOL|P_VI_DEF,
2676 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2679 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681 {"title", NULL, P_BOOL|P_VI_DEF,
2682#ifdef FEAT_TITLE
2683 (char_u *)&p_title, PV_NONE,
2684#else
2685 (char_u *)NULL, PV_NONE,
2686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688 {"titlelen", NULL, P_NUM|P_VI_DEF,
2689#ifdef FEAT_TITLE
2690 (char_u *)&p_titlelen, PV_NONE,
2691#else
2692 (char_u *)NULL, PV_NONE,
2693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002695 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696#ifdef FEAT_TITLE
2697 (char_u *)&p_titleold, PV_NONE,
2698 {(char_u *)N_("Thanks for flying Vim"),
2699 (char_u *)0L}
2700#else
2701 (char_u *)NULL, PV_NONE,
2702 {(char_u *)0L, (char_u *)0L}
2703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"titlestring", NULL, P_STRING|P_VI_DEF,
2706#ifdef FEAT_TITLE
2707 (char_u *)&p_titlestring, PV_NONE,
2708#else
2709 (char_u *)NULL, PV_NONE,
2710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002713 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)"icons,tooltips", (char_u *)0L}
2716 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002718#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2720 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722#endif
2723 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2724 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002725 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2727 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2730 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2733 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002735 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2736#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2737 (char_u *)&p_ttym, PV_NONE,
2738#else
2739 (char_u *)NULL, PV_NONE,
2740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002741 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2743 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2746 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002748 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2749 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002750#ifdef FEAT_PERSISTENT_UNDO
2751 (char_u *)&p_udir, PV_NONE,
2752 {(char_u *)".", (char_u *)0L}
2753#else
2754 (char_u *)NULL, PV_NONE,
2755 {(char_u *)0L, (char_u *)0L}
2756#endif
2757 SCRIPTID_INIT},
2758 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2759#ifdef FEAT_PERSISTENT_UNDO
2760 (char_u *)&p_udf, PV_UDF,
2761#else
2762 (char_u *)NULL, PV_NONE,
2763#endif
2764 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002766 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {
2768#if defined(UNIX) || defined(WIN3264) || defined(OS2) || defined(VMS)
2769 (char_u *)1000L,
2770#else
2771 (char_u *)100L,
2772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002774 {"undoreload", "ur", P_NUM|P_VI_DEF,
2775 (char_u *)&p_ur, PV_NONE,
2776 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 {"updatecount", "uc", P_NUM|P_VI_DEF,
2778 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002779 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 {"updatetime", "ut", P_NUM|P_VI_DEF,
2781 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"verbose", "vbs", P_NUM|P_VI_DEF,
2784 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002786 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2787 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2790#ifdef FEAT_SESSION
2791 (char_u *)&p_vdir, PV_NONE,
2792 {(char_u *)DFLT_VDIR, (char_u *)0L}
2793#else
2794 (char_u *)NULL, PV_NONE,
2795 {(char_u *)0L, (char_u *)0L}
2796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002798 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799#ifdef FEAT_SESSION
2800 (char_u *)&p_vop, PV_NONE,
2801 {(char_u *)"folds,options,cursor", (char_u *)0L}
2802#else
2803 (char_u *)NULL, PV_NONE,
2804 {(char_u *)0L, (char_u *)0L}
2805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002807 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808#ifdef FEAT_VIMINFO
2809 (char_u *)&p_viminfo, PV_NONE,
2810#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
Bram Moolenaard812df62008-11-09 12:46:09 +00002811 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812#else
2813# ifdef AMIGA
2814 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002815 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002817 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818# endif
2819#endif
2820#else
2821 (char_u *)NULL, PV_NONE,
2822 {(char_u *)0L, (char_u *)0L}
2823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002825 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2826 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827#ifdef FEAT_VIRTUALEDIT
2828 (char_u *)&p_ve, PV_NONE,
2829 {(char_u *)"", (char_u *)""}
2830#else
2831 (char_u *)NULL, PV_NONE,
2832 {(char_u *)0L, (char_u *)0L}
2833#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2836 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"w300", NULL, P_NUM|P_VI_DEF,
2839 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"w1200", NULL, P_NUM|P_VI_DEF,
2842 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"w9600", NULL, P_NUM|P_VI_DEF,
2845 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 {"warn", NULL, P_BOOL|P_VI_DEF,
2848 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2851 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002853 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"wildchar", "wc", P_NUM|P_VIM,
2857 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2859 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002860 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002863 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864#ifdef FEAT_WILDIGN
2865 (char_u *)&p_wig, PV_NONE,
2866#else
2867 (char_u *)NULL, PV_NONE,
2868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002870 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2871 (char_u *)&p_wic, PV_NONE,
2872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2874#ifdef FEAT_WILDMENU
2875 (char_u *)&p_wmnu, PV_NONE,
2876#else
2877 (char_u *)NULL, PV_NONE,
2878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002880 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002882 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002883 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2884#ifdef FEAT_CMDL_COMPL
2885 (char_u *)&p_wop, PV_NONE,
2886 {(char_u *)"", (char_u *)0L}
2887#else
2888 (char_u *)NULL, PV_NONE,
2889 {(char_u *)NULL, (char_u *)0L}
2890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2893#ifdef FEAT_WAK
2894 (char_u *)&p_wak, PV_NONE,
2895 {(char_u *)"menu", (char_u *)0L}
2896#else
2897 (char_u *)NULL, PV_NONE,
2898 {(char_u *)NULL, (char_u *)0L}
2899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002902 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002903 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002904 {"winheight", "wh", P_NUM|P_VI_DEF,
2905#ifdef FEAT_WINDOWS
2906 (char_u *)&p_wh, PV_NONE,
2907#else
2908 (char_u *)NULL, PV_NONE,
2909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002910 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002912#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913 (char_u *)VAR_WIN, PV_WFH,
2914#else
2915 (char_u *)NULL, PV_NONE,
2916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002918 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2919#ifdef FEAT_VERTSPLIT
2920 (char_u *)VAR_WIN, PV_WFW,
2921#else
2922 (char_u *)NULL, PV_NONE,
2923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2926#ifdef FEAT_WINDOWS
2927 (char_u *)&p_wmh, PV_NONE,
2928#else
2929 (char_u *)NULL, PV_NONE,
2930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002931 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2933#ifdef FEAT_VERTSPLIT
2934 (char_u *)&p_wmw, PV_NONE,
2935#else
2936 (char_u *)NULL, PV_NONE,
2937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2940#ifdef FEAT_VERTSPLIT
2941 (char_u *)&p_wiw, PV_NONE,
2942#else
2943 (char_u *)NULL, PV_NONE,
2944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002945 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2947 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2950 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2953 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002954 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 {"write", NULL, P_BOOL|P_VI_DEF,
2956 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"writeany", "wa", P_BOOL|P_VI_DEF,
2959 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002960 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2962 (char_u *)&p_wb, PV_NONE,
2963 {
2964#ifdef FEAT_WRITEBACKUP
2965 (char_u *)TRUE,
2966#else
2967 (char_u *)FALSE,
2968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002969 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 {"writedelay", "wd", P_NUM|P_VI_DEF,
2971 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002972 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973
2974/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002975#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002977 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978
2979 p_term("t_AB", T_CAB)
2980 p_term("t_AF", T_CAF)
2981 p_term("t_AL", T_CAL)
2982 p_term("t_al", T_AL)
2983 p_term("t_bc", T_BC)
2984 p_term("t_cd", T_CD)
2985 p_term("t_ce", T_CE)
2986 p_term("t_cl", T_CL)
2987 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002988 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 p_term("t_Co", T_CCO)
2990 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002991 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 p_term("t_cs", T_CS)
2993#ifdef FEAT_VERTSPLIT
2994 p_term("t_CV", T_CSV)
2995#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 p_term("t_da", T_DA)
2997 p_term("t_db", T_DB)
2998 p_term("t_DL", T_CDL)
2999 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003000 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 p_term("t_fs", T_FS)
3002 p_term("t_IE", T_CIE)
3003 p_term("t_IS", T_CIS)
3004 p_term("t_ke", T_KE)
3005 p_term("t_ks", T_KS)
3006 p_term("t_le", T_LE)
3007 p_term("t_mb", T_MB)
3008 p_term("t_md", T_MD)
3009 p_term("t_me", T_ME)
3010 p_term("t_mr", T_MR)
3011 p_term("t_ms", T_MS)
3012 p_term("t_nd", T_ND)
3013 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003014 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 p_term("t_RI", T_CRI)
3016 p_term("t_RV", T_CRV)
3017 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003019 p_term("t_Sf", T_CSF)
3020 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003022 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024 p_term("t_te", T_TE)
3025 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003026 p_term("t_ts", T_TS)
3027 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 p_term("t_ue", T_UE)
3029 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003030 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031 p_term("t_vb", T_VB)
3032 p_term("t_ve", T_VE)
3033 p_term("t_vi", T_VI)
3034 p_term("t_vs", T_VS)
3035 p_term("t_WP", T_CWP)
3036 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003037 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 p_term("t_xs", T_XS)
3039 p_term("t_ZH", T_CZH)
3040 p_term("t_ZR", T_CZR)
3041
3042/* terminal key codes are not in here */
3043
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003044 /* end marker */
3045 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046};
3047
3048#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3049
3050#ifdef FEAT_MBYTE
3051static char *(p_ambw_values[]) = {"single", "double", NULL};
3052#endif
3053static char *(p_bg_values[]) = {"light", "dark", NULL};
3054static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
3055static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003056#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003057static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003058#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003059#ifdef FEAT_CMDL_COMPL
3060static char *(p_wop_values[]) = {"tagfile", NULL};
3061#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062#ifdef FEAT_WAK
3063static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3064#endif
3065static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3067static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069#ifdef FEAT_BROWSE
3070static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3071#endif
3072#ifdef FEAT_SCROLLBIND
3073static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3074#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003075static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076#ifdef FEAT_VERTSPLIT
3077static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3078#endif
3079#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003080# ifdef FEAT_AUTOCMD
3081static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3082# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003084# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3086#endif
3087static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3088#ifdef FEAT_FOLDING
3089static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003090# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003092# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 NULL};
3094static char *(p_fcl_values[]) = {"all", NULL};
3095#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003096#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003097static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003098#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099
3100static void set_option_default __ARGS((int, int opt_flags, int compatible));
3101static void set_options_default __ARGS((int opt_flags));
Bram Moolenaarf740b292006-02-16 22:11:02 +00003102static char_u *term_bg_default __ARGS((void));
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003103static void did_set_option __ARGS((int opt_idx, int opt_flags, int new_value));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104static char_u *illegal_char __ARGS((char_u *, int));
3105static int string_to_key __ARGS((char_u *arg));
3106#ifdef FEAT_CMDWIN
3107static char_u *check_cedit __ARGS((void));
3108#endif
3109#ifdef FEAT_TITLE
3110static void did_set_title __ARGS((int icon));
3111#endif
3112static char_u *option_expand __ARGS((int opt_idx, char_u *val));
3113static void didset_options __ARGS((void));
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003114static void didset_options2 __ARGS((void));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115static void check_string_option __ARGS((char_u **pp));
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003116#if defined(FEAT_EVAL) || defined(PROTO)
3117static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
3118#else
3119# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3120#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02003122static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123static 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));
3124static char_u *set_chars_option __ARGS((char_u **varp));
Bram Moolenaar1a384422010-07-14 19:53:30 +02003125#ifdef FEAT_SYN_HL
3126static int int_cmp __ARGS((const void *a, const void *b));
3127#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128#ifdef FEAT_CLIPBOARD
3129static char_u *check_clipboard_option __ARGS((void));
3130#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003131#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003132static char_u *did_set_spell_option __ARGS((int is_spellfile));
Bram Moolenaar860cae12010-06-05 23:22:07 +02003133static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003134#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003135#ifdef FEAT_EVAL
3136static void set_option_scriptID_idx __ARGS((int opt_idx, int opt_flags, int id));
3137#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138static char_u *set_bool_option __ARGS((int opt_idx, char_u *varp, int value, int opt_flags));
Bram Moolenaar555b2802005-05-19 21:08:39 +00003139static 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 +00003140static void check_redraw __ARGS((long_u flags));
3141static int findoption __ARGS((char_u *));
3142static int find_key_option __ARGS((char_u *));
3143static void showoptions __ARGS((int all, int opt_flags));
3144static int optval_default __ARGS((struct vimoption *, char_u *varp));
3145static void showoneopt __ARGS((struct vimoption *, int opt_flags));
3146static int put_setstring __ARGS((FILE *fd, char *cmd, char *name, char_u **valuep, int expand));
3147static int put_setnum __ARGS((FILE *fd, char *cmd, char *name, long *valuep));
3148static int put_setbool __ARGS((FILE *fd, char *cmd, char *name, int value));
3149static int istermoption __ARGS((struct vimoption *));
3150static char_u *get_varp_scope __ARGS((struct vimoption *p, int opt_flags));
3151static char_u *get_varp __ARGS((struct vimoption *));
3152static void option_value2string __ARGS((struct vimoption *, int opt_flags));
Bram Moolenaar8dc907d2014-06-25 14:44:10 +02003153static void check_winopt __ARGS((winopt_T *wop));
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154static int wc_use_keyname __ARGS((char_u *varp, long *wcp));
3155#ifdef FEAT_LANGMAP
3156static void langmap_init __ARGS((void));
3157static void langmap_set __ARGS((void));
3158#endif
3159static void paste_option_changed __ARGS((void));
3160static void compatible_set __ARGS((void));
3161#ifdef FEAT_LINEBREAK
3162static void fill_breakat_flags __ARGS((void));
3163#endif
3164static int opt_strings_flags __ARGS((char_u *val, char **values, unsigned *flagp, int list));
3165static int check_opt_strings __ARGS((char_u *val, char **values, int));
3166static int check_opt_wim __ARGS((void));
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003167#ifdef FEAT_LINEBREAK
3168static int briopt_check __ARGS((win_T *wp));
3169#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170
3171/*
3172 * Initialize the options, first part.
3173 *
3174 * Called only once from main(), just after creating the first buffer.
3175 */
3176 void
3177set_init_1()
3178{
3179 char_u *p;
3180 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003181 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182
3183#ifdef FEAT_LANGMAP
3184 langmap_init();
3185#endif
3186
3187 /* Be Vi compatible by default */
3188 p_cp = TRUE;
3189
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003190 /* Use POSIX compatibility when $VIM_POSIX is set. */
3191 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003192 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003193 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003194 set_string_default("shm", (char_u *)"A");
3195 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003196
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 /*
3198 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003199 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003201 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3203# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003204 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003206 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207# ifdef WIN3264
Bram Moolenaar7c626922005-02-07 22:01:03 +00003208 || ((p = default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209# endif
3210#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003211 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 set_string_default("sh", p);
3213
3214#ifdef FEAT_WILDIGN
3215 /*
3216 * Set the default for 'backupskip' to include environment variables for
3217 * temp files.
3218 */
3219 {
3220# ifdef UNIX
3221 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3222# else
3223 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3224# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003225 int len;
3226 garray_T ga;
3227 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228
3229 ga_init2(&ga, 1, 100);
3230 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3231 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003232 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233# ifdef UNIX
3234 if (*names[n] == NUL)
3235 p = (char_u *)"/tmp";
3236 else
3237# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003238 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003239 if (p != NULL && *p != NUL)
3240 {
3241 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003242 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243 if (ga_grow(&ga, len) == OK)
3244 {
3245 if (ga.ga_len > 0)
3246 STRCAT(ga.ga_data, ",");
3247 STRCAT(ga.ga_data, p);
3248 add_pathsep(ga.ga_data);
3249 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250 ga.ga_len += len;
3251 }
3252 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003253 if (mustfree)
3254 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255 }
3256 if (ga.ga_data != NULL)
3257 {
3258 set_string_default("bsk", ga.ga_data);
3259 vim_free(ga.ga_data);
3260 }
3261 }
3262#endif
3263
3264 /*
3265 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3266 */
3267 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003268 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003270#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3271 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3272#endif
3273 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003275 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003276 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277#else
3278# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003279 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003280 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003282 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283# endif
3284#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003286 opt_idx = findoption((char_u *)"maxmem");
3287 if (opt_idx >= 0)
3288 {
3289#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003290 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3291 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003292#endif
3293 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3294 }
3295 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003296 }
3297
3298#ifdef FEAT_GUI_W32
3299 /* force 'shortname' for Win32s */
3300 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003301 {
3302 opt_idx = findoption((char_u *)"shortname");
3303 if (opt_idx >= 0)
3304 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3305 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306#endif
3307
3308#ifdef FEAT_SEARCHPATH
3309 {
3310 char_u *cdpath;
3311 char_u *buf;
3312 int i;
3313 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003314 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315
3316 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003317 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318 if (cdpath != NULL)
3319 {
3320 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3321 if (buf != NULL)
3322 {
3323 buf[0] = ','; /* start with ",", current dir first */
3324 j = 1;
3325 for (i = 0; cdpath[i] != NUL; ++i)
3326 {
3327 if (vim_ispathlistsep(cdpath[i]))
3328 buf[j++] = ',';
3329 else
3330 {
3331 if (cdpath[i] == ' ' || cdpath[i] == ',')
3332 buf[j++] = '\\';
3333 buf[j++] = cdpath[i];
3334 }
3335 }
3336 buf[j] = NUL;
3337 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003338 if (opt_idx >= 0)
3339 {
3340 options[opt_idx].def_val[VI_DEFAULT] = buf;
3341 options[opt_idx].flags |= P_DEF_ALLOCED;
3342 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003343 else
3344 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003346 if (mustfree)
3347 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 }
3349 }
3350#endif
3351
3352#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(OS2) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
3353 /* Set print encoding on platforms that don't default to latin1 */
3354 set_string_default("penc",
3355# if defined(MSWIN) || defined(OS2)
3356 (char_u *)"cp1252"
3357# else
3358# ifdef VMS
3359 (char_u *)"dec-mcs"
3360# else
3361# ifdef EBCDIC
3362 (char_u *)"ebcdic-uk"
3363# else
3364# ifdef MAC
3365 (char_u *)"mac-roman"
3366# else /* HPUX */
3367 (char_u *)"hp-roman8"
3368# endif
3369# endif
3370# endif
3371# endif
3372 );
3373#endif
3374
3375#ifdef FEAT_POSTSCRIPT
3376 /* 'printexpr' must be allocated to be able to evaluate it. */
3377 set_string_default("pexpr",
Bram Moolenaared203462004-06-16 11:19:22 +00003378# if defined(MSWIN) || defined(MSDOS) || defined(OS2)
3379 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380# else
3381# ifdef VMS
3382 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3383
3384# else
3385 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3386# endif
3387# endif
3388 );
3389#endif
3390
3391 /*
3392 * Set all the options (except the terminal options) to their default
3393 * value. Also set the global value for local options.
3394 */
3395 set_options_default(0);
3396
3397#ifdef FEAT_GUI
3398 if (found_reverse_arg)
3399 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3400#endif
3401
3402 curbuf->b_p_initialized = TRUE;
3403 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003404 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003405 check_buf_options(curbuf);
3406 check_win_options(curwin);
3407 check_options();
3408
3409 /* Must be before option_expand(), because that one needs vim_isIDc() */
3410 didset_options();
3411
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003412#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003413 /* Use the current chartab for the generic chartab. This is not in
3414 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003415 init_spell_chartab();
3416#endif
3417
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 /*
3419 * Expand environment variables and things like "~" for the defaults.
3420 * If option_expand() returns non-NULL the variable is expanded. This can
3421 * only happen for non-indirect options.
3422 * Also set the default to the expanded value, so ":set" does not list
3423 * them.
3424 * Don't set the P_ALLOCED flag, because we don't want to free the
3425 * default.
3426 */
3427 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3428 {
3429 if ((options[opt_idx].flags & P_GETTEXT)
3430 && options[opt_idx].var != NULL)
3431 p = (char_u *)_(*(char **)options[opt_idx].var);
3432 else
3433 p = option_expand(opt_idx, NULL);
3434 if (p != NULL && (p = vim_strsave(p)) != NULL)
3435 {
3436 *(char_u **)options[opt_idx].var = p;
3437 /* VIMEXP
3438 * Defaults for all expanded options are currently the same for Vi
3439 * and Vim. When this changes, add some code here! Also need to
3440 * split P_DEF_ALLOCED in two.
3441 */
3442 if (options[opt_idx].flags & P_DEF_ALLOCED)
3443 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3444 options[opt_idx].def_val[VI_DEFAULT] = p;
3445 options[opt_idx].flags |= P_DEF_ALLOCED;
3446 }
3447 }
3448
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449 save_file_ff(curbuf); /* Buffer is unchanged */
3450
Bram Moolenaar071d4272004-06-13 20:20:40 +00003451#if defined(FEAT_ARABIC)
3452 /* Detect use of mlterm.
3453 * Mlterm is a terminal emulator akin to xterm that has some special
3454 * abilities (bidi namely).
3455 * NOTE: mlterm's author is being asked to 'set' a variable
3456 * instead of an environment variable due to inheritance.
3457 */
3458 if (mch_getenv((char_u *)"MLTERM") != NULL)
3459 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3460#endif
3461
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003462 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003463
3464#ifdef FEAT_MBYTE
3465# if defined(WIN3264) && defined(FEAT_GETTEXT)
3466 /*
3467 * If $LANG isn't set, try to get a good value for it. This makes the
3468 * right language be used automatically. Don't do this for English.
3469 */
3470 if (mch_getenv((char_u *)"LANG") == NULL)
3471 {
3472 char buf[20];
3473
3474 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3475 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3476 * only the first two. */
3477 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3478 (LPTSTR)buf, 20);
3479 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3480 {
3481 /* There are a few exceptions (probably more) */
3482 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3483 STRCPY(buf, "zh_TW");
3484 else if (STRNICMP(buf, "chs", 3) == 0
3485 || STRNICMP(buf, "zhc", 3) == 0)
3486 STRCPY(buf, "zh_CN");
3487 else if (STRNICMP(buf, "jp", 2) == 0)
3488 STRCPY(buf, "ja");
3489 else
3490 buf[2] = NUL; /* truncate to two-letter code */
3491 vim_setenv("LANG", buf);
3492 }
3493 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003494# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003495# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003496 /* Moved to os_mac_conv.c to avoid dependency problems. */
3497 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003498# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003499# endif
3500
3501 /* enc_locale() will try to find the encoding of the current locale. */
3502 p = enc_locale();
3503 if (p != NULL)
3504 {
3505 char_u *save_enc;
3506
3507 /* Try setting 'encoding' and check if the value is valid.
3508 * If not, go back to the default "latin1". */
3509 save_enc = p_enc;
3510 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003511 if (STRCMP(p_enc, "gb18030") == 0)
3512 {
3513 /* We don't support "gb18030", but "cp936" is a good substitute
3514 * for practical purposes, thus use that. It's not an alias to
3515 * still support conversion between gb18030 and utf-8. */
3516 p_enc = vim_strsave((char_u *)"cp936");
3517 vim_free(p);
3518 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003519 if (mb_init() == NULL)
3520 {
3521 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003522 if (opt_idx >= 0)
3523 {
3524 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3525 options[opt_idx].flags |= P_DEF_ALLOCED;
3526 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003527
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003528#if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(MACOS) \
3529 || defined(VMS)
3530 if (STRCMP(p_enc, "latin1") == 0
3531# ifdef FEAT_MBYTE
3532 || enc_utf8
3533# endif
3534 )
3535 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003536 /* Adjust the default for 'isprint' and 'iskeyword' to match
3537 * latin1. Also set the defaults for when 'nocompatible' is
3538 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003539 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003540 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003541 set_string_option_direct((char_u *)"isk", -1,
3542 ISK_LATIN1, OPT_FREE, SID_NONE);
3543 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003544 if (opt_idx >= 0)
3545 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003546 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003547 if (opt_idx >= 0)
3548 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003549 (void)init_chartab();
3550 }
3551#endif
3552
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553# if defined(WIN3264) && !defined(FEAT_GUI)
3554 /* Win32 console: When GetACP() returns a different value from
3555 * GetConsoleCP() set 'termencoding'. */
3556 if (GetACP() != GetConsoleCP())
3557 {
3558 char buf[50];
3559
3560 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3561 p_tenc = vim_strsave((char_u *)buf);
3562 if (p_tenc != NULL)
3563 {
3564 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003565 if (opt_idx >= 0)
3566 {
3567 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3568 options[opt_idx].flags |= P_DEF_ALLOCED;
3569 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003570 convert_setup(&input_conv, p_tenc, p_enc);
3571 convert_setup(&output_conv, p_enc, p_tenc);
3572 }
3573 else
3574 p_tenc = empty_option;
3575 }
3576# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003577# if defined(WIN3264) && defined(FEAT_MBYTE)
3578 /* $HOME may have characters in active code page. */
3579 init_homedir();
3580# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003581 }
3582 else
3583 {
3584 vim_free(p_enc);
3585 p_enc = save_enc;
3586 }
3587 }
3588#endif
3589
3590#ifdef FEAT_MULTI_LANG
3591 /* Set the default for 'helplang'. */
3592 set_helplang_default(get_mess_lang());
3593#endif
3594}
3595
3596/*
3597 * Set an option to its default value.
3598 * This does not take care of side effects!
3599 */
3600 static void
3601set_option_default(opt_idx, opt_flags, compatible)
3602 int opt_idx;
3603 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3604 int compatible; /* use Vi default value */
3605{
3606 char_u *varp; /* pointer to variable for current option */
3607 int dvi; /* index in def_val[] */
3608 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003609 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003610 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3611
3612 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3613 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003614 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615 {
3616 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3617 if (flags & P_STRING)
3618 {
3619 /* Use set_string_option_direct() for local options to handle
3620 * freeing and allocating the value. */
3621 if (options[opt_idx].indir != PV_NONE)
3622 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003623 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003624 else
3625 {
3626 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3627 free_string_option(*(char_u **)(varp));
3628 *(char_u **)varp = options[opt_idx].def_val[dvi];
3629 options[opt_idx].flags &= ~P_ALLOCED;
3630 }
3631 }
3632 else if (flags & P_NUM)
3633 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003634 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003635 win_comp_scroll(curwin);
3636 else
3637 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003638 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003639 /* May also set global value for local option. */
3640 if (both)
3641 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3642 *(long *)varp;
3643 }
3644 }
3645 else /* P_BOOL */
3646 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003647 /* the cast to long is required for Manx C, long_i is needed for
3648 * MSVC */
3649 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003650#ifdef UNIX
3651 /* 'modeline' defaults to off for root */
3652 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3653 *(int *)varp = FALSE;
3654#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655 /* May also set global value for local option. */
3656 if (both)
3657 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3658 *(int *)varp;
3659 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003660
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003661 /* The default value is not insecure. */
3662 flagsp = insecure_flag(opt_idx, opt_flags);
3663 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003664 }
3665
3666#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003667 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003668#endif
3669}
3670
3671/*
3672 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003673 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674 */
3675 static void
3676set_options_default(opt_flags)
3677 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3678{
3679 int i;
3680#ifdef FEAT_WINDOWS
3681 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003682 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683#endif
3684
3685 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003686 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003687#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003688 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003689 || (TRUE
3690# if defined(FEAT_MBYTE)
3691 && options[i].var != (char_u *)&p_enc
3692# endif
3693# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003694 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003695 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003696# endif
3697 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003698#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003699 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700 set_option_default(i, opt_flags, p_cp);
3701
3702#ifdef FEAT_WINDOWS
3703 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003704 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705 win_comp_scroll(wp);
3706#else
3707 win_comp_scroll(curwin);
3708#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003709#ifdef FEAT_CINDENT
3710 parse_cino(curbuf);
3711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003712}
3713
3714/*
3715 * Set the Vi-default value of a string option.
3716 * Used for 'sh', 'backupskip' and 'term'.
3717 */
3718 void
3719set_string_default(name, val)
3720 char *name;
3721 char_u *val;
3722{
3723 char_u *p;
3724 int opt_idx;
3725
3726 p = vim_strsave(val);
3727 if (p != NULL) /* we don't want a NULL */
3728 {
3729 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003730 if (opt_idx >= 0)
3731 {
3732 if (options[opt_idx].flags & P_DEF_ALLOCED)
3733 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3734 options[opt_idx].def_val[VI_DEFAULT] = p;
3735 options[opt_idx].flags |= P_DEF_ALLOCED;
3736 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737 }
3738}
3739
3740/*
3741 * Set the Vi-default value of a number option.
3742 * Used for 'lines' and 'columns'.
3743 */
3744 void
3745set_number_default(name, val)
3746 char *name;
3747 long val;
3748{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003749 int opt_idx;
3750
3751 opt_idx = findoption((char_u *)name);
3752 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003753 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003754}
3755
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003756#if defined(EXITFREE) || defined(PROTO)
3757/*
3758 * Free all options.
3759 */
3760 void
3761free_all_options()
3762{
3763 int i;
3764
3765 for (i = 0; !istermoption(&options[i]); i++)
3766 {
3767 if (options[i].indir == PV_NONE)
3768 {
3769 /* global option: free value and default value. */
3770 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3771 free_string_option(*(char_u **)options[i].var);
3772 if (options[i].flags & P_DEF_ALLOCED)
3773 free_string_option(options[i].def_val[VI_DEFAULT]);
3774 }
3775 else if (options[i].var != VAR_WIN
3776 && (options[i].flags & P_STRING))
3777 /* buffer-local option: free global value */
3778 free_string_option(*(char_u **)options[i].var);
3779 }
3780}
3781#endif
3782
3783
Bram Moolenaar071d4272004-06-13 20:20:40 +00003784/*
3785 * Initialize the options, part two: After getting Rows and Columns and
3786 * setting 'term'.
3787 */
3788 void
3789set_init_2()
3790{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003791 int idx;
3792
Bram Moolenaar071d4272004-06-13 20:20:40 +00003793 /*
3794 * 'scroll' defaults to half the window height. Note that this default is
3795 * wrong when the window height changes.
3796 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003797 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003798 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003799 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003800 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 comp_col();
3802
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003803 /*
3804 * 'window' is only for backwards compatibility with Vi.
3805 * Default is Rows - 1.
3806 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003807 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003808 p_window = Rows - 1;
3809 set_number_default("window", Rows - 1);
3810
Bram Moolenaarf740b292006-02-16 22:11:02 +00003811 /* For DOS console the default is always black. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812#if !((defined(MSDOS) || defined(OS2) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003813 /*
3814 * If 'background' wasn't set by the user, try guessing the value,
3815 * depending on the terminal name. Only need to check for terminals
3816 * with a dark background, that can handle color.
3817 */
3818 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003819 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3820 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003822 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003823 /* don't mark it as set, when starting the GUI it may be
3824 * changed again */
3825 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826 }
3827#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003828
3829#ifdef CURSOR_SHAPE
3830 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3831#endif
3832#ifdef FEAT_MOUSESHAPE
3833 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3834#endif
3835#ifdef FEAT_PRINTER
3836 (void)parse_printoptions(); /* parse 'printoptions' default value */
3837#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838}
3839
3840/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003841 * Return "dark" or "light" depending on the kind of terminal.
3842 * This is just guessing! Recognized are:
3843 * "linux" Linux console
3844 * "screen.linux" Linux console with screen
3845 * "cygwin" Cygwin shell
3846 * "putty" Putty program
3847 * We also check the COLORFGBG environment variable, which is set by
3848 * rxvt and derivatives. This variable contains either two or three
3849 * values separated by semicolons; we want the last value in either
3850 * case. If this value is 0-6 or 8, our background is dark.
3851 */
3852 static char_u *
3853term_bg_default()
3854{
Bram Moolenaarf740b292006-02-16 22:11:02 +00003855#if defined(MSDOS) || defined(OS2) || defined(WIN3264)
3856 /* DOS console nearly always black */
3857 return (char_u *)"dark";
3858#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003859 char_u *p;
3860
Bram Moolenaarf740b292006-02-16 22:11:02 +00003861 if (STRCMP(T_NAME, "linux") == 0
3862 || STRCMP(T_NAME, "screen.linux") == 0
3863 || STRCMP(T_NAME, "cygwin") == 0
3864 || STRCMP(T_NAME, "putty") == 0
3865 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3866 && (p = vim_strrchr(p, ';')) != NULL
3867 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3868 && p[2] == NUL))
3869 return (char_u *)"dark";
3870 return (char_u *)"light";
3871#endif
3872}
3873
3874/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875 * Initialize the options, part three: After reading the .vimrc
3876 */
3877 void
3878set_init_3()
3879{
3880#if defined(UNIX) || defined(OS2) || defined(WIN3264)
3881/*
3882 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3883 * This is done after other initializations, where 'shell' might have been
3884 * set, but only if they have not been set before.
3885 */
3886 char_u *p;
3887 int idx_srr;
3888 int do_srr;
3889#ifdef FEAT_QUICKFIX
3890 int idx_sp;
3891 int do_sp;
3892#endif
3893
3894 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003895 if (idx_srr < 0)
3896 do_srr = FALSE;
3897 else
3898 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003899#ifdef FEAT_QUICKFIX
3900 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003901 if (idx_sp < 0)
3902 do_sp = FALSE;
3903 else
3904 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003905#endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003906 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003907 if (p != NULL)
3908 {
3909 /*
3910 * Default for p_sp is "| tee", for p_srr is ">".
3911 * For known shells it is changed here to include stderr.
3912 */
3913 if ( fnamecmp(p, "csh") == 0
3914 || fnamecmp(p, "tcsh") == 0
3915# if defined(OS2) || defined(WIN3264) /* also check with .exe extension */
3916 || fnamecmp(p, "csh.exe") == 0
3917 || fnamecmp(p, "tcsh.exe") == 0
3918# endif
3919 )
3920 {
3921#if defined(FEAT_QUICKFIX)
3922 if (do_sp)
3923 {
3924# ifdef WIN3264
3925 p_sp = (char_u *)">&";
3926# else
3927 p_sp = (char_u *)"|& tee";
3928# endif
3929 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3930 }
3931#endif
3932 if (do_srr)
3933 {
3934 p_srr = (char_u *)">&";
3935 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3936 }
3937 }
3938 else
3939# ifndef OS2 /* Always use bourne shell style redirection if we reach this */
3940 if ( fnamecmp(p, "sh") == 0
3941 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003942 || fnamecmp(p, "mksh") == 0
3943 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003945 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003947 || fnamecmp(p, "fish") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948# ifdef WIN3264
3949 || fnamecmp(p, "cmd") == 0
3950 || fnamecmp(p, "sh.exe") == 0
3951 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003952 || fnamecmp(p, "mksh.exe") == 0
3953 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003955 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 || fnamecmp(p, "bash.exe") == 0
3957 || fnamecmp(p, "cmd.exe") == 0
3958# endif
3959 )
3960# endif
3961 {
3962#if defined(FEAT_QUICKFIX)
3963 if (do_sp)
3964 {
3965# ifdef WIN3264
3966 p_sp = (char_u *)">%s 2>&1";
3967# else
3968 p_sp = (char_u *)"2>&1| tee";
3969# endif
3970 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3971 }
3972#endif
3973 if (do_srr)
3974 {
3975 p_srr = (char_u *)">%s 2>&1";
3976 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3977 }
3978 }
3979 vim_free(p);
3980 }
3981#endif
3982
3983#if defined(MSDOS) || defined(WIN3264) || defined(OS2)
3984 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003985 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3986 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987 * This is done after other initializations, where 'shell' might have been
3988 * set, but only if they have not been set before. Default for p_shcf is
3989 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3990 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3991 * command.com. And for Win32 we need to set p_sxq instead.
3992 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003993 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 {
3995 int idx3;
3996
3997 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003998 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003999 {
4000 p_shcf = (char_u *)"-c";
4001 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4002 }
4003
4004# ifndef DJGPP
4005# ifdef WIN3264
4006 /* Somehow Win32 requires the quotes around the redirection too */
4007 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004008 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009 {
4010 p_sxq = (char_u *)"\"";
4011 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4012 }
4013# else
4014 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004015 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004016 {
4017 p_shq = (char_u *)"\"";
4018 options[idx3].def_val[VI_DEFAULT] = p_shq;
4019 }
4020# endif
4021# endif
4022 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004023 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4024 {
4025 int idx3;
4026
4027 /*
4028 * cmd.exe on Windows will strip the first and last double quote given
4029 * on the command line, e.g. most of the time things like:
4030 * cmd /c "my path/to/echo" "my args to echo"
4031 * become:
4032 * my path/to/echo" "my args to echo
4033 * when executed.
4034 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004035 * To avoid this, set shellxquote to surround the command in
4036 * parenthesis. This appears to make most commands work, without
4037 * breaking commands that worked previously, such as
4038 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004039 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004040 idx3 = findoption((char_u *)"sxq");
4041 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4042 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004043 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004044 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4045 }
4046
Bram Moolenaara64ba222012-02-12 23:23:31 +01004047 idx3 = findoption((char_u *)"shcf");
4048 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4049 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004050 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004051 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4052 }
4053 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054#endif
4055
4056#ifdef FEAT_TITLE
4057 set_title_defaults();
4058#endif
4059}
4060
4061#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4062/*
4063 * When 'helplang' is still at its default value, set it to "lang".
4064 * Only the first two characters of "lang" are used.
4065 */
4066 void
4067set_helplang_default(lang)
4068 char_u *lang;
4069{
4070 int idx;
4071
4072 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4073 return;
4074 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004075 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 {
4077 if (options[idx].flags & P_ALLOCED)
4078 free_string_option(p_hlg);
4079 p_hlg = vim_strsave(lang);
4080 if (p_hlg == NULL)
4081 p_hlg = empty_option;
4082 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004083 {
4084 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4085 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4086 {
4087 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4088 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4089 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004091 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 options[idx].flags |= P_ALLOCED;
4093 }
4094}
4095#endif
4096
4097#ifdef FEAT_GUI
4098static char_u *gui_bg_default __ARGS((void));
4099
4100 static char_u *
4101gui_bg_default()
4102{
4103 if (gui_get_lightness(gui.back_pixel) < 127)
4104 return (char_u *)"dark";
4105 return (char_u *)"light";
4106}
4107
4108/*
4109 * Option initializations that can only be done after opening the GUI window.
4110 */
4111 void
4112init_gui_options()
4113{
4114 /* Set the 'background' option according to the lightness of the
4115 * background color, unless the user has set it already. */
4116 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4117 {
4118 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4119 highlight_changed();
4120 }
4121}
4122#endif
4123
4124#ifdef FEAT_TITLE
4125/*
4126 * 'title' and 'icon' only default to true if they have not been set or reset
4127 * in .vimrc and we can read the old value.
4128 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4129 * they can be reset. This reduces startup time when using X on a remote
4130 * machine.
4131 */
4132 void
4133set_title_defaults()
4134{
4135 int idx1;
4136 long val;
4137
4138 /*
4139 * If GUI is (going to be) used, we can always set the window title and
4140 * icon name. Saves a bit of time, because the X11 display server does
4141 * not need to be contacted.
4142 */
4143 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004144 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 {
4146#ifdef FEAT_GUI
4147 if (gui.starting || gui.in_use)
4148 val = TRUE;
4149 else
4150#endif
4151 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004152 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 p_title = val;
4154 }
4155 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004156 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 {
4158#ifdef FEAT_GUI
4159 if (gui.starting || gui.in_use)
4160 val = TRUE;
4161 else
4162#endif
4163 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004164 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165 p_icon = val;
4166 }
4167}
4168#endif
4169
4170/*
4171 * Parse 'arg' for option settings.
4172 *
4173 * 'arg' may be IObuff, but only when no errors can be present and option
4174 * does not need to be expanded with option_expand().
4175 * "opt_flags":
4176 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004177 * OPT_GLOBAL for ":setglobal"
4178 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004180 * OPT_WINONLY to only set window-local options
4181 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182 *
4183 * returns FAIL if an error is detected, OK otherwise
4184 */
4185 int
4186do_set(arg, opt_flags)
4187 char_u *arg; /* option string (may be written to!) */
4188 int opt_flags;
4189{
4190 int opt_idx;
4191 char_u *errmsg;
4192 char_u errbuf[80];
4193 char_u *startarg;
4194 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4195 int nextchar; /* next non-white char after option name */
4196 int afterchar; /* character just after option name */
4197 int len;
4198 int i;
4199 long value;
4200 int key;
4201 long_u flags; /* flags for current option */
4202 char_u *varp = NULL; /* pointer to variable for current option */
4203 int did_show = FALSE; /* already showed one value */
4204 int adding; /* "opt+=arg" */
4205 int prepending; /* "opt^=arg" */
4206 int removing; /* "opt-=arg" */
4207 int cp_val = 0;
4208 char_u key_name[2];
4209
4210 if (*arg == NUL)
4211 {
4212 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004213 did_show = TRUE;
4214 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215 }
4216
4217 while (*arg != NUL) /* loop to process all options */
4218 {
4219 errmsg = NULL;
4220 startarg = arg; /* remember for error message */
4221
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004222 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4223 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224 {
4225 /*
4226 * ":set all" show all options.
4227 * ":set all&" set all options to their default value.
4228 */
4229 arg += 3;
4230 if (*arg == '&')
4231 {
4232 ++arg;
4233 /* Only for :set command set global value of local options. */
4234 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004235 didset_options();
4236 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004237 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238 }
4239 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004240 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004241 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004242 did_show = TRUE;
4243 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004244 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004245 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246 {
4247 showoptions(2, opt_flags);
4248 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004249 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004250 arg += 7;
4251 }
4252 else
4253 {
4254 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004255 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256 {
4257 prefix = 0;
4258 arg += 2;
4259 }
4260 else if (STRNCMP(arg, "inv", 3) == 0)
4261 {
4262 prefix = 2;
4263 arg += 3;
4264 }
4265
4266 /* find end of name */
4267 key = 0;
4268 if (*arg == '<')
4269 {
4270 nextchar = 0;
4271 opt_idx = -1;
4272 /* look out for <t_>;> */
4273 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4274 len = 5;
4275 else
4276 {
4277 len = 1;
4278 while (arg[len] != NUL && arg[len] != '>')
4279 ++len;
4280 }
4281 if (arg[len] != '>')
4282 {
4283 errmsg = e_invarg;
4284 goto skip;
4285 }
4286 arg[len] = NUL; /* put NUL after name */
4287 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4288 opt_idx = findoption(arg + 1);
4289 arg[len++] = '>'; /* restore '>' */
4290 if (opt_idx == -1)
4291 key = find_key_option(arg + 1);
4292 }
4293 else
4294 {
4295 len = 0;
4296 /*
4297 * The two characters after "t_" may not be alphanumeric.
4298 */
4299 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4300 len = 4;
4301 else
4302 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4303 ++len;
4304 nextchar = arg[len];
4305 arg[len] = NUL; /* put NUL after name */
4306 opt_idx = findoption(arg);
4307 arg[len] = nextchar; /* restore nextchar */
4308 if (opt_idx == -1)
4309 key = find_key_option(arg);
4310 }
4311
4312 /* remember character after option name */
4313 afterchar = arg[len];
4314
4315 /* skip white space, allow ":set ai ?" */
4316 while (vim_iswhite(arg[len]))
4317 ++len;
4318
4319 adding = FALSE;
4320 prepending = FALSE;
4321 removing = FALSE;
4322 if (arg[len] != NUL && arg[len + 1] == '=')
4323 {
4324 if (arg[len] == '+')
4325 {
4326 adding = TRUE; /* "+=" */
4327 ++len;
4328 }
4329 else if (arg[len] == '^')
4330 {
4331 prepending = TRUE; /* "^=" */
4332 ++len;
4333 }
4334 else if (arg[len] == '-')
4335 {
4336 removing = TRUE; /* "-=" */
4337 ++len;
4338 }
4339 }
4340 nextchar = arg[len];
4341
4342 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4343 {
4344 errmsg = (char_u *)N_("E518: Unknown option");
4345 goto skip;
4346 }
4347
4348 if (opt_idx >= 0)
4349 {
4350 if (options[opt_idx].var == NULL) /* hidden option: skip */
4351 {
4352 /* Only give an error message when requesting the value of
4353 * a hidden option, ignore setting it. */
4354 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4355 && (!(options[opt_idx].flags & P_BOOL)
4356 || nextchar == '?'))
4357 errmsg = (char_u *)N_("E519: Option not supported");
4358 goto skip;
4359 }
4360
4361 flags = options[opt_idx].flags;
4362 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4363 }
4364 else
4365 {
4366 flags = P_STRING;
4367 if (key < 0)
4368 {
4369 key_name[0] = KEY2TERMCAP0(key);
4370 key_name[1] = KEY2TERMCAP1(key);
4371 }
4372 else
4373 {
4374 key_name[0] = KS_KEY;
4375 key_name[1] = (key & 0xff);
4376 }
4377 }
4378
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004379 /* Skip all options that are not window-local (used when showing
4380 * an already loaded buffer in a window). */
4381 if ((opt_flags & OPT_WINONLY)
4382 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4383 goto skip;
4384
Bram Moolenaara3227e22006-03-08 21:32:40 +00004385 /* Skip all options that are window-local (used for :vimgrep). */
4386 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4387 && options[opt_idx].var == VAR_WIN)
4388 goto skip;
4389
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004390 /* Disallow changing some options from modelines. */
4391 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004392 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004393 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004394 {
4395 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4396 goto skip;
4397 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004398#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004399 /* In diff mode some options are overruled. This avoids that
4400 * 'foldmethod' becomes "marker" instead of "diff" and that
4401 * "wrap" gets set. */
4402 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004403 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004404 && (options[opt_idx].indir == PV_FDM
4405 || options[opt_idx].indir == PV_WRAP))
4406 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004407#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 }
4409
4410#ifdef HAVE_SANDBOX
4411 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004412 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004413 {
4414 errmsg = (char_u *)_(e_sandbox);
4415 goto skip;
4416 }
4417#endif
4418
4419 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4420 {
4421 arg += len;
4422 cp_val = p_cp;
4423 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4424 {
4425 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4426 {
4427 cp_val = FALSE;
4428 arg += 3;
4429 }
4430 else /* "opt&vi": set to Vi default */
4431 {
4432 cp_val = TRUE;
4433 arg += 2;
4434 }
4435 }
4436 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4437 && arg[1] != NUL && !vim_iswhite(arg[1]))
4438 {
4439 errmsg = e_trailing;
4440 goto skip;
4441 }
4442 }
4443
4444 /*
4445 * allow '=' and ':' as MSDOS command.com allows only one
4446 * '=' character per "set" command line. grrr. (jw)
4447 */
4448 if (nextchar == '?'
4449 || (prefix == 1
4450 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4451 && !(flags & P_BOOL)))
4452 {
4453 /*
4454 * print value
4455 */
4456 if (did_show)
4457 msg_putchar('\n'); /* cursor below last one */
4458 else
4459 {
4460 gotocmdline(TRUE); /* cursor at status line */
4461 did_show = TRUE; /* remember that we did a line */
4462 }
4463 if (opt_idx >= 0)
4464 {
4465 showoneopt(&options[opt_idx], opt_flags);
4466#ifdef FEAT_EVAL
4467 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004468 {
4469 /* Mention where the option was last set. */
4470 if (varp == options[opt_idx].var)
4471 last_set_msg(options[opt_idx].scriptID);
4472 else if ((int)options[opt_idx].indir & PV_WIN)
4473 last_set_msg(curwin->w_p_scriptID[
4474 (int)options[opt_idx].indir & PV_MASK]);
4475 else if ((int)options[opt_idx].indir & PV_BUF)
4476 last_set_msg(curbuf->b_p_scriptID[
4477 (int)options[opt_idx].indir & PV_MASK]);
4478 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004479#endif
4480 }
4481 else
4482 {
4483 char_u *p;
4484
4485 p = find_termcode(key_name);
4486 if (p == NULL)
4487 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004488 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004489 goto skip;
4490 }
4491 else
4492 (void)show_one_termcode(key_name, p, TRUE);
4493 }
4494 if (nextchar != '?'
4495 && nextchar != NUL && !vim_iswhite(afterchar))
4496 errmsg = e_trailing;
4497 }
4498 else
4499 {
4500 if (flags & P_BOOL) /* boolean */
4501 {
4502 if (nextchar == '=' || nextchar == ':')
4503 {
4504 errmsg = e_invarg;
4505 goto skip;
4506 }
4507
4508 /*
4509 * ":set opt!": invert
4510 * ":set opt&": reset to default value
4511 * ":set opt<": reset to global value
4512 */
4513 if (nextchar == '!')
4514 value = *(int *)(varp) ^ 1;
4515 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004516 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004517 ((flags & P_VI_DEF) || cp_val)
4518 ? VI_DEFAULT : VIM_DEFAULT];
4519 else if (nextchar == '<')
4520 {
4521 /* For 'autoread' -1 means to use global value. */
4522 if ((int *)varp == &curbuf->b_p_ar
4523 && opt_flags == OPT_LOCAL)
4524 value = -1;
4525 else
4526 value = *(int *)get_varp_scope(&(options[opt_idx]),
4527 OPT_GLOBAL);
4528 }
4529 else
4530 {
4531 /*
4532 * ":set invopt": invert
4533 * ":set opt" or ":set noopt": set or reset
4534 */
4535 if (nextchar != NUL && !vim_iswhite(afterchar))
4536 {
4537 errmsg = e_trailing;
4538 goto skip;
4539 }
4540 if (prefix == 2) /* inv */
4541 value = *(int *)(varp) ^ 1;
4542 else
4543 value = prefix;
4544 }
4545
4546 errmsg = set_bool_option(opt_idx, varp, (int)value,
4547 opt_flags);
4548 }
4549 else /* numeric or string */
4550 {
4551 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4552 || prefix != 1)
4553 {
4554 errmsg = e_invarg;
4555 goto skip;
4556 }
4557
4558 if (flags & P_NUM) /* numeric */
4559 {
4560 /*
4561 * Different ways to set a number option:
4562 * & set to default value
4563 * < set to global value
4564 * <xx> accept special key codes for 'wildchar'
4565 * c accept any non-digit for 'wildchar'
4566 * [-]0-9 set number
4567 * other error
4568 */
4569 ++arg;
4570 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004571 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004572 ((flags & P_VI_DEF) || cp_val)
4573 ? VI_DEFAULT : VIM_DEFAULT];
4574 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004575 {
4576 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4577 * use the global value. */
4578 if ((long *)varp == &curbuf->b_p_ul
4579 && opt_flags == OPT_LOCAL)
4580 value = NO_LOCAL_UNDOLEVEL;
4581 else
4582 value = *(long *)get_varp_scope(
4583 &(options[opt_idx]), OPT_GLOBAL);
4584 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004585 else if (((long *)varp == &p_wc
4586 || (long *)varp == &p_wcm)
4587 && (*arg == '<'
4588 || *arg == '^'
4589 || ((!arg[1] || vim_iswhite(arg[1]))
4590 && !VIM_ISDIGIT(*arg))))
4591 {
4592 value = string_to_key(arg);
4593 if (value == 0 && (long *)varp != &p_wcm)
4594 {
4595 errmsg = e_invarg;
4596 goto skip;
4597 }
4598 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004599 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4600 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004601 /* Allow negative (for 'undolevels'), octal and
4602 * hex numbers. */
Bram Moolenaar5d1bc782015-07-17 13:03:48 +02004603 vim_str2nr(arg, NULL, &i, TRUE, TRUE, &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004604 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4605 {
4606 errmsg = e_invarg;
4607 goto skip;
4608 }
4609 }
4610 else
4611 {
4612 errmsg = (char_u *)N_("E521: Number required after =");
4613 goto skip;
4614 }
4615
4616 if (adding)
4617 value = *(long *)varp + value;
4618 if (prepending)
4619 value = *(long *)varp * value;
4620 if (removing)
4621 value = *(long *)varp - value;
4622 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004623 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004624 }
4625 else if (opt_idx >= 0) /* string */
4626 {
4627 char_u *save_arg = NULL;
4628 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004629 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004630 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004631 char_u *origval = NULL;
4632#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4633 char_u *saved_origval = NULL;
4634#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004635 unsigned newlen;
4636 int comma;
4637 int bs;
4638 int new_value_alloced; /* new string option
4639 was allocated */
4640
4641 /* When using ":set opt=val" for a global option
4642 * with a local value the local value will be
4643 * reset, use the global value here. */
4644 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004645 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004646 varp = options[opt_idx].var;
4647
4648 /* The old value is kept until we are sure that the
4649 * new value is valid. */
4650 oldval = *(char_u **)varp;
4651 if (nextchar == '&') /* set to default val */
4652 {
4653 newval = options[opt_idx].def_val[
4654 ((flags & P_VI_DEF) || cp_val)
4655 ? VI_DEFAULT : VIM_DEFAULT];
4656 if ((char_u **)varp == &p_bg)
4657 {
4658 /* guess the value of 'background' */
4659#ifdef FEAT_GUI
4660 if (gui.in_use)
4661 newval = gui_bg_default();
4662 else
4663#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004664 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004665 }
4666
4667 /* expand environment variables and ~ (since the
4668 * default value was already expanded, only
4669 * required when an environment variable was set
4670 * later */
4671 if (newval == NULL)
4672 newval = empty_option;
4673 else
4674 {
4675 s = option_expand(opt_idx, newval);
4676 if (s == NULL)
4677 s = newval;
4678 newval = vim_strsave(s);
4679 }
4680 new_value_alloced = TRUE;
4681 }
4682 else if (nextchar == '<') /* set to global val */
4683 {
4684 newval = vim_strsave(*(char_u **)get_varp_scope(
4685 &(options[opt_idx]), OPT_GLOBAL));
4686 new_value_alloced = TRUE;
4687 }
4688 else
4689 {
4690 ++arg; /* jump to after the '=' or ':' */
4691
4692 /*
4693 * Set 'keywordprg' to ":help" if an empty
4694 * value was passed to :set by the user.
4695 * Misuse errbuf[] for the resulting string.
4696 */
4697 if (varp == (char_u *)&p_kp
4698 && (*arg == NUL || *arg == ' '))
4699 {
4700 STRCPY(errbuf, ":help");
4701 save_arg = arg;
4702 arg = errbuf;
4703 }
4704 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004705 * Convert 'backspace' number to string, for
4706 * adding, prepending and removing string.
4707 */
4708 else if (varp == (char_u *)&p_bs
4709 && VIM_ISDIGIT(**(char_u **)varp))
4710 {
4711 i = getdigits((char_u **)varp);
4712 switch (i)
4713 {
4714 case 0:
4715 *(char_u **)varp = empty_option;
4716 break;
4717 case 1:
4718 *(char_u **)varp = vim_strsave(
4719 (char_u *)"indent,eol");
4720 break;
4721 case 2:
4722 *(char_u **)varp = vim_strsave(
4723 (char_u *)"indent,eol,start");
4724 break;
4725 }
4726 vim_free(oldval);
4727 oldval = *(char_u **)varp;
4728 }
4729 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004730 * Convert 'whichwrap' number to string, for
4731 * backwards compatibility with Vim 3.0.
4732 * Misuse errbuf[] for the resulting string.
4733 */
4734 else if (varp == (char_u *)&p_ww
4735 && VIM_ISDIGIT(*arg))
4736 {
4737 *errbuf = NUL;
4738 i = getdigits(&arg);
4739 if (i & 1)
4740 STRCAT(errbuf, "b,");
4741 if (i & 2)
4742 STRCAT(errbuf, "s,");
4743 if (i & 4)
4744 STRCAT(errbuf, "h,l,");
4745 if (i & 8)
4746 STRCAT(errbuf, "<,>,");
4747 if (i & 16)
4748 STRCAT(errbuf, "[,],");
4749 if (*errbuf != NUL) /* remove trailing , */
4750 errbuf[STRLEN(errbuf) - 1] = NUL;
4751 save_arg = arg;
4752 arg = errbuf;
4753 }
4754 /*
4755 * Remove '>' before 'dir' and 'bdir', for
4756 * backwards compatibility with version 3.0
4757 */
4758 else if ( *arg == '>'
4759 && (varp == (char_u *)&p_dir
4760 || varp == (char_u *)&p_bdir))
4761 {
4762 ++arg;
4763 }
4764
4765 /* When setting the local value of a global
4766 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004767 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004768 && (opt_flags & OPT_LOCAL))
4769 origval = *(char_u **)get_varp(
4770 &options[opt_idx]);
4771 else
4772 origval = oldval;
4773
4774 /*
4775 * Copy the new string into allocated memory.
4776 * Can't use set_string_option_direct(), because
4777 * we need to remove the backslashes.
4778 */
4779 /* get a bit too much */
4780 newlen = (unsigned)STRLEN(arg) + 1;
4781 if (adding || prepending || removing)
4782 newlen += (unsigned)STRLEN(origval) + 1;
4783 newval = alloc(newlen);
4784 if (newval == NULL) /* out of mem, don't change */
4785 break;
4786 s = newval;
4787
4788 /*
4789 * Copy the string, skip over escaped chars.
4790 * For MS-DOS and WIN32 backslashes before normal
4791 * file name characters are not removed, and keep
4792 * backslash at start, for "\\machine\path", but
4793 * do remove it for "\\\\machine\\path".
4794 * The reverse is found in ExpandOldSetting().
4795 */
4796 while (*arg && !vim_iswhite(*arg))
4797 {
4798 if (*arg == '\\' && arg[1] != NUL
4799#ifdef BACKSLASH_IN_FILENAME
4800 && !((flags & P_EXPAND)
4801 && vim_isfilec(arg[1])
4802 && (arg[1] != '\\'
4803 || (s == newval
4804 && arg[2] != '\\')))
4805#endif
4806 )
4807 ++arg; /* remove backslash */
4808#ifdef FEAT_MBYTE
4809 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004810 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004811 {
4812 /* copy multibyte char */
4813 mch_memmove(s, arg, (size_t)i);
4814 arg += i;
4815 s += i;
4816 }
4817 else
4818#endif
4819 *s++ = *arg++;
4820 }
4821 *s = NUL;
4822
4823 /*
4824 * Expand environment variables and ~.
4825 * Don't do it when adding without inserting a
4826 * comma.
4827 */
4828 if (!(adding || prepending || removing)
4829 || (flags & P_COMMA))
4830 {
4831 s = option_expand(opt_idx, newval);
4832 if (s != NULL)
4833 {
4834 vim_free(newval);
4835 newlen = (unsigned)STRLEN(s) + 1;
4836 if (adding || prepending || removing)
4837 newlen += (unsigned)STRLEN(origval) + 1;
4838 newval = alloc(newlen);
4839 if (newval == NULL)
4840 break;
4841 STRCPY(newval, s);
4842 }
4843 }
4844
4845 /* locate newval[] in origval[] when removing it
4846 * and when adding to avoid duplicates */
4847 i = 0; /* init for GCC */
4848 if (removing || (flags & P_NODUP))
4849 {
4850 i = (int)STRLEN(newval);
4851 bs = 0;
4852 for (s = origval; *s; ++s)
4853 {
4854 if ((!(flags & P_COMMA)
4855 || s == origval
4856 || (s[-1] == ',' && !(bs & 1)))
4857 && STRNCMP(s, newval, i) == 0
4858 && (!(flags & P_COMMA)
4859 || s[i] == ','
4860 || s[i] == NUL))
4861 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004862 /* Count backslashes. Only a comma with an
4863 * even number of backslashes before it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00004864 * recognized as a separator */
4865 if (s > origval && s[-1] == '\\')
4866 ++bs;
4867 else
4868 bs = 0;
4869 }
4870
4871 /* do not add if already there */
4872 if ((adding || prepending) && *s)
4873 {
4874 prepending = FALSE;
4875 adding = FALSE;
4876 STRCPY(newval, origval);
4877 }
4878 }
4879
4880 /* concatenate the two strings; add a ',' if
4881 * needed */
4882 if (adding || prepending)
4883 {
4884 comma = ((flags & P_COMMA) && *origval != NUL
4885 && *newval != NUL);
4886 if (adding)
4887 {
4888 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004889 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004890 if (comma && i > 1
4891 && (flags & P_ONECOMMA) == P_ONECOMMA
4892 && origval[i - 1] == ','
4893 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004894 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004895 mch_memmove(newval + i + comma, newval,
4896 STRLEN(newval) + 1);
4897 mch_memmove(newval, origval, (size_t)i);
4898 }
4899 else
4900 {
4901 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004902 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004903 }
4904 if (comma)
4905 newval[i] = ',';
4906 }
4907
4908 /* Remove newval[] from origval[]. (Note: "i" has
4909 * been set above and is used here). */
4910 if (removing)
4911 {
4912 STRCPY(newval, origval);
4913 if (*s)
4914 {
4915 /* may need to remove a comma */
4916 if (flags & P_COMMA)
4917 {
4918 if (s == origval)
4919 {
4920 /* include comma after string */
4921 if (s[i] == ',')
4922 ++i;
4923 }
4924 else
4925 {
4926 /* include comma before string */
4927 --s;
4928 ++i;
4929 }
4930 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004931 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004932 }
4933 }
4934
4935 if (flags & P_FLAGLIST)
4936 {
4937 /* Remove flags that appear twice. */
4938 for (s = newval; *s; ++s)
4939 if ((!(flags & P_COMMA) || *s != ',')
4940 && vim_strchr(s + 1, *s) != NULL)
4941 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004942 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004943 --s;
4944 }
4945 }
4946
4947 if (save_arg != NULL) /* number for 'whichwrap' */
4948 arg = save_arg;
4949 new_value_alloced = TRUE;
4950 }
4951
4952 /* Set the new value. */
4953 *(char_u **)(varp) = newval;
4954
Bram Moolenaar53744302015-07-17 17:38:22 +02004955#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004956 if (!starting
4957# ifdef FEAT_CRYPT
4958 && options[opt_idx].indir != PV_KEY
4959# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004960 && origval != NULL)
4961 /* origval may be freed by
4962 * did_set_string_option(), make a copy. */
4963 saved_origval = vim_strsave(origval);
4964#endif
4965
Bram Moolenaar071d4272004-06-13 20:20:40 +00004966 /* Handle side effects, and set the global value for
4967 * ":set" on local options. */
4968 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4969 new_value_alloced, oldval, errbuf, opt_flags);
4970
4971 /* If error detected, print the error message. */
4972 if (errmsg != NULL)
4973 goto skip;
Bram Moolenaar53744302015-07-17 17:38:22 +02004974#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4975 if (saved_origval != NULL)
4976 {
4977 char_u buf_type[7];
4978
4979 sprintf((char *)buf_type, "%s",
4980 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004981 set_vim_var_string(VV_OPTION_NEW,
4982 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004983 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4984 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4985 apply_autocmds(EVENT_OPTIONSET,
4986 (char_u *)options[opt_idx].fullname,
4987 NULL, FALSE, NULL);
4988 reset_v_option_vars();
4989 vim_free(saved_origval);
4990 }
4991#endif
4992
Bram Moolenaar071d4272004-06-13 20:20:40 +00004993 }
4994 else /* key code option */
4995 {
4996 char_u *p;
4997
4998 if (nextchar == '&')
4999 {
5000 if (add_termcap_entry(key_name, TRUE) == FAIL)
5001 errmsg = (char_u *)N_("E522: Not found in termcap");
5002 }
5003 else
5004 {
5005 ++arg; /* jump to after the '=' or ':' */
5006 for (p = arg; *p && !vim_iswhite(*p); ++p)
5007 if (*p == '\\' && p[1] != NUL)
5008 ++p;
5009 nextchar = *p;
5010 *p = NUL;
5011 add_termcode(key_name, arg, FALSE);
5012 *p = nextchar;
5013 }
5014 if (full_screen)
5015 ttest(FALSE);
5016 redraw_all_later(CLEAR);
5017 }
5018 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005019
Bram Moolenaar071d4272004-06-13 20:20:40 +00005020 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005021 did_set_option(opt_idx, opt_flags,
5022 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005023 }
5024
5025skip:
5026 /*
5027 * Advance to next argument.
5028 * - skip until a blank found, taking care of backslashes
5029 * - skip blanks
5030 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5031 */
5032 for (i = 0; i < 2 ; ++i)
5033 {
5034 while (*arg != NUL && !vim_iswhite(*arg))
5035 if (*arg++ == '\\' && *arg != NUL)
5036 ++arg;
5037 arg = skipwhite(arg);
5038 if (*arg != '=')
5039 break;
5040 }
5041 }
5042
5043 if (errmsg != NULL)
5044 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005045 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005046 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005047 if (i + (arg - startarg) < IOSIZE)
5048 {
5049 /* append the argument with the error */
5050 STRCAT(IObuff, ": ");
5051 mch_memmove(IObuff + i, startarg, (arg - startarg));
5052 IObuff[i + (arg - startarg)] = NUL;
5053 }
5054 /* make sure all characters are printable */
5055 trans_characters(IObuff, IOSIZE);
5056
5057 ++no_wait_return; /* wait_return done later */
5058 emsg(IObuff); /* show error highlighted */
5059 --no_wait_return;
5060
5061 return FAIL;
5062 }
5063
5064 arg = skipwhite(arg);
5065 }
5066
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005067theend:
5068 if (silent_mode && did_show)
5069 {
5070 /* After displaying option values in silent mode. */
5071 silent_mode = FALSE;
5072 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5073 msg_putchar('\n');
5074 cursor_on(); /* msg_start() switches it off */
5075 out_flush();
5076 silent_mode = TRUE;
5077 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5078 }
5079
Bram Moolenaar071d4272004-06-13 20:20:40 +00005080 return OK;
5081}
5082
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005083/*
5084 * Call this when an option has been given a new value through a user command.
5085 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5086 */
5087 static void
5088did_set_option(opt_idx, opt_flags, new_value)
5089 int opt_idx;
5090 int opt_flags; /* possibly with OPT_MODELINE */
5091 int new_value; /* value was replaced completely */
5092{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005093 long_u *p;
5094
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005095 options[opt_idx].flags |= P_WAS_SET;
5096
5097 /* When an option is set in the sandbox, from a modeline or in secure mode
5098 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005099 * flag. */
5100 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005101 if (secure
5102#ifdef HAVE_SANDBOX
5103 || sandbox != 0
5104#endif
5105 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005106 *p = *p | P_INSECURE;
5107 else if (new_value)
5108 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005109}
5110
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 static char_u *
5112illegal_char(errbuf, c)
5113 char_u *errbuf;
5114 int c;
5115{
5116 if (errbuf == NULL)
5117 return (char_u *)"";
5118 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005119 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120 return errbuf;
5121}
5122
5123/*
5124 * Convert a key name or string into a key value.
5125 * Used for 'wildchar' and 'cedit' options.
5126 */
5127 static int
5128string_to_key(arg)
5129 char_u *arg;
5130{
5131 if (*arg == '<')
5132 return find_key_option(arg + 1);
5133 if (*arg == '^')
5134 return Ctrl_chr(arg[1]);
5135 return *arg;
5136}
5137
5138#ifdef FEAT_CMDWIN
5139/*
5140 * Check value of 'cedit' and set cedit_key.
5141 * Returns NULL if value is OK, error message otherwise.
5142 */
5143 static char_u *
5144check_cedit()
5145{
5146 int n;
5147
5148 if (*p_cedit == NUL)
5149 cedit_key = -1;
5150 else
5151 {
5152 n = string_to_key(p_cedit);
5153 if (vim_isprintc(n))
5154 return e_invarg;
5155 cedit_key = n;
5156 }
5157 return NULL;
5158}
5159#endif
5160
5161#ifdef FEAT_TITLE
5162/*
5163 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5164 * maketitle() to create and display it.
5165 * When switching the title or icon off, call mch_restore_title() to get
5166 * the old value back.
5167 */
5168 static void
5169did_set_title(icon)
5170 int icon; /* Did set icon instead of title */
5171{
5172 if (starting != NO_SCREEN
5173#ifdef FEAT_GUI
5174 && !gui.starting
5175#endif
5176 )
5177 {
5178 maketitle();
5179 if (icon)
5180 {
5181 if (!p_icon)
5182 mch_restore_title(2);
5183 }
5184 else
5185 {
5186 if (!p_title)
5187 mch_restore_title(1);
5188 }
5189 }
5190}
5191#endif
5192
5193/*
5194 * set_options_bin - called when 'bin' changes value.
5195 */
5196 void
5197set_options_bin(oldval, newval, opt_flags)
5198 int oldval;
5199 int newval;
5200 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5201{
5202 /*
5203 * The option values that are changed when 'bin' changes are
5204 * copied when 'bin is set and restored when 'bin' is reset.
5205 */
5206 if (newval)
5207 {
5208 if (!oldval) /* switched on */
5209 {
5210 if (!(opt_flags & OPT_GLOBAL))
5211 {
5212 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5213 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5214 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5215 curbuf->b_p_et_nobin = curbuf->b_p_et;
5216 }
5217 if (!(opt_flags & OPT_LOCAL))
5218 {
5219 p_tw_nobin = p_tw;
5220 p_wm_nobin = p_wm;
5221 p_ml_nobin = p_ml;
5222 p_et_nobin = p_et;
5223 }
5224 }
5225
5226 if (!(opt_flags & OPT_GLOBAL))
5227 {
5228 curbuf->b_p_tw = 0; /* no automatic line wrap */
5229 curbuf->b_p_wm = 0; /* no automatic line wrap */
5230 curbuf->b_p_ml = 0; /* no modelines */
5231 curbuf->b_p_et = 0; /* no expandtab */
5232 }
5233 if (!(opt_flags & OPT_LOCAL))
5234 {
5235 p_tw = 0;
5236 p_wm = 0;
5237 p_ml = FALSE;
5238 p_et = FALSE;
5239 p_bin = TRUE; /* needed when called for the "-b" argument */
5240 }
5241 }
5242 else if (oldval) /* switched off */
5243 {
5244 if (!(opt_flags & OPT_GLOBAL))
5245 {
5246 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5247 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5248 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5249 curbuf->b_p_et = curbuf->b_p_et_nobin;
5250 }
5251 if (!(opt_flags & OPT_LOCAL))
5252 {
5253 p_tw = p_tw_nobin;
5254 p_wm = p_wm_nobin;
5255 p_ml = p_ml_nobin;
5256 p_et = p_et_nobin;
5257 }
5258 }
5259}
5260
5261#ifdef FEAT_VIMINFO
5262/*
5263 * Find the parameter represented by the given character (eg ', :, ", or /),
5264 * and return its associated value in the 'viminfo' string.
5265 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005266 * If the parameter is not specified in the string or there is no following
5267 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005268 */
5269 int
5270get_viminfo_parameter(type)
5271 int type;
5272{
5273 char_u *p;
5274
5275 p = find_viminfo_parameter(type);
5276 if (p != NULL && VIM_ISDIGIT(*p))
5277 return atoi((char *)p);
5278 return -1;
5279}
5280
5281/*
5282 * Find the parameter represented by the given character (eg ''', ':', '"', or
5283 * '/') in the 'viminfo' option and return a pointer to the string after it.
5284 * Return NULL if the parameter is not specified in the string.
5285 */
5286 char_u *
5287find_viminfo_parameter(type)
5288 int type;
5289{
5290 char_u *p;
5291
5292 for (p = p_viminfo; *p; ++p)
5293 {
5294 if (*p == type)
5295 return p + 1;
5296 if (*p == 'n') /* 'n' is always the last one */
5297 break;
5298 p = vim_strchr(p, ','); /* skip until next ',' */
5299 if (p == NULL) /* hit the end without finding parameter */
5300 break;
5301 }
5302 return NULL;
5303}
5304#endif
5305
5306/*
5307 * Expand environment variables for some string options.
5308 * These string options cannot be indirect!
5309 * If "val" is NULL expand the current value of the option.
5310 * Return pointer to NameBuff, or NULL when not expanded.
5311 */
5312 static char_u *
5313option_expand(opt_idx, val)
5314 int opt_idx;
5315 char_u *val;
5316{
5317 /* if option doesn't need expansion nothing to do */
5318 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5319 return NULL;
5320
5321 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5322 * expand_env() would truncate the string. */
5323 if (val != NULL && STRLEN(val) > MAXPATHL)
5324 return NULL;
5325
5326 if (val == NULL)
5327 val = *(char_u **)options[opt_idx].var;
5328
5329 /*
5330 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5331 * Escape spaces when expanding 'tags', they are used to separate file
5332 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005333 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005334 */
5335 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005336 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005337#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005338 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5339#endif
5340 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005341 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5342 return NULL;
5343
5344 return NameBuff;
5345}
5346
5347/*
5348 * After setting various option values: recompute variables that depend on
5349 * option values.
5350 */
5351 static void
5352didset_options()
5353{
5354 /* initialize the table for 'iskeyword' et.al. */
5355 (void)init_chartab();
5356
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005357#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005358 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005360 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005361 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362#ifdef FEAT_SESSION
5363 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5364 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5365#endif
5366#ifdef FEAT_FOLDING
5367 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5368#endif
5369 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005370 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005371#ifdef FEAT_VIRTUALEDIT
5372 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5373#endif
5374#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5375 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5376#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005377#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005378 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005379 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005380 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005381 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005382#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005383#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5384 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5385#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005386#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5388#endif
5389#ifdef FEAT_CMDWIN
5390 /* set cedit_key */
5391 (void)check_cedit();
5392#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005393#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005394 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005395#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005396#ifdef FEAT_LINEBREAK
5397 /* initialize the table for 'breakat'. */
5398 fill_breakat_flags();
5399#endif
5400
5401}
5402
5403/*
5404 * More side effects of setting options.
5405 */
5406 static void
5407didset_options2()
5408{
5409 /* Initialize the highlight_attr[] table. */
5410 (void)highlight_changed();
5411
5412 /* Parse default for 'wildmode' */
5413 check_opt_wim();
5414
5415 (void)set_chars_option(&p_lcs);
5416#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5417 /* Parse default for 'fillchars'. */
5418 (void)set_chars_option(&p_fcs);
5419#endif
5420
5421#ifdef FEAT_CLIPBOARD
5422 /* Parse default for 'clipboard' */
5423 (void)check_clipboard_option();
5424#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005425}
5426
5427/*
5428 * Check for string options that are NULL (normally only termcap options).
5429 */
5430 void
5431check_options()
5432{
5433 int opt_idx;
5434
5435 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5436 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5437 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5438}
5439
5440/*
5441 * Check string options in a buffer for NULL value.
5442 */
5443 void
5444check_buf_options(buf)
5445 buf_T *buf;
5446{
5447#if defined(FEAT_QUICKFIX)
5448 check_string_option(&buf->b_p_bh);
5449 check_string_option(&buf->b_p_bt);
5450#endif
5451#ifdef FEAT_MBYTE
5452 check_string_option(&buf->b_p_fenc);
5453#endif
5454 check_string_option(&buf->b_p_ff);
5455#ifdef FEAT_FIND_ID
5456 check_string_option(&buf->b_p_def);
5457 check_string_option(&buf->b_p_inc);
5458# ifdef FEAT_EVAL
5459 check_string_option(&buf->b_p_inex);
5460# endif
5461#endif
5462#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5463 check_string_option(&buf->b_p_inde);
5464 check_string_option(&buf->b_p_indk);
5465#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005466#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5467 check_string_option(&buf->b_p_bexpr);
5468#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005469#if defined(FEAT_CRYPT)
5470 check_string_option(&buf->b_p_cm);
5471#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005472#if defined(FEAT_EVAL)
5473 check_string_option(&buf->b_p_fex);
5474#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005475#ifdef FEAT_CRYPT
5476 check_string_option(&buf->b_p_key);
5477#endif
5478 check_string_option(&buf->b_p_kp);
5479 check_string_option(&buf->b_p_mps);
5480 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005481 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005482 check_string_option(&buf->b_p_isk);
5483#ifdef FEAT_COMMENTS
5484 check_string_option(&buf->b_p_com);
5485#endif
5486#ifdef FEAT_FOLDING
5487 check_string_option(&buf->b_p_cms);
5488#endif
5489 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005490#ifdef FEAT_TEXTOBJ
5491 check_string_option(&buf->b_p_qe);
5492#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005493#ifdef FEAT_SYN_HL
5494 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005495#endif
5496#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005497 check_string_option(&buf->b_s.b_p_spc);
5498 check_string_option(&buf->b_s.b_p_spf);
5499 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005500#endif
5501#ifdef FEAT_SEARCHPATH
5502 check_string_option(&buf->b_p_sua);
5503#endif
5504#ifdef FEAT_CINDENT
5505 check_string_option(&buf->b_p_cink);
5506 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005507 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508#endif
5509#ifdef FEAT_AUTOCMD
5510 check_string_option(&buf->b_p_ft);
5511#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005512#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5513 check_string_option(&buf->b_p_cinw);
5514#endif
5515#ifdef FEAT_INS_EXPAND
5516 check_string_option(&buf->b_p_cpt);
5517#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005518#ifdef FEAT_COMPL_FUNC
5519 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005520 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005521#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005522#ifdef FEAT_KEYMAP
5523 check_string_option(&buf->b_p_keymap);
5524#endif
5525#ifdef FEAT_QUICKFIX
5526 check_string_option(&buf->b_p_gp);
5527 check_string_option(&buf->b_p_mp);
5528 check_string_option(&buf->b_p_efm);
5529#endif
5530 check_string_option(&buf->b_p_ep);
5531 check_string_option(&buf->b_p_path);
5532 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005533 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005534#ifdef FEAT_INS_EXPAND
5535 check_string_option(&buf->b_p_dict);
5536 check_string_option(&buf->b_p_tsr);
5537#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005538#ifdef FEAT_LISP
5539 check_string_option(&buf->b_p_lw);
5540#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005541 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005542}
5543
5544/*
5545 * Free the string allocated for an option.
5546 * Checks for the string being empty_option. This may happen if we're out of
5547 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5548 * check_options().
5549 * Does NOT check for P_ALLOCED flag!
5550 */
5551 void
5552free_string_option(p)
5553 char_u *p;
5554{
5555 if (p != empty_option)
5556 vim_free(p);
5557}
5558
5559 void
5560clear_string_option(pp)
5561 char_u **pp;
5562{
5563 if (*pp != empty_option)
5564 vim_free(*pp);
5565 *pp = empty_option;
5566}
5567
5568 static void
5569check_string_option(pp)
5570 char_u **pp;
5571{
5572 if (*pp == NULL)
5573 *pp = empty_option;
5574}
5575
5576/*
5577 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5578 */
5579 void
5580set_term_option_alloced(p)
5581 char_u **p;
5582{
5583 int opt_idx;
5584
5585 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5586 if (options[opt_idx].var == (char_u *)p)
5587 {
5588 options[opt_idx].flags |= P_ALLOCED;
5589 return;
5590 }
5591 return; /* cannot happen: didn't find it! */
5592}
5593
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005594#if defined(FEAT_EVAL) || defined(PROTO)
5595/*
5596 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5597 * Return FALSE when it wasn't.
5598 * Return -1 for an unknown option.
5599 */
5600 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005601was_set_insecurely(opt, opt_flags)
5602 char_u *opt;
5603 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005604{
5605 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005606 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005607
5608 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005609 {
5610 flagp = insecure_flag(idx, opt_flags);
5611 return (*flagp & P_INSECURE) != 0;
5612 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005613 EMSG2(_(e_intern2), "was_set_insecurely()");
5614 return -1;
5615}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005616
5617/*
5618 * Get a pointer to the flags used for the P_INSECURE flag of option
5619 * "opt_idx". For some local options a local flags field is used.
5620 */
5621 static long_u *
5622insecure_flag(opt_idx, opt_flags)
5623 int opt_idx;
5624 int opt_flags;
5625{
5626 if (opt_flags & OPT_LOCAL)
5627 switch ((int)options[opt_idx].indir)
5628 {
5629#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005630 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005631#endif
5632#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005633# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005634 case PV_FDE: return &curwin->w_p_fde_flags;
5635 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005636# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005637# ifdef FEAT_BEVAL
5638 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5639# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005640# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005641 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005642# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005643 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005644# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005645 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005646# endif
5647#endif
5648 }
5649
5650 /* Nothing special, return global flags field. */
5651 return &options[opt_idx].flags;
5652}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005653#endif
5654
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005655#ifdef FEAT_TITLE
5656static void redraw_titles __ARGS((void));
5657
5658/*
5659 * Redraw the window title and/or tab page text later.
5660 */
5661static void redraw_titles()
5662{
5663 need_maketitle = TRUE;
5664# ifdef FEAT_WINDOWS
5665 redraw_tabline = TRUE;
5666# endif
5667}
5668#endif
5669
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670/*
5671 * Set a string option to a new value (without checking the effect).
5672 * The string is copied into allocated memory.
5673 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005674 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005675 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676 */
5677 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005678set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005679 char_u *name;
5680 int opt_idx;
5681 char_u *val;
5682 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005683 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684{
5685 char_u *s;
5686 char_u **varp;
5687 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005688 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689
Bram Moolenaar89d40322006-08-29 15:30:07 +00005690 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005692 idx = findoption(name);
5693 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005694 {
5695 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005696 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005698 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699 }
5700
Bram Moolenaar89d40322006-08-29 15:30:07 +00005701 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702 return;
5703
5704 s = vim_strsave(val);
5705 if (s != NULL)
5706 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005707 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005709 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710 free_string_option(*varp);
5711 *varp = s;
5712
5713 /* For buffer/window local option may also set the global value. */
5714 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005715 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716
Bram Moolenaar89d40322006-08-29 15:30:07 +00005717 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005718
5719 /* When setting both values of a global option with a local value,
5720 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005721 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005722 {
5723 free_string_option(*varp);
5724 *varp = empty_option;
5725 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005726# ifdef FEAT_EVAL
5727 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005728 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005729 set_sid == 0 ? current_SID : set_sid);
5730# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731 }
5732}
5733
5734/*
5735 * Set global value for string option when it's a local option.
5736 */
5737 static void
5738set_string_option_global(opt_idx, varp)
5739 int opt_idx; /* option index */
5740 char_u **varp; /* pointer to option variable */
5741{
5742 char_u **p, *s;
5743
5744 /* the global value is always allocated */
5745 if (options[opt_idx].var == VAR_WIN)
5746 p = (char_u **)GLOBAL_WO(varp);
5747 else
5748 p = (char_u **)options[opt_idx].var;
5749 if (options[opt_idx].indir != PV_NONE
5750 && p != varp
5751 && (s = vim_strsave(*varp)) != NULL)
5752 {
5753 free_string_option(*p);
5754 *p = s;
5755 }
5756}
5757
5758/*
5759 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005760 *
5761 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005762 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005763 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764set_string_option(opt_idx, value, opt_flags)
5765 int opt_idx;
5766 char_u *value;
5767 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5768{
5769 char_u *s;
5770 char_u **varp;
5771 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005772#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5773 char_u *saved_oldval = NULL;
5774#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005775 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005776
5777 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005778 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005779
5780 s = vim_strsave(value);
5781 if (s != NULL)
5782 {
5783 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5784 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005785 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005786 ? OPT_GLOBAL : OPT_LOCAL)
5787 : opt_flags);
5788 oldval = *varp;
5789 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005790
5791#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005792 if (!starting
5793# ifdef FEAT_CRYPT
5794 && options[opt_idx].indir != PV_KEY
5795# endif
5796 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005797 saved_oldval = vim_strsave(oldval);
5798#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005799 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5800 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005801 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005802
5803 /* call autocomamnd after handling side effects */
5804#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5805 if (saved_oldval != NULL)
5806 {
5807 char_u buf_type[7];
5808 sprintf((char *)buf_type, "%s",
5809 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005810 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5811 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005812 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5813 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5814 reset_v_option_vars();
5815 vim_free(saved_oldval);
5816 }
5817#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005818 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005819 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005820}
5821
5822/*
5823 * Handle string options that need some action to perform when changed.
5824 * Returns NULL for success, or an error message for an error.
5825 */
5826 static char_u *
5827did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5828 opt_flags)
5829 int opt_idx; /* index in options[] table */
5830 char_u **varp; /* pointer to the option variable */
5831 int new_value_alloced; /* new value was allocated */
5832 char_u *oldval; /* previous value of the option */
5833 char_u *errbuf; /* buffer for errors, or NULL */
5834 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5835{
5836 char_u *errmsg = NULL;
5837 char_u *s, *p;
5838 int did_chartab = FALSE;
5839 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005840 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005841#ifdef FEAT_GUI
5842 /* set when changing an option that only requires a redraw in the GUI */
5843 int redraw_gui_only = FALSE;
5844#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005845
5846 /* Get the global option to compare with, otherwise we would have to check
5847 * two values for all local options. */
5848 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5849
5850 /* Disallow changing some options from secure mode */
5851 if ((secure
5852#ifdef HAVE_SANDBOX
5853 || sandbox != 0
5854#endif
5855 ) && (options[opt_idx].flags & P_SECURE))
5856 {
5857 errmsg = e_secure;
5858 }
5859
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005860 /* Check for a "normal" file name in some options. Disallow a path
5861 * separator (slash and/or backslash), wildcards and characters that are
5862 * often illegal in a file name. */
5863 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005864 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005865 {
5866 errmsg = e_invarg;
5867 }
5868
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869 /* 'term' */
5870 else if (varp == &T_NAME)
5871 {
5872 if (T_NAME[0] == NUL)
5873 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5874#ifdef FEAT_GUI
5875 if (gui.in_use)
5876 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5877 else if (term_is_gui(T_NAME))
5878 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5879#endif
5880 else if (set_termname(T_NAME) == FAIL)
5881 errmsg = (char_u *)N_("E522: Not found in termcap");
5882 else
5883 /* Screen colors may have changed. */
5884 redraw_later_clear();
5885 }
5886
5887 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005888 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005890 char_u *bkc = p_bkc;
5891 unsigned int *flags = &bkc_flags;
5892
5893 if (opt_flags & OPT_LOCAL)
5894 {
5895 bkc = curbuf->b_p_bkc;
5896 flags = &curbuf->b_bkc_flags;
5897 }
5898
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005899 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5900 /* make the local value empty: use the global value */
5901 *flags = 0;
5902 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005903 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005904 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5905 errmsg = e_invarg;
5906 if ((((int)*flags & BKC_AUTO) != 0)
5907 + (((int)*flags & BKC_YES) != 0)
5908 + (((int)*flags & BKC_NO) != 0) != 1)
5909 {
5910 /* Must have exactly one of "auto", "yes" and "no". */
5911 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5912 errmsg = e_invarg;
5913 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005914 }
5915 }
5916
5917 /* 'backupext' and 'patchmode' */
5918 else if (varp == &p_bex || varp == &p_pm)
5919 {
5920 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5921 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5922 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5923 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005924#ifdef FEAT_LINEBREAK
5925 /* 'breakindentopt' */
5926 else if (varp == &curwin->w_p_briopt)
5927 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005928 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005929 errmsg = e_invarg;
5930 }
5931#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932
5933 /*
5934 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5935 * If the new option is invalid, use old value. 'lisp' option: refill
5936 * chartab[] for '-' char
5937 */
5938 else if ( varp == &p_isi
5939 || varp == &(curbuf->b_p_isk)
5940 || varp == &p_isp
5941 || varp == &p_isf)
5942 {
5943 if (init_chartab() == FAIL)
5944 {
5945 did_chartab = TRUE; /* need to restore it below */
5946 errmsg = e_invarg; /* error in value */
5947 }
5948 }
5949
5950 /* 'helpfile' */
5951 else if (varp == &p_hf)
5952 {
5953 /* May compute new values for $VIM and $VIMRUNTIME */
5954 if (didset_vim)
5955 {
5956 vim_setenv((char_u *)"VIM", (char_u *)"");
5957 didset_vim = FALSE;
5958 }
5959 if (didset_vimruntime)
5960 {
5961 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5962 didset_vimruntime = FALSE;
5963 }
5964 }
5965
Bram Moolenaar1a384422010-07-14 19:53:30 +02005966#ifdef FEAT_SYN_HL
5967 /* 'colorcolumn' */
5968 else if (varp == &curwin->w_p_cc)
5969 errmsg = check_colorcolumn(curwin);
5970#endif
5971
Bram Moolenaar071d4272004-06-13 20:20:40 +00005972#ifdef FEAT_MULTI_LANG
5973 /* 'helplang' */
5974 else if (varp == &p_hlg)
5975 {
5976 /* Check for "", "ab", "ab,cd", etc. */
5977 for (s = p_hlg; *s != NUL; s += 3)
5978 {
5979 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5980 {
5981 errmsg = e_invarg;
5982 break;
5983 }
5984 if (s[2] == NUL)
5985 break;
5986 }
5987 }
5988#endif
5989
5990 /* 'highlight' */
5991 else if (varp == &p_hl)
5992 {
5993 if (highlight_changed() == FAIL)
5994 errmsg = e_invarg; /* invalid flags */
5995 }
5996
5997 /* 'nrformats' */
5998 else if (gvarp == &p_nf)
5999 {
6000 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6001 errmsg = e_invarg;
6002 }
6003
6004#ifdef FEAT_SESSION
6005 /* 'sessionoptions' */
6006 else if (varp == &p_ssop)
6007 {
6008 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6009 errmsg = e_invarg;
6010 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6011 {
6012 /* Don't allow both "sesdir" and "curdir". */
6013 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6014 errmsg = e_invarg;
6015 }
6016 }
6017 /* 'viewoptions' */
6018 else if (varp == &p_vop)
6019 {
6020 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6021 errmsg = e_invarg;
6022 }
6023#endif
6024
6025 /* 'scrollopt' */
6026#ifdef FEAT_SCROLLBIND
6027 else if (varp == &p_sbo)
6028 {
6029 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6030 errmsg = e_invarg;
6031 }
6032#endif
6033
6034 /* 'ambiwidth' */
6035#ifdef FEAT_MBYTE
6036 else if (varp == &p_ambw)
6037 {
6038 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6039 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006040 else if (set_chars_option(&p_lcs) != NULL)
6041 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6042# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6043 else if (set_chars_option(&p_fcs) != NULL)
6044 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6045# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006046 }
6047#endif
6048
6049 /* 'background' */
6050 else if (varp == &p_bg)
6051 {
6052 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6053 {
6054#ifdef FEAT_EVAL
6055 int dark = (*p_bg == 'd');
6056#endif
6057
6058 init_highlight(FALSE, FALSE);
6059
6060#ifdef FEAT_EVAL
6061 if (dark != (*p_bg == 'd')
6062 && get_var_value((char_u *)"g:colors_name") != NULL)
6063 {
6064 /* The color scheme must have set 'background' back to another
6065 * value, that's not what we want here. Disable the color
6066 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006067 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006068 free_string_option(p_bg);
6069 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6070 check_string_option(&p_bg);
6071 init_highlight(FALSE, FALSE);
6072 }
6073#endif
6074 }
6075 else
6076 errmsg = e_invarg;
6077 }
6078
6079 /* 'wildmode' */
6080 else if (varp == &p_wim)
6081 {
6082 if (check_opt_wim() == FAIL)
6083 errmsg = e_invarg;
6084 }
6085
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006086#ifdef FEAT_CMDL_COMPL
6087 /* 'wildoptions' */
6088 else if (varp == &p_wop)
6089 {
6090 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6091 errmsg = e_invarg;
6092 }
6093#endif
6094
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095#ifdef FEAT_WAK
6096 /* 'winaltkeys' */
6097 else if (varp == &p_wak)
6098 {
6099 if (*p_wak == NUL
6100 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6101 errmsg = e_invarg;
6102# ifdef FEAT_MENU
6103# ifdef FEAT_GUI_MOTIF
6104 else if (gui.in_use)
6105 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6106# else
6107# ifdef FEAT_GUI_GTK
6108 else if (gui.in_use)
6109 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6110# endif
6111# endif
6112# endif
6113 }
6114#endif
6115
6116#ifdef FEAT_AUTOCMD
6117 /* 'eventignore' */
6118 else if (varp == &p_ei)
6119 {
6120 if (check_ei() == FAIL)
6121 errmsg = e_invarg;
6122 }
6123#endif
6124
6125#ifdef FEAT_MBYTE
6126 /* 'encoding' and 'fileencoding' */
6127 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6128 {
6129 if (gvarp == &p_fenc)
6130 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006131 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006132 errmsg = e_modifiable;
6133 else if (vim_strchr(*varp, ',') != NULL)
6134 /* No comma allowed in 'fileencoding'; catches confusing it
6135 * with 'fileencodings'. */
6136 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006138 {
6139# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006140 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006141 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006142# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006143 /* Add 'fileencoding' to the swap file. */
6144 ml_setflags(curbuf);
6145 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006146 }
6147 if (errmsg == NULL)
6148 {
6149 /* canonize the value, so that STRCMP() can be used on it */
6150 p = enc_canonize(*varp);
6151 if (p != NULL)
6152 {
6153 vim_free(*varp);
6154 *varp = p;
6155 }
6156 if (varp == &p_enc)
6157 {
6158 errmsg = mb_init();
6159# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006160 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006161# endif
6162 }
6163 }
6164
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006165# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006166 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6167 {
6168 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6169 if (STRCMP(p_tenc, "utf-8") != 0)
6170 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6171 }
6172# endif
6173
6174 if (errmsg == NULL)
6175 {
6176# ifdef FEAT_KEYMAP
6177 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6178 * (with another encoding). */
6179 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6180 (void)keymap_init();
6181# endif
6182
6183 /* When 'termencoding' is not empty and 'encoding' changes or when
6184 * 'termencoding' changes, need to setup for keyboard input and
6185 * display output conversion. */
6186 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6187 {
6188 convert_setup(&input_conv, p_tenc, p_enc);
6189 convert_setup(&output_conv, p_enc, p_tenc);
6190 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006191
6192# if defined(WIN3264) && defined(FEAT_MBYTE)
6193 /* $HOME may have characters in active code page. */
6194 if (varp == &p_enc)
6195 init_homedir();
6196# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006197 }
6198 }
6199#endif
6200
6201#if defined(FEAT_POSTSCRIPT)
6202 else if (varp == &p_penc)
6203 {
6204 /* Canonize printencoding if VIM standard one */
6205 p = enc_canonize(p_penc);
6206 if (p != NULL)
6207 {
6208 vim_free(p_penc);
6209 p_penc = p;
6210 }
6211 else
6212 {
6213 /* Ensure lower case and '-' for '_' */
6214 for (s = p_penc; *s != NUL; s++)
6215 {
6216 if (*s == '_')
6217 *s = '-';
6218 else
6219 *s = TOLOWER_ASC(*s);
6220 }
6221 }
6222 }
6223#endif
6224
Bram Moolenaar9372a112005-12-06 19:59:18 +00006225#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006226 else if (varp == &p_imak)
6227 {
6228 if (gui.in_use && !im_xim_isvalid_imactivate())
6229 errmsg = e_invarg;
6230 }
6231#endif
6232
6233#ifdef FEAT_KEYMAP
6234 else if (varp == &curbuf->b_p_keymap)
6235 {
6236 /* load or unload key mapping tables */
6237 errmsg = keymap_init();
6238
Bram Moolenaarfab06232009-03-04 03:13:35 +00006239 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006241 if (*curbuf->b_p_keymap != NUL)
6242 {
6243 /* Installed a new keymap, switch on using it. */
6244 curbuf->b_p_iminsert = B_IMODE_LMAP;
6245 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6246 curbuf->b_p_imsearch = B_IMODE_LMAP;
6247 }
6248 else
6249 {
6250 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6251 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6252 curbuf->b_p_iminsert = B_IMODE_NONE;
6253 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6254 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6255 }
6256 if ((opt_flags & OPT_LOCAL) == 0)
6257 {
6258 set_iminsert_global();
6259 set_imsearch_global();
6260 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006261# ifdef FEAT_WINDOWS
6262 status_redraw_curbuf();
6263# endif
6264 }
6265 }
6266#endif
6267
6268 /* 'fileformat' */
6269 else if (gvarp == &p_ff)
6270 {
6271 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6272 errmsg = e_modifiable;
6273 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6274 errmsg = e_invarg;
6275 else
6276 {
6277 /* may also change 'textmode' */
6278 if (get_fileformat(curbuf) == EOL_DOS)
6279 curbuf->b_p_tx = TRUE;
6280 else
6281 curbuf->b_p_tx = FALSE;
6282#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006283 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006284#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006285 /* update flag in swap file */
6286 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006287 /* Redraw needed when switching to/from "mac": a CR in the text
6288 * will be displayed differently. */
6289 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6290 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006291 }
6292 }
6293
6294 /* 'fileformats' */
6295 else if (varp == &p_ffs)
6296 {
6297 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6298 errmsg = e_invarg;
6299 else
6300 {
6301 /* also change 'textauto' */
6302 if (*p_ffs == NUL)
6303 p_ta = FALSE;
6304 else
6305 p_ta = TRUE;
6306 }
6307 }
6308
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006309#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006310 /* 'cryptkey' */
6311 else if (gvarp == &p_key)
6312 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006313# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006314 /* Make sure the ":set" command doesn't show the new value in the
6315 * history. */
6316 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006317# endif
6318 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6319 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006320 ml_set_crypt_key(curbuf, oldval,
6321 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006322 }
6323
6324 else if (gvarp == &p_cm)
6325 {
6326 if (opt_flags & OPT_LOCAL)
6327 p = curbuf->b_p_cm;
6328 else
6329 p = p_cm;
6330 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6331 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006332 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006333 errmsg = e_invarg;
6334 else
6335 {
6336 /* When setting the global value to empty, make it "zip". */
6337 if (*p_cm == NUL)
6338 {
6339 if (new_value_alloced)
6340 free_string_option(p_cm);
6341 p_cm = vim_strsave((char_u *)"zip");
6342 new_value_alloced = TRUE;
6343 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006344 /* When using ":set cm=name" the local value is going to be empty.
6345 * Do that here, otherwise the crypt functions will still use the
6346 * local value. */
6347 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6348 {
6349 free_string_option(curbuf->b_p_cm);
6350 curbuf->b_p_cm = empty_option;
6351 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006352
6353 /* Need to update the swapfile when the effective method changed.
6354 * Set "s" to the effective old value, "p" to the effective new
6355 * method and compare. */
6356 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6357 s = p_cm; /* was previously using the global value */
6358 else
6359 s = oldval;
6360 if (*curbuf->b_p_cm == NUL)
6361 p = p_cm; /* is now using the global value */
6362 else
6363 p = curbuf->b_p_cm;
6364 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006365 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006366
6367 /* If the global value changes need to update the swapfile for all
6368 * buffers using that value. */
6369 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6370 {
6371 buf_T *buf;
6372
6373 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6374 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006375 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006376 }
6377 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006378 }
6379#endif
6380
6381 /* 'matchpairs' */
6382 else if (gvarp == &p_mps)
6383 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006384#ifdef FEAT_MBYTE
6385 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006387 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006389 int x2 = -1;
6390 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006391
6392 if (*p != NUL)
6393 p += mb_ptr2len(p);
6394 if (*p != NUL)
6395 x2 = *p++;
6396 if (*p != NUL)
6397 {
6398 x3 = mb_ptr2char(p);
6399 p += mb_ptr2len(p);
6400 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006401 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006402 {
6403 errmsg = e_invarg;
6404 break;
6405 }
6406 if (*p == NUL)
6407 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006409 }
6410 else
6411#endif
6412 {
6413 /* Check for "x:y,x:y" */
6414 for (p = *varp; *p != NUL; p += 4)
6415 {
6416 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6417 {
6418 errmsg = e_invarg;
6419 break;
6420 }
6421 if (p[3] == NUL)
6422 break;
6423 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006424 }
6425 }
6426
6427#ifdef FEAT_COMMENTS
6428 /* 'comments' */
6429 else if (gvarp == &p_com)
6430 {
6431 for (s = *varp; *s; )
6432 {
6433 while (*s && *s != ':')
6434 {
6435 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6436 && !VIM_ISDIGIT(*s) && *s != '-')
6437 {
6438 errmsg = illegal_char(errbuf, *s);
6439 break;
6440 }
6441 ++s;
6442 }
6443 if (*s++ == NUL)
6444 errmsg = (char_u *)N_("E524: Missing colon");
6445 else if (*s == ',' || *s == NUL)
6446 errmsg = (char_u *)N_("E525: Zero length string");
6447 if (errmsg != NULL)
6448 break;
6449 while (*s && *s != ',')
6450 {
6451 if (*s == '\\' && s[1] != NUL)
6452 ++s;
6453 ++s;
6454 }
6455 s = skip_to_option_part(s);
6456 }
6457 }
6458#endif
6459
6460 /* 'listchars' */
6461 else if (varp == &p_lcs)
6462 {
6463 errmsg = set_chars_option(varp);
6464 }
6465
6466#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6467 /* 'fillchars' */
6468 else if (varp == &p_fcs)
6469 {
6470 errmsg = set_chars_option(varp);
6471 }
6472#endif
6473
6474#ifdef FEAT_CMDWIN
6475 /* 'cedit' */
6476 else if (varp == &p_cedit)
6477 {
6478 errmsg = check_cedit();
6479 }
6480#endif
6481
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006482 /* 'verbosefile' */
6483 else if (varp == &p_vfile)
6484 {
6485 verbose_stop();
6486 if (*p_vfile != NUL && verbose_open() == FAIL)
6487 errmsg = e_invarg;
6488 }
6489
Bram Moolenaar071d4272004-06-13 20:20:40 +00006490#ifdef FEAT_VIMINFO
6491 /* 'viminfo' */
6492 else if (varp == &p_viminfo)
6493 {
6494 for (s = p_viminfo; *s;)
6495 {
6496 /* Check it's a valid character */
6497 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6498 {
6499 errmsg = illegal_char(errbuf, *s);
6500 break;
6501 }
6502 if (*s == 'n') /* name is always last one */
6503 {
6504 break;
6505 }
6506 else if (*s == 'r') /* skip until next ',' */
6507 {
6508 while (*++s && *s != ',')
6509 ;
6510 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006511 else if (*s == '%')
6512 {
6513 /* optional number */
6514 while (vim_isdigit(*++s))
6515 ;
6516 }
6517 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518 ++s; /* no extra chars */
6519 else /* must have a number */
6520 {
6521 while (vim_isdigit(*++s))
6522 ;
6523
6524 if (!VIM_ISDIGIT(*(s - 1)))
6525 {
6526 if (errbuf != NULL)
6527 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006528 sprintf((char *)errbuf,
6529 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006530 transchar_byte(*(s - 1)));
6531 errmsg = errbuf;
6532 }
6533 else
6534 errmsg = (char_u *)"";
6535 break;
6536 }
6537 }
6538 if (*s == ',')
6539 ++s;
6540 else if (*s)
6541 {
6542 if (errbuf != NULL)
6543 errmsg = (char_u *)N_("E527: Missing comma");
6544 else
6545 errmsg = (char_u *)"";
6546 break;
6547 }
6548 }
6549 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6550 errmsg = (char_u *)N_("E528: Must specify a ' value");
6551 }
6552#endif /* FEAT_VIMINFO */
6553
6554 /* terminal options */
6555 else if (istermoption(&options[opt_idx]) && full_screen)
6556 {
6557 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6558 if (varp == &T_CCO)
6559 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006560 int colors = atoi((char *)T_CCO);
6561
6562 /* Only reinitialize colors if t_Co value has really changed to
6563 * avoid expensive reload of colorscheme if t_Co is set to the
6564 * same value multiple times. */
6565 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006567 t_colors = colors;
6568 if (t_colors <= 1)
6569 {
6570 if (new_value_alloced)
6571 vim_free(T_CCO);
6572 T_CCO = empty_option;
6573 }
6574 /* We now have a different color setup, initialize it again. */
6575 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006576 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006577 }
6578 ttest(FALSE);
6579 if (varp == &T_ME)
6580 {
6581 out_str(T_ME);
6582 redraw_later(CLEAR);
6583#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6584 /* Since t_me has been set, this probably means that the user
6585 * wants to use this as default colors. Need to reset default
6586 * background/foreground colors. */
6587 mch_set_normal_colors();
6588#endif
6589 }
6590 }
6591
6592#ifdef FEAT_LINEBREAK
6593 /* 'showbreak' */
6594 else if (varp == &p_sbr)
6595 {
6596 for (s = p_sbr; *s; )
6597 {
6598 if (ptr2cells(s) != 1)
6599 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006600 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006601 }
6602 }
6603#endif
6604
6605#ifdef FEAT_GUI
6606 /* 'guifont' */
6607 else if (varp == &p_guifont)
6608 {
6609 if (gui.in_use)
6610 {
6611 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006612# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006613 /*
6614 * Put up a font dialog and let the user select a new value.
6615 * If this is cancelled go back to the old value but don't
6616 * give an error message.
6617 */
6618 if (STRCMP(p, "*") == 0)
6619 {
6620 p = gui_mch_font_dialog(oldval);
6621
6622 if (new_value_alloced)
6623 free_string_option(p_guifont);
6624
6625 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6626 new_value_alloced = TRUE;
6627 }
6628# endif
6629 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6630 {
6631# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6632 if (STRCMP(p_guifont, "*") == 0)
6633 {
6634 /* Dialog was cancelled: Keep the old value without giving
6635 * an error message. */
6636 if (new_value_alloced)
6637 free_string_option(p_guifont);
6638 p_guifont = vim_strsave(oldval);
6639 new_value_alloced = TRUE;
6640 }
6641 else
6642# endif
6643 errmsg = (char_u *)N_("E596: Invalid font(s)");
6644 }
6645 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006646 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006647 }
6648# ifdef FEAT_XFONTSET
6649 else if (varp == &p_guifontset)
6650 {
6651 if (STRCMP(p_guifontset, "*") == 0)
6652 errmsg = (char_u *)N_("E597: can't select fontset");
6653 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6654 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006655 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006656 }
6657# endif
6658# ifdef FEAT_MBYTE
6659 else if (varp == &p_guifontwide)
6660 {
6661 if (STRCMP(p_guifontwide, "*") == 0)
6662 errmsg = (char_u *)N_("E533: can't select wide font");
6663 else if (gui_get_wide_font() == FAIL)
6664 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006665 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006666 }
6667# endif
6668#endif
6669
6670#ifdef CURSOR_SHAPE
6671 /* 'guicursor' */
6672 else if (varp == &p_guicursor)
6673 errmsg = parse_shape_opt(SHAPE_CURSOR);
6674#endif
6675
6676#ifdef FEAT_MOUSESHAPE
6677 /* 'mouseshape' */
6678 else if (varp == &p_mouseshape)
6679 {
6680 errmsg = parse_shape_opt(SHAPE_MOUSE);
6681 update_mouseshape(-1);
6682 }
6683#endif
6684
6685#ifdef FEAT_PRINTER
6686 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006687 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006688# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006689 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006690 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006691# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006692#endif
6693
6694#ifdef FEAT_LANGMAP
6695 /* 'langmap' */
6696 else if (varp == &p_langmap)
6697 langmap_set();
6698#endif
6699
6700#ifdef FEAT_LINEBREAK
6701 /* 'breakat' */
6702 else if (varp == &p_breakat)
6703 fill_breakat_flags();
6704#endif
6705
6706#ifdef FEAT_TITLE
6707 /* 'titlestring' and 'iconstring' */
6708 else if (varp == &p_titlestring || varp == &p_iconstring)
6709 {
6710# ifdef FEAT_STL_OPT
6711 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6712
6713 /* NULL => statusline syntax */
6714 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6715 stl_syntax |= flagval;
6716 else
6717 stl_syntax &= ~flagval;
6718# endif
6719 did_set_title(varp == &p_iconstring);
6720
6721 }
6722#endif
6723
6724#ifdef FEAT_GUI
6725 /* 'guioptions' */
6726 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006727 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006728 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006729 redraw_gui_only = TRUE;
6730 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006731#endif
6732
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006733#if defined(FEAT_GUI_TABLINE)
6734 /* 'guitablabel' */
6735 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006736 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006737 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006738 redraw_gui_only = TRUE;
6739 }
6740 /* 'guitabtooltip' */
6741 else if (varp == &p_gtt)
6742 {
6743 redraw_gui_only = TRUE;
6744 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006745#endif
6746
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6748 /* 'ttymouse' */
6749 else if (varp == &p_ttym)
6750 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006751 /* Switch the mouse off before changing the escape sequences used for
6752 * that. */
6753 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6755 errmsg = e_invarg;
6756 else
6757 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006758 if (termcap_active)
6759 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006760 }
6761#endif
6762
Bram Moolenaar071d4272004-06-13 20:20:40 +00006763 /* 'selection' */
6764 else if (varp == &p_sel)
6765 {
6766 if (*p_sel == NUL
6767 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6768 errmsg = e_invarg;
6769 }
6770
6771 /* 'selectmode' */
6772 else if (varp == &p_slm)
6773 {
6774 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6775 errmsg = e_invarg;
6776 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777
6778#ifdef FEAT_BROWSE
6779 /* 'browsedir' */
6780 else if (varp == &p_bsdir)
6781 {
6782 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6783 && !mch_isdir(p_bsdir))
6784 errmsg = e_invarg;
6785 }
6786#endif
6787
Bram Moolenaar071d4272004-06-13 20:20:40 +00006788 /* 'keymodel' */
6789 else if (varp == &p_km)
6790 {
6791 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6792 errmsg = e_invarg;
6793 else
6794 {
6795 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6796 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6797 }
6798 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006799
6800 /* 'mousemodel' */
6801 else if (varp == &p_mousem)
6802 {
6803 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6804 errmsg = e_invarg;
6805#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6806 else if (*p_mousem != *oldval)
6807 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6808 * to create or delete the popup menus. */
6809 gui_motif_update_mousemodel(root_menu);
6810#endif
6811 }
6812
6813 /* 'switchbuf' */
6814 else if (varp == &p_swb)
6815 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006816 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006817 errmsg = e_invarg;
6818 }
6819
6820 /* 'debug' */
6821 else if (varp == &p_debug)
6822 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006823 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006824 errmsg = e_invarg;
6825 }
6826
6827 /* 'display' */
6828 else if (varp == &p_dy)
6829 {
6830 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6831 errmsg = e_invarg;
6832 else
6833 (void)init_chartab();
6834
6835 }
6836
6837#ifdef FEAT_VERTSPLIT
6838 /* 'eadirection' */
6839 else if (varp == &p_ead)
6840 {
6841 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6842 errmsg = e_invarg;
6843 }
6844#endif
6845
6846#ifdef FEAT_CLIPBOARD
6847 /* 'clipboard' */
6848 else if (varp == &p_cb)
6849 errmsg = check_clipboard_option();
6850#endif
6851
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006852#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006853 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6854 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006855 else if (varp == &(curwin->w_s->b_p_spl)
6856 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006857 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006858 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006859 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006860 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006861 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006862 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006863 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006864 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006865 /* 'spellsuggest' */
6866 else if (varp == &p_sps)
6867 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006868 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006869 errmsg = e_invarg;
6870 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006871 /* 'mkspellmem' */
6872 else if (varp == &p_msm)
6873 {
6874 if (spell_check_msm() != OK)
6875 errmsg = e_invarg;
6876 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006877#endif
6878
Bram Moolenaar071d4272004-06-13 20:20:40 +00006879#ifdef FEAT_QUICKFIX
6880 /* When 'bufhidden' is set, check for valid value. */
6881 else if (gvarp == &p_bh)
6882 {
6883 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6884 errmsg = e_invarg;
6885 }
6886
6887 /* When 'buftype' is set, check for valid value. */
6888 else if (gvarp == &p_bt)
6889 {
6890 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6891 errmsg = e_invarg;
6892 else
6893 {
6894# ifdef FEAT_WINDOWS
6895 if (curwin->w_status_height)
6896 {
6897 curwin->w_redr_status = TRUE;
6898 redraw_later(VALID);
6899 }
6900# endif
6901 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006902# ifdef FEAT_TITLE
6903 redraw_titles();
6904# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006905 }
6906 }
6907#endif
6908
6909#ifdef FEAT_STL_OPT
6910 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006911 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006912 {
6913 int wid;
6914
6915 if (varp == &p_ruf) /* reset ru_wid first */
6916 ru_wid = 0;
6917 s = *varp;
6918 if (varp == &p_ruf && *s == '%')
6919 {
6920 /* set ru_wid if 'ruf' starts with "%99(" */
6921 if (*++s == '-') /* ignore a '-' */
6922 s++;
6923 wid = getdigits(&s);
6924 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6925 ru_wid = wid;
6926 else
6927 errmsg = check_stl_option(p_ruf);
6928 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006929 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006930 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006931 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006932 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006933 comp_col();
6934 }
6935#endif
6936
6937#ifdef FEAT_INS_EXPAND
6938 /* check if it is a valid value for 'complete' -- Acevedo */
6939 else if (gvarp == &p_cpt)
6940 {
6941 for (s = *varp; *s;)
6942 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006943 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006944 s++;
6945 if (!*s)
6946 break;
6947 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6948 {
6949 errmsg = illegal_char(errbuf, *s);
6950 break;
6951 }
6952 if (*++s != NUL && *s != ',' && *s != ' ')
6953 {
6954 if (s[-1] == 'k' || s[-1] == 's')
6955 {
6956 /* skip optional filename after 'k' and 's' */
6957 while (*s && *s != ',' && *s != ' ')
6958 {
6959 if (*s == '\\')
6960 ++s;
6961 ++s;
6962 }
6963 }
6964 else
6965 {
6966 if (errbuf != NULL)
6967 {
6968 sprintf((char *)errbuf,
6969 _("E535: Illegal character after <%c>"),
6970 *--s);
6971 errmsg = errbuf;
6972 }
6973 else
6974 errmsg = (char_u *)"";
6975 break;
6976 }
6977 }
6978 }
6979 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006980
6981 /* 'completeopt' */
6982 else if (varp == &p_cot)
6983 {
6984 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6985 errmsg = e_invarg;
6986 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006987#endif /* FEAT_INS_EXPAND */
6988
6989
6990#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6991 else if (varp == &p_toolbar)
6992 {
6993 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6994 &toolbar_flags, TRUE) != OK)
6995 errmsg = e_invarg;
6996 else
6997 {
6998 out_flush();
6999 gui_mch_show_toolbar((toolbar_flags &
7000 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7001 }
7002 }
7003#endif
7004
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007005#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007006 /* 'toolbariconsize': GTK+ 2 only */
7007 else if (varp == &p_tbis)
7008 {
7009 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7010 errmsg = e_invarg;
7011 else
7012 {
7013 out_flush();
7014 gui_mch_show_toolbar((toolbar_flags &
7015 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7016 }
7017 }
7018#endif
7019
7020 /* 'pastetoggle': translate key codes like in a mapping */
7021 else if (varp == &p_pt)
7022 {
7023 if (*p_pt)
7024 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007025 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007026 if (p != NULL)
7027 {
7028 if (new_value_alloced)
7029 free_string_option(p_pt);
7030 p_pt = p;
7031 new_value_alloced = TRUE;
7032 }
7033 }
7034 }
7035
7036 /* 'backspace' */
7037 else if (varp == &p_bs)
7038 {
7039 if (VIM_ISDIGIT(*p_bs))
7040 {
7041 if (*p_bs >'2' || p_bs[1] != NUL)
7042 errmsg = e_invarg;
7043 }
7044 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7045 errmsg = e_invarg;
7046 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007047 else if (varp == &p_bo)
7048 {
7049 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7050 errmsg = e_invarg;
7051 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007052
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007053 /* 'tagcase' */
7054 else if (gvarp == &p_tc)
7055 {
7056 unsigned int *flags;
7057
7058 if (opt_flags & OPT_LOCAL)
7059 {
7060 p = curbuf->b_p_tc;
7061 flags = &curbuf->b_tc_flags;
7062 }
7063 else
7064 {
7065 p = p_tc;
7066 flags = &tc_flags;
7067 }
7068
7069 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7070 /* make the local value empty: use the global value */
7071 *flags = 0;
7072 else if (*p == NUL
7073 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7074 errmsg = e_invarg;
7075 }
7076
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007077#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 /* 'casemap' */
7079 else if (varp == &p_cmp)
7080 {
7081 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7082 errmsg = e_invarg;
7083 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085
7086#ifdef FEAT_DIFF
7087 /* 'diffopt' */
7088 else if (varp == &p_dip)
7089 {
7090 if (diffopt_changed() == FAIL)
7091 errmsg = e_invarg;
7092 }
7093#endif
7094
7095#ifdef FEAT_FOLDING
7096 /* 'foldmethod' */
7097 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7098 {
7099 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7100 || *curwin->w_p_fdm == NUL)
7101 errmsg = e_invarg;
7102 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007103 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007104 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007105 if (foldmethodIsDiff(curwin))
7106 newFoldLevel();
7107 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007108 }
7109# ifdef FEAT_EVAL
7110 /* 'foldexpr' */
7111 else if (varp == &curwin->w_p_fde)
7112 {
7113 if (foldmethodIsExpr(curwin))
7114 foldUpdateAll(curwin);
7115 }
7116# endif
7117 /* 'foldmarker' */
7118 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7119 {
7120 p = vim_strchr(*varp, ',');
7121 if (p == NULL)
7122 errmsg = (char_u *)N_("E536: comma required");
7123 else if (p == *varp || p[1] == NUL)
7124 errmsg = e_invarg;
7125 else if (foldmethodIsMarker(curwin))
7126 foldUpdateAll(curwin);
7127 }
7128 /* 'commentstring' */
7129 else if (gvarp == &p_cms)
7130 {
7131 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7132 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7133 }
7134 /* 'foldopen' */
7135 else if (varp == &p_fdo)
7136 {
7137 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7138 errmsg = e_invarg;
7139 }
7140 /* 'foldclose' */
7141 else if (varp == &p_fcl)
7142 {
7143 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7144 errmsg = e_invarg;
7145 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007146 /* 'foldignore' */
7147 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7148 {
7149 if (foldmethodIsIndent(curwin))
7150 foldUpdateAll(curwin);
7151 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007152#endif
7153
7154#ifdef FEAT_VIRTUALEDIT
7155 /* 'virtualedit' */
7156 else if (varp == &p_ve)
7157 {
7158 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7159 errmsg = e_invarg;
7160 else if (STRCMP(p_ve, oldval) != 0)
7161 {
7162 /* Recompute cursor position in case the new 've' setting
7163 * changes something. */
7164 validate_virtcol();
7165 coladvance(curwin->w_virtcol);
7166 }
7167 }
7168#endif
7169
7170#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7171 else if (varp == &p_csqf)
7172 {
7173 if (p_csqf != NULL)
7174 {
7175 p = p_csqf;
7176 while (*p != NUL)
7177 {
7178 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7179 || p[1] == NUL
7180 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7181 || (p[2] != NUL && p[2] != ','))
7182 {
7183 errmsg = e_invarg;
7184 break;
7185 }
7186 else if (p[2] == NUL)
7187 break;
7188 else
7189 p += 3;
7190 }
7191 }
7192 }
7193#endif
7194
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007195#ifdef FEAT_CINDENT
7196 /* 'cinoptions' */
7197 else if (gvarp == &p_cino)
7198 {
7199 /* TODO: recognize errors */
7200 parse_cino(curbuf);
7201 }
7202#endif
7203
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007204#if defined(FEAT_RENDER_OPTIONS)
7205 else if (varp == &p_rop && gui.in_use)
7206 {
7207 if (!gui_mch_set_rendering_options(p_rop))
7208 errmsg = e_invarg;
7209 }
7210#endif
7211
Bram Moolenaar071d4272004-06-13 20:20:40 +00007212 /* Options that are a list of flags. */
7213 else
7214 {
7215 p = NULL;
7216 if (varp == &p_ww)
7217 p = (char_u *)WW_ALL;
7218 if (varp == &p_shm)
7219 p = (char_u *)SHM_ALL;
7220 else if (varp == &(p_cpo))
7221 p = (char_u *)CPO_ALL;
7222 else if (varp == &(curbuf->b_p_fo))
7223 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007224#ifdef FEAT_CONCEAL
7225 else if (varp == &curwin->w_p_cocu)
7226 p = (char_u *)COCU_ALL;
7227#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007228 else if (varp == &p_mouse)
7229 {
7230#ifdef FEAT_MOUSE
7231 p = (char_u *)MOUSE_ALL;
7232#else
7233 if (*p_mouse != NUL)
7234 errmsg = (char_u *)N_("E538: No mouse support");
7235#endif
7236 }
7237#if defined(FEAT_GUI)
7238 else if (varp == &p_go)
7239 p = (char_u *)GO_ALL;
7240#endif
7241 if (p != NULL)
7242 {
7243 for (s = *varp; *s; ++s)
7244 if (vim_strchr(p, *s) == NULL)
7245 {
7246 errmsg = illegal_char(errbuf, *s);
7247 break;
7248 }
7249 }
7250 }
7251
7252 /*
7253 * If error detected, restore the previous value.
7254 */
7255 if (errmsg != NULL)
7256 {
7257 if (new_value_alloced)
7258 free_string_option(*varp);
7259 *varp = oldval;
7260 /*
7261 * When resetting some values, need to act on it.
7262 */
7263 if (did_chartab)
7264 (void)init_chartab();
7265 if (varp == &p_hl)
7266 (void)highlight_changed();
7267 }
7268 else
7269 {
7270#ifdef FEAT_EVAL
7271 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007272 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007273#endif
7274 /*
7275 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007276 * Use "free_oldval", because recursiveness may change the flags under
7277 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007278 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007279 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007280 free_string_option(oldval);
7281 if (new_value_alloced)
7282 options[opt_idx].flags |= P_ALLOCED;
7283 else
7284 options[opt_idx].flags &= ~P_ALLOCED;
7285
7286 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007287 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007288 {
7289 /* global option with local value set to use global value; free
7290 * the local value and make it empty */
7291 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7292 free_string_option(*(char_u **)p);
7293 *(char_u **)p = empty_option;
7294 }
7295
7296 /* May set global value for local option. */
7297 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7298 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007299
7300#ifdef FEAT_AUTOCMD
7301 /*
7302 * Trigger the autocommand only after setting the flags.
7303 */
7304# ifdef FEAT_SYN_HL
7305 /* When 'syntax' is set, load the syntax of that name */
7306 if (varp == &(curbuf->b_p_syn))
7307 {
7308 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7309 curbuf->b_fname, TRUE, curbuf);
7310 }
7311# endif
7312 else if (varp == &(curbuf->b_p_ft))
7313 {
7314 /* 'filetype' is set, trigger the FileType autocommand */
7315 did_filetype = TRUE;
7316 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7317 curbuf->b_fname, TRUE, curbuf);
7318 }
7319#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007320#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007321 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007322 {
7323 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007324 char_u *q = curwin->w_s->b_p_spl;
7325
7326 /* Skip the first name if it is "cjk". */
7327 if (STRNCMP(q, "cjk,", 4) == 0)
7328 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007329
7330 /*
7331 * Source the spell/LANG.vim in 'runtimepath'.
7332 * They could set 'spellcapcheck' depending on the language.
7333 * Use the first name in 'spelllang' up to '_region' or
7334 * '.encoding'.
7335 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007336 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007337 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7338 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007339 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007340 source_runtime(fname, TRUE);
7341 }
7342#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007343 }
7344
7345#ifdef FEAT_MOUSE
7346 if (varp == &p_mouse)
7347 {
7348# ifdef FEAT_MOUSE_TTY
7349 if (*p_mouse == NUL)
7350 mch_setmouse(FALSE); /* switch mouse off */
7351 else
7352# endif
7353 setmouse(); /* in case 'mouse' changed */
7354 }
7355#endif
7356
Bram Moolenaar913077c2012-03-28 19:59:04 +02007357 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007358 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007359 curwin->w_set_curswant = TRUE;
7360
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007361#ifdef FEAT_GUI
7362 /* check redraw when it's not a GUI option or the GUI is active. */
7363 if (!redraw_gui_only || gui.in_use)
7364#endif
7365 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007366
7367 return errmsg;
7368}
7369
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007370#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007371/*
7372 * Simple int comparison function for use with qsort()
7373 */
7374 static int
7375int_cmp(a, b)
7376 const void *a;
7377 const void *b;
7378{
7379 return *(const int *)a - *(const int *)b;
7380}
7381
7382/*
7383 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7384 * Returns error message, NULL if it's OK.
7385 */
7386 char_u *
7387check_colorcolumn(wp)
7388 win_T *wp;
7389{
7390 char_u *s;
7391 int col;
7392 int count = 0;
7393 int color_cols[256];
7394 int i;
7395 int j = 0;
7396
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007397 if (wp->w_buffer == NULL)
7398 return NULL; /* buffer was closed */
7399
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007400 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007401 {
7402 if (*s == '-' || *s == '+')
7403 {
7404 /* -N and +N: add to 'textwidth' */
7405 col = (*s == '-') ? -1 : 1;
7406 ++s;
7407 if (!VIM_ISDIGIT(*s))
7408 return e_invarg;
7409 col = col * getdigits(&s);
7410 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007411 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007412 col += wp->w_buffer->b_p_tw;
7413 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007414 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007415 }
7416 else if (VIM_ISDIGIT(*s))
7417 col = getdigits(&s);
7418 else
7419 return e_invarg;
7420 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007421skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007422 if (*s == NUL)
7423 break;
7424 if (*s != ',')
7425 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007426 if (*++s == NUL)
7427 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007428 }
7429
7430 vim_free(wp->w_p_cc_cols);
7431 if (count == 0)
7432 wp->w_p_cc_cols = NULL;
7433 else
7434 {
7435 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7436 if (wp->w_p_cc_cols != NULL)
7437 {
7438 /* sort the columns for faster usage on screen redraw inside
7439 * win_line() */
7440 qsort(color_cols, count, sizeof(int), int_cmp);
7441
7442 for (i = 0; i < count; ++i)
7443 /* skip duplicates */
7444 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7445 wp->w_p_cc_cols[j++] = color_cols[i];
7446 wp->w_p_cc_cols[j] = -1; /* end marker */
7447 }
7448 }
7449
7450 return NULL; /* no error */
7451}
7452#endif
7453
Bram Moolenaar071d4272004-06-13 20:20:40 +00007454/*
7455 * Handle setting 'listchars' or 'fillchars'.
7456 * Returns error message, NULL if it's OK.
7457 */
7458 static char_u *
7459set_chars_option(varp)
7460 char_u **varp;
7461{
7462 int round, i, len, entries;
7463 char_u *p, *s;
7464 int c1, c2 = 0;
7465 struct charstab
7466 {
7467 int *cp;
7468 char *name;
7469 };
7470#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7471 static struct charstab filltab[] =
7472 {
7473 {&fill_stl, "stl"},
7474 {&fill_stlnc, "stlnc"},
7475 {&fill_vert, "vert"},
7476 {&fill_fold, "fold"},
7477 {&fill_diff, "diff"},
7478 };
7479#endif
7480 static struct charstab lcstab[] =
7481 {
7482 {&lcs_eol, "eol"},
7483 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007484 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007485 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007486 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007487 {&lcs_tab2, "tab"},
7488 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007489#ifdef FEAT_CONCEAL
7490 {&lcs_conceal, "conceal"},
7491#else
7492 {NULL, "conceal"},
7493#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007494 };
7495 struct charstab *tab;
7496
7497#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7498 if (varp == &p_lcs)
7499#endif
7500 {
7501 tab = lcstab;
7502 entries = sizeof(lcstab) / sizeof(struct charstab);
7503 }
7504#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7505 else
7506 {
7507 tab = filltab;
7508 entries = sizeof(filltab) / sizeof(struct charstab);
7509 }
7510#endif
7511
7512 /* first round: check for valid value, second round: assign values */
7513 for (round = 0; round <= 1; ++round)
7514 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007515 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007516 {
7517 /* After checking that the value is valid: set defaults: space for
7518 * 'fillchars', NUL for 'listchars' */
7519 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007520 if (tab[i].cp != NULL)
7521 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007522 if (varp == &p_lcs)
7523 lcs_tab1 = NUL;
7524#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7525 else
7526 fill_diff = '-';
7527#endif
7528 }
7529 p = *varp;
7530 while (*p)
7531 {
7532 for (i = 0; i < entries; ++i)
7533 {
7534 len = (int)STRLEN(tab[i].name);
7535 if (STRNCMP(p, tab[i].name, len) == 0
7536 && p[len] == ':'
7537 && p[len + 1] != NUL)
7538 {
7539 s = p + len + 1;
7540#ifdef FEAT_MBYTE
7541 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007542 if (mb_char2cells(c1) > 1)
7543 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007544#else
7545 c1 = *s++;
7546#endif
7547 if (tab[i].cp == &lcs_tab2)
7548 {
7549 if (*s == NUL)
7550 continue;
7551#ifdef FEAT_MBYTE
7552 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007553 if (mb_char2cells(c2) > 1)
7554 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007555#else
7556 c2 = *s++;
7557#endif
7558 }
7559 if (*s == ',' || *s == NUL)
7560 {
7561 if (round)
7562 {
7563 if (tab[i].cp == &lcs_tab2)
7564 {
7565 lcs_tab1 = c1;
7566 lcs_tab2 = c2;
7567 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007568 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007569 *(tab[i].cp) = c1;
7570
7571 }
7572 p = s;
7573 break;
7574 }
7575 }
7576 }
7577
7578 if (i == entries)
7579 return e_invarg;
7580 if (*p == ',')
7581 ++p;
7582 }
7583 }
7584
7585 return NULL; /* no error */
7586}
7587
7588#ifdef FEAT_STL_OPT
7589/*
7590 * Check validity of options with the 'statusline' format.
7591 * Return error message or NULL.
7592 */
7593 char_u *
7594check_stl_option(s)
7595 char_u *s;
7596{
7597 int itemcnt = 0;
7598 int groupdepth = 0;
7599 static char_u errbuf[80];
7600
7601 while (*s && itemcnt < STL_MAX_ITEM)
7602 {
7603 /* Check for valid keys after % sequences */
7604 while (*s && *s != '%')
7605 s++;
7606 if (!*s)
7607 break;
7608 s++;
7609 if (*s != '%' && *s != ')')
7610 ++itemcnt;
7611 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7612 {
7613 s++;
7614 continue;
7615 }
7616 if (*s == ')')
7617 {
7618 s++;
7619 if (--groupdepth < 0)
7620 break;
7621 continue;
7622 }
7623 if (*s == '-')
7624 s++;
7625 while (VIM_ISDIGIT(*s))
7626 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007627 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007628 continue;
7629 if (*s == '.')
7630 {
7631 s++;
7632 while (*s && VIM_ISDIGIT(*s))
7633 s++;
7634 }
7635 if (*s == '(')
7636 {
7637 groupdepth++;
7638 continue;
7639 }
7640 if (vim_strchr(STL_ALL, *s) == NULL)
7641 {
7642 return illegal_char(errbuf, *s);
7643 }
7644 if (*s == '{')
7645 {
7646 s++;
7647 while (*s != '}' && *s)
7648 s++;
7649 if (*s != '}')
7650 return (char_u *)N_("E540: Unclosed expression sequence");
7651 }
7652 }
7653 if (itemcnt >= STL_MAX_ITEM)
7654 return (char_u *)N_("E541: too many items");
7655 if (groupdepth != 0)
7656 return (char_u *)N_("E542: unbalanced groups");
7657 return NULL;
7658}
7659#endif
7660
7661#ifdef FEAT_CLIPBOARD
7662/*
7663 * Extract the items in the 'clipboard' option and set global values.
7664 */
7665 static char_u *
7666check_clipboard_option()
7667{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007668 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007669 int new_autoselect_star = FALSE;
7670 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007671 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007672 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007673 regprog_T *new_exclude_prog = NULL;
7674 char_u *errmsg = NULL;
7675 char_u *p;
7676
7677 for (p = p_cb; *p != NUL; )
7678 {
7679 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7680 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007681 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007682 p += 7;
7683 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007684 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007685 && (p[11] == ',' || p[11] == NUL))
7686 {
7687 new_unnamed |= CLIP_UNNAMED_PLUS;
7688 p += 11;
7689 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007690 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007691 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007692 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007693 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007694 p += 10;
7695 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007696 else if (STRNCMP(p, "autoselectplus", 14) == 0
7697 && (p[14] == ',' || p[14] == NUL))
7698 {
7699 new_autoselect_plus = TRUE;
7700 p += 14;
7701 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007702 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007703 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007704 {
7705 new_autoselectml = TRUE;
7706 p += 12;
7707 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007708 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7709 {
7710 new_html = TRUE;
7711 p += 4;
7712 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7714 {
7715 p += 8;
7716 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7717 if (new_exclude_prog == NULL)
7718 errmsg = e_invarg;
7719 break;
7720 }
7721 else
7722 {
7723 errmsg = e_invarg;
7724 break;
7725 }
7726 if (*p == ',')
7727 ++p;
7728 }
7729 if (errmsg == NULL)
7730 {
7731 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007732 clip_autoselect_star = new_autoselect_star;
7733 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007734 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007735 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007736 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007737 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007738#ifdef FEAT_GUI_GTK
7739 if (gui.in_use)
7740 {
7741 gui_gtk_set_selection_targets();
7742 gui_gtk_set_dnd_targets();
7743 }
7744#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007745 }
7746 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007747 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748
7749 return errmsg;
7750}
7751#endif
7752
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007753#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007754 static char_u *
7755did_set_spell_option(is_spellfile)
7756 int is_spellfile;
7757{
7758 char_u *errmsg = NULL;
7759 win_T *wp;
7760 int l;
7761
7762 if (is_spellfile)
7763 {
7764 l = (int)STRLEN(curwin->w_s->b_p_spf);
7765 if (l > 0 && (l < 4
7766 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7767 errmsg = e_invarg;
7768 }
7769
7770 if (errmsg == NULL)
7771 {
7772 FOR_ALL_WINDOWS(wp)
7773 if (wp->w_buffer == curbuf && wp->w_p_spell)
7774 {
7775 errmsg = did_set_spelllang(wp);
7776# ifdef FEAT_WINDOWS
7777 break;
7778# endif
7779 }
7780 }
7781 return errmsg;
7782}
7783
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007784/*
7785 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7786 * Return error message when failed, NULL when OK.
7787 */
7788 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007789compile_cap_prog(synblock)
7790 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007791{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007792 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007793 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007794
Bram Moolenaar860cae12010-06-05 23:22:07 +02007795 if (*synblock->b_p_spc == NUL)
7796 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007797 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007798 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007799 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007800 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007801 if (re != NULL)
7802 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007803 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007804 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007805 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007806 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007807 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007808 return e_invarg;
7809 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007810 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007811 }
7812
Bram Moolenaar473de612013-06-08 18:19:48 +02007813 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007814 return NULL;
7815}
7816#endif
7817
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007818#if defined(FEAT_EVAL) || defined(PROTO)
7819/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007820 * Set the scriptID for an option, taking care of setting the buffer- or
7821 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007822 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007823 static void
7824set_option_scriptID_idx(opt_idx, opt_flags, id)
7825 int opt_idx;
7826 int opt_flags;
7827 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007828{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007829 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7830 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007831
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007832 /* Remember where the option was set. For local options need to do that
7833 * in the buffer or window structure. */
7834 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007835 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007836 if (both || (opt_flags & OPT_LOCAL))
7837 {
7838 if (indir & PV_BUF)
7839 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7840 else if (indir & PV_WIN)
7841 curwin->w_p_scriptID[indir & PV_MASK] = id;
7842 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007843}
7844#endif
7845
Bram Moolenaar071d4272004-06-13 20:20:40 +00007846/*
7847 * Set the value of a boolean option, and take care of side effects.
7848 * Returns NULL for success, or an error message for an error.
7849 */
7850 static char_u *
7851set_bool_option(opt_idx, varp, value, opt_flags)
7852 int opt_idx; /* index in options[] table */
7853 char_u *varp; /* pointer to the option variable */
7854 int value; /* new value */
7855 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7856{
7857 int old_value = *(int *)varp;
7858
Bram Moolenaar071d4272004-06-13 20:20:40 +00007859 /* Disallow changing some options from secure mode */
7860 if ((secure
7861#ifdef HAVE_SANDBOX
7862 || sandbox != 0
7863#endif
7864 ) && (options[opt_idx].flags & P_SECURE))
7865 return e_secure;
7866
7867 *(int *)varp = value; /* set the new value */
7868#ifdef FEAT_EVAL
7869 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007870 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007871#endif
7872
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007873#ifdef FEAT_GUI
7874 need_mouse_correct = TRUE;
7875#endif
7876
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877 /* May set global value for local option. */
7878 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7879 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7880
7881 /*
7882 * Handle side effects of changing a bool option.
7883 */
7884
7885 /* 'compatible' */
7886 if ((int *)varp == &p_cp)
7887 {
7888 compatible_set();
7889 }
7890
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007891#ifdef FEAT_PERSISTENT_UNDO
7892 /* 'undofile' */
7893 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7894 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007895 /* Only take action when the option was set. When reset we do not
7896 * delete the undo file, the option may be set again without making
7897 * any changes in between. */
7898 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007899 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007900 char_u hash[UNDO_HASH_SIZE];
7901 buf_T *save_curbuf = curbuf;
7902
7903 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007904 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007905 /* When 'undofile' is set globally: for every buffer, otherwise
7906 * only for the current buffer: Try to read in the undofile,
7907 * if one exists, the buffer wasn't changed and the buffer was
7908 * loaded */
7909 if ((curbuf == save_curbuf
7910 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7911 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7912 {
7913 u_compute_hash(hash);
7914 u_read_undo(NULL, hash, curbuf->b_fname);
7915 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007916 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007917 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007918 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007919 }
7920#endif
7921
Bram Moolenaar071d4272004-06-13 20:20:40 +00007922 else if ((int *)varp == &curbuf->b_p_ro)
7923 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007924 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7926 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007927
7928 /* when 'readonly' is set may give W10 again */
7929 if (curbuf->b_p_ro)
7930 curbuf->b_did_warn = FALSE;
7931
Bram Moolenaar071d4272004-06-13 20:20:40 +00007932#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007933 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007934#endif
7935 }
7936
Bram Moolenaar9c449722010-07-20 18:44:27 +02007937#ifdef FEAT_GUI
7938 else if ((int *)varp == &p_mh)
7939 {
7940 if (!p_mh)
7941 gui_mch_mousehide(FALSE);
7942 }
7943#endif
7944
Bram Moolenaara539df02010-08-01 14:35:05 +02007945#ifdef FEAT_TITLE
7946 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007948 {
7949 redraw_titles();
7950 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007951 /* when 'endofline' is changed, redraw the window title */
7952 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007953 {
7954 redraw_titles();
7955 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007956 /* when 'fixeol' is changed, redraw the window title */
7957 else if ((int *)varp == &curbuf->b_p_fixeol)
7958 {
7959 redraw_titles();
7960 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007961# ifdef FEAT_MBYTE
7962 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007963 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007964 {
7965 redraw_titles();
7966 }
7967# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968#endif
7969
7970 /* when 'bin' is set also set some other options */
7971 else if ((int *)varp == &curbuf->b_p_bin)
7972 {
7973 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7974#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007975 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976#endif
7977 }
7978
7979#ifdef FEAT_AUTOCMD
7980 /* when 'buflisted' changes, trigger autocommands */
7981 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7982 {
7983 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7984 NULL, NULL, TRUE, curbuf);
7985 }
7986#endif
7987
7988 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7989 else if ((int *)varp == &curbuf->b_p_swf)
7990 {
7991 if (curbuf->b_p_swf && p_uc)
7992 ml_open_file(curbuf); /* create the swap file */
7993 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007994 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7995 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996 mf_close_file(curbuf, TRUE); /* remove the swap file */
7997 }
7998
7999 /* when 'terse' is set change 'shortmess' */
8000 else if ((int *)varp == &p_terse)
8001 {
8002 char_u *p;
8003
8004 p = vim_strchr(p_shm, SHM_SEARCH);
8005
8006 /* insert 's' in p_shm */
8007 if (p_terse && p == NULL)
8008 {
8009 STRCPY(IObuff, p_shm);
8010 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008011 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008012 }
8013 /* remove 's' from p_shm */
8014 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008015 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 }
8017
8018 /* when 'paste' is set or reset also change other options */
8019 else if ((int *)varp == &p_paste)
8020 {
8021 paste_option_changed();
8022 }
8023
8024 /* when 'insertmode' is set from an autocommand need to do work here */
8025 else if ((int *)varp == &p_im)
8026 {
8027 if (p_im)
8028 {
8029 if ((State & INSERT) == 0)
8030 need_start_insertmode = TRUE;
8031 stop_insert_mode = FALSE;
8032 }
8033 else
8034 {
8035 need_start_insertmode = FALSE;
8036 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008037 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008038 clear_cmdline = TRUE; /* remove "(insert)" */
8039 restart_edit = 0;
8040 }
8041 }
8042
8043 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8044 else if ((int *)varp == &p_ic && p_hls)
8045 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008046 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008047 }
8048
8049#ifdef FEAT_SEARCH_EXTRA
8050 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8051 else if ((int *)varp == &p_hls)
8052 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008053 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008054 }
8055#endif
8056
8057#ifdef FEAT_SCROLLBIND
8058 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8059 * at the end of normal_cmd() */
8060 else if ((int *)varp == &curwin->w_p_scb)
8061 {
8062 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008063 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008065 curwin->w_scbind_pos = curwin->w_topline;
8066 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008067 }
8068#endif
8069
8070#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8071 /* There can be only one window with 'previewwindow' set. */
8072 else if ((int *)varp == &curwin->w_p_pvw)
8073 {
8074 if (curwin->w_p_pvw)
8075 {
8076 win_T *win;
8077
8078 for (win = firstwin; win != NULL; win = win->w_next)
8079 if (win->w_p_pvw && win != curwin)
8080 {
8081 curwin->w_p_pvw = FALSE;
8082 return (char_u *)N_("E590: A preview window already exists");
8083 }
8084 }
8085 }
8086#endif
8087
8088 /* when 'textmode' is set or reset also change 'fileformat' */
8089 else if ((int *)varp == &curbuf->b_p_tx)
8090 {
8091 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8092 }
8093
8094 /* when 'textauto' is set or reset also change 'fileformats' */
8095 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008096 set_string_option_direct((char_u *)"ffs", -1,
8097 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008098 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008099
8100 /*
8101 * When 'lisp' option changes include/exclude '-' in
8102 * keyword characters.
8103 */
8104#ifdef FEAT_LISP
8105 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8106 {
8107 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8108 }
8109#endif
8110
8111#ifdef FEAT_TITLE
8112 /* when 'title' changed, may need to change the title; same for 'icon' */
8113 else if ((int *)varp == &p_title)
8114 {
8115 did_set_title(FALSE);
8116 }
8117
8118 else if ((int *)varp == &p_icon)
8119 {
8120 did_set_title(TRUE);
8121 }
8122#endif
8123
8124 else if ((int *)varp == &curbuf->b_changed)
8125 {
8126 if (!value)
8127 save_file_ff(curbuf); /* Buffer is unchanged */
8128#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008129 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008130#endif
8131#ifdef FEAT_AUTOCMD
8132 modified_was_set = value;
8133#endif
8134 }
8135
8136#ifdef BACKSLASH_IN_FILENAME
8137 else if ((int *)varp == &p_ssl)
8138 {
8139 if (p_ssl)
8140 {
8141 psepc = '/';
8142 psepcN = '\\';
8143 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144 }
8145 else
8146 {
8147 psepc = '\\';
8148 psepcN = '/';
8149 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 }
8151
8152 /* need to adjust the file name arguments and buffer names. */
8153 buflist_slash_adjust();
8154 alist_slash_adjust();
8155# ifdef FEAT_EVAL
8156 scriptnames_slash_adjust();
8157# endif
8158 }
8159#endif
8160
8161 /* If 'wrap' is set, set w_leftcol to zero. */
8162 else if ((int *)varp == &curwin->w_p_wrap)
8163 {
8164 if (curwin->w_p_wrap)
8165 curwin->w_leftcol = 0;
8166 }
8167
8168#ifdef FEAT_WINDOWS
8169 else if ((int *)varp == &p_ea)
8170 {
8171 if (p_ea && !old_value)
8172 win_equal(curwin, FALSE, 0);
8173 }
8174#endif
8175
8176 else if ((int *)varp == &p_wiv)
8177 {
8178 /*
8179 * When 'weirdinvert' changed, set/reset 't_xs'.
8180 * Then set 'weirdinvert' according to value of 't_xs'.
8181 */
8182 if (p_wiv && !old_value)
8183 T_XS = (char_u *)"y";
8184 else if (!p_wiv && old_value)
8185 T_XS = empty_option;
8186 p_wiv = (*T_XS != NUL);
8187 }
8188
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008189#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190 else if ((int *)varp == &p_beval)
8191 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008192 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008194 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195 gui_mch_disable_beval_area(balloonEval);
8196 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008197#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008199#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200 else if ((int *)varp == &p_acd)
8201 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008202 /* Change directories when the 'acd' option is set now. */
8203 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008204 }
8205#endif
8206
8207#ifdef FEAT_DIFF
8208 /* 'diff' */
8209 else if ((int *)varp == &curwin->w_p_diff)
8210 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008211 /* May add or remove the buffer from the list of diff buffers. */
8212 diff_buf_adjust(curwin);
8213# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008214 if (foldmethodIsDiff(curwin))
8215 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008216# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008217 }
8218#endif
8219
8220#ifdef USE_IM_CONTROL
8221 /* 'imdisable' */
8222 else if ((int *)varp == &p_imdisable)
8223 {
8224 /* Only de-activate it here, it will be enabled when changing mode. */
8225 if (p_imdisable)
8226 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008227 else if (State & INSERT)
8228 /* When the option is set from an autocommand, it may need to take
8229 * effect right away. */
8230 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008231 }
8232#endif
8233
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008234#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008235 /* 'spell' */
8236 else if ((int *)varp == &curwin->w_p_spell)
8237 {
8238 if (curwin->w_p_spell)
8239 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008240 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008241 if (errmsg != NULL)
8242 EMSG(_(errmsg));
8243 }
8244 }
8245#endif
8246
Bram Moolenaar071d4272004-06-13 20:20:40 +00008247#ifdef FEAT_FKMAP
8248 else if ((int *)varp == &p_altkeymap)
8249 {
8250 if (old_value != p_altkeymap)
8251 {
8252 if (!p_altkeymap)
8253 {
8254 p_hkmap = p_fkmap;
8255 p_fkmap = 0;
8256 }
8257 else
8258 {
8259 p_fkmap = p_hkmap;
8260 p_hkmap = 0;
8261 }
8262 (void)init_chartab();
8263 }
8264 }
8265
8266 /*
8267 * In case some second language keymapping options have changed, check
8268 * and correct the setting in a consistent way.
8269 */
8270
8271 /*
8272 * If hkmap or fkmap are set, reset Arabic keymapping.
8273 */
8274 if ((p_hkmap || p_fkmap) && p_altkeymap)
8275 {
8276 p_altkeymap = p_fkmap;
8277# ifdef FEAT_ARABIC
8278 curwin->w_p_arab = FALSE;
8279# endif
8280 (void)init_chartab();
8281 }
8282
8283 /*
8284 * If hkmap set, reset Farsi keymapping.
8285 */
8286 if (p_hkmap && p_altkeymap)
8287 {
8288 p_altkeymap = 0;
8289 p_fkmap = 0;
8290# ifdef FEAT_ARABIC
8291 curwin->w_p_arab = FALSE;
8292# endif
8293 (void)init_chartab();
8294 }
8295
8296 /*
8297 * If fkmap set, reset Hebrew keymapping.
8298 */
8299 if (p_fkmap && !p_altkeymap)
8300 {
8301 p_altkeymap = 1;
8302 p_hkmap = 0;
8303# ifdef FEAT_ARABIC
8304 curwin->w_p_arab = FALSE;
8305# endif
8306 (void)init_chartab();
8307 }
8308#endif
8309
8310#ifdef FEAT_ARABIC
8311 if ((int *)varp == &curwin->w_p_arab)
8312 {
8313 if (curwin->w_p_arab)
8314 {
8315 /*
8316 * 'arabic' is set, handle various sub-settings.
8317 */
8318 if (!p_tbidi)
8319 {
8320 /* set rightleft mode */
8321 if (!curwin->w_p_rl)
8322 {
8323 curwin->w_p_rl = TRUE;
8324 changed_window_setting();
8325 }
8326
8327 /* Enable Arabic shaping (major part of what Arabic requires) */
8328 if (!p_arshape)
8329 {
8330 p_arshape = TRUE;
8331 redraw_later_clear();
8332 }
8333 }
8334
8335 /* Arabic requires a utf-8 encoding, inform the user if its not
8336 * set. */
8337 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008338 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008339 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8340
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008341 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008342 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8343#ifdef FEAT_EVAL
8344 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8345#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008346 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008347
8348# ifdef FEAT_MBYTE
8349 /* set 'delcombine' */
8350 p_deco = TRUE;
8351# endif
8352
8353# ifdef FEAT_KEYMAP
8354 /* Force-set the necessary keymap for arabic */
8355 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8356 OPT_LOCAL);
8357# endif
8358# ifdef FEAT_FKMAP
8359 p_altkeymap = 0;
8360 p_hkmap = 0;
8361 p_fkmap = 0;
8362 (void)init_chartab();
8363# endif
8364 }
8365 else
8366 {
8367 /*
8368 * 'arabic' is reset, handle various sub-settings.
8369 */
8370 if (!p_tbidi)
8371 {
8372 /* reset rightleft mode */
8373 if (curwin->w_p_rl)
8374 {
8375 curwin->w_p_rl = FALSE;
8376 changed_window_setting();
8377 }
8378
8379 /* 'arabicshape' isn't reset, it is a global option and
8380 * another window may still need it "on". */
8381 }
8382
8383 /* 'delcombine' isn't reset, it is a global option and another
8384 * window may still want it "on". */
8385
8386# ifdef FEAT_KEYMAP
8387 /* Revert to the default keymap */
8388 curbuf->b_p_iminsert = B_IMODE_NONE;
8389 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8390# endif
8391 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008392 }
8393
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008394#endif
8395
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396 /*
8397 * End of handling side effects for bool options.
8398 */
8399
Bram Moolenaar53744302015-07-17 17:38:22 +02008400 /* after handling side effects, call autocommand */
8401
Bram Moolenaar071d4272004-06-13 20:20:40 +00008402 options[opt_idx].flags |= P_WAS_SET;
8403
Bram Moolenaar53744302015-07-17 17:38:22 +02008404#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8405 if (!starting)
8406 {
8407 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008408 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8409 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8410 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008411 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8412 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8413 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8414 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8415 reset_v_option_vars();
8416 }
8417#endif
8418
Bram Moolenaar071d4272004-06-13 20:20:40 +00008419 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008420 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008421 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008422 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423 check_redraw(options[opt_idx].flags);
8424
8425 return NULL;
8426}
8427
8428/*
8429 * Set the value of a number option, and take care of side effects.
8430 * Returns NULL for success, or an error message for an error.
8431 */
8432 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008433set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 int opt_idx; /* index in options[] table */
8435 char_u *varp; /* pointer to the option variable */
8436 long value; /* new value */
8437 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008438 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008439 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8440 OPT_MODELINE */
8441{
8442 char_u *errmsg = NULL;
8443 long old_value = *(long *)varp;
8444 long old_Rows = Rows; /* remember old Rows */
8445 long old_Columns = Columns; /* remember old Columns */
8446 long *pp = (long *)varp;
8447
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008448 /* Disallow changing some options from secure mode. */
8449 if ((secure
8450#ifdef HAVE_SANDBOX
8451 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008452#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008453 ) && (options[opt_idx].flags & P_SECURE))
8454 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008455
8456 *pp = value;
8457#ifdef FEAT_EVAL
8458 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008459 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008461#ifdef FEAT_GUI
8462 need_mouse_correct = TRUE;
8463#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464
Bram Moolenaar14f24742012-08-08 18:01:05 +02008465 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466 {
8467 errmsg = e_positive;
8468 curbuf->b_p_sw = curbuf->b_p_ts;
8469 }
8470
8471 /*
8472 * Number options that need some action when changed
8473 */
8474#ifdef FEAT_WINDOWS
8475 if (pp == &p_wh || pp == &p_hh)
8476 {
8477 if (p_wh < 1)
8478 {
8479 errmsg = e_positive;
8480 p_wh = 1;
8481 }
8482 if (p_wmh > p_wh)
8483 {
8484 errmsg = e_winheight;
8485 p_wh = p_wmh;
8486 }
8487 if (p_hh < 0)
8488 {
8489 errmsg = e_positive;
8490 p_hh = 0;
8491 }
8492
8493 /* Change window height NOW */
8494 if (lastwin != firstwin)
8495 {
8496 if (pp == &p_wh && curwin->w_height < p_wh)
8497 win_setheight((int)p_wh);
8498 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8499 win_setheight((int)p_hh);
8500 }
8501 }
8502
8503 /* 'winminheight' */
8504 else if (pp == &p_wmh)
8505 {
8506 if (p_wmh < 0)
8507 {
8508 errmsg = e_positive;
8509 p_wmh = 0;
8510 }
8511 if (p_wmh > p_wh)
8512 {
8513 errmsg = e_winheight;
8514 p_wmh = p_wh;
8515 }
8516 win_setminheight();
8517 }
8518
8519# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008520 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521 {
8522 if (p_wiw < 1)
8523 {
8524 errmsg = e_positive;
8525 p_wiw = 1;
8526 }
8527 if (p_wmw > p_wiw)
8528 {
8529 errmsg = e_winwidth;
8530 p_wiw = p_wmw;
8531 }
8532
8533 /* Change window width NOW */
8534 if (lastwin != firstwin && curwin->w_width < p_wiw)
8535 win_setwidth((int)p_wiw);
8536 }
8537
8538 /* 'winminwidth' */
8539 else if (pp == &p_wmw)
8540 {
8541 if (p_wmw < 0)
8542 {
8543 errmsg = e_positive;
8544 p_wmw = 0;
8545 }
8546 if (p_wmw > p_wiw)
8547 {
8548 errmsg = e_winwidth;
8549 p_wmw = p_wiw;
8550 }
8551 win_setminheight();
8552 }
8553# endif
8554
8555#endif
8556
8557#ifdef FEAT_WINDOWS
8558 /* (re)set last window status line */
8559 else if (pp == &p_ls)
8560 {
8561 last_status(FALSE);
8562 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008563
8564 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008565 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008566 {
8567 shell_new_rows(); /* recompute window positions and heights */
8568 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008569#endif
8570
8571#ifdef FEAT_GUI
8572 else if (pp == &p_linespace)
8573 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008574 /* Recompute gui.char_height and resize the Vim window to keep the
8575 * same number of lines. */
8576 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008577 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008578 }
8579#endif
8580
8581#ifdef FEAT_FOLDING
8582 /* 'foldlevel' */
8583 else if (pp == &curwin->w_p_fdl)
8584 {
8585 if (curwin->w_p_fdl < 0)
8586 curwin->w_p_fdl = 0;
8587 newFoldLevel();
8588 }
8589
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008590 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 else if (pp == &curwin->w_p_fml)
8592 {
8593 foldUpdateAll(curwin);
8594 }
8595
8596 /* 'foldnestmax' */
8597 else if (pp == &curwin->w_p_fdn)
8598 {
8599 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8600 foldUpdateAll(curwin);
8601 }
8602
8603 /* 'foldcolumn' */
8604 else if (pp == &curwin->w_p_fdc)
8605 {
8606 if (curwin->w_p_fdc < 0)
8607 {
8608 errmsg = e_positive;
8609 curwin->w_p_fdc = 0;
8610 }
8611 else if (curwin->w_p_fdc > 12)
8612 {
8613 errmsg = e_invarg;
8614 curwin->w_p_fdc = 12;
8615 }
8616 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008617#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008619#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008620 /* 'shiftwidth' or 'tabstop' */
8621 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8622 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008623# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624 if (foldmethodIsIndent(curwin))
8625 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008626# endif
8627# ifdef FEAT_CINDENT
8628 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8629 * parse 'cinoptions'. */
8630 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8631 parse_cino(curbuf);
8632# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008633 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008634#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008636#ifdef FEAT_MBYTE
8637 /* 'maxcombine' */
8638 else if (pp == &p_mco)
8639 {
8640 if (p_mco > MAX_MCO)
8641 p_mco = MAX_MCO;
8642 else if (p_mco < 0)
8643 p_mco = 0;
8644 screenclear(); /* will re-allocate the screen */
8645 }
8646#endif
8647
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648 else if (pp == &curbuf->b_p_iminsert)
8649 {
8650 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8651 {
8652 errmsg = e_invarg;
8653 curbuf->b_p_iminsert = B_IMODE_NONE;
8654 }
8655 p_iminsert = curbuf->b_p_iminsert;
8656 if (termcap_active) /* don't do this in the alternate screen */
8657 showmode();
8658#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8659 /* Show/unshow value of 'keymap' in status lines. */
8660 status_redraw_curbuf();
8661#endif
8662 }
8663
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008664 else if (pp == &p_window)
8665 {
8666 if (p_window < 1)
8667 p_window = 1;
8668 else if (p_window >= Rows)
8669 p_window = Rows - 1;
8670 }
8671
Bram Moolenaar071d4272004-06-13 20:20:40 +00008672 else if (pp == &curbuf->b_p_imsearch)
8673 {
8674 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8675 {
8676 errmsg = e_invarg;
8677 curbuf->b_p_imsearch = B_IMODE_NONE;
8678 }
8679 p_imsearch = curbuf->b_p_imsearch;
8680 }
8681
8682#ifdef FEAT_TITLE
8683 /* if 'titlelen' has changed, redraw the title */
8684 else if (pp == &p_titlelen)
8685 {
8686 if (p_titlelen < 0)
8687 {
8688 errmsg = e_positive;
8689 p_titlelen = 85;
8690 }
8691 if (starting != NO_SCREEN && old_value != p_titlelen)
8692 need_maketitle = TRUE;
8693 }
8694#endif
8695
8696 /* if p_ch changed value, change the command line height */
8697 else if (pp == &p_ch)
8698 {
8699 if (p_ch < 1)
8700 {
8701 errmsg = e_positive;
8702 p_ch = 1;
8703 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008704 if (p_ch > Rows - min_rows() + 1)
8705 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008706
8707 /* Only compute the new window layout when startup has been
8708 * completed. Otherwise the frame sizes may be wrong. */
8709 if (p_ch != old_value && full_screen
8710#ifdef FEAT_GUI
8711 && !gui.starting
8712#endif
8713 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008714 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008715 }
8716
8717 /* when 'updatecount' changes from zero to non-zero, open swap files */
8718 else if (pp == &p_uc)
8719 {
8720 if (p_uc < 0)
8721 {
8722 errmsg = e_positive;
8723 p_uc = 100;
8724 }
8725 if (p_uc && !old_value)
8726 ml_open_files();
8727 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008728#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008729 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008730 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008731 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008732 {
8733 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008734 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008735 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008736 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008737 {
8738 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008739 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008740 }
8741 }
8742#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008743#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008744 else if (pp == &p_mzq)
8745 mzvim_reset_timer();
8746#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008747
8748 /* sync undo before 'undolevels' changes */
8749 else if (pp == &p_ul)
8750 {
8751 /* use the old value, otherwise u_sync() may not work properly */
8752 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008753 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008754 p_ul = value;
8755 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008756 else if (pp == &curbuf->b_p_ul)
8757 {
8758 /* use the old value, otherwise u_sync() may not work properly */
8759 curbuf->b_p_ul = old_value;
8760 u_sync(TRUE);
8761 curbuf->b_p_ul = value;
8762 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008764#ifdef FEAT_LINEBREAK
8765 /* 'numberwidth' must be positive */
8766 else if (pp == &curwin->w_p_nuw)
8767 {
8768 if (curwin->w_p_nuw < 1)
8769 {
8770 errmsg = e_positive;
8771 curwin->w_p_nuw = 1;
8772 }
8773 if (curwin->w_p_nuw > 10)
8774 {
8775 errmsg = e_invarg;
8776 curwin->w_p_nuw = 10;
8777 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008778 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008779 }
8780#endif
8781
Bram Moolenaar1a384422010-07-14 19:53:30 +02008782 else if (pp == &curbuf->b_p_tw)
8783 {
8784 if (curbuf->b_p_tw < 0)
8785 {
8786 errmsg = e_positive;
8787 curbuf->b_p_tw = 0;
8788 }
8789#ifdef FEAT_SYN_HL
8790# ifdef FEAT_WINDOWS
8791 {
8792 win_T *wp;
8793 tabpage_T *tp;
8794
8795 FOR_ALL_TAB_WINDOWS(tp, wp)
8796 check_colorcolumn(wp);
8797 }
8798# else
8799 check_colorcolumn(curwin);
8800# endif
8801#endif
8802 }
8803
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804 /*
8805 * Check the bounds for numeric options here
8806 */
8807 if (Rows < min_rows() && full_screen)
8808 {
8809 if (errbuf != NULL)
8810 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008811 vim_snprintf((char *)errbuf, errbuflen,
8812 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813 errmsg = errbuf;
8814 }
8815 Rows = min_rows();
8816 }
8817 if (Columns < MIN_COLUMNS && full_screen)
8818 {
8819 if (errbuf != NULL)
8820 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008821 vim_snprintf((char *)errbuf, errbuflen,
8822 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 errmsg = errbuf;
8824 }
8825 Columns = MIN_COLUMNS;
8826 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008827 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828
8829#ifdef DJGPP
8830 /* avoid a crash by checking for a too large value of 'columns' */
8831 if (old_Columns != Columns && full_screen && term_console)
8832 mch_check_columns();
8833#endif
8834
8835 /*
8836 * If the screen (shell) height has been changed, assume it is the
8837 * physical screenheight.
8838 */
8839 if (old_Rows != Rows || old_Columns != Columns)
8840 {
8841 /* Changing the screen size is not allowed while updating the screen. */
8842 if (updating_screen)
8843 *pp = old_value;
8844 else if (full_screen
8845#ifdef FEAT_GUI
8846 && !gui.starting
8847#endif
8848 )
8849 set_shellsize((int)Columns, (int)Rows, TRUE);
8850 else
8851 {
8852 /* Postpone the resizing; check the size and cmdline position for
8853 * messages. */
8854 check_shellsize();
8855 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8856 cmdline_row = Rows - p_ch;
8857 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008858 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008859 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008860 }
8861
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862 if (curbuf->b_p_ts <= 0)
8863 {
8864 errmsg = e_positive;
8865 curbuf->b_p_ts = 8;
8866 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008867 if (p_tm < 0)
8868 {
8869 errmsg = e_positive;
8870 p_tm = 0;
8871 }
8872 if ((curwin->w_p_scr <= 0
8873 || (curwin->w_p_scr > curwin->w_height
8874 && curwin->w_height > 0))
8875 && full_screen)
8876 {
8877 if (pp == &(curwin->w_p_scr))
8878 {
8879 if (curwin->w_p_scr != 0)
8880 errmsg = e_scroll;
8881 win_comp_scroll(curwin);
8882 }
8883 /* If 'scroll' became invalid because of a side effect silently adjust
8884 * it. */
8885 else if (curwin->w_p_scr <= 0)
8886 curwin->w_p_scr = 1;
8887 else /* curwin->w_p_scr > curwin->w_height */
8888 curwin->w_p_scr = curwin->w_height;
8889 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008890 if (p_hi < 0)
8891 {
8892 errmsg = e_positive;
8893 p_hi = 0;
8894 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008895 else if (p_hi > 10000)
8896 {
8897 errmsg = e_invarg;
8898 p_hi = 10000;
8899 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008900 if (p_re < 0 || p_re > 2)
8901 {
8902 errmsg = e_invarg;
8903 p_re = 0;
8904 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008905 if (p_report < 0)
8906 {
8907 errmsg = e_positive;
8908 p_report = 1;
8909 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008910 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008911 {
8912 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8913 p_sj = Rows / 2;
8914 else
8915 {
8916 errmsg = e_scroll;
8917 p_sj = 1;
8918 }
8919 }
8920 if (p_so < 0 && full_screen)
8921 {
8922 errmsg = e_scroll;
8923 p_so = 0;
8924 }
8925 if (p_siso < 0 && full_screen)
8926 {
8927 errmsg = e_positive;
8928 p_siso = 0;
8929 }
8930#ifdef FEAT_CMDWIN
8931 if (p_cwh < 1)
8932 {
8933 errmsg = e_positive;
8934 p_cwh = 1;
8935 }
8936#endif
8937 if (p_ut < 0)
8938 {
8939 errmsg = e_positive;
8940 p_ut = 2000;
8941 }
8942 if (p_ss < 0)
8943 {
8944 errmsg = e_positive;
8945 p_ss = 0;
8946 }
8947
8948 /* May set global value for local option. */
8949 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8950 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8951
8952 options[opt_idx].flags |= P_WAS_SET;
8953
Bram Moolenaar53744302015-07-17 17:38:22 +02008954#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8955 if (!starting && errmsg == NULL)
8956 {
8957 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008958 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8959 vim_snprintf((char *)buf_new, 10, "%ld", value);
8960 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008961 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8962 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8963 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8964 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8965 reset_v_option_vars();
8966 }
8967#endif
8968
Bram Moolenaar071d4272004-06-13 20:20:40 +00008969 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008970 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008971 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008972 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973 check_redraw(options[opt_idx].flags);
8974
8975 return errmsg;
8976}
8977
8978/*
8979 * Called after an option changed: check if something needs to be redrawn.
8980 */
8981 static void
8982check_redraw(flags)
8983 long_u flags;
8984{
8985 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008986 int doclear = (flags & P_RCLR) == P_RCLR;
8987 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008988
8989#ifdef FEAT_WINDOWS
8990 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8991 status_redraw_all();
8992#endif
8993
8994 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8995 changed_window_setting();
8996 if (flags & P_RBUF)
8997 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008998 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008999 redraw_all_later(CLEAR);
9000 else if (all)
9001 redraw_all_later(NOT_VALID);
9002}
9003
9004/*
9005 * Find index for option 'arg'.
9006 * Return -1 if not found.
9007 */
9008 static int
9009findoption(arg)
9010 char_u *arg;
9011{
9012 int opt_idx;
9013 char *s, *p;
9014 static short quick_tab[27] = {0, 0}; /* quick access table */
9015 int is_term_opt;
9016
9017 /*
9018 * For first call: Initialize the quick-access table.
9019 * It contains the index for the first option that starts with a certain
9020 * letter. There are 26 letters, plus the first "t_" option.
9021 */
9022 if (quick_tab[1] == 0)
9023 {
9024 p = options[0].fullname;
9025 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9026 {
9027 if (s[0] != p[0])
9028 {
9029 if (s[0] == 't' && s[1] == '_')
9030 quick_tab[26] = opt_idx;
9031 else
9032 quick_tab[CharOrdLow(s[0])] = opt_idx;
9033 }
9034 p = s;
9035 }
9036 }
9037
9038 /*
9039 * Check for name starting with an illegal character.
9040 */
9041#ifdef EBCDIC
9042 if (!islower(arg[0]))
9043#else
9044 if (arg[0] < 'a' || arg[0] > 'z')
9045#endif
9046 return -1;
9047
9048 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9049 if (is_term_opt)
9050 opt_idx = quick_tab[26];
9051 else
9052 opt_idx = quick_tab[CharOrdLow(arg[0])];
9053 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9054 {
9055 if (STRCMP(arg, s) == 0) /* match full name */
9056 break;
9057 }
9058 if (s == NULL && !is_term_opt)
9059 {
9060 opt_idx = quick_tab[CharOrdLow(arg[0])];
9061 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9062 {
9063 s = options[opt_idx].shortname;
9064 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9065 break;
9066 s = NULL;
9067 }
9068 }
9069 if (s == NULL)
9070 opt_idx = -1;
9071 return opt_idx;
9072}
9073
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009074#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075/*
9076 * Get the value for an option.
9077 *
9078 * Returns:
9079 * Number or Toggle option: 1, *numval gets value.
9080 * String option: 0, *stringval gets allocated string.
9081 * Hidden Number or Toggle option: -1.
9082 * hidden String option: -2.
9083 * unknown option: -3.
9084 */
9085 int
9086get_option_value(name, numval, stringval, opt_flags)
9087 char_u *name;
9088 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02009089 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009090 int opt_flags;
9091{
9092 int opt_idx;
9093 char_u *varp;
9094
9095 opt_idx = findoption(name);
9096 if (opt_idx < 0) /* unknown option */
9097 return -3;
9098
9099 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9100
9101 if (options[opt_idx].flags & P_STRING)
9102 {
9103 if (varp == NULL) /* hidden option */
9104 return -2;
9105 if (stringval != NULL)
9106 {
9107#ifdef FEAT_CRYPT
9108 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009109 if ((char_u **)varp == &curbuf->b_p_key
9110 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 *stringval = vim_strsave((char_u *)"*****");
9112 else
9113#endif
9114 *stringval = vim_strsave(*(char_u **)(varp));
9115 }
9116 return 0;
9117 }
9118
9119 if (varp == NULL) /* hidden option */
9120 return -1;
9121 if (options[opt_idx].flags & P_NUM)
9122 *numval = *(long *)varp;
9123 else
9124 {
9125 /* Special case: 'modified' is b_changed, but we also want to consider
9126 * it set when 'ff' or 'fenc' changed. */
9127 if ((int *)varp == &curbuf->b_changed)
9128 *numval = curbufIsChanged();
9129 else
9130 *numval = *(int *)varp;
9131 }
9132 return 1;
9133}
9134#endif
9135
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009136#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009137/*
9138 * Returns the option attributes and its value. Unlike the above function it
9139 * will return either global value or local value of the option depending on
9140 * what was requested, but it will never return global value if it was
9141 * requested to return local one and vice versa. Neither it will return
9142 * buffer-local value if it was requested to return window-local one.
9143 *
9144 * Pretends that option is absent if it is not present in the requested scope
9145 * (i.e. has no global, window-local or buffer-local value depending on
9146 * opt_type). Uses
9147 *
9148 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009149 * 0 hidden or unknown option, also option that does not have requested
9150 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009151 * see SOPT_* in vim.h for other flags
9152 *
9153 * Possible opt_type values: see SREQ_* in vim.h
9154 */
9155 int
9156get_option_value_strict(name, numval, stringval, opt_type, from)
9157 char_u *name;
9158 long *numval;
9159 char_u **stringval; /* NULL when only obtaining attributes */
9160 int opt_type;
9161 void *from;
9162{
9163 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009164 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009165 struct vimoption *p;
9166 int r = 0;
9167
9168 opt_idx = findoption(name);
9169 if (opt_idx < 0)
9170 return 0;
9171
9172 p = &(options[opt_idx]);
9173
9174 /* Hidden option */
9175 if (p->var == NULL)
9176 return 0;
9177
9178 if (p->flags & P_BOOL)
9179 r |= SOPT_BOOL;
9180 else if (p->flags & P_NUM)
9181 r |= SOPT_NUM;
9182 else if (p->flags & P_STRING)
9183 r |= SOPT_STRING;
9184
9185 if (p->indir == PV_NONE)
9186 {
9187 if (opt_type == SREQ_GLOBAL)
9188 r |= SOPT_GLOBAL;
9189 else
9190 return 0; /* Did not request global-only option */
9191 }
9192 else
9193 {
9194 if (p->indir & PV_BOTH)
9195 r |= SOPT_GLOBAL;
9196 else if (opt_type == SREQ_GLOBAL)
9197 return 0; /* Requested global option */
9198
9199 if (p->indir & PV_WIN)
9200 {
9201 if (opt_type == SREQ_BUF)
9202 return 0; /* Did not request window-local option */
9203 else
9204 r |= SOPT_WIN;
9205 }
9206 else if (p->indir & PV_BUF)
9207 {
9208 if (opt_type == SREQ_WIN)
9209 return 0; /* Did not request buffer-local option */
9210 else
9211 r |= SOPT_BUF;
9212 }
9213 }
9214
9215 if (stringval == NULL)
9216 return r;
9217
9218 if (opt_type == SREQ_GLOBAL)
9219 varp = p->var;
9220 else
9221 {
9222 if (opt_type == SREQ_BUF)
9223 {
9224 /* Special case: 'modified' is b_changed, but we also want to
9225 * consider it set when 'ff' or 'fenc' changed. */
9226 if (p->indir == PV_MOD)
9227 {
9228 *numval = bufIsChanged((buf_T *) from);
9229 varp = NULL;
9230 }
9231#ifdef FEAT_CRYPT
9232 else if (p->indir == PV_KEY)
9233 {
9234 /* never return the value of the crypt key */
9235 *stringval = NULL;
9236 varp = NULL;
9237 }
9238#endif
9239 else
9240 {
9241 aco_save_T aco;
9242 aucmd_prepbuf(&aco, (buf_T *) from);
9243 varp = get_varp(p);
9244 aucmd_restbuf(&aco);
9245 }
9246 }
9247 else if (opt_type == SREQ_WIN)
9248 {
9249 win_T *save_curwin;
9250 save_curwin = curwin;
9251 curwin = (win_T *) from;
9252 curbuf = curwin->w_buffer;
9253 varp = get_varp(p);
9254 curwin = save_curwin;
9255 curbuf = curwin->w_buffer;
9256 }
9257 if (varp == p->var)
9258 return (r | SOPT_UNSET);
9259 }
9260
9261 if (varp != NULL)
9262 {
9263 if (p->flags & P_STRING)
9264 *stringval = vim_strsave(*(char_u **)(varp));
9265 else if (p->flags & P_NUM)
9266 *numval = *(long *) varp;
9267 else
9268 *numval = *(int *)varp;
9269 }
9270
9271 return r;
9272}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009273
9274/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009275 * Iterate over options. First argument is a pointer to a pointer to a
9276 * structure inside options[] array, second is option type like in the above
9277 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009278 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009279 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009280 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009281 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009282 * first argument to NULL.
9283 *
9284 * Returns full option name for current option on each call.
9285 */
9286 char_u *
9287option_iter_next(option, opt_type)
9288 void **option;
9289 int opt_type;
9290{
9291 struct vimoption *ret = NULL;
9292 do
9293 {
9294 if (*option == NULL)
9295 *option = (void *) options;
9296 else if (((struct vimoption *) (*option))->fullname == NULL)
9297 {
9298 *option = NULL;
9299 return NULL;
9300 }
9301 else
9302 *option = (void *) (((struct vimoption *) (*option)) + 1);
9303
9304 ret = ((struct vimoption *) (*option));
9305
9306 /* Hidden option */
9307 if (ret->var == NULL)
9308 {
9309 ret = NULL;
9310 continue;
9311 }
9312
9313 switch (opt_type)
9314 {
9315 case SREQ_GLOBAL:
9316 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9317 ret = NULL;
9318 break;
9319 case SREQ_BUF:
9320 if (!(ret->indir & PV_BUF))
9321 ret = NULL;
9322 break;
9323 case SREQ_WIN:
9324 if (!(ret->indir & PV_WIN))
9325 ret = NULL;
9326 break;
9327 default:
9328 EMSG2(_(e_intern2), "option_iter_next()");
9329 return NULL;
9330 }
9331 }
9332 while (ret == NULL);
9333
9334 return (char_u *)ret->fullname;
9335}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009336#endif
9337
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338/*
9339 * Set the value of option "name".
9340 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009341 *
9342 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009344 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345set_option_value(name, number, string, opt_flags)
9346 char_u *name;
9347 long number;
9348 char_u *string;
9349 int opt_flags; /* OPT_LOCAL or 0 (both) */
9350{
9351 int opt_idx;
9352 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009353 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009354
9355 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009356 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009357 EMSG2(_("E355: Unknown option: %s"), name);
9358 else
9359 {
9360 flags = options[opt_idx].flags;
9361#ifdef HAVE_SANDBOX
9362 /* Disallow changing some options in the sandbox */
9363 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009364 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009365 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009366 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009367 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009369 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009370 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009371 else
9372 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009373 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009374 if (varp != NULL) /* hidden option is not changed */
9375 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009376 if (number == 0 && string != NULL)
9377 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009378 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009379
9380 /* Either we are given a string or we are setting option
9381 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009382 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009383 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009384 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009385 {
9386 /* There's another character after zeros or the string
9387 * is empty. In both cases, we are trying to set a
9388 * num option using a string. */
9389 EMSG3(_("E521: Number required: &%s = '%s'"),
9390 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009391 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009392
9393 }
9394 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009395 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009396 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009397 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009398 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009399 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009400 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009401 }
9402 }
9403 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009404 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009405}
9406
9407/*
9408 * Get the terminal code for a terminal option.
9409 * Returns NULL when not found.
9410 */
9411 char_u *
9412get_term_code(tname)
9413 char_u *tname;
9414{
9415 int opt_idx;
9416 char_u *varp;
9417
9418 if (tname[0] != 't' || tname[1] != '_' ||
9419 tname[2] == NUL || tname[3] == NUL)
9420 return NULL;
9421 if ((opt_idx = findoption(tname)) >= 0)
9422 {
9423 varp = get_varp(&(options[opt_idx]));
9424 if (varp != NULL)
9425 varp = *(char_u **)(varp);
9426 return varp;
9427 }
9428 return find_termcode(tname + 2);
9429}
9430
9431 char_u *
9432get_highlight_default()
9433{
9434 int i;
9435
9436 i = findoption((char_u *)"hl");
9437 if (i >= 0)
9438 return options[i].def_val[VI_DEFAULT];
9439 return (char_u *)NULL;
9440}
9441
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009442#if defined(FEAT_MBYTE) || defined(PROTO)
9443 char_u *
9444get_encoding_default()
9445{
9446 int i;
9447
9448 i = findoption((char_u *)"enc");
9449 if (i >= 0)
9450 return options[i].def_val[VI_DEFAULT];
9451 return (char_u *)NULL;
9452}
9453#endif
9454
Bram Moolenaar071d4272004-06-13 20:20:40 +00009455/*
9456 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9457 */
9458 static int
9459find_key_option(arg)
9460 char_u *arg;
9461{
9462 int key;
9463 int modifiers;
9464
9465 /*
9466 * Don't use get_special_key_code() for t_xx, we don't want it to call
9467 * add_termcap_entry().
9468 */
9469 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9470 key = TERMCAP2KEY(arg[2], arg[3]);
9471 else
9472 {
9473 --arg; /* put arg at the '<' */
9474 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009475 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009476 if (modifiers) /* can't handle modifiers here */
9477 key = 0;
9478 }
9479 return key;
9480}
9481
9482/*
9483 * if 'all' == 0: show changed options
9484 * if 'all' == 1: show all normal options
9485 * if 'all' == 2: show all terminal options
9486 */
9487 static void
9488showoptions(all, opt_flags)
9489 int all;
9490 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9491{
9492 struct vimoption *p;
9493 int col;
9494 int isterm;
9495 char_u *varp;
9496 struct vimoption **items;
9497 int item_count;
9498 int run;
9499 int row, rows;
9500 int cols;
9501 int i;
9502 int len;
9503
9504#define INC 20
9505#define GAP 3
9506
9507 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9508 PARAM_COUNT));
9509 if (items == NULL)
9510 return;
9511
9512 /* Highlight title */
9513 if (all == 2)
9514 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9515 else if (opt_flags & OPT_GLOBAL)
9516 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9517 else if (opt_flags & OPT_LOCAL)
9518 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9519 else
9520 MSG_PUTS_TITLE(_("\n--- Options ---"));
9521
9522 /*
9523 * do the loop two times:
9524 * 1. display the short items
9525 * 2. display the long items (only strings and numbers)
9526 */
9527 for (run = 1; run <= 2 && !got_int; ++run)
9528 {
9529 /*
9530 * collect the items in items[]
9531 */
9532 item_count = 0;
9533 for (p = &options[0]; p->fullname != NULL; p++)
9534 {
9535 varp = NULL;
9536 isterm = istermoption(p);
9537 if (opt_flags != 0)
9538 {
9539 if (p->indir != PV_NONE && !isterm)
9540 varp = get_varp_scope(p, opt_flags);
9541 }
9542 else
9543 varp = get_varp(p);
9544 if (varp != NULL
9545 && ((all == 2 && isterm)
9546 || (all == 1 && !isterm)
9547 || (all == 0 && !optval_default(p, varp))))
9548 {
9549 if (p->flags & P_BOOL)
9550 len = 1; /* a toggle option fits always */
9551 else
9552 {
9553 option_value2string(p, opt_flags);
9554 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9555 }
9556 if ((len <= INC - GAP && run == 1) ||
9557 (len > INC - GAP && run == 2))
9558 items[item_count++] = p;
9559 }
9560 }
9561
9562 /*
9563 * display the items
9564 */
9565 if (run == 1)
9566 {
9567 cols = (Columns + GAP - 3) / INC;
9568 if (cols == 0)
9569 cols = 1;
9570 rows = (item_count + cols - 1) / cols;
9571 }
9572 else /* run == 2 */
9573 rows = item_count;
9574 for (row = 0; row < rows && !got_int; ++row)
9575 {
9576 msg_putchar('\n'); /* go to next line */
9577 if (got_int) /* 'q' typed in more */
9578 break;
9579 col = 0;
9580 for (i = row; i < item_count; i += rows)
9581 {
9582 msg_col = col; /* make columns */
9583 showoneopt(items[i], opt_flags);
9584 col += INC;
9585 }
9586 out_flush();
9587 ui_breakcheck();
9588 }
9589 }
9590 vim_free(items);
9591}
9592
9593/*
9594 * Return TRUE if option "p" has its default value.
9595 */
9596 static int
9597optval_default(p, varp)
9598 struct vimoption *p;
9599 char_u *varp;
9600{
9601 int dvi;
9602
9603 if (varp == NULL)
9604 return TRUE; /* hidden option is always at default */
9605 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9606 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009607 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009608 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009609 /* the cast to long is required for Manx C, long_i is
9610 * needed for MSVC */
9611 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009612 /* P_STRING */
9613 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9614}
9615
9616/*
9617 * showoneopt: show the value of one option
9618 * must not be called with a hidden option!
9619 */
9620 static void
9621showoneopt(p, opt_flags)
9622 struct vimoption *p;
9623 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9624{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009625 char_u *varp;
9626 int save_silent = silent_mode;
9627
9628 silent_mode = FALSE;
9629 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009630
9631 varp = get_varp_scope(p, opt_flags);
9632
9633 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9634 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9635 ? !curbufIsChanged() : !*(int *)varp))
9636 MSG_PUTS("no");
9637 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9638 MSG_PUTS("--");
9639 else
9640 MSG_PUTS(" ");
9641 MSG_PUTS(p->fullname);
9642 if (!(p->flags & P_BOOL))
9643 {
9644 msg_putchar('=');
9645 /* put value string in NameBuff */
9646 option_value2string(p, opt_flags);
9647 msg_outtrans(NameBuff);
9648 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009649
9650 silent_mode = save_silent;
9651 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009652}
9653
9654/*
9655 * Write modified options as ":set" commands to a file.
9656 *
9657 * There are three values for "opt_flags":
9658 * OPT_GLOBAL: Write global option values and fresh values of
9659 * buffer-local options (used for start of a session
9660 * file).
9661 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9662 * curwin (used for a vimrc file).
9663 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9664 * and local values for window-local options of
9665 * curwin. Local values are also written when at the
9666 * default value, because a modeline or autocommand
9667 * may have set them when doing ":edit file" and the
9668 * user has set them back at the default or fresh
9669 * value.
9670 * When "local_only" is TRUE, don't write fresh
9671 * values, only local values (for ":mkview").
9672 * (fresh value = value used for a new buffer or window for a local option).
9673 *
9674 * Return FAIL on error, OK otherwise.
9675 */
9676 int
9677makeset(fd, opt_flags, local_only)
9678 FILE *fd;
9679 int opt_flags;
9680 int local_only;
9681{
9682 struct vimoption *p;
9683 char_u *varp; /* currently used value */
9684 char_u *varp_fresh; /* local value */
9685 char_u *varp_local = NULL; /* fresh value */
9686 char *cmd;
9687 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009688 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009689
9690 /*
9691 * The options that don't have a default (terminal name, columns, lines)
9692 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009693 * Do the loop over "options[]" twice: once for options with the
9694 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009695 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009696 for (pri = 1; pri >= 0; --pri)
9697 {
9698 for (p = &options[0]; !istermoption(p); p++)
9699 if (!(p->flags & P_NO_MKRC)
9700 && !istermoption(p)
9701 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009702 {
9703 /* skip global option when only doing locals */
9704 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9705 continue;
9706
9707 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9708 * file, they are always buffer-specific. */
9709 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9710 continue;
9711
9712 /* Global values are only written when not at the default value. */
9713 varp = get_varp_scope(p, opt_flags);
9714 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9715 continue;
9716
9717 round = 2;
9718 if (p->indir != PV_NONE)
9719 {
9720 if (p->var == VAR_WIN)
9721 {
9722 /* skip window-local option when only doing globals */
9723 if (!(opt_flags & OPT_LOCAL))
9724 continue;
9725 /* When fresh value of window-local option is not at the
9726 * default, need to write it too. */
9727 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9728 {
9729 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9730 if (!optval_default(p, varp_fresh))
9731 {
9732 round = 1;
9733 varp_local = varp;
9734 varp = varp_fresh;
9735 }
9736 }
9737 }
9738 }
9739
9740 /* Round 1: fresh value for window-local options.
9741 * Round 2: other values */
9742 for ( ; round <= 2; varp = varp_local, ++round)
9743 {
9744 if (round == 1 || (opt_flags & OPT_GLOBAL))
9745 cmd = "set";
9746 else
9747 cmd = "setlocal";
9748
9749 if (p->flags & P_BOOL)
9750 {
9751 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9752 return FAIL;
9753 }
9754 else if (p->flags & P_NUM)
9755 {
9756 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9757 return FAIL;
9758 }
9759 else /* P_STRING */
9760 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009761#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9762 int do_endif = FALSE;
9763
Bram Moolenaar071d4272004-06-13 20:20:40 +00009764 /* Don't set 'syntax' and 'filetype' again if the value is
9765 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009766 if (
9767# if defined(FEAT_SYN_HL)
9768 p->indir == PV_SYN
9769# if defined(FEAT_AUTOCMD)
9770 ||
9771# endif
9772# endif
9773# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009774 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009775# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009776 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009777 {
9778 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9779 *(char_u **)(varp)) < 0
9780 || put_eol(fd) < 0)
9781 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009782 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009785 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9786 (p->flags & P_EXPAND) != 0) == FAIL)
9787 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009788#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9789 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790 {
9791 if (put_line(fd, "endif") == FAIL)
9792 return FAIL;
9793 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009794#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795 }
9796 }
9797 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009798 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009799 return OK;
9800}
9801
9802#if defined(FEAT_FOLDING) || defined(PROTO)
9803/*
9804 * Generate set commands for the local fold options only. Used when
9805 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9806 */
9807 int
9808makefoldset(fd)
9809 FILE *fd;
9810{
9811 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9812# ifdef FEAT_EVAL
9813 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9814 == FAIL
9815# endif
9816 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9817 == FAIL
9818 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9819 == FAIL
9820 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9821 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9822 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9823 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9824 )
9825 return FAIL;
9826
9827 return OK;
9828}
9829#endif
9830
9831 static int
9832put_setstring(fd, cmd, name, valuep, expand)
9833 FILE *fd;
9834 char *cmd;
9835 char *name;
9836 char_u **valuep;
9837 int expand;
9838{
9839 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009840 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009841
9842 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9843 return FAIL;
9844 if (*valuep != NULL)
9845 {
9846 /* Output 'pastetoggle' as key names. For other
9847 * options some characters have to be escaped with
9848 * CTRL-V or backslash */
9849 if (valuep == &p_pt)
9850 {
9851 s = *valuep;
9852 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009853 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009854 return FAIL;
9855 }
9856 else if (expand)
9857 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009858 buf = alloc(MAXPATHL);
9859 if (buf == NULL)
9860 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009861 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9862 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009863 {
9864 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009866 }
9867 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009868 }
9869 else if (put_escstr(fd, *valuep, 2) == FAIL)
9870 return FAIL;
9871 }
9872 if (put_eol(fd) < 0)
9873 return FAIL;
9874 return OK;
9875}
9876
9877 static int
9878put_setnum(fd, cmd, name, valuep)
9879 FILE *fd;
9880 char *cmd;
9881 char *name;
9882 long *valuep;
9883{
9884 long wc;
9885
9886 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9887 return FAIL;
9888 if (wc_use_keyname((char_u *)valuep, &wc))
9889 {
9890 /* print 'wildchar' and 'wildcharm' as a key name */
9891 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9892 return FAIL;
9893 }
9894 else if (fprintf(fd, "%ld", *valuep) < 0)
9895 return FAIL;
9896 if (put_eol(fd) < 0)
9897 return FAIL;
9898 return OK;
9899}
9900
9901 static int
9902put_setbool(fd, cmd, name, value)
9903 FILE *fd;
9904 char *cmd;
9905 char *name;
9906 int value;
9907{
Bram Moolenaar893de922007-10-02 18:40:57 +00009908 if (value < 0) /* global/local option using global value */
9909 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009910 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9911 || put_eol(fd) < 0)
9912 return FAIL;
9913 return OK;
9914}
9915
9916/*
9917 * Clear all the terminal options.
9918 * If the option has been allocated, free the memory.
9919 * Terminal options are never hidden or indirect.
9920 */
9921 void
9922clear_termoptions()
9923{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009924 /*
9925 * Reset a few things before clearing the old options. This may cause
9926 * outputting a few things that the terminal doesn't understand, but the
9927 * screen will be cleared later, so this is OK.
9928 */
9929#ifdef FEAT_MOUSE_TTY
9930 mch_setmouse(FALSE); /* switch mouse off */
9931#endif
9932#ifdef FEAT_TITLE
9933 mch_restore_title(3); /* restore window titles */
9934#endif
9935#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9936 /* When starting the GUI close the display opened for the clipboard.
9937 * After restoring the title, because that will need the display. */
9938 if (gui.starting)
9939 clear_xterm_clip();
9940#endif
9941#ifdef WIN3264
9942 /*
9943 * Check if this is allowed now.
9944 */
9945 if (can_end_termcap_mode(FALSE) == TRUE)
9946#endif
9947 stoptermcap(); /* stop termcap mode */
9948
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009949 free_termoptions();
9950}
9951
9952 void
9953free_termoptions()
9954{
9955 struct vimoption *p;
9956
Bram Moolenaar071d4272004-06-13 20:20:40 +00009957 for (p = &options[0]; p->fullname != NULL; p++)
9958 if (istermoption(p))
9959 {
9960 if (p->flags & P_ALLOCED)
9961 free_string_option(*(char_u **)(p->var));
9962 if (p->flags & P_DEF_ALLOCED)
9963 free_string_option(p->def_val[VI_DEFAULT]);
9964 *(char_u **)(p->var) = empty_option;
9965 p->def_val[VI_DEFAULT] = empty_option;
9966 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9967 }
9968 clear_termcodes();
9969}
9970
9971/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009972 * Free the string for one term option, if it was allocated.
9973 * Set the string to empty_option and clear allocated flag.
9974 * "var" points to the option value.
9975 */
9976 void
9977free_one_termoption(var)
9978 char_u *var;
9979{
9980 struct vimoption *p;
9981
9982 for (p = &options[0]; p->fullname != NULL; p++)
9983 if (p->var == var)
9984 {
9985 if (p->flags & P_ALLOCED)
9986 free_string_option(*(char_u **)(p->var));
9987 *(char_u **)(p->var) = empty_option;
9988 p->flags &= ~P_ALLOCED;
9989 break;
9990 }
9991}
9992
9993/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009994 * Set the terminal option defaults to the current value.
9995 * Used after setting the terminal name.
9996 */
9997 void
9998set_term_defaults()
9999{
10000 struct vimoption *p;
10001
10002 for (p = &options[0]; p->fullname != NULL; p++)
10003 {
10004 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10005 {
10006 if (p->flags & P_DEF_ALLOCED)
10007 {
10008 free_string_option(p->def_val[VI_DEFAULT]);
10009 p->flags &= ~P_DEF_ALLOCED;
10010 }
10011 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10012 if (p->flags & P_ALLOCED)
10013 {
10014 p->flags |= P_DEF_ALLOCED;
10015 p->flags &= ~P_ALLOCED; /* don't free the value now */
10016 }
10017 }
10018 }
10019}
10020
10021/*
10022 * return TRUE if 'p' starts with 't_'
10023 */
10024 static int
10025istermoption(p)
10026 struct vimoption *p;
10027{
10028 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10029}
10030
10031/*
10032 * Compute columns for ruler and shown command. 'sc_col' is also used to
10033 * decide what the maximum length of a message on the status line can be.
10034 * If there is a status line for the last window, 'sc_col' is independent
10035 * of 'ru_col'.
10036 */
10037
10038#define COL_RULER 17 /* columns needed by standard ruler */
10039
10040 void
10041comp_col()
10042{
10043#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10044 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10045
10046 sc_col = 0;
10047 ru_col = 0;
10048 if (p_ru)
10049 {
10050#ifdef FEAT_STL_OPT
10051 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10052#else
10053 ru_col = COL_RULER + 1;
10054#endif
10055 /* no last status line, adjust sc_col */
10056 if (!last_has_status)
10057 sc_col = ru_col;
10058 }
10059 if (p_sc)
10060 {
10061 sc_col += SHOWCMD_COLS;
10062 if (!p_ru || last_has_status) /* no need for separating space */
10063 ++sc_col;
10064 }
10065 sc_col = Columns - sc_col;
10066 ru_col = Columns - ru_col;
10067 if (sc_col <= 0) /* screen too narrow, will become a mess */
10068 sc_col = 1;
10069 if (ru_col <= 0)
10070 ru_col = 1;
10071#else
10072 sc_col = Columns;
10073 ru_col = Columns;
10074#endif
10075}
10076
10077/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010078 * Unset local option value, similar to ":set opt<".
10079 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010080 void
10081unset_global_local_option(name, from)
10082 char_u *name;
10083 void *from;
10084{
10085 struct vimoption *p;
10086 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010087 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010088
10089 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010090 if (opt_idx < 0)
10091 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010092 p = &(options[opt_idx]);
10093
10094 switch ((int)p->indir)
10095 {
10096 /* global option with local value: use local value if it's been set */
10097 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010098 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010099 break;
10100 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010101 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010102 break;
10103 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010104 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010105 break;
10106 case PV_AR:
10107 buf->b_p_ar = -1;
10108 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010109 case PV_BKC:
10110 clear_string_option(&buf->b_p_bkc);
10111 buf->b_bkc_flags = 0;
10112 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010113 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010114 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010115 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010116 case PV_TC:
10117 clear_string_option(&buf->b_p_tc);
10118 buf->b_tc_flags = 0;
10119 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010120#ifdef FEAT_FIND_ID
10121 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010122 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010123 break;
10124 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010125 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010126 break;
10127#endif
10128#ifdef FEAT_INS_EXPAND
10129 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010130 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010131 break;
10132 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010133 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010134 break;
10135#endif
10136#ifdef FEAT_QUICKFIX
10137 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010138 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010139 break;
10140 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010141 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010142 break;
10143 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010144 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010145 break;
10146#endif
10147#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10148 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010149 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010150 break;
10151#endif
10152#if defined(FEAT_CRYPT)
10153 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010154 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010155 break;
10156#endif
10157#ifdef FEAT_STL_OPT
10158 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010159 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010160 break;
10161#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010162 case PV_UL:
10163 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10164 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010165#ifdef FEAT_LISP
10166 case PV_LW:
10167 clear_string_option(&buf->b_p_lw);
10168 break;
10169#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010170 }
10171}
10172
10173/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174 * Get pointer to option variable, depending on local or global scope.
10175 */
10176 static char_u *
10177get_varp_scope(p, opt_flags)
10178 struct vimoption *p;
10179 int opt_flags;
10180{
10181 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10182 {
10183 if (p->var == VAR_WIN)
10184 return (char_u *)GLOBAL_WO(get_varp(p));
10185 return p->var;
10186 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010187 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 {
10189 switch ((int)p->indir)
10190 {
10191#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010192 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10193 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10194 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010196 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10197 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10198 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010199 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010200 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010201 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010203 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10204 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010205#endif
10206#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010207 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10208 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010209#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010210#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10211 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10212#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010213#if defined(FEAT_CRYPT)
10214 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10215#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010216#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010217 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010218#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010219 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010220#ifdef FEAT_LISP
10221 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10222#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010223 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010224 }
10225 return NULL; /* "cannot happen" */
10226 }
10227 return get_varp(p);
10228}
10229
10230/*
10231 * Get pointer to option variable.
10232 */
10233 static char_u *
10234get_varp(p)
10235 struct vimoption *p;
10236{
10237 /* hidden option, always return NULL */
10238 if (p->var == NULL)
10239 return NULL;
10240
10241 switch ((int)p->indir)
10242 {
10243 case PV_NONE: return p->var;
10244
10245 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010246 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010248 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010249 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010250 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010251 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010252 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010254 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010256 case PV_TC: return *curbuf->b_p_tc != NUL
10257 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010258 case PV_BKC: return *curbuf->b_p_bkc != NUL
10259 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010261 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010263 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10265#endif
10266#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010267 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010268 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010269 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10271#endif
10272#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010273 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010275 case PV_GP: return *curbuf->b_p_gp != NUL
10276 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10277 case PV_MP: return *curbuf->b_p_mp != NUL
10278 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010280#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10281 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10282 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10283#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010284#if defined(FEAT_CRYPT)
10285 case PV_CM: return *curbuf->b_p_cm != NUL
10286 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10287#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010288#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010289 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010290 ? (char_u *)&(curwin->w_p_stl) : p->var;
10291#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010292 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10293 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010294#ifdef FEAT_LISP
10295 case PV_LW: return *curbuf->b_p_lw != NUL
10296 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10297#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010298
10299#ifdef FEAT_ARABIC
10300 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10301#endif
10302 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010303#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010304 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10305#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010306#ifdef FEAT_SYN_HL
10307 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10308 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010309 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010310#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311#ifdef FEAT_DIFF
10312 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10313#endif
10314#ifdef FEAT_FOLDING
10315 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10316 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10317 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10318 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10319 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10320 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10321 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10322# ifdef FEAT_EVAL
10323 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10324 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10325# endif
10326 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10327#endif
10328 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010329 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010330#ifdef FEAT_LINEBREAK
10331 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10332#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010333#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010334 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10335#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010336#ifdef FEAT_VERTSPLIT
10337 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10338#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010339#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10340 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10341#endif
10342#ifdef FEAT_RIGHTLEFT
10343 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10344 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10345#endif
10346 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10347 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10348#ifdef FEAT_LINEBREAK
10349 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010350 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10351 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352#endif
10353#ifdef FEAT_SCROLLBIND
10354 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10355#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010356#ifdef FEAT_CURSORBIND
10357 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10358#endif
10359#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010360 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10361 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010362#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363
10364 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10365 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10366#ifdef FEAT_MBYTE
10367 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10368#endif
10369#if defined(FEAT_QUICKFIX)
10370 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10371 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10372#endif
10373 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10374 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10375#ifdef FEAT_CINDENT
10376 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10377 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10378 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10379#endif
10380#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10381 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10382#endif
10383#ifdef FEAT_COMMENTS
10384 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10385#endif
10386#ifdef FEAT_FOLDING
10387 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10388#endif
10389#ifdef FEAT_INS_EXPAND
10390 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10391#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010392#ifdef FEAT_COMPL_FUNC
10393 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010394 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010396 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010397 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10399#ifdef FEAT_MBYTE
10400 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10401#endif
10402 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10403#ifdef FEAT_AUTOCMD
10404 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10405#endif
10406 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010407 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10409 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10410 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10411 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10412#ifdef FEAT_FIND_ID
10413# ifdef FEAT_EVAL
10414 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10415# endif
10416#endif
10417#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10418 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10419 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10420#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010421#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010422 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10423#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010424#ifdef FEAT_CRYPT
10425 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10426#endif
10427#ifdef FEAT_LISP
10428 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10429#endif
10430 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10431 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10432 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10433 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10434 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010435 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010436#ifdef FEAT_TEXTOBJ
10437 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10440#ifdef FEAT_SMARTINDENT
10441 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10442#endif
10443#ifndef SHORT_FNAME
10444 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10445#endif
10446 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10447#ifdef FEAT_SEARCHPATH
10448 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10449#endif
10450 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10451#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010452 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010453 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10454#endif
10455#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010456 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10457 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10458 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459#endif
10460 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10461 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10462 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10463 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010464#ifdef FEAT_PERSISTENT_UNDO
10465 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10466#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010467 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10468#ifdef FEAT_KEYMAP
10469 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10470#endif
10471 default: EMSG(_("E356: get_varp ERROR"));
10472 }
10473 /* always return a valid pointer to avoid a crash! */
10474 return (char_u *)&(curbuf->b_p_wm);
10475}
10476
10477/*
10478 * Get the value of 'equalprg', either the buffer-local one or the global one.
10479 */
10480 char_u *
10481get_equalprg()
10482{
10483 if (*curbuf->b_p_ep == NUL)
10484 return p_ep;
10485 return curbuf->b_p_ep;
10486}
10487
10488#if defined(FEAT_WINDOWS) || defined(PROTO)
10489/*
10490 * Copy options from one window to another.
10491 * Used when splitting a window.
10492 */
10493 void
10494win_copy_options(wp_from, wp_to)
10495 win_T *wp_from;
10496 win_T *wp_to;
10497{
10498 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10499 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10500# ifdef FEAT_RIGHTLEFT
10501# ifdef FEAT_FKMAP
10502 /* Is this right? */
10503 wp_to->w_farsi = wp_from->w_farsi;
10504# endif
10505# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010506#if defined(FEAT_LINEBREAK)
10507 briopt_check(wp_to);
10508#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010509}
10510#endif
10511
10512/*
10513 * Copy the options from one winopt_T to another.
10514 * Doesn't free the old option values in "to", use clear_winopt() for that.
10515 * The 'scroll' option is not copied, because it depends on the window height.
10516 * The 'previewwindow' option is reset, there can be only one preview window.
10517 */
10518 void
10519copy_winopt(from, to)
10520 winopt_T *from;
10521 winopt_T *to;
10522{
10523#ifdef FEAT_ARABIC
10524 to->wo_arab = from->wo_arab;
10525#endif
10526 to->wo_list = from->wo_list;
10527 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010528 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010529#ifdef FEAT_LINEBREAK
10530 to->wo_nuw = from->wo_nuw;
10531#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010532#ifdef FEAT_RIGHTLEFT
10533 to->wo_rl = from->wo_rl;
10534 to->wo_rlc = vim_strsave(from->wo_rlc);
10535#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010536#ifdef FEAT_STL_OPT
10537 to->wo_stl = vim_strsave(from->wo_stl);
10538#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010540#ifdef FEAT_DIFF
10541 to->wo_wrap_save = from->wo_wrap_save;
10542#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543#ifdef FEAT_LINEBREAK
10544 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010545 to->wo_bri = from->wo_bri;
10546 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547#endif
10548#ifdef FEAT_SCROLLBIND
10549 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010550 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010551#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010552#ifdef FEAT_CURSORBIND
10553 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010554 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010555#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010556#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010557 to->wo_spell = from->wo_spell;
10558#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010559#ifdef FEAT_SYN_HL
10560 to->wo_cuc = from->wo_cuc;
10561 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010562 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010563#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564#ifdef FEAT_DIFF
10565 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010566 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010568#ifdef FEAT_CONCEAL
10569 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010570 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010571#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572#ifdef FEAT_FOLDING
10573 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010574 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010576 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577 to->wo_fdi = vim_strsave(from->wo_fdi);
10578 to->wo_fml = from->wo_fml;
10579 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010580 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010582 to->wo_fdm_save = from->wo_diff_saved
10583 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584 to->wo_fdn = from->wo_fdn;
10585# ifdef FEAT_EVAL
10586 to->wo_fde = vim_strsave(from->wo_fde);
10587 to->wo_fdt = vim_strsave(from->wo_fdt);
10588# endif
10589 to->wo_fmr = vim_strsave(from->wo_fmr);
10590#endif
10591 check_winopt(to); /* don't want NULL pointers */
10592}
10593
10594/*
10595 * Check string options in a window for a NULL value.
10596 */
10597 void
10598check_win_options(win)
10599 win_T *win;
10600{
10601 check_winopt(&win->w_onebuf_opt);
10602 check_winopt(&win->w_allbuf_opt);
10603}
10604
10605/*
10606 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10607 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010608 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010609check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010610 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611{
10612#ifdef FEAT_FOLDING
10613 check_string_option(&wop->wo_fdi);
10614 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010615 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616# ifdef FEAT_EVAL
10617 check_string_option(&wop->wo_fde);
10618 check_string_option(&wop->wo_fdt);
10619# endif
10620 check_string_option(&wop->wo_fmr);
10621#endif
10622#ifdef FEAT_RIGHTLEFT
10623 check_string_option(&wop->wo_rlc);
10624#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010625#ifdef FEAT_STL_OPT
10626 check_string_option(&wop->wo_stl);
10627#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010628#ifdef FEAT_SYN_HL
10629 check_string_option(&wop->wo_cc);
10630#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010631#ifdef FEAT_CONCEAL
10632 check_string_option(&wop->wo_cocu);
10633#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010634#ifdef FEAT_LINEBREAK
10635 check_string_option(&wop->wo_briopt);
10636#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010637}
10638
10639/*
10640 * Free the allocated memory inside a winopt_T.
10641 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642 void
10643clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010644 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010645{
10646#ifdef FEAT_FOLDING
10647 clear_string_option(&wop->wo_fdi);
10648 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010649 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010650# ifdef FEAT_EVAL
10651 clear_string_option(&wop->wo_fde);
10652 clear_string_option(&wop->wo_fdt);
10653# endif
10654 clear_string_option(&wop->wo_fmr);
10655#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010656#ifdef FEAT_LINEBREAK
10657 clear_string_option(&wop->wo_briopt);
10658#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010659#ifdef FEAT_RIGHTLEFT
10660 clear_string_option(&wop->wo_rlc);
10661#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010662#ifdef FEAT_STL_OPT
10663 clear_string_option(&wop->wo_stl);
10664#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010665#ifdef FEAT_SYN_HL
10666 clear_string_option(&wop->wo_cc);
10667#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010668#ifdef FEAT_CONCEAL
10669 clear_string_option(&wop->wo_cocu);
10670#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010671}
10672
10673/*
10674 * Copy global option values to local options for one buffer.
10675 * Used when creating a new buffer and sometimes when entering a buffer.
10676 * flags:
10677 * BCO_ENTER We will enter the buf buffer.
10678 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10679 * appropriate.
10680 * BCO_NOHELP Don't copy the values to a help buffer.
10681 */
10682 void
10683buf_copy_options(buf, flags)
10684 buf_T *buf;
10685 int flags;
10686{
10687 int should_copy = TRUE;
10688 char_u *save_p_isk = NULL; /* init for GCC */
10689 int dont_do_help;
10690 int did_isk = FALSE;
10691
10692 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010693 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010694 */
10695 if (buf == NULL || !buf_valid(buf))
10696 return;
10697
10698 /*
10699 * Skip this when the option defaults have not been set yet. Happens when
10700 * main() allocates the first buffer.
10701 */
10702 if (p_cpo != NULL)
10703 {
10704 /*
10705 * Always copy when entering and 'cpo' contains 'S'.
10706 * Don't copy when already initialized.
10707 * Don't copy when 'cpo' contains 's' and not entering.
10708 * 'S' BCO_ENTER initialized 's' should_copy
10709 * yes yes X X TRUE
10710 * yes no yes X FALSE
10711 * no X yes X FALSE
10712 * X no no yes FALSE
10713 * X no no no TRUE
10714 * no yes no X TRUE
10715 */
10716 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10717 && (buf->b_p_initialized
10718 || (!(flags & BCO_ENTER)
10719 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10720 should_copy = FALSE;
10721
10722 if (should_copy || (flags & BCO_ALWAYS))
10723 {
10724 /* Don't copy the options specific to a help buffer when
10725 * BCO_NOHELP is given or the options were initialized already
10726 * (jumping back to a help file with CTRL-T or CTRL-O) */
10727 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10728 || buf->b_p_initialized;
10729 if (dont_do_help) /* don't free b_p_isk */
10730 {
10731 save_p_isk = buf->b_p_isk;
10732 buf->b_p_isk = NULL;
10733 }
10734 /*
10735 * Always free the allocated strings.
10736 * If not already initialized, set 'readonly' and copy 'fileformat'.
10737 */
10738 if (!buf->b_p_initialized)
10739 {
10740 free_buf_options(buf, TRUE);
10741 buf->b_p_ro = FALSE; /* don't copy readonly */
10742 buf->b_p_tx = p_tx;
10743#ifdef FEAT_MBYTE
10744 buf->b_p_fenc = vim_strsave(p_fenc);
10745#endif
10746 buf->b_p_ff = vim_strsave(p_ff);
10747#if defined(FEAT_QUICKFIX)
10748 buf->b_p_bh = empty_option;
10749 buf->b_p_bt = empty_option;
10750#endif
10751 }
10752 else
10753 free_buf_options(buf, FALSE);
10754
10755 buf->b_p_ai = p_ai;
10756 buf->b_p_ai_nopaste = p_ai_nopaste;
10757 buf->b_p_sw = p_sw;
10758 buf->b_p_tw = p_tw;
10759 buf->b_p_tw_nopaste = p_tw_nopaste;
10760 buf->b_p_tw_nobin = p_tw_nobin;
10761 buf->b_p_wm = p_wm;
10762 buf->b_p_wm_nopaste = p_wm_nopaste;
10763 buf->b_p_wm_nobin = p_wm_nobin;
10764 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010765#ifdef FEAT_MBYTE
10766 buf->b_p_bomb = p_bomb;
10767#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010768 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010769 buf->b_p_et = p_et;
10770 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010771 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772 buf->b_p_ml = p_ml;
10773 buf->b_p_ml_nobin = p_ml_nobin;
10774 buf->b_p_inf = p_inf;
10775 buf->b_p_swf = p_swf;
10776#ifdef FEAT_INS_EXPAND
10777 buf->b_p_cpt = vim_strsave(p_cpt);
10778#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010779#ifdef FEAT_COMPL_FUNC
10780 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010781 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010782#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010783 buf->b_p_sts = p_sts;
10784 buf->b_p_sts_nopaste = p_sts_nopaste;
10785#ifndef SHORT_FNAME
10786 buf->b_p_sn = p_sn;
10787#endif
10788#ifdef FEAT_COMMENTS
10789 buf->b_p_com = vim_strsave(p_com);
10790#endif
10791#ifdef FEAT_FOLDING
10792 buf->b_p_cms = vim_strsave(p_cms);
10793#endif
10794 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010795 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796 buf->b_p_nf = vim_strsave(p_nf);
10797 buf->b_p_mps = vim_strsave(p_mps);
10798#ifdef FEAT_SMARTINDENT
10799 buf->b_p_si = p_si;
10800#endif
10801 buf->b_p_ci = p_ci;
10802#ifdef FEAT_CINDENT
10803 buf->b_p_cin = p_cin;
10804 buf->b_p_cink = vim_strsave(p_cink);
10805 buf->b_p_cino = vim_strsave(p_cino);
10806#endif
10807#ifdef FEAT_AUTOCMD
10808 /* Don't copy 'filetype', it must be detected */
10809 buf->b_p_ft = empty_option;
10810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811 buf->b_p_pi = p_pi;
10812#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10813 buf->b_p_cinw = vim_strsave(p_cinw);
10814#endif
10815#ifdef FEAT_LISP
10816 buf->b_p_lisp = p_lisp;
10817#endif
10818#ifdef FEAT_SYN_HL
10819 /* Don't copy 'syntax', it must be set */
10820 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010821 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010822#endif
10823#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010824 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010825 (void)compile_cap_prog(&buf->b_s);
10826 buf->b_s.b_p_spf = vim_strsave(p_spf);
10827 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828#endif
10829#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10830 buf->b_p_inde = vim_strsave(p_inde);
10831 buf->b_p_indk = vim_strsave(p_indk);
10832#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010833#if defined(FEAT_EVAL)
10834 buf->b_p_fex = vim_strsave(p_fex);
10835#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010836#ifdef FEAT_CRYPT
10837 buf->b_p_key = vim_strsave(p_key);
10838#endif
10839#ifdef FEAT_SEARCHPATH
10840 buf->b_p_sua = vim_strsave(p_sua);
10841#endif
10842#ifdef FEAT_KEYMAP
10843 buf->b_p_keymap = vim_strsave(p_keymap);
10844 buf->b_kmap_state |= KEYMAP_INIT;
10845#endif
10846 /* This isn't really an option, but copying the langmap and IME
10847 * state from the current buffer is better than resetting it. */
10848 buf->b_p_iminsert = p_iminsert;
10849 buf->b_p_imsearch = p_imsearch;
10850
10851 /* options that are normally global but also have a local value
10852 * are not copied, start using the global value */
10853 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010854 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010855 buf->b_p_bkc = empty_option;
10856 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010857#ifdef FEAT_QUICKFIX
10858 buf->b_p_gp = empty_option;
10859 buf->b_p_mp = empty_option;
10860 buf->b_p_efm = empty_option;
10861#endif
10862 buf->b_p_ep = empty_option;
10863 buf->b_p_kp = empty_option;
10864 buf->b_p_path = empty_option;
10865 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010866 buf->b_p_tc = empty_option;
10867 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010868#ifdef FEAT_FIND_ID
10869 buf->b_p_def = empty_option;
10870 buf->b_p_inc = empty_option;
10871# ifdef FEAT_EVAL
10872 buf->b_p_inex = vim_strsave(p_inex);
10873# endif
10874#endif
10875#ifdef FEAT_INS_EXPAND
10876 buf->b_p_dict = empty_option;
10877 buf->b_p_tsr = empty_option;
10878#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010879#ifdef FEAT_TEXTOBJ
10880 buf->b_p_qe = vim_strsave(p_qe);
10881#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010882#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10883 buf->b_p_bexpr = empty_option;
10884#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010885#if defined(FEAT_CRYPT)
10886 buf->b_p_cm = empty_option;
10887#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010888#ifdef FEAT_PERSISTENT_UNDO
10889 buf->b_p_udf = p_udf;
10890#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010891#ifdef FEAT_LISP
10892 buf->b_p_lw = empty_option;
10893#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010894
10895 /*
10896 * Don't copy the options set by ex_help(), use the saved values,
10897 * when going from a help buffer to a non-help buffer.
10898 * Don't touch these at all when BCO_NOHELP is used and going from
10899 * or to a help buffer.
10900 */
10901 if (dont_do_help)
10902 buf->b_p_isk = save_p_isk;
10903 else
10904 {
10905 buf->b_p_isk = vim_strsave(p_isk);
10906 did_isk = TRUE;
10907 buf->b_p_ts = p_ts;
10908 buf->b_help = FALSE;
10909#ifdef FEAT_QUICKFIX
10910 if (buf->b_p_bt[0] == 'h')
10911 clear_string_option(&buf->b_p_bt);
10912#endif
10913 buf->b_p_ma = p_ma;
10914 }
10915 }
10916
10917 /*
10918 * When the options should be copied (ignoring BCO_ALWAYS), set the
10919 * flag that indicates that the options have been initialized.
10920 */
10921 if (should_copy)
10922 buf->b_p_initialized = TRUE;
10923 }
10924
10925 check_buf_options(buf); /* make sure we don't have NULLs */
10926 if (did_isk)
10927 (void)buf_init_chartab(buf, FALSE);
10928}
10929
10930/*
10931 * Reset the 'modifiable' option and its default value.
10932 */
10933 void
10934reset_modifiable()
10935{
10936 int opt_idx;
10937
10938 curbuf->b_p_ma = FALSE;
10939 p_ma = FALSE;
10940 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010941 if (opt_idx >= 0)
10942 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943}
10944
10945/*
10946 * Set the global value for 'iminsert' to the local value.
10947 */
10948 void
10949set_iminsert_global()
10950{
10951 p_iminsert = curbuf->b_p_iminsert;
10952}
10953
10954/*
10955 * Set the global value for 'imsearch' to the local value.
10956 */
10957 void
10958set_imsearch_global()
10959{
10960 p_imsearch = curbuf->b_p_imsearch;
10961}
10962
10963#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10964static int expand_option_idx = -1;
10965static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10966static int expand_option_flags = 0;
10967
10968 void
10969set_context_in_set_cmd(xp, arg, opt_flags)
10970 expand_T *xp;
10971 char_u *arg;
10972 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10973{
10974 int nextchar;
10975 long_u flags = 0; /* init for GCC */
10976 int opt_idx = 0; /* init for GCC */
10977 char_u *p;
10978 char_u *s;
10979 int is_term_option = FALSE;
10980 int key;
10981
10982 expand_option_flags = opt_flags;
10983
10984 xp->xp_context = EXPAND_SETTINGS;
10985 if (*arg == NUL)
10986 {
10987 xp->xp_pattern = arg;
10988 return;
10989 }
10990 p = arg + STRLEN(arg) - 1;
10991 if (*p == ' ' && *(p - 1) != '\\')
10992 {
10993 xp->xp_pattern = p + 1;
10994 return;
10995 }
10996 while (p > arg)
10997 {
10998 s = p;
10999 /* count number of backslashes before ' ' or ',' */
11000 if (*p == ' ' || *p == ',')
11001 {
11002 while (s > arg && *(s - 1) == '\\')
11003 --s;
11004 }
11005 /* break at a space with an even number of backslashes */
11006 if (*p == ' ' && ((p - s) & 1) == 0)
11007 {
11008 ++p;
11009 break;
11010 }
11011 --p;
11012 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011013 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011014 {
11015 xp->xp_context = EXPAND_BOOL_SETTINGS;
11016 p += 2;
11017 }
11018 if (STRNCMP(p, "inv", 3) == 0)
11019 {
11020 xp->xp_context = EXPAND_BOOL_SETTINGS;
11021 p += 3;
11022 }
11023 xp->xp_pattern = arg = p;
11024 if (*arg == '<')
11025 {
11026 while (*p != '>')
11027 if (*p++ == NUL) /* expand terminal option name */
11028 return;
11029 key = get_special_key_code(arg + 1);
11030 if (key == 0) /* unknown name */
11031 {
11032 xp->xp_context = EXPAND_NOTHING;
11033 return;
11034 }
11035 nextchar = *++p;
11036 is_term_option = TRUE;
11037 expand_option_name[2] = KEY2TERMCAP0(key);
11038 expand_option_name[3] = KEY2TERMCAP1(key);
11039 }
11040 else
11041 {
11042 if (p[0] == 't' && p[1] == '_')
11043 {
11044 p += 2;
11045 if (*p != NUL)
11046 ++p;
11047 if (*p == NUL)
11048 return; /* expand option name */
11049 nextchar = *++p;
11050 is_term_option = TRUE;
11051 expand_option_name[2] = p[-2];
11052 expand_option_name[3] = p[-1];
11053 }
11054 else
11055 {
11056 /* Allow * wildcard */
11057 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11058 p++;
11059 if (*p == NUL)
11060 return;
11061 nextchar = *p;
11062 *p = NUL;
11063 opt_idx = findoption(arg);
11064 *p = nextchar;
11065 if (opt_idx == -1 || options[opt_idx].var == NULL)
11066 {
11067 xp->xp_context = EXPAND_NOTHING;
11068 return;
11069 }
11070 flags = options[opt_idx].flags;
11071 if (flags & P_BOOL)
11072 {
11073 xp->xp_context = EXPAND_NOTHING;
11074 return;
11075 }
11076 }
11077 }
11078 /* handle "-=" and "+=" */
11079 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11080 {
11081 ++p;
11082 nextchar = '=';
11083 }
11084 if ((nextchar != '=' && nextchar != ':')
11085 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11086 {
11087 xp->xp_context = EXPAND_UNSUCCESSFUL;
11088 return;
11089 }
11090 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11091 {
11092 xp->xp_context = EXPAND_OLD_SETTING;
11093 if (is_term_option)
11094 expand_option_idx = -1;
11095 else
11096 expand_option_idx = opt_idx;
11097 xp->xp_pattern = p + 1;
11098 return;
11099 }
11100 xp->xp_context = EXPAND_NOTHING;
11101 if (is_term_option || (flags & P_NUM))
11102 return;
11103
11104 xp->xp_pattern = p + 1;
11105
11106 if (flags & P_EXPAND)
11107 {
11108 p = options[opt_idx].var;
11109 if (p == (char_u *)&p_bdir
11110 || p == (char_u *)&p_dir
11111 || p == (char_u *)&p_path
11112 || p == (char_u *)&p_rtp
11113#ifdef FEAT_SEARCHPATH
11114 || p == (char_u *)&p_cdpath
11115#endif
11116#ifdef FEAT_SESSION
11117 || p == (char_u *)&p_vdir
11118#endif
11119 )
11120 {
11121 xp->xp_context = EXPAND_DIRECTORIES;
11122 if (p == (char_u *)&p_path
11123#ifdef FEAT_SEARCHPATH
11124 || p == (char_u *)&p_cdpath
11125#endif
11126 )
11127 xp->xp_backslash = XP_BS_THREE;
11128 else
11129 xp->xp_backslash = XP_BS_ONE;
11130 }
11131 else
11132 {
11133 xp->xp_context = EXPAND_FILES;
11134 /* for 'tags' need three backslashes for a space */
11135 if (p == (char_u *)&p_tags)
11136 xp->xp_backslash = XP_BS_THREE;
11137 else
11138 xp->xp_backslash = XP_BS_ONE;
11139 }
11140 }
11141
11142 /* For an option that is a list of file names, find the start of the
11143 * last file name. */
11144 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11145 {
11146 /* count number of backslashes before ' ' or ',' */
11147 if (*p == ' ' || *p == ',')
11148 {
11149 s = p;
11150 while (s > xp->xp_pattern && *(s - 1) == '\\')
11151 --s;
11152 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11153 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11154 {
11155 xp->xp_pattern = p + 1;
11156 break;
11157 }
11158 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011159
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011160#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011161 /* for 'spellsuggest' start at "file:" */
11162 if (options[opt_idx].var == (char_u *)&p_sps
11163 && STRNCMP(p, "file:", 5) == 0)
11164 {
11165 xp->xp_pattern = p + 5;
11166 break;
11167 }
11168#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011169 }
11170
11171 return;
11172}
11173
11174 int
11175ExpandSettings(xp, regmatch, num_file, file)
11176 expand_T *xp;
11177 regmatch_T *regmatch;
11178 int *num_file;
11179 char_u ***file;
11180{
11181 int num_normal = 0; /* Nr of matching non-term-code settings */
11182 int num_term = 0; /* Nr of matching terminal code settings */
11183 int opt_idx;
11184 int match;
11185 int count = 0;
11186 char_u *str;
11187 int loop;
11188 int is_term_opt;
11189 char_u name_buf[MAX_KEY_NAME_LEN];
11190 static char *(names[]) = {"all", "termcap"};
11191 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11192
11193 /* do this loop twice:
11194 * loop == 0: count the number of matching options
11195 * loop == 1: copy the matching options into allocated memory
11196 */
11197 for (loop = 0; loop <= 1; ++loop)
11198 {
11199 regmatch->rm_ic = ic;
11200 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11201 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011202 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11203 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011204 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11205 {
11206 if (loop == 0)
11207 num_normal++;
11208 else
11209 (*file)[count++] = vim_strsave((char_u *)names[match]);
11210 }
11211 }
11212 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11213 opt_idx++)
11214 {
11215 if (options[opt_idx].var == NULL)
11216 continue;
11217 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11218 && !(options[opt_idx].flags & P_BOOL))
11219 continue;
11220 is_term_opt = istermoption(&options[opt_idx]);
11221 if (is_term_opt && num_normal > 0)
11222 continue;
11223 match = FALSE;
11224 if (vim_regexec(regmatch, str, (colnr_T)0)
11225 || (options[opt_idx].shortname != NULL
11226 && vim_regexec(regmatch,
11227 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11228 match = TRUE;
11229 else if (is_term_opt)
11230 {
11231 name_buf[0] = '<';
11232 name_buf[1] = 't';
11233 name_buf[2] = '_';
11234 name_buf[3] = str[2];
11235 name_buf[4] = str[3];
11236 name_buf[5] = '>';
11237 name_buf[6] = NUL;
11238 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11239 {
11240 match = TRUE;
11241 str = name_buf;
11242 }
11243 }
11244 if (match)
11245 {
11246 if (loop == 0)
11247 {
11248 if (is_term_opt)
11249 num_term++;
11250 else
11251 num_normal++;
11252 }
11253 else
11254 (*file)[count++] = vim_strsave(str);
11255 }
11256 }
11257 /*
11258 * Check terminal key codes, these are not in the option table
11259 */
11260 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11261 {
11262 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11263 {
11264 if (!isprint(str[0]) || !isprint(str[1]))
11265 continue;
11266
11267 name_buf[0] = 't';
11268 name_buf[1] = '_';
11269 name_buf[2] = str[0];
11270 name_buf[3] = str[1];
11271 name_buf[4] = NUL;
11272
11273 match = FALSE;
11274 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11275 match = TRUE;
11276 else
11277 {
11278 name_buf[0] = '<';
11279 name_buf[1] = 't';
11280 name_buf[2] = '_';
11281 name_buf[3] = str[0];
11282 name_buf[4] = str[1];
11283 name_buf[5] = '>';
11284 name_buf[6] = NUL;
11285
11286 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11287 match = TRUE;
11288 }
11289 if (match)
11290 {
11291 if (loop == 0)
11292 num_term++;
11293 else
11294 (*file)[count++] = vim_strsave(name_buf);
11295 }
11296 }
11297
11298 /*
11299 * Check special key names.
11300 */
11301 regmatch->rm_ic = TRUE; /* ignore case here */
11302 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11303 {
11304 name_buf[0] = '<';
11305 STRCPY(name_buf + 1, str);
11306 STRCAT(name_buf, ">");
11307
11308 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11309 {
11310 if (loop == 0)
11311 num_term++;
11312 else
11313 (*file)[count++] = vim_strsave(name_buf);
11314 }
11315 }
11316 }
11317 if (loop == 0)
11318 {
11319 if (num_normal > 0)
11320 *num_file = num_normal;
11321 else if (num_term > 0)
11322 *num_file = num_term;
11323 else
11324 return OK;
11325 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11326 if (*file == NULL)
11327 {
11328 *file = (char_u **)"";
11329 return FAIL;
11330 }
11331 }
11332 }
11333 return OK;
11334}
11335
11336 int
11337ExpandOldSetting(num_file, file)
11338 int *num_file;
11339 char_u ***file;
11340{
11341 char_u *var = NULL; /* init for GCC */
11342 char_u *buf;
11343
11344 *num_file = 0;
11345 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11346 if (*file == NULL)
11347 return FAIL;
11348
11349 /*
11350 * For a terminal key code expand_option_idx is < 0.
11351 */
11352 if (expand_option_idx < 0)
11353 {
11354 var = find_termcode(expand_option_name + 2);
11355 if (var == NULL)
11356 expand_option_idx = findoption(expand_option_name);
11357 }
11358
11359 if (expand_option_idx >= 0)
11360 {
11361 /* put string of option value in NameBuff */
11362 option_value2string(&options[expand_option_idx], expand_option_flags);
11363 var = NameBuff;
11364 }
11365 else if (var == NULL)
11366 var = (char_u *)"";
11367
11368 /* A backslash is required before some characters. This is the reverse of
11369 * what happens in do_set(). */
11370 buf = vim_strsave_escaped(var, escape_chars);
11371
11372 if (buf == NULL)
11373 {
11374 vim_free(*file);
11375 *file = NULL;
11376 return FAIL;
11377 }
11378
11379#ifdef BACKSLASH_IN_FILENAME
11380 /* For MS-Windows et al. we don't double backslashes at the start and
11381 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011382 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011383 if (var[0] == '\\' && var[1] == '\\'
11384 && expand_option_idx >= 0
11385 && (options[expand_option_idx].flags & P_EXPAND)
11386 && vim_isfilec(var[2])
11387 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011388 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011389#endif
11390
11391 *file[0] = buf;
11392 *num_file = 1;
11393 return OK;
11394}
11395#endif
11396
11397/*
11398 * Get the value for the numeric or string option *opp in a nice format into
11399 * NameBuff[]. Must not be called with a hidden option!
11400 */
11401 static void
11402option_value2string(opp, opt_flags)
11403 struct vimoption *opp;
11404 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11405{
11406 char_u *varp;
11407
11408 varp = get_varp_scope(opp, opt_flags);
11409
11410 if (opp->flags & P_NUM)
11411 {
11412 long wc = 0;
11413
11414 if (wc_use_keyname(varp, &wc))
11415 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11416 else if (wc != 0)
11417 STRCPY(NameBuff, transchar((int)wc));
11418 else
11419 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11420 }
11421 else /* P_STRING */
11422 {
11423 varp = *(char_u **)(varp);
11424 if (varp == NULL) /* just in case */
11425 NameBuff[0] = NUL;
11426#ifdef FEAT_CRYPT
11427 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011428 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011429 STRCPY(NameBuff, "*****");
11430#endif
11431 else if (opp->flags & P_EXPAND)
11432 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11433 /* Translate 'pastetoggle' into special key names */
11434 else if ((char_u **)opp->var == &p_pt)
11435 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11436 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011437 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011438 }
11439}
11440
11441/*
11442 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11443 * printed as a keyname.
11444 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11445 */
11446 static int
11447wc_use_keyname(varp, wcp)
11448 char_u *varp;
11449 long *wcp;
11450{
11451 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11452 {
11453 *wcp = *(long *)varp;
11454 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11455 return TRUE;
11456 }
11457 return FALSE;
11458}
11459
Bram Moolenaar01615492015-02-03 13:00:38 +010011460#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011461/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011462 * Any character has an equivalent 'langmap' character. This is used for
11463 * keyboards that have a special language mode that sends characters above
11464 * 128 (although other characters can be translated too). The "to" field is a
11465 * Vim command character. This avoids having to switch the keyboard back to
11466 * ASCII mode when leaving Insert mode.
11467 *
11468 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11469 * commands.
11470 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11471 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11472 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011473 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011474# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011475/*
11476 * With multi-byte support use growarray for 'langmap' chars >= 256
11477 */
11478typedef struct
11479{
11480 int from;
11481 int to;
11482} langmap_entry_T;
11483
11484static garray_T langmap_mapga;
11485static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011486
11487/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011488 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11489 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011490 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011491 static void
11492langmap_set_entry(from, to)
11493 int from;
11494 int to;
11495{
11496 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011497 int a = 0;
11498 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011499
11500 /* Do a binary search for an existing entry. */
11501 while (a != b)
11502 {
11503 int i = (a + b) / 2;
11504 int d = entries[i].from - from;
11505
11506 if (d == 0)
11507 {
11508 entries[i].to = to;
11509 return;
11510 }
11511 if (d < 0)
11512 a = i + 1;
11513 else
11514 b = i;
11515 }
11516
11517 if (ga_grow(&langmap_mapga, 1) != OK)
11518 return; /* out of memory */
11519
11520 /* insert new entry at position "a" */
11521 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11522 mch_memmove(entries + 1, entries,
11523 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11524 ++langmap_mapga.ga_len;
11525 entries[0].from = from;
11526 entries[0].to = to;
11527}
11528
11529/*
11530 * Apply 'langmap' to multi-byte character "c" and return the result.
11531 */
11532 int
11533langmap_adjust_mb(c)
11534 int c;
11535{
11536 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11537 int a = 0;
11538 int b = langmap_mapga.ga_len;
11539
11540 while (a != b)
11541 {
11542 int i = (a + b) / 2;
11543 int d = entries[i].from - c;
11544
11545 if (d == 0)
11546 return entries[i].to; /* found matching entry */
11547 if (d < 0)
11548 a = i + 1;
11549 else
11550 b = i;
11551 }
11552 return c; /* no entry found, return "c" unmodified */
11553}
11554# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555
11556 static void
11557langmap_init()
11558{
11559 int i;
11560
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011561 for (i = 0; i < 256; i++)
11562 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11563# ifdef FEAT_MBYTE
11564 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11565# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011566}
11567
11568/*
11569 * Called when langmap option is set; the language map can be
11570 * changed at any time!
11571 */
11572 static void
11573langmap_set()
11574{
11575 char_u *p;
11576 char_u *p2;
11577 int from, to;
11578
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011579#ifdef FEAT_MBYTE
11580 ga_clear(&langmap_mapga); /* clear the previous map first */
11581#endif
11582 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011583
11584 for (p = p_langmap; p[0] != NUL; )
11585 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011586 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11587 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011588 {
11589 if (p2[0] == '\\' && p2[1] != NUL)
11590 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011591 }
11592 if (p2[0] == ';')
11593 ++p2; /* abcd;ABCD form, p2 points to A */
11594 else
11595 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11596 while (p[0])
11597 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011598 if (p[0] == ',')
11599 {
11600 ++p;
11601 break;
11602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011603 if (p[0] == '\\' && p[1] != NUL)
11604 ++p;
11605#ifdef FEAT_MBYTE
11606 from = (*mb_ptr2char)(p);
11607#else
11608 from = p[0];
11609#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011610 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011611 if (p2 == NULL)
11612 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011613 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011614 if (p[0] != ',')
11615 {
11616 if (p[0] == '\\')
11617 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011618#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011619 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011620#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011621 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011622#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011623 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011624 }
11625 else
11626 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011627 if (p2[0] != ',')
11628 {
11629 if (p2[0] == '\\')
11630 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011631#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011632 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011634 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011635#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011636 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011637 }
11638 if (to == NUL)
11639 {
11640 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11641 transchar(from));
11642 return;
11643 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011644
11645#ifdef FEAT_MBYTE
11646 if (from >= 256)
11647 langmap_set_entry(from, to);
11648 else
11649#endif
11650 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011651
11652 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011653 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011654 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011655 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011656 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011657 if (*p == ';')
11658 {
11659 p = p2;
11660 if (p[0] != NUL)
11661 {
11662 if (p[0] != ',')
11663 {
11664 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11665 return;
11666 }
11667 ++p;
11668 }
11669 break;
11670 }
11671 }
11672 }
11673 }
11674}
11675#endif
11676
11677/*
11678 * Return TRUE if format option 'x' is in effect.
11679 * Take care of no formatting when 'paste' is set.
11680 */
11681 int
11682has_format_option(x)
11683 int x;
11684{
11685 if (p_paste)
11686 return FALSE;
11687 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11688}
11689
11690/*
11691 * Return TRUE if "x" is present in 'shortmess' option, or
11692 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11693 */
11694 int
11695shortmess(x)
11696 int x;
11697{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011698 return p_shm != NULL &&
11699 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011700 || (vim_strchr(p_shm, 'a') != NULL
11701 && vim_strchr((char_u *)SHM_A, x) != NULL));
11702}
11703
11704/*
11705 * paste_option_changed() - Called after p_paste was set or reset.
11706 */
11707 static void
11708paste_option_changed()
11709{
11710 static int old_p_paste = FALSE;
11711 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011712 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011713#ifdef FEAT_CMDL_INFO
11714 static int save_ru = 0;
11715#endif
11716#ifdef FEAT_RIGHTLEFT
11717 static int save_ri = 0;
11718 static int save_hkmap = 0;
11719#endif
11720 buf_T *buf;
11721
11722 if (p_paste)
11723 {
11724 /*
11725 * Paste switched from off to on.
11726 * Save the current values, so they can be restored later.
11727 */
11728 if (!old_p_paste)
11729 {
11730 /* save options for each buffer */
11731 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11732 {
11733 buf->b_p_tw_nopaste = buf->b_p_tw;
11734 buf->b_p_wm_nopaste = buf->b_p_wm;
11735 buf->b_p_sts_nopaste = buf->b_p_sts;
11736 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011737 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011738 }
11739
11740 /* save global options */
11741 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011742 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011743#ifdef FEAT_CMDL_INFO
11744 save_ru = p_ru;
11745#endif
11746#ifdef FEAT_RIGHTLEFT
11747 save_ri = p_ri;
11748 save_hkmap = p_hkmap;
11749#endif
11750 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011751 p_ai_nopaste = p_ai;
11752 p_et_nopaste = p_et;
11753 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011754 p_tw_nopaste = p_tw;
11755 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011756 }
11757
11758 /*
11759 * Always set the option values, also when 'paste' is set when it is
11760 * already on.
11761 */
11762 /* set options for each buffer */
11763 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11764 {
11765 buf->b_p_tw = 0; /* textwidth is 0 */
11766 buf->b_p_wm = 0; /* wrapmargin is 0 */
11767 buf->b_p_sts = 0; /* softtabstop is 0 */
11768 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011769 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011770 }
11771
11772 /* set global options */
11773 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011774 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011775#ifdef FEAT_CMDL_INFO
11776# ifdef FEAT_WINDOWS
11777 if (p_ru)
11778 status_redraw_all(); /* redraw to remove the ruler */
11779# endif
11780 p_ru = 0; /* no ruler */
11781#endif
11782#ifdef FEAT_RIGHTLEFT
11783 p_ri = 0; /* no reverse insert */
11784 p_hkmap = 0; /* no Hebrew keyboard */
11785#endif
11786 /* set global values for local buffer options */
11787 p_tw = 0;
11788 p_wm = 0;
11789 p_sts = 0;
11790 p_ai = 0;
11791 }
11792
11793 /*
11794 * Paste switched from on to off: Restore saved values.
11795 */
11796 else if (old_p_paste)
11797 {
11798 /* restore options for each buffer */
11799 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11800 {
11801 buf->b_p_tw = buf->b_p_tw_nopaste;
11802 buf->b_p_wm = buf->b_p_wm_nopaste;
11803 buf->b_p_sts = buf->b_p_sts_nopaste;
11804 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011805 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011806 }
11807
11808 /* restore global options */
11809 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011810 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011811#ifdef FEAT_CMDL_INFO
11812# ifdef FEAT_WINDOWS
11813 if (p_ru != save_ru)
11814 status_redraw_all(); /* redraw to draw the ruler */
11815# endif
11816 p_ru = save_ru;
11817#endif
11818#ifdef FEAT_RIGHTLEFT
11819 p_ri = save_ri;
11820 p_hkmap = save_hkmap;
11821#endif
11822 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011823 p_ai = p_ai_nopaste;
11824 p_et = p_et_nopaste;
11825 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011826 p_tw = p_tw_nopaste;
11827 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011828 }
11829
11830 old_p_paste = p_paste;
11831}
11832
11833/*
11834 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11835 *
11836 * Reset 'compatible' and set the values for options that didn't get set yet
11837 * to the Vim defaults.
11838 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011839 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840 */
11841 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011842vimrc_found(fname, envname)
11843 char_u *fname;
11844 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011846 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011847 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011848 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011849
11850 if (!option_was_set((char_u *)"cp"))
11851 {
11852 p_cp = FALSE;
11853 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11854 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11855 set_option_default(opt_idx, OPT_FREE, FALSE);
11856 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011857 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011858 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011859
11860 if (fname != NULL)
11861 {
11862 p = vim_getenv(envname, &dofree);
11863 if (p == NULL)
11864 {
11865 /* Set $MYVIMRC to the first vimrc file found. */
11866 p = FullName_save(fname, FALSE);
11867 if (p != NULL)
11868 {
11869 vim_setenv(envname, p);
11870 vim_free(p);
11871 }
11872 }
11873 else if (dofree)
11874 vim_free(p);
11875 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011876}
11877
11878/*
11879 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11880 */
11881 void
11882change_compatible(on)
11883 int on;
11884{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011885 int opt_idx;
11886
Bram Moolenaar071d4272004-06-13 20:20:40 +000011887 if (p_cp != on)
11888 {
11889 p_cp = on;
11890 compatible_set();
11891 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011892 opt_idx = findoption((char_u *)"cp");
11893 if (opt_idx >= 0)
11894 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011895}
11896
11897/*
11898 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011899 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900 */
11901 int
11902option_was_set(name)
11903 char_u *name;
11904{
11905 int idx;
11906
11907 idx = findoption(name);
11908 if (idx < 0) /* unknown option */
11909 return FALSE;
11910 if (options[idx].flags & P_WAS_SET)
11911 return TRUE;
11912 return FALSE;
11913}
11914
11915/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011916 * Reset the flag indicating option "name" was set.
11917 */
11918 void
11919reset_option_was_set(name)
11920 char_u *name;
11921{
11922 int idx = findoption(name);
11923
11924 if (idx >= 0)
11925 options[idx].flags &= ~P_WAS_SET;
11926}
11927
11928/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011929 * compatible_set() - Called when 'compatible' has been set or unset.
11930 *
11931 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11932 * flag) to a Vi compatible value.
11933 * When 'compatible' is unset: Set all options that have a different default
11934 * for Vim (without the P_VI_DEF flag) to that default.
11935 */
11936 static void
11937compatible_set()
11938{
11939 int opt_idx;
11940
11941 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11942 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11943 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11944 set_option_default(opt_idx, OPT_FREE, p_cp);
11945 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011946 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947}
11948
11949#ifdef FEAT_LINEBREAK
11950
11951# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11952 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011953 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011954# endif
11955
11956/*
11957 * fill_breakat_flags() -- called when 'breakat' changes value.
11958 */
11959 static void
11960fill_breakat_flags()
11961{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011962 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963 int i;
11964
11965 for (i = 0; i < 256; i++)
11966 breakat_flags[i] = FALSE;
11967
11968 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011969 for (p = p_breakat; *p; p++)
11970 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011971}
11972
11973# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011974 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011975# endif
11976
11977#endif
11978
11979/*
11980 * Check an option that can be a range of string values.
11981 *
11982 * Return OK for correct value, FAIL otherwise.
11983 * Empty is always OK.
11984 */
11985 static int
11986check_opt_strings(val, values, list)
11987 char_u *val;
11988 char **values;
11989 int list; /* when TRUE: accept a list of values */
11990{
11991 return opt_strings_flags(val, values, NULL, list);
11992}
11993
11994/*
11995 * Handle an option that can be a range of string values.
11996 * Set a flag in "*flagp" for each string present.
11997 *
11998 * Return OK for correct value, FAIL otherwise.
11999 * Empty is always OK.
12000 */
12001 static int
12002opt_strings_flags(val, values, flagp, list)
12003 char_u *val; /* new value */
12004 char **values; /* array of valid string values */
12005 unsigned *flagp;
12006 int list; /* when TRUE: accept a list of values */
12007{
12008 int i;
12009 int len;
12010 unsigned new_flags = 0;
12011
12012 while (*val)
12013 {
12014 for (i = 0; ; ++i)
12015 {
12016 if (values[i] == NULL) /* val not found in values[] */
12017 return FAIL;
12018
12019 len = (int)STRLEN(values[i]);
12020 if (STRNCMP(values[i], val, len) == 0
12021 && ((list && val[len] == ',') || val[len] == NUL))
12022 {
12023 val += len + (val[len] == ',');
12024 new_flags |= (1 << i);
12025 break; /* check next item in val list */
12026 }
12027 }
12028 }
12029 if (flagp != NULL)
12030 *flagp = new_flags;
12031
12032 return OK;
12033}
12034
12035/*
12036 * Read the 'wildmode' option, fill wim_flags[].
12037 */
12038 static int
12039check_opt_wim()
12040{
12041 char_u new_wim_flags[4];
12042 char_u *p;
12043 int i;
12044 int idx = 0;
12045
12046 for (i = 0; i < 4; ++i)
12047 new_wim_flags[i] = 0;
12048
12049 for (p = p_wim; *p; ++p)
12050 {
12051 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12052 ;
12053 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12054 return FAIL;
12055 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12056 new_wim_flags[idx] |= WIM_LONGEST;
12057 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12058 new_wim_flags[idx] |= WIM_FULL;
12059 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12060 new_wim_flags[idx] |= WIM_LIST;
12061 else
12062 return FAIL;
12063 p += i;
12064 if (*p == NUL)
12065 break;
12066 if (*p == ',')
12067 {
12068 if (idx == 3)
12069 return FAIL;
12070 ++idx;
12071 }
12072 }
12073
12074 /* fill remaining entries with last flag */
12075 while (idx < 3)
12076 {
12077 new_wim_flags[idx + 1] = new_wim_flags[idx];
12078 ++idx;
12079 }
12080
12081 /* only when there are no errors, wim_flags[] is changed */
12082 for (i = 0; i < 4; ++i)
12083 wim_flags[i] = new_wim_flags[i];
12084 return OK;
12085}
12086
12087/*
12088 * Check if backspacing over something is allowed.
12089 */
12090 int
12091can_bs(what)
12092 int what; /* BS_INDENT, BS_EOL or BS_START */
12093{
12094 switch (*p_bs)
12095 {
12096 case '2': return TRUE;
12097 case '1': return (what != BS_START);
12098 case '0': return FALSE;
12099 }
12100 return vim_strchr(p_bs, what) != NULL;
12101}
12102
12103/*
12104 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12105 * the file must be considered changed when the value is different.
12106 */
12107 void
12108save_file_ff(buf)
12109 buf_T *buf;
12110{
12111 buf->b_start_ffc = *buf->b_p_ff;
12112 buf->b_start_eol = buf->b_p_eol;
12113#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012114 buf->b_start_bomb = buf->b_p_bomb;
12115
Bram Moolenaar071d4272004-06-13 20:20:40 +000012116 /* Only use free/alloc when necessary, they take time. */
12117 if (buf->b_start_fenc == NULL
12118 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12119 {
12120 vim_free(buf->b_start_fenc);
12121 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12122 }
12123#endif
12124}
12125
12126/*
12127 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12128 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012129 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12130 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012131 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012132 * When "ignore_empty" is true don't consider a new, empty buffer to be
12133 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012134 */
12135 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012136file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012137 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012138 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012139{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012140 /* In a buffer that was never loaded the options are not valid. */
12141 if (buf->b_flags & BF_NEVERLOADED)
12142 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012143 if (ignore_empty
12144 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012145 && buf->b_ml.ml_line_count == 1
12146 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12147 return FALSE;
12148 if (buf->b_start_ffc != *buf->b_p_ff)
12149 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012150 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012151 return TRUE;
12152#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012153 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12154 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012155 if (buf->b_start_fenc == NULL)
12156 return (*buf->b_p_fenc != NUL);
12157 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12158#else
12159 return FALSE;
12160#endif
12161}
12162
12163/*
12164 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12165 */
12166 int
12167check_ff_value(p)
12168 char_u *p;
12169{
12170 return check_opt_strings(p, p_ff_values, FALSE);
12171}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012172
12173/*
12174 * Return the effective shiftwidth value for current buffer, using the
12175 * 'tabstop' value when 'shiftwidth' is zero.
12176 */
12177 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012178get_sw_value(buf)
12179 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012180{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012181 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012182}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012183
12184/*
12185 * Return the effective softtabstop value for the current buffer, using the
12186 * 'tabstop' value when 'softtabstop' is negative.
12187 */
12188 long
12189get_sts_value()
12190{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012191 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012192}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012193
12194/*
12195 * Check matchpairs option for "*initc".
12196 * If there is a match set "*initc" to the matching character and "*findc" to
12197 * the opposite character. Set "*backwards" to the direction.
12198 * When "switchit" is TRUE swap the direction.
12199 */
12200 void
12201find_mps_values(initc, findc, backwards, switchit)
12202 int *initc;
12203 int *findc;
12204 int *backwards;
12205 int switchit;
12206{
12207 char_u *ptr;
12208
12209 ptr = curbuf->b_p_mps;
12210 while (*ptr != NUL)
12211 {
12212#ifdef FEAT_MBYTE
12213 if (has_mbyte)
12214 {
12215 char_u *prev;
12216
12217 if (mb_ptr2char(ptr) == *initc)
12218 {
12219 if (switchit)
12220 {
12221 *findc = *initc;
12222 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12223 *backwards = TRUE;
12224 }
12225 else
12226 {
12227 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12228 *backwards = FALSE;
12229 }
12230 return;
12231 }
12232 prev = ptr;
12233 ptr += mb_ptr2len(ptr) + 1;
12234 if (mb_ptr2char(ptr) == *initc)
12235 {
12236 if (switchit)
12237 {
12238 *findc = *initc;
12239 *initc = mb_ptr2char(prev);
12240 *backwards = FALSE;
12241 }
12242 else
12243 {
12244 *findc = mb_ptr2char(prev);
12245 *backwards = TRUE;
12246 }
12247 return;
12248 }
12249 ptr += mb_ptr2len(ptr);
12250 }
12251 else
12252#endif
12253 {
12254 if (*ptr == *initc)
12255 {
12256 if (switchit)
12257 {
12258 *backwards = TRUE;
12259 *findc = *initc;
12260 *initc = ptr[2];
12261 }
12262 else
12263 {
12264 *backwards = FALSE;
12265 *findc = ptr[2];
12266 }
12267 return;
12268 }
12269 ptr += 2;
12270 if (*ptr == *initc)
12271 {
12272 if (switchit)
12273 {
12274 *backwards = FALSE;
12275 *findc = *initc;
12276 *initc = ptr[-2];
12277 }
12278 else
12279 {
12280 *backwards = TRUE;
12281 *findc = ptr[-2];
12282 }
12283 return;
12284 }
12285 ++ptr;
12286 }
12287 if (*ptr == ',')
12288 ++ptr;
12289 }
12290}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012291
12292#if defined(FEAT_LINEBREAK) || defined(PROTO)
12293/*
12294 * This is called when 'breakindentopt' is changed and when a window is
12295 * initialized.
12296 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012297 static int
12298briopt_check(wp)
12299 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012300{
12301 char_u *p;
12302 int bri_shift = 0;
12303 long bri_min = 20;
12304 int bri_sbr = FALSE;
12305
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012306 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012307 while (*p != NUL)
12308 {
12309 if (STRNCMP(p, "shift:", 6) == 0
12310 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12311 {
12312 p += 6;
12313 bri_shift = getdigits(&p);
12314 }
12315 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12316 {
12317 p += 4;
12318 bri_min = getdigits(&p);
12319 }
12320 else if (STRNCMP(p, "sbr", 3) == 0)
12321 {
12322 p += 3;
12323 bri_sbr = TRUE;
12324 }
12325 if (*p != ',' && *p != NUL)
12326 return FAIL;
12327 if (*p == ',')
12328 ++p;
12329 }
12330
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012331 wp->w_p_brishift = bri_shift;
12332 wp->w_p_brimin = bri_min;
12333 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012334
12335 return OK;
12336}
12337#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012338
12339/*
12340 * Get the local or global value of 'backupcopy'.
12341 */
12342 unsigned int
12343get_bkc_value(buf)
12344 buf_T *buf;
12345{
12346 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12347}