blob: 0c38de68961a9bab6d500c87914930da9c8bcca9 [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)
Bram Moolenaara9884962015-12-13 15:08:56 +01004973 {
4974#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4975 vim_free(saved_origval);
4976#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004977 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004978 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004979#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4980 if (saved_origval != NULL)
4981 {
4982 char_u buf_type[7];
4983
4984 sprintf((char *)buf_type, "%s",
4985 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004986 set_vim_var_string(VV_OPTION_NEW,
4987 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004988 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4989 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4990 apply_autocmds(EVENT_OPTIONSET,
4991 (char_u *)options[opt_idx].fullname,
4992 NULL, FALSE, NULL);
4993 reset_v_option_vars();
4994 vim_free(saved_origval);
4995 }
4996#endif
4997
Bram Moolenaar071d4272004-06-13 20:20:40 +00004998 }
4999 else /* key code option */
5000 {
5001 char_u *p;
5002
5003 if (nextchar == '&')
5004 {
5005 if (add_termcap_entry(key_name, TRUE) == FAIL)
5006 errmsg = (char_u *)N_("E522: Not found in termcap");
5007 }
5008 else
5009 {
5010 ++arg; /* jump to after the '=' or ':' */
5011 for (p = arg; *p && !vim_iswhite(*p); ++p)
5012 if (*p == '\\' && p[1] != NUL)
5013 ++p;
5014 nextchar = *p;
5015 *p = NUL;
5016 add_termcode(key_name, arg, FALSE);
5017 *p = nextchar;
5018 }
5019 if (full_screen)
5020 ttest(FALSE);
5021 redraw_all_later(CLEAR);
5022 }
5023 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005024
Bram Moolenaar071d4272004-06-13 20:20:40 +00005025 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005026 did_set_option(opt_idx, opt_flags,
5027 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005028 }
5029
5030skip:
5031 /*
5032 * Advance to next argument.
5033 * - skip until a blank found, taking care of backslashes
5034 * - skip blanks
5035 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5036 */
5037 for (i = 0; i < 2 ; ++i)
5038 {
5039 while (*arg != NUL && !vim_iswhite(*arg))
5040 if (*arg++ == '\\' && *arg != NUL)
5041 ++arg;
5042 arg = skipwhite(arg);
5043 if (*arg != '=')
5044 break;
5045 }
5046 }
5047
5048 if (errmsg != NULL)
5049 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005050 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005051 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005052 if (i + (arg - startarg) < IOSIZE)
5053 {
5054 /* append the argument with the error */
5055 STRCAT(IObuff, ": ");
5056 mch_memmove(IObuff + i, startarg, (arg - startarg));
5057 IObuff[i + (arg - startarg)] = NUL;
5058 }
5059 /* make sure all characters are printable */
5060 trans_characters(IObuff, IOSIZE);
5061
5062 ++no_wait_return; /* wait_return done later */
5063 emsg(IObuff); /* show error highlighted */
5064 --no_wait_return;
5065
5066 return FAIL;
5067 }
5068
5069 arg = skipwhite(arg);
5070 }
5071
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005072theend:
5073 if (silent_mode && did_show)
5074 {
5075 /* After displaying option values in silent mode. */
5076 silent_mode = FALSE;
5077 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5078 msg_putchar('\n');
5079 cursor_on(); /* msg_start() switches it off */
5080 out_flush();
5081 silent_mode = TRUE;
5082 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5083 }
5084
Bram Moolenaar071d4272004-06-13 20:20:40 +00005085 return OK;
5086}
5087
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005088/*
5089 * Call this when an option has been given a new value through a user command.
5090 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5091 */
5092 static void
5093did_set_option(opt_idx, opt_flags, new_value)
5094 int opt_idx;
5095 int opt_flags; /* possibly with OPT_MODELINE */
5096 int new_value; /* value was replaced completely */
5097{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005098 long_u *p;
5099
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005100 options[opt_idx].flags |= P_WAS_SET;
5101
5102 /* When an option is set in the sandbox, from a modeline or in secure mode
5103 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005104 * flag. */
5105 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005106 if (secure
5107#ifdef HAVE_SANDBOX
5108 || sandbox != 0
5109#endif
5110 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005111 *p = *p | P_INSECURE;
5112 else if (new_value)
5113 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005114}
5115
Bram Moolenaar071d4272004-06-13 20:20:40 +00005116 static char_u *
5117illegal_char(errbuf, c)
5118 char_u *errbuf;
5119 int c;
5120{
5121 if (errbuf == NULL)
5122 return (char_u *)"";
5123 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005124 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005125 return errbuf;
5126}
5127
5128/*
5129 * Convert a key name or string into a key value.
5130 * Used for 'wildchar' and 'cedit' options.
5131 */
5132 static int
5133string_to_key(arg)
5134 char_u *arg;
5135{
5136 if (*arg == '<')
5137 return find_key_option(arg + 1);
5138 if (*arg == '^')
5139 return Ctrl_chr(arg[1]);
5140 return *arg;
5141}
5142
5143#ifdef FEAT_CMDWIN
5144/*
5145 * Check value of 'cedit' and set cedit_key.
5146 * Returns NULL if value is OK, error message otherwise.
5147 */
5148 static char_u *
5149check_cedit()
5150{
5151 int n;
5152
5153 if (*p_cedit == NUL)
5154 cedit_key = -1;
5155 else
5156 {
5157 n = string_to_key(p_cedit);
5158 if (vim_isprintc(n))
5159 return e_invarg;
5160 cedit_key = n;
5161 }
5162 return NULL;
5163}
5164#endif
5165
5166#ifdef FEAT_TITLE
5167/*
5168 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5169 * maketitle() to create and display it.
5170 * When switching the title or icon off, call mch_restore_title() to get
5171 * the old value back.
5172 */
5173 static void
5174did_set_title(icon)
5175 int icon; /* Did set icon instead of title */
5176{
5177 if (starting != NO_SCREEN
5178#ifdef FEAT_GUI
5179 && !gui.starting
5180#endif
5181 )
5182 {
5183 maketitle();
5184 if (icon)
5185 {
5186 if (!p_icon)
5187 mch_restore_title(2);
5188 }
5189 else
5190 {
5191 if (!p_title)
5192 mch_restore_title(1);
5193 }
5194 }
5195}
5196#endif
5197
5198/*
5199 * set_options_bin - called when 'bin' changes value.
5200 */
5201 void
5202set_options_bin(oldval, newval, opt_flags)
5203 int oldval;
5204 int newval;
5205 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5206{
5207 /*
5208 * The option values that are changed when 'bin' changes are
5209 * copied when 'bin is set and restored when 'bin' is reset.
5210 */
5211 if (newval)
5212 {
5213 if (!oldval) /* switched on */
5214 {
5215 if (!(opt_flags & OPT_GLOBAL))
5216 {
5217 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5218 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5219 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5220 curbuf->b_p_et_nobin = curbuf->b_p_et;
5221 }
5222 if (!(opt_flags & OPT_LOCAL))
5223 {
5224 p_tw_nobin = p_tw;
5225 p_wm_nobin = p_wm;
5226 p_ml_nobin = p_ml;
5227 p_et_nobin = p_et;
5228 }
5229 }
5230
5231 if (!(opt_flags & OPT_GLOBAL))
5232 {
5233 curbuf->b_p_tw = 0; /* no automatic line wrap */
5234 curbuf->b_p_wm = 0; /* no automatic line wrap */
5235 curbuf->b_p_ml = 0; /* no modelines */
5236 curbuf->b_p_et = 0; /* no expandtab */
5237 }
5238 if (!(opt_flags & OPT_LOCAL))
5239 {
5240 p_tw = 0;
5241 p_wm = 0;
5242 p_ml = FALSE;
5243 p_et = FALSE;
5244 p_bin = TRUE; /* needed when called for the "-b" argument */
5245 }
5246 }
5247 else if (oldval) /* switched off */
5248 {
5249 if (!(opt_flags & OPT_GLOBAL))
5250 {
5251 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5252 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5253 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5254 curbuf->b_p_et = curbuf->b_p_et_nobin;
5255 }
5256 if (!(opt_flags & OPT_LOCAL))
5257 {
5258 p_tw = p_tw_nobin;
5259 p_wm = p_wm_nobin;
5260 p_ml = p_ml_nobin;
5261 p_et = p_et_nobin;
5262 }
5263 }
5264}
5265
5266#ifdef FEAT_VIMINFO
5267/*
5268 * Find the parameter represented by the given character (eg ', :, ", or /),
5269 * and return its associated value in the 'viminfo' string.
5270 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005271 * If the parameter is not specified in the string or there is no following
5272 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273 */
5274 int
5275get_viminfo_parameter(type)
5276 int type;
5277{
5278 char_u *p;
5279
5280 p = find_viminfo_parameter(type);
5281 if (p != NULL && VIM_ISDIGIT(*p))
5282 return atoi((char *)p);
5283 return -1;
5284}
5285
5286/*
5287 * Find the parameter represented by the given character (eg ''', ':', '"', or
5288 * '/') in the 'viminfo' option and return a pointer to the string after it.
5289 * Return NULL if the parameter is not specified in the string.
5290 */
5291 char_u *
5292find_viminfo_parameter(type)
5293 int type;
5294{
5295 char_u *p;
5296
5297 for (p = p_viminfo; *p; ++p)
5298 {
5299 if (*p == type)
5300 return p + 1;
5301 if (*p == 'n') /* 'n' is always the last one */
5302 break;
5303 p = vim_strchr(p, ','); /* skip until next ',' */
5304 if (p == NULL) /* hit the end without finding parameter */
5305 break;
5306 }
5307 return NULL;
5308}
5309#endif
5310
5311/*
5312 * Expand environment variables for some string options.
5313 * These string options cannot be indirect!
5314 * If "val" is NULL expand the current value of the option.
5315 * Return pointer to NameBuff, or NULL when not expanded.
5316 */
5317 static char_u *
5318option_expand(opt_idx, val)
5319 int opt_idx;
5320 char_u *val;
5321{
5322 /* if option doesn't need expansion nothing to do */
5323 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5324 return NULL;
5325
5326 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5327 * expand_env() would truncate the string. */
5328 if (val != NULL && STRLEN(val) > MAXPATHL)
5329 return NULL;
5330
5331 if (val == NULL)
5332 val = *(char_u **)options[opt_idx].var;
5333
5334 /*
5335 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5336 * Escape spaces when expanding 'tags', they are used to separate file
5337 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005338 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005339 */
5340 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005341 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005342#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005343 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5344#endif
5345 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5347 return NULL;
5348
5349 return NameBuff;
5350}
5351
5352/*
5353 * After setting various option values: recompute variables that depend on
5354 * option values.
5355 */
5356 static void
5357didset_options()
5358{
5359 /* initialize the table for 'iskeyword' et.al. */
5360 (void)init_chartab();
5361
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005362#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005364#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005365 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005366 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005367#ifdef FEAT_SESSION
5368 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5369 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5370#endif
5371#ifdef FEAT_FOLDING
5372 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5373#endif
5374 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005375 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376#ifdef FEAT_VIRTUALEDIT
5377 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5378#endif
5379#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5380 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5381#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005382#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005383 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005384 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005385 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005386 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005388#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5389 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5390#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005391#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005392 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5393#endif
5394#ifdef FEAT_CMDWIN
5395 /* set cedit_key */
5396 (void)check_cedit();
5397#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005398#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005399 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005400#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005401#ifdef FEAT_LINEBREAK
5402 /* initialize the table for 'breakat'. */
5403 fill_breakat_flags();
5404#endif
5405
5406}
5407
5408/*
5409 * More side effects of setting options.
5410 */
5411 static void
5412didset_options2()
5413{
5414 /* Initialize the highlight_attr[] table. */
5415 (void)highlight_changed();
5416
5417 /* Parse default for 'wildmode' */
5418 check_opt_wim();
5419
5420 (void)set_chars_option(&p_lcs);
5421#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5422 /* Parse default for 'fillchars'. */
5423 (void)set_chars_option(&p_fcs);
5424#endif
5425
5426#ifdef FEAT_CLIPBOARD
5427 /* Parse default for 'clipboard' */
5428 (void)check_clipboard_option();
5429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005430}
5431
5432/*
5433 * Check for string options that are NULL (normally only termcap options).
5434 */
5435 void
5436check_options()
5437{
5438 int opt_idx;
5439
5440 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5441 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5442 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5443}
5444
5445/*
5446 * Check string options in a buffer for NULL value.
5447 */
5448 void
5449check_buf_options(buf)
5450 buf_T *buf;
5451{
5452#if defined(FEAT_QUICKFIX)
5453 check_string_option(&buf->b_p_bh);
5454 check_string_option(&buf->b_p_bt);
5455#endif
5456#ifdef FEAT_MBYTE
5457 check_string_option(&buf->b_p_fenc);
5458#endif
5459 check_string_option(&buf->b_p_ff);
5460#ifdef FEAT_FIND_ID
5461 check_string_option(&buf->b_p_def);
5462 check_string_option(&buf->b_p_inc);
5463# ifdef FEAT_EVAL
5464 check_string_option(&buf->b_p_inex);
5465# endif
5466#endif
5467#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5468 check_string_option(&buf->b_p_inde);
5469 check_string_option(&buf->b_p_indk);
5470#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005471#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5472 check_string_option(&buf->b_p_bexpr);
5473#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005474#if defined(FEAT_CRYPT)
5475 check_string_option(&buf->b_p_cm);
5476#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005477#if defined(FEAT_EVAL)
5478 check_string_option(&buf->b_p_fex);
5479#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005480#ifdef FEAT_CRYPT
5481 check_string_option(&buf->b_p_key);
5482#endif
5483 check_string_option(&buf->b_p_kp);
5484 check_string_option(&buf->b_p_mps);
5485 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005486 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005487 check_string_option(&buf->b_p_isk);
5488#ifdef FEAT_COMMENTS
5489 check_string_option(&buf->b_p_com);
5490#endif
5491#ifdef FEAT_FOLDING
5492 check_string_option(&buf->b_p_cms);
5493#endif
5494 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005495#ifdef FEAT_TEXTOBJ
5496 check_string_option(&buf->b_p_qe);
5497#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005498#ifdef FEAT_SYN_HL
5499 check_string_option(&buf->b_p_syn);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005500#endif
5501#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005502 check_string_option(&buf->b_s.b_p_spc);
5503 check_string_option(&buf->b_s.b_p_spf);
5504 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005505#endif
5506#ifdef FEAT_SEARCHPATH
5507 check_string_option(&buf->b_p_sua);
5508#endif
5509#ifdef FEAT_CINDENT
5510 check_string_option(&buf->b_p_cink);
5511 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005512 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513#endif
5514#ifdef FEAT_AUTOCMD
5515 check_string_option(&buf->b_p_ft);
5516#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5518 check_string_option(&buf->b_p_cinw);
5519#endif
5520#ifdef FEAT_INS_EXPAND
5521 check_string_option(&buf->b_p_cpt);
5522#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005523#ifdef FEAT_COMPL_FUNC
5524 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005525 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005526#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005527#ifdef FEAT_KEYMAP
5528 check_string_option(&buf->b_p_keymap);
5529#endif
5530#ifdef FEAT_QUICKFIX
5531 check_string_option(&buf->b_p_gp);
5532 check_string_option(&buf->b_p_mp);
5533 check_string_option(&buf->b_p_efm);
5534#endif
5535 check_string_option(&buf->b_p_ep);
5536 check_string_option(&buf->b_p_path);
5537 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005538 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539#ifdef FEAT_INS_EXPAND
5540 check_string_option(&buf->b_p_dict);
5541 check_string_option(&buf->b_p_tsr);
5542#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005543#ifdef FEAT_LISP
5544 check_string_option(&buf->b_p_lw);
5545#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005546 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005547}
5548
5549/*
5550 * Free the string allocated for an option.
5551 * Checks for the string being empty_option. This may happen if we're out of
5552 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5553 * check_options().
5554 * Does NOT check for P_ALLOCED flag!
5555 */
5556 void
5557free_string_option(p)
5558 char_u *p;
5559{
5560 if (p != empty_option)
5561 vim_free(p);
5562}
5563
5564 void
5565clear_string_option(pp)
5566 char_u **pp;
5567{
5568 if (*pp != empty_option)
5569 vim_free(*pp);
5570 *pp = empty_option;
5571}
5572
5573 static void
5574check_string_option(pp)
5575 char_u **pp;
5576{
5577 if (*pp == NULL)
5578 *pp = empty_option;
5579}
5580
5581/*
5582 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5583 */
5584 void
5585set_term_option_alloced(p)
5586 char_u **p;
5587{
5588 int opt_idx;
5589
5590 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5591 if (options[opt_idx].var == (char_u *)p)
5592 {
5593 options[opt_idx].flags |= P_ALLOCED;
5594 return;
5595 }
5596 return; /* cannot happen: didn't find it! */
5597}
5598
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005599#if defined(FEAT_EVAL) || defined(PROTO)
5600/*
5601 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5602 * Return FALSE when it wasn't.
5603 * Return -1 for an unknown option.
5604 */
5605 int
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005606was_set_insecurely(opt, opt_flags)
5607 char_u *opt;
5608 int opt_flags;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005609{
5610 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005611 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005612
5613 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005614 {
5615 flagp = insecure_flag(idx, opt_flags);
5616 return (*flagp & P_INSECURE) != 0;
5617 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005618 EMSG2(_(e_intern2), "was_set_insecurely()");
5619 return -1;
5620}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005621
5622/*
5623 * Get a pointer to the flags used for the P_INSECURE flag of option
5624 * "opt_idx". For some local options a local flags field is used.
5625 */
5626 static long_u *
5627insecure_flag(opt_idx, opt_flags)
5628 int opt_idx;
5629 int opt_flags;
5630{
5631 if (opt_flags & OPT_LOCAL)
5632 switch ((int)options[opt_idx].indir)
5633 {
5634#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005635 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005636#endif
5637#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005638# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005639 case PV_FDE: return &curwin->w_p_fde_flags;
5640 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005641# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005642# ifdef FEAT_BEVAL
5643 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5644# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005645# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005646 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005647# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005648 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005649# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005650 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005651# endif
5652#endif
5653 }
5654
5655 /* Nothing special, return global flags field. */
5656 return &options[opt_idx].flags;
5657}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005658#endif
5659
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005660#ifdef FEAT_TITLE
5661static void redraw_titles __ARGS((void));
5662
5663/*
5664 * Redraw the window title and/or tab page text later.
5665 */
5666static void redraw_titles()
5667{
5668 need_maketitle = TRUE;
5669# ifdef FEAT_WINDOWS
5670 redraw_tabline = TRUE;
5671# endif
5672}
5673#endif
5674
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675/*
5676 * Set a string option to a new value (without checking the effect).
5677 * The string is copied into allocated memory.
5678 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005679 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005680 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681 */
5682 void
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005683set_string_option_direct(name, opt_idx, val, opt_flags, set_sid)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684 char_u *name;
5685 int opt_idx;
5686 char_u *val;
5687 int opt_flags; /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar78a15312009-05-15 19:33:18 +00005688 int set_sid UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689{
5690 char_u *s;
5691 char_u **varp;
5692 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005693 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694
Bram Moolenaar89d40322006-08-29 15:30:07 +00005695 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005697 idx = findoption(name);
5698 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005699 {
5700 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005701 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704 }
5705
Bram Moolenaar89d40322006-08-29 15:30:07 +00005706 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707 return;
5708
5709 s = vim_strsave(val);
5710 if (s != NULL)
5711 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005712 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005714 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715 free_string_option(*varp);
5716 *varp = s;
5717
5718 /* For buffer/window local option may also set the global value. */
5719 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005720 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005721
Bram Moolenaar89d40322006-08-29 15:30:07 +00005722 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005723
5724 /* When setting both values of a global option with a local value,
5725 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005726 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727 {
5728 free_string_option(*varp);
5729 *varp = empty_option;
5730 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005731# ifdef FEAT_EVAL
5732 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005733 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005734 set_sid == 0 ? current_SID : set_sid);
5735# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736 }
5737}
5738
5739/*
5740 * Set global value for string option when it's a local option.
5741 */
5742 static void
5743set_string_option_global(opt_idx, varp)
5744 int opt_idx; /* option index */
5745 char_u **varp; /* pointer to option variable */
5746{
5747 char_u **p, *s;
5748
5749 /* the global value is always allocated */
5750 if (options[opt_idx].var == VAR_WIN)
5751 p = (char_u **)GLOBAL_WO(varp);
5752 else
5753 p = (char_u **)options[opt_idx].var;
5754 if (options[opt_idx].indir != PV_NONE
5755 && p != varp
5756 && (s = vim_strsave(*varp)) != NULL)
5757 {
5758 free_string_option(*p);
5759 *p = s;
5760 }
5761}
5762
5763/*
5764 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005765 *
5766 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005767 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005768 static char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00005769set_string_option(opt_idx, value, opt_flags)
5770 int opt_idx;
5771 char_u *value;
5772 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5773{
5774 char_u *s;
5775 char_u **varp;
5776 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005777#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5778 char_u *saved_oldval = NULL;
5779#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005780 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005781
5782 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005783 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005784
5785 s = vim_strsave(value);
5786 if (s != NULL)
5787 {
5788 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5789 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005790 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005791 ? OPT_GLOBAL : OPT_LOCAL)
5792 : opt_flags);
5793 oldval = *varp;
5794 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005795
5796#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005797 if (!starting
5798# ifdef FEAT_CRYPT
5799 && options[opt_idx].indir != PV_KEY
5800# endif
5801 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005802 saved_oldval = vim_strsave(oldval);
5803#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005804 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5805 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005806 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005807
5808 /* call autocomamnd after handling side effects */
5809#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5810 if (saved_oldval != NULL)
5811 {
5812 char_u buf_type[7];
5813 sprintf((char *)buf_type, "%s",
5814 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005815 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5816 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005817 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5818 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5819 reset_v_option_vars();
5820 vim_free(saved_oldval);
5821 }
5822#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005823 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005824 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005825}
5826
5827/*
5828 * Handle string options that need some action to perform when changed.
5829 * Returns NULL for success, or an error message for an error.
5830 */
5831 static char_u *
5832did_set_string_option(opt_idx, varp, new_value_alloced, oldval, errbuf,
5833 opt_flags)
5834 int opt_idx; /* index in options[] table */
5835 char_u **varp; /* pointer to the option variable */
5836 int new_value_alloced; /* new value was allocated */
5837 char_u *oldval; /* previous value of the option */
5838 char_u *errbuf; /* buffer for errors, or NULL */
5839 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
5840{
5841 char_u *errmsg = NULL;
5842 char_u *s, *p;
5843 int did_chartab = FALSE;
5844 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005845 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005846#ifdef FEAT_GUI
5847 /* set when changing an option that only requires a redraw in the GUI */
5848 int redraw_gui_only = FALSE;
5849#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005850
5851 /* Get the global option to compare with, otherwise we would have to check
5852 * two values for all local options. */
5853 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5854
5855 /* Disallow changing some options from secure mode */
5856 if ((secure
5857#ifdef HAVE_SANDBOX
5858 || sandbox != 0
5859#endif
5860 ) && (options[opt_idx].flags & P_SECURE))
5861 {
5862 errmsg = e_secure;
5863 }
5864
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005865 /* Check for a "normal" file name in some options. Disallow a path
5866 * separator (slash and/or backslash), wildcards and characters that are
5867 * often illegal in a file name. */
5868 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005869 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005870 {
5871 errmsg = e_invarg;
5872 }
5873
Bram Moolenaar071d4272004-06-13 20:20:40 +00005874 /* 'term' */
5875 else if (varp == &T_NAME)
5876 {
5877 if (T_NAME[0] == NUL)
5878 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5879#ifdef FEAT_GUI
5880 if (gui.in_use)
5881 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5882 else if (term_is_gui(T_NAME))
5883 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5884#endif
5885 else if (set_termname(T_NAME) == FAIL)
5886 errmsg = (char_u *)N_("E522: Not found in termcap");
5887 else
5888 /* Screen colors may have changed. */
5889 redraw_later_clear();
5890 }
5891
5892 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005893 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005895 char_u *bkc = p_bkc;
5896 unsigned int *flags = &bkc_flags;
5897
5898 if (opt_flags & OPT_LOCAL)
5899 {
5900 bkc = curbuf->b_p_bkc;
5901 flags = &curbuf->b_bkc_flags;
5902 }
5903
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005904 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5905 /* make the local value empty: use the global value */
5906 *flags = 0;
5907 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005908 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005909 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5910 errmsg = e_invarg;
5911 if ((((int)*flags & BKC_AUTO) != 0)
5912 + (((int)*flags & BKC_YES) != 0)
5913 + (((int)*flags & BKC_NO) != 0) != 1)
5914 {
5915 /* Must have exactly one of "auto", "yes" and "no". */
5916 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5917 errmsg = e_invarg;
5918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 }
5920 }
5921
5922 /* 'backupext' and 'patchmode' */
5923 else if (varp == &p_bex || varp == &p_pm)
5924 {
5925 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5926 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5927 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5928 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005929#ifdef FEAT_LINEBREAK
5930 /* 'breakindentopt' */
5931 else if (varp == &curwin->w_p_briopt)
5932 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005933 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005934 errmsg = e_invarg;
5935 }
5936#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937
5938 /*
5939 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill chartab[]
5940 * If the new option is invalid, use old value. 'lisp' option: refill
5941 * chartab[] for '-' char
5942 */
5943 else if ( varp == &p_isi
5944 || varp == &(curbuf->b_p_isk)
5945 || varp == &p_isp
5946 || varp == &p_isf)
5947 {
5948 if (init_chartab() == FAIL)
5949 {
5950 did_chartab = TRUE; /* need to restore it below */
5951 errmsg = e_invarg; /* error in value */
5952 }
5953 }
5954
5955 /* 'helpfile' */
5956 else if (varp == &p_hf)
5957 {
5958 /* May compute new values for $VIM and $VIMRUNTIME */
5959 if (didset_vim)
5960 {
5961 vim_setenv((char_u *)"VIM", (char_u *)"");
5962 didset_vim = FALSE;
5963 }
5964 if (didset_vimruntime)
5965 {
5966 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5967 didset_vimruntime = FALSE;
5968 }
5969 }
5970
Bram Moolenaar1a384422010-07-14 19:53:30 +02005971#ifdef FEAT_SYN_HL
5972 /* 'colorcolumn' */
5973 else if (varp == &curwin->w_p_cc)
5974 errmsg = check_colorcolumn(curwin);
5975#endif
5976
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977#ifdef FEAT_MULTI_LANG
5978 /* 'helplang' */
5979 else if (varp == &p_hlg)
5980 {
5981 /* Check for "", "ab", "ab,cd", etc. */
5982 for (s = p_hlg; *s != NUL; s += 3)
5983 {
5984 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5985 {
5986 errmsg = e_invarg;
5987 break;
5988 }
5989 if (s[2] == NUL)
5990 break;
5991 }
5992 }
5993#endif
5994
5995 /* 'highlight' */
5996 else if (varp == &p_hl)
5997 {
5998 if (highlight_changed() == FAIL)
5999 errmsg = e_invarg; /* invalid flags */
6000 }
6001
6002 /* 'nrformats' */
6003 else if (gvarp == &p_nf)
6004 {
6005 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6006 errmsg = e_invarg;
6007 }
6008
6009#ifdef FEAT_SESSION
6010 /* 'sessionoptions' */
6011 else if (varp == &p_ssop)
6012 {
6013 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6014 errmsg = e_invarg;
6015 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6016 {
6017 /* Don't allow both "sesdir" and "curdir". */
6018 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6019 errmsg = e_invarg;
6020 }
6021 }
6022 /* 'viewoptions' */
6023 else if (varp == &p_vop)
6024 {
6025 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6026 errmsg = e_invarg;
6027 }
6028#endif
6029
6030 /* 'scrollopt' */
6031#ifdef FEAT_SCROLLBIND
6032 else if (varp == &p_sbo)
6033 {
6034 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6035 errmsg = e_invarg;
6036 }
6037#endif
6038
6039 /* 'ambiwidth' */
6040#ifdef FEAT_MBYTE
6041 else if (varp == &p_ambw)
6042 {
6043 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6044 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006045 else if (set_chars_option(&p_lcs) != NULL)
6046 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6047# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6048 else if (set_chars_option(&p_fcs) != NULL)
6049 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6050# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006051 }
6052#endif
6053
6054 /* 'background' */
6055 else if (varp == &p_bg)
6056 {
6057 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6058 {
6059#ifdef FEAT_EVAL
6060 int dark = (*p_bg == 'd');
6061#endif
6062
6063 init_highlight(FALSE, FALSE);
6064
6065#ifdef FEAT_EVAL
6066 if (dark != (*p_bg == 'd')
6067 && get_var_value((char_u *)"g:colors_name") != NULL)
6068 {
6069 /* The color scheme must have set 'background' back to another
6070 * value, that's not what we want here. Disable the color
6071 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006072 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006073 free_string_option(p_bg);
6074 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6075 check_string_option(&p_bg);
6076 init_highlight(FALSE, FALSE);
6077 }
6078#endif
6079 }
6080 else
6081 errmsg = e_invarg;
6082 }
6083
6084 /* 'wildmode' */
6085 else if (varp == &p_wim)
6086 {
6087 if (check_opt_wim() == FAIL)
6088 errmsg = e_invarg;
6089 }
6090
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006091#ifdef FEAT_CMDL_COMPL
6092 /* 'wildoptions' */
6093 else if (varp == &p_wop)
6094 {
6095 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6096 errmsg = e_invarg;
6097 }
6098#endif
6099
Bram Moolenaar071d4272004-06-13 20:20:40 +00006100#ifdef FEAT_WAK
6101 /* 'winaltkeys' */
6102 else if (varp == &p_wak)
6103 {
6104 if (*p_wak == NUL
6105 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6106 errmsg = e_invarg;
6107# ifdef FEAT_MENU
6108# ifdef FEAT_GUI_MOTIF
6109 else if (gui.in_use)
6110 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6111# else
6112# ifdef FEAT_GUI_GTK
6113 else if (gui.in_use)
6114 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6115# endif
6116# endif
6117# endif
6118 }
6119#endif
6120
6121#ifdef FEAT_AUTOCMD
6122 /* 'eventignore' */
6123 else if (varp == &p_ei)
6124 {
6125 if (check_ei() == FAIL)
6126 errmsg = e_invarg;
6127 }
6128#endif
6129
6130#ifdef FEAT_MBYTE
6131 /* 'encoding' and 'fileencoding' */
6132 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6133 {
6134 if (gvarp == &p_fenc)
6135 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006136 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 errmsg = e_modifiable;
6138 else if (vim_strchr(*varp, ',') != NULL)
6139 /* No comma allowed in 'fileencoding'; catches confusing it
6140 * with 'fileencodings'. */
6141 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006142 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006143 {
6144# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006145 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006146 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006147# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006148 /* Add 'fileencoding' to the swap file. */
6149 ml_setflags(curbuf);
6150 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006151 }
6152 if (errmsg == NULL)
6153 {
6154 /* canonize the value, so that STRCMP() can be used on it */
6155 p = enc_canonize(*varp);
6156 if (p != NULL)
6157 {
6158 vim_free(*varp);
6159 *varp = p;
6160 }
6161 if (varp == &p_enc)
6162 {
6163 errmsg = mb_init();
6164# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006165 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006166# endif
6167 }
6168 }
6169
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006170# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006171 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6172 {
6173 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6174 if (STRCMP(p_tenc, "utf-8") != 0)
6175 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6176 }
6177# endif
6178
6179 if (errmsg == NULL)
6180 {
6181# ifdef FEAT_KEYMAP
6182 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6183 * (with another encoding). */
6184 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6185 (void)keymap_init();
6186# endif
6187
6188 /* When 'termencoding' is not empty and 'encoding' changes or when
6189 * 'termencoding' changes, need to setup for keyboard input and
6190 * display output conversion. */
6191 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6192 {
6193 convert_setup(&input_conv, p_tenc, p_enc);
6194 convert_setup(&output_conv, p_enc, p_tenc);
6195 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006196
6197# if defined(WIN3264) && defined(FEAT_MBYTE)
6198 /* $HOME may have characters in active code page. */
6199 if (varp == &p_enc)
6200 init_homedir();
6201# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006202 }
6203 }
6204#endif
6205
6206#if defined(FEAT_POSTSCRIPT)
6207 else if (varp == &p_penc)
6208 {
6209 /* Canonize printencoding if VIM standard one */
6210 p = enc_canonize(p_penc);
6211 if (p != NULL)
6212 {
6213 vim_free(p_penc);
6214 p_penc = p;
6215 }
6216 else
6217 {
6218 /* Ensure lower case and '-' for '_' */
6219 for (s = p_penc; *s != NUL; s++)
6220 {
6221 if (*s == '_')
6222 *s = '-';
6223 else
6224 *s = TOLOWER_ASC(*s);
6225 }
6226 }
6227 }
6228#endif
6229
Bram Moolenaar9372a112005-12-06 19:59:18 +00006230#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006231 else if (varp == &p_imak)
6232 {
6233 if (gui.in_use && !im_xim_isvalid_imactivate())
6234 errmsg = e_invarg;
6235 }
6236#endif
6237
6238#ifdef FEAT_KEYMAP
6239 else if (varp == &curbuf->b_p_keymap)
6240 {
6241 /* load or unload key mapping tables */
6242 errmsg = keymap_init();
6243
Bram Moolenaarfab06232009-03-04 03:13:35 +00006244 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006245 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006246 if (*curbuf->b_p_keymap != NUL)
6247 {
6248 /* Installed a new keymap, switch on using it. */
6249 curbuf->b_p_iminsert = B_IMODE_LMAP;
6250 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6251 curbuf->b_p_imsearch = B_IMODE_LMAP;
6252 }
6253 else
6254 {
6255 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6256 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6257 curbuf->b_p_iminsert = B_IMODE_NONE;
6258 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6259 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6260 }
6261 if ((opt_flags & OPT_LOCAL) == 0)
6262 {
6263 set_iminsert_global();
6264 set_imsearch_global();
6265 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266# ifdef FEAT_WINDOWS
6267 status_redraw_curbuf();
6268# endif
6269 }
6270 }
6271#endif
6272
6273 /* 'fileformat' */
6274 else if (gvarp == &p_ff)
6275 {
6276 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6277 errmsg = e_modifiable;
6278 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6279 errmsg = e_invarg;
6280 else
6281 {
6282 /* may also change 'textmode' */
6283 if (get_fileformat(curbuf) == EOL_DOS)
6284 curbuf->b_p_tx = TRUE;
6285 else
6286 curbuf->b_p_tx = FALSE;
6287#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006288 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006289#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006290 /* update flag in swap file */
6291 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006292 /* Redraw needed when switching to/from "mac": a CR in the text
6293 * will be displayed differently. */
6294 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6295 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296 }
6297 }
6298
6299 /* 'fileformats' */
6300 else if (varp == &p_ffs)
6301 {
6302 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6303 errmsg = e_invarg;
6304 else
6305 {
6306 /* also change 'textauto' */
6307 if (*p_ffs == NUL)
6308 p_ta = FALSE;
6309 else
6310 p_ta = TRUE;
6311 }
6312 }
6313
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006314#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006315 /* 'cryptkey' */
6316 else if (gvarp == &p_key)
6317 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006318# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319 /* Make sure the ":set" command doesn't show the new value in the
6320 * history. */
6321 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006322# endif
6323 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6324 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006325 ml_set_crypt_key(curbuf, oldval,
6326 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006327 }
6328
6329 else if (gvarp == &p_cm)
6330 {
6331 if (opt_flags & OPT_LOCAL)
6332 p = curbuf->b_p_cm;
6333 else
6334 p = p_cm;
6335 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6336 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006337 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006338 errmsg = e_invarg;
6339 else
6340 {
6341 /* When setting the global value to empty, make it "zip". */
6342 if (*p_cm == NUL)
6343 {
6344 if (new_value_alloced)
6345 free_string_option(p_cm);
6346 p_cm = vim_strsave((char_u *)"zip");
6347 new_value_alloced = TRUE;
6348 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006349 /* When using ":set cm=name" the local value is going to be empty.
6350 * Do that here, otherwise the crypt functions will still use the
6351 * local value. */
6352 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6353 {
6354 free_string_option(curbuf->b_p_cm);
6355 curbuf->b_p_cm = empty_option;
6356 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006357
6358 /* Need to update the swapfile when the effective method changed.
6359 * Set "s" to the effective old value, "p" to the effective new
6360 * method and compare. */
6361 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6362 s = p_cm; /* was previously using the global value */
6363 else
6364 s = oldval;
6365 if (*curbuf->b_p_cm == NUL)
6366 p = p_cm; /* is now using the global value */
6367 else
6368 p = curbuf->b_p_cm;
6369 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006370 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006371
6372 /* If the global value changes need to update the swapfile for all
6373 * buffers using that value. */
6374 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6375 {
6376 buf_T *buf;
6377
6378 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6379 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006380 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006381 }
6382 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 }
6384#endif
6385
6386 /* 'matchpairs' */
6387 else if (gvarp == &p_mps)
6388 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006389#ifdef FEAT_MBYTE
6390 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006391 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006392 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006393 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006394 int x2 = -1;
6395 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006396
6397 if (*p != NUL)
6398 p += mb_ptr2len(p);
6399 if (*p != NUL)
6400 x2 = *p++;
6401 if (*p != NUL)
6402 {
6403 x3 = mb_ptr2char(p);
6404 p += mb_ptr2len(p);
6405 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006406 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006407 {
6408 errmsg = e_invarg;
6409 break;
6410 }
6411 if (*p == NUL)
6412 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006413 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006414 }
6415 else
6416#endif
6417 {
6418 /* Check for "x:y,x:y" */
6419 for (p = *varp; *p != NUL; p += 4)
6420 {
6421 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6422 {
6423 errmsg = e_invarg;
6424 break;
6425 }
6426 if (p[3] == NUL)
6427 break;
6428 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006429 }
6430 }
6431
6432#ifdef FEAT_COMMENTS
6433 /* 'comments' */
6434 else if (gvarp == &p_com)
6435 {
6436 for (s = *varp; *s; )
6437 {
6438 while (*s && *s != ':')
6439 {
6440 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6441 && !VIM_ISDIGIT(*s) && *s != '-')
6442 {
6443 errmsg = illegal_char(errbuf, *s);
6444 break;
6445 }
6446 ++s;
6447 }
6448 if (*s++ == NUL)
6449 errmsg = (char_u *)N_("E524: Missing colon");
6450 else if (*s == ',' || *s == NUL)
6451 errmsg = (char_u *)N_("E525: Zero length string");
6452 if (errmsg != NULL)
6453 break;
6454 while (*s && *s != ',')
6455 {
6456 if (*s == '\\' && s[1] != NUL)
6457 ++s;
6458 ++s;
6459 }
6460 s = skip_to_option_part(s);
6461 }
6462 }
6463#endif
6464
6465 /* 'listchars' */
6466 else if (varp == &p_lcs)
6467 {
6468 errmsg = set_chars_option(varp);
6469 }
6470
6471#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6472 /* 'fillchars' */
6473 else if (varp == &p_fcs)
6474 {
6475 errmsg = set_chars_option(varp);
6476 }
6477#endif
6478
6479#ifdef FEAT_CMDWIN
6480 /* 'cedit' */
6481 else if (varp == &p_cedit)
6482 {
6483 errmsg = check_cedit();
6484 }
6485#endif
6486
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006487 /* 'verbosefile' */
6488 else if (varp == &p_vfile)
6489 {
6490 verbose_stop();
6491 if (*p_vfile != NUL && verbose_open() == FAIL)
6492 errmsg = e_invarg;
6493 }
6494
Bram Moolenaar071d4272004-06-13 20:20:40 +00006495#ifdef FEAT_VIMINFO
6496 /* 'viminfo' */
6497 else if (varp == &p_viminfo)
6498 {
6499 for (s = p_viminfo; *s;)
6500 {
6501 /* Check it's a valid character */
6502 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6503 {
6504 errmsg = illegal_char(errbuf, *s);
6505 break;
6506 }
6507 if (*s == 'n') /* name is always last one */
6508 {
6509 break;
6510 }
6511 else if (*s == 'r') /* skip until next ',' */
6512 {
6513 while (*++s && *s != ',')
6514 ;
6515 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006516 else if (*s == '%')
6517 {
6518 /* optional number */
6519 while (vim_isdigit(*++s))
6520 ;
6521 }
6522 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006523 ++s; /* no extra chars */
6524 else /* must have a number */
6525 {
6526 while (vim_isdigit(*++s))
6527 ;
6528
6529 if (!VIM_ISDIGIT(*(s - 1)))
6530 {
6531 if (errbuf != NULL)
6532 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006533 sprintf((char *)errbuf,
6534 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006535 transchar_byte(*(s - 1)));
6536 errmsg = errbuf;
6537 }
6538 else
6539 errmsg = (char_u *)"";
6540 break;
6541 }
6542 }
6543 if (*s == ',')
6544 ++s;
6545 else if (*s)
6546 {
6547 if (errbuf != NULL)
6548 errmsg = (char_u *)N_("E527: Missing comma");
6549 else
6550 errmsg = (char_u *)"";
6551 break;
6552 }
6553 }
6554 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6555 errmsg = (char_u *)N_("E528: Must specify a ' value");
6556 }
6557#endif /* FEAT_VIMINFO */
6558
6559 /* terminal options */
6560 else if (istermoption(&options[opt_idx]) && full_screen)
6561 {
6562 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6563 if (varp == &T_CCO)
6564 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006565 int colors = atoi((char *)T_CCO);
6566
6567 /* Only reinitialize colors if t_Co value has really changed to
6568 * avoid expensive reload of colorscheme if t_Co is set to the
6569 * same value multiple times. */
6570 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006571 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006572 t_colors = colors;
6573 if (t_colors <= 1)
6574 {
6575 if (new_value_alloced)
6576 vim_free(T_CCO);
6577 T_CCO = empty_option;
6578 }
6579 /* We now have a different color setup, initialize it again. */
6580 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 }
6583 ttest(FALSE);
6584 if (varp == &T_ME)
6585 {
6586 out_str(T_ME);
6587 redraw_later(CLEAR);
6588#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6589 /* Since t_me has been set, this probably means that the user
6590 * wants to use this as default colors. Need to reset default
6591 * background/foreground colors. */
6592 mch_set_normal_colors();
6593#endif
6594 }
6595 }
6596
6597#ifdef FEAT_LINEBREAK
6598 /* 'showbreak' */
6599 else if (varp == &p_sbr)
6600 {
6601 for (s = p_sbr; *s; )
6602 {
6603 if (ptr2cells(s) != 1)
6604 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006605 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606 }
6607 }
6608#endif
6609
6610#ifdef FEAT_GUI
6611 /* 'guifont' */
6612 else if (varp == &p_guifont)
6613 {
6614 if (gui.in_use)
6615 {
6616 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006617# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 /*
6619 * Put up a font dialog and let the user select a new value.
6620 * If this is cancelled go back to the old value but don't
6621 * give an error message.
6622 */
6623 if (STRCMP(p, "*") == 0)
6624 {
6625 p = gui_mch_font_dialog(oldval);
6626
6627 if (new_value_alloced)
6628 free_string_option(p_guifont);
6629
6630 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6631 new_value_alloced = TRUE;
6632 }
6633# endif
6634 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6635 {
6636# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6637 if (STRCMP(p_guifont, "*") == 0)
6638 {
6639 /* Dialog was cancelled: Keep the old value without giving
6640 * an error message. */
6641 if (new_value_alloced)
6642 free_string_option(p_guifont);
6643 p_guifont = vim_strsave(oldval);
6644 new_value_alloced = TRUE;
6645 }
6646 else
6647# endif
6648 errmsg = (char_u *)N_("E596: Invalid font(s)");
6649 }
6650 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006651 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006652 }
6653# ifdef FEAT_XFONTSET
6654 else if (varp == &p_guifontset)
6655 {
6656 if (STRCMP(p_guifontset, "*") == 0)
6657 errmsg = (char_u *)N_("E597: can't select fontset");
6658 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6659 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006660 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006661 }
6662# endif
6663# ifdef FEAT_MBYTE
6664 else if (varp == &p_guifontwide)
6665 {
6666 if (STRCMP(p_guifontwide, "*") == 0)
6667 errmsg = (char_u *)N_("E533: can't select wide font");
6668 else if (gui_get_wide_font() == FAIL)
6669 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006670 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006671 }
6672# endif
6673#endif
6674
6675#ifdef CURSOR_SHAPE
6676 /* 'guicursor' */
6677 else if (varp == &p_guicursor)
6678 errmsg = parse_shape_opt(SHAPE_CURSOR);
6679#endif
6680
6681#ifdef FEAT_MOUSESHAPE
6682 /* 'mouseshape' */
6683 else if (varp == &p_mouseshape)
6684 {
6685 errmsg = parse_shape_opt(SHAPE_MOUSE);
6686 update_mouseshape(-1);
6687 }
6688#endif
6689
6690#ifdef FEAT_PRINTER
6691 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006692 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006693# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006694 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006695 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006696# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006697#endif
6698
6699#ifdef FEAT_LANGMAP
6700 /* 'langmap' */
6701 else if (varp == &p_langmap)
6702 langmap_set();
6703#endif
6704
6705#ifdef FEAT_LINEBREAK
6706 /* 'breakat' */
6707 else if (varp == &p_breakat)
6708 fill_breakat_flags();
6709#endif
6710
6711#ifdef FEAT_TITLE
6712 /* 'titlestring' and 'iconstring' */
6713 else if (varp == &p_titlestring || varp == &p_iconstring)
6714 {
6715# ifdef FEAT_STL_OPT
6716 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6717
6718 /* NULL => statusline syntax */
6719 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6720 stl_syntax |= flagval;
6721 else
6722 stl_syntax &= ~flagval;
6723# endif
6724 did_set_title(varp == &p_iconstring);
6725
6726 }
6727#endif
6728
6729#ifdef FEAT_GUI
6730 /* 'guioptions' */
6731 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006732 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006733 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006734 redraw_gui_only = TRUE;
6735 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006736#endif
6737
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006738#if defined(FEAT_GUI_TABLINE)
6739 /* 'guitablabel' */
6740 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006741 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006742 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006743 redraw_gui_only = TRUE;
6744 }
6745 /* 'guitabtooltip' */
6746 else if (varp == &p_gtt)
6747 {
6748 redraw_gui_only = TRUE;
6749 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006750#endif
6751
Bram Moolenaar071d4272004-06-13 20:20:40 +00006752#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6753 /* 'ttymouse' */
6754 else if (varp == &p_ttym)
6755 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006756 /* Switch the mouse off before changing the escape sequences used for
6757 * that. */
6758 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006759 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6760 errmsg = e_invarg;
6761 else
6762 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006763 if (termcap_active)
6764 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765 }
6766#endif
6767
Bram Moolenaar071d4272004-06-13 20:20:40 +00006768 /* 'selection' */
6769 else if (varp == &p_sel)
6770 {
6771 if (*p_sel == NUL
6772 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6773 errmsg = e_invarg;
6774 }
6775
6776 /* 'selectmode' */
6777 else if (varp == &p_slm)
6778 {
6779 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6780 errmsg = e_invarg;
6781 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006782
6783#ifdef FEAT_BROWSE
6784 /* 'browsedir' */
6785 else if (varp == &p_bsdir)
6786 {
6787 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6788 && !mch_isdir(p_bsdir))
6789 errmsg = e_invarg;
6790 }
6791#endif
6792
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 /* 'keymodel' */
6794 else if (varp == &p_km)
6795 {
6796 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6797 errmsg = e_invarg;
6798 else
6799 {
6800 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6801 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6802 }
6803 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006804
6805 /* 'mousemodel' */
6806 else if (varp == &p_mousem)
6807 {
6808 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6809 errmsg = e_invarg;
6810#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6811 else if (*p_mousem != *oldval)
6812 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6813 * to create or delete the popup menus. */
6814 gui_motif_update_mousemodel(root_menu);
6815#endif
6816 }
6817
6818 /* 'switchbuf' */
6819 else if (varp == &p_swb)
6820 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006821 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006822 errmsg = e_invarg;
6823 }
6824
6825 /* 'debug' */
6826 else if (varp == &p_debug)
6827 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006828 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829 errmsg = e_invarg;
6830 }
6831
6832 /* 'display' */
6833 else if (varp == &p_dy)
6834 {
6835 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6836 errmsg = e_invarg;
6837 else
6838 (void)init_chartab();
6839
6840 }
6841
6842#ifdef FEAT_VERTSPLIT
6843 /* 'eadirection' */
6844 else if (varp == &p_ead)
6845 {
6846 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6847 errmsg = e_invarg;
6848 }
6849#endif
6850
6851#ifdef FEAT_CLIPBOARD
6852 /* 'clipboard' */
6853 else if (varp == &p_cb)
6854 errmsg = check_clipboard_option();
6855#endif
6856
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006857#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006858 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6859 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006860 else if (varp == &(curwin->w_s->b_p_spl)
6861 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006862 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006863 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006864 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006865 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006866 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006867 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006868 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006869 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006870 /* 'spellsuggest' */
6871 else if (varp == &p_sps)
6872 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006873 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006874 errmsg = e_invarg;
6875 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006876 /* 'mkspellmem' */
6877 else if (varp == &p_msm)
6878 {
6879 if (spell_check_msm() != OK)
6880 errmsg = e_invarg;
6881 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006882#endif
6883
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884#ifdef FEAT_QUICKFIX
6885 /* When 'bufhidden' is set, check for valid value. */
6886 else if (gvarp == &p_bh)
6887 {
6888 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6889 errmsg = e_invarg;
6890 }
6891
6892 /* When 'buftype' is set, check for valid value. */
6893 else if (gvarp == &p_bt)
6894 {
6895 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6896 errmsg = e_invarg;
6897 else
6898 {
6899# ifdef FEAT_WINDOWS
6900 if (curwin->w_status_height)
6901 {
6902 curwin->w_redr_status = TRUE;
6903 redraw_later(VALID);
6904 }
6905# endif
6906 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006907# ifdef FEAT_TITLE
6908 redraw_titles();
6909# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 }
6911 }
6912#endif
6913
6914#ifdef FEAT_STL_OPT
6915 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006916 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917 {
6918 int wid;
6919
6920 if (varp == &p_ruf) /* reset ru_wid first */
6921 ru_wid = 0;
6922 s = *varp;
6923 if (varp == &p_ruf && *s == '%')
6924 {
6925 /* set ru_wid if 'ruf' starts with "%99(" */
6926 if (*++s == '-') /* ignore a '-' */
6927 s++;
6928 wid = getdigits(&s);
6929 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6930 ru_wid = wid;
6931 else
6932 errmsg = check_stl_option(p_ruf);
6933 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006934 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006935 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006936 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006937 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006938 comp_col();
6939 }
6940#endif
6941
6942#ifdef FEAT_INS_EXPAND
6943 /* check if it is a valid value for 'complete' -- Acevedo */
6944 else if (gvarp == &p_cpt)
6945 {
6946 for (s = *varp; *s;)
6947 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006948 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006949 s++;
6950 if (!*s)
6951 break;
6952 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6953 {
6954 errmsg = illegal_char(errbuf, *s);
6955 break;
6956 }
6957 if (*++s != NUL && *s != ',' && *s != ' ')
6958 {
6959 if (s[-1] == 'k' || s[-1] == 's')
6960 {
6961 /* skip optional filename after 'k' and 's' */
6962 while (*s && *s != ',' && *s != ' ')
6963 {
6964 if (*s == '\\')
6965 ++s;
6966 ++s;
6967 }
6968 }
6969 else
6970 {
6971 if (errbuf != NULL)
6972 {
6973 sprintf((char *)errbuf,
6974 _("E535: Illegal character after <%c>"),
6975 *--s);
6976 errmsg = errbuf;
6977 }
6978 else
6979 errmsg = (char_u *)"";
6980 break;
6981 }
6982 }
6983 }
6984 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006985
6986 /* 'completeopt' */
6987 else if (varp == &p_cot)
6988 {
6989 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6990 errmsg = e_invarg;
6991 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992#endif /* FEAT_INS_EXPAND */
6993
6994
6995#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6996 else if (varp == &p_toolbar)
6997 {
6998 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6999 &toolbar_flags, TRUE) != OK)
7000 errmsg = e_invarg;
7001 else
7002 {
7003 out_flush();
7004 gui_mch_show_toolbar((toolbar_flags &
7005 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7006 }
7007 }
7008#endif
7009
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007010#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007011 /* 'toolbariconsize': GTK+ 2 only */
7012 else if (varp == &p_tbis)
7013 {
7014 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7015 errmsg = e_invarg;
7016 else
7017 {
7018 out_flush();
7019 gui_mch_show_toolbar((toolbar_flags &
7020 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7021 }
7022 }
7023#endif
7024
7025 /* 'pastetoggle': translate key codes like in a mapping */
7026 else if (varp == &p_pt)
7027 {
7028 if (*p_pt)
7029 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007030 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007031 if (p != NULL)
7032 {
7033 if (new_value_alloced)
7034 free_string_option(p_pt);
7035 p_pt = p;
7036 new_value_alloced = TRUE;
7037 }
7038 }
7039 }
7040
7041 /* 'backspace' */
7042 else if (varp == &p_bs)
7043 {
7044 if (VIM_ISDIGIT(*p_bs))
7045 {
7046 if (*p_bs >'2' || p_bs[1] != NUL)
7047 errmsg = e_invarg;
7048 }
7049 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7050 errmsg = e_invarg;
7051 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007052 else if (varp == &p_bo)
7053 {
7054 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7055 errmsg = e_invarg;
7056 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007057
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007058 /* 'tagcase' */
7059 else if (gvarp == &p_tc)
7060 {
7061 unsigned int *flags;
7062
7063 if (opt_flags & OPT_LOCAL)
7064 {
7065 p = curbuf->b_p_tc;
7066 flags = &curbuf->b_tc_flags;
7067 }
7068 else
7069 {
7070 p = p_tc;
7071 flags = &tc_flags;
7072 }
7073
7074 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7075 /* make the local value empty: use the global value */
7076 *flags = 0;
7077 else if (*p == NUL
7078 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7079 errmsg = e_invarg;
7080 }
7081
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007082#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007083 /* 'casemap' */
7084 else if (varp == &p_cmp)
7085 {
7086 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7087 errmsg = e_invarg;
7088 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007089#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007090
7091#ifdef FEAT_DIFF
7092 /* 'diffopt' */
7093 else if (varp == &p_dip)
7094 {
7095 if (diffopt_changed() == FAIL)
7096 errmsg = e_invarg;
7097 }
7098#endif
7099
7100#ifdef FEAT_FOLDING
7101 /* 'foldmethod' */
7102 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7103 {
7104 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7105 || *curwin->w_p_fdm == NUL)
7106 errmsg = e_invarg;
7107 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007108 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007109 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007110 if (foldmethodIsDiff(curwin))
7111 newFoldLevel();
7112 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007113 }
7114# ifdef FEAT_EVAL
7115 /* 'foldexpr' */
7116 else if (varp == &curwin->w_p_fde)
7117 {
7118 if (foldmethodIsExpr(curwin))
7119 foldUpdateAll(curwin);
7120 }
7121# endif
7122 /* 'foldmarker' */
7123 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7124 {
7125 p = vim_strchr(*varp, ',');
7126 if (p == NULL)
7127 errmsg = (char_u *)N_("E536: comma required");
7128 else if (p == *varp || p[1] == NUL)
7129 errmsg = e_invarg;
7130 else if (foldmethodIsMarker(curwin))
7131 foldUpdateAll(curwin);
7132 }
7133 /* 'commentstring' */
7134 else if (gvarp == &p_cms)
7135 {
7136 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7137 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7138 }
7139 /* 'foldopen' */
7140 else if (varp == &p_fdo)
7141 {
7142 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7143 errmsg = e_invarg;
7144 }
7145 /* 'foldclose' */
7146 else if (varp == &p_fcl)
7147 {
7148 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7149 errmsg = e_invarg;
7150 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007151 /* 'foldignore' */
7152 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7153 {
7154 if (foldmethodIsIndent(curwin))
7155 foldUpdateAll(curwin);
7156 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007157#endif
7158
7159#ifdef FEAT_VIRTUALEDIT
7160 /* 'virtualedit' */
7161 else if (varp == &p_ve)
7162 {
7163 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7164 errmsg = e_invarg;
7165 else if (STRCMP(p_ve, oldval) != 0)
7166 {
7167 /* Recompute cursor position in case the new 've' setting
7168 * changes something. */
7169 validate_virtcol();
7170 coladvance(curwin->w_virtcol);
7171 }
7172 }
7173#endif
7174
7175#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7176 else if (varp == &p_csqf)
7177 {
7178 if (p_csqf != NULL)
7179 {
7180 p = p_csqf;
7181 while (*p != NUL)
7182 {
7183 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7184 || p[1] == NUL
7185 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7186 || (p[2] != NUL && p[2] != ','))
7187 {
7188 errmsg = e_invarg;
7189 break;
7190 }
7191 else if (p[2] == NUL)
7192 break;
7193 else
7194 p += 3;
7195 }
7196 }
7197 }
7198#endif
7199
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007200#ifdef FEAT_CINDENT
7201 /* 'cinoptions' */
7202 else if (gvarp == &p_cino)
7203 {
7204 /* TODO: recognize errors */
7205 parse_cino(curbuf);
7206 }
7207#endif
7208
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007209#if defined(FEAT_RENDER_OPTIONS)
7210 else if (varp == &p_rop && gui.in_use)
7211 {
7212 if (!gui_mch_set_rendering_options(p_rop))
7213 errmsg = e_invarg;
7214 }
7215#endif
7216
Bram Moolenaar071d4272004-06-13 20:20:40 +00007217 /* Options that are a list of flags. */
7218 else
7219 {
7220 p = NULL;
7221 if (varp == &p_ww)
7222 p = (char_u *)WW_ALL;
7223 if (varp == &p_shm)
7224 p = (char_u *)SHM_ALL;
7225 else if (varp == &(p_cpo))
7226 p = (char_u *)CPO_ALL;
7227 else if (varp == &(curbuf->b_p_fo))
7228 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007229#ifdef FEAT_CONCEAL
7230 else if (varp == &curwin->w_p_cocu)
7231 p = (char_u *)COCU_ALL;
7232#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007233 else if (varp == &p_mouse)
7234 {
7235#ifdef FEAT_MOUSE
7236 p = (char_u *)MOUSE_ALL;
7237#else
7238 if (*p_mouse != NUL)
7239 errmsg = (char_u *)N_("E538: No mouse support");
7240#endif
7241 }
7242#if defined(FEAT_GUI)
7243 else if (varp == &p_go)
7244 p = (char_u *)GO_ALL;
7245#endif
7246 if (p != NULL)
7247 {
7248 for (s = *varp; *s; ++s)
7249 if (vim_strchr(p, *s) == NULL)
7250 {
7251 errmsg = illegal_char(errbuf, *s);
7252 break;
7253 }
7254 }
7255 }
7256
7257 /*
7258 * If error detected, restore the previous value.
7259 */
7260 if (errmsg != NULL)
7261 {
7262 if (new_value_alloced)
7263 free_string_option(*varp);
7264 *varp = oldval;
7265 /*
7266 * When resetting some values, need to act on it.
7267 */
7268 if (did_chartab)
7269 (void)init_chartab();
7270 if (varp == &p_hl)
7271 (void)highlight_changed();
7272 }
7273 else
7274 {
7275#ifdef FEAT_EVAL
7276 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007277 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007278#endif
7279 /*
7280 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007281 * Use "free_oldval", because recursiveness may change the flags under
7282 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007283 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007284 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285 free_string_option(oldval);
7286 if (new_value_alloced)
7287 options[opt_idx].flags |= P_ALLOCED;
7288 else
7289 options[opt_idx].flags &= ~P_ALLOCED;
7290
7291 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007292 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007293 {
7294 /* global option with local value set to use global value; free
7295 * the local value and make it empty */
7296 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7297 free_string_option(*(char_u **)p);
7298 *(char_u **)p = empty_option;
7299 }
7300
7301 /* May set global value for local option. */
7302 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7303 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007304
7305#ifdef FEAT_AUTOCMD
7306 /*
7307 * Trigger the autocommand only after setting the flags.
7308 */
7309# ifdef FEAT_SYN_HL
7310 /* When 'syntax' is set, load the syntax of that name */
7311 if (varp == &(curbuf->b_p_syn))
7312 {
7313 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7314 curbuf->b_fname, TRUE, curbuf);
7315 }
7316# endif
7317 else if (varp == &(curbuf->b_p_ft))
7318 {
7319 /* 'filetype' is set, trigger the FileType autocommand */
7320 did_filetype = TRUE;
7321 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7322 curbuf->b_fname, TRUE, curbuf);
7323 }
7324#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007325#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007326 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007327 {
7328 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007329 char_u *q = curwin->w_s->b_p_spl;
7330
7331 /* Skip the first name if it is "cjk". */
7332 if (STRNCMP(q, "cjk,", 4) == 0)
7333 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007334
7335 /*
7336 * Source the spell/LANG.vim in 'runtimepath'.
7337 * They could set 'spellcapcheck' depending on the language.
7338 * Use the first name in 'spelllang' up to '_region' or
7339 * '.encoding'.
7340 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007341 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007342 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7343 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007344 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007345 source_runtime(fname, TRUE);
7346 }
7347#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007348 }
7349
7350#ifdef FEAT_MOUSE
7351 if (varp == &p_mouse)
7352 {
7353# ifdef FEAT_MOUSE_TTY
7354 if (*p_mouse == NUL)
7355 mch_setmouse(FALSE); /* switch mouse off */
7356 else
7357# endif
7358 setmouse(); /* in case 'mouse' changed */
7359 }
7360#endif
7361
Bram Moolenaar913077c2012-03-28 19:59:04 +02007362 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007363 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007364 curwin->w_set_curswant = TRUE;
7365
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007366#ifdef FEAT_GUI
7367 /* check redraw when it's not a GUI option or the GUI is active. */
7368 if (!redraw_gui_only || gui.in_use)
7369#endif
7370 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007371
7372 return errmsg;
7373}
7374
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007375#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007376/*
7377 * Simple int comparison function for use with qsort()
7378 */
7379 static int
7380int_cmp(a, b)
7381 const void *a;
7382 const void *b;
7383{
7384 return *(const int *)a - *(const int *)b;
7385}
7386
7387/*
7388 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7389 * Returns error message, NULL if it's OK.
7390 */
7391 char_u *
7392check_colorcolumn(wp)
7393 win_T *wp;
7394{
7395 char_u *s;
7396 int col;
7397 int count = 0;
7398 int color_cols[256];
7399 int i;
7400 int j = 0;
7401
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007402 if (wp->w_buffer == NULL)
7403 return NULL; /* buffer was closed */
7404
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007405 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007406 {
7407 if (*s == '-' || *s == '+')
7408 {
7409 /* -N and +N: add to 'textwidth' */
7410 col = (*s == '-') ? -1 : 1;
7411 ++s;
7412 if (!VIM_ISDIGIT(*s))
7413 return e_invarg;
7414 col = col * getdigits(&s);
7415 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007416 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007417 col += wp->w_buffer->b_p_tw;
7418 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007419 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007420 }
7421 else if (VIM_ISDIGIT(*s))
7422 col = getdigits(&s);
7423 else
7424 return e_invarg;
7425 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007426skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007427 if (*s == NUL)
7428 break;
7429 if (*s != ',')
7430 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007431 if (*++s == NUL)
7432 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007433 }
7434
7435 vim_free(wp->w_p_cc_cols);
7436 if (count == 0)
7437 wp->w_p_cc_cols = NULL;
7438 else
7439 {
7440 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7441 if (wp->w_p_cc_cols != NULL)
7442 {
7443 /* sort the columns for faster usage on screen redraw inside
7444 * win_line() */
7445 qsort(color_cols, count, sizeof(int), int_cmp);
7446
7447 for (i = 0; i < count; ++i)
7448 /* skip duplicates */
7449 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7450 wp->w_p_cc_cols[j++] = color_cols[i];
7451 wp->w_p_cc_cols[j] = -1; /* end marker */
7452 }
7453 }
7454
7455 return NULL; /* no error */
7456}
7457#endif
7458
Bram Moolenaar071d4272004-06-13 20:20:40 +00007459/*
7460 * Handle setting 'listchars' or 'fillchars'.
7461 * Returns error message, NULL if it's OK.
7462 */
7463 static char_u *
7464set_chars_option(varp)
7465 char_u **varp;
7466{
7467 int round, i, len, entries;
7468 char_u *p, *s;
7469 int c1, c2 = 0;
7470 struct charstab
7471 {
7472 int *cp;
7473 char *name;
7474 };
7475#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7476 static struct charstab filltab[] =
7477 {
7478 {&fill_stl, "stl"},
7479 {&fill_stlnc, "stlnc"},
7480 {&fill_vert, "vert"},
7481 {&fill_fold, "fold"},
7482 {&fill_diff, "diff"},
7483 };
7484#endif
7485 static struct charstab lcstab[] =
7486 {
7487 {&lcs_eol, "eol"},
7488 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007489 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007490 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007491 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007492 {&lcs_tab2, "tab"},
7493 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007494#ifdef FEAT_CONCEAL
7495 {&lcs_conceal, "conceal"},
7496#else
7497 {NULL, "conceal"},
7498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007499 };
7500 struct charstab *tab;
7501
7502#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7503 if (varp == &p_lcs)
7504#endif
7505 {
7506 tab = lcstab;
7507 entries = sizeof(lcstab) / sizeof(struct charstab);
7508 }
7509#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7510 else
7511 {
7512 tab = filltab;
7513 entries = sizeof(filltab) / sizeof(struct charstab);
7514 }
7515#endif
7516
7517 /* first round: check for valid value, second round: assign values */
7518 for (round = 0; round <= 1; ++round)
7519 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007520 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521 {
7522 /* After checking that the value is valid: set defaults: space for
7523 * 'fillchars', NUL for 'listchars' */
7524 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007525 if (tab[i].cp != NULL)
7526 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527 if (varp == &p_lcs)
7528 lcs_tab1 = NUL;
7529#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7530 else
7531 fill_diff = '-';
7532#endif
7533 }
7534 p = *varp;
7535 while (*p)
7536 {
7537 for (i = 0; i < entries; ++i)
7538 {
7539 len = (int)STRLEN(tab[i].name);
7540 if (STRNCMP(p, tab[i].name, len) == 0
7541 && p[len] == ':'
7542 && p[len + 1] != NUL)
7543 {
7544 s = p + len + 1;
7545#ifdef FEAT_MBYTE
7546 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007547 if (mb_char2cells(c1) > 1)
7548 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007549#else
7550 c1 = *s++;
7551#endif
7552 if (tab[i].cp == &lcs_tab2)
7553 {
7554 if (*s == NUL)
7555 continue;
7556#ifdef FEAT_MBYTE
7557 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007558 if (mb_char2cells(c2) > 1)
7559 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007560#else
7561 c2 = *s++;
7562#endif
7563 }
7564 if (*s == ',' || *s == NUL)
7565 {
7566 if (round)
7567 {
7568 if (tab[i].cp == &lcs_tab2)
7569 {
7570 lcs_tab1 = c1;
7571 lcs_tab2 = c2;
7572 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007573 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007574 *(tab[i].cp) = c1;
7575
7576 }
7577 p = s;
7578 break;
7579 }
7580 }
7581 }
7582
7583 if (i == entries)
7584 return e_invarg;
7585 if (*p == ',')
7586 ++p;
7587 }
7588 }
7589
7590 return NULL; /* no error */
7591}
7592
7593#ifdef FEAT_STL_OPT
7594/*
7595 * Check validity of options with the 'statusline' format.
7596 * Return error message or NULL.
7597 */
7598 char_u *
7599check_stl_option(s)
7600 char_u *s;
7601{
7602 int itemcnt = 0;
7603 int groupdepth = 0;
7604 static char_u errbuf[80];
7605
7606 while (*s && itemcnt < STL_MAX_ITEM)
7607 {
7608 /* Check for valid keys after % sequences */
7609 while (*s && *s != '%')
7610 s++;
7611 if (!*s)
7612 break;
7613 s++;
7614 if (*s != '%' && *s != ')')
7615 ++itemcnt;
7616 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7617 {
7618 s++;
7619 continue;
7620 }
7621 if (*s == ')')
7622 {
7623 s++;
7624 if (--groupdepth < 0)
7625 break;
7626 continue;
7627 }
7628 if (*s == '-')
7629 s++;
7630 while (VIM_ISDIGIT(*s))
7631 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007632 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007633 continue;
7634 if (*s == '.')
7635 {
7636 s++;
7637 while (*s && VIM_ISDIGIT(*s))
7638 s++;
7639 }
7640 if (*s == '(')
7641 {
7642 groupdepth++;
7643 continue;
7644 }
7645 if (vim_strchr(STL_ALL, *s) == NULL)
7646 {
7647 return illegal_char(errbuf, *s);
7648 }
7649 if (*s == '{')
7650 {
7651 s++;
7652 while (*s != '}' && *s)
7653 s++;
7654 if (*s != '}')
7655 return (char_u *)N_("E540: Unclosed expression sequence");
7656 }
7657 }
7658 if (itemcnt >= STL_MAX_ITEM)
7659 return (char_u *)N_("E541: too many items");
7660 if (groupdepth != 0)
7661 return (char_u *)N_("E542: unbalanced groups");
7662 return NULL;
7663}
7664#endif
7665
7666#ifdef FEAT_CLIPBOARD
7667/*
7668 * Extract the items in the 'clipboard' option and set global values.
7669 */
7670 static char_u *
7671check_clipboard_option()
7672{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007673 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007674 int new_autoselect_star = FALSE;
7675 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007676 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007677 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007678 regprog_T *new_exclude_prog = NULL;
7679 char_u *errmsg = NULL;
7680 char_u *p;
7681
7682 for (p = p_cb; *p != NUL; )
7683 {
7684 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7685 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007686 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007687 p += 7;
7688 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007689 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007690 && (p[11] == ',' || p[11] == NUL))
7691 {
7692 new_unnamed |= CLIP_UNNAMED_PLUS;
7693 p += 11;
7694 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007695 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007696 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007697 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007698 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007699 p += 10;
7700 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007701 else if (STRNCMP(p, "autoselectplus", 14) == 0
7702 && (p[14] == ',' || p[14] == NUL))
7703 {
7704 new_autoselect_plus = TRUE;
7705 p += 14;
7706 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007707 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007708 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007709 {
7710 new_autoselectml = TRUE;
7711 p += 12;
7712 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007713 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7714 {
7715 new_html = TRUE;
7716 p += 4;
7717 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007718 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7719 {
7720 p += 8;
7721 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7722 if (new_exclude_prog == NULL)
7723 errmsg = e_invarg;
7724 break;
7725 }
7726 else
7727 {
7728 errmsg = e_invarg;
7729 break;
7730 }
7731 if (*p == ',')
7732 ++p;
7733 }
7734 if (errmsg == NULL)
7735 {
7736 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007737 clip_autoselect_star = new_autoselect_star;
7738 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007739 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007740 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007741 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007742 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007743#ifdef FEAT_GUI_GTK
7744 if (gui.in_use)
7745 {
7746 gui_gtk_set_selection_targets();
7747 gui_gtk_set_dnd_targets();
7748 }
7749#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 }
7751 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007752 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007753
7754 return errmsg;
7755}
7756#endif
7757
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007758#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007759 static char_u *
7760did_set_spell_option(is_spellfile)
7761 int is_spellfile;
7762{
7763 char_u *errmsg = NULL;
7764 win_T *wp;
7765 int l;
7766
7767 if (is_spellfile)
7768 {
7769 l = (int)STRLEN(curwin->w_s->b_p_spf);
7770 if (l > 0 && (l < 4
7771 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7772 errmsg = e_invarg;
7773 }
7774
7775 if (errmsg == NULL)
7776 {
7777 FOR_ALL_WINDOWS(wp)
7778 if (wp->w_buffer == curbuf && wp->w_p_spell)
7779 {
7780 errmsg = did_set_spelllang(wp);
7781# ifdef FEAT_WINDOWS
7782 break;
7783# endif
7784 }
7785 }
7786 return errmsg;
7787}
7788
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007789/*
7790 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7791 * Return error message when failed, NULL when OK.
7792 */
7793 static char_u *
Bram Moolenaar860cae12010-06-05 23:22:07 +02007794compile_cap_prog(synblock)
7795 synblock_T *synblock;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007796{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007797 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007798 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007799
Bram Moolenaar860cae12010-06-05 23:22:07 +02007800 if (*synblock->b_p_spc == NUL)
7801 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007802 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007803 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007804 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007805 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007806 if (re != NULL)
7807 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007808 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007809 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007810 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007811 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007812 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007813 return e_invarg;
7814 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007815 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007816 }
7817
Bram Moolenaar473de612013-06-08 18:19:48 +02007818 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007819 return NULL;
7820}
7821#endif
7822
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007823#if defined(FEAT_EVAL) || defined(PROTO)
7824/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007825 * Set the scriptID for an option, taking care of setting the buffer- or
7826 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007827 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007828 static void
7829set_option_scriptID_idx(opt_idx, opt_flags, id)
7830 int opt_idx;
7831 int opt_flags;
7832 int id;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007833{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007834 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7835 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007836
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007837 /* Remember where the option was set. For local options need to do that
7838 * in the buffer or window structure. */
7839 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007840 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007841 if (both || (opt_flags & OPT_LOCAL))
7842 {
7843 if (indir & PV_BUF)
7844 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7845 else if (indir & PV_WIN)
7846 curwin->w_p_scriptID[indir & PV_MASK] = id;
7847 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007848}
7849#endif
7850
Bram Moolenaar071d4272004-06-13 20:20:40 +00007851/*
7852 * Set the value of a boolean option, and take care of side effects.
7853 * Returns NULL for success, or an error message for an error.
7854 */
7855 static char_u *
7856set_bool_option(opt_idx, varp, value, opt_flags)
7857 int opt_idx; /* index in options[] table */
7858 char_u *varp; /* pointer to the option variable */
7859 int value; /* new value */
7860 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
7861{
7862 int old_value = *(int *)varp;
7863
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864 /* Disallow changing some options from secure mode */
7865 if ((secure
7866#ifdef HAVE_SANDBOX
7867 || sandbox != 0
7868#endif
7869 ) && (options[opt_idx].flags & P_SECURE))
7870 return e_secure;
7871
7872 *(int *)varp = value; /* set the new value */
7873#ifdef FEAT_EVAL
7874 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007875 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007876#endif
7877
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007878#ifdef FEAT_GUI
7879 need_mouse_correct = TRUE;
7880#endif
7881
Bram Moolenaar071d4272004-06-13 20:20:40 +00007882 /* May set global value for local option. */
7883 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7884 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7885
7886 /*
7887 * Handle side effects of changing a bool option.
7888 */
7889
7890 /* 'compatible' */
7891 if ((int *)varp == &p_cp)
7892 {
7893 compatible_set();
7894 }
7895
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007896#ifdef FEAT_PERSISTENT_UNDO
7897 /* 'undofile' */
7898 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7899 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007900 /* Only take action when the option was set. When reset we do not
7901 * delete the undo file, the option may be set again without making
7902 * any changes in between. */
7903 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007904 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007905 char_u hash[UNDO_HASH_SIZE];
7906 buf_T *save_curbuf = curbuf;
7907
7908 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007909 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007910 /* When 'undofile' is set globally: for every buffer, otherwise
7911 * only for the current buffer: Try to read in the undofile,
7912 * if one exists, the buffer wasn't changed and the buffer was
7913 * loaded */
7914 if ((curbuf == save_curbuf
7915 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7916 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7917 {
7918 u_compute_hash(hash);
7919 u_read_undo(NULL, hash, curbuf->b_fname);
7920 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007921 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007922 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007923 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007924 }
7925#endif
7926
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927 else if ((int *)varp == &curbuf->b_p_ro)
7928 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007929 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007930 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7931 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007932
7933 /* when 'readonly' is set may give W10 again */
7934 if (curbuf->b_p_ro)
7935 curbuf->b_did_warn = FALSE;
7936
Bram Moolenaar071d4272004-06-13 20:20:40 +00007937#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007938 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939#endif
7940 }
7941
Bram Moolenaar9c449722010-07-20 18:44:27 +02007942#ifdef FEAT_GUI
7943 else if ((int *)varp == &p_mh)
7944 {
7945 if (!p_mh)
7946 gui_mch_mousehide(FALSE);
7947 }
7948#endif
7949
Bram Moolenaara539df02010-08-01 14:35:05 +02007950#ifdef FEAT_TITLE
7951 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007952 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007953 {
7954 redraw_titles();
7955 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 /* when 'endofline' is changed, redraw the window title */
7957 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007958 {
7959 redraw_titles();
7960 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007961 /* when 'fixeol' is changed, redraw the window title */
7962 else if ((int *)varp == &curbuf->b_p_fixeol)
7963 {
7964 redraw_titles();
7965 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007966# ifdef FEAT_MBYTE
7967 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007968 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007969 {
7970 redraw_titles();
7971 }
7972# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973#endif
7974
7975 /* when 'bin' is set also set some other options */
7976 else if ((int *)varp == &curbuf->b_p_bin)
7977 {
7978 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7979#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007980 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981#endif
7982 }
7983
7984#ifdef FEAT_AUTOCMD
7985 /* when 'buflisted' changes, trigger autocommands */
7986 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7987 {
7988 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7989 NULL, NULL, TRUE, curbuf);
7990 }
7991#endif
7992
7993 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7994 else if ((int *)varp == &curbuf->b_p_swf)
7995 {
7996 if (curbuf->b_p_swf && p_uc)
7997 ml_open_file(curbuf); /* create the swap file */
7998 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007999 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8000 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001 mf_close_file(curbuf, TRUE); /* remove the swap file */
8002 }
8003
8004 /* when 'terse' is set change 'shortmess' */
8005 else if ((int *)varp == &p_terse)
8006 {
8007 char_u *p;
8008
8009 p = vim_strchr(p_shm, SHM_SEARCH);
8010
8011 /* insert 's' in p_shm */
8012 if (p_terse && p == NULL)
8013 {
8014 STRCPY(IObuff, p_shm);
8015 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008016 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 }
8018 /* remove 's' from p_shm */
8019 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008020 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 }
8022
8023 /* when 'paste' is set or reset also change other options */
8024 else if ((int *)varp == &p_paste)
8025 {
8026 paste_option_changed();
8027 }
8028
8029 /* when 'insertmode' is set from an autocommand need to do work here */
8030 else if ((int *)varp == &p_im)
8031 {
8032 if (p_im)
8033 {
8034 if ((State & INSERT) == 0)
8035 need_start_insertmode = TRUE;
8036 stop_insert_mode = FALSE;
8037 }
8038 else
8039 {
8040 need_start_insertmode = FALSE;
8041 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008042 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008043 clear_cmdline = TRUE; /* remove "(insert)" */
8044 restart_edit = 0;
8045 }
8046 }
8047
8048 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8049 else if ((int *)varp == &p_ic && p_hls)
8050 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008051 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008052 }
8053
8054#ifdef FEAT_SEARCH_EXTRA
8055 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8056 else if ((int *)varp == &p_hls)
8057 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008058 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008059 }
8060#endif
8061
8062#ifdef FEAT_SCROLLBIND
8063 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8064 * at the end of normal_cmd() */
8065 else if ((int *)varp == &curwin->w_p_scb)
8066 {
8067 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008068 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008070 curwin->w_scbind_pos = curwin->w_topline;
8071 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072 }
8073#endif
8074
8075#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8076 /* There can be only one window with 'previewwindow' set. */
8077 else if ((int *)varp == &curwin->w_p_pvw)
8078 {
8079 if (curwin->w_p_pvw)
8080 {
8081 win_T *win;
8082
8083 for (win = firstwin; win != NULL; win = win->w_next)
8084 if (win->w_p_pvw && win != curwin)
8085 {
8086 curwin->w_p_pvw = FALSE;
8087 return (char_u *)N_("E590: A preview window already exists");
8088 }
8089 }
8090 }
8091#endif
8092
8093 /* when 'textmode' is set or reset also change 'fileformat' */
8094 else if ((int *)varp == &curbuf->b_p_tx)
8095 {
8096 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8097 }
8098
8099 /* when 'textauto' is set or reset also change 'fileformats' */
8100 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008101 set_string_option_direct((char_u *)"ffs", -1,
8102 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008103 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104
8105 /*
8106 * When 'lisp' option changes include/exclude '-' in
8107 * keyword characters.
8108 */
8109#ifdef FEAT_LISP
8110 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8111 {
8112 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8113 }
8114#endif
8115
8116#ifdef FEAT_TITLE
8117 /* when 'title' changed, may need to change the title; same for 'icon' */
8118 else if ((int *)varp == &p_title)
8119 {
8120 did_set_title(FALSE);
8121 }
8122
8123 else if ((int *)varp == &p_icon)
8124 {
8125 did_set_title(TRUE);
8126 }
8127#endif
8128
8129 else if ((int *)varp == &curbuf->b_changed)
8130 {
8131 if (!value)
8132 save_file_ff(curbuf); /* Buffer is unchanged */
8133#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008134 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135#endif
8136#ifdef FEAT_AUTOCMD
8137 modified_was_set = value;
8138#endif
8139 }
8140
8141#ifdef BACKSLASH_IN_FILENAME
8142 else if ((int *)varp == &p_ssl)
8143 {
8144 if (p_ssl)
8145 {
8146 psepc = '/';
8147 psepcN = '\\';
8148 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 }
8150 else
8151 {
8152 psepc = '\\';
8153 psepcN = '/';
8154 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 }
8156
8157 /* need to adjust the file name arguments and buffer names. */
8158 buflist_slash_adjust();
8159 alist_slash_adjust();
8160# ifdef FEAT_EVAL
8161 scriptnames_slash_adjust();
8162# endif
8163 }
8164#endif
8165
8166 /* If 'wrap' is set, set w_leftcol to zero. */
8167 else if ((int *)varp == &curwin->w_p_wrap)
8168 {
8169 if (curwin->w_p_wrap)
8170 curwin->w_leftcol = 0;
8171 }
8172
8173#ifdef FEAT_WINDOWS
8174 else if ((int *)varp == &p_ea)
8175 {
8176 if (p_ea && !old_value)
8177 win_equal(curwin, FALSE, 0);
8178 }
8179#endif
8180
8181 else if ((int *)varp == &p_wiv)
8182 {
8183 /*
8184 * When 'weirdinvert' changed, set/reset 't_xs'.
8185 * Then set 'weirdinvert' according to value of 't_xs'.
8186 */
8187 if (p_wiv && !old_value)
8188 T_XS = (char_u *)"y";
8189 else if (!p_wiv && old_value)
8190 T_XS = empty_option;
8191 p_wiv = (*T_XS != NUL);
8192 }
8193
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008194#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195 else if ((int *)varp == &p_beval)
8196 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008197 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008199 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200 gui_mch_disable_beval_area(balloonEval);
8201 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008202#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008203
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008204#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 else if ((int *)varp == &p_acd)
8206 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008207 /* Change directories when the 'acd' option is set now. */
8208 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209 }
8210#endif
8211
8212#ifdef FEAT_DIFF
8213 /* 'diff' */
8214 else if ((int *)varp == &curwin->w_p_diff)
8215 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008216 /* May add or remove the buffer from the list of diff buffers. */
8217 diff_buf_adjust(curwin);
8218# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008219 if (foldmethodIsDiff(curwin))
8220 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008221# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222 }
8223#endif
8224
8225#ifdef USE_IM_CONTROL
8226 /* 'imdisable' */
8227 else if ((int *)varp == &p_imdisable)
8228 {
8229 /* Only de-activate it here, it will be enabled when changing mode. */
8230 if (p_imdisable)
8231 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008232 else if (State & INSERT)
8233 /* When the option is set from an autocommand, it may need to take
8234 * effect right away. */
8235 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008236 }
8237#endif
8238
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008239#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008240 /* 'spell' */
8241 else if ((int *)varp == &curwin->w_p_spell)
8242 {
8243 if (curwin->w_p_spell)
8244 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008245 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008246 if (errmsg != NULL)
8247 EMSG(_(errmsg));
8248 }
8249 }
8250#endif
8251
Bram Moolenaar071d4272004-06-13 20:20:40 +00008252#ifdef FEAT_FKMAP
8253 else if ((int *)varp == &p_altkeymap)
8254 {
8255 if (old_value != p_altkeymap)
8256 {
8257 if (!p_altkeymap)
8258 {
8259 p_hkmap = p_fkmap;
8260 p_fkmap = 0;
8261 }
8262 else
8263 {
8264 p_fkmap = p_hkmap;
8265 p_hkmap = 0;
8266 }
8267 (void)init_chartab();
8268 }
8269 }
8270
8271 /*
8272 * In case some second language keymapping options have changed, check
8273 * and correct the setting in a consistent way.
8274 */
8275
8276 /*
8277 * If hkmap or fkmap are set, reset Arabic keymapping.
8278 */
8279 if ((p_hkmap || p_fkmap) && p_altkeymap)
8280 {
8281 p_altkeymap = p_fkmap;
8282# ifdef FEAT_ARABIC
8283 curwin->w_p_arab = FALSE;
8284# endif
8285 (void)init_chartab();
8286 }
8287
8288 /*
8289 * If hkmap set, reset Farsi keymapping.
8290 */
8291 if (p_hkmap && p_altkeymap)
8292 {
8293 p_altkeymap = 0;
8294 p_fkmap = 0;
8295# ifdef FEAT_ARABIC
8296 curwin->w_p_arab = FALSE;
8297# endif
8298 (void)init_chartab();
8299 }
8300
8301 /*
8302 * If fkmap set, reset Hebrew keymapping.
8303 */
8304 if (p_fkmap && !p_altkeymap)
8305 {
8306 p_altkeymap = 1;
8307 p_hkmap = 0;
8308# ifdef FEAT_ARABIC
8309 curwin->w_p_arab = FALSE;
8310# endif
8311 (void)init_chartab();
8312 }
8313#endif
8314
8315#ifdef FEAT_ARABIC
8316 if ((int *)varp == &curwin->w_p_arab)
8317 {
8318 if (curwin->w_p_arab)
8319 {
8320 /*
8321 * 'arabic' is set, handle various sub-settings.
8322 */
8323 if (!p_tbidi)
8324 {
8325 /* set rightleft mode */
8326 if (!curwin->w_p_rl)
8327 {
8328 curwin->w_p_rl = TRUE;
8329 changed_window_setting();
8330 }
8331
8332 /* Enable Arabic shaping (major part of what Arabic requires) */
8333 if (!p_arshape)
8334 {
8335 p_arshape = TRUE;
8336 redraw_later_clear();
8337 }
8338 }
8339
8340 /* Arabic requires a utf-8 encoding, inform the user if its not
8341 * set. */
8342 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008343 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008344 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8345
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008346 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008347 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8348#ifdef FEAT_EVAL
8349 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8350#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008351 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352
8353# ifdef FEAT_MBYTE
8354 /* set 'delcombine' */
8355 p_deco = TRUE;
8356# endif
8357
8358# ifdef FEAT_KEYMAP
8359 /* Force-set the necessary keymap for arabic */
8360 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8361 OPT_LOCAL);
8362# endif
8363# ifdef FEAT_FKMAP
8364 p_altkeymap = 0;
8365 p_hkmap = 0;
8366 p_fkmap = 0;
8367 (void)init_chartab();
8368# endif
8369 }
8370 else
8371 {
8372 /*
8373 * 'arabic' is reset, handle various sub-settings.
8374 */
8375 if (!p_tbidi)
8376 {
8377 /* reset rightleft mode */
8378 if (curwin->w_p_rl)
8379 {
8380 curwin->w_p_rl = FALSE;
8381 changed_window_setting();
8382 }
8383
8384 /* 'arabicshape' isn't reset, it is a global option and
8385 * another window may still need it "on". */
8386 }
8387
8388 /* 'delcombine' isn't reset, it is a global option and another
8389 * window may still want it "on". */
8390
8391# ifdef FEAT_KEYMAP
8392 /* Revert to the default keymap */
8393 curbuf->b_p_iminsert = B_IMODE_NONE;
8394 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8395# endif
8396 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008397 }
8398
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008399#endif
8400
Bram Moolenaar071d4272004-06-13 20:20:40 +00008401 /*
8402 * End of handling side effects for bool options.
8403 */
8404
Bram Moolenaar53744302015-07-17 17:38:22 +02008405 /* after handling side effects, call autocommand */
8406
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 options[opt_idx].flags |= P_WAS_SET;
8408
Bram Moolenaar53744302015-07-17 17:38:22 +02008409#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8410 if (!starting)
8411 {
8412 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008413 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8414 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8415 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008416 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8417 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8418 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8419 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8420 reset_v_option_vars();
8421 }
8422#endif
8423
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008425 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008426 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008427 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428 check_redraw(options[opt_idx].flags);
8429
8430 return NULL;
8431}
8432
8433/*
8434 * Set the value of a number option, and take care of side effects.
8435 * Returns NULL for success, or an error message for an error.
8436 */
8437 static char_u *
Bram Moolenaar555b2802005-05-19 21:08:39 +00008438set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008439 int opt_idx; /* index in options[] table */
8440 char_u *varp; /* pointer to the option variable */
8441 long value; /* new value */
8442 char_u *errbuf; /* buffer for error messages */
Bram Moolenaar555b2802005-05-19 21:08:39 +00008443 size_t errbuflen; /* length of "errbuf" */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444 int opt_flags; /* OPT_LOCAL, OPT_GLOBAL and
8445 OPT_MODELINE */
8446{
8447 char_u *errmsg = NULL;
8448 long old_value = *(long *)varp;
8449 long old_Rows = Rows; /* remember old Rows */
8450 long old_Columns = Columns; /* remember old Columns */
8451 long *pp = (long *)varp;
8452
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008453 /* Disallow changing some options from secure mode. */
8454 if ((secure
8455#ifdef HAVE_SANDBOX
8456 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008458 ) && (options[opt_idx].flags & P_SECURE))
8459 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460
8461 *pp = value;
8462#ifdef FEAT_EVAL
8463 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008464 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008465#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008466#ifdef FEAT_GUI
8467 need_mouse_correct = TRUE;
8468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008469
Bram Moolenaar14f24742012-08-08 18:01:05 +02008470 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471 {
8472 errmsg = e_positive;
8473 curbuf->b_p_sw = curbuf->b_p_ts;
8474 }
8475
8476 /*
8477 * Number options that need some action when changed
8478 */
8479#ifdef FEAT_WINDOWS
8480 if (pp == &p_wh || pp == &p_hh)
8481 {
8482 if (p_wh < 1)
8483 {
8484 errmsg = e_positive;
8485 p_wh = 1;
8486 }
8487 if (p_wmh > p_wh)
8488 {
8489 errmsg = e_winheight;
8490 p_wh = p_wmh;
8491 }
8492 if (p_hh < 0)
8493 {
8494 errmsg = e_positive;
8495 p_hh = 0;
8496 }
8497
8498 /* Change window height NOW */
8499 if (lastwin != firstwin)
8500 {
8501 if (pp == &p_wh && curwin->w_height < p_wh)
8502 win_setheight((int)p_wh);
8503 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8504 win_setheight((int)p_hh);
8505 }
8506 }
8507
8508 /* 'winminheight' */
8509 else if (pp == &p_wmh)
8510 {
8511 if (p_wmh < 0)
8512 {
8513 errmsg = e_positive;
8514 p_wmh = 0;
8515 }
8516 if (p_wmh > p_wh)
8517 {
8518 errmsg = e_winheight;
8519 p_wmh = p_wh;
8520 }
8521 win_setminheight();
8522 }
8523
8524# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008525 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008526 {
8527 if (p_wiw < 1)
8528 {
8529 errmsg = e_positive;
8530 p_wiw = 1;
8531 }
8532 if (p_wmw > p_wiw)
8533 {
8534 errmsg = e_winwidth;
8535 p_wiw = p_wmw;
8536 }
8537
8538 /* Change window width NOW */
8539 if (lastwin != firstwin && curwin->w_width < p_wiw)
8540 win_setwidth((int)p_wiw);
8541 }
8542
8543 /* 'winminwidth' */
8544 else if (pp == &p_wmw)
8545 {
8546 if (p_wmw < 0)
8547 {
8548 errmsg = e_positive;
8549 p_wmw = 0;
8550 }
8551 if (p_wmw > p_wiw)
8552 {
8553 errmsg = e_winwidth;
8554 p_wmw = p_wiw;
8555 }
8556 win_setminheight();
8557 }
8558# endif
8559
8560#endif
8561
8562#ifdef FEAT_WINDOWS
8563 /* (re)set last window status line */
8564 else if (pp == &p_ls)
8565 {
8566 last_status(FALSE);
8567 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008568
8569 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008570 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008571 {
8572 shell_new_rows(); /* recompute window positions and heights */
8573 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008574#endif
8575
8576#ifdef FEAT_GUI
8577 else if (pp == &p_linespace)
8578 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008579 /* Recompute gui.char_height and resize the Vim window to keep the
8580 * same number of lines. */
8581 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008582 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008583 }
8584#endif
8585
8586#ifdef FEAT_FOLDING
8587 /* 'foldlevel' */
8588 else if (pp == &curwin->w_p_fdl)
8589 {
8590 if (curwin->w_p_fdl < 0)
8591 curwin->w_p_fdl = 0;
8592 newFoldLevel();
8593 }
8594
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008595 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008596 else if (pp == &curwin->w_p_fml)
8597 {
8598 foldUpdateAll(curwin);
8599 }
8600
8601 /* 'foldnestmax' */
8602 else if (pp == &curwin->w_p_fdn)
8603 {
8604 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8605 foldUpdateAll(curwin);
8606 }
8607
8608 /* 'foldcolumn' */
8609 else if (pp == &curwin->w_p_fdc)
8610 {
8611 if (curwin->w_p_fdc < 0)
8612 {
8613 errmsg = e_positive;
8614 curwin->w_p_fdc = 0;
8615 }
8616 else if (curwin->w_p_fdc > 12)
8617 {
8618 errmsg = e_invarg;
8619 curwin->w_p_fdc = 12;
8620 }
8621 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008622#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008623
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008624#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625 /* 'shiftwidth' or 'tabstop' */
8626 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8627 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008628# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008629 if (foldmethodIsIndent(curwin))
8630 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008631# endif
8632# ifdef FEAT_CINDENT
8633 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8634 * parse 'cinoptions'. */
8635 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8636 parse_cino(curbuf);
8637# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008639#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008641#ifdef FEAT_MBYTE
8642 /* 'maxcombine' */
8643 else if (pp == &p_mco)
8644 {
8645 if (p_mco > MAX_MCO)
8646 p_mco = MAX_MCO;
8647 else if (p_mco < 0)
8648 p_mco = 0;
8649 screenclear(); /* will re-allocate the screen */
8650 }
8651#endif
8652
Bram Moolenaar071d4272004-06-13 20:20:40 +00008653 else if (pp == &curbuf->b_p_iminsert)
8654 {
8655 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8656 {
8657 errmsg = e_invarg;
8658 curbuf->b_p_iminsert = B_IMODE_NONE;
8659 }
8660 p_iminsert = curbuf->b_p_iminsert;
8661 if (termcap_active) /* don't do this in the alternate screen */
8662 showmode();
8663#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8664 /* Show/unshow value of 'keymap' in status lines. */
8665 status_redraw_curbuf();
8666#endif
8667 }
8668
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008669 else if (pp == &p_window)
8670 {
8671 if (p_window < 1)
8672 p_window = 1;
8673 else if (p_window >= Rows)
8674 p_window = Rows - 1;
8675 }
8676
Bram Moolenaar071d4272004-06-13 20:20:40 +00008677 else if (pp == &curbuf->b_p_imsearch)
8678 {
8679 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8680 {
8681 errmsg = e_invarg;
8682 curbuf->b_p_imsearch = B_IMODE_NONE;
8683 }
8684 p_imsearch = curbuf->b_p_imsearch;
8685 }
8686
8687#ifdef FEAT_TITLE
8688 /* if 'titlelen' has changed, redraw the title */
8689 else if (pp == &p_titlelen)
8690 {
8691 if (p_titlelen < 0)
8692 {
8693 errmsg = e_positive;
8694 p_titlelen = 85;
8695 }
8696 if (starting != NO_SCREEN && old_value != p_titlelen)
8697 need_maketitle = TRUE;
8698 }
8699#endif
8700
8701 /* if p_ch changed value, change the command line height */
8702 else if (pp == &p_ch)
8703 {
8704 if (p_ch < 1)
8705 {
8706 errmsg = e_positive;
8707 p_ch = 1;
8708 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008709 if (p_ch > Rows - min_rows() + 1)
8710 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008711
8712 /* Only compute the new window layout when startup has been
8713 * completed. Otherwise the frame sizes may be wrong. */
8714 if (p_ch != old_value && full_screen
8715#ifdef FEAT_GUI
8716 && !gui.starting
8717#endif
8718 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008719 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720 }
8721
8722 /* when 'updatecount' changes from zero to non-zero, open swap files */
8723 else if (pp == &p_uc)
8724 {
8725 if (p_uc < 0)
8726 {
8727 errmsg = e_positive;
8728 p_uc = 100;
8729 }
8730 if (p_uc && !old_value)
8731 ml_open_files();
8732 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008733#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008734 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008735 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008736 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008737 {
8738 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008739 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008740 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008741 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008742 {
8743 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008744 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008745 }
8746 }
8747#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008748#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008749 else if (pp == &p_mzq)
8750 mzvim_reset_timer();
8751#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752
8753 /* sync undo before 'undolevels' changes */
8754 else if (pp == &p_ul)
8755 {
8756 /* use the old value, otherwise u_sync() may not work properly */
8757 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008758 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008759 p_ul = value;
8760 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008761 else if (pp == &curbuf->b_p_ul)
8762 {
8763 /* use the old value, otherwise u_sync() may not work properly */
8764 curbuf->b_p_ul = old_value;
8765 u_sync(TRUE);
8766 curbuf->b_p_ul = value;
8767 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008768
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008769#ifdef FEAT_LINEBREAK
8770 /* 'numberwidth' must be positive */
8771 else if (pp == &curwin->w_p_nuw)
8772 {
8773 if (curwin->w_p_nuw < 1)
8774 {
8775 errmsg = e_positive;
8776 curwin->w_p_nuw = 1;
8777 }
8778 if (curwin->w_p_nuw > 10)
8779 {
8780 errmsg = e_invarg;
8781 curwin->w_p_nuw = 10;
8782 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008783 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008784 }
8785#endif
8786
Bram Moolenaar1a384422010-07-14 19:53:30 +02008787 else if (pp == &curbuf->b_p_tw)
8788 {
8789 if (curbuf->b_p_tw < 0)
8790 {
8791 errmsg = e_positive;
8792 curbuf->b_p_tw = 0;
8793 }
8794#ifdef FEAT_SYN_HL
8795# ifdef FEAT_WINDOWS
8796 {
8797 win_T *wp;
8798 tabpage_T *tp;
8799
8800 FOR_ALL_TAB_WINDOWS(tp, wp)
8801 check_colorcolumn(wp);
8802 }
8803# else
8804 check_colorcolumn(curwin);
8805# endif
8806#endif
8807 }
8808
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 /*
8810 * Check the bounds for numeric options here
8811 */
8812 if (Rows < min_rows() && full_screen)
8813 {
8814 if (errbuf != NULL)
8815 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008816 vim_snprintf((char *)errbuf, errbuflen,
8817 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008818 errmsg = errbuf;
8819 }
8820 Rows = min_rows();
8821 }
8822 if (Columns < MIN_COLUMNS && full_screen)
8823 {
8824 if (errbuf != NULL)
8825 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008826 vim_snprintf((char *)errbuf, errbuflen,
8827 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828 errmsg = errbuf;
8829 }
8830 Columns = MIN_COLUMNS;
8831 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008832 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833
8834#ifdef DJGPP
8835 /* avoid a crash by checking for a too large value of 'columns' */
8836 if (old_Columns != Columns && full_screen && term_console)
8837 mch_check_columns();
8838#endif
8839
8840 /*
8841 * If the screen (shell) height has been changed, assume it is the
8842 * physical screenheight.
8843 */
8844 if (old_Rows != Rows || old_Columns != Columns)
8845 {
8846 /* Changing the screen size is not allowed while updating the screen. */
8847 if (updating_screen)
8848 *pp = old_value;
8849 else if (full_screen
8850#ifdef FEAT_GUI
8851 && !gui.starting
8852#endif
8853 )
8854 set_shellsize((int)Columns, (int)Rows, TRUE);
8855 else
8856 {
8857 /* Postpone the resizing; check the size and cmdline position for
8858 * messages. */
8859 check_shellsize();
8860 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8861 cmdline_row = Rows - p_ch;
8862 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008863 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008864 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 }
8866
Bram Moolenaar071d4272004-06-13 20:20:40 +00008867 if (curbuf->b_p_ts <= 0)
8868 {
8869 errmsg = e_positive;
8870 curbuf->b_p_ts = 8;
8871 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872 if (p_tm < 0)
8873 {
8874 errmsg = e_positive;
8875 p_tm = 0;
8876 }
8877 if ((curwin->w_p_scr <= 0
8878 || (curwin->w_p_scr > curwin->w_height
8879 && curwin->w_height > 0))
8880 && full_screen)
8881 {
8882 if (pp == &(curwin->w_p_scr))
8883 {
8884 if (curwin->w_p_scr != 0)
8885 errmsg = e_scroll;
8886 win_comp_scroll(curwin);
8887 }
8888 /* If 'scroll' became invalid because of a side effect silently adjust
8889 * it. */
8890 else if (curwin->w_p_scr <= 0)
8891 curwin->w_p_scr = 1;
8892 else /* curwin->w_p_scr > curwin->w_height */
8893 curwin->w_p_scr = curwin->w_height;
8894 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008895 if (p_hi < 0)
8896 {
8897 errmsg = e_positive;
8898 p_hi = 0;
8899 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008900 else if (p_hi > 10000)
8901 {
8902 errmsg = e_invarg;
8903 p_hi = 10000;
8904 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008905 if (p_re < 0 || p_re > 2)
8906 {
8907 errmsg = e_invarg;
8908 p_re = 0;
8909 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910 if (p_report < 0)
8911 {
8912 errmsg = e_positive;
8913 p_report = 1;
8914 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008915 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008916 {
8917 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8918 p_sj = Rows / 2;
8919 else
8920 {
8921 errmsg = e_scroll;
8922 p_sj = 1;
8923 }
8924 }
8925 if (p_so < 0 && full_screen)
8926 {
8927 errmsg = e_scroll;
8928 p_so = 0;
8929 }
8930 if (p_siso < 0 && full_screen)
8931 {
8932 errmsg = e_positive;
8933 p_siso = 0;
8934 }
8935#ifdef FEAT_CMDWIN
8936 if (p_cwh < 1)
8937 {
8938 errmsg = e_positive;
8939 p_cwh = 1;
8940 }
8941#endif
8942 if (p_ut < 0)
8943 {
8944 errmsg = e_positive;
8945 p_ut = 2000;
8946 }
8947 if (p_ss < 0)
8948 {
8949 errmsg = e_positive;
8950 p_ss = 0;
8951 }
8952
8953 /* May set global value for local option. */
8954 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8955 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8956
8957 options[opt_idx].flags |= P_WAS_SET;
8958
Bram Moolenaar53744302015-07-17 17:38:22 +02008959#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8960 if (!starting && errmsg == NULL)
8961 {
8962 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008963 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8964 vim_snprintf((char *)buf_new, 10, "%ld", value);
8965 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008966 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8967 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8968 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8969 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8970 reset_v_option_vars();
8971 }
8972#endif
8973
Bram Moolenaar071d4272004-06-13 20:20:40 +00008974 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008975 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008976 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008977 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 check_redraw(options[opt_idx].flags);
8979
8980 return errmsg;
8981}
8982
8983/*
8984 * Called after an option changed: check if something needs to be redrawn.
8985 */
8986 static void
8987check_redraw(flags)
8988 long_u flags;
8989{
8990 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008991 int doclear = (flags & P_RCLR) == P_RCLR;
8992 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993
8994#ifdef FEAT_WINDOWS
8995 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8996 status_redraw_all();
8997#endif
8998
8999 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9000 changed_window_setting();
9001 if (flags & P_RBUF)
9002 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009003 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009004 redraw_all_later(CLEAR);
9005 else if (all)
9006 redraw_all_later(NOT_VALID);
9007}
9008
9009/*
9010 * Find index for option 'arg'.
9011 * Return -1 if not found.
9012 */
9013 static int
9014findoption(arg)
9015 char_u *arg;
9016{
9017 int opt_idx;
9018 char *s, *p;
9019 static short quick_tab[27] = {0, 0}; /* quick access table */
9020 int is_term_opt;
9021
9022 /*
9023 * For first call: Initialize the quick-access table.
9024 * It contains the index for the first option that starts with a certain
9025 * letter. There are 26 letters, plus the first "t_" option.
9026 */
9027 if (quick_tab[1] == 0)
9028 {
9029 p = options[0].fullname;
9030 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9031 {
9032 if (s[0] != p[0])
9033 {
9034 if (s[0] == 't' && s[1] == '_')
9035 quick_tab[26] = opt_idx;
9036 else
9037 quick_tab[CharOrdLow(s[0])] = opt_idx;
9038 }
9039 p = s;
9040 }
9041 }
9042
9043 /*
9044 * Check for name starting with an illegal character.
9045 */
9046#ifdef EBCDIC
9047 if (!islower(arg[0]))
9048#else
9049 if (arg[0] < 'a' || arg[0] > 'z')
9050#endif
9051 return -1;
9052
9053 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9054 if (is_term_opt)
9055 opt_idx = quick_tab[26];
9056 else
9057 opt_idx = quick_tab[CharOrdLow(arg[0])];
9058 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9059 {
9060 if (STRCMP(arg, s) == 0) /* match full name */
9061 break;
9062 }
9063 if (s == NULL && !is_term_opt)
9064 {
9065 opt_idx = quick_tab[CharOrdLow(arg[0])];
9066 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9067 {
9068 s = options[opt_idx].shortname;
9069 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9070 break;
9071 s = NULL;
9072 }
9073 }
9074 if (s == NULL)
9075 opt_idx = -1;
9076 return opt_idx;
9077}
9078
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009079#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080/*
9081 * Get the value for an option.
9082 *
9083 * Returns:
9084 * Number or Toggle option: 1, *numval gets value.
9085 * String option: 0, *stringval gets allocated string.
9086 * Hidden Number or Toggle option: -1.
9087 * hidden String option: -2.
9088 * unknown option: -3.
9089 */
9090 int
9091get_option_value(name, numval, stringval, opt_flags)
9092 char_u *name;
9093 long *numval;
Bram Moolenaar370df582010-06-22 05:16:38 +02009094 char_u **stringval; /* NULL when only checking existence */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009095 int opt_flags;
9096{
9097 int opt_idx;
9098 char_u *varp;
9099
9100 opt_idx = findoption(name);
9101 if (opt_idx < 0) /* unknown option */
9102 return -3;
9103
9104 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9105
9106 if (options[opt_idx].flags & P_STRING)
9107 {
9108 if (varp == NULL) /* hidden option */
9109 return -2;
9110 if (stringval != NULL)
9111 {
9112#ifdef FEAT_CRYPT
9113 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009114 if ((char_u **)varp == &curbuf->b_p_key
9115 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116 *stringval = vim_strsave((char_u *)"*****");
9117 else
9118#endif
9119 *stringval = vim_strsave(*(char_u **)(varp));
9120 }
9121 return 0;
9122 }
9123
9124 if (varp == NULL) /* hidden option */
9125 return -1;
9126 if (options[opt_idx].flags & P_NUM)
9127 *numval = *(long *)varp;
9128 else
9129 {
9130 /* Special case: 'modified' is b_changed, but we also want to consider
9131 * it set when 'ff' or 'fenc' changed. */
9132 if ((int *)varp == &curbuf->b_changed)
9133 *numval = curbufIsChanged();
9134 else
9135 *numval = *(int *)varp;
9136 }
9137 return 1;
9138}
9139#endif
9140
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009141#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009142/*
9143 * Returns the option attributes and its value. Unlike the above function it
9144 * will return either global value or local value of the option depending on
9145 * what was requested, but it will never return global value if it was
9146 * requested to return local one and vice versa. Neither it will return
9147 * buffer-local value if it was requested to return window-local one.
9148 *
9149 * Pretends that option is absent if it is not present in the requested scope
9150 * (i.e. has no global, window-local or buffer-local value depending on
9151 * opt_type). Uses
9152 *
9153 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009154 * 0 hidden or unknown option, also option that does not have requested
9155 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009156 * see SOPT_* in vim.h for other flags
9157 *
9158 * Possible opt_type values: see SREQ_* in vim.h
9159 */
9160 int
9161get_option_value_strict(name, numval, stringval, opt_type, from)
9162 char_u *name;
9163 long *numval;
9164 char_u **stringval; /* NULL when only obtaining attributes */
9165 int opt_type;
9166 void *from;
9167{
9168 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009169 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009170 struct vimoption *p;
9171 int r = 0;
9172
9173 opt_idx = findoption(name);
9174 if (opt_idx < 0)
9175 return 0;
9176
9177 p = &(options[opt_idx]);
9178
9179 /* Hidden option */
9180 if (p->var == NULL)
9181 return 0;
9182
9183 if (p->flags & P_BOOL)
9184 r |= SOPT_BOOL;
9185 else if (p->flags & P_NUM)
9186 r |= SOPT_NUM;
9187 else if (p->flags & P_STRING)
9188 r |= SOPT_STRING;
9189
9190 if (p->indir == PV_NONE)
9191 {
9192 if (opt_type == SREQ_GLOBAL)
9193 r |= SOPT_GLOBAL;
9194 else
9195 return 0; /* Did not request global-only option */
9196 }
9197 else
9198 {
9199 if (p->indir & PV_BOTH)
9200 r |= SOPT_GLOBAL;
9201 else if (opt_type == SREQ_GLOBAL)
9202 return 0; /* Requested global option */
9203
9204 if (p->indir & PV_WIN)
9205 {
9206 if (opt_type == SREQ_BUF)
9207 return 0; /* Did not request window-local option */
9208 else
9209 r |= SOPT_WIN;
9210 }
9211 else if (p->indir & PV_BUF)
9212 {
9213 if (opt_type == SREQ_WIN)
9214 return 0; /* Did not request buffer-local option */
9215 else
9216 r |= SOPT_BUF;
9217 }
9218 }
9219
9220 if (stringval == NULL)
9221 return r;
9222
9223 if (opt_type == SREQ_GLOBAL)
9224 varp = p->var;
9225 else
9226 {
9227 if (opt_type == SREQ_BUF)
9228 {
9229 /* Special case: 'modified' is b_changed, but we also want to
9230 * consider it set when 'ff' or 'fenc' changed. */
9231 if (p->indir == PV_MOD)
9232 {
9233 *numval = bufIsChanged((buf_T *) from);
9234 varp = NULL;
9235 }
9236#ifdef FEAT_CRYPT
9237 else if (p->indir == PV_KEY)
9238 {
9239 /* never return the value of the crypt key */
9240 *stringval = NULL;
9241 varp = NULL;
9242 }
9243#endif
9244 else
9245 {
9246 aco_save_T aco;
9247 aucmd_prepbuf(&aco, (buf_T *) from);
9248 varp = get_varp(p);
9249 aucmd_restbuf(&aco);
9250 }
9251 }
9252 else if (opt_type == SREQ_WIN)
9253 {
9254 win_T *save_curwin;
9255 save_curwin = curwin;
9256 curwin = (win_T *) from;
9257 curbuf = curwin->w_buffer;
9258 varp = get_varp(p);
9259 curwin = save_curwin;
9260 curbuf = curwin->w_buffer;
9261 }
9262 if (varp == p->var)
9263 return (r | SOPT_UNSET);
9264 }
9265
9266 if (varp != NULL)
9267 {
9268 if (p->flags & P_STRING)
9269 *stringval = vim_strsave(*(char_u **)(varp));
9270 else if (p->flags & P_NUM)
9271 *numval = *(long *) varp;
9272 else
9273 *numval = *(int *)varp;
9274 }
9275
9276 return r;
9277}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009278
9279/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009280 * Iterate over options. First argument is a pointer to a pointer to a
9281 * structure inside options[] array, second is option type like in the above
9282 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009283 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009284 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009285 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009286 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009287 * first argument to NULL.
9288 *
9289 * Returns full option name for current option on each call.
9290 */
9291 char_u *
9292option_iter_next(option, opt_type)
9293 void **option;
9294 int opt_type;
9295{
9296 struct vimoption *ret = NULL;
9297 do
9298 {
9299 if (*option == NULL)
9300 *option = (void *) options;
9301 else if (((struct vimoption *) (*option))->fullname == NULL)
9302 {
9303 *option = NULL;
9304 return NULL;
9305 }
9306 else
9307 *option = (void *) (((struct vimoption *) (*option)) + 1);
9308
9309 ret = ((struct vimoption *) (*option));
9310
9311 /* Hidden option */
9312 if (ret->var == NULL)
9313 {
9314 ret = NULL;
9315 continue;
9316 }
9317
9318 switch (opt_type)
9319 {
9320 case SREQ_GLOBAL:
9321 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9322 ret = NULL;
9323 break;
9324 case SREQ_BUF:
9325 if (!(ret->indir & PV_BUF))
9326 ret = NULL;
9327 break;
9328 case SREQ_WIN:
9329 if (!(ret->indir & PV_WIN))
9330 ret = NULL;
9331 break;
9332 default:
9333 EMSG2(_(e_intern2), "option_iter_next()");
9334 return NULL;
9335 }
9336 }
9337 while (ret == NULL);
9338
9339 return (char_u *)ret->fullname;
9340}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009341#endif
9342
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343/*
9344 * Set the value of option "name".
9345 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009346 *
9347 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009348 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009349 char_u *
Bram Moolenaar071d4272004-06-13 20:20:40 +00009350set_option_value(name, number, string, opt_flags)
9351 char_u *name;
9352 long number;
9353 char_u *string;
9354 int opt_flags; /* OPT_LOCAL or 0 (both) */
9355{
9356 int opt_idx;
9357 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009358 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009359
9360 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009361 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362 EMSG2(_("E355: Unknown option: %s"), name);
9363 else
9364 {
9365 flags = options[opt_idx].flags;
9366#ifdef HAVE_SANDBOX
9367 /* Disallow changing some options in the sandbox */
9368 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009369 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009371 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009372 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009373#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009374 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009375 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009376 else
9377 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009378 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009379 if (varp != NULL) /* hidden option is not changed */
9380 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009381 if (number == 0 && string != NULL)
9382 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009383 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009384
9385 /* Either we are given a string or we are setting option
9386 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009387 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009388 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009389 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009390 {
9391 /* There's another character after zeros or the string
9392 * is empty. In both cases, we are trying to set a
9393 * num option using a string. */
9394 EMSG3(_("E521: Number required: &%s = '%s'"),
9395 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009396 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009397
9398 }
9399 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009400 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009401 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009402 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009403 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009404 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009405 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009406 }
9407 }
9408 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009409 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009410}
9411
9412/*
9413 * Get the terminal code for a terminal option.
9414 * Returns NULL when not found.
9415 */
9416 char_u *
9417get_term_code(tname)
9418 char_u *tname;
9419{
9420 int opt_idx;
9421 char_u *varp;
9422
9423 if (tname[0] != 't' || tname[1] != '_' ||
9424 tname[2] == NUL || tname[3] == NUL)
9425 return NULL;
9426 if ((opt_idx = findoption(tname)) >= 0)
9427 {
9428 varp = get_varp(&(options[opt_idx]));
9429 if (varp != NULL)
9430 varp = *(char_u **)(varp);
9431 return varp;
9432 }
9433 return find_termcode(tname + 2);
9434}
9435
9436 char_u *
9437get_highlight_default()
9438{
9439 int i;
9440
9441 i = findoption((char_u *)"hl");
9442 if (i >= 0)
9443 return options[i].def_val[VI_DEFAULT];
9444 return (char_u *)NULL;
9445}
9446
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009447#if defined(FEAT_MBYTE) || defined(PROTO)
9448 char_u *
9449get_encoding_default()
9450{
9451 int i;
9452
9453 i = findoption((char_u *)"enc");
9454 if (i >= 0)
9455 return options[i].def_val[VI_DEFAULT];
9456 return (char_u *)NULL;
9457}
9458#endif
9459
Bram Moolenaar071d4272004-06-13 20:20:40 +00009460/*
9461 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9462 */
9463 static int
9464find_key_option(arg)
9465 char_u *arg;
9466{
9467 int key;
9468 int modifiers;
9469
9470 /*
9471 * Don't use get_special_key_code() for t_xx, we don't want it to call
9472 * add_termcap_entry().
9473 */
9474 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9475 key = TERMCAP2KEY(arg[2], arg[3]);
9476 else
9477 {
9478 --arg; /* put arg at the '<' */
9479 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009480 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009481 if (modifiers) /* can't handle modifiers here */
9482 key = 0;
9483 }
9484 return key;
9485}
9486
9487/*
9488 * if 'all' == 0: show changed options
9489 * if 'all' == 1: show all normal options
9490 * if 'all' == 2: show all terminal options
9491 */
9492 static void
9493showoptions(all, opt_flags)
9494 int all;
9495 int opt_flags; /* OPT_LOCAL and/or OPT_GLOBAL */
9496{
9497 struct vimoption *p;
9498 int col;
9499 int isterm;
9500 char_u *varp;
9501 struct vimoption **items;
9502 int item_count;
9503 int run;
9504 int row, rows;
9505 int cols;
9506 int i;
9507 int len;
9508
9509#define INC 20
9510#define GAP 3
9511
9512 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9513 PARAM_COUNT));
9514 if (items == NULL)
9515 return;
9516
9517 /* Highlight title */
9518 if (all == 2)
9519 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9520 else if (opt_flags & OPT_GLOBAL)
9521 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9522 else if (opt_flags & OPT_LOCAL)
9523 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9524 else
9525 MSG_PUTS_TITLE(_("\n--- Options ---"));
9526
9527 /*
9528 * do the loop two times:
9529 * 1. display the short items
9530 * 2. display the long items (only strings and numbers)
9531 */
9532 for (run = 1; run <= 2 && !got_int; ++run)
9533 {
9534 /*
9535 * collect the items in items[]
9536 */
9537 item_count = 0;
9538 for (p = &options[0]; p->fullname != NULL; p++)
9539 {
9540 varp = NULL;
9541 isterm = istermoption(p);
9542 if (opt_flags != 0)
9543 {
9544 if (p->indir != PV_NONE && !isterm)
9545 varp = get_varp_scope(p, opt_flags);
9546 }
9547 else
9548 varp = get_varp(p);
9549 if (varp != NULL
9550 && ((all == 2 && isterm)
9551 || (all == 1 && !isterm)
9552 || (all == 0 && !optval_default(p, varp))))
9553 {
9554 if (p->flags & P_BOOL)
9555 len = 1; /* a toggle option fits always */
9556 else
9557 {
9558 option_value2string(p, opt_flags);
9559 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9560 }
9561 if ((len <= INC - GAP && run == 1) ||
9562 (len > INC - GAP && run == 2))
9563 items[item_count++] = p;
9564 }
9565 }
9566
9567 /*
9568 * display the items
9569 */
9570 if (run == 1)
9571 {
9572 cols = (Columns + GAP - 3) / INC;
9573 if (cols == 0)
9574 cols = 1;
9575 rows = (item_count + cols - 1) / cols;
9576 }
9577 else /* run == 2 */
9578 rows = item_count;
9579 for (row = 0; row < rows && !got_int; ++row)
9580 {
9581 msg_putchar('\n'); /* go to next line */
9582 if (got_int) /* 'q' typed in more */
9583 break;
9584 col = 0;
9585 for (i = row; i < item_count; i += rows)
9586 {
9587 msg_col = col; /* make columns */
9588 showoneopt(items[i], opt_flags);
9589 col += INC;
9590 }
9591 out_flush();
9592 ui_breakcheck();
9593 }
9594 }
9595 vim_free(items);
9596}
9597
9598/*
9599 * Return TRUE if option "p" has its default value.
9600 */
9601 static int
9602optval_default(p, varp)
9603 struct vimoption *p;
9604 char_u *varp;
9605{
9606 int dvi;
9607
9608 if (varp == NULL)
9609 return TRUE; /* hidden option is always at default */
9610 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9611 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009612 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009613 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009614 /* the cast to long is required for Manx C, long_i is
9615 * needed for MSVC */
9616 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009617 /* P_STRING */
9618 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9619}
9620
9621/*
9622 * showoneopt: show the value of one option
9623 * must not be called with a hidden option!
9624 */
9625 static void
9626showoneopt(p, opt_flags)
9627 struct vimoption *p;
9628 int opt_flags; /* OPT_LOCAL or OPT_GLOBAL */
9629{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009630 char_u *varp;
9631 int save_silent = silent_mode;
9632
9633 silent_mode = FALSE;
9634 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009635
9636 varp = get_varp_scope(p, opt_flags);
9637
9638 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9639 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9640 ? !curbufIsChanged() : !*(int *)varp))
9641 MSG_PUTS("no");
9642 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9643 MSG_PUTS("--");
9644 else
9645 MSG_PUTS(" ");
9646 MSG_PUTS(p->fullname);
9647 if (!(p->flags & P_BOOL))
9648 {
9649 msg_putchar('=');
9650 /* put value string in NameBuff */
9651 option_value2string(p, opt_flags);
9652 msg_outtrans(NameBuff);
9653 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009654
9655 silent_mode = save_silent;
9656 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657}
9658
9659/*
9660 * Write modified options as ":set" commands to a file.
9661 *
9662 * There are three values for "opt_flags":
9663 * OPT_GLOBAL: Write global option values and fresh values of
9664 * buffer-local options (used for start of a session
9665 * file).
9666 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9667 * curwin (used for a vimrc file).
9668 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9669 * and local values for window-local options of
9670 * curwin. Local values are also written when at the
9671 * default value, because a modeline or autocommand
9672 * may have set them when doing ":edit file" and the
9673 * user has set them back at the default or fresh
9674 * value.
9675 * When "local_only" is TRUE, don't write fresh
9676 * values, only local values (for ":mkview").
9677 * (fresh value = value used for a new buffer or window for a local option).
9678 *
9679 * Return FAIL on error, OK otherwise.
9680 */
9681 int
9682makeset(fd, opt_flags, local_only)
9683 FILE *fd;
9684 int opt_flags;
9685 int local_only;
9686{
9687 struct vimoption *p;
9688 char_u *varp; /* currently used value */
9689 char_u *varp_fresh; /* local value */
9690 char_u *varp_local = NULL; /* fresh value */
9691 char *cmd;
9692 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009693 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009694
9695 /*
9696 * The options that don't have a default (terminal name, columns, lines)
9697 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009698 * Do the loop over "options[]" twice: once for options with the
9699 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009700 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009701 for (pri = 1; pri >= 0; --pri)
9702 {
9703 for (p = &options[0]; !istermoption(p); p++)
9704 if (!(p->flags & P_NO_MKRC)
9705 && !istermoption(p)
9706 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009707 {
9708 /* skip global option when only doing locals */
9709 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9710 continue;
9711
9712 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9713 * file, they are always buffer-specific. */
9714 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9715 continue;
9716
9717 /* Global values are only written when not at the default value. */
9718 varp = get_varp_scope(p, opt_flags);
9719 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9720 continue;
9721
9722 round = 2;
9723 if (p->indir != PV_NONE)
9724 {
9725 if (p->var == VAR_WIN)
9726 {
9727 /* skip window-local option when only doing globals */
9728 if (!(opt_flags & OPT_LOCAL))
9729 continue;
9730 /* When fresh value of window-local option is not at the
9731 * default, need to write it too. */
9732 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9733 {
9734 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9735 if (!optval_default(p, varp_fresh))
9736 {
9737 round = 1;
9738 varp_local = varp;
9739 varp = varp_fresh;
9740 }
9741 }
9742 }
9743 }
9744
9745 /* Round 1: fresh value for window-local options.
9746 * Round 2: other values */
9747 for ( ; round <= 2; varp = varp_local, ++round)
9748 {
9749 if (round == 1 || (opt_flags & OPT_GLOBAL))
9750 cmd = "set";
9751 else
9752 cmd = "setlocal";
9753
9754 if (p->flags & P_BOOL)
9755 {
9756 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9757 return FAIL;
9758 }
9759 else if (p->flags & P_NUM)
9760 {
9761 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9762 return FAIL;
9763 }
9764 else /* P_STRING */
9765 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009766#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9767 int do_endif = FALSE;
9768
Bram Moolenaar071d4272004-06-13 20:20:40 +00009769 /* Don't set 'syntax' and 'filetype' again if the value is
9770 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009771 if (
9772# if defined(FEAT_SYN_HL)
9773 p->indir == PV_SYN
9774# if defined(FEAT_AUTOCMD)
9775 ||
9776# endif
9777# endif
9778# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009779 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009780# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009781 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009782 {
9783 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9784 *(char_u **)(varp)) < 0
9785 || put_eol(fd) < 0)
9786 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009787 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009788 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009789#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009790 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9791 (p->flags & P_EXPAND) != 0) == FAIL)
9792 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009793#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9794 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009795 {
9796 if (put_line(fd, "endif") == FAIL)
9797 return FAIL;
9798 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009799#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009800 }
9801 }
9802 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009803 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009804 return OK;
9805}
9806
9807#if defined(FEAT_FOLDING) || defined(PROTO)
9808/*
9809 * Generate set commands for the local fold options only. Used when
9810 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9811 */
9812 int
9813makefoldset(fd)
9814 FILE *fd;
9815{
9816 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9817# ifdef FEAT_EVAL
9818 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9819 == FAIL
9820# endif
9821 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9822 == FAIL
9823 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9824 == FAIL
9825 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9826 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9827 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9828 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9829 )
9830 return FAIL;
9831
9832 return OK;
9833}
9834#endif
9835
9836 static int
9837put_setstring(fd, cmd, name, valuep, expand)
9838 FILE *fd;
9839 char *cmd;
9840 char *name;
9841 char_u **valuep;
9842 int expand;
9843{
9844 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009845 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009846
9847 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9848 return FAIL;
9849 if (*valuep != NULL)
9850 {
9851 /* Output 'pastetoggle' as key names. For other
9852 * options some characters have to be escaped with
9853 * CTRL-V or backslash */
9854 if (valuep == &p_pt)
9855 {
9856 s = *valuep;
9857 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009858 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009859 return FAIL;
9860 }
9861 else if (expand)
9862 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009863 buf = alloc(MAXPATHL);
9864 if (buf == NULL)
9865 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009866 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9867 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009868 {
9869 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009870 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009871 }
9872 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009873 }
9874 else if (put_escstr(fd, *valuep, 2) == FAIL)
9875 return FAIL;
9876 }
9877 if (put_eol(fd) < 0)
9878 return FAIL;
9879 return OK;
9880}
9881
9882 static int
9883put_setnum(fd, cmd, name, valuep)
9884 FILE *fd;
9885 char *cmd;
9886 char *name;
9887 long *valuep;
9888{
9889 long wc;
9890
9891 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9892 return FAIL;
9893 if (wc_use_keyname((char_u *)valuep, &wc))
9894 {
9895 /* print 'wildchar' and 'wildcharm' as a key name */
9896 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9897 return FAIL;
9898 }
9899 else if (fprintf(fd, "%ld", *valuep) < 0)
9900 return FAIL;
9901 if (put_eol(fd) < 0)
9902 return FAIL;
9903 return OK;
9904}
9905
9906 static int
9907put_setbool(fd, cmd, name, value)
9908 FILE *fd;
9909 char *cmd;
9910 char *name;
9911 int value;
9912{
Bram Moolenaar893de922007-10-02 18:40:57 +00009913 if (value < 0) /* global/local option using global value */
9914 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9916 || put_eol(fd) < 0)
9917 return FAIL;
9918 return OK;
9919}
9920
9921/*
9922 * Clear all the terminal options.
9923 * If the option has been allocated, free the memory.
9924 * Terminal options are never hidden or indirect.
9925 */
9926 void
9927clear_termoptions()
9928{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009929 /*
9930 * Reset a few things before clearing the old options. This may cause
9931 * outputting a few things that the terminal doesn't understand, but the
9932 * screen will be cleared later, so this is OK.
9933 */
9934#ifdef FEAT_MOUSE_TTY
9935 mch_setmouse(FALSE); /* switch mouse off */
9936#endif
9937#ifdef FEAT_TITLE
9938 mch_restore_title(3); /* restore window titles */
9939#endif
9940#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9941 /* When starting the GUI close the display opened for the clipboard.
9942 * After restoring the title, because that will need the display. */
9943 if (gui.starting)
9944 clear_xterm_clip();
9945#endif
9946#ifdef WIN3264
9947 /*
9948 * Check if this is allowed now.
9949 */
9950 if (can_end_termcap_mode(FALSE) == TRUE)
9951#endif
9952 stoptermcap(); /* stop termcap mode */
9953
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009954 free_termoptions();
9955}
9956
9957 void
9958free_termoptions()
9959{
9960 struct vimoption *p;
9961
Bram Moolenaar071d4272004-06-13 20:20:40 +00009962 for (p = &options[0]; p->fullname != NULL; p++)
9963 if (istermoption(p))
9964 {
9965 if (p->flags & P_ALLOCED)
9966 free_string_option(*(char_u **)(p->var));
9967 if (p->flags & P_DEF_ALLOCED)
9968 free_string_option(p->def_val[VI_DEFAULT]);
9969 *(char_u **)(p->var) = empty_option;
9970 p->def_val[VI_DEFAULT] = empty_option;
9971 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9972 }
9973 clear_termcodes();
9974}
9975
9976/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009977 * Free the string for one term option, if it was allocated.
9978 * Set the string to empty_option and clear allocated flag.
9979 * "var" points to the option value.
9980 */
9981 void
9982free_one_termoption(var)
9983 char_u *var;
9984{
9985 struct vimoption *p;
9986
9987 for (p = &options[0]; p->fullname != NULL; p++)
9988 if (p->var == var)
9989 {
9990 if (p->flags & P_ALLOCED)
9991 free_string_option(*(char_u **)(p->var));
9992 *(char_u **)(p->var) = empty_option;
9993 p->flags &= ~P_ALLOCED;
9994 break;
9995 }
9996}
9997
9998/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009999 * Set the terminal option defaults to the current value.
10000 * Used after setting the terminal name.
10001 */
10002 void
10003set_term_defaults()
10004{
10005 struct vimoption *p;
10006
10007 for (p = &options[0]; p->fullname != NULL; p++)
10008 {
10009 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10010 {
10011 if (p->flags & P_DEF_ALLOCED)
10012 {
10013 free_string_option(p->def_val[VI_DEFAULT]);
10014 p->flags &= ~P_DEF_ALLOCED;
10015 }
10016 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10017 if (p->flags & P_ALLOCED)
10018 {
10019 p->flags |= P_DEF_ALLOCED;
10020 p->flags &= ~P_ALLOCED; /* don't free the value now */
10021 }
10022 }
10023 }
10024}
10025
10026/*
10027 * return TRUE if 'p' starts with 't_'
10028 */
10029 static int
10030istermoption(p)
10031 struct vimoption *p;
10032{
10033 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10034}
10035
10036/*
10037 * Compute columns for ruler and shown command. 'sc_col' is also used to
10038 * decide what the maximum length of a message on the status line can be.
10039 * If there is a status line for the last window, 'sc_col' is independent
10040 * of 'ru_col'.
10041 */
10042
10043#define COL_RULER 17 /* columns needed by standard ruler */
10044
10045 void
10046comp_col()
10047{
10048#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
10049 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
10050
10051 sc_col = 0;
10052 ru_col = 0;
10053 if (p_ru)
10054 {
10055#ifdef FEAT_STL_OPT
10056 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10057#else
10058 ru_col = COL_RULER + 1;
10059#endif
10060 /* no last status line, adjust sc_col */
10061 if (!last_has_status)
10062 sc_col = ru_col;
10063 }
10064 if (p_sc)
10065 {
10066 sc_col += SHOWCMD_COLS;
10067 if (!p_ru || last_has_status) /* no need for separating space */
10068 ++sc_col;
10069 }
10070 sc_col = Columns - sc_col;
10071 ru_col = Columns - ru_col;
10072 if (sc_col <= 0) /* screen too narrow, will become a mess */
10073 sc_col = 1;
10074 if (ru_col <= 0)
10075 ru_col = 1;
10076#else
10077 sc_col = Columns;
10078 ru_col = Columns;
10079#endif
10080}
10081
10082/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010083 * Unset local option value, similar to ":set opt<".
10084 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010085 void
10086unset_global_local_option(name, from)
10087 char_u *name;
10088 void *from;
10089{
10090 struct vimoption *p;
10091 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010092 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010093
10094 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010095 if (opt_idx < 0)
10096 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010097 p = &(options[opt_idx]);
10098
10099 switch ((int)p->indir)
10100 {
10101 /* global option with local value: use local value if it's been set */
10102 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010103 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010104 break;
10105 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010106 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010107 break;
10108 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010109 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010110 break;
10111 case PV_AR:
10112 buf->b_p_ar = -1;
10113 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010114 case PV_BKC:
10115 clear_string_option(&buf->b_p_bkc);
10116 buf->b_bkc_flags = 0;
10117 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010118 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010119 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010120 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010121 case PV_TC:
10122 clear_string_option(&buf->b_p_tc);
10123 buf->b_tc_flags = 0;
10124 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010125#ifdef FEAT_FIND_ID
10126 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010127 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010128 break;
10129 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010130 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010131 break;
10132#endif
10133#ifdef FEAT_INS_EXPAND
10134 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010135 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010136 break;
10137 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010138 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010139 break;
10140#endif
10141#ifdef FEAT_QUICKFIX
10142 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010143 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010144 break;
10145 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010146 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010147 break;
10148 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010149 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010150 break;
10151#endif
10152#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10153 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010154 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010155 break;
10156#endif
10157#if defined(FEAT_CRYPT)
10158 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010159 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010160 break;
10161#endif
10162#ifdef FEAT_STL_OPT
10163 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010164 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010165 break;
10166#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010167 case PV_UL:
10168 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10169 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010170#ifdef FEAT_LISP
10171 case PV_LW:
10172 clear_string_option(&buf->b_p_lw);
10173 break;
10174#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010175 }
10176}
10177
10178/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179 * Get pointer to option variable, depending on local or global scope.
10180 */
10181 static char_u *
10182get_varp_scope(p, opt_flags)
10183 struct vimoption *p;
10184 int opt_flags;
10185{
10186 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10187 {
10188 if (p->var == VAR_WIN)
10189 return (char_u *)GLOBAL_WO(get_varp(p));
10190 return p->var;
10191 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010192 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 {
10194 switch ((int)p->indir)
10195 {
10196#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010197 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10198 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10199 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010201 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10202 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10203 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010204 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010205 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010206 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010207#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010208 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10209 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010210#endif
10211#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010212 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10213 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010214#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010215#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10216 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10217#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010218#if defined(FEAT_CRYPT)
10219 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10220#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010221#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010222 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010223#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010224 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010225#ifdef FEAT_LISP
10226 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10227#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010228 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229 }
10230 return NULL; /* "cannot happen" */
10231 }
10232 return get_varp(p);
10233}
10234
10235/*
10236 * Get pointer to option variable.
10237 */
10238 static char_u *
10239get_varp(p)
10240 struct vimoption *p;
10241{
10242 /* hidden option, always return NULL */
10243 if (p->var == NULL)
10244 return NULL;
10245
10246 switch ((int)p->indir)
10247 {
10248 case PV_NONE: return p->var;
10249
10250 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010251 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010253 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010254 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010255 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010256 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010257 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010258 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010259 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010261 case PV_TC: return *curbuf->b_p_tc != NUL
10262 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010263 case PV_BKC: return *curbuf->b_p_bkc != NUL
10264 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010265#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010266 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010267 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010268 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010269 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10270#endif
10271#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010272 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010274 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010275 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10276#endif
10277#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010278 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010280 case PV_GP: return *curbuf->b_p_gp != NUL
10281 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10282 case PV_MP: return *curbuf->b_p_mp != NUL
10283 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010284#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010285#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10286 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10287 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10288#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010289#if defined(FEAT_CRYPT)
10290 case PV_CM: return *curbuf->b_p_cm != NUL
10291 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10292#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010293#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010294 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010295 ? (char_u *)&(curwin->w_p_stl) : p->var;
10296#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010297 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10298 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010299#ifdef FEAT_LISP
10300 case PV_LW: return *curbuf->b_p_lw != NUL
10301 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10302#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303
10304#ifdef FEAT_ARABIC
10305 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10306#endif
10307 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010308#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010309 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10310#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010311#ifdef FEAT_SYN_HL
10312 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10313 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010314 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010315#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010316#ifdef FEAT_DIFF
10317 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10318#endif
10319#ifdef FEAT_FOLDING
10320 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10321 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10322 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10323 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10324 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10325 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10326 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10327# ifdef FEAT_EVAL
10328 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10329 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10330# endif
10331 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10332#endif
10333 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010334 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010335#ifdef FEAT_LINEBREAK
10336 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10337#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010338#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010339 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10340#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010341#ifdef FEAT_VERTSPLIT
10342 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10345 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10346#endif
10347#ifdef FEAT_RIGHTLEFT
10348 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10349 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10350#endif
10351 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10352 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10353#ifdef FEAT_LINEBREAK
10354 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010355 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10356 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357#endif
10358#ifdef FEAT_SCROLLBIND
10359 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10360#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010361#ifdef FEAT_CURSORBIND
10362 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10363#endif
10364#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010365 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10366 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010367#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010368
10369 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10370 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10371#ifdef FEAT_MBYTE
10372 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10373#endif
10374#if defined(FEAT_QUICKFIX)
10375 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10376 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10377#endif
10378 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10379 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10380#ifdef FEAT_CINDENT
10381 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10382 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10383 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10384#endif
10385#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10386 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10387#endif
10388#ifdef FEAT_COMMENTS
10389 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10390#endif
10391#ifdef FEAT_FOLDING
10392 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10393#endif
10394#ifdef FEAT_INS_EXPAND
10395 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10396#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010397#ifdef FEAT_COMPL_FUNC
10398 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010399 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010402 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10404#ifdef FEAT_MBYTE
10405 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10406#endif
10407 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10408#ifdef FEAT_AUTOCMD
10409 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10410#endif
10411 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010412 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10414 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10415 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10416 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10417#ifdef FEAT_FIND_ID
10418# ifdef FEAT_EVAL
10419 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10420# endif
10421#endif
10422#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10423 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10424 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10425#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010426#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010427 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10428#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429#ifdef FEAT_CRYPT
10430 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10431#endif
10432#ifdef FEAT_LISP
10433 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10434#endif
10435 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10436 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10437 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10438 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10439 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010440 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010441#ifdef FEAT_TEXTOBJ
10442 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10443#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010444 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10445#ifdef FEAT_SMARTINDENT
10446 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10447#endif
10448#ifndef SHORT_FNAME
10449 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10450#endif
10451 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10452#ifdef FEAT_SEARCHPATH
10453 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10454#endif
10455 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10456#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010457 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010458 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10459#endif
10460#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010461 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10462 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10463 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010464#endif
10465 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10466 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10467 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10468 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010469#ifdef FEAT_PERSISTENT_UNDO
10470 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10471#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10473#ifdef FEAT_KEYMAP
10474 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10475#endif
10476 default: EMSG(_("E356: get_varp ERROR"));
10477 }
10478 /* always return a valid pointer to avoid a crash! */
10479 return (char_u *)&(curbuf->b_p_wm);
10480}
10481
10482/*
10483 * Get the value of 'equalprg', either the buffer-local one or the global one.
10484 */
10485 char_u *
10486get_equalprg()
10487{
10488 if (*curbuf->b_p_ep == NUL)
10489 return p_ep;
10490 return curbuf->b_p_ep;
10491}
10492
10493#if defined(FEAT_WINDOWS) || defined(PROTO)
10494/*
10495 * Copy options from one window to another.
10496 * Used when splitting a window.
10497 */
10498 void
10499win_copy_options(wp_from, wp_to)
10500 win_T *wp_from;
10501 win_T *wp_to;
10502{
10503 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10504 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10505# ifdef FEAT_RIGHTLEFT
10506# ifdef FEAT_FKMAP
10507 /* Is this right? */
10508 wp_to->w_farsi = wp_from->w_farsi;
10509# endif
10510# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010511#if defined(FEAT_LINEBREAK)
10512 briopt_check(wp_to);
10513#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010514}
10515#endif
10516
10517/*
10518 * Copy the options from one winopt_T to another.
10519 * Doesn't free the old option values in "to", use clear_winopt() for that.
10520 * The 'scroll' option is not copied, because it depends on the window height.
10521 * The 'previewwindow' option is reset, there can be only one preview window.
10522 */
10523 void
10524copy_winopt(from, to)
10525 winopt_T *from;
10526 winopt_T *to;
10527{
10528#ifdef FEAT_ARABIC
10529 to->wo_arab = from->wo_arab;
10530#endif
10531 to->wo_list = from->wo_list;
10532 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010533 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010534#ifdef FEAT_LINEBREAK
10535 to->wo_nuw = from->wo_nuw;
10536#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537#ifdef FEAT_RIGHTLEFT
10538 to->wo_rl = from->wo_rl;
10539 to->wo_rlc = vim_strsave(from->wo_rlc);
10540#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010541#ifdef FEAT_STL_OPT
10542 to->wo_stl = vim_strsave(from->wo_stl);
10543#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010545#ifdef FEAT_DIFF
10546 to->wo_wrap_save = from->wo_wrap_save;
10547#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548#ifdef FEAT_LINEBREAK
10549 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010550 to->wo_bri = from->wo_bri;
10551 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552#endif
10553#ifdef FEAT_SCROLLBIND
10554 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010555 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010557#ifdef FEAT_CURSORBIND
10558 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010559 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010560#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010561#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010562 to->wo_spell = from->wo_spell;
10563#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010564#ifdef FEAT_SYN_HL
10565 to->wo_cuc = from->wo_cuc;
10566 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010567 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010568#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569#ifdef FEAT_DIFF
10570 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010571 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010573#ifdef FEAT_CONCEAL
10574 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010575 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010576#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577#ifdef FEAT_FOLDING
10578 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010579 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010581 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582 to->wo_fdi = vim_strsave(from->wo_fdi);
10583 to->wo_fml = from->wo_fml;
10584 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010585 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010587 to->wo_fdm_save = from->wo_diff_saved
10588 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 to->wo_fdn = from->wo_fdn;
10590# ifdef FEAT_EVAL
10591 to->wo_fde = vim_strsave(from->wo_fde);
10592 to->wo_fdt = vim_strsave(from->wo_fdt);
10593# endif
10594 to->wo_fmr = vim_strsave(from->wo_fmr);
10595#endif
10596 check_winopt(to); /* don't want NULL pointers */
10597}
10598
10599/*
10600 * Check string options in a window for a NULL value.
10601 */
10602 void
10603check_win_options(win)
10604 win_T *win;
10605{
10606 check_winopt(&win->w_onebuf_opt);
10607 check_winopt(&win->w_allbuf_opt);
10608}
10609
10610/*
10611 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10612 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010613 static void
Bram Moolenaar071d4272004-06-13 20:20:40 +000010614check_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010615 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616{
10617#ifdef FEAT_FOLDING
10618 check_string_option(&wop->wo_fdi);
10619 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010620 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621# ifdef FEAT_EVAL
10622 check_string_option(&wop->wo_fde);
10623 check_string_option(&wop->wo_fdt);
10624# endif
10625 check_string_option(&wop->wo_fmr);
10626#endif
10627#ifdef FEAT_RIGHTLEFT
10628 check_string_option(&wop->wo_rlc);
10629#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010630#ifdef FEAT_STL_OPT
10631 check_string_option(&wop->wo_stl);
10632#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010633#ifdef FEAT_SYN_HL
10634 check_string_option(&wop->wo_cc);
10635#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010636#ifdef FEAT_CONCEAL
10637 check_string_option(&wop->wo_cocu);
10638#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010639#ifdef FEAT_LINEBREAK
10640 check_string_option(&wop->wo_briopt);
10641#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642}
10643
10644/*
10645 * Free the allocated memory inside a winopt_T.
10646 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647 void
10648clear_winopt(wop)
Bram Moolenaar78a15312009-05-15 19:33:18 +000010649 winopt_T *wop UNUSED;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010650{
10651#ifdef FEAT_FOLDING
10652 clear_string_option(&wop->wo_fdi);
10653 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010654 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655# ifdef FEAT_EVAL
10656 clear_string_option(&wop->wo_fde);
10657 clear_string_option(&wop->wo_fdt);
10658# endif
10659 clear_string_option(&wop->wo_fmr);
10660#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010661#ifdef FEAT_LINEBREAK
10662 clear_string_option(&wop->wo_briopt);
10663#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010664#ifdef FEAT_RIGHTLEFT
10665 clear_string_option(&wop->wo_rlc);
10666#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010667#ifdef FEAT_STL_OPT
10668 clear_string_option(&wop->wo_stl);
10669#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010670#ifdef FEAT_SYN_HL
10671 clear_string_option(&wop->wo_cc);
10672#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010673#ifdef FEAT_CONCEAL
10674 clear_string_option(&wop->wo_cocu);
10675#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010676}
10677
10678/*
10679 * Copy global option values to local options for one buffer.
10680 * Used when creating a new buffer and sometimes when entering a buffer.
10681 * flags:
10682 * BCO_ENTER We will enter the buf buffer.
10683 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10684 * appropriate.
10685 * BCO_NOHELP Don't copy the values to a help buffer.
10686 */
10687 void
10688buf_copy_options(buf, flags)
10689 buf_T *buf;
10690 int flags;
10691{
10692 int should_copy = TRUE;
10693 char_u *save_p_isk = NULL; /* init for GCC */
10694 int dont_do_help;
10695 int did_isk = FALSE;
10696
10697 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010698 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699 */
10700 if (buf == NULL || !buf_valid(buf))
10701 return;
10702
10703 /*
10704 * Skip this when the option defaults have not been set yet. Happens when
10705 * main() allocates the first buffer.
10706 */
10707 if (p_cpo != NULL)
10708 {
10709 /*
10710 * Always copy when entering and 'cpo' contains 'S'.
10711 * Don't copy when already initialized.
10712 * Don't copy when 'cpo' contains 's' and not entering.
10713 * 'S' BCO_ENTER initialized 's' should_copy
10714 * yes yes X X TRUE
10715 * yes no yes X FALSE
10716 * no X yes X FALSE
10717 * X no no yes FALSE
10718 * X no no no TRUE
10719 * no yes no X TRUE
10720 */
10721 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10722 && (buf->b_p_initialized
10723 || (!(flags & BCO_ENTER)
10724 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10725 should_copy = FALSE;
10726
10727 if (should_copy || (flags & BCO_ALWAYS))
10728 {
10729 /* Don't copy the options specific to a help buffer when
10730 * BCO_NOHELP is given or the options were initialized already
10731 * (jumping back to a help file with CTRL-T or CTRL-O) */
10732 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10733 || buf->b_p_initialized;
10734 if (dont_do_help) /* don't free b_p_isk */
10735 {
10736 save_p_isk = buf->b_p_isk;
10737 buf->b_p_isk = NULL;
10738 }
10739 /*
10740 * Always free the allocated strings.
10741 * If not already initialized, set 'readonly' and copy 'fileformat'.
10742 */
10743 if (!buf->b_p_initialized)
10744 {
10745 free_buf_options(buf, TRUE);
10746 buf->b_p_ro = FALSE; /* don't copy readonly */
10747 buf->b_p_tx = p_tx;
10748#ifdef FEAT_MBYTE
10749 buf->b_p_fenc = vim_strsave(p_fenc);
10750#endif
10751 buf->b_p_ff = vim_strsave(p_ff);
10752#if defined(FEAT_QUICKFIX)
10753 buf->b_p_bh = empty_option;
10754 buf->b_p_bt = empty_option;
10755#endif
10756 }
10757 else
10758 free_buf_options(buf, FALSE);
10759
10760 buf->b_p_ai = p_ai;
10761 buf->b_p_ai_nopaste = p_ai_nopaste;
10762 buf->b_p_sw = p_sw;
10763 buf->b_p_tw = p_tw;
10764 buf->b_p_tw_nopaste = p_tw_nopaste;
10765 buf->b_p_tw_nobin = p_tw_nobin;
10766 buf->b_p_wm = p_wm;
10767 buf->b_p_wm_nopaste = p_wm_nopaste;
10768 buf->b_p_wm_nobin = p_wm_nobin;
10769 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010770#ifdef FEAT_MBYTE
10771 buf->b_p_bomb = p_bomb;
10772#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010773 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 buf->b_p_et = p_et;
10775 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010776 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777 buf->b_p_ml = p_ml;
10778 buf->b_p_ml_nobin = p_ml_nobin;
10779 buf->b_p_inf = p_inf;
10780 buf->b_p_swf = p_swf;
10781#ifdef FEAT_INS_EXPAND
10782 buf->b_p_cpt = vim_strsave(p_cpt);
10783#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010784#ifdef FEAT_COMPL_FUNC
10785 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010786 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010787#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788 buf->b_p_sts = p_sts;
10789 buf->b_p_sts_nopaste = p_sts_nopaste;
10790#ifndef SHORT_FNAME
10791 buf->b_p_sn = p_sn;
10792#endif
10793#ifdef FEAT_COMMENTS
10794 buf->b_p_com = vim_strsave(p_com);
10795#endif
10796#ifdef FEAT_FOLDING
10797 buf->b_p_cms = vim_strsave(p_cms);
10798#endif
10799 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010800 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801 buf->b_p_nf = vim_strsave(p_nf);
10802 buf->b_p_mps = vim_strsave(p_mps);
10803#ifdef FEAT_SMARTINDENT
10804 buf->b_p_si = p_si;
10805#endif
10806 buf->b_p_ci = p_ci;
10807#ifdef FEAT_CINDENT
10808 buf->b_p_cin = p_cin;
10809 buf->b_p_cink = vim_strsave(p_cink);
10810 buf->b_p_cino = vim_strsave(p_cino);
10811#endif
10812#ifdef FEAT_AUTOCMD
10813 /* Don't copy 'filetype', it must be detected */
10814 buf->b_p_ft = empty_option;
10815#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010816 buf->b_p_pi = p_pi;
10817#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10818 buf->b_p_cinw = vim_strsave(p_cinw);
10819#endif
10820#ifdef FEAT_LISP
10821 buf->b_p_lisp = p_lisp;
10822#endif
10823#ifdef FEAT_SYN_HL
10824 /* Don't copy 'syntax', it must be set */
10825 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010826 buf->b_p_smc = p_smc;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010827#endif
10828#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010829 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010830 (void)compile_cap_prog(&buf->b_s);
10831 buf->b_s.b_p_spf = vim_strsave(p_spf);
10832 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010833#endif
10834#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10835 buf->b_p_inde = vim_strsave(p_inde);
10836 buf->b_p_indk = vim_strsave(p_indk);
10837#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010838#if defined(FEAT_EVAL)
10839 buf->b_p_fex = vim_strsave(p_fex);
10840#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010841#ifdef FEAT_CRYPT
10842 buf->b_p_key = vim_strsave(p_key);
10843#endif
10844#ifdef FEAT_SEARCHPATH
10845 buf->b_p_sua = vim_strsave(p_sua);
10846#endif
10847#ifdef FEAT_KEYMAP
10848 buf->b_p_keymap = vim_strsave(p_keymap);
10849 buf->b_kmap_state |= KEYMAP_INIT;
10850#endif
10851 /* This isn't really an option, but copying the langmap and IME
10852 * state from the current buffer is better than resetting it. */
10853 buf->b_p_iminsert = p_iminsert;
10854 buf->b_p_imsearch = p_imsearch;
10855
10856 /* options that are normally global but also have a local value
10857 * are not copied, start using the global value */
10858 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010859 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010860 buf->b_p_bkc = empty_option;
10861 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862#ifdef FEAT_QUICKFIX
10863 buf->b_p_gp = empty_option;
10864 buf->b_p_mp = empty_option;
10865 buf->b_p_efm = empty_option;
10866#endif
10867 buf->b_p_ep = empty_option;
10868 buf->b_p_kp = empty_option;
10869 buf->b_p_path = empty_option;
10870 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010871 buf->b_p_tc = empty_option;
10872 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010873#ifdef FEAT_FIND_ID
10874 buf->b_p_def = empty_option;
10875 buf->b_p_inc = empty_option;
10876# ifdef FEAT_EVAL
10877 buf->b_p_inex = vim_strsave(p_inex);
10878# endif
10879#endif
10880#ifdef FEAT_INS_EXPAND
10881 buf->b_p_dict = empty_option;
10882 buf->b_p_tsr = empty_option;
10883#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010884#ifdef FEAT_TEXTOBJ
10885 buf->b_p_qe = vim_strsave(p_qe);
10886#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010887#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10888 buf->b_p_bexpr = empty_option;
10889#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010890#if defined(FEAT_CRYPT)
10891 buf->b_p_cm = empty_option;
10892#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010893#ifdef FEAT_PERSISTENT_UNDO
10894 buf->b_p_udf = p_udf;
10895#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010896#ifdef FEAT_LISP
10897 buf->b_p_lw = empty_option;
10898#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010899
10900 /*
10901 * Don't copy the options set by ex_help(), use the saved values,
10902 * when going from a help buffer to a non-help buffer.
10903 * Don't touch these at all when BCO_NOHELP is used and going from
10904 * or to a help buffer.
10905 */
10906 if (dont_do_help)
10907 buf->b_p_isk = save_p_isk;
10908 else
10909 {
10910 buf->b_p_isk = vim_strsave(p_isk);
10911 did_isk = TRUE;
10912 buf->b_p_ts = p_ts;
10913 buf->b_help = FALSE;
10914#ifdef FEAT_QUICKFIX
10915 if (buf->b_p_bt[0] == 'h')
10916 clear_string_option(&buf->b_p_bt);
10917#endif
10918 buf->b_p_ma = p_ma;
10919 }
10920 }
10921
10922 /*
10923 * When the options should be copied (ignoring BCO_ALWAYS), set the
10924 * flag that indicates that the options have been initialized.
10925 */
10926 if (should_copy)
10927 buf->b_p_initialized = TRUE;
10928 }
10929
10930 check_buf_options(buf); /* make sure we don't have NULLs */
10931 if (did_isk)
10932 (void)buf_init_chartab(buf, FALSE);
10933}
10934
10935/*
10936 * Reset the 'modifiable' option and its default value.
10937 */
10938 void
10939reset_modifiable()
10940{
10941 int opt_idx;
10942
10943 curbuf->b_p_ma = FALSE;
10944 p_ma = FALSE;
10945 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010946 if (opt_idx >= 0)
10947 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010948}
10949
10950/*
10951 * Set the global value for 'iminsert' to the local value.
10952 */
10953 void
10954set_iminsert_global()
10955{
10956 p_iminsert = curbuf->b_p_iminsert;
10957}
10958
10959/*
10960 * Set the global value for 'imsearch' to the local value.
10961 */
10962 void
10963set_imsearch_global()
10964{
10965 p_imsearch = curbuf->b_p_imsearch;
10966}
10967
10968#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10969static int expand_option_idx = -1;
10970static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10971static int expand_option_flags = 0;
10972
10973 void
10974set_context_in_set_cmd(xp, arg, opt_flags)
10975 expand_T *xp;
10976 char_u *arg;
10977 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
10978{
10979 int nextchar;
10980 long_u flags = 0; /* init for GCC */
10981 int opt_idx = 0; /* init for GCC */
10982 char_u *p;
10983 char_u *s;
10984 int is_term_option = FALSE;
10985 int key;
10986
10987 expand_option_flags = opt_flags;
10988
10989 xp->xp_context = EXPAND_SETTINGS;
10990 if (*arg == NUL)
10991 {
10992 xp->xp_pattern = arg;
10993 return;
10994 }
10995 p = arg + STRLEN(arg) - 1;
10996 if (*p == ' ' && *(p - 1) != '\\')
10997 {
10998 xp->xp_pattern = p + 1;
10999 return;
11000 }
11001 while (p > arg)
11002 {
11003 s = p;
11004 /* count number of backslashes before ' ' or ',' */
11005 if (*p == ' ' || *p == ',')
11006 {
11007 while (s > arg && *(s - 1) == '\\')
11008 --s;
11009 }
11010 /* break at a space with an even number of backslashes */
11011 if (*p == ' ' && ((p - s) & 1) == 0)
11012 {
11013 ++p;
11014 break;
11015 }
11016 --p;
11017 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011018 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011019 {
11020 xp->xp_context = EXPAND_BOOL_SETTINGS;
11021 p += 2;
11022 }
11023 if (STRNCMP(p, "inv", 3) == 0)
11024 {
11025 xp->xp_context = EXPAND_BOOL_SETTINGS;
11026 p += 3;
11027 }
11028 xp->xp_pattern = arg = p;
11029 if (*arg == '<')
11030 {
11031 while (*p != '>')
11032 if (*p++ == NUL) /* expand terminal option name */
11033 return;
11034 key = get_special_key_code(arg + 1);
11035 if (key == 0) /* unknown name */
11036 {
11037 xp->xp_context = EXPAND_NOTHING;
11038 return;
11039 }
11040 nextchar = *++p;
11041 is_term_option = TRUE;
11042 expand_option_name[2] = KEY2TERMCAP0(key);
11043 expand_option_name[3] = KEY2TERMCAP1(key);
11044 }
11045 else
11046 {
11047 if (p[0] == 't' && p[1] == '_')
11048 {
11049 p += 2;
11050 if (*p != NUL)
11051 ++p;
11052 if (*p == NUL)
11053 return; /* expand option name */
11054 nextchar = *++p;
11055 is_term_option = TRUE;
11056 expand_option_name[2] = p[-2];
11057 expand_option_name[3] = p[-1];
11058 }
11059 else
11060 {
11061 /* Allow * wildcard */
11062 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11063 p++;
11064 if (*p == NUL)
11065 return;
11066 nextchar = *p;
11067 *p = NUL;
11068 opt_idx = findoption(arg);
11069 *p = nextchar;
11070 if (opt_idx == -1 || options[opt_idx].var == NULL)
11071 {
11072 xp->xp_context = EXPAND_NOTHING;
11073 return;
11074 }
11075 flags = options[opt_idx].flags;
11076 if (flags & P_BOOL)
11077 {
11078 xp->xp_context = EXPAND_NOTHING;
11079 return;
11080 }
11081 }
11082 }
11083 /* handle "-=" and "+=" */
11084 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11085 {
11086 ++p;
11087 nextchar = '=';
11088 }
11089 if ((nextchar != '=' && nextchar != ':')
11090 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11091 {
11092 xp->xp_context = EXPAND_UNSUCCESSFUL;
11093 return;
11094 }
11095 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11096 {
11097 xp->xp_context = EXPAND_OLD_SETTING;
11098 if (is_term_option)
11099 expand_option_idx = -1;
11100 else
11101 expand_option_idx = opt_idx;
11102 xp->xp_pattern = p + 1;
11103 return;
11104 }
11105 xp->xp_context = EXPAND_NOTHING;
11106 if (is_term_option || (flags & P_NUM))
11107 return;
11108
11109 xp->xp_pattern = p + 1;
11110
11111 if (flags & P_EXPAND)
11112 {
11113 p = options[opt_idx].var;
11114 if (p == (char_u *)&p_bdir
11115 || p == (char_u *)&p_dir
11116 || p == (char_u *)&p_path
11117 || p == (char_u *)&p_rtp
11118#ifdef FEAT_SEARCHPATH
11119 || p == (char_u *)&p_cdpath
11120#endif
11121#ifdef FEAT_SESSION
11122 || p == (char_u *)&p_vdir
11123#endif
11124 )
11125 {
11126 xp->xp_context = EXPAND_DIRECTORIES;
11127 if (p == (char_u *)&p_path
11128#ifdef FEAT_SEARCHPATH
11129 || p == (char_u *)&p_cdpath
11130#endif
11131 )
11132 xp->xp_backslash = XP_BS_THREE;
11133 else
11134 xp->xp_backslash = XP_BS_ONE;
11135 }
11136 else
11137 {
11138 xp->xp_context = EXPAND_FILES;
11139 /* for 'tags' need three backslashes for a space */
11140 if (p == (char_u *)&p_tags)
11141 xp->xp_backslash = XP_BS_THREE;
11142 else
11143 xp->xp_backslash = XP_BS_ONE;
11144 }
11145 }
11146
11147 /* For an option that is a list of file names, find the start of the
11148 * last file name. */
11149 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11150 {
11151 /* count number of backslashes before ' ' or ',' */
11152 if (*p == ' ' || *p == ',')
11153 {
11154 s = p;
11155 while (s > xp->xp_pattern && *(s - 1) == '\\')
11156 --s;
11157 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11158 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11159 {
11160 xp->xp_pattern = p + 1;
11161 break;
11162 }
11163 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011164
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011165#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011166 /* for 'spellsuggest' start at "file:" */
11167 if (options[opt_idx].var == (char_u *)&p_sps
11168 && STRNCMP(p, "file:", 5) == 0)
11169 {
11170 xp->xp_pattern = p + 5;
11171 break;
11172 }
11173#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011174 }
11175
11176 return;
11177}
11178
11179 int
11180ExpandSettings(xp, regmatch, num_file, file)
11181 expand_T *xp;
11182 regmatch_T *regmatch;
11183 int *num_file;
11184 char_u ***file;
11185{
11186 int num_normal = 0; /* Nr of matching non-term-code settings */
11187 int num_term = 0; /* Nr of matching terminal code settings */
11188 int opt_idx;
11189 int match;
11190 int count = 0;
11191 char_u *str;
11192 int loop;
11193 int is_term_opt;
11194 char_u name_buf[MAX_KEY_NAME_LEN];
11195 static char *(names[]) = {"all", "termcap"};
11196 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11197
11198 /* do this loop twice:
11199 * loop == 0: count the number of matching options
11200 * loop == 1: copy the matching options into allocated memory
11201 */
11202 for (loop = 0; loop <= 1; ++loop)
11203 {
11204 regmatch->rm_ic = ic;
11205 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11206 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011207 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11208 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011209 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11210 {
11211 if (loop == 0)
11212 num_normal++;
11213 else
11214 (*file)[count++] = vim_strsave((char_u *)names[match]);
11215 }
11216 }
11217 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11218 opt_idx++)
11219 {
11220 if (options[opt_idx].var == NULL)
11221 continue;
11222 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11223 && !(options[opt_idx].flags & P_BOOL))
11224 continue;
11225 is_term_opt = istermoption(&options[opt_idx]);
11226 if (is_term_opt && num_normal > 0)
11227 continue;
11228 match = FALSE;
11229 if (vim_regexec(regmatch, str, (colnr_T)0)
11230 || (options[opt_idx].shortname != NULL
11231 && vim_regexec(regmatch,
11232 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11233 match = TRUE;
11234 else if (is_term_opt)
11235 {
11236 name_buf[0] = '<';
11237 name_buf[1] = 't';
11238 name_buf[2] = '_';
11239 name_buf[3] = str[2];
11240 name_buf[4] = str[3];
11241 name_buf[5] = '>';
11242 name_buf[6] = NUL;
11243 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11244 {
11245 match = TRUE;
11246 str = name_buf;
11247 }
11248 }
11249 if (match)
11250 {
11251 if (loop == 0)
11252 {
11253 if (is_term_opt)
11254 num_term++;
11255 else
11256 num_normal++;
11257 }
11258 else
11259 (*file)[count++] = vim_strsave(str);
11260 }
11261 }
11262 /*
11263 * Check terminal key codes, these are not in the option table
11264 */
11265 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11266 {
11267 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11268 {
11269 if (!isprint(str[0]) || !isprint(str[1]))
11270 continue;
11271
11272 name_buf[0] = 't';
11273 name_buf[1] = '_';
11274 name_buf[2] = str[0];
11275 name_buf[3] = str[1];
11276 name_buf[4] = NUL;
11277
11278 match = FALSE;
11279 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11280 match = TRUE;
11281 else
11282 {
11283 name_buf[0] = '<';
11284 name_buf[1] = 't';
11285 name_buf[2] = '_';
11286 name_buf[3] = str[0];
11287 name_buf[4] = str[1];
11288 name_buf[5] = '>';
11289 name_buf[6] = NUL;
11290
11291 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11292 match = TRUE;
11293 }
11294 if (match)
11295 {
11296 if (loop == 0)
11297 num_term++;
11298 else
11299 (*file)[count++] = vim_strsave(name_buf);
11300 }
11301 }
11302
11303 /*
11304 * Check special key names.
11305 */
11306 regmatch->rm_ic = TRUE; /* ignore case here */
11307 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11308 {
11309 name_buf[0] = '<';
11310 STRCPY(name_buf + 1, str);
11311 STRCAT(name_buf, ">");
11312
11313 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11314 {
11315 if (loop == 0)
11316 num_term++;
11317 else
11318 (*file)[count++] = vim_strsave(name_buf);
11319 }
11320 }
11321 }
11322 if (loop == 0)
11323 {
11324 if (num_normal > 0)
11325 *num_file = num_normal;
11326 else if (num_term > 0)
11327 *num_file = num_term;
11328 else
11329 return OK;
11330 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11331 if (*file == NULL)
11332 {
11333 *file = (char_u **)"";
11334 return FAIL;
11335 }
11336 }
11337 }
11338 return OK;
11339}
11340
11341 int
11342ExpandOldSetting(num_file, file)
11343 int *num_file;
11344 char_u ***file;
11345{
11346 char_u *var = NULL; /* init for GCC */
11347 char_u *buf;
11348
11349 *num_file = 0;
11350 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11351 if (*file == NULL)
11352 return FAIL;
11353
11354 /*
11355 * For a terminal key code expand_option_idx is < 0.
11356 */
11357 if (expand_option_idx < 0)
11358 {
11359 var = find_termcode(expand_option_name + 2);
11360 if (var == NULL)
11361 expand_option_idx = findoption(expand_option_name);
11362 }
11363
11364 if (expand_option_idx >= 0)
11365 {
11366 /* put string of option value in NameBuff */
11367 option_value2string(&options[expand_option_idx], expand_option_flags);
11368 var = NameBuff;
11369 }
11370 else if (var == NULL)
11371 var = (char_u *)"";
11372
11373 /* A backslash is required before some characters. This is the reverse of
11374 * what happens in do_set(). */
11375 buf = vim_strsave_escaped(var, escape_chars);
11376
11377 if (buf == NULL)
11378 {
11379 vim_free(*file);
11380 *file = NULL;
11381 return FAIL;
11382 }
11383
11384#ifdef BACKSLASH_IN_FILENAME
11385 /* For MS-Windows et al. we don't double backslashes at the start and
11386 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011387 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388 if (var[0] == '\\' && var[1] == '\\'
11389 && expand_option_idx >= 0
11390 && (options[expand_option_idx].flags & P_EXPAND)
11391 && vim_isfilec(var[2])
11392 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011393 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011394#endif
11395
11396 *file[0] = buf;
11397 *num_file = 1;
11398 return OK;
11399}
11400#endif
11401
11402/*
11403 * Get the value for the numeric or string option *opp in a nice format into
11404 * NameBuff[]. Must not be called with a hidden option!
11405 */
11406 static void
11407option_value2string(opp, opt_flags)
11408 struct vimoption *opp;
11409 int opt_flags; /* OPT_GLOBAL and/or OPT_LOCAL */
11410{
11411 char_u *varp;
11412
11413 varp = get_varp_scope(opp, opt_flags);
11414
11415 if (opp->flags & P_NUM)
11416 {
11417 long wc = 0;
11418
11419 if (wc_use_keyname(varp, &wc))
11420 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11421 else if (wc != 0)
11422 STRCPY(NameBuff, transchar((int)wc));
11423 else
11424 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11425 }
11426 else /* P_STRING */
11427 {
11428 varp = *(char_u **)(varp);
11429 if (varp == NULL) /* just in case */
11430 NameBuff[0] = NUL;
11431#ifdef FEAT_CRYPT
11432 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011433 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011434 STRCPY(NameBuff, "*****");
11435#endif
11436 else if (opp->flags & P_EXPAND)
11437 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11438 /* Translate 'pastetoggle' into special key names */
11439 else if ((char_u **)opp->var == &p_pt)
11440 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11441 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011442 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011443 }
11444}
11445
11446/*
11447 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11448 * printed as a keyname.
11449 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11450 */
11451 static int
11452wc_use_keyname(varp, wcp)
11453 char_u *varp;
11454 long *wcp;
11455{
11456 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11457 {
11458 *wcp = *(long *)varp;
11459 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11460 return TRUE;
11461 }
11462 return FALSE;
11463}
11464
Bram Moolenaar01615492015-02-03 13:00:38 +010011465#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011466/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011467 * Any character has an equivalent 'langmap' character. This is used for
11468 * keyboards that have a special language mode that sends characters above
11469 * 128 (although other characters can be translated too). The "to" field is a
11470 * Vim command character. This avoids having to switch the keyboard back to
11471 * ASCII mode when leaving Insert mode.
11472 *
11473 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11474 * commands.
11475 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11476 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11477 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011478 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011479# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011480/*
11481 * With multi-byte support use growarray for 'langmap' chars >= 256
11482 */
11483typedef struct
11484{
11485 int from;
11486 int to;
11487} langmap_entry_T;
11488
11489static garray_T langmap_mapga;
11490static void langmap_set_entry __ARGS((int from, int to));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491
11492/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011493 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11494 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011495 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011496 static void
11497langmap_set_entry(from, to)
11498 int from;
11499 int to;
11500{
11501 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011502 int a = 0;
11503 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011504
11505 /* Do a binary search for an existing entry. */
11506 while (a != b)
11507 {
11508 int i = (a + b) / 2;
11509 int d = entries[i].from - from;
11510
11511 if (d == 0)
11512 {
11513 entries[i].to = to;
11514 return;
11515 }
11516 if (d < 0)
11517 a = i + 1;
11518 else
11519 b = i;
11520 }
11521
11522 if (ga_grow(&langmap_mapga, 1) != OK)
11523 return; /* out of memory */
11524
11525 /* insert new entry at position "a" */
11526 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11527 mch_memmove(entries + 1, entries,
11528 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11529 ++langmap_mapga.ga_len;
11530 entries[0].from = from;
11531 entries[0].to = to;
11532}
11533
11534/*
11535 * Apply 'langmap' to multi-byte character "c" and return the result.
11536 */
11537 int
11538langmap_adjust_mb(c)
11539 int c;
11540{
11541 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11542 int a = 0;
11543 int b = langmap_mapga.ga_len;
11544
11545 while (a != b)
11546 {
11547 int i = (a + b) / 2;
11548 int d = entries[i].from - c;
11549
11550 if (d == 0)
11551 return entries[i].to; /* found matching entry */
11552 if (d < 0)
11553 a = i + 1;
11554 else
11555 b = i;
11556 }
11557 return c; /* no entry found, return "c" unmodified */
11558}
11559# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011560
11561 static void
11562langmap_init()
11563{
11564 int i;
11565
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011566 for (i = 0; i < 256; i++)
11567 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11568# ifdef FEAT_MBYTE
11569 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11570# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011571}
11572
11573/*
11574 * Called when langmap option is set; the language map can be
11575 * changed at any time!
11576 */
11577 static void
11578langmap_set()
11579{
11580 char_u *p;
11581 char_u *p2;
11582 int from, to;
11583
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011584#ifdef FEAT_MBYTE
11585 ga_clear(&langmap_mapga); /* clear the previous map first */
11586#endif
11587 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011588
11589 for (p = p_langmap; p[0] != NUL; )
11590 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011591 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11592 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011593 {
11594 if (p2[0] == '\\' && p2[1] != NUL)
11595 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011596 }
11597 if (p2[0] == ';')
11598 ++p2; /* abcd;ABCD form, p2 points to A */
11599 else
11600 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11601 while (p[0])
11602 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011603 if (p[0] == ',')
11604 {
11605 ++p;
11606 break;
11607 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011608 if (p[0] == '\\' && p[1] != NUL)
11609 ++p;
11610#ifdef FEAT_MBYTE
11611 from = (*mb_ptr2char)(p);
11612#else
11613 from = p[0];
11614#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011615 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616 if (p2 == NULL)
11617 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011618 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011619 if (p[0] != ',')
11620 {
11621 if (p[0] == '\\')
11622 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011624 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011625#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011626 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011627#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011628 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011629 }
11630 else
11631 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011632 if (p2[0] != ',')
11633 {
11634 if (p2[0] == '\\')
11635 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011636#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011637 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011638#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011639 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011641 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011642 }
11643 if (to == NUL)
11644 {
11645 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11646 transchar(from));
11647 return;
11648 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011649
11650#ifdef FEAT_MBYTE
11651 if (from >= 256)
11652 langmap_set_entry(from, to);
11653 else
11654#endif
11655 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011656
11657 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011658 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011659 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011660 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011661 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011662 if (*p == ';')
11663 {
11664 p = p2;
11665 if (p[0] != NUL)
11666 {
11667 if (p[0] != ',')
11668 {
11669 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11670 return;
11671 }
11672 ++p;
11673 }
11674 break;
11675 }
11676 }
11677 }
11678 }
11679}
11680#endif
11681
11682/*
11683 * Return TRUE if format option 'x' is in effect.
11684 * Take care of no formatting when 'paste' is set.
11685 */
11686 int
11687has_format_option(x)
11688 int x;
11689{
11690 if (p_paste)
11691 return FALSE;
11692 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11693}
11694
11695/*
11696 * Return TRUE if "x" is present in 'shortmess' option, or
11697 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11698 */
11699 int
11700shortmess(x)
11701 int x;
11702{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011703 return p_shm != NULL &&
11704 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011705 || (vim_strchr(p_shm, 'a') != NULL
11706 && vim_strchr((char_u *)SHM_A, x) != NULL));
11707}
11708
11709/*
11710 * paste_option_changed() - Called after p_paste was set or reset.
11711 */
11712 static void
11713paste_option_changed()
11714{
11715 static int old_p_paste = FALSE;
11716 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011717 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011718#ifdef FEAT_CMDL_INFO
11719 static int save_ru = 0;
11720#endif
11721#ifdef FEAT_RIGHTLEFT
11722 static int save_ri = 0;
11723 static int save_hkmap = 0;
11724#endif
11725 buf_T *buf;
11726
11727 if (p_paste)
11728 {
11729 /*
11730 * Paste switched from off to on.
11731 * Save the current values, so they can be restored later.
11732 */
11733 if (!old_p_paste)
11734 {
11735 /* save options for each buffer */
11736 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11737 {
11738 buf->b_p_tw_nopaste = buf->b_p_tw;
11739 buf->b_p_wm_nopaste = buf->b_p_wm;
11740 buf->b_p_sts_nopaste = buf->b_p_sts;
11741 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011742 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011743 }
11744
11745 /* save global options */
11746 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011747 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011748#ifdef FEAT_CMDL_INFO
11749 save_ru = p_ru;
11750#endif
11751#ifdef FEAT_RIGHTLEFT
11752 save_ri = p_ri;
11753 save_hkmap = p_hkmap;
11754#endif
11755 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011756 p_ai_nopaste = p_ai;
11757 p_et_nopaste = p_et;
11758 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011759 p_tw_nopaste = p_tw;
11760 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 }
11762
11763 /*
11764 * Always set the option values, also when 'paste' is set when it is
11765 * already on.
11766 */
11767 /* set options for each buffer */
11768 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11769 {
11770 buf->b_p_tw = 0; /* textwidth is 0 */
11771 buf->b_p_wm = 0; /* wrapmargin is 0 */
11772 buf->b_p_sts = 0; /* softtabstop is 0 */
11773 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011774 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011775 }
11776
11777 /* set global options */
11778 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011779 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011780#ifdef FEAT_CMDL_INFO
11781# ifdef FEAT_WINDOWS
11782 if (p_ru)
11783 status_redraw_all(); /* redraw to remove the ruler */
11784# endif
11785 p_ru = 0; /* no ruler */
11786#endif
11787#ifdef FEAT_RIGHTLEFT
11788 p_ri = 0; /* no reverse insert */
11789 p_hkmap = 0; /* no Hebrew keyboard */
11790#endif
11791 /* set global values for local buffer options */
11792 p_tw = 0;
11793 p_wm = 0;
11794 p_sts = 0;
11795 p_ai = 0;
11796 }
11797
11798 /*
11799 * Paste switched from on to off: Restore saved values.
11800 */
11801 else if (old_p_paste)
11802 {
11803 /* restore options for each buffer */
11804 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11805 {
11806 buf->b_p_tw = buf->b_p_tw_nopaste;
11807 buf->b_p_wm = buf->b_p_wm_nopaste;
11808 buf->b_p_sts = buf->b_p_sts_nopaste;
11809 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011810 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011811 }
11812
11813 /* restore global options */
11814 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011815 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816#ifdef FEAT_CMDL_INFO
11817# ifdef FEAT_WINDOWS
11818 if (p_ru != save_ru)
11819 status_redraw_all(); /* redraw to draw the ruler */
11820# endif
11821 p_ru = save_ru;
11822#endif
11823#ifdef FEAT_RIGHTLEFT
11824 p_ri = save_ri;
11825 p_hkmap = save_hkmap;
11826#endif
11827 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011828 p_ai = p_ai_nopaste;
11829 p_et = p_et_nopaste;
11830 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011831 p_tw = p_tw_nopaste;
11832 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011833 }
11834
11835 old_p_paste = p_paste;
11836}
11837
11838/*
11839 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11840 *
11841 * Reset 'compatible' and set the values for options that didn't get set yet
11842 * to the Vim defaults.
11843 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011844 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845 */
11846 void
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011847vimrc_found(fname, envname)
11848 char_u *fname;
11849 char_u *envname;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011850{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011851 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011852 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011853 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011854
11855 if (!option_was_set((char_u *)"cp"))
11856 {
11857 p_cp = FALSE;
11858 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11859 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11860 set_option_default(opt_idx, OPT_FREE, FALSE);
11861 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011862 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011863 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011864
11865 if (fname != NULL)
11866 {
11867 p = vim_getenv(envname, &dofree);
11868 if (p == NULL)
11869 {
11870 /* Set $MYVIMRC to the first vimrc file found. */
11871 p = FullName_save(fname, FALSE);
11872 if (p != NULL)
11873 {
11874 vim_setenv(envname, p);
11875 vim_free(p);
11876 }
11877 }
11878 else if (dofree)
11879 vim_free(p);
11880 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881}
11882
11883/*
11884 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11885 */
11886 void
11887change_compatible(on)
11888 int on;
11889{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011890 int opt_idx;
11891
Bram Moolenaar071d4272004-06-13 20:20:40 +000011892 if (p_cp != on)
11893 {
11894 p_cp = on;
11895 compatible_set();
11896 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011897 opt_idx = findoption((char_u *)"cp");
11898 if (opt_idx >= 0)
11899 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900}
11901
11902/*
11903 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011904 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011905 */
11906 int
11907option_was_set(name)
11908 char_u *name;
11909{
11910 int idx;
11911
11912 idx = findoption(name);
11913 if (idx < 0) /* unknown option */
11914 return FALSE;
11915 if (options[idx].flags & P_WAS_SET)
11916 return TRUE;
11917 return FALSE;
11918}
11919
11920/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011921 * Reset the flag indicating option "name" was set.
11922 */
11923 void
11924reset_option_was_set(name)
11925 char_u *name;
11926{
11927 int idx = findoption(name);
11928
11929 if (idx >= 0)
11930 options[idx].flags &= ~P_WAS_SET;
11931}
11932
11933/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011934 * compatible_set() - Called when 'compatible' has been set or unset.
11935 *
11936 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11937 * flag) to a Vi compatible value.
11938 * When 'compatible' is unset: Set all options that have a different default
11939 * for Vim (without the P_VI_DEF flag) to that default.
11940 */
11941 static void
11942compatible_set()
11943{
11944 int opt_idx;
11945
11946 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11947 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11948 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11949 set_option_default(opt_idx, OPT_FREE, p_cp);
11950 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011951 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011952}
11953
11954#ifdef FEAT_LINEBREAK
11955
11956# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11957 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011958 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011959# endif
11960
11961/*
11962 * fill_breakat_flags() -- called when 'breakat' changes value.
11963 */
11964 static void
11965fill_breakat_flags()
11966{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011967 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011968 int i;
11969
11970 for (i = 0; i < 256; i++)
11971 breakat_flags[i] = FALSE;
11972
11973 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011974 for (p = p_breakat; *p; p++)
11975 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011976}
11977
11978# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011979 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011980# endif
11981
11982#endif
11983
11984/*
11985 * Check an option that can be a range of string values.
11986 *
11987 * Return OK for correct value, FAIL otherwise.
11988 * Empty is always OK.
11989 */
11990 static int
11991check_opt_strings(val, values, list)
11992 char_u *val;
11993 char **values;
11994 int list; /* when TRUE: accept a list of values */
11995{
11996 return opt_strings_flags(val, values, NULL, list);
11997}
11998
11999/*
12000 * Handle an option that can be a range of string values.
12001 * Set a flag in "*flagp" for each string present.
12002 *
12003 * Return OK for correct value, FAIL otherwise.
12004 * Empty is always OK.
12005 */
12006 static int
12007opt_strings_flags(val, values, flagp, list)
12008 char_u *val; /* new value */
12009 char **values; /* array of valid string values */
12010 unsigned *flagp;
12011 int list; /* when TRUE: accept a list of values */
12012{
12013 int i;
12014 int len;
12015 unsigned new_flags = 0;
12016
12017 while (*val)
12018 {
12019 for (i = 0; ; ++i)
12020 {
12021 if (values[i] == NULL) /* val not found in values[] */
12022 return FAIL;
12023
12024 len = (int)STRLEN(values[i]);
12025 if (STRNCMP(values[i], val, len) == 0
12026 && ((list && val[len] == ',') || val[len] == NUL))
12027 {
12028 val += len + (val[len] == ',');
12029 new_flags |= (1 << i);
12030 break; /* check next item in val list */
12031 }
12032 }
12033 }
12034 if (flagp != NULL)
12035 *flagp = new_flags;
12036
12037 return OK;
12038}
12039
12040/*
12041 * Read the 'wildmode' option, fill wim_flags[].
12042 */
12043 static int
12044check_opt_wim()
12045{
12046 char_u new_wim_flags[4];
12047 char_u *p;
12048 int i;
12049 int idx = 0;
12050
12051 for (i = 0; i < 4; ++i)
12052 new_wim_flags[i] = 0;
12053
12054 for (p = p_wim; *p; ++p)
12055 {
12056 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12057 ;
12058 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12059 return FAIL;
12060 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12061 new_wim_flags[idx] |= WIM_LONGEST;
12062 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12063 new_wim_flags[idx] |= WIM_FULL;
12064 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12065 new_wim_flags[idx] |= WIM_LIST;
12066 else
12067 return FAIL;
12068 p += i;
12069 if (*p == NUL)
12070 break;
12071 if (*p == ',')
12072 {
12073 if (idx == 3)
12074 return FAIL;
12075 ++idx;
12076 }
12077 }
12078
12079 /* fill remaining entries with last flag */
12080 while (idx < 3)
12081 {
12082 new_wim_flags[idx + 1] = new_wim_flags[idx];
12083 ++idx;
12084 }
12085
12086 /* only when there are no errors, wim_flags[] is changed */
12087 for (i = 0; i < 4; ++i)
12088 wim_flags[i] = new_wim_flags[i];
12089 return OK;
12090}
12091
12092/*
12093 * Check if backspacing over something is allowed.
12094 */
12095 int
12096can_bs(what)
12097 int what; /* BS_INDENT, BS_EOL or BS_START */
12098{
12099 switch (*p_bs)
12100 {
12101 case '2': return TRUE;
12102 case '1': return (what != BS_START);
12103 case '0': return FALSE;
12104 }
12105 return vim_strchr(p_bs, what) != NULL;
12106}
12107
12108/*
12109 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12110 * the file must be considered changed when the value is different.
12111 */
12112 void
12113save_file_ff(buf)
12114 buf_T *buf;
12115{
12116 buf->b_start_ffc = *buf->b_p_ff;
12117 buf->b_start_eol = buf->b_p_eol;
12118#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012119 buf->b_start_bomb = buf->b_p_bomb;
12120
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121 /* Only use free/alloc when necessary, they take time. */
12122 if (buf->b_start_fenc == NULL
12123 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12124 {
12125 vim_free(buf->b_start_fenc);
12126 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12127 }
12128#endif
12129}
12130
12131/*
12132 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12133 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012134 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12135 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012136 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012137 * When "ignore_empty" is true don't consider a new, empty buffer to be
12138 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012139 */
12140 int
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012141file_ff_differs(buf, ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012142 buf_T *buf;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012143 int ignore_empty;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012144{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012145 /* In a buffer that was never loaded the options are not valid. */
12146 if (buf->b_flags & BF_NEVERLOADED)
12147 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012148 if (ignore_empty
12149 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012150 && buf->b_ml.ml_line_count == 1
12151 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12152 return FALSE;
12153 if (buf->b_start_ffc != *buf->b_p_ff)
12154 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012155 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012156 return TRUE;
12157#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012158 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12159 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012160 if (buf->b_start_fenc == NULL)
12161 return (*buf->b_p_fenc != NUL);
12162 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12163#else
12164 return FALSE;
12165#endif
12166}
12167
12168/*
12169 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12170 */
12171 int
12172check_ff_value(p)
12173 char_u *p;
12174{
12175 return check_opt_strings(p, p_ff_values, FALSE);
12176}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012177
12178/*
12179 * Return the effective shiftwidth value for current buffer, using the
12180 * 'tabstop' value when 'shiftwidth' is zero.
12181 */
12182 long
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012183get_sw_value(buf)
12184 buf_T *buf;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012185{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012186 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012187}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012188
12189/*
12190 * Return the effective softtabstop value for the current buffer, using the
12191 * 'tabstop' value when 'softtabstop' is negative.
12192 */
12193 long
12194get_sts_value()
12195{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012196 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012197}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012198
12199/*
12200 * Check matchpairs option for "*initc".
12201 * If there is a match set "*initc" to the matching character and "*findc" to
12202 * the opposite character. Set "*backwards" to the direction.
12203 * When "switchit" is TRUE swap the direction.
12204 */
12205 void
12206find_mps_values(initc, findc, backwards, switchit)
12207 int *initc;
12208 int *findc;
12209 int *backwards;
12210 int switchit;
12211{
12212 char_u *ptr;
12213
12214 ptr = curbuf->b_p_mps;
12215 while (*ptr != NUL)
12216 {
12217#ifdef FEAT_MBYTE
12218 if (has_mbyte)
12219 {
12220 char_u *prev;
12221
12222 if (mb_ptr2char(ptr) == *initc)
12223 {
12224 if (switchit)
12225 {
12226 *findc = *initc;
12227 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12228 *backwards = TRUE;
12229 }
12230 else
12231 {
12232 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12233 *backwards = FALSE;
12234 }
12235 return;
12236 }
12237 prev = ptr;
12238 ptr += mb_ptr2len(ptr) + 1;
12239 if (mb_ptr2char(ptr) == *initc)
12240 {
12241 if (switchit)
12242 {
12243 *findc = *initc;
12244 *initc = mb_ptr2char(prev);
12245 *backwards = FALSE;
12246 }
12247 else
12248 {
12249 *findc = mb_ptr2char(prev);
12250 *backwards = TRUE;
12251 }
12252 return;
12253 }
12254 ptr += mb_ptr2len(ptr);
12255 }
12256 else
12257#endif
12258 {
12259 if (*ptr == *initc)
12260 {
12261 if (switchit)
12262 {
12263 *backwards = TRUE;
12264 *findc = *initc;
12265 *initc = ptr[2];
12266 }
12267 else
12268 {
12269 *backwards = FALSE;
12270 *findc = ptr[2];
12271 }
12272 return;
12273 }
12274 ptr += 2;
12275 if (*ptr == *initc)
12276 {
12277 if (switchit)
12278 {
12279 *backwards = FALSE;
12280 *findc = *initc;
12281 *initc = ptr[-2];
12282 }
12283 else
12284 {
12285 *backwards = TRUE;
12286 *findc = ptr[-2];
12287 }
12288 return;
12289 }
12290 ++ptr;
12291 }
12292 if (*ptr == ',')
12293 ++ptr;
12294 }
12295}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012296
12297#if defined(FEAT_LINEBREAK) || defined(PROTO)
12298/*
12299 * This is called when 'breakindentopt' is changed and when a window is
12300 * initialized.
12301 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012302 static int
12303briopt_check(wp)
12304 win_T *wp;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012305{
12306 char_u *p;
12307 int bri_shift = 0;
12308 long bri_min = 20;
12309 int bri_sbr = FALSE;
12310
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012311 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012312 while (*p != NUL)
12313 {
12314 if (STRNCMP(p, "shift:", 6) == 0
12315 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12316 {
12317 p += 6;
12318 bri_shift = getdigits(&p);
12319 }
12320 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12321 {
12322 p += 4;
12323 bri_min = getdigits(&p);
12324 }
12325 else if (STRNCMP(p, "sbr", 3) == 0)
12326 {
12327 p += 3;
12328 bri_sbr = TRUE;
12329 }
12330 if (*p != ',' && *p != NUL)
12331 return FAIL;
12332 if (*p == ',')
12333 ++p;
12334 }
12335
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012336 wp->w_p_brishift = bri_shift;
12337 wp->w_p_brimin = bri_min;
12338 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012339
12340 return OK;
12341}
12342#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012343
12344/*
12345 * Get the local or global value of 'backupcopy'.
12346 */
12347 unsigned int
12348get_bkc_value(buf)
12349 buf_T *buf;
12350{
12351 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12352}