blob: 6645cb2efdbdab9bc688d1410c02206e480e22e6 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
25 * - Add documentation! One line in doc/help.txt, full description in
26 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000110#ifdef FEAT_EVAL
111# define PV_FEX OPT_BUF(BV_FEX)
112#endif
113#define PV_FF OPT_BUF(BV_FF)
114#define PV_FLP OPT_BUF(BV_FLP)
115#define PV_FO OPT_BUF(BV_FO)
116#ifdef FEAT_AUTOCMD
117# define PV_FT OPT_BUF(BV_FT)
118#endif
119#define PV_IMI OPT_BUF(BV_IMI)
120#define PV_IMS OPT_BUF(BV_IMS)
121#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
122# define PV_INDE OPT_BUF(BV_INDE)
123# define PV_INDK OPT_BUF(BV_INDK)
124#endif
125#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
126# define PV_INEX OPT_BUF(BV_INEX)
127#endif
128#define PV_INF OPT_BUF(BV_INF)
129#define PV_ISK OPT_BUF(BV_ISK)
130#ifdef FEAT_CRYPT
131# define PV_KEY OPT_BUF(BV_KEY)
132#endif
133#ifdef FEAT_KEYMAP
134# define PV_KMAP OPT_BUF(BV_KMAP)
135#endif
136#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
137#ifdef FEAT_LISP
138# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100139# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000140#endif
141#define PV_MA OPT_BUF(BV_MA)
142#define PV_ML OPT_BUF(BV_ML)
143#define PV_MOD OPT_BUF(BV_MOD)
144#define PV_MPS OPT_BUF(BV_MPS)
145#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000146#ifdef FEAT_COMPL_FUNC
147# define PV_OFU OPT_BUF(BV_OFU)
148#endif
149#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
150#define PV_PI OPT_BUF(BV_PI)
151#ifdef FEAT_TEXTOBJ
152# define PV_QE OPT_BUF(BV_QE)
153#endif
154#define PV_RO OPT_BUF(BV_RO)
155#ifdef FEAT_SMARTINDENT
156# define PV_SI OPT_BUF(BV_SI)
157#endif
158#ifndef SHORT_FNAME
159# define PV_SN OPT_BUF(BV_SN)
160#endif
161#ifdef FEAT_SYN_HL
162# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000163# define PV_SYN OPT_BUF(BV_SYN)
164#endif
165#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000166# define PV_SPC OPT_BUF(BV_SPC)
167# define PV_SPF OPT_BUF(BV_SPF)
168# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000169#endif
170#define PV_STS OPT_BUF(BV_STS)
171#ifdef FEAT_SEARCHPATH
172# define PV_SUA OPT_BUF(BV_SUA)
173#endif
174#define PV_SW OPT_BUF(BV_SW)
175#define PV_SWF OPT_BUF(BV_SWF)
176#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100177#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_TS OPT_BUF(BV_TS)
179#define PV_TW OPT_BUF(BV_TW)
180#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200181#ifdef FEAT_PERSISTENT_UNDO
182# define PV_UDF OPT_BUF(BV_UDF)
183#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000184#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185
186/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000187 * Definition of the PV_ values for window-local options.
188 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190#define PV_LIST OPT_WIN(WV_LIST)
191#ifdef FEAT_ARABIC
192# define PV_ARAB OPT_WIN(WV_ARAB)
193#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200194#ifdef FEAT_LINEBREAK
195# define PV_BRI OPT_WIN(WV_BRI)
196# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
197#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000198#ifdef FEAT_DIFF
199# define PV_DIFF OPT_WIN(WV_DIFF)
200#endif
201#ifdef FEAT_FOLDING
202# define PV_FDC OPT_WIN(WV_FDC)
203# define PV_FEN OPT_WIN(WV_FEN)
204# define PV_FDI OPT_WIN(WV_FDI)
205# define PV_FDL OPT_WIN(WV_FDL)
206# define PV_FDM OPT_WIN(WV_FDM)
207# define PV_FML OPT_WIN(WV_FML)
208# define PV_FDN OPT_WIN(WV_FDN)
209# ifdef FEAT_EVAL
210# define PV_FDE OPT_WIN(WV_FDE)
211# define PV_FDT OPT_WIN(WV_FDT)
212# endif
213# define PV_FMR OPT_WIN(WV_FMR)
214#endif
215#ifdef FEAT_LINEBREAK
216# define PV_LBR OPT_WIN(WV_LBR)
217#endif
218#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200219#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000220#ifdef FEAT_LINEBREAK
221# define PV_NUW OPT_WIN(WV_NUW)
222#endif
223#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
224# define PV_PVW OPT_WIN(WV_PVW)
225#endif
226#ifdef FEAT_RIGHTLEFT
227# define PV_RL OPT_WIN(WV_RL)
228# define PV_RLC OPT_WIN(WV_RLC)
229#endif
230#ifdef FEAT_SCROLLBIND
231# define PV_SCBIND OPT_WIN(WV_SCBIND)
232#endif
233#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000234#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000235# define PV_SPELL OPT_WIN(WV_SPELL)
236#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000237#ifdef FEAT_SYN_HL
238# define PV_CUC OPT_WIN(WV_CUC)
239# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200240# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000241#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000242#ifdef FEAT_STL_OPT
243# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
244#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100245#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000246#ifdef FEAT_WINDOWS
247# define PV_WFH OPT_WIN(WV_WFH)
248#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249#ifdef FEAT_VERTSPLIT
250# define PV_WFW OPT_WIN(WV_WFW)
251#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000252#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CURSORBIND
254# define PV_CRBIND OPT_WIN(WV_CRBIND)
255#endif
256#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200257# define PV_COCU OPT_WIN(WV_COCU)
258# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000260
261/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262typedef enum
263{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000264 PV_NONE = 0,
265 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266} idopt_T;
267
268/*
269 * Options local to a window have a value local to a buffer and global to all
270 * buffers. Indicate this by setting "var" to VAR_WIN.
271 */
272#define VAR_WIN ((char_u *)-1)
273
274/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000275 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 * Only to be used in option.c!
277 */
278static int p_ai;
279static int p_bin;
280#ifdef FEAT_MBYTE
281static int p_bomb;
282#endif
283#if defined(FEAT_QUICKFIX)
284static char_u *p_bh;
285static char_u *p_bt;
286#endif
287static int p_bl;
288static int p_ci;
289#ifdef FEAT_CINDENT
290static int p_cin;
291static char_u *p_cink;
292static char_u *p_cino;
293#endif
294#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
295static char_u *p_cinw;
296#endif
297#ifdef FEAT_COMMENTS
298static char_u *p_com;
299#endif
300#ifdef FEAT_FOLDING
301static char_u *p_cms;
302#endif
303#ifdef FEAT_INS_EXPAND
304static char_u *p_cpt;
305#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#ifdef FEAT_COMPL_FUNC
307static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000308static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200311static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312static int p_et;
313#ifdef FEAT_MBYTE
314static char_u *p_fenc;
315#endif
316static char_u *p_ff;
317static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000318static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319#ifdef FEAT_AUTOCMD
320static char_u *p_ft;
321#endif
322static long p_iminsert;
323static long p_imsearch;
324#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
325static char_u *p_inex;
326#endif
327#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
328static char_u *p_inde;
329static char_u *p_indk;
330#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000331#if defined(FEAT_EVAL)
332static char_u *p_fex;
333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334static int p_inf;
335static char_u *p_isk;
336#ifdef FEAT_CRYPT
337static char_u *p_key;
338#endif
339#ifdef FEAT_LISP
340static int p_lisp;
341#endif
342static int p_ml;
343static int p_ma;
344static int p_mod;
345static char_u *p_mps;
346static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000348#ifdef FEAT_TEXTOBJ
349static char_u *p_qe;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_ro;
352#ifdef FEAT_SMARTINDENT
353static int p_si;
354#endif
355#ifndef SHORT_FNAME
356static int p_sn;
357#endif
358static long p_sts;
359#if defined(FEAT_SEARCHPATH)
360static char_u *p_sua;
361#endif
362static long p_sw;
363static int p_swf;
364#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000365static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000367#endif
368#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000369static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000370static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000371static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000372#endif
373static long p_ts;
374static long p_tw;
375static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200376#ifdef FEAT_PERSISTENT_UNDO
377static int p_udf;
378#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000379static long p_wm;
380#ifdef FEAT_KEYMAP
381static char_u *p_keymap;
382#endif
383
384/* Saved values for when 'bin' is set. */
385static int p_et_nobin;
386static int p_ml_nobin;
387static long p_tw_nobin;
388static long p_wm_nobin;
389
390/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200391static int p_ai_nopaste;
392static int p_et_nopaste;
393static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394static long p_tw_nopaste;
395static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396
397struct vimoption
398{
399 char *fullname; /* full option name */
400 char *shortname; /* permissible abbreviation */
401 long_u flags; /* see below */
402 char_u *var; /* global option: pointer to variable;
403 * window-local option: VAR_WIN;
404 * buffer-local option: global value */
405 idopt_T indir; /* global option: PV_NONE;
406 * local option: indirect option index */
407 char_u *def_val[2]; /* default values for variable (vi and vim) */
408#ifdef FEAT_EVAL
409 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000410# define SCRIPTID_INIT , 0
411#else
412# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413#endif
414};
415
416#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
417#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
418
419/*
420 * Flags
421 */
422#define P_BOOL 0x01 /* the option is boolean */
423#define P_NUM 0x02 /* the option is numeric */
424#define P_STRING 0x04 /* the option is a string */
425#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000426 must use free_string_option() when
427 assigning new value. Not set if default is
428 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000429#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
430 never be used for local or hidden options! */
431#define P_NODEFAULT 0x40 /* don't set to default value */
432#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
433 use vim_free() when assigning new value */
434#define P_WAS_SET 0x100 /* option has been set/reset */
435#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
436#define P_VI_DEF 0x400 /* Use Vi default for Vim */
437#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
438
439 /* when option changed, what to display: */
440#define P_RSTAT 0x1000 /* redraw status lines */
441#define P_RWIN 0x2000 /* redraw current window */
442#define P_RBUF 0x4000 /* redraw current buffer */
443#define P_RALL 0x6000 /* redraw all windows */
444#define P_RCLR 0x7000 /* clear and redraw all */
445
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200446#define P_COMMA 0x8000 /* comma separated list */
447#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
448 * commas */
449#define P_NODUP 0x20000L /* don't allow duplicate strings */
450#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200452#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
453#define P_GETTEXT 0x100000L /* expand default value with _() */
454#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
455#define P_NFNAME 0x400000L /* only normal file name chars allowed */
456#define P_INSECURE 0x800000L /* option was set from a modeline */
457#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000458 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200459#define P_NO_ML 0x2000000L /* not allowed in modeline */
460#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200461 * there is a redraw flag */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000462
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000463#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
464
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000465/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
466 * for the currency sign. */
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100467#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000468# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000469#else
470# define ISP_LATIN1 (char_u *)"@,161-255"
471#endif
472
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000473/* The 16 bit MS-DOS version is low on space, make the string as short as
474 * possible when compiling with few features. */
475#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
476 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200477 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100478# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000479#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100480# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000481#endif
482
Bram Moolenaar071d4272004-06-13 20:20:40 +0000483/*
484 * options[] is initialized here.
485 * The order of the options MUST be alphabetic for ":set all" and findoption().
486 * All option names MUST start with a lowercase letter (for findoption()).
487 * Exception: "t_" options are at the end.
488 * The options with a NULL variable are 'hidden': a set command for them is
489 * ignored and they are not printed.
490 */
491static struct vimoption
492#ifdef FEAT_GUI_W16
493 _far
494#endif
495 options[] =
496{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200497 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498#ifdef FEAT_RIGHTLEFT
499 (char_u *)&p_aleph, PV_NONE,
500#else
501 (char_u *)NULL, PV_NONE,
502#endif
503 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100504#if (defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505 (char_u *)128L,
506#else
507 (char_u *)224L,
508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000509 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
511#if defined(FEAT_GUI) && defined(MACOS_X)
512 (char_u *)&p_antialias, PV_NONE,
513 {(char_u *)FALSE, (char_u *)FALSE}
514#else
515 (char_u *)NULL, PV_NONE,
516 {(char_u *)FALSE, (char_u *)FALSE}
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200519 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520#ifdef FEAT_ARABIC
521 (char_u *)VAR_WIN, PV_ARAB,
522#else
523 (char_u *)NULL, PV_NONE,
524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000525 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
527#ifdef FEAT_ARABIC
528 (char_u *)&p_arshape, PV_NONE,
529#else
530 (char_u *)NULL, PV_NONE,
531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000532 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
534#ifdef FEAT_RIGHTLEFT
535 (char_u *)&p_ari, PV_NONE,
536#else
537 (char_u *)NULL, PV_NONE,
538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000540 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
541#ifdef FEAT_FKMAP
542 (char_u *)&p_altkeymap, PV_NONE,
543#else
544 (char_u *)NULL, PV_NONE,
545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
548#if defined(FEAT_MBYTE)
549 (char_u *)&p_ambw, PV_NONE,
550 {(char_u *)"single", (char_u *)0L}
551#else
552 (char_u *)NULL, PV_NONE,
553 {(char_u *)0L, (char_u *)0L}
554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000556#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autochdir", "acd", P_BOOL|P_VI_DEF,
558 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560#endif
561 {"autoindent", "ai", P_BOOL|P_VI_DEF,
562 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000563 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564 {"autoprint", "ap", P_BOOL|P_VI_DEF,
565 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000568 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autowrite", "aw", P_BOOL|P_VI_DEF,
571 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autowriteall","awa", P_BOOL|P_VI_DEF,
574 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
577 (char_u *)&p_bg, PV_NONE,
578 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100579#if (defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 (char_u *)"dark",
581#else
582 (char_u *)"light",
583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000584 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200585 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000587 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
589 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200592 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593#ifdef UNIX
594 {(char_u *)"yes", (char_u *)"auto"}
595#else
596 {(char_u *)"auto", (char_u *)"auto"}
597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000598 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200599 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
600 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000602 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000603 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 (char_u *)&p_bex, PV_NONE,
605 {
606#ifdef VMS
607 (char_u *)"_",
608#else
609 (char_u *)"~",
610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000611 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200612 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000613#ifdef FEAT_WILDIGN
614 (char_u *)&p_bsk, PV_NONE,
615 {(char_u *)"", (char_u *)0L}
616#else
617 (char_u *)NULL, PV_NONE,
618 {(char_u *)0L, (char_u *)0L}
619#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621#ifdef FEAT_BEVAL
622 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
623 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
626 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000628# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000629 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000630 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000632# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633#endif
634 {"beautify", "bf", P_BOOL|P_VI_DEF,
635 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200637 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
638 (char_u *)&p_bo, PV_NONE,
639 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
641 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000642 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000643 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
644#ifdef MSDOS
645 (char_u *)&p_biosk, PV_NONE,
646#else
647 (char_u *)NULL, PV_NONE,
648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000650 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
651#ifdef FEAT_MBYTE
652 (char_u *)&p_bomb, PV_BOMB,
653#else
654 (char_u *)NULL, PV_NONE,
655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000656 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000657 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
658#ifdef FEAT_LINEBREAK
659 (char_u *)&p_breakat, PV_NONE,
660 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
661#else
662 (char_u *)NULL, PV_NONE,
663 {(char_u *)0L, (char_u *)0L}
664#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200666 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
667#ifdef FEAT_LINEBREAK
668 (char_u *)VAR_WIN, PV_BRI,
669 {(char_u *)FALSE, (char_u *)0L}
670#else
671 (char_u *)NULL, PV_NONE,
672 {(char_u *)0L, (char_u *)0L}
673#endif
674 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200675 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
676 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200677#ifdef FEAT_LINEBREAK
678 (char_u *)VAR_WIN, PV_BRIOPT,
679 {(char_u *)"", (char_u *)NULL}
680#else
681 (char_u *)NULL, PV_NONE,
682 {(char_u *)"", (char_u *)NULL}
683#endif
684 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000685 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
686#ifdef FEAT_BROWSE
687 (char_u *)&p_bsdir, PV_NONE,
688 {(char_u *)"last", (char_u *)0L}
689#else
690 (char_u *)NULL, PV_NONE,
691 {(char_u *)0L, (char_u *)0L}
692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000693 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000694 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
695#if defined(FEAT_QUICKFIX)
696 (char_u *)&p_bh, PV_BH,
697 {(char_u *)"", (char_u *)0L}
698#else
699 (char_u *)NULL, PV_NONE,
700 {(char_u *)0L, (char_u *)0L}
701#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000702 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
704 (char_u *)&p_bl, PV_BL,
705 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000706 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
708#if defined(FEAT_QUICKFIX)
709 (char_u *)&p_bt, PV_BT,
710 {(char_u *)"", (char_u *)0L}
711#else
712 (char_u *)NULL, PV_NONE,
713 {(char_u *)0L, (char_u *)0L}
714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000715 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200716 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000717#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 (char_u *)&p_cmp, PV_NONE,
719 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000720#else
721 (char_u *)NULL, PV_NONE,
722 {(char_u *)0L, (char_u *)0L}
723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
726#ifdef FEAT_SEARCHPATH
727 (char_u *)&p_cdpath, PV_NONE,
728 {(char_u *)",,", (char_u *)0L}
729#else
730 (char_u *)NULL, PV_NONE,
731 {(char_u *)0L, (char_u *)0L}
732#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000733 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734 {"cedit", NULL, P_STRING,
735#ifdef FEAT_CMDWIN
736 (char_u *)&p_cedit, PV_NONE,
737 {(char_u *)"", (char_u *)CTRL_F_STR}
738#else
739 (char_u *)NULL, PV_NONE,
740 {(char_u *)0L, (char_u *)0L}
741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000742 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000743 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
744#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
745 (char_u *)&p_ccv, PV_NONE,
746 {(char_u *)"", (char_u *)0L}
747#else
748 (char_u *)NULL, PV_NONE,
749 {(char_u *)0L, (char_u *)0L}
750#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000751 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000752 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
753#ifdef FEAT_CINDENT
754 (char_u *)&p_cin, PV_CIN,
755#else
756 (char_u *)NULL, PV_NONE,
757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000758 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200759 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760#ifdef FEAT_CINDENT
761 (char_u *)&p_cink, PV_CINK,
762 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
763#else
764 (char_u *)NULL, PV_NONE,
765 {(char_u *)0L, (char_u *)0L}
766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000767 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200768 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769#ifdef FEAT_CINDENT
770 (char_u *)&p_cino, PV_CINO,
771#else
772 (char_u *)NULL, PV_NONE,
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200775 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
777 (char_u *)&p_cinw, PV_CINW,
778 {(char_u *)"if,else,while,do,for,switch",
779 (char_u *)0L}
780#else
781 (char_u *)NULL, PV_NONE,
782 {(char_u *)0L, (char_u *)0L}
783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000784 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200785 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786#ifdef FEAT_CLIPBOARD
787 (char_u *)&p_cb, PV_NONE,
788# ifdef FEAT_XCLIPBOARD
789 {(char_u *)"autoselect,exclude:cons\\|linux",
790 (char_u *)0L}
791# else
792 {(char_u *)"", (char_u *)0L}
793# endif
794#else
795 (char_u *)NULL, PV_NONE,
796 {(char_u *)"", (char_u *)0L}
797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000798 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000799 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
800 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000801 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000802 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
803#ifdef FEAT_CMDWIN
804 (char_u *)&p_cwh, PV_NONE,
805#else
806 (char_u *)NULL, PV_NONE,
807#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000808 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200809 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200810#ifdef FEAT_SYN_HL
811 (char_u *)VAR_WIN, PV_CC,
812#else
813 (char_u *)NULL, PV_NONE,
814#endif
815 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
817 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000818 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200819 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
820 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000821#ifdef FEAT_COMMENTS
822 (char_u *)&p_com, PV_COM,
823 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
824 (char_u *)0L}
825#else
826 (char_u *)NULL, PV_NONE,
827 {(char_u *)0L, (char_u *)0L}
828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000829 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200830 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000831#ifdef FEAT_FOLDING
832 (char_u *)&p_cms, PV_CMS,
833 {(char_u *)"/*%s*/", (char_u *)0L}
834#else
835 (char_u *)NULL, PV_NONE,
836 {(char_u *)0L, (char_u *)0L}
837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000838 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000839 /* P_PRI_MKRC isn't needed here, optval_default()
840 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841 {"compatible", "cp", P_BOOL|P_RALL,
842 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000843 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200844 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000845#ifdef FEAT_INS_EXPAND
846 (char_u *)&p_cpt, PV_CPT,
847 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
848#else
849 (char_u *)NULL, PV_NONE,
850 {(char_u *)0L, (char_u *)0L}
851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000852 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200853 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200854#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200855 (char_u *)VAR_WIN, PV_COCU,
856 {(char_u *)"", (char_u *)NULL}
857#else
858 (char_u *)NULL, PV_NONE,
859 {(char_u *)NULL, (char_u *)0L}
860#endif
861 SCRIPTID_INIT},
862 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
863#ifdef FEAT_CONCEAL
864 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200865#else
866 (char_u *)NULL, PV_NONE,
867#endif
868 {(char_u *)0L, (char_u *)0L}
869 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000870 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
871#ifdef FEAT_COMPL_FUNC
872 (char_u *)&p_cfu, PV_CFU,
873 {(char_u *)"", (char_u *)0L}
874#else
875 (char_u *)NULL, PV_NONE,
876 {(char_u *)0L, (char_u *)0L}
877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000878 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200879 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000880#ifdef FEAT_INS_EXPAND
881 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000882 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000883#else
884 (char_u *)NULL, PV_NONE,
885 {(char_u *)0L, (char_u *)0L}
886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000887 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000888 {"confirm", "cf", P_BOOL|P_VI_DEF,
889#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
890 (char_u *)&p_confirm, PV_NONE,
891#else
892 (char_u *)NULL, PV_NONE,
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"conskey", "consk",P_BOOL|P_VI_DEF,
896#ifdef MSDOS
897 (char_u *)&p_consk, PV_NONE,
898#else
899 (char_u *)NULL, PV_NONE,
900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
903 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
906 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
908 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200909 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200910#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200911 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200912 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200913#else
914 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200915 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200916#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
919#ifdef FEAT_CSCOPE
920 (char_u *)&p_cspc, PV_NONE,
921#else
922 (char_u *)NULL, PV_NONE,
923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000924 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
926#ifdef FEAT_CSCOPE
927 (char_u *)&p_csprg, PV_NONE,
928 {(char_u *)"cscope", (char_u *)0L}
929#else
930 (char_u *)NULL, PV_NONE,
931 {(char_u *)0L, (char_u *)0L}
932#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000933 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200934 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000935#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
936 (char_u *)&p_csqf, PV_NONE,
937 {(char_u *)"", (char_u *)0L}
938#else
939 (char_u *)NULL, PV_NONE,
940 {(char_u *)0L, (char_u *)0L}
941#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000942 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200943 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
944#ifdef FEAT_CSCOPE
945 (char_u *)&p_csre, PV_NONE,
946#else
947 (char_u *)NULL, PV_NONE,
948#endif
949 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000950 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
951#ifdef FEAT_CSCOPE
952 (char_u *)&p_cst, PV_NONE,
953#else
954 (char_u *)NULL, PV_NONE,
955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000956 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
958#ifdef FEAT_CSCOPE
959 (char_u *)&p_csto, PV_NONE,
960#else
961 (char_u *)NULL, PV_NONE,
962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000963 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000964 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
965#ifdef FEAT_CSCOPE
966 (char_u *)&p_csverbose, PV_NONE,
967#else
968 (char_u *)NULL, PV_NONE,
969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000970 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200971 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
972#ifdef FEAT_CURSORBIND
973 (char_u *)VAR_WIN, PV_CRBIND,
974#else
975 (char_u *)NULL, PV_NONE,
976#endif
977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000978 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
979#ifdef FEAT_SYN_HL
980 (char_u *)VAR_WIN, PV_CUC,
981#else
982 (char_u *)NULL, PV_NONE,
983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000984 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000985 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
986#ifdef FEAT_SYN_HL
987 (char_u *)VAR_WIN, PV_CUL,
988#else
989 (char_u *)NULL, PV_NONE,
990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992 {"debug", NULL, P_STRING|P_VI_DEF,
993 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000994 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200995 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000997 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000998 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999#else
1000 (char_u *)NULL, PV_NONE,
1001 {(char_u *)NULL, (char_u *)0L}
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1005#ifdef FEAT_MBYTE
1006 (char_u *)&p_deco, PV_NONE,
1007#else
1008 (char_u *)NULL, PV_NONE,
1009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001011 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001013 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014#else
1015 (char_u *)NULL, PV_NONE,
1016#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001017 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1019#ifdef FEAT_DIFF
1020 (char_u *)VAR_WIN, PV_DIFF,
1021#else
1022 (char_u *)NULL, PV_NONE,
1023#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001024 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001025 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1027 (char_u *)&p_dex, PV_NONE,
1028 {(char_u *)"", (char_u *)0L}
1029#else
1030 (char_u *)NULL, PV_NONE,
1031 {(char_u *)0L, (char_u *)0L}
1032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001033 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001034 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1035 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036#ifdef FEAT_DIFF
1037 (char_u *)&p_dip, PV_NONE,
1038 {(char_u *)"filler", (char_u *)NULL}
1039#else
1040 (char_u *)NULL, PV_NONE,
1041 {(char_u *)"", (char_u *)NULL}
1042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1045#ifdef FEAT_DIGRAPHS
1046 (char_u *)&p_dg, PV_NONE,
1047#else
1048 (char_u *)NULL, PV_NONE,
1049#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001051 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1052 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001054 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001055 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001057 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 {"eadirection", "ead", P_STRING|P_VI_DEF,
1059#ifdef FEAT_VERTSPLIT
1060 (char_u *)&p_ead, PV_NONE,
1061 {(char_u *)"both", (char_u *)0L}
1062#else
1063 (char_u *)NULL, PV_NONE,
1064 {(char_u *)NULL, (char_u *)0L}
1065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1068 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001070 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071#ifdef FEAT_MBYTE
1072 (char_u *)&p_enc, PV_NONE,
1073 {(char_u *)ENC_DFLT, (char_u *)0L}
1074#else
1075 (char_u *)NULL, PV_NONE,
1076 {(char_u *)0L, (char_u *)0L}
1077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001078 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001079 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1080 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1083 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001084 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001086 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001087 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1089 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1092#ifdef FEAT_QUICKFIX
1093 (char_u *)&p_ef, PV_NONE,
1094 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1095#else
1096 (char_u *)NULL, PV_NONE,
1097 {(char_u *)NULL, (char_u *)0L}
1098#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001100 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001102 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104#else
1105 (char_u *)NULL, PV_NONE,
1106 {(char_u *)NULL, (char_u *)0L}
1107#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"esckeys", "ek", P_BOOL|P_VIM,
1110 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001112 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113#ifdef FEAT_AUTOCMD
1114 (char_u *)&p_ei, PV_NONE,
1115#else
1116 (char_u *)NULL, PV_NONE,
1117#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1120 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1123 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001125 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1126 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001127#ifdef FEAT_MBYTE
1128 (char_u *)&p_fenc, PV_FENC,
1129 {(char_u *)"", (char_u *)0L}
1130#else
1131 (char_u *)NULL, PV_NONE,
1132 {(char_u *)0L, (char_u *)0L}
1133#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001134 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001135 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136#ifdef FEAT_MBYTE
1137 (char_u *)&p_fencs, PV_NONE,
1138 {(char_u *)"ucs-bom", (char_u *)0L}
1139#else
1140 (char_u *)NULL, PV_NONE,
1141 {(char_u *)0L, (char_u *)0L}
1142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001144 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1145 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001147 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001148 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1151 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001152 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1153 (char_u *)&p_fic, PV_NONE,
1154 {
1155#ifdef CASE_INSENSITIVE_FILENAME
1156 (char_u *)TRUE,
1157#else
1158 (char_u *)FALSE,
1159#endif
1160 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001161 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001162#ifdef FEAT_AUTOCMD
1163 (char_u *)&p_ft, PV_FT,
1164 {(char_u *)"", (char_u *)0L}
1165#else
1166 (char_u *)NULL, PV_NONE,
1167 {(char_u *)0L, (char_u *)0L}
1168#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001170 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1172 (char_u *)&p_fcs, PV_NONE,
1173 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1174#else
1175 (char_u *)NULL, PV_NONE,
1176 {(char_u *)"", (char_u *)0L}
1177#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001179 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1180 (char_u *)&p_fixeol, PV_FIXEOL,
1181 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001182 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1183#ifdef FEAT_FKMAP
1184 (char_u *)&p_fkmap, PV_NONE,
1185#else
1186 (char_u *)NULL, PV_NONE,
1187#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001188 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"flash", "fl", P_BOOL|P_VI_DEF,
1190 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001193 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001195 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1197 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1200 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001201 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001202 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1203# ifdef FEAT_EVAL
1204 (char_u *)VAR_WIN, PV_FDE,
1205 {(char_u *)"0", (char_u *)NULL}
1206# else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
1209# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1212 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1215 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001217 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001221 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)"{{{,}}}", (char_u *)NULL}
1224 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1226 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001227 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1229 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1232 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001233 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001234 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001235 (char_u *)&p_fdo, PV_NONE,
1236 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1239# ifdef FEAT_EVAL
1240 (char_u *)VAR_WIN, PV_FDT,
1241 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001242# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001245# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001246 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001248 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001249#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001250 (char_u *)&p_fex, PV_FEX,
1251 {(char_u *)"", (char_u *)0L}
1252#else
1253 (char_u *)NULL, PV_NONE,
1254 {(char_u *)0L, (char_u *)0L}
1255#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001256 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001257 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1258 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001259 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1260 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001261 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1262 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1264 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1266 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001267 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001268 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1269#ifdef HAVE_FSYNC
1270 (char_u *)&p_fs, PV_NONE,
1271 {(char_u *)TRUE, (char_u *)0L}
1272#else
1273 (char_u *)NULL, PV_NONE,
1274 {(char_u *)FALSE, (char_u *)0L}
1275#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1278 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001279 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 {"graphic", "gr", P_BOOL|P_VI_DEF,
1281 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001282 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001283 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001284#ifdef FEAT_QUICKFIX
1285 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001286 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287#else
1288 (char_u *)NULL, PV_NONE,
1289 {(char_u *)NULL, (char_u *)0L}
1290#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001291 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001292 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1293#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001294 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001295 {
1296# ifdef WIN3264
1297 /* may be changed to "grep -n" in os_win32.c */
1298 (char_u *)"findstr /n",
1299# else
1300# ifdef UNIX
1301 /* Add an extra file name so that grep will always
1302 * insert a file name in the match line. */
1303 (char_u *)"grep -n $* /dev/null",
1304# else
1305# ifdef VMS
1306 (char_u *)"SEARCH/NUMBERS ",
1307# else
1308 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001309# endif
1310# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313#else
1314 (char_u *)NULL, PV_NONE,
1315 {(char_u *)NULL, (char_u *)0L}
1316#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001317 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001318 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319#ifdef CURSOR_SHAPE
1320 (char_u *)&p_guicursor, PV_NONE,
1321 {
1322# ifdef FEAT_GUI
1323 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
1324# else /* MSDOS or Win32 console */
1325 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1326# endif
1327 (char_u *)0L}
1328#else
1329 (char_u *)NULL, PV_NONE,
1330 {(char_u *)NULL, (char_u *)0L}
1331#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001332 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001333 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334#ifdef FEAT_GUI
1335 (char_u *)&p_guifont, PV_NONE,
1336 {(char_u *)"", (char_u *)0L}
1337#else
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)NULL, (char_u *)0L}
1340#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001341 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001342 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1344 (char_u *)&p_guifontset, PV_NONE,
1345 {(char_u *)"", (char_u *)0L}
1346#else
1347 (char_u *)NULL, PV_NONE,
1348 {(char_u *)NULL, (char_u *)0L}
1349#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001351 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1353 (char_u *)&p_guifontwide, PV_NONE,
1354 {(char_u *)"", (char_u *)0L}
1355#else
1356 (char_u *)NULL, PV_NONE,
1357 {(char_u *)NULL, (char_u *)0L}
1358#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001359 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001360 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001361#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 (char_u *)&p_ghr, PV_NONE,
1363#else
1364 (char_u *)NULL, PV_NONE,
1365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001366 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001368#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 (char_u *)&p_go, PV_NONE,
1370# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001371 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001373 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001374# endif
1375#else
1376 (char_u *)NULL, PV_NONE,
1377 {(char_u *)NULL, (char_u *)0L}
1378#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001379 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {"guipty", NULL, P_BOOL|P_VI_DEF,
1381#if defined(FEAT_GUI)
1382 (char_u *)&p_guipty, PV_NONE,
1383#else
1384 (char_u *)NULL, PV_NONE,
1385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001386 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001387 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001388#if defined(FEAT_GUI_TABLINE)
1389 (char_u *)&p_gtl, PV_NONE,
1390 {(char_u *)"", (char_u *)0L}
1391#else
1392 (char_u *)NULL, PV_NONE,
1393 {(char_u *)NULL, (char_u *)0L}
1394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001395 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001396 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001397#if defined(FEAT_GUI_TABLINE)
1398 (char_u *)&p_gtt, PV_NONE,
1399 {(char_u *)"", (char_u *)0L}
1400#else
1401 (char_u *)NULL, PV_NONE,
1402 {(char_u *)NULL, (char_u *)0L}
1403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001404 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1406 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001407 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1409 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001410 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"helpheight", "hh", P_NUM|P_VI_DEF,
1413#ifdef FEAT_WINDOWS
1414 (char_u *)&p_hh, PV_NONE,
1415#else
1416 (char_u *)NULL, PV_NONE,
1417#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001418 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001419 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001420#ifdef FEAT_MULTI_LANG
1421 (char_u *)&p_hlg, PV_NONE,
1422 {(char_u *)"", (char_u *)0L}
1423#else
1424 (char_u *)NULL, PV_NONE,
1425 {(char_u *)0L, (char_u *)0L}
1426#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001427 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"hidden", "hid", P_BOOL|P_VI_DEF,
1429 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001430 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001431 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001433 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1434 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"history", "hi", P_NUM|P_VIM,
1436 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001437 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1439#ifdef FEAT_RIGHTLEFT
1440 (char_u *)&p_hkmap, PV_NONE,
1441#else
1442 (char_u *)NULL, PV_NONE,
1443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1446#ifdef FEAT_RIGHTLEFT
1447 (char_u *)&p_hkmapp, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1453 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001454 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"icon", NULL, P_BOOL|P_VI_DEF,
1456#ifdef FEAT_TITLE
1457 (char_u *)&p_icon, PV_NONE,
1458#else
1459 (char_u *)NULL, PV_NONE,
1460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"iconstring", NULL, P_STRING|P_VI_DEF,
1463#ifdef FEAT_TITLE
1464 (char_u *)&p_iconstring, PV_NONE,
1465#else
1466 (char_u *)NULL, PV_NONE,
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1470 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001472 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1473# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1474 (char_u *)&p_imaf, PV_NONE,
1475 {(char_u *)"", (char_u *)NULL}
1476# else
1477 (char_u *)NULL, PV_NONE,
1478 {(char_u *)NULL, (char_u *)0L}
1479# endif
1480 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001482#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483 (char_u *)&p_imak, PV_NONE,
1484#else
1485 (char_u *)NULL, PV_NONE,
1486#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001487 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1489#ifdef USE_IM_CONTROL
1490 (char_u *)&p_imcmdline, PV_NONE,
1491#else
1492 (char_u *)NULL, PV_NONE,
1493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001494 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1496#ifdef USE_IM_CONTROL
1497 (char_u *)&p_imdisable, PV_NONE,
1498#else
1499 (char_u *)NULL, PV_NONE,
1500#endif
1501#ifdef __sgi
1502 {(char_u *)TRUE, (char_u *)0L}
1503#else
1504 {(char_u *)FALSE, (char_u *)0L}
1505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001506 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"iminsert", "imi", P_NUM|P_VI_DEF,
1508 (char_u *)&p_iminsert, PV_IMI,
1509#ifdef B_IMODE_IM
1510 {(char_u *)B_IMODE_IM, (char_u *)0L}
1511#else
1512 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001514 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001515 {"imsearch", "ims", P_NUM|P_VI_DEF,
1516 (char_u *)&p_imsearch, PV_IMS,
1517#ifdef B_IMODE_IM
1518 {(char_u *)B_IMODE_IM, (char_u *)0L}
1519#else
1520 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001522 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001523 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001524# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1525 (char_u *)&p_imsf, PV_NONE,
1526 {(char_u *)"", (char_u *)NULL}
1527# else
1528 (char_u *)NULL, PV_NONE,
1529 {(char_u *)NULL, (char_u *)0L}
1530# endif
1531 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1533#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001534 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001535 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1536#else
1537 (char_u *)NULL, PV_NONE,
1538 {(char_u *)0L, (char_u *)0L}
1539#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001540 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001541 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1542#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1543 (char_u *)&p_inex, PV_INEX,
1544 {(char_u *)"", (char_u *)0L}
1545#else
1546 (char_u *)NULL, PV_NONE,
1547 {(char_u *)0L, (char_u *)0L}
1548#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001549 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1551 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1554#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1555 (char_u *)&p_inde, PV_INDE,
1556 {(char_u *)"", (char_u *)0L}
1557#else
1558 (char_u *)NULL, PV_NONE,
1559 {(char_u *)0L, (char_u *)0L}
1560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001561 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001562 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001563#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1564 (char_u *)&p_indk, PV_INDK,
1565 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1566#else
1567 (char_u *)NULL, PV_NONE,
1568 {(char_u *)0L, (char_u *)0L}
1569#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 {"infercase", "inf", P_BOOL|P_VI_DEF,
1572 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1575 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1578 (char_u *)&p_isf, PV_NONE,
1579 {
1580#ifdef BACKSLASH_IN_FILENAME
1581 /* Excluded are: & and ^ are special in cmd.exe
1582 * ( and ) are used in text separating fnames */
1583 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1584#else
1585# ifdef AMIGA
1586 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1587# else
1588# ifdef VMS
1589 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1590# else /* UNIX et al. */
1591# ifdef EBCDIC
1592 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1593# else
1594 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1595# endif
1596# endif
1597# endif
1598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001599 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1601 (char_u *)&p_isi, PV_NONE,
1602 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001603#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001604 (char_u *)"@,48-57,_,128-167,224-235",
1605#else
1606# ifdef EBCDIC
1607 /* TODO: EBCDIC Check this! @ == isalpha()*/
1608 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1609 "112-120,128,140-142,156,158,172,"
1610 "174,186,191,203-207,219-225,235-239,"
1611 "251-254",
1612# else
1613 (char_u *)"@,48-57,_,192-255",
1614# endif
1615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001616 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1618 (char_u *)&p_isk, PV_ISK,
1619 {
1620#ifdef EBCDIC
1621 (char_u *)"@,240-249,_",
1622 /* TODO: EBCDIC Check this! @ == isalpha()*/
1623 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1624 "112-120,128,140-142,156,158,172,"
1625 "174,186,191,203-207,219-225,235-239,"
1626 "251-254",
1627#else
1628 (char_u *)"@,48-57,_",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001629# if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 (char_u *)"@,48-57,_,128-167,224-235"
1631# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001632 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001633# endif
1634#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001635 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1637 (char_u *)&p_isp, PV_NONE,
1638 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001639#if defined(MSDOS) || defined(MSWIN) \
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001640 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 || defined(VMS)
1642 (char_u *)"@,~-255",
1643#else
1644# ifdef EBCDIC
1645 /* all chars above 63 are printable */
1646 (char_u *)"63-255",
1647# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001648 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649# endif
1650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001651 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001652 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1653 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001654 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1656#ifdef FEAT_CRYPT
1657 (char_u *)&p_key, PV_KEY,
1658 {(char_u *)"", (char_u *)0L}
1659#else
1660 (char_u *)NULL, PV_NONE,
1661 {(char_u *)0L, (char_u *)0L}
1662#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001663 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001664 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665#ifdef FEAT_KEYMAP
1666 (char_u *)&p_keymap, PV_KMAP,
1667 {(char_u *)"", (char_u *)0L}
1668#else
1669 (char_u *)NULL, PV_NONE,
1670 {(char_u *)"", (char_u *)0L}
1671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001672 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001673 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001675 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001676 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001677 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 {
1679#if defined(MSDOS) || defined(MSWIN)
1680 (char_u *)":help",
1681#else
1682#ifdef VMS
1683 (char_u *)"help",
1684#else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001685# ifdef USEMAN_S
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 (char_u *)"man -s",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001687# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 (char_u *)"man",
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689# endif
1690#endif
1691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001693 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694#ifdef FEAT_LANGMAP
1695 (char_u *)&p_langmap, PV_NONE,
1696 {(char_u *)"", /* unmatched } */
1697#else
1698 (char_u *)NULL, PV_NONE,
1699 {(char_u *)NULL,
1700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001701 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001702 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1704 (char_u *)&p_lm, PV_NONE,
1705#else
1706 (char_u *)NULL, PV_NONE,
1707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001708 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001709 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1710#ifdef FEAT_LANGMAP
1711 (char_u *)&p_lnr, PV_NONE,
1712#else
1713 (char_u *)NULL, PV_NONE,
1714#endif
1715 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001716 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1717#ifdef FEAT_WINDOWS
1718 (char_u *)&p_ls, PV_NONE,
1719#else
1720 (char_u *)NULL, PV_NONE,
1721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001722 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1724 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001725 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001726 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1727#ifdef FEAT_LINEBREAK
1728 (char_u *)VAR_WIN, PV_LBR,
1729#else
1730 (char_u *)NULL, PV_NONE,
1731#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001732 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1734 (char_u *)&Rows, PV_NONE,
1735 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001736#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 (char_u *)25L,
1738#else
1739 (char_u *)24L,
1740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1743#ifdef FEAT_GUI
1744 (char_u *)&p_linespace, PV_NONE,
1745#else
1746 (char_u *)NULL, PV_NONE,
1747#endif
1748#ifdef FEAT_GUI_W32
1749 {(char_u *)1L, (char_u *)0L}
1750#else
1751 {(char_u *)0L, (char_u *)0L}
1752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001753 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754 {"lisp", NULL, P_BOOL|P_VI_DEF,
1755#ifdef FEAT_LISP
1756 (char_u *)&p_lisp, PV_LISP,
1757#else
1758 (char_u *)NULL, PV_NONE,
1759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001760 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001761 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001763 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1765#else
1766 (char_u *)NULL, PV_NONE,
1767 {(char_u *)"", (char_u *)0L}
1768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001769 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1771 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001772 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001773 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001775 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1777 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001778 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001779#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001780 {"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1781 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001782 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1783 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001784#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001785#ifdef FEAT_GUI_MAC
1786 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1787 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001789#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"magic", NULL, P_BOOL|P_VI_DEF,
1791 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001792 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001793 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001794#ifdef FEAT_QUICKFIX
1795 (char_u *)&p_mef, PV_NONE,
1796 {(char_u *)"", (char_u *)0L}
1797#else
1798 (char_u *)NULL, PV_NONE,
1799 {(char_u *)NULL, (char_u *)0L}
1800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001801 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001802 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1803#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001804 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001805# ifdef VMS
1806 {(char_u *)"MMS", (char_u *)0L}
1807# else
1808 {(char_u *)"make", (char_u *)0L}
1809# endif
1810#else
1811 (char_u *)NULL, PV_NONE,
1812 {(char_u *)NULL, (char_u *)0L}
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001815 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1818 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001819 {"matchtime", "mat", P_NUM|P_VI_DEF,
1820 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001821 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001822 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001823#ifdef FEAT_MBYTE
1824 (char_u *)&p_mco, PV_NONE,
1825#else
1826 (char_u *)NULL, PV_NONE,
1827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001828 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1830#ifdef FEAT_EVAL
1831 (char_u *)&p_mfd, PV_NONE,
1832#else
1833 (char_u *)NULL, PV_NONE,
1834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001835 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1837 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"maxmem", "mm", P_NUM|P_VI_DEF,
1840 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1842 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001843 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1844 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001845 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1847 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1849 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"menuitems", "mis", P_NUM|P_VI_DEF,
1851#ifdef FEAT_MENU
1852 (char_u *)&p_mis, PV_NONE,
1853#else
1854 (char_u *)NULL, PV_NONE,
1855#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001856 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"mesg", NULL, P_BOOL|P_VI_DEF,
1858 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001860 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001861#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001862 (char_u *)&p_msm, PV_NONE,
1863 {(char_u *)"460000,2000,500", (char_u *)0L}
1864#else
1865 (char_u *)NULL, PV_NONE,
1866 {(char_u *)0L, (char_u *)0L}
1867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001868 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"modeline", "ml", P_BOOL|P_VIM,
1870 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"modelines", "mls", P_NUM|P_VI_DEF,
1873 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001874 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001875 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1876 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001877 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1879 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001880 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001881 {"more", NULL, P_BOOL|P_VIM,
1882 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001883 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1885 (char_u *)&p_mouse, PV_NONE,
1886 {
1887#if defined(MSDOS) || defined(WIN3264)
1888 (char_u *)"a",
1889#else
1890 (char_u *)"",
1891#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001892 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1894#ifdef FEAT_GUI
1895 (char_u *)&p_mousef, PV_NONE,
1896#else
1897 (char_u *)NULL, PV_NONE,
1898#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1901#ifdef FEAT_GUI
1902 (char_u *)&p_mh, PV_NONE,
1903#else
1904 (char_u *)NULL, PV_NONE,
1905#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001906 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1908 (char_u *)&p_mousem, PV_NONE,
1909 {
1910#if defined(MSDOS) || defined(MSWIN)
1911 (char_u *)"popup",
1912#else
1913# if defined(MACOS)
1914 (char_u *)"popup_setpos",
1915# else
1916 (char_u *)"extend",
1917# endif
1918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001920 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921#ifdef FEAT_MOUSESHAPE
1922 (char_u *)&p_mouseshape, PV_NONE,
1923 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1924#else
1925 (char_u *)NULL, PV_NONE,
1926 {(char_u *)NULL, (char_u *)0L}
1927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001928 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1930 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001931 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001932 {"mzquantum", "mzq", P_NUM,
1933#ifdef FEAT_MZSCHEME
1934 (char_u *)&p_mzq, PV_NONE,
1935#else
1936 (char_u *)NULL, PV_NONE,
1937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001938 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 {"novice", NULL, P_BOOL|P_VI_DEF,
1940 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001942 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001943 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001944 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001945 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001946 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1947 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001948 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001949 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1950#ifdef FEAT_LINEBREAK
1951 (char_u *)VAR_WIN, PV_NUW,
1952#else
1953 (char_u *)NULL, PV_NONE,
1954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001956 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001957#ifdef FEAT_COMPL_FUNC
1958 (char_u *)&p_ofu, PV_OFU,
1959 {(char_u *)"", (char_u *)0L}
1960#else
1961 (char_u *)NULL, PV_NONE,
1962 {(char_u *)0L, (char_u *)0L}
1963#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001965 {"open", NULL, P_BOOL|P_VI_DEF,
1966 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001967 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001968 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001969#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001970 (char_u *)&p_odev, PV_NONE,
1971#else
1972 (char_u *)NULL, PV_NONE,
1973#endif
1974 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001975 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001976 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1977 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"optimize", "opt", P_BOOL|P_VI_DEF,
1980 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001984 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"paragraphs", "para", P_STRING|P_VI_DEF,
1986 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001987 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001989 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001990 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1993 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1996#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1997 (char_u *)&p_pex, PV_NONE,
1998 {(char_u *)"", (char_u *)0L}
1999#else
2000 (char_u *)NULL, PV_NONE,
2001 {(char_u *)0L, (char_u *)0L}
2002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002003 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002004 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002005 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002008 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 {
2010#if defined AMIGA || defined MSDOS || defined MSWIN
2011 (char_u *)".,,",
2012#else
2013# if defined(__EMX__)
2014 (char_u *)".,/emx/include,,",
2015# else /* Unix, probably */
2016 (char_u *)".,/usr/include,,",
2017# endif
2018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002019 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002020#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002021 {"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2022 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002023 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2024 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002025#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2027 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002028 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002029 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2031 (char_u *)&p_pvh, PV_NONE,
2032#else
2033 (char_u *)NULL, PV_NONE,
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2037#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2038 (char_u *)VAR_WIN, PV_PVW,
2039#else
2040 (char_u *)NULL, PV_NONE,
2041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002043 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044#ifdef FEAT_PRINTER
2045 (char_u *)&p_pdev, PV_NONE,
2046 {(char_u *)"", (char_u *)0L}
2047#else
2048 (char_u *)NULL, PV_NONE,
2049 {(char_u *)NULL, (char_u *)0L}
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"printencoding", "penc", P_STRING|P_VI_DEF,
2053#ifdef FEAT_POSTSCRIPT
2054 (char_u *)&p_penc, PV_NONE,
2055 {(char_u *)"", (char_u *)0L}
2056#else
2057 (char_u *)NULL, PV_NONE,
2058 {(char_u *)NULL, (char_u *)0L}
2059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002060 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2062#ifdef FEAT_POSTSCRIPT
2063 (char_u *)&p_pexpr, PV_NONE,
2064 {(char_u *)"", (char_u *)0L}
2065#else
2066 (char_u *)NULL, PV_NONE,
2067 {(char_u *)NULL, (char_u *)0L}
2068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002069 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070 {"printfont", "pfn", P_STRING|P_VI_DEF,
2071#ifdef FEAT_PRINTER
2072 (char_u *)&p_pfn, PV_NONE,
2073 {
2074# ifdef MSWIN
2075 (char_u *)"Courier_New:h10",
2076# else
2077 (char_u *)"courier",
2078# endif
2079 (char_u *)0L}
2080#else
2081 (char_u *)NULL, PV_NONE,
2082 {(char_u *)NULL, (char_u *)0L}
2083#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2086#ifdef FEAT_PRINTER
2087 (char_u *)&p_header, PV_NONE,
2088 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2089#else
2090 (char_u *)NULL, PV_NONE,
2091 {(char_u *)NULL, (char_u *)0L}
2092#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002093 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002094 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2095#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2096 (char_u *)&p_pmcs, PV_NONE,
2097 {(char_u *)"", (char_u *)0L}
2098#else
2099 (char_u *)NULL, PV_NONE,
2100 {(char_u *)NULL, (char_u *)0L}
2101#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002102 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002103 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2104#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2105 (char_u *)&p_pmfn, PV_NONE,
2106 {(char_u *)"", (char_u *)0L}
2107#else
2108 (char_u *)NULL, PV_NONE,
2109 {(char_u *)NULL, (char_u *)0L}
2110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002111 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002112 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113#ifdef FEAT_PRINTER
2114 (char_u *)&p_popt, PV_NONE,
2115 {(char_u *)"", (char_u *)0L}
2116#else
2117 (char_u *)NULL, PV_NONE,
2118 {(char_u *)NULL, (char_u *)0L}
2119#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002120 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002122 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002123 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002124 {"pumheight", "ph", P_NUM|P_VI_DEF,
2125#ifdef FEAT_INS_EXPAND
2126 (char_u *)&p_ph, PV_NONE,
2127#else
2128 (char_u *)NULL, PV_NONE,
2129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002130 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002131#if defined(DYNAMIC_PYTHON3)
Bram Moolenaar0796c062015-11-10 19:41:37 +01002132 {"pythonthreedll", NULL, P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002133 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002134 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2135 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002136#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002137#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002138 {"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2139 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002140 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2141 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002142#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 Moolenaar25e4fcd2016-01-09 14:57:47 +01002216#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002217 {"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2218 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002219 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2220 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2223#ifdef FEAT_CMDL_INFO
2224 (char_u *)&p_ru, PV_NONE,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002229 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2230#ifdef FEAT_STL_OPT
2231 (char_u *)&p_ruf, PV_NONE,
2232#else
2233 (char_u *)NULL, PV_NONE,
2234#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002235 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002236 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2237 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002239 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2240 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2242 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002243 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2245#ifdef FEAT_SCROLLBIND
2246 (char_u *)VAR_WIN, PV_SCBIND,
2247#else
2248 (char_u *)NULL, PV_NONE,
2249#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002250 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2252 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002253 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2255 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002256 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002257 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258#ifdef FEAT_SCROLLBIND
2259 (char_u *)&p_sbo, PV_NONE,
2260 {(char_u *)"ver,jump", (char_u *)0L}
2261#else
2262 (char_u *)NULL, PV_NONE,
2263 {(char_u *)0L, (char_u *)0L}
2264#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"sections", "sect", P_STRING|P_VI_DEF,
2267 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2269 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2271 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002275 {(char_u *)"inclusive", (char_u *)0L}
2276 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002277 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002278 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002280 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281#ifdef FEAT_SESSION
2282 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002283 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 (char_u *)0L}
2285#else
2286 (char_u *)NULL, PV_NONE,
2287 {(char_u *)0L, (char_u *)0L}
2288#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2291 (char_u *)&p_sh, PV_NONE,
2292 {
2293#ifdef VMS
2294 (char_u *)"-",
2295#else
2296# if defined(MSDOS)
2297 (char_u *)"command",
2298# else
Bram Moolenaarcf7164a2016-02-20 13:55:06 +01002299# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 (char_u *)"", /* set in set_init_1() */
Bram Moolenaarcf7164a2016-02-20 13:55:06 +01002301# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303# endif
2304# endif
2305#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002306 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2308 (char_u *)&p_shcf, PV_NONE,
2309 {
2310#if defined(MSDOS) || defined(MSWIN)
2311 (char_u *)"/c",
2312#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002315 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002316 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2317#ifdef FEAT_QUICKFIX
2318 (char_u *)&p_sp, PV_NONE,
2319 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002320#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322#else
2323 (char_u *)">",
2324#endif
2325 (char_u *)0L}
2326#else
2327 (char_u *)NULL, PV_NONE,
2328 {(char_u *)0L, (char_u *)0L}
2329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2332 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002333 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2335 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002336 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2338#ifdef BACKSLASH_IN_FILENAME
2339 (char_u *)&p_ssl, PV_NONE,
2340#else
2341 (char_u *)NULL, PV_NONE,
2342#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002343 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002344 {"shelltemp", "stmp", P_BOOL,
2345 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"shelltype", "st", P_NUM|P_VI_DEF,
2348#ifdef AMIGA
2349 (char_u *)&p_st, PV_NONE,
2350#else
2351 (char_u *)NULL, PV_NONE,
2352#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002353 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2355 (char_u *)&p_sxq, PV_NONE,
2356 {
2357#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2358 (char_u *)"\"",
2359#else
2360 (char_u *)"",
2361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002363 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2364 (char_u *)&p_sxe, PV_NONE,
2365 {
Bram Moolenaarcf7164a2016-02-20 13:55:06 +01002366#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002367 (char_u *)"\"&|<>()@^",
2368#else
2369 (char_u *)"",
2370#endif
2371 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2373 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2376 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2379 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)"", (char_u *)"filnxtToO"}
2381 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 {"shortname", "sn", P_BOOL|P_VI_DEF,
2383#ifdef SHORT_FNAME
2384 (char_u *)NULL, PV_NONE,
2385#else
2386 (char_u *)&p_sn, PV_SN,
2387#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002388 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2390#ifdef FEAT_LINEBREAK
2391 (char_u *)&p_sbr, PV_NONE,
2392#else
2393 (char_u *)NULL, PV_NONE,
2394#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 {"showcmd", "sc", P_BOOL|P_VIM,
2397#ifdef FEAT_CMDL_INFO
2398 (char_u *)&p_sc, PV_NONE,
2399#else
2400 (char_u *)NULL, PV_NONE,
2401#endif
2402 {(char_u *)FALSE,
2403#ifdef UNIX
2404 (char_u *)FALSE
2405#else
2406 (char_u *)TRUE
2407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002408 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2410 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002411 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2413 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002414 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415 {"showmode", "smd", P_BOOL|P_VIM,
2416 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002417 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002418 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2419#ifdef FEAT_WINDOWS
2420 (char_u *)&p_stal, PV_NONE,
2421#else
2422 (char_u *)NULL, PV_NONE,
2423#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002424 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2426 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002427 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002428 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2429 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002430 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2432 (char_u *)NULL, 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 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2435 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2438#ifdef FEAT_SMARTINDENT
2439 (char_u *)&p_si, PV_SI,
2440#else
2441 (char_u *)NULL, PV_NONE,
2442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002443 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2445 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002446 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2448 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"sourceany", NULL, 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 Moolenaar217ad922005-03-20 22:37:15 +00002453 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002454#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002455 (char_u *)VAR_WIN, PV_SPELL,
2456#else
2457 (char_u *)NULL, PV_NONE,
2458#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002460 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002461#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002462 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002463 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002464#else
2465 (char_u *)NULL, PV_NONE,
2466 {(char_u *)0L, (char_u *)0L}
2467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002469 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2470 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002471#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002472 (char_u *)&p_spf, PV_SPF,
2473 {(char_u *)"", (char_u *)0L}
2474#else
2475 (char_u *)NULL, PV_NONE,
2476 {(char_u *)0L, (char_u *)0L}
2477#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002479 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2480 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002481#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002482 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002483 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002484#else
2485 (char_u *)NULL, PV_NONE,
2486 {(char_u *)0L, (char_u *)0L}
2487#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002488 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002489 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002490#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002491 (char_u *)&p_sps, PV_NONE,
2492 {(char_u *)"best", (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 Moolenaar071d4272004-06-13 20:20:40 +00002498 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2499#ifdef FEAT_WINDOWS
2500 (char_u *)&p_sb, PV_NONE,
2501#else
2502 (char_u *)NULL, PV_NONE,
2503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"splitright", "spr", P_BOOL|P_VI_DEF,
2506#ifdef FEAT_VERTSPLIT
2507 (char_u *)&p_spr, PV_NONE,
2508#else
2509 (char_u *)NULL, PV_NONE,
2510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2513 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2516#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002517 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518#else
2519 (char_u *)NULL, PV_NONE,
2520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002522 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 (char_u *)&p_su, PV_NONE,
2524 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002526 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002527#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 (char_u *)&p_sua, PV_SUA,
2529 {(char_u *)"", (char_u *)0L}
2530#else
2531 (char_u *)NULL, PV_NONE,
2532 {(char_u *)0L, (char_u *)0L}
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2536 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"swapsync", "sws", P_STRING|P_VI_DEF,
2539 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002541 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002544 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2545#ifdef FEAT_SYN_HL
2546 (char_u *)&p_smc, PV_SMC,
2547 {(char_u *)3000L, (char_u *)0L}
2548#else
2549 (char_u *)NULL, PV_NONE,
2550 {(char_u *)0L, (char_u *)0L}
2551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002552 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002553 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554#ifdef FEAT_SYN_HL
2555 (char_u *)&p_syn, PV_SYN,
2556 {(char_u *)"", (char_u *)0L}
2557#else
2558 (char_u *)NULL, PV_NONE,
2559 {(char_u *)0L, (char_u *)0L}
2560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002562 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2563#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002564 (char_u *)&p_tal, PV_NONE,
2565#else
2566 (char_u *)NULL, PV_NONE,
2567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002569 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2570#ifdef FEAT_WINDOWS
2571 (char_u *)&p_tpm, PV_NONE,
2572#else
2573 (char_u *)NULL, PV_NONE,
2574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2577 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2580 (char_u *)&p_tbs, PV_NONE,
2581#ifdef VMS /* binary searching doesn't appear to work on VMS */
2582 {(char_u *)0L, (char_u *)0L}
2583#else
2584 {(char_u *)TRUE, (char_u *)0L}
2585#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002587 {"tagcase", "tc", P_STRING|P_VIM,
2588 (char_u *)&p_tc, PV_TC,
2589 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 {"taglength", "tl", P_NUM|P_VI_DEF,
2591 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002592 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593 {"tagrelative", "tr", P_BOOL|P_VIM,
2594 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002595 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002596 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002597 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 {
2599#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2600 (char_u *)"./tags,./TAGS,tags,TAGS",
2601#else
2602 (char_u *)"./tags,tags",
2603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002604 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2606 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002607 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002608#if defined(DYNAMIC_TCL)
2609 {"tcldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2610 (char_u *)&p_tcldll, PV_NONE,
2611 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2612 SCRIPTID_INIT},
2613#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2615 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2618#ifdef FEAT_ARABIC
2619 (char_u *)&p_tbidi, PV_NONE,
2620#else
2621 (char_u *)NULL, PV_NONE,
2622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2625#ifdef FEAT_MBYTE
2626 (char_u *)&p_tenc, PV_NONE,
2627 {(char_u *)"", (char_u *)0L}
2628#else
2629 (char_u *)NULL, PV_NONE,
2630 {(char_u *)0L, (char_u *)0L}
2631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 {"terse", NULL, P_BOOL|P_VI_DEF,
2634 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002635 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 {"textauto", "ta", P_BOOL|P_VIM,
2637 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002638 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2639 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2641 (char_u *)&p_tx, PV_TX,
2642 {
2643#ifdef USE_CRNL
2644 (char_u *)TRUE,
2645#else
2646 (char_u *)FALSE,
2647#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002649 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002652 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002654 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655#else
2656 (char_u *)NULL, PV_NONE,
2657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002658 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2660 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662 {"timeout", "to", P_BOOL|P_VI_DEF,
2663 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2666 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"title", NULL, P_BOOL|P_VI_DEF,
2669#ifdef FEAT_TITLE
2670 (char_u *)&p_title, PV_NONE,
2671#else
2672 (char_u *)NULL, PV_NONE,
2673#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002674 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"titlelen", NULL, P_NUM|P_VI_DEF,
2676#ifdef FEAT_TITLE
2677 (char_u *)&p_titlelen, PV_NONE,
2678#else
2679 (char_u *)NULL, PV_NONE,
2680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002681 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002682 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683#ifdef FEAT_TITLE
2684 (char_u *)&p_titleold, PV_NONE,
2685 {(char_u *)N_("Thanks for flying Vim"),
2686 (char_u *)0L}
2687#else
2688 (char_u *)NULL, PV_NONE,
2689 {(char_u *)0L, (char_u *)0L}
2690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {"titlestring", NULL, P_STRING|P_VI_DEF,
2693#ifdef FEAT_TITLE
2694 (char_u *)&p_titlestring, PV_NONE,
2695#else
2696 (char_u *)NULL, PV_NONE,
2697#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002700 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002702 {(char_u *)"icons,tooltips", (char_u *)0L}
2703 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002705#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002706 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2707 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709#endif
2710 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2711 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002712 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2714 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2717 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2720 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2723#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2724 (char_u *)&p_ttym, PV_NONE,
2725#else
2726 (char_u *)NULL, PV_NONE,
2727#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2730 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2733 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002735 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2736 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002737#ifdef FEAT_PERSISTENT_UNDO
2738 (char_u *)&p_udir, PV_NONE,
2739 {(char_u *)".", (char_u *)0L}
2740#else
2741 (char_u *)NULL, PV_NONE,
2742 {(char_u *)0L, (char_u *)0L}
2743#endif
2744 SCRIPTID_INIT},
2745 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2746#ifdef FEAT_PERSISTENT_UNDO
2747 (char_u *)&p_udf, PV_UDF,
2748#else
2749 (char_u *)NULL, PV_NONE,
2750#endif
2751 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002753 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002755#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 (char_u *)1000L,
2757#else
2758 (char_u *)100L,
2759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002760 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002761 {"undoreload", "ur", P_NUM|P_VI_DEF,
2762 (char_u *)&p_ur, PV_NONE,
2763 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 {"updatecount", "uc", P_NUM|P_VI_DEF,
2765 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"updatetime", "ut", P_NUM|P_VI_DEF,
2768 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002769 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 {"verbose", "vbs", P_NUM|P_VI_DEF,
2771 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002772 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002773 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2774 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2777#ifdef FEAT_SESSION
2778 (char_u *)&p_vdir, PV_NONE,
2779 {(char_u *)DFLT_VDIR, (char_u *)0L}
2780#else
2781 (char_u *)NULL, PV_NONE,
2782 {(char_u *)0L, (char_u *)0L}
2783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002784 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002785 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786#ifdef FEAT_SESSION
2787 (char_u *)&p_vop, PV_NONE,
2788 {(char_u *)"folds,options,cursor", (char_u *)0L}
2789#else
2790 (char_u *)NULL, PV_NONE,
2791 {(char_u *)0L, (char_u *)0L}
2792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002793 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002794 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795#ifdef FEAT_VIMINFO
2796 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002797#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002798 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799#else
2800# ifdef AMIGA
2801 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002802 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002804 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805# endif
2806#endif
2807#else
2808 (char_u *)NULL, PV_NONE,
2809 {(char_u *)0L, (char_u *)0L}
2810#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002811 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002812 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2813 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814#ifdef FEAT_VIRTUALEDIT
2815 (char_u *)&p_ve, PV_NONE,
2816 {(char_u *)"", (char_u *)""}
2817#else
2818 (char_u *)NULL, PV_NONE,
2819 {(char_u *)0L, (char_u *)0L}
2820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2823 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 {"w300", NULL, P_NUM|P_VI_DEF,
2826 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002827 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 {"w1200", NULL, P_NUM|P_VI_DEF,
2829 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002830 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831 {"w9600", NULL, P_NUM|P_VI_DEF,
2832 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"warn", NULL, P_BOOL|P_VI_DEF,
2835 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002836 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2838 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002840 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"wildchar", "wc", P_NUM|P_VIM,
2844 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2846 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002847 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002850 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851#ifdef FEAT_WILDIGN
2852 (char_u *)&p_wig, PV_NONE,
2853#else
2854 (char_u *)NULL, PV_NONE,
2855#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002856 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002857 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2858 (char_u *)&p_wic, PV_NONE,
2859 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2861#ifdef FEAT_WILDMENU
2862 (char_u *)&p_wmnu, PV_NONE,
2863#else
2864 (char_u *)NULL, PV_NONE,
2865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002867 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002870 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2871#ifdef FEAT_CMDL_COMPL
2872 (char_u *)&p_wop, PV_NONE,
2873 {(char_u *)"", (char_u *)0L}
2874#else
2875 (char_u *)NULL, PV_NONE,
2876 {(char_u *)NULL, (char_u *)0L}
2877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002878 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2880#ifdef FEAT_WAK
2881 (char_u *)&p_wak, PV_NONE,
2882 {(char_u *)"menu", (char_u *)0L}
2883#else
2884 (char_u *)NULL, PV_NONE,
2885 {(char_u *)NULL, (char_u *)0L}
2886#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002887 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002889 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002890 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 {"winheight", "wh", P_NUM|P_VI_DEF,
2892#ifdef FEAT_WINDOWS
2893 (char_u *)&p_wh, PV_NONE,
2894#else
2895 (char_u *)NULL, PV_NONE,
2896#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002897 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002899#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 (char_u *)VAR_WIN, PV_WFH,
2901#else
2902 (char_u *)NULL, PV_NONE,
2903#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002904 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002905 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2906#ifdef FEAT_VERTSPLIT
2907 (char_u *)VAR_WIN, PV_WFW,
2908#else
2909 (char_u *)NULL, PV_NONE,
2910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002911 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2913#ifdef FEAT_WINDOWS
2914 (char_u *)&p_wmh, PV_NONE,
2915#else
2916 (char_u *)NULL, PV_NONE,
2917#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002918 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2920#ifdef FEAT_VERTSPLIT
2921 (char_u *)&p_wmw, PV_NONE,
2922#else
2923 (char_u *)NULL, PV_NONE,
2924#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002926 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2927#ifdef FEAT_VERTSPLIT
2928 (char_u *)&p_wiw, PV_NONE,
2929#else
2930 (char_u *)NULL, PV_NONE,
2931#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002932 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2934 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002936 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2937 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2940 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002941 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942 {"write", NULL, P_BOOL|P_VI_DEF,
2943 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002944 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945 {"writeany", "wa", P_BOOL|P_VI_DEF,
2946 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002947 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2949 (char_u *)&p_wb, PV_NONE,
2950 {
2951#ifdef FEAT_WRITEBACKUP
2952 (char_u *)TRUE,
2953#else
2954 (char_u *)FALSE,
2955#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002956 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957 {"writedelay", "wd", P_NUM|P_VI_DEF,
2958 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002959 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960
2961/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002962#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002964 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965
2966 p_term("t_AB", T_CAB)
2967 p_term("t_AF", T_CAF)
2968 p_term("t_AL", T_CAL)
2969 p_term("t_al", T_AL)
2970 p_term("t_bc", T_BC)
2971 p_term("t_cd", T_CD)
2972 p_term("t_ce", T_CE)
2973 p_term("t_cl", T_CL)
2974 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002975 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 p_term("t_Co", T_CCO)
2977 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002978 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 p_term("t_cs", T_CS)
2980#ifdef FEAT_VERTSPLIT
2981 p_term("t_CV", T_CSV)
2982#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 p_term("t_da", T_DA)
2984 p_term("t_db", T_DB)
2985 p_term("t_DL", T_CDL)
2986 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002987 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 p_term("t_fs", T_FS)
2989 p_term("t_IE", T_CIE)
2990 p_term("t_IS", T_CIS)
2991 p_term("t_ke", T_KE)
2992 p_term("t_ks", T_KS)
2993 p_term("t_le", T_LE)
2994 p_term("t_mb", T_MB)
2995 p_term("t_md", T_MD)
2996 p_term("t_me", T_ME)
2997 p_term("t_mr", T_MR)
2998 p_term("t_ms", T_MS)
2999 p_term("t_nd", T_ND)
3000 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003001 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 p_term("t_RI", T_CRI)
3003 p_term("t_RV", T_CRV)
3004 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003006 p_term("t_Sf", T_CSF)
3007 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003009 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003010 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_te", T_TE)
3012 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003013 p_term("t_ts", T_TS)
3014 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 p_term("t_ue", T_UE)
3016 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003017 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 p_term("t_vb", T_VB)
3019 p_term("t_ve", T_VE)
3020 p_term("t_vi", T_VI)
3021 p_term("t_vs", T_VS)
3022 p_term("t_WP", T_CWP)
3023 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003024 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 p_term("t_xs", T_XS)
3026 p_term("t_ZH", T_CZH)
3027 p_term("t_ZR", T_CZR)
3028
3029/* terminal key codes are not in here */
3030
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003031 /* end marker */
3032 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033};
3034
3035#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3036
3037#ifdef FEAT_MBYTE
3038static char *(p_ambw_values[]) = {"single", "double", NULL};
3039#endif
3040static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003041static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003043#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003044static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003045#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003046#ifdef FEAT_CMDL_COMPL
3047static char *(p_wop_values[]) = {"tagfile", NULL};
3048#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049#ifdef FEAT_WAK
3050static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3051#endif
3052static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3054static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056#ifdef FEAT_BROWSE
3057static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3058#endif
3059#ifdef FEAT_SCROLLBIND
3060static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3061#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003062static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063#ifdef FEAT_VERTSPLIT
3064static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3065#endif
3066#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003067# ifdef FEAT_AUTOCMD
3068static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3069# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003071# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3073#endif
3074static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3075#ifdef FEAT_FOLDING
3076static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003077# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003079# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 NULL};
3081static char *(p_fcl_values[]) = {"all", NULL};
3082#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003083#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003084static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003085#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003087static void set_option_default(int, int opt_flags, int compatible);
3088static void set_options_default(int opt_flags);
3089static char_u *term_bg_default(void);
3090static void did_set_option(int opt_idx, int opt_flags, int new_value);
3091static char_u *illegal_char(char_u *, int);
3092static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003094static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095#endif
3096#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003097static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003099static char_u *option_expand(int opt_idx, char_u *val);
3100static void didset_options(void);
3101static void didset_options2(void);
3102static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003103#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003104static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003105#else
3106# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3107#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003108static void set_string_option_global(int opt_idx, char_u **varp);
3109static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3110static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3111static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003112#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003113static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003114#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003116static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003118#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003119static char_u *did_set_spell_option(int is_spellfile);
3120static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003121#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003122#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003123static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003124#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003125static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3126static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3127static void check_redraw(long_u flags);
3128static int findoption(char_u *);
3129static int find_key_option(char_u *);
3130static void showoptions(int all, int opt_flags);
3131static int optval_default(struct vimoption *, char_u *varp);
3132static void showoneopt(struct vimoption *, int opt_flags);
3133static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3134static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3135static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3136static int istermoption(struct vimoption *);
3137static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3138static char_u *get_varp(struct vimoption *);
3139static void option_value2string(struct vimoption *, int opt_flags);
3140static void check_winopt(winopt_T *wop);
3141static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003143static void langmap_init(void);
3144static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003146static void paste_option_changed(void);
3147static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003149static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003151static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3152static int check_opt_strings(char_u *val, char **values, int);
3153static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003154#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003155static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157
3158/*
3159 * Initialize the options, first part.
3160 *
3161 * Called only once from main(), just after creating the first buffer.
3162 */
3163 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003164set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165{
3166 char_u *p;
3167 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003168 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169
3170#ifdef FEAT_LANGMAP
3171 langmap_init();
3172#endif
3173
3174 /* Be Vi compatible by default */
3175 p_cp = TRUE;
3176
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003177 /* Use POSIX compatibility when $VIM_POSIX is set. */
3178 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003179 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003180 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003181 set_string_default("shm", (char_u *)"A");
3182 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003183
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184 /*
3185 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003186 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003188 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003189#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003191 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003193 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003195 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196# endif
3197#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003198 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199 set_string_default("sh", p);
3200
3201#ifdef FEAT_WILDIGN
3202 /*
3203 * Set the default for 'backupskip' to include environment variables for
3204 * temp files.
3205 */
3206 {
3207# ifdef UNIX
3208 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3209# else
3210 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3211# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003212 int len;
3213 garray_T ga;
3214 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215
3216 ga_init2(&ga, 1, 100);
3217 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3218 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003219 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220# ifdef UNIX
3221 if (*names[n] == NUL)
3222 p = (char_u *)"/tmp";
3223 else
3224# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003225 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 if (p != NULL && *p != NUL)
3227 {
3228 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003229 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230 if (ga_grow(&ga, len) == OK)
3231 {
3232 if (ga.ga_len > 0)
3233 STRCAT(ga.ga_data, ",");
3234 STRCAT(ga.ga_data, p);
3235 add_pathsep(ga.ga_data);
3236 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237 ga.ga_len += len;
3238 }
3239 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003240 if (mustfree)
3241 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242 }
3243 if (ga.ga_data != NULL)
3244 {
3245 set_string_default("bsk", ga.ga_data);
3246 vim_free(ga.ga_data);
3247 }
3248 }
3249#endif
3250
3251 /*
3252 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3253 */
3254 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003255 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003257#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3258 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3259#endif
3260 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003262 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003263 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264#else
3265# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003266 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003267 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003269 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270# endif
3271#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003273 opt_idx = findoption((char_u *)"maxmem");
3274 if (opt_idx >= 0)
3275 {
3276#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003277 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3278 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003279#endif
3280 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3281 }
3282 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283 }
3284
3285#ifdef FEAT_GUI_W32
3286 /* force 'shortname' for Win32s */
3287 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003288 {
3289 opt_idx = findoption((char_u *)"shortname");
3290 if (opt_idx >= 0)
3291 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3292 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003293#endif
3294
3295#ifdef FEAT_SEARCHPATH
3296 {
3297 char_u *cdpath;
3298 char_u *buf;
3299 int i;
3300 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003301 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302
3303 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003304 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305 if (cdpath != NULL)
3306 {
3307 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3308 if (buf != NULL)
3309 {
3310 buf[0] = ','; /* start with ",", current dir first */
3311 j = 1;
3312 for (i = 0; cdpath[i] != NUL; ++i)
3313 {
3314 if (vim_ispathlistsep(cdpath[i]))
3315 buf[j++] = ',';
3316 else
3317 {
3318 if (cdpath[i] == ' ' || cdpath[i] == ',')
3319 buf[j++] = '\\';
3320 buf[j++] = cdpath[i];
3321 }
3322 }
3323 buf[j] = NUL;
3324 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003325 if (opt_idx >= 0)
3326 {
3327 options[opt_idx].def_val[VI_DEFAULT] = buf;
3328 options[opt_idx].flags |= P_DEF_ALLOCED;
3329 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003330 else
3331 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003333 if (mustfree)
3334 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335 }
3336 }
3337#endif
3338
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003339#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340 /* Set print encoding on platforms that don't default to latin1 */
3341 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003342# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343 (char_u *)"cp1252"
3344# else
3345# ifdef VMS
3346 (char_u *)"dec-mcs"
3347# else
3348# ifdef EBCDIC
3349 (char_u *)"ebcdic-uk"
3350# else
3351# ifdef MAC
3352 (char_u *)"mac-roman"
3353# else /* HPUX */
3354 (char_u *)"hp-roman8"
3355# endif
3356# endif
3357# endif
3358# endif
3359 );
3360#endif
3361
3362#ifdef FEAT_POSTSCRIPT
3363 /* 'printexpr' must be allocated to be able to evaluate it. */
3364 set_string_default("pexpr",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003365# if defined(MSWIN) || defined(MSDOS)
Bram Moolenaared203462004-06-16 11:19:22 +00003366 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367# else
3368# ifdef VMS
3369 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3370
3371# else
3372 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3373# endif
3374# endif
3375 );
3376#endif
3377
3378 /*
3379 * Set all the options (except the terminal options) to their default
3380 * value. Also set the global value for local options.
3381 */
3382 set_options_default(0);
3383
3384#ifdef FEAT_GUI
3385 if (found_reverse_arg)
3386 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3387#endif
3388
3389 curbuf->b_p_initialized = TRUE;
3390 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003391 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392 check_buf_options(curbuf);
3393 check_win_options(curwin);
3394 check_options();
3395
3396 /* Must be before option_expand(), because that one needs vim_isIDc() */
3397 didset_options();
3398
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003399#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003400 /* Use the current chartab for the generic chartab. This is not in
3401 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003402 init_spell_chartab();
3403#endif
3404
Bram Moolenaar071d4272004-06-13 20:20:40 +00003405 /*
3406 * Expand environment variables and things like "~" for the defaults.
3407 * If option_expand() returns non-NULL the variable is expanded. This can
3408 * only happen for non-indirect options.
3409 * Also set the default to the expanded value, so ":set" does not list
3410 * them.
3411 * Don't set the P_ALLOCED flag, because we don't want to free the
3412 * default.
3413 */
3414 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3415 {
3416 if ((options[opt_idx].flags & P_GETTEXT)
3417 && options[opt_idx].var != NULL)
3418 p = (char_u *)_(*(char **)options[opt_idx].var);
3419 else
3420 p = option_expand(opt_idx, NULL);
3421 if (p != NULL && (p = vim_strsave(p)) != NULL)
3422 {
3423 *(char_u **)options[opt_idx].var = p;
3424 /* VIMEXP
3425 * Defaults for all expanded options are currently the same for Vi
3426 * and Vim. When this changes, add some code here! Also need to
3427 * split P_DEF_ALLOCED in two.
3428 */
3429 if (options[opt_idx].flags & P_DEF_ALLOCED)
3430 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3431 options[opt_idx].def_val[VI_DEFAULT] = p;
3432 options[opt_idx].flags |= P_DEF_ALLOCED;
3433 }
3434 }
3435
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436 save_file_ff(curbuf); /* Buffer is unchanged */
3437
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438#if defined(FEAT_ARABIC)
3439 /* Detect use of mlterm.
3440 * Mlterm is a terminal emulator akin to xterm that has some special
3441 * abilities (bidi namely).
3442 * NOTE: mlterm's author is being asked to 'set' a variable
3443 * instead of an environment variable due to inheritance.
3444 */
3445 if (mch_getenv((char_u *)"MLTERM") != NULL)
3446 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3447#endif
3448
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003449 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450
3451#ifdef FEAT_MBYTE
3452# if defined(WIN3264) && defined(FEAT_GETTEXT)
3453 /*
3454 * If $LANG isn't set, try to get a good value for it. This makes the
3455 * right language be used automatically. Don't do this for English.
3456 */
3457 if (mch_getenv((char_u *)"LANG") == NULL)
3458 {
3459 char buf[20];
3460
3461 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3462 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3463 * only the first two. */
3464 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3465 (LPTSTR)buf, 20);
3466 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3467 {
3468 /* There are a few exceptions (probably more) */
3469 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3470 STRCPY(buf, "zh_TW");
3471 else if (STRNICMP(buf, "chs", 3) == 0
3472 || STRNICMP(buf, "zhc", 3) == 0)
3473 STRCPY(buf, "zh_CN");
3474 else if (STRNICMP(buf, "jp", 2) == 0)
3475 STRCPY(buf, "ja");
3476 else
3477 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003478 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 }
3480 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003481# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003482# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003483 /* Moved to os_mac_conv.c to avoid dependency problems. */
3484 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003485# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486# endif
3487
3488 /* enc_locale() will try to find the encoding of the current locale. */
3489 p = enc_locale();
3490 if (p != NULL)
3491 {
3492 char_u *save_enc;
3493
3494 /* Try setting 'encoding' and check if the value is valid.
3495 * If not, go back to the default "latin1". */
3496 save_enc = p_enc;
3497 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003498 if (STRCMP(p_enc, "gb18030") == 0)
3499 {
3500 /* We don't support "gb18030", but "cp936" is a good substitute
3501 * for practical purposes, thus use that. It's not an alias to
3502 * still support conversion between gb18030 and utf-8. */
3503 p_enc = vim_strsave((char_u *)"cp936");
3504 vim_free(p);
3505 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506 if (mb_init() == NULL)
3507 {
3508 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003509 if (opt_idx >= 0)
3510 {
3511 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3512 options[opt_idx].flags |= P_DEF_ALLOCED;
3513 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003514
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003515#if defined(MSDOS) || defined(MSWIN) || defined(MACOS) \
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003516 || defined(VMS)
3517 if (STRCMP(p_enc, "latin1") == 0
3518# ifdef FEAT_MBYTE
3519 || enc_utf8
3520# endif
3521 )
3522 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003523 /* Adjust the default for 'isprint' and 'iskeyword' to match
3524 * latin1. Also set the defaults for when 'nocompatible' is
3525 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003526 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003527 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003528 set_string_option_direct((char_u *)"isk", -1,
3529 ISK_LATIN1, OPT_FREE, SID_NONE);
3530 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003531 if (opt_idx >= 0)
3532 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003533 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003534 if (opt_idx >= 0)
3535 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003536 (void)init_chartab();
3537 }
3538#endif
3539
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540# if defined(WIN3264) && !defined(FEAT_GUI)
3541 /* Win32 console: When GetACP() returns a different value from
3542 * GetConsoleCP() set 'termencoding'. */
3543 if (GetACP() != GetConsoleCP())
3544 {
3545 char buf[50];
3546
3547 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3548 p_tenc = vim_strsave((char_u *)buf);
3549 if (p_tenc != NULL)
3550 {
3551 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003552 if (opt_idx >= 0)
3553 {
3554 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3555 options[opt_idx].flags |= P_DEF_ALLOCED;
3556 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003557 convert_setup(&input_conv, p_tenc, p_enc);
3558 convert_setup(&output_conv, p_enc, p_tenc);
3559 }
3560 else
3561 p_tenc = empty_option;
3562 }
3563# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003564# if defined(WIN3264) && defined(FEAT_MBYTE)
3565 /* $HOME may have characters in active code page. */
3566 init_homedir();
3567# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003568 }
3569 else
3570 {
3571 vim_free(p_enc);
3572 p_enc = save_enc;
3573 }
3574 }
3575#endif
3576
3577#ifdef FEAT_MULTI_LANG
3578 /* Set the default for 'helplang'. */
3579 set_helplang_default(get_mess_lang());
3580#endif
3581}
3582
3583/*
3584 * Set an option to its default value.
3585 * This does not take care of side effects!
3586 */
3587 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003588set_option_default(
3589 int opt_idx,
3590 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3591 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592{
3593 char_u *varp; /* pointer to variable for current option */
3594 int dvi; /* index in def_val[] */
3595 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003596 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003597 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3598
3599 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3600 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003601 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003602 {
3603 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3604 if (flags & P_STRING)
3605 {
3606 /* Use set_string_option_direct() for local options to handle
3607 * freeing and allocating the value. */
3608 if (options[opt_idx].indir != PV_NONE)
3609 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003610 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003611 else
3612 {
3613 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3614 free_string_option(*(char_u **)(varp));
3615 *(char_u **)varp = options[opt_idx].def_val[dvi];
3616 options[opt_idx].flags &= ~P_ALLOCED;
3617 }
3618 }
3619 else if (flags & P_NUM)
3620 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003621 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622 win_comp_scroll(curwin);
3623 else
3624 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003625 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626 /* May also set global value for local option. */
3627 if (both)
3628 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3629 *(long *)varp;
3630 }
3631 }
3632 else /* P_BOOL */
3633 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003634 /* the cast to long is required for Manx C, long_i is needed for
3635 * MSVC */
3636 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003637#ifdef UNIX
3638 /* 'modeline' defaults to off for root */
3639 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3640 *(int *)varp = FALSE;
3641#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003642 /* May also set global value for local option. */
3643 if (both)
3644 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3645 *(int *)varp;
3646 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003647
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003648 /* The default value is not insecure. */
3649 flagsp = insecure_flag(opt_idx, opt_flags);
3650 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651 }
3652
3653#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003654 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655#endif
3656}
3657
3658/*
3659 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003660 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661 */
3662 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003663set_options_default(
3664 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003665{
3666 int i;
3667#ifdef FEAT_WINDOWS
3668 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003669 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003670#endif
3671
3672 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003673 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003674#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003675 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003676 || (TRUE
3677# if defined(FEAT_MBYTE)
3678 && options[i].var != (char_u *)&p_enc
3679# endif
3680# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003681 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003682 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003683# endif
3684 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003685#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003686 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687 set_option_default(i, opt_flags, p_cp);
3688
3689#ifdef FEAT_WINDOWS
3690 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003691 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692 win_comp_scroll(wp);
3693#else
3694 win_comp_scroll(curwin);
3695#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003696#ifdef FEAT_CINDENT
3697 parse_cino(curbuf);
3698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003699}
3700
3701/*
3702 * Set the Vi-default value of a string option.
3703 * Used for 'sh', 'backupskip' and 'term'.
3704 */
3705 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003706set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003707{
3708 char_u *p;
3709 int opt_idx;
3710
3711 p = vim_strsave(val);
3712 if (p != NULL) /* we don't want a NULL */
3713 {
3714 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003715 if (opt_idx >= 0)
3716 {
3717 if (options[opt_idx].flags & P_DEF_ALLOCED)
3718 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3719 options[opt_idx].def_val[VI_DEFAULT] = p;
3720 options[opt_idx].flags |= P_DEF_ALLOCED;
3721 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722 }
3723}
3724
3725/*
3726 * Set the Vi-default value of a number option.
3727 * Used for 'lines' and 'columns'.
3728 */
3729 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003730set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003732 int opt_idx;
3733
3734 opt_idx = findoption((char_u *)name);
3735 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003736 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737}
3738
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003739#if defined(EXITFREE) || defined(PROTO)
3740/*
3741 * Free all options.
3742 */
3743 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003744free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003745{
3746 int i;
3747
3748 for (i = 0; !istermoption(&options[i]); i++)
3749 {
3750 if (options[i].indir == PV_NONE)
3751 {
3752 /* global option: free value and default value. */
3753 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3754 free_string_option(*(char_u **)options[i].var);
3755 if (options[i].flags & P_DEF_ALLOCED)
3756 free_string_option(options[i].def_val[VI_DEFAULT]);
3757 }
3758 else if (options[i].var != VAR_WIN
3759 && (options[i].flags & P_STRING))
3760 /* buffer-local option: free global value */
3761 free_string_option(*(char_u **)options[i].var);
3762 }
3763}
3764#endif
3765
3766
Bram Moolenaar071d4272004-06-13 20:20:40 +00003767/*
3768 * Initialize the options, part two: After getting Rows and Columns and
3769 * setting 'term'.
3770 */
3771 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003772set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003774 int idx;
3775
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776 /*
3777 * 'scroll' defaults to half the window height. Note that this default is
3778 * wrong when the window height changes.
3779 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003780 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003781 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003782 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003783 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003784 comp_col();
3785
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003786 /*
3787 * 'window' is only for backwards compatibility with Vi.
3788 * Default is Rows - 1.
3789 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003790 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003791 p_window = Rows - 1;
3792 set_number_default("window", Rows - 1);
3793
Bram Moolenaarf740b292006-02-16 22:11:02 +00003794 /* For DOS console the default is always black. */
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003795#if !((defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003796 /*
3797 * If 'background' wasn't set by the user, try guessing the value,
3798 * depending on the terminal name. Only need to check for terminals
3799 * with a dark background, that can handle color.
3800 */
3801 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003802 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3803 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003804 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003805 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003806 /* don't mark it as set, when starting the GUI it may be
3807 * changed again */
3808 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 }
3810#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003811
3812#ifdef CURSOR_SHAPE
3813 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3814#endif
3815#ifdef FEAT_MOUSESHAPE
3816 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3817#endif
3818#ifdef FEAT_PRINTER
3819 (void)parse_printoptions(); /* parse 'printoptions' default value */
3820#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821}
3822
3823/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003824 * Return "dark" or "light" depending on the kind of terminal.
3825 * This is just guessing! Recognized are:
3826 * "linux" Linux console
3827 * "screen.linux" Linux console with screen
3828 * "cygwin" Cygwin shell
3829 * "putty" Putty program
3830 * We also check the COLORFGBG environment variable, which is set by
3831 * rxvt and derivatives. This variable contains either two or three
3832 * values separated by semicolons; we want the last value in either
3833 * case. If this value is 0-6 or 8, our background is dark.
3834 */
3835 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003836term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003837{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003838#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003839 /* DOS console nearly always black */
3840 return (char_u *)"dark";
3841#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003842 char_u *p;
3843
Bram Moolenaarf740b292006-02-16 22:11:02 +00003844 if (STRCMP(T_NAME, "linux") == 0
3845 || STRCMP(T_NAME, "screen.linux") == 0
3846 || STRCMP(T_NAME, "cygwin") == 0
3847 || STRCMP(T_NAME, "putty") == 0
3848 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3849 && (p = vim_strrchr(p, ';')) != NULL
3850 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3851 && p[2] == NUL))
3852 return (char_u *)"dark";
3853 return (char_u *)"light";
3854#endif
3855}
3856
3857/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 * Initialize the options, part three: After reading the .vimrc
3859 */
3860 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003861set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003863#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864/*
3865 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3866 * This is done after other initializations, where 'shell' might have been
3867 * set, but only if they have not been set before.
3868 */
3869 char_u *p;
3870 int idx_srr;
3871 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003872# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873 int idx_sp;
3874 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003875# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003876
3877 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003878 if (idx_srr < 0)
3879 do_srr = FALSE;
3880 else
3881 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003882# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003884 if (idx_sp < 0)
3885 do_sp = FALSE;
3886 else
3887 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003888# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003889 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890 if (p != NULL)
3891 {
3892 /*
3893 * Default for p_sp is "| tee", for p_srr is ">".
3894 * For known shells it is changed here to include stderr.
3895 */
3896 if ( fnamecmp(p, "csh") == 0
3897 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003898# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003899 || fnamecmp(p, "csh.exe") == 0
3900 || fnamecmp(p, "tcsh.exe") == 0
3901# endif
3902 )
3903 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003904# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003905 if (do_sp)
3906 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003907# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003909# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003910 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003911# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3913 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003914# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 if (do_srr)
3916 {
3917 p_srr = (char_u *)">&";
3918 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3919 }
3920 }
3921 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003922 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 if ( fnamecmp(p, "sh") == 0
3924 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003925 || fnamecmp(p, "mksh") == 0
3926 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003927 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003928 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003930 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003931# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003932 || fnamecmp(p, "cmd") == 0
3933 || fnamecmp(p, "sh.exe") == 0
3934 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003935 || fnamecmp(p, "mksh.exe") == 0
3936 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003938 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 || fnamecmp(p, "bash.exe") == 0
3940 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003942 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003944# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945 if (do_sp)
3946 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003947# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003949# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003951# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3953 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003954# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 if (do_srr)
3956 {
3957 p_srr = (char_u *)">%s 2>&1";
3958 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3959 }
3960 }
3961 vim_free(p);
3962 }
3963#endif
3964
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003965#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003967 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3968 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003969 * This is done after other initializations, where 'shell' might have been
3970 * set, but only if they have not been set before. Default for p_shcf is
3971 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3972 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3973 * command.com. And for Win32 we need to set p_sxq instead.
3974 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003975 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003976 {
3977 int idx3;
3978
3979 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003980 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 {
3982 p_shcf = (char_u *)"-c";
3983 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3984 }
3985
3986# ifndef DJGPP
3987# ifdef WIN3264
3988 /* Somehow Win32 requires the quotes around the redirection too */
3989 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003990 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 {
3992 p_sxq = (char_u *)"\"";
3993 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3994 }
3995# else
3996 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003997 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003998 {
3999 p_shq = (char_u *)"\"";
4000 options[idx3].def_val[VI_DEFAULT] = p_shq;
4001 }
4002# endif
4003# endif
4004 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004005 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4006 {
4007 int idx3;
4008
4009 /*
4010 * cmd.exe on Windows will strip the first and last double quote given
4011 * on the command line, e.g. most of the time things like:
4012 * cmd /c "my path/to/echo" "my args to echo"
4013 * become:
4014 * my path/to/echo" "my args to echo
4015 * when executed.
4016 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004017 * To avoid this, set shellxquote to surround the command in
4018 * parenthesis. This appears to make most commands work, without
4019 * breaking commands that worked previously, such as
4020 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004021 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004022 idx3 = findoption((char_u *)"sxq");
4023 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4024 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004025 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004026 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4027 }
4028
Bram Moolenaara64ba222012-02-12 23:23:31 +01004029 idx3 = findoption((char_u *)"shcf");
4030 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4031 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004032 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004033 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4034 }
4035 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004036#endif
4037
4038#ifdef FEAT_TITLE
4039 set_title_defaults();
4040#endif
4041}
4042
4043#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4044/*
4045 * When 'helplang' is still at its default value, set it to "lang".
4046 * Only the first two characters of "lang" are used.
4047 */
4048 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004049set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050{
4051 int idx;
4052
4053 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4054 return;
4055 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004056 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 {
4058 if (options[idx].flags & P_ALLOCED)
4059 free_string_option(p_hlg);
4060 p_hlg = vim_strsave(lang);
4061 if (p_hlg == NULL)
4062 p_hlg = empty_option;
4063 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004064 {
4065 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4066 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4067 {
4068 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4069 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4070 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004072 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004073 options[idx].flags |= P_ALLOCED;
4074 }
4075}
4076#endif
4077
4078#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004079static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080
4081 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004082gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083{
4084 if (gui_get_lightness(gui.back_pixel) < 127)
4085 return (char_u *)"dark";
4086 return (char_u *)"light";
4087}
4088
4089/*
4090 * Option initializations that can only be done after opening the GUI window.
4091 */
4092 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004093init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094{
4095 /* Set the 'background' option according to the lightness of the
4096 * background color, unless the user has set it already. */
4097 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4098 {
4099 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4100 highlight_changed();
4101 }
4102}
4103#endif
4104
4105#ifdef FEAT_TITLE
4106/*
4107 * 'title' and 'icon' only default to true if they have not been set or reset
4108 * in .vimrc and we can read the old value.
4109 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4110 * they can be reset. This reduces startup time when using X on a remote
4111 * machine.
4112 */
4113 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004114set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115{
4116 int idx1;
4117 long val;
4118
4119 /*
4120 * If GUI is (going to be) used, we can always set the window title and
4121 * icon name. Saves a bit of time, because the X11 display server does
4122 * not need to be contacted.
4123 */
4124 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004125 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 {
4127#ifdef FEAT_GUI
4128 if (gui.starting || gui.in_use)
4129 val = TRUE;
4130 else
4131#endif
4132 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004133 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 p_title = val;
4135 }
4136 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004137 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 {
4139#ifdef FEAT_GUI
4140 if (gui.starting || gui.in_use)
4141 val = TRUE;
4142 else
4143#endif
4144 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004145 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 p_icon = val;
4147 }
4148}
4149#endif
4150
4151/*
4152 * Parse 'arg' for option settings.
4153 *
4154 * 'arg' may be IObuff, but only when no errors can be present and option
4155 * does not need to be expanded with option_expand().
4156 * "opt_flags":
4157 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004158 * OPT_GLOBAL for ":setglobal"
4159 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004161 * OPT_WINONLY to only set window-local options
4162 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 *
4164 * returns FAIL if an error is detected, OK otherwise
4165 */
4166 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004167do_set(
4168 char_u *arg, /* option string (may be written to!) */
4169 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004170{
4171 int opt_idx;
4172 char_u *errmsg;
4173 char_u errbuf[80];
4174 char_u *startarg;
4175 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4176 int nextchar; /* next non-white char after option name */
4177 int afterchar; /* character just after option name */
4178 int len;
4179 int i;
4180 long value;
4181 int key;
4182 long_u flags; /* flags for current option */
4183 char_u *varp = NULL; /* pointer to variable for current option */
4184 int did_show = FALSE; /* already showed one value */
4185 int adding; /* "opt+=arg" */
4186 int prepending; /* "opt^=arg" */
4187 int removing; /* "opt-=arg" */
4188 int cp_val = 0;
4189 char_u key_name[2];
4190
4191 if (*arg == NUL)
4192 {
4193 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004194 did_show = TRUE;
4195 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004196 }
4197
4198 while (*arg != NUL) /* loop to process all options */
4199 {
4200 errmsg = NULL;
4201 startarg = arg; /* remember for error message */
4202
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004203 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4204 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004205 {
4206 /*
4207 * ":set all" show all options.
4208 * ":set all&" set all options to their default value.
4209 */
4210 arg += 3;
4211 if (*arg == '&')
4212 {
4213 ++arg;
4214 /* Only for :set command set global value of local options. */
4215 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004216 didset_options();
4217 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004218 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219 }
4220 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004221 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004223 did_show = TRUE;
4224 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004225 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004226 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 {
4228 showoptions(2, opt_flags);
4229 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004230 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004231 arg += 7;
4232 }
4233 else
4234 {
4235 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004236 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004237 {
4238 prefix = 0;
4239 arg += 2;
4240 }
4241 else if (STRNCMP(arg, "inv", 3) == 0)
4242 {
4243 prefix = 2;
4244 arg += 3;
4245 }
4246
4247 /* find end of name */
4248 key = 0;
4249 if (*arg == '<')
4250 {
4251 nextchar = 0;
4252 opt_idx = -1;
4253 /* look out for <t_>;> */
4254 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4255 len = 5;
4256 else
4257 {
4258 len = 1;
4259 while (arg[len] != NUL && arg[len] != '>')
4260 ++len;
4261 }
4262 if (arg[len] != '>')
4263 {
4264 errmsg = e_invarg;
4265 goto skip;
4266 }
4267 arg[len] = NUL; /* put NUL after name */
4268 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4269 opt_idx = findoption(arg + 1);
4270 arg[len++] = '>'; /* restore '>' */
4271 if (opt_idx == -1)
4272 key = find_key_option(arg + 1);
4273 }
4274 else
4275 {
4276 len = 0;
4277 /*
4278 * The two characters after "t_" may not be alphanumeric.
4279 */
4280 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4281 len = 4;
4282 else
4283 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4284 ++len;
4285 nextchar = arg[len];
4286 arg[len] = NUL; /* put NUL after name */
4287 opt_idx = findoption(arg);
4288 arg[len] = nextchar; /* restore nextchar */
4289 if (opt_idx == -1)
4290 key = find_key_option(arg);
4291 }
4292
4293 /* remember character after option name */
4294 afterchar = arg[len];
4295
4296 /* skip white space, allow ":set ai ?" */
4297 while (vim_iswhite(arg[len]))
4298 ++len;
4299
4300 adding = FALSE;
4301 prepending = FALSE;
4302 removing = FALSE;
4303 if (arg[len] != NUL && arg[len + 1] == '=')
4304 {
4305 if (arg[len] == '+')
4306 {
4307 adding = TRUE; /* "+=" */
4308 ++len;
4309 }
4310 else if (arg[len] == '^')
4311 {
4312 prepending = TRUE; /* "^=" */
4313 ++len;
4314 }
4315 else if (arg[len] == '-')
4316 {
4317 removing = TRUE; /* "-=" */
4318 ++len;
4319 }
4320 }
4321 nextchar = arg[len];
4322
4323 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4324 {
4325 errmsg = (char_u *)N_("E518: Unknown option");
4326 goto skip;
4327 }
4328
4329 if (opt_idx >= 0)
4330 {
4331 if (options[opt_idx].var == NULL) /* hidden option: skip */
4332 {
4333 /* Only give an error message when requesting the value of
4334 * a hidden option, ignore setting it. */
4335 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4336 && (!(options[opt_idx].flags & P_BOOL)
4337 || nextchar == '?'))
4338 errmsg = (char_u *)N_("E519: Option not supported");
4339 goto skip;
4340 }
4341
4342 flags = options[opt_idx].flags;
4343 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4344 }
4345 else
4346 {
4347 flags = P_STRING;
4348 if (key < 0)
4349 {
4350 key_name[0] = KEY2TERMCAP0(key);
4351 key_name[1] = KEY2TERMCAP1(key);
4352 }
4353 else
4354 {
4355 key_name[0] = KS_KEY;
4356 key_name[1] = (key & 0xff);
4357 }
4358 }
4359
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004360 /* Skip all options that are not window-local (used when showing
4361 * an already loaded buffer in a window). */
4362 if ((opt_flags & OPT_WINONLY)
4363 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4364 goto skip;
4365
Bram Moolenaara3227e22006-03-08 21:32:40 +00004366 /* Skip all options that are window-local (used for :vimgrep). */
4367 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4368 && options[opt_idx].var == VAR_WIN)
4369 goto skip;
4370
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004371 /* Disallow changing some options from modelines. */
4372 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004373 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004374 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004375 {
4376 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4377 goto skip;
4378 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004379#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004380 /* In diff mode some options are overruled. This avoids that
4381 * 'foldmethod' becomes "marker" instead of "diff" and that
4382 * "wrap" gets set. */
4383 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004384 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004385 && (options[opt_idx].indir == PV_FDM
4386 || options[opt_idx].indir == PV_WRAP))
4387 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004388#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004389 }
4390
4391#ifdef HAVE_SANDBOX
4392 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004393 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004394 {
4395 errmsg = (char_u *)_(e_sandbox);
4396 goto skip;
4397 }
4398#endif
4399
4400 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4401 {
4402 arg += len;
4403 cp_val = p_cp;
4404 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4405 {
4406 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4407 {
4408 cp_val = FALSE;
4409 arg += 3;
4410 }
4411 else /* "opt&vi": set to Vi default */
4412 {
4413 cp_val = TRUE;
4414 arg += 2;
4415 }
4416 }
4417 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4418 && arg[1] != NUL && !vim_iswhite(arg[1]))
4419 {
4420 errmsg = e_trailing;
4421 goto skip;
4422 }
4423 }
4424
4425 /*
4426 * allow '=' and ':' as MSDOS command.com allows only one
4427 * '=' character per "set" command line. grrr. (jw)
4428 */
4429 if (nextchar == '?'
4430 || (prefix == 1
4431 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4432 && !(flags & P_BOOL)))
4433 {
4434 /*
4435 * print value
4436 */
4437 if (did_show)
4438 msg_putchar('\n'); /* cursor below last one */
4439 else
4440 {
4441 gotocmdline(TRUE); /* cursor at status line */
4442 did_show = TRUE; /* remember that we did a line */
4443 }
4444 if (opt_idx >= 0)
4445 {
4446 showoneopt(&options[opt_idx], opt_flags);
4447#ifdef FEAT_EVAL
4448 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004449 {
4450 /* Mention where the option was last set. */
4451 if (varp == options[opt_idx].var)
4452 last_set_msg(options[opt_idx].scriptID);
4453 else if ((int)options[opt_idx].indir & PV_WIN)
4454 last_set_msg(curwin->w_p_scriptID[
4455 (int)options[opt_idx].indir & PV_MASK]);
4456 else if ((int)options[opt_idx].indir & PV_BUF)
4457 last_set_msg(curbuf->b_p_scriptID[
4458 (int)options[opt_idx].indir & PV_MASK]);
4459 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004460#endif
4461 }
4462 else
4463 {
4464 char_u *p;
4465
4466 p = find_termcode(key_name);
4467 if (p == NULL)
4468 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004469 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004470 goto skip;
4471 }
4472 else
4473 (void)show_one_termcode(key_name, p, TRUE);
4474 }
4475 if (nextchar != '?'
4476 && nextchar != NUL && !vim_iswhite(afterchar))
4477 errmsg = e_trailing;
4478 }
4479 else
4480 {
4481 if (flags & P_BOOL) /* boolean */
4482 {
4483 if (nextchar == '=' || nextchar == ':')
4484 {
4485 errmsg = e_invarg;
4486 goto skip;
4487 }
4488
4489 /*
4490 * ":set opt!": invert
4491 * ":set opt&": reset to default value
4492 * ":set opt<": reset to global value
4493 */
4494 if (nextchar == '!')
4495 value = *(int *)(varp) ^ 1;
4496 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004497 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004498 ((flags & P_VI_DEF) || cp_val)
4499 ? VI_DEFAULT : VIM_DEFAULT];
4500 else if (nextchar == '<')
4501 {
4502 /* For 'autoread' -1 means to use global value. */
4503 if ((int *)varp == &curbuf->b_p_ar
4504 && opt_flags == OPT_LOCAL)
4505 value = -1;
4506 else
4507 value = *(int *)get_varp_scope(&(options[opt_idx]),
4508 OPT_GLOBAL);
4509 }
4510 else
4511 {
4512 /*
4513 * ":set invopt": invert
4514 * ":set opt" or ":set noopt": set or reset
4515 */
4516 if (nextchar != NUL && !vim_iswhite(afterchar))
4517 {
4518 errmsg = e_trailing;
4519 goto skip;
4520 }
4521 if (prefix == 2) /* inv */
4522 value = *(int *)(varp) ^ 1;
4523 else
4524 value = prefix;
4525 }
4526
4527 errmsg = set_bool_option(opt_idx, varp, (int)value,
4528 opt_flags);
4529 }
4530 else /* numeric or string */
4531 {
4532 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4533 || prefix != 1)
4534 {
4535 errmsg = e_invarg;
4536 goto skip;
4537 }
4538
4539 if (flags & P_NUM) /* numeric */
4540 {
4541 /*
4542 * Different ways to set a number option:
4543 * & set to default value
4544 * < set to global value
4545 * <xx> accept special key codes for 'wildchar'
4546 * c accept any non-digit for 'wildchar'
4547 * [-]0-9 set number
4548 * other error
4549 */
4550 ++arg;
4551 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004552 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004553 ((flags & P_VI_DEF) || cp_val)
4554 ? VI_DEFAULT : VIM_DEFAULT];
4555 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004556 {
4557 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4558 * use the global value. */
4559 if ((long *)varp == &curbuf->b_p_ul
4560 && opt_flags == OPT_LOCAL)
4561 value = NO_LOCAL_UNDOLEVEL;
4562 else
4563 value = *(long *)get_varp_scope(
4564 &(options[opt_idx]), OPT_GLOBAL);
4565 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004566 else if (((long *)varp == &p_wc
4567 || (long *)varp == &p_wcm)
4568 && (*arg == '<'
4569 || *arg == '^'
4570 || ((!arg[1] || vim_iswhite(arg[1]))
4571 && !VIM_ISDIGIT(*arg))))
4572 {
4573 value = string_to_key(arg);
4574 if (value == 0 && (long *)varp != &p_wcm)
4575 {
4576 errmsg = e_invarg;
4577 goto skip;
4578 }
4579 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004580 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4581 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004582 /* Allow negative (for 'undolevels'), octal and
4583 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004584 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4585 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004586 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4587 {
4588 errmsg = e_invarg;
4589 goto skip;
4590 }
4591 }
4592 else
4593 {
4594 errmsg = (char_u *)N_("E521: Number required after =");
4595 goto skip;
4596 }
4597
4598 if (adding)
4599 value = *(long *)varp + value;
4600 if (prepending)
4601 value = *(long *)varp * value;
4602 if (removing)
4603 value = *(long *)varp - value;
4604 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004605 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004606 }
4607 else if (opt_idx >= 0) /* string */
4608 {
4609 char_u *save_arg = NULL;
4610 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004611 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004612 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004613 char_u *origval = NULL;
4614#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4615 char_u *saved_origval = NULL;
4616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004617 unsigned newlen;
4618 int comma;
4619 int bs;
4620 int new_value_alloced; /* new string option
4621 was allocated */
4622
4623 /* When using ":set opt=val" for a global option
4624 * with a local value the local value will be
4625 * reset, use the global value here. */
4626 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004627 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004628 varp = options[opt_idx].var;
4629
4630 /* The old value is kept until we are sure that the
4631 * new value is valid. */
4632 oldval = *(char_u **)varp;
4633 if (nextchar == '&') /* set to default val */
4634 {
4635 newval = options[opt_idx].def_val[
4636 ((flags & P_VI_DEF) || cp_val)
4637 ? VI_DEFAULT : VIM_DEFAULT];
4638 if ((char_u **)varp == &p_bg)
4639 {
4640 /* guess the value of 'background' */
4641#ifdef FEAT_GUI
4642 if (gui.in_use)
4643 newval = gui_bg_default();
4644 else
4645#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004646 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004647 }
4648
4649 /* expand environment variables and ~ (since the
4650 * default value was already expanded, only
4651 * required when an environment variable was set
4652 * later */
4653 if (newval == NULL)
4654 newval = empty_option;
4655 else
4656 {
4657 s = option_expand(opt_idx, newval);
4658 if (s == NULL)
4659 s = newval;
4660 newval = vim_strsave(s);
4661 }
4662 new_value_alloced = TRUE;
4663 }
4664 else if (nextchar == '<') /* set to global val */
4665 {
4666 newval = vim_strsave(*(char_u **)get_varp_scope(
4667 &(options[opt_idx]), OPT_GLOBAL));
4668 new_value_alloced = TRUE;
4669 }
4670 else
4671 {
4672 ++arg; /* jump to after the '=' or ':' */
4673
4674 /*
4675 * Set 'keywordprg' to ":help" if an empty
4676 * value was passed to :set by the user.
4677 * Misuse errbuf[] for the resulting string.
4678 */
4679 if (varp == (char_u *)&p_kp
4680 && (*arg == NUL || *arg == ' '))
4681 {
4682 STRCPY(errbuf, ":help");
4683 save_arg = arg;
4684 arg = errbuf;
4685 }
4686 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004687 * Convert 'backspace' number to string, for
4688 * adding, prepending and removing string.
4689 */
4690 else if (varp == (char_u *)&p_bs
4691 && VIM_ISDIGIT(**(char_u **)varp))
4692 {
4693 i = getdigits((char_u **)varp);
4694 switch (i)
4695 {
4696 case 0:
4697 *(char_u **)varp = empty_option;
4698 break;
4699 case 1:
4700 *(char_u **)varp = vim_strsave(
4701 (char_u *)"indent,eol");
4702 break;
4703 case 2:
4704 *(char_u **)varp = vim_strsave(
4705 (char_u *)"indent,eol,start");
4706 break;
4707 }
4708 vim_free(oldval);
4709 oldval = *(char_u **)varp;
4710 }
4711 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004712 * Convert 'whichwrap' number to string, for
4713 * backwards compatibility with Vim 3.0.
4714 * Misuse errbuf[] for the resulting string.
4715 */
4716 else if (varp == (char_u *)&p_ww
4717 && VIM_ISDIGIT(*arg))
4718 {
4719 *errbuf = NUL;
4720 i = getdigits(&arg);
4721 if (i & 1)
4722 STRCAT(errbuf, "b,");
4723 if (i & 2)
4724 STRCAT(errbuf, "s,");
4725 if (i & 4)
4726 STRCAT(errbuf, "h,l,");
4727 if (i & 8)
4728 STRCAT(errbuf, "<,>,");
4729 if (i & 16)
4730 STRCAT(errbuf, "[,],");
4731 if (*errbuf != NUL) /* remove trailing , */
4732 errbuf[STRLEN(errbuf) - 1] = NUL;
4733 save_arg = arg;
4734 arg = errbuf;
4735 }
4736 /*
4737 * Remove '>' before 'dir' and 'bdir', for
4738 * backwards compatibility with version 3.0
4739 */
4740 else if ( *arg == '>'
4741 && (varp == (char_u *)&p_dir
4742 || varp == (char_u *)&p_bdir))
4743 {
4744 ++arg;
4745 }
4746
4747 /* When setting the local value of a global
4748 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004749 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004750 && (opt_flags & OPT_LOCAL))
4751 origval = *(char_u **)get_varp(
4752 &options[opt_idx]);
4753 else
4754 origval = oldval;
4755
4756 /*
4757 * Copy the new string into allocated memory.
4758 * Can't use set_string_option_direct(), because
4759 * we need to remove the backslashes.
4760 */
4761 /* get a bit too much */
4762 newlen = (unsigned)STRLEN(arg) + 1;
4763 if (adding || prepending || removing)
4764 newlen += (unsigned)STRLEN(origval) + 1;
4765 newval = alloc(newlen);
4766 if (newval == NULL) /* out of mem, don't change */
4767 break;
4768 s = newval;
4769
4770 /*
4771 * Copy the string, skip over escaped chars.
4772 * For MS-DOS and WIN32 backslashes before normal
4773 * file name characters are not removed, and keep
4774 * backslash at start, for "\\machine\path", but
4775 * do remove it for "\\\\machine\\path".
4776 * The reverse is found in ExpandOldSetting().
4777 */
4778 while (*arg && !vim_iswhite(*arg))
4779 {
4780 if (*arg == '\\' && arg[1] != NUL
4781#ifdef BACKSLASH_IN_FILENAME
4782 && !((flags & P_EXPAND)
4783 && vim_isfilec(arg[1])
4784 && (arg[1] != '\\'
4785 || (s == newval
4786 && arg[2] != '\\')))
4787#endif
4788 )
4789 ++arg; /* remove backslash */
4790#ifdef FEAT_MBYTE
4791 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004792 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004793 {
4794 /* copy multibyte char */
4795 mch_memmove(s, arg, (size_t)i);
4796 arg += i;
4797 s += i;
4798 }
4799 else
4800#endif
4801 *s++ = *arg++;
4802 }
4803 *s = NUL;
4804
4805 /*
4806 * Expand environment variables and ~.
4807 * Don't do it when adding without inserting a
4808 * comma.
4809 */
4810 if (!(adding || prepending || removing)
4811 || (flags & P_COMMA))
4812 {
4813 s = option_expand(opt_idx, newval);
4814 if (s != NULL)
4815 {
4816 vim_free(newval);
4817 newlen = (unsigned)STRLEN(s) + 1;
4818 if (adding || prepending || removing)
4819 newlen += (unsigned)STRLEN(origval) + 1;
4820 newval = alloc(newlen);
4821 if (newval == NULL)
4822 break;
4823 STRCPY(newval, s);
4824 }
4825 }
4826
4827 /* locate newval[] in origval[] when removing it
4828 * and when adding to avoid duplicates */
4829 i = 0; /* init for GCC */
4830 if (removing || (flags & P_NODUP))
4831 {
4832 i = (int)STRLEN(newval);
4833 bs = 0;
4834 for (s = origval; *s; ++s)
4835 {
4836 if ((!(flags & P_COMMA)
4837 || s == origval
4838 || (s[-1] == ',' && !(bs & 1)))
4839 && STRNCMP(s, newval, i) == 0
4840 && (!(flags & P_COMMA)
4841 || s[i] == ','
4842 || s[i] == NUL))
4843 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004844 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004845 * even number of backslashes or a single
4846 * backslash preceded by a comma before it
4847 * is recognized as a separator */
4848 if ((s > origval + 1
4849 && s[-1] == '\\'
4850 && s[-2] != ',')
4851 || (s == origval + 1
4852 && s[-1] == '\\'))
4853
Bram Moolenaar071d4272004-06-13 20:20:40 +00004854 ++bs;
4855 else
4856 bs = 0;
4857 }
4858
4859 /* do not add if already there */
4860 if ((adding || prepending) && *s)
4861 {
4862 prepending = FALSE;
4863 adding = FALSE;
4864 STRCPY(newval, origval);
4865 }
4866 }
4867
4868 /* concatenate the two strings; add a ',' if
4869 * needed */
4870 if (adding || prepending)
4871 {
4872 comma = ((flags & P_COMMA) && *origval != NUL
4873 && *newval != NUL);
4874 if (adding)
4875 {
4876 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004877 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004878 if (comma && i > 1
4879 && (flags & P_ONECOMMA) == P_ONECOMMA
4880 && origval[i - 1] == ','
4881 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004882 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004883 mch_memmove(newval + i + comma, newval,
4884 STRLEN(newval) + 1);
4885 mch_memmove(newval, origval, (size_t)i);
4886 }
4887 else
4888 {
4889 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004890 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004891 }
4892 if (comma)
4893 newval[i] = ',';
4894 }
4895
4896 /* Remove newval[] from origval[]. (Note: "i" has
4897 * been set above and is used here). */
4898 if (removing)
4899 {
4900 STRCPY(newval, origval);
4901 if (*s)
4902 {
4903 /* may need to remove a comma */
4904 if (flags & P_COMMA)
4905 {
4906 if (s == origval)
4907 {
4908 /* include comma after string */
4909 if (s[i] == ',')
4910 ++i;
4911 }
4912 else
4913 {
4914 /* include comma before string */
4915 --s;
4916 ++i;
4917 }
4918 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004919 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004920 }
4921 }
4922
4923 if (flags & P_FLAGLIST)
4924 {
4925 /* Remove flags that appear twice. */
4926 for (s = newval; *s; ++s)
4927 if ((!(flags & P_COMMA) || *s != ',')
4928 && vim_strchr(s + 1, *s) != NULL)
4929 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004930 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004931 --s;
4932 }
4933 }
4934
4935 if (save_arg != NULL) /* number for 'whichwrap' */
4936 arg = save_arg;
4937 new_value_alloced = TRUE;
4938 }
4939
4940 /* Set the new value. */
4941 *(char_u **)(varp) = newval;
4942
Bram Moolenaar53744302015-07-17 17:38:22 +02004943#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004944 if (!starting
4945# ifdef FEAT_CRYPT
4946 && options[opt_idx].indir != PV_KEY
4947# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004948 && origval != NULL)
4949 /* origval may be freed by
4950 * did_set_string_option(), make a copy. */
4951 saved_origval = vim_strsave(origval);
4952#endif
4953
Bram Moolenaar071d4272004-06-13 20:20:40 +00004954 /* Handle side effects, and set the global value for
4955 * ":set" on local options. */
4956 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4957 new_value_alloced, oldval, errbuf, opt_flags);
4958
4959 /* If error detected, print the error message. */
4960 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004961 {
4962#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4963 vim_free(saved_origval);
4964#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004965 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004966 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004967#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4968 if (saved_origval != NULL)
4969 {
4970 char_u buf_type[7];
4971
4972 sprintf((char *)buf_type, "%s",
4973 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004974 set_vim_var_string(VV_OPTION_NEW,
4975 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004976 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4977 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4978 apply_autocmds(EVENT_OPTIONSET,
4979 (char_u *)options[opt_idx].fullname,
4980 NULL, FALSE, NULL);
4981 reset_v_option_vars();
4982 vim_free(saved_origval);
4983 }
4984#endif
4985
Bram Moolenaar071d4272004-06-13 20:20:40 +00004986 }
4987 else /* key code option */
4988 {
4989 char_u *p;
4990
4991 if (nextchar == '&')
4992 {
4993 if (add_termcap_entry(key_name, TRUE) == FAIL)
4994 errmsg = (char_u *)N_("E522: Not found in termcap");
4995 }
4996 else
4997 {
4998 ++arg; /* jump to after the '=' or ':' */
4999 for (p = arg; *p && !vim_iswhite(*p); ++p)
5000 if (*p == '\\' && p[1] != NUL)
5001 ++p;
5002 nextchar = *p;
5003 *p = NUL;
5004 add_termcode(key_name, arg, FALSE);
5005 *p = nextchar;
5006 }
5007 if (full_screen)
5008 ttest(FALSE);
5009 redraw_all_later(CLEAR);
5010 }
5011 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005012
Bram Moolenaar071d4272004-06-13 20:20:40 +00005013 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005014 did_set_option(opt_idx, opt_flags,
5015 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005016 }
5017
5018skip:
5019 /*
5020 * Advance to next argument.
5021 * - skip until a blank found, taking care of backslashes
5022 * - skip blanks
5023 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5024 */
5025 for (i = 0; i < 2 ; ++i)
5026 {
5027 while (*arg != NUL && !vim_iswhite(*arg))
5028 if (*arg++ == '\\' && *arg != NUL)
5029 ++arg;
5030 arg = skipwhite(arg);
5031 if (*arg != '=')
5032 break;
5033 }
5034 }
5035
5036 if (errmsg != NULL)
5037 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005038 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005039 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005040 if (i + (arg - startarg) < IOSIZE)
5041 {
5042 /* append the argument with the error */
5043 STRCAT(IObuff, ": ");
5044 mch_memmove(IObuff + i, startarg, (arg - startarg));
5045 IObuff[i + (arg - startarg)] = NUL;
5046 }
5047 /* make sure all characters are printable */
5048 trans_characters(IObuff, IOSIZE);
5049
5050 ++no_wait_return; /* wait_return done later */
5051 emsg(IObuff); /* show error highlighted */
5052 --no_wait_return;
5053
5054 return FAIL;
5055 }
5056
5057 arg = skipwhite(arg);
5058 }
5059
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005060theend:
5061 if (silent_mode && did_show)
5062 {
5063 /* After displaying option values in silent mode. */
5064 silent_mode = FALSE;
5065 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5066 msg_putchar('\n');
5067 cursor_on(); /* msg_start() switches it off */
5068 out_flush();
5069 silent_mode = TRUE;
5070 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5071 }
5072
Bram Moolenaar071d4272004-06-13 20:20:40 +00005073 return OK;
5074}
5075
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005076/*
5077 * Call this when an option has been given a new value through a user command.
5078 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5079 */
5080 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005081did_set_option(
5082 int opt_idx,
5083 int opt_flags, /* possibly with OPT_MODELINE */
5084 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005085{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005086 long_u *p;
5087
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005088 options[opt_idx].flags |= P_WAS_SET;
5089
5090 /* When an option is set in the sandbox, from a modeline or in secure mode
5091 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005092 * flag. */
5093 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005094 if (secure
5095#ifdef HAVE_SANDBOX
5096 || sandbox != 0
5097#endif
5098 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005099 *p = *p | P_INSECURE;
5100 else if (new_value)
5101 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005102}
5103
Bram Moolenaar071d4272004-06-13 20:20:40 +00005104 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005105illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005106{
5107 if (errbuf == NULL)
5108 return (char_u *)"";
5109 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005110 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 return errbuf;
5112}
5113
5114/*
5115 * Convert a key name or string into a key value.
5116 * Used for 'wildchar' and 'cedit' options.
5117 */
5118 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005119string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120{
5121 if (*arg == '<')
5122 return find_key_option(arg + 1);
5123 if (*arg == '^')
5124 return Ctrl_chr(arg[1]);
5125 return *arg;
5126}
5127
5128#ifdef FEAT_CMDWIN
5129/*
5130 * Check value of 'cedit' and set cedit_key.
5131 * Returns NULL if value is OK, error message otherwise.
5132 */
5133 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005134check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005135{
5136 int n;
5137
5138 if (*p_cedit == NUL)
5139 cedit_key = -1;
5140 else
5141 {
5142 n = string_to_key(p_cedit);
5143 if (vim_isprintc(n))
5144 return e_invarg;
5145 cedit_key = n;
5146 }
5147 return NULL;
5148}
5149#endif
5150
5151#ifdef FEAT_TITLE
5152/*
5153 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5154 * maketitle() to create and display it.
5155 * When switching the title or icon off, call mch_restore_title() to get
5156 * the old value back.
5157 */
5158 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005159did_set_title(
5160 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005161{
5162 if (starting != NO_SCREEN
5163#ifdef FEAT_GUI
5164 && !gui.starting
5165#endif
5166 )
5167 {
5168 maketitle();
5169 if (icon)
5170 {
5171 if (!p_icon)
5172 mch_restore_title(2);
5173 }
5174 else
5175 {
5176 if (!p_title)
5177 mch_restore_title(1);
5178 }
5179 }
5180}
5181#endif
5182
5183/*
5184 * set_options_bin - called when 'bin' changes value.
5185 */
5186 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005187set_options_bin(
5188 int oldval,
5189 int newval,
5190 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005191{
5192 /*
5193 * The option values that are changed when 'bin' changes are
5194 * copied when 'bin is set and restored when 'bin' is reset.
5195 */
5196 if (newval)
5197 {
5198 if (!oldval) /* switched on */
5199 {
5200 if (!(opt_flags & OPT_GLOBAL))
5201 {
5202 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5203 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5204 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5205 curbuf->b_p_et_nobin = curbuf->b_p_et;
5206 }
5207 if (!(opt_flags & OPT_LOCAL))
5208 {
5209 p_tw_nobin = p_tw;
5210 p_wm_nobin = p_wm;
5211 p_ml_nobin = p_ml;
5212 p_et_nobin = p_et;
5213 }
5214 }
5215
5216 if (!(opt_flags & OPT_GLOBAL))
5217 {
5218 curbuf->b_p_tw = 0; /* no automatic line wrap */
5219 curbuf->b_p_wm = 0; /* no automatic line wrap */
5220 curbuf->b_p_ml = 0; /* no modelines */
5221 curbuf->b_p_et = 0; /* no expandtab */
5222 }
5223 if (!(opt_flags & OPT_LOCAL))
5224 {
5225 p_tw = 0;
5226 p_wm = 0;
5227 p_ml = FALSE;
5228 p_et = FALSE;
5229 p_bin = TRUE; /* needed when called for the "-b" argument */
5230 }
5231 }
5232 else if (oldval) /* switched off */
5233 {
5234 if (!(opt_flags & OPT_GLOBAL))
5235 {
5236 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5237 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5238 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5239 curbuf->b_p_et = curbuf->b_p_et_nobin;
5240 }
5241 if (!(opt_flags & OPT_LOCAL))
5242 {
5243 p_tw = p_tw_nobin;
5244 p_wm = p_wm_nobin;
5245 p_ml = p_ml_nobin;
5246 p_et = p_et_nobin;
5247 }
5248 }
5249}
5250
5251#ifdef FEAT_VIMINFO
5252/*
5253 * Find the parameter represented by the given character (eg ', :, ", or /),
5254 * and return its associated value in the 'viminfo' string.
5255 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005256 * If the parameter is not specified in the string or there is no following
5257 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005258 */
5259 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005260get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005261{
5262 char_u *p;
5263
5264 p = find_viminfo_parameter(type);
5265 if (p != NULL && VIM_ISDIGIT(*p))
5266 return atoi((char *)p);
5267 return -1;
5268}
5269
5270/*
5271 * Find the parameter represented by the given character (eg ''', ':', '"', or
5272 * '/') in the 'viminfo' option and return a pointer to the string after it.
5273 * Return NULL if the parameter is not specified in the string.
5274 */
5275 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005276find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005277{
5278 char_u *p;
5279
5280 for (p = p_viminfo; *p; ++p)
5281 {
5282 if (*p == type)
5283 return p + 1;
5284 if (*p == 'n') /* 'n' is always the last one */
5285 break;
5286 p = vim_strchr(p, ','); /* skip until next ',' */
5287 if (p == NULL) /* hit the end without finding parameter */
5288 break;
5289 }
5290 return NULL;
5291}
5292#endif
5293
5294/*
5295 * Expand environment variables for some string options.
5296 * These string options cannot be indirect!
5297 * If "val" is NULL expand the current value of the option.
5298 * Return pointer to NameBuff, or NULL when not expanded.
5299 */
5300 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005301option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005302{
5303 /* if option doesn't need expansion nothing to do */
5304 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5305 return NULL;
5306
5307 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5308 * expand_env() would truncate the string. */
5309 if (val != NULL && STRLEN(val) > MAXPATHL)
5310 return NULL;
5311
5312 if (val == NULL)
5313 val = *(char_u **)options[opt_idx].var;
5314
5315 /*
5316 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5317 * Escape spaces when expanding 'tags', they are used to separate file
5318 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005319 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005320 */
5321 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005322 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005323#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005324 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5325#endif
5326 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5328 return NULL;
5329
5330 return NameBuff;
5331}
5332
5333/*
5334 * After setting various option values: recompute variables that depend on
5335 * option values.
5336 */
5337 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005338didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005339{
5340 /* initialize the table for 'iskeyword' et.al. */
5341 (void)init_chartab();
5342
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005343#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005344 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005345#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005347 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348#ifdef FEAT_SESSION
5349 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5350 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5351#endif
5352#ifdef FEAT_FOLDING
5353 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5354#endif
5355 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005356 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357#ifdef FEAT_VIRTUALEDIT
5358 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5359#endif
5360#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5361 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5362#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005363#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005364 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005365 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005366 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005367 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5370 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5371#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005372#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005373 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5374#endif
5375#ifdef FEAT_CMDWIN
5376 /* set cedit_key */
5377 (void)check_cedit();
5378#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005379#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005380 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005381#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005382#ifdef FEAT_LINEBREAK
5383 /* initialize the table for 'breakat'. */
5384 fill_breakat_flags();
5385#endif
5386
5387}
5388
5389/*
5390 * More side effects of setting options.
5391 */
5392 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005393didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005394{
5395 /* Initialize the highlight_attr[] table. */
5396 (void)highlight_changed();
5397
5398 /* Parse default for 'wildmode' */
5399 check_opt_wim();
5400
5401 (void)set_chars_option(&p_lcs);
5402#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5403 /* Parse default for 'fillchars'. */
5404 (void)set_chars_option(&p_fcs);
5405#endif
5406
5407#ifdef FEAT_CLIPBOARD
5408 /* Parse default for 'clipboard' */
5409 (void)check_clipboard_option();
5410#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005411}
5412
5413/*
5414 * Check for string options that are NULL (normally only termcap options).
5415 */
5416 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005417check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005418{
5419 int opt_idx;
5420
5421 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5422 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5423 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5424}
5425
5426/*
5427 * Check string options in a buffer for NULL value.
5428 */
5429 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005430check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005431{
5432#if defined(FEAT_QUICKFIX)
5433 check_string_option(&buf->b_p_bh);
5434 check_string_option(&buf->b_p_bt);
5435#endif
5436#ifdef FEAT_MBYTE
5437 check_string_option(&buf->b_p_fenc);
5438#endif
5439 check_string_option(&buf->b_p_ff);
5440#ifdef FEAT_FIND_ID
5441 check_string_option(&buf->b_p_def);
5442 check_string_option(&buf->b_p_inc);
5443# ifdef FEAT_EVAL
5444 check_string_option(&buf->b_p_inex);
5445# endif
5446#endif
5447#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5448 check_string_option(&buf->b_p_inde);
5449 check_string_option(&buf->b_p_indk);
5450#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005451#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5452 check_string_option(&buf->b_p_bexpr);
5453#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005454#if defined(FEAT_CRYPT)
5455 check_string_option(&buf->b_p_cm);
5456#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005457#if defined(FEAT_EVAL)
5458 check_string_option(&buf->b_p_fex);
5459#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005460#ifdef FEAT_CRYPT
5461 check_string_option(&buf->b_p_key);
5462#endif
5463 check_string_option(&buf->b_p_kp);
5464 check_string_option(&buf->b_p_mps);
5465 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005466 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005467 check_string_option(&buf->b_p_isk);
5468#ifdef FEAT_COMMENTS
5469 check_string_option(&buf->b_p_com);
5470#endif
5471#ifdef FEAT_FOLDING
5472 check_string_option(&buf->b_p_cms);
5473#endif
5474 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005475#ifdef FEAT_TEXTOBJ
5476 check_string_option(&buf->b_p_qe);
5477#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478#ifdef FEAT_SYN_HL
5479 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005480 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005481#endif
5482#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005483 check_string_option(&buf->b_s.b_p_spc);
5484 check_string_option(&buf->b_s.b_p_spf);
5485 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005486#endif
5487#ifdef FEAT_SEARCHPATH
5488 check_string_option(&buf->b_p_sua);
5489#endif
5490#ifdef FEAT_CINDENT
5491 check_string_option(&buf->b_p_cink);
5492 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005493 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005494#endif
5495#ifdef FEAT_AUTOCMD
5496 check_string_option(&buf->b_p_ft);
5497#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005498#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5499 check_string_option(&buf->b_p_cinw);
5500#endif
5501#ifdef FEAT_INS_EXPAND
5502 check_string_option(&buf->b_p_cpt);
5503#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005504#ifdef FEAT_COMPL_FUNC
5505 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005506 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005507#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508#ifdef FEAT_KEYMAP
5509 check_string_option(&buf->b_p_keymap);
5510#endif
5511#ifdef FEAT_QUICKFIX
5512 check_string_option(&buf->b_p_gp);
5513 check_string_option(&buf->b_p_mp);
5514 check_string_option(&buf->b_p_efm);
5515#endif
5516 check_string_option(&buf->b_p_ep);
5517 check_string_option(&buf->b_p_path);
5518 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005519 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520#ifdef FEAT_INS_EXPAND
5521 check_string_option(&buf->b_p_dict);
5522 check_string_option(&buf->b_p_tsr);
5523#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005524#ifdef FEAT_LISP
5525 check_string_option(&buf->b_p_lw);
5526#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005527 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528}
5529
5530/*
5531 * Free the string allocated for an option.
5532 * Checks for the string being empty_option. This may happen if we're out of
5533 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5534 * check_options().
5535 * Does NOT check for P_ALLOCED flag!
5536 */
5537 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005538free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539{
5540 if (p != empty_option)
5541 vim_free(p);
5542}
5543
5544 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005545clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005546{
5547 if (*pp != empty_option)
5548 vim_free(*pp);
5549 *pp = empty_option;
5550}
5551
5552 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005553check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005554{
5555 if (*pp == NULL)
5556 *pp = empty_option;
5557}
5558
5559/*
5560 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5561 */
5562 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005563set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564{
5565 int opt_idx;
5566
5567 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5568 if (options[opt_idx].var == (char_u *)p)
5569 {
5570 options[opt_idx].flags |= P_ALLOCED;
5571 return;
5572 }
5573 return; /* cannot happen: didn't find it! */
5574}
5575
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005576#if defined(FEAT_EVAL) || defined(PROTO)
5577/*
5578 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5579 * Return FALSE when it wasn't.
5580 * Return -1 for an unknown option.
5581 */
5582 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005583was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005584{
5585 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005586 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005587
5588 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005589 {
5590 flagp = insecure_flag(idx, opt_flags);
5591 return (*flagp & P_INSECURE) != 0;
5592 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005593 EMSG2(_(e_intern2), "was_set_insecurely()");
5594 return -1;
5595}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005596
5597/*
5598 * Get a pointer to the flags used for the P_INSECURE flag of option
5599 * "opt_idx". For some local options a local flags field is used.
5600 */
5601 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005602insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005603{
5604 if (opt_flags & OPT_LOCAL)
5605 switch ((int)options[opt_idx].indir)
5606 {
5607#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005608 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005609#endif
5610#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005611# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005612 case PV_FDE: return &curwin->w_p_fde_flags;
5613 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005614# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005615# ifdef FEAT_BEVAL
5616 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5617# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005618# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005619 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005620# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005621 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005622# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005623 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005624# endif
5625#endif
5626 }
5627
5628 /* Nothing special, return global flags field. */
5629 return &options[opt_idx].flags;
5630}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005631#endif
5632
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005633#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005634static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005635
5636/*
5637 * Redraw the window title and/or tab page text later.
5638 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005639static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005640{
5641 need_maketitle = TRUE;
5642# ifdef FEAT_WINDOWS
5643 redraw_tabline = TRUE;
5644# endif
5645}
5646#endif
5647
Bram Moolenaar071d4272004-06-13 20:20:40 +00005648/*
5649 * Set a string option to a new value (without checking the effect).
5650 * The string is copied into allocated memory.
5651 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005652 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005653 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005654 */
5655 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005656set_string_option_direct(
5657 char_u *name,
5658 int opt_idx,
5659 char_u *val,
5660 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5661 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005662{
5663 char_u *s;
5664 char_u **varp;
5665 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005666 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667
Bram Moolenaar89d40322006-08-29 15:30:07 +00005668 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005669 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005670 idx = findoption(name);
5671 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005672 {
5673 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005674 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005676 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677 }
5678
Bram Moolenaar89d40322006-08-29 15:30:07 +00005679 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680 return;
5681
5682 s = vim_strsave(val);
5683 if (s != NULL)
5684 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005685 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005686 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005687 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005688 free_string_option(*varp);
5689 *varp = s;
5690
5691 /* For buffer/window local option may also set the global value. */
5692 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005693 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694
Bram Moolenaar89d40322006-08-29 15:30:07 +00005695 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696
5697 /* When setting both values of a global option with a local value,
5698 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005699 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005700 {
5701 free_string_option(*varp);
5702 *varp = empty_option;
5703 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005704# ifdef FEAT_EVAL
5705 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005706 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005707 set_sid == 0 ? current_SID : set_sid);
5708# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005709 }
5710}
5711
5712/*
5713 * Set global value for string option when it's a local option.
5714 */
5715 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005716set_string_option_global(
5717 int opt_idx, /* option index */
5718 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719{
5720 char_u **p, *s;
5721
5722 /* the global value is always allocated */
5723 if (options[opt_idx].var == VAR_WIN)
5724 p = (char_u **)GLOBAL_WO(varp);
5725 else
5726 p = (char_u **)options[opt_idx].var;
5727 if (options[opt_idx].indir != PV_NONE
5728 && p != varp
5729 && (s = vim_strsave(*varp)) != NULL)
5730 {
5731 free_string_option(*p);
5732 *p = s;
5733 }
5734}
5735
5736/*
5737 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005738 *
5739 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005740 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005741 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005742set_string_option(
5743 int opt_idx,
5744 char_u *value,
5745 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746{
5747 char_u *s;
5748 char_u **varp;
5749 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005750#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5751 char_u *saved_oldval = NULL;
5752#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005753 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754
5755 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005756 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757
5758 s = vim_strsave(value);
5759 if (s != NULL)
5760 {
5761 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5762 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005763 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764 ? OPT_GLOBAL : OPT_LOCAL)
5765 : opt_flags);
5766 oldval = *varp;
5767 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005768
5769#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005770 if (!starting
5771# ifdef FEAT_CRYPT
5772 && options[opt_idx].indir != PV_KEY
5773# endif
5774 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005775 saved_oldval = vim_strsave(oldval);
5776#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005777 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5778 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005779 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005780
5781 /* call autocomamnd after handling side effects */
5782#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5783 if (saved_oldval != NULL)
5784 {
5785 char_u buf_type[7];
5786 sprintf((char *)buf_type, "%s",
5787 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005788 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5789 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005790 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5791 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5792 reset_v_option_vars();
5793 vim_free(saved_oldval);
5794 }
5795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005796 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005797 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005798}
5799
5800/*
5801 * Handle string options that need some action to perform when changed.
5802 * Returns NULL for success, or an error message for an error.
5803 */
5804 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005805did_set_string_option(
5806 int opt_idx, /* index in options[] table */
5807 char_u **varp, /* pointer to the option variable */
5808 int new_value_alloced, /* new value was allocated */
5809 char_u *oldval, /* previous value of the option */
5810 char_u *errbuf, /* buffer for errors, or NULL */
5811 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005812{
5813 char_u *errmsg = NULL;
5814 char_u *s, *p;
5815 int did_chartab = FALSE;
5816 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005817 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005818#ifdef FEAT_GUI
5819 /* set when changing an option that only requires a redraw in the GUI */
5820 int redraw_gui_only = FALSE;
5821#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005822
5823 /* Get the global option to compare with, otherwise we would have to check
5824 * two values for all local options. */
5825 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5826
5827 /* Disallow changing some options from secure mode */
5828 if ((secure
5829#ifdef HAVE_SANDBOX
5830 || sandbox != 0
5831#endif
5832 ) && (options[opt_idx].flags & P_SECURE))
5833 {
5834 errmsg = e_secure;
5835 }
5836
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005837 /* Check for a "normal" file name in some options. Disallow a path
5838 * separator (slash and/or backslash), wildcards and characters that are
5839 * often illegal in a file name. */
5840 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005841 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005842 {
5843 errmsg = e_invarg;
5844 }
5845
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846 /* 'term' */
5847 else if (varp == &T_NAME)
5848 {
5849 if (T_NAME[0] == NUL)
5850 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5851#ifdef FEAT_GUI
5852 if (gui.in_use)
5853 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5854 else if (term_is_gui(T_NAME))
5855 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5856#endif
5857 else if (set_termname(T_NAME) == FAIL)
5858 errmsg = (char_u *)N_("E522: Not found in termcap");
5859 else
5860 /* Screen colors may have changed. */
5861 redraw_later_clear();
5862 }
5863
5864 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005865 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005867 char_u *bkc = p_bkc;
5868 unsigned int *flags = &bkc_flags;
5869
5870 if (opt_flags & OPT_LOCAL)
5871 {
5872 bkc = curbuf->b_p_bkc;
5873 flags = &curbuf->b_bkc_flags;
5874 }
5875
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005876 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5877 /* make the local value empty: use the global value */
5878 *flags = 0;
5879 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005881 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5882 errmsg = e_invarg;
5883 if ((((int)*flags & BKC_AUTO) != 0)
5884 + (((int)*flags & BKC_YES) != 0)
5885 + (((int)*flags & BKC_NO) != 0) != 1)
5886 {
5887 /* Must have exactly one of "auto", "yes" and "no". */
5888 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5889 errmsg = e_invarg;
5890 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891 }
5892 }
5893
5894 /* 'backupext' and 'patchmode' */
5895 else if (varp == &p_bex || varp == &p_pm)
5896 {
5897 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5898 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5899 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5900 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005901#ifdef FEAT_LINEBREAK
5902 /* 'breakindentopt' */
5903 else if (varp == &curwin->w_p_briopt)
5904 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005905 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005906 errmsg = e_invarg;
5907 }
5908#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005909
5910 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005911 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005913 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005914 */
5915 else if ( varp == &p_isi
5916 || varp == &(curbuf->b_p_isk)
5917 || varp == &p_isp
5918 || varp == &p_isf)
5919 {
5920 if (init_chartab() == FAIL)
5921 {
5922 did_chartab = TRUE; /* need to restore it below */
5923 errmsg = e_invarg; /* error in value */
5924 }
5925 }
5926
5927 /* 'helpfile' */
5928 else if (varp == &p_hf)
5929 {
5930 /* May compute new values for $VIM and $VIMRUNTIME */
5931 if (didset_vim)
5932 {
5933 vim_setenv((char_u *)"VIM", (char_u *)"");
5934 didset_vim = FALSE;
5935 }
5936 if (didset_vimruntime)
5937 {
5938 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5939 didset_vimruntime = FALSE;
5940 }
5941 }
5942
Bram Moolenaar1a384422010-07-14 19:53:30 +02005943#ifdef FEAT_SYN_HL
5944 /* 'colorcolumn' */
5945 else if (varp == &curwin->w_p_cc)
5946 errmsg = check_colorcolumn(curwin);
5947#endif
5948
Bram Moolenaar071d4272004-06-13 20:20:40 +00005949#ifdef FEAT_MULTI_LANG
5950 /* 'helplang' */
5951 else if (varp == &p_hlg)
5952 {
5953 /* Check for "", "ab", "ab,cd", etc. */
5954 for (s = p_hlg; *s != NUL; s += 3)
5955 {
5956 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5957 {
5958 errmsg = e_invarg;
5959 break;
5960 }
5961 if (s[2] == NUL)
5962 break;
5963 }
5964 }
5965#endif
5966
5967 /* 'highlight' */
5968 else if (varp == &p_hl)
5969 {
5970 if (highlight_changed() == FAIL)
5971 errmsg = e_invarg; /* invalid flags */
5972 }
5973
5974 /* 'nrformats' */
5975 else if (gvarp == &p_nf)
5976 {
5977 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5978 errmsg = e_invarg;
5979 }
5980
5981#ifdef FEAT_SESSION
5982 /* 'sessionoptions' */
5983 else if (varp == &p_ssop)
5984 {
5985 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5986 errmsg = e_invarg;
5987 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5988 {
5989 /* Don't allow both "sesdir" and "curdir". */
5990 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5991 errmsg = e_invarg;
5992 }
5993 }
5994 /* 'viewoptions' */
5995 else if (varp == &p_vop)
5996 {
5997 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5998 errmsg = e_invarg;
5999 }
6000#endif
6001
6002 /* 'scrollopt' */
6003#ifdef FEAT_SCROLLBIND
6004 else if (varp == &p_sbo)
6005 {
6006 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6007 errmsg = e_invarg;
6008 }
6009#endif
6010
6011 /* 'ambiwidth' */
6012#ifdef FEAT_MBYTE
6013 else if (varp == &p_ambw)
6014 {
6015 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6016 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006017 else if (set_chars_option(&p_lcs) != NULL)
6018 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6019# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6020 else if (set_chars_option(&p_fcs) != NULL)
6021 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6022# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006023 }
6024#endif
6025
6026 /* 'background' */
6027 else if (varp == &p_bg)
6028 {
6029 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6030 {
6031#ifdef FEAT_EVAL
6032 int dark = (*p_bg == 'd');
6033#endif
6034
6035 init_highlight(FALSE, FALSE);
6036
6037#ifdef FEAT_EVAL
6038 if (dark != (*p_bg == 'd')
6039 && get_var_value((char_u *)"g:colors_name") != NULL)
6040 {
6041 /* The color scheme must have set 'background' back to another
6042 * value, that's not what we want here. Disable the color
6043 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006044 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006045 free_string_option(p_bg);
6046 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6047 check_string_option(&p_bg);
6048 init_highlight(FALSE, FALSE);
6049 }
6050#endif
6051 }
6052 else
6053 errmsg = e_invarg;
6054 }
6055
6056 /* 'wildmode' */
6057 else if (varp == &p_wim)
6058 {
6059 if (check_opt_wim() == FAIL)
6060 errmsg = e_invarg;
6061 }
6062
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006063#ifdef FEAT_CMDL_COMPL
6064 /* 'wildoptions' */
6065 else if (varp == &p_wop)
6066 {
6067 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6068 errmsg = e_invarg;
6069 }
6070#endif
6071
Bram Moolenaar071d4272004-06-13 20:20:40 +00006072#ifdef FEAT_WAK
6073 /* 'winaltkeys' */
6074 else if (varp == &p_wak)
6075 {
6076 if (*p_wak == NUL
6077 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6078 errmsg = e_invarg;
6079# ifdef FEAT_MENU
6080# ifdef FEAT_GUI_MOTIF
6081 else if (gui.in_use)
6082 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6083# else
6084# ifdef FEAT_GUI_GTK
6085 else if (gui.in_use)
6086 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6087# endif
6088# endif
6089# endif
6090 }
6091#endif
6092
6093#ifdef FEAT_AUTOCMD
6094 /* 'eventignore' */
6095 else if (varp == &p_ei)
6096 {
6097 if (check_ei() == FAIL)
6098 errmsg = e_invarg;
6099 }
6100#endif
6101
6102#ifdef FEAT_MBYTE
6103 /* 'encoding' and 'fileencoding' */
6104 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6105 {
6106 if (gvarp == &p_fenc)
6107 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006108 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006109 errmsg = e_modifiable;
6110 else if (vim_strchr(*varp, ',') != NULL)
6111 /* No comma allowed in 'fileencoding'; catches confusing it
6112 * with 'fileencodings'. */
6113 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006114 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006115 {
6116# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006118 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006120 /* Add 'fileencoding' to the swap file. */
6121 ml_setflags(curbuf);
6122 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006123 }
6124 if (errmsg == NULL)
6125 {
6126 /* canonize the value, so that STRCMP() can be used on it */
6127 p = enc_canonize(*varp);
6128 if (p != NULL)
6129 {
6130 vim_free(*varp);
6131 *varp = p;
6132 }
6133 if (varp == &p_enc)
6134 {
6135 errmsg = mb_init();
6136# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006137 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138# endif
6139 }
6140 }
6141
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006142# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006143 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6144 {
6145 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6146 if (STRCMP(p_tenc, "utf-8") != 0)
6147 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6148 }
6149# endif
6150
6151 if (errmsg == NULL)
6152 {
6153# ifdef FEAT_KEYMAP
6154 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6155 * (with another encoding). */
6156 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6157 (void)keymap_init();
6158# endif
6159
6160 /* When 'termencoding' is not empty and 'encoding' changes or when
6161 * 'termencoding' changes, need to setup for keyboard input and
6162 * display output conversion. */
6163 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6164 {
6165 convert_setup(&input_conv, p_tenc, p_enc);
6166 convert_setup(&output_conv, p_enc, p_tenc);
6167 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006168
6169# if defined(WIN3264) && defined(FEAT_MBYTE)
6170 /* $HOME may have characters in active code page. */
6171 if (varp == &p_enc)
6172 init_homedir();
6173# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006174 }
6175 }
6176#endif
6177
6178#if defined(FEAT_POSTSCRIPT)
6179 else if (varp == &p_penc)
6180 {
6181 /* Canonize printencoding if VIM standard one */
6182 p = enc_canonize(p_penc);
6183 if (p != NULL)
6184 {
6185 vim_free(p_penc);
6186 p_penc = p;
6187 }
6188 else
6189 {
6190 /* Ensure lower case and '-' for '_' */
6191 for (s = p_penc; *s != NUL; s++)
6192 {
6193 if (*s == '_')
6194 *s = '-';
6195 else
6196 *s = TOLOWER_ASC(*s);
6197 }
6198 }
6199 }
6200#endif
6201
Bram Moolenaar9372a112005-12-06 19:59:18 +00006202#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006203 else if (varp == &p_imak)
6204 {
6205 if (gui.in_use && !im_xim_isvalid_imactivate())
6206 errmsg = e_invarg;
6207 }
6208#endif
6209
6210#ifdef FEAT_KEYMAP
6211 else if (varp == &curbuf->b_p_keymap)
6212 {
6213 /* load or unload key mapping tables */
6214 errmsg = keymap_init();
6215
Bram Moolenaarfab06232009-03-04 03:13:35 +00006216 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006217 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006218 if (*curbuf->b_p_keymap != NUL)
6219 {
6220 /* Installed a new keymap, switch on using it. */
6221 curbuf->b_p_iminsert = B_IMODE_LMAP;
6222 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6223 curbuf->b_p_imsearch = B_IMODE_LMAP;
6224 }
6225 else
6226 {
6227 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6228 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6229 curbuf->b_p_iminsert = B_IMODE_NONE;
6230 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6231 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6232 }
6233 if ((opt_flags & OPT_LOCAL) == 0)
6234 {
6235 set_iminsert_global();
6236 set_imsearch_global();
6237 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006238# ifdef FEAT_WINDOWS
6239 status_redraw_curbuf();
6240# endif
6241 }
6242 }
6243#endif
6244
6245 /* 'fileformat' */
6246 else if (gvarp == &p_ff)
6247 {
6248 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6249 errmsg = e_modifiable;
6250 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6251 errmsg = e_invarg;
6252 else
6253 {
6254 /* may also change 'textmode' */
6255 if (get_fileformat(curbuf) == EOL_DOS)
6256 curbuf->b_p_tx = TRUE;
6257 else
6258 curbuf->b_p_tx = FALSE;
6259#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006260 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006261#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006262 /* update flag in swap file */
6263 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006264 /* Redraw needed when switching to/from "mac": a CR in the text
6265 * will be displayed differently. */
6266 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6267 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006268 }
6269 }
6270
6271 /* 'fileformats' */
6272 else if (varp == &p_ffs)
6273 {
6274 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6275 errmsg = e_invarg;
6276 else
6277 {
6278 /* also change 'textauto' */
6279 if (*p_ffs == NUL)
6280 p_ta = FALSE;
6281 else
6282 p_ta = TRUE;
6283 }
6284 }
6285
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006286#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006287 /* 'cryptkey' */
6288 else if (gvarp == &p_key)
6289 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006290# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006291 /* Make sure the ":set" command doesn't show the new value in the
6292 * history. */
6293 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006294# endif
6295 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6296 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006297 ml_set_crypt_key(curbuf, oldval,
6298 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006299 }
6300
6301 else if (gvarp == &p_cm)
6302 {
6303 if (opt_flags & OPT_LOCAL)
6304 p = curbuf->b_p_cm;
6305 else
6306 p = p_cm;
6307 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6308 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006309 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006310 errmsg = e_invarg;
6311 else
6312 {
6313 /* When setting the global value to empty, make it "zip". */
6314 if (*p_cm == NUL)
6315 {
6316 if (new_value_alloced)
6317 free_string_option(p_cm);
6318 p_cm = vim_strsave((char_u *)"zip");
6319 new_value_alloced = TRUE;
6320 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006321 /* When using ":set cm=name" the local value is going to be empty.
6322 * Do that here, otherwise the crypt functions will still use the
6323 * local value. */
6324 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6325 {
6326 free_string_option(curbuf->b_p_cm);
6327 curbuf->b_p_cm = empty_option;
6328 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006329
6330 /* Need to update the swapfile when the effective method changed.
6331 * Set "s" to the effective old value, "p" to the effective new
6332 * method and compare. */
6333 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6334 s = p_cm; /* was previously using the global value */
6335 else
6336 s = oldval;
6337 if (*curbuf->b_p_cm == NUL)
6338 p = p_cm; /* is now using the global value */
6339 else
6340 p = curbuf->b_p_cm;
6341 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006342 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006343
6344 /* If the global value changes need to update the swapfile for all
6345 * buffers using that value. */
6346 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6347 {
6348 buf_T *buf;
6349
6350 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6351 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006352 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006353 }
6354 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006355 }
6356#endif
6357
6358 /* 'matchpairs' */
6359 else if (gvarp == &p_mps)
6360 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006361#ifdef FEAT_MBYTE
6362 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006364 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006365 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006366 int x2 = -1;
6367 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006368
6369 if (*p != NUL)
6370 p += mb_ptr2len(p);
6371 if (*p != NUL)
6372 x2 = *p++;
6373 if (*p != NUL)
6374 {
6375 x3 = mb_ptr2char(p);
6376 p += mb_ptr2len(p);
6377 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006378 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006379 {
6380 errmsg = e_invarg;
6381 break;
6382 }
6383 if (*p == NUL)
6384 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006385 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006386 }
6387 else
6388#endif
6389 {
6390 /* Check for "x:y,x:y" */
6391 for (p = *varp; *p != NUL; p += 4)
6392 {
6393 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6394 {
6395 errmsg = e_invarg;
6396 break;
6397 }
6398 if (p[3] == NUL)
6399 break;
6400 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006401 }
6402 }
6403
6404#ifdef FEAT_COMMENTS
6405 /* 'comments' */
6406 else if (gvarp == &p_com)
6407 {
6408 for (s = *varp; *s; )
6409 {
6410 while (*s && *s != ':')
6411 {
6412 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6413 && !VIM_ISDIGIT(*s) && *s != '-')
6414 {
6415 errmsg = illegal_char(errbuf, *s);
6416 break;
6417 }
6418 ++s;
6419 }
6420 if (*s++ == NUL)
6421 errmsg = (char_u *)N_("E524: Missing colon");
6422 else if (*s == ',' || *s == NUL)
6423 errmsg = (char_u *)N_("E525: Zero length string");
6424 if (errmsg != NULL)
6425 break;
6426 while (*s && *s != ',')
6427 {
6428 if (*s == '\\' && s[1] != NUL)
6429 ++s;
6430 ++s;
6431 }
6432 s = skip_to_option_part(s);
6433 }
6434 }
6435#endif
6436
6437 /* 'listchars' */
6438 else if (varp == &p_lcs)
6439 {
6440 errmsg = set_chars_option(varp);
6441 }
6442
6443#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6444 /* 'fillchars' */
6445 else if (varp == &p_fcs)
6446 {
6447 errmsg = set_chars_option(varp);
6448 }
6449#endif
6450
6451#ifdef FEAT_CMDWIN
6452 /* 'cedit' */
6453 else if (varp == &p_cedit)
6454 {
6455 errmsg = check_cedit();
6456 }
6457#endif
6458
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006459 /* 'verbosefile' */
6460 else if (varp == &p_vfile)
6461 {
6462 verbose_stop();
6463 if (*p_vfile != NUL && verbose_open() == FAIL)
6464 errmsg = e_invarg;
6465 }
6466
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467#ifdef FEAT_VIMINFO
6468 /* 'viminfo' */
6469 else if (varp == &p_viminfo)
6470 {
6471 for (s = p_viminfo; *s;)
6472 {
6473 /* Check it's a valid character */
6474 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6475 {
6476 errmsg = illegal_char(errbuf, *s);
6477 break;
6478 }
6479 if (*s == 'n') /* name is always last one */
6480 {
6481 break;
6482 }
6483 else if (*s == 'r') /* skip until next ',' */
6484 {
6485 while (*++s && *s != ',')
6486 ;
6487 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006488 else if (*s == '%')
6489 {
6490 /* optional number */
6491 while (vim_isdigit(*++s))
6492 ;
6493 }
6494 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006495 ++s; /* no extra chars */
6496 else /* must have a number */
6497 {
6498 while (vim_isdigit(*++s))
6499 ;
6500
6501 if (!VIM_ISDIGIT(*(s - 1)))
6502 {
6503 if (errbuf != NULL)
6504 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006505 sprintf((char *)errbuf,
6506 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006507 transchar_byte(*(s - 1)));
6508 errmsg = errbuf;
6509 }
6510 else
6511 errmsg = (char_u *)"";
6512 break;
6513 }
6514 }
6515 if (*s == ',')
6516 ++s;
6517 else if (*s)
6518 {
6519 if (errbuf != NULL)
6520 errmsg = (char_u *)N_("E527: Missing comma");
6521 else
6522 errmsg = (char_u *)"";
6523 break;
6524 }
6525 }
6526 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6527 errmsg = (char_u *)N_("E528: Must specify a ' value");
6528 }
6529#endif /* FEAT_VIMINFO */
6530
6531 /* terminal options */
6532 else if (istermoption(&options[opt_idx]) && full_screen)
6533 {
6534 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6535 if (varp == &T_CCO)
6536 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006537 int colors = atoi((char *)T_CCO);
6538
6539 /* Only reinitialize colors if t_Co value has really changed to
6540 * avoid expensive reload of colorscheme if t_Co is set to the
6541 * same value multiple times. */
6542 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006543 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006544 t_colors = colors;
6545 if (t_colors <= 1)
6546 {
6547 if (new_value_alloced)
6548 vim_free(T_CCO);
6549 T_CCO = empty_option;
6550 }
6551 /* We now have a different color setup, initialize it again. */
6552 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006553 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006554 }
6555 ttest(FALSE);
6556 if (varp == &T_ME)
6557 {
6558 out_str(T_ME);
6559 redraw_later(CLEAR);
6560#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6561 /* Since t_me has been set, this probably means that the user
6562 * wants to use this as default colors. Need to reset default
6563 * background/foreground colors. */
6564 mch_set_normal_colors();
6565#endif
6566 }
6567 }
6568
6569#ifdef FEAT_LINEBREAK
6570 /* 'showbreak' */
6571 else if (varp == &p_sbr)
6572 {
6573 for (s = p_sbr; *s; )
6574 {
6575 if (ptr2cells(s) != 1)
6576 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006577 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 }
6579 }
6580#endif
6581
6582#ifdef FEAT_GUI
6583 /* 'guifont' */
6584 else if (varp == &p_guifont)
6585 {
6586 if (gui.in_use)
6587 {
6588 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006589# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590 /*
6591 * Put up a font dialog and let the user select a new value.
6592 * If this is cancelled go back to the old value but don't
6593 * give an error message.
6594 */
6595 if (STRCMP(p, "*") == 0)
6596 {
6597 p = gui_mch_font_dialog(oldval);
6598
6599 if (new_value_alloced)
6600 free_string_option(p_guifont);
6601
6602 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6603 new_value_alloced = TRUE;
6604 }
6605# endif
6606 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6607 {
6608# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6609 if (STRCMP(p_guifont, "*") == 0)
6610 {
6611 /* Dialog was cancelled: Keep the old value without giving
6612 * an error message. */
6613 if (new_value_alloced)
6614 free_string_option(p_guifont);
6615 p_guifont = vim_strsave(oldval);
6616 new_value_alloced = TRUE;
6617 }
6618 else
6619# endif
6620 errmsg = (char_u *)N_("E596: Invalid font(s)");
6621 }
6622 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006623 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 }
6625# ifdef FEAT_XFONTSET
6626 else if (varp == &p_guifontset)
6627 {
6628 if (STRCMP(p_guifontset, "*") == 0)
6629 errmsg = (char_u *)N_("E597: can't select fontset");
6630 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6631 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006632 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006633 }
6634# endif
6635# ifdef FEAT_MBYTE
6636 else if (varp == &p_guifontwide)
6637 {
6638 if (STRCMP(p_guifontwide, "*") == 0)
6639 errmsg = (char_u *)N_("E533: can't select wide font");
6640 else if (gui_get_wide_font() == FAIL)
6641 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006642 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006643 }
6644# endif
6645#endif
6646
6647#ifdef CURSOR_SHAPE
6648 /* 'guicursor' */
6649 else if (varp == &p_guicursor)
6650 errmsg = parse_shape_opt(SHAPE_CURSOR);
6651#endif
6652
6653#ifdef FEAT_MOUSESHAPE
6654 /* 'mouseshape' */
6655 else if (varp == &p_mouseshape)
6656 {
6657 errmsg = parse_shape_opt(SHAPE_MOUSE);
6658 update_mouseshape(-1);
6659 }
6660#endif
6661
6662#ifdef FEAT_PRINTER
6663 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006664 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006665# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006666 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006667 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006668# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006669#endif
6670
6671#ifdef FEAT_LANGMAP
6672 /* 'langmap' */
6673 else if (varp == &p_langmap)
6674 langmap_set();
6675#endif
6676
6677#ifdef FEAT_LINEBREAK
6678 /* 'breakat' */
6679 else if (varp == &p_breakat)
6680 fill_breakat_flags();
6681#endif
6682
6683#ifdef FEAT_TITLE
6684 /* 'titlestring' and 'iconstring' */
6685 else if (varp == &p_titlestring || varp == &p_iconstring)
6686 {
6687# ifdef FEAT_STL_OPT
6688 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6689
6690 /* NULL => statusline syntax */
6691 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6692 stl_syntax |= flagval;
6693 else
6694 stl_syntax &= ~flagval;
6695# endif
6696 did_set_title(varp == &p_iconstring);
6697
6698 }
6699#endif
6700
6701#ifdef FEAT_GUI
6702 /* 'guioptions' */
6703 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006704 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006705 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006706 redraw_gui_only = TRUE;
6707 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006708#endif
6709
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006710#if defined(FEAT_GUI_TABLINE)
6711 /* 'guitablabel' */
6712 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006713 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006714 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006715 redraw_gui_only = TRUE;
6716 }
6717 /* 'guitabtooltip' */
6718 else if (varp == &p_gtt)
6719 {
6720 redraw_gui_only = TRUE;
6721 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006722#endif
6723
Bram Moolenaar071d4272004-06-13 20:20:40 +00006724#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6725 /* 'ttymouse' */
6726 else if (varp == &p_ttym)
6727 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006728 /* Switch the mouse off before changing the escape sequences used for
6729 * that. */
6730 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006731 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6732 errmsg = e_invarg;
6733 else
6734 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006735 if (termcap_active)
6736 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006737 }
6738#endif
6739
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740 /* 'selection' */
6741 else if (varp == &p_sel)
6742 {
6743 if (*p_sel == NUL
6744 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6745 errmsg = e_invarg;
6746 }
6747
6748 /* 'selectmode' */
6749 else if (varp == &p_slm)
6750 {
6751 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6752 errmsg = e_invarg;
6753 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006754
6755#ifdef FEAT_BROWSE
6756 /* 'browsedir' */
6757 else if (varp == &p_bsdir)
6758 {
6759 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6760 && !mch_isdir(p_bsdir))
6761 errmsg = e_invarg;
6762 }
6763#endif
6764
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765 /* 'keymodel' */
6766 else if (varp == &p_km)
6767 {
6768 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6769 errmsg = e_invarg;
6770 else
6771 {
6772 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6773 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6774 }
6775 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006776
6777 /* 'mousemodel' */
6778 else if (varp == &p_mousem)
6779 {
6780 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6781 errmsg = e_invarg;
6782#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6783 else if (*p_mousem != *oldval)
6784 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6785 * to create or delete the popup menus. */
6786 gui_motif_update_mousemodel(root_menu);
6787#endif
6788 }
6789
6790 /* 'switchbuf' */
6791 else if (varp == &p_swb)
6792 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006793 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006794 errmsg = e_invarg;
6795 }
6796
6797 /* 'debug' */
6798 else if (varp == &p_debug)
6799 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006800 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006801 errmsg = e_invarg;
6802 }
6803
6804 /* 'display' */
6805 else if (varp == &p_dy)
6806 {
6807 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6808 errmsg = e_invarg;
6809 else
6810 (void)init_chartab();
6811
6812 }
6813
6814#ifdef FEAT_VERTSPLIT
6815 /* 'eadirection' */
6816 else if (varp == &p_ead)
6817 {
6818 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6819 errmsg = e_invarg;
6820 }
6821#endif
6822
6823#ifdef FEAT_CLIPBOARD
6824 /* 'clipboard' */
6825 else if (varp == &p_cb)
6826 errmsg = check_clipboard_option();
6827#endif
6828
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006829#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006830 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6831 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006832 else if (varp == &(curwin->w_s->b_p_spl)
6833 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006834 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006835 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006836 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006837 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006838 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006839 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006840 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006841 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006842 /* 'spellsuggest' */
6843 else if (varp == &p_sps)
6844 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006845 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006846 errmsg = e_invarg;
6847 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006848 /* 'mkspellmem' */
6849 else if (varp == &p_msm)
6850 {
6851 if (spell_check_msm() != OK)
6852 errmsg = e_invarg;
6853 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006854#endif
6855
Bram Moolenaar071d4272004-06-13 20:20:40 +00006856#ifdef FEAT_QUICKFIX
6857 /* When 'bufhidden' is set, check for valid value. */
6858 else if (gvarp == &p_bh)
6859 {
6860 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6861 errmsg = e_invarg;
6862 }
6863
6864 /* When 'buftype' is set, check for valid value. */
6865 else if (gvarp == &p_bt)
6866 {
6867 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6868 errmsg = e_invarg;
6869 else
6870 {
6871# ifdef FEAT_WINDOWS
6872 if (curwin->w_status_height)
6873 {
6874 curwin->w_redr_status = TRUE;
6875 redraw_later(VALID);
6876 }
6877# endif
6878 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006879# ifdef FEAT_TITLE
6880 redraw_titles();
6881# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006882 }
6883 }
6884#endif
6885
6886#ifdef FEAT_STL_OPT
6887 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006888 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006889 {
6890 int wid;
6891
6892 if (varp == &p_ruf) /* reset ru_wid first */
6893 ru_wid = 0;
6894 s = *varp;
6895 if (varp == &p_ruf && *s == '%')
6896 {
6897 /* set ru_wid if 'ruf' starts with "%99(" */
6898 if (*++s == '-') /* ignore a '-' */
6899 s++;
6900 wid = getdigits(&s);
6901 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6902 ru_wid = wid;
6903 else
6904 errmsg = check_stl_option(p_ruf);
6905 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006906 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006907 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006908 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006909 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 comp_col();
6911 }
6912#endif
6913
6914#ifdef FEAT_INS_EXPAND
6915 /* check if it is a valid value for 'complete' -- Acevedo */
6916 else if (gvarp == &p_cpt)
6917 {
6918 for (s = *varp; *s;)
6919 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006920 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006921 s++;
6922 if (!*s)
6923 break;
6924 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6925 {
6926 errmsg = illegal_char(errbuf, *s);
6927 break;
6928 }
6929 if (*++s != NUL && *s != ',' && *s != ' ')
6930 {
6931 if (s[-1] == 'k' || s[-1] == 's')
6932 {
6933 /* skip optional filename after 'k' and 's' */
6934 while (*s && *s != ',' && *s != ' ')
6935 {
6936 if (*s == '\\')
6937 ++s;
6938 ++s;
6939 }
6940 }
6941 else
6942 {
6943 if (errbuf != NULL)
6944 {
6945 sprintf((char *)errbuf,
6946 _("E535: Illegal character after <%c>"),
6947 *--s);
6948 errmsg = errbuf;
6949 }
6950 else
6951 errmsg = (char_u *)"";
6952 break;
6953 }
6954 }
6955 }
6956 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006957
6958 /* 'completeopt' */
6959 else if (varp == &p_cot)
6960 {
6961 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6962 errmsg = e_invarg;
6963 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006964#endif /* FEAT_INS_EXPAND */
6965
6966
6967#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6968 else if (varp == &p_toolbar)
6969 {
6970 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6971 &toolbar_flags, TRUE) != OK)
6972 errmsg = e_invarg;
6973 else
6974 {
6975 out_flush();
6976 gui_mch_show_toolbar((toolbar_flags &
6977 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6978 }
6979 }
6980#endif
6981
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006982#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006983 /* 'toolbariconsize': GTK+ 2 only */
6984 else if (varp == &p_tbis)
6985 {
6986 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6987 errmsg = e_invarg;
6988 else
6989 {
6990 out_flush();
6991 gui_mch_show_toolbar((toolbar_flags &
6992 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6993 }
6994 }
6995#endif
6996
6997 /* 'pastetoggle': translate key codes like in a mapping */
6998 else if (varp == &p_pt)
6999 {
7000 if (*p_pt)
7001 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007002 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007003 if (p != NULL)
7004 {
7005 if (new_value_alloced)
7006 free_string_option(p_pt);
7007 p_pt = p;
7008 new_value_alloced = TRUE;
7009 }
7010 }
7011 }
7012
7013 /* 'backspace' */
7014 else if (varp == &p_bs)
7015 {
7016 if (VIM_ISDIGIT(*p_bs))
7017 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007018 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007019 errmsg = e_invarg;
7020 }
7021 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7022 errmsg = e_invarg;
7023 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007024 else if (varp == &p_bo)
7025 {
7026 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7027 errmsg = e_invarg;
7028 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007030 /* 'tagcase' */
7031 else if (gvarp == &p_tc)
7032 {
7033 unsigned int *flags;
7034
7035 if (opt_flags & OPT_LOCAL)
7036 {
7037 p = curbuf->b_p_tc;
7038 flags = &curbuf->b_tc_flags;
7039 }
7040 else
7041 {
7042 p = p_tc;
7043 flags = &tc_flags;
7044 }
7045
7046 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7047 /* make the local value empty: use the global value */
7048 *flags = 0;
7049 else if (*p == NUL
7050 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7051 errmsg = e_invarg;
7052 }
7053
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007054#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007055 /* 'casemap' */
7056 else if (varp == &p_cmp)
7057 {
7058 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7059 errmsg = e_invarg;
7060 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007061#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007062
7063#ifdef FEAT_DIFF
7064 /* 'diffopt' */
7065 else if (varp == &p_dip)
7066 {
7067 if (diffopt_changed() == FAIL)
7068 errmsg = e_invarg;
7069 }
7070#endif
7071
7072#ifdef FEAT_FOLDING
7073 /* 'foldmethod' */
7074 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7075 {
7076 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7077 || *curwin->w_p_fdm == NUL)
7078 errmsg = e_invarg;
7079 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007080 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007081 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007082 if (foldmethodIsDiff(curwin))
7083 newFoldLevel();
7084 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085 }
7086# ifdef FEAT_EVAL
7087 /* 'foldexpr' */
7088 else if (varp == &curwin->w_p_fde)
7089 {
7090 if (foldmethodIsExpr(curwin))
7091 foldUpdateAll(curwin);
7092 }
7093# endif
7094 /* 'foldmarker' */
7095 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7096 {
7097 p = vim_strchr(*varp, ',');
7098 if (p == NULL)
7099 errmsg = (char_u *)N_("E536: comma required");
7100 else if (p == *varp || p[1] == NUL)
7101 errmsg = e_invarg;
7102 else if (foldmethodIsMarker(curwin))
7103 foldUpdateAll(curwin);
7104 }
7105 /* 'commentstring' */
7106 else if (gvarp == &p_cms)
7107 {
7108 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7109 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7110 }
7111 /* 'foldopen' */
7112 else if (varp == &p_fdo)
7113 {
7114 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7115 errmsg = e_invarg;
7116 }
7117 /* 'foldclose' */
7118 else if (varp == &p_fcl)
7119 {
7120 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7121 errmsg = e_invarg;
7122 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007123 /* 'foldignore' */
7124 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7125 {
7126 if (foldmethodIsIndent(curwin))
7127 foldUpdateAll(curwin);
7128 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129#endif
7130
7131#ifdef FEAT_VIRTUALEDIT
7132 /* 'virtualedit' */
7133 else if (varp == &p_ve)
7134 {
7135 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7136 errmsg = e_invarg;
7137 else if (STRCMP(p_ve, oldval) != 0)
7138 {
7139 /* Recompute cursor position in case the new 've' setting
7140 * changes something. */
7141 validate_virtcol();
7142 coladvance(curwin->w_virtcol);
7143 }
7144 }
7145#endif
7146
7147#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7148 else if (varp == &p_csqf)
7149 {
7150 if (p_csqf != NULL)
7151 {
7152 p = p_csqf;
7153 while (*p != NUL)
7154 {
7155 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7156 || p[1] == NUL
7157 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7158 || (p[2] != NUL && p[2] != ','))
7159 {
7160 errmsg = e_invarg;
7161 break;
7162 }
7163 else if (p[2] == NUL)
7164 break;
7165 else
7166 p += 3;
7167 }
7168 }
7169 }
7170#endif
7171
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007172#ifdef FEAT_CINDENT
7173 /* 'cinoptions' */
7174 else if (gvarp == &p_cino)
7175 {
7176 /* TODO: recognize errors */
7177 parse_cino(curbuf);
7178 }
7179#endif
7180
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007181#if defined(FEAT_RENDER_OPTIONS)
7182 else if (varp == &p_rop && gui.in_use)
7183 {
7184 if (!gui_mch_set_rendering_options(p_rop))
7185 errmsg = e_invarg;
7186 }
7187#endif
7188
Bram Moolenaar071d4272004-06-13 20:20:40 +00007189 /* Options that are a list of flags. */
7190 else
7191 {
7192 p = NULL;
7193 if (varp == &p_ww)
7194 p = (char_u *)WW_ALL;
7195 if (varp == &p_shm)
7196 p = (char_u *)SHM_ALL;
7197 else if (varp == &(p_cpo))
7198 p = (char_u *)CPO_ALL;
7199 else if (varp == &(curbuf->b_p_fo))
7200 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007201#ifdef FEAT_CONCEAL
7202 else if (varp == &curwin->w_p_cocu)
7203 p = (char_u *)COCU_ALL;
7204#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007205 else if (varp == &p_mouse)
7206 {
7207#ifdef FEAT_MOUSE
7208 p = (char_u *)MOUSE_ALL;
7209#else
7210 if (*p_mouse != NUL)
7211 errmsg = (char_u *)N_("E538: No mouse support");
7212#endif
7213 }
7214#if defined(FEAT_GUI)
7215 else if (varp == &p_go)
7216 p = (char_u *)GO_ALL;
7217#endif
7218 if (p != NULL)
7219 {
7220 for (s = *varp; *s; ++s)
7221 if (vim_strchr(p, *s) == NULL)
7222 {
7223 errmsg = illegal_char(errbuf, *s);
7224 break;
7225 }
7226 }
7227 }
7228
7229 /*
7230 * If error detected, restore the previous value.
7231 */
7232 if (errmsg != NULL)
7233 {
7234 if (new_value_alloced)
7235 free_string_option(*varp);
7236 *varp = oldval;
7237 /*
7238 * When resetting some values, need to act on it.
7239 */
7240 if (did_chartab)
7241 (void)init_chartab();
7242 if (varp == &p_hl)
7243 (void)highlight_changed();
7244 }
7245 else
7246 {
7247#ifdef FEAT_EVAL
7248 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007249 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007250#endif
7251 /*
7252 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007253 * Use "free_oldval", because recursiveness may change the flags under
7254 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007255 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007256 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007257 free_string_option(oldval);
7258 if (new_value_alloced)
7259 options[opt_idx].flags |= P_ALLOCED;
7260 else
7261 options[opt_idx].flags &= ~P_ALLOCED;
7262
7263 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007264 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007265 {
7266 /* global option with local value set to use global value; free
7267 * the local value and make it empty */
7268 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7269 free_string_option(*(char_u **)p);
7270 *(char_u **)p = empty_option;
7271 }
7272
7273 /* May set global value for local option. */
7274 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7275 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007276
7277#ifdef FEAT_AUTOCMD
7278 /*
7279 * Trigger the autocommand only after setting the flags.
7280 */
7281# ifdef FEAT_SYN_HL
7282 /* When 'syntax' is set, load the syntax of that name */
7283 if (varp == &(curbuf->b_p_syn))
7284 {
7285 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7286 curbuf->b_fname, TRUE, curbuf);
7287 }
7288# endif
7289 else if (varp == &(curbuf->b_p_ft))
7290 {
7291 /* 'filetype' is set, trigger the FileType autocommand */
7292 did_filetype = TRUE;
7293 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7294 curbuf->b_fname, TRUE, curbuf);
7295 }
7296#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007297#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007298 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007299 {
7300 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007301 char_u *q = curwin->w_s->b_p_spl;
7302
7303 /* Skip the first name if it is "cjk". */
7304 if (STRNCMP(q, "cjk,", 4) == 0)
7305 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007306
7307 /*
7308 * Source the spell/LANG.vim in 'runtimepath'.
7309 * They could set 'spellcapcheck' depending on the language.
7310 * Use the first name in 'spelllang' up to '_region' or
7311 * '.encoding'.
7312 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007313 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007314 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7315 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007316 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007317 source_runtime(fname, TRUE);
7318 }
7319#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320 }
7321
7322#ifdef FEAT_MOUSE
7323 if (varp == &p_mouse)
7324 {
7325# ifdef FEAT_MOUSE_TTY
7326 if (*p_mouse == NUL)
7327 mch_setmouse(FALSE); /* switch mouse off */
7328 else
7329# endif
7330 setmouse(); /* in case 'mouse' changed */
7331 }
7332#endif
7333
Bram Moolenaar913077c2012-03-28 19:59:04 +02007334 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007335 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007336 curwin->w_set_curswant = TRUE;
7337
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007338#ifdef FEAT_GUI
7339 /* check redraw when it's not a GUI option or the GUI is active. */
7340 if (!redraw_gui_only || gui.in_use)
7341#endif
7342 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007343
7344 return errmsg;
7345}
7346
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007347#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007348/*
7349 * Simple int comparison function for use with qsort()
7350 */
7351 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007352int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007353{
7354 return *(const int *)a - *(const int *)b;
7355}
7356
7357/*
7358 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7359 * Returns error message, NULL if it's OK.
7360 */
7361 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007362check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007363{
7364 char_u *s;
7365 int col;
7366 int count = 0;
7367 int color_cols[256];
7368 int i;
7369 int j = 0;
7370
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007371 if (wp->w_buffer == NULL)
7372 return NULL; /* buffer was closed */
7373
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007374 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007375 {
7376 if (*s == '-' || *s == '+')
7377 {
7378 /* -N and +N: add to 'textwidth' */
7379 col = (*s == '-') ? -1 : 1;
7380 ++s;
7381 if (!VIM_ISDIGIT(*s))
7382 return e_invarg;
7383 col = col * getdigits(&s);
7384 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007385 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007386 col += wp->w_buffer->b_p_tw;
7387 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007388 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007389 }
7390 else if (VIM_ISDIGIT(*s))
7391 col = getdigits(&s);
7392 else
7393 return e_invarg;
7394 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007395skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007396 if (*s == NUL)
7397 break;
7398 if (*s != ',')
7399 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007400 if (*++s == NUL)
7401 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007402 }
7403
7404 vim_free(wp->w_p_cc_cols);
7405 if (count == 0)
7406 wp->w_p_cc_cols = NULL;
7407 else
7408 {
7409 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7410 if (wp->w_p_cc_cols != NULL)
7411 {
7412 /* sort the columns for faster usage on screen redraw inside
7413 * win_line() */
7414 qsort(color_cols, count, sizeof(int), int_cmp);
7415
7416 for (i = 0; i < count; ++i)
7417 /* skip duplicates */
7418 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7419 wp->w_p_cc_cols[j++] = color_cols[i];
7420 wp->w_p_cc_cols[j] = -1; /* end marker */
7421 }
7422 }
7423
7424 return NULL; /* no error */
7425}
7426#endif
7427
Bram Moolenaar071d4272004-06-13 20:20:40 +00007428/*
7429 * Handle setting 'listchars' or 'fillchars'.
7430 * Returns error message, NULL if it's OK.
7431 */
7432 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007433set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007434{
7435 int round, i, len, entries;
7436 char_u *p, *s;
7437 int c1, c2 = 0;
7438 struct charstab
7439 {
7440 int *cp;
7441 char *name;
7442 };
7443#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7444 static struct charstab filltab[] =
7445 {
7446 {&fill_stl, "stl"},
7447 {&fill_stlnc, "stlnc"},
7448 {&fill_vert, "vert"},
7449 {&fill_fold, "fold"},
7450 {&fill_diff, "diff"},
7451 };
7452#endif
7453 static struct charstab lcstab[] =
7454 {
7455 {&lcs_eol, "eol"},
7456 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007457 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007458 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007459 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460 {&lcs_tab2, "tab"},
7461 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007462#ifdef FEAT_CONCEAL
7463 {&lcs_conceal, "conceal"},
7464#else
7465 {NULL, "conceal"},
7466#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007467 };
7468 struct charstab *tab;
7469
7470#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7471 if (varp == &p_lcs)
7472#endif
7473 {
7474 tab = lcstab;
7475 entries = sizeof(lcstab) / sizeof(struct charstab);
7476 }
7477#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7478 else
7479 {
7480 tab = filltab;
7481 entries = sizeof(filltab) / sizeof(struct charstab);
7482 }
7483#endif
7484
7485 /* first round: check for valid value, second round: assign values */
7486 for (round = 0; round <= 1; ++round)
7487 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007488 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489 {
7490 /* After checking that the value is valid: set defaults: space for
7491 * 'fillchars', NUL for 'listchars' */
7492 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007493 if (tab[i].cp != NULL)
7494 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007495 if (varp == &p_lcs)
7496 lcs_tab1 = NUL;
7497#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7498 else
7499 fill_diff = '-';
7500#endif
7501 }
7502 p = *varp;
7503 while (*p)
7504 {
7505 for (i = 0; i < entries; ++i)
7506 {
7507 len = (int)STRLEN(tab[i].name);
7508 if (STRNCMP(p, tab[i].name, len) == 0
7509 && p[len] == ':'
7510 && p[len + 1] != NUL)
7511 {
7512 s = p + len + 1;
7513#ifdef FEAT_MBYTE
7514 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007515 if (mb_char2cells(c1) > 1)
7516 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007517#else
7518 c1 = *s++;
7519#endif
7520 if (tab[i].cp == &lcs_tab2)
7521 {
7522 if (*s == NUL)
7523 continue;
7524#ifdef FEAT_MBYTE
7525 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007526 if (mb_char2cells(c2) > 1)
7527 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007528#else
7529 c2 = *s++;
7530#endif
7531 }
7532 if (*s == ',' || *s == NUL)
7533 {
7534 if (round)
7535 {
7536 if (tab[i].cp == &lcs_tab2)
7537 {
7538 lcs_tab1 = c1;
7539 lcs_tab2 = c2;
7540 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007541 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007542 *(tab[i].cp) = c1;
7543
7544 }
7545 p = s;
7546 break;
7547 }
7548 }
7549 }
7550
7551 if (i == entries)
7552 return e_invarg;
7553 if (*p == ',')
7554 ++p;
7555 }
7556 }
7557
7558 return NULL; /* no error */
7559}
7560
7561#ifdef FEAT_STL_OPT
7562/*
7563 * Check validity of options with the 'statusline' format.
7564 * Return error message or NULL.
7565 */
7566 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007567check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007568{
7569 int itemcnt = 0;
7570 int groupdepth = 0;
7571 static char_u errbuf[80];
7572
7573 while (*s && itemcnt < STL_MAX_ITEM)
7574 {
7575 /* Check for valid keys after % sequences */
7576 while (*s && *s != '%')
7577 s++;
7578 if (!*s)
7579 break;
7580 s++;
7581 if (*s != '%' && *s != ')')
7582 ++itemcnt;
7583 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7584 {
7585 s++;
7586 continue;
7587 }
7588 if (*s == ')')
7589 {
7590 s++;
7591 if (--groupdepth < 0)
7592 break;
7593 continue;
7594 }
7595 if (*s == '-')
7596 s++;
7597 while (VIM_ISDIGIT(*s))
7598 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007599 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007600 continue;
7601 if (*s == '.')
7602 {
7603 s++;
7604 while (*s && VIM_ISDIGIT(*s))
7605 s++;
7606 }
7607 if (*s == '(')
7608 {
7609 groupdepth++;
7610 continue;
7611 }
7612 if (vim_strchr(STL_ALL, *s) == NULL)
7613 {
7614 return illegal_char(errbuf, *s);
7615 }
7616 if (*s == '{')
7617 {
7618 s++;
7619 while (*s != '}' && *s)
7620 s++;
7621 if (*s != '}')
7622 return (char_u *)N_("E540: Unclosed expression sequence");
7623 }
7624 }
7625 if (itemcnt >= STL_MAX_ITEM)
7626 return (char_u *)N_("E541: too many items");
7627 if (groupdepth != 0)
7628 return (char_u *)N_("E542: unbalanced groups");
7629 return NULL;
7630}
7631#endif
7632
7633#ifdef FEAT_CLIPBOARD
7634/*
7635 * Extract the items in the 'clipboard' option and set global values.
7636 */
7637 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007638check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007639{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007640 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007641 int new_autoselect_star = FALSE;
7642 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007643 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007644 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007645 regprog_T *new_exclude_prog = NULL;
7646 char_u *errmsg = NULL;
7647 char_u *p;
7648
7649 for (p = p_cb; *p != NUL; )
7650 {
7651 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7652 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007653 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007654 p += 7;
7655 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007656 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007657 && (p[11] == ',' || p[11] == NUL))
7658 {
7659 new_unnamed |= CLIP_UNNAMED_PLUS;
7660 p += 11;
7661 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007662 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007663 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007664 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007665 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007666 p += 10;
7667 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007668 else if (STRNCMP(p, "autoselectplus", 14) == 0
7669 && (p[14] == ',' || p[14] == NUL))
7670 {
7671 new_autoselect_plus = TRUE;
7672 p += 14;
7673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007674 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007675 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007676 {
7677 new_autoselectml = TRUE;
7678 p += 12;
7679 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007680 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7681 {
7682 new_html = TRUE;
7683 p += 4;
7684 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007685 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7686 {
7687 p += 8;
7688 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7689 if (new_exclude_prog == NULL)
7690 errmsg = e_invarg;
7691 break;
7692 }
7693 else
7694 {
7695 errmsg = e_invarg;
7696 break;
7697 }
7698 if (*p == ',')
7699 ++p;
7700 }
7701 if (errmsg == NULL)
7702 {
7703 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007704 clip_autoselect_star = new_autoselect_star;
7705 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007706 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007707 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007708 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007709 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007710#ifdef FEAT_GUI_GTK
7711 if (gui.in_use)
7712 {
7713 gui_gtk_set_selection_targets();
7714 gui_gtk_set_dnd_targets();
7715 }
7716#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007717 }
7718 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007719 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007720
7721 return errmsg;
7722}
7723#endif
7724
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007725#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007726 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007727did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007728{
7729 char_u *errmsg = NULL;
7730 win_T *wp;
7731 int l;
7732
7733 if (is_spellfile)
7734 {
7735 l = (int)STRLEN(curwin->w_s->b_p_spf);
7736 if (l > 0 && (l < 4
7737 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7738 errmsg = e_invarg;
7739 }
7740
7741 if (errmsg == NULL)
7742 {
7743 FOR_ALL_WINDOWS(wp)
7744 if (wp->w_buffer == curbuf && wp->w_p_spell)
7745 {
7746 errmsg = did_set_spelllang(wp);
7747# ifdef FEAT_WINDOWS
7748 break;
7749# endif
7750 }
7751 }
7752 return errmsg;
7753}
7754
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007755/*
7756 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7757 * Return error message when failed, NULL when OK.
7758 */
7759 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007760compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007761{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007762 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007763 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007764
Bram Moolenaar860cae12010-06-05 23:22:07 +02007765 if (*synblock->b_p_spc == NUL)
7766 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007767 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007768 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007769 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007770 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007771 if (re != NULL)
7772 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007773 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007774 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007775 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007776 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007777 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007778 return e_invarg;
7779 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007780 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007781 }
7782
Bram Moolenaar473de612013-06-08 18:19:48 +02007783 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007784 return NULL;
7785}
7786#endif
7787
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007788#if defined(FEAT_EVAL) || defined(PROTO)
7789/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007790 * Set the scriptID for an option, taking care of setting the buffer- or
7791 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007792 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007793 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007794set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007795{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007796 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7797 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007798
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007799 /* Remember where the option was set. For local options need to do that
7800 * in the buffer or window structure. */
7801 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007802 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007803 if (both || (opt_flags & OPT_LOCAL))
7804 {
7805 if (indir & PV_BUF)
7806 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7807 else if (indir & PV_WIN)
7808 curwin->w_p_scriptID[indir & PV_MASK] = id;
7809 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007810}
7811#endif
7812
Bram Moolenaar071d4272004-06-13 20:20:40 +00007813/*
7814 * Set the value of a boolean option, and take care of side effects.
7815 * Returns NULL for success, or an error message for an error.
7816 */
7817 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007818set_bool_option(
7819 int opt_idx, /* index in options[] table */
7820 char_u *varp, /* pointer to the option variable */
7821 int value, /* new value */
7822 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007823{
7824 int old_value = *(int *)varp;
7825
Bram Moolenaar071d4272004-06-13 20:20:40 +00007826 /* Disallow changing some options from secure mode */
7827 if ((secure
7828#ifdef HAVE_SANDBOX
7829 || sandbox != 0
7830#endif
7831 ) && (options[opt_idx].flags & P_SECURE))
7832 return e_secure;
7833
7834 *(int *)varp = value; /* set the new value */
7835#ifdef FEAT_EVAL
7836 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007837 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007838#endif
7839
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007840#ifdef FEAT_GUI
7841 need_mouse_correct = TRUE;
7842#endif
7843
Bram Moolenaar071d4272004-06-13 20:20:40 +00007844 /* May set global value for local option. */
7845 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7846 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7847
7848 /*
7849 * Handle side effects of changing a bool option.
7850 */
7851
7852 /* 'compatible' */
7853 if ((int *)varp == &p_cp)
7854 {
7855 compatible_set();
7856 }
7857
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007858#ifdef FEAT_PERSISTENT_UNDO
7859 /* 'undofile' */
7860 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7861 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007862 /* Only take action when the option was set. When reset we do not
7863 * delete the undo file, the option may be set again without making
7864 * any changes in between. */
7865 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007866 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007867 char_u hash[UNDO_HASH_SIZE];
7868 buf_T *save_curbuf = curbuf;
7869
7870 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007871 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007872 /* When 'undofile' is set globally: for every buffer, otherwise
7873 * only for the current buffer: Try to read in the undofile,
7874 * if one exists, the buffer wasn't changed and the buffer was
7875 * loaded */
7876 if ((curbuf == save_curbuf
7877 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7878 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7879 {
7880 u_compute_hash(hash);
7881 u_read_undo(NULL, hash, curbuf->b_fname);
7882 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007883 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007884 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007885 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007886 }
7887#endif
7888
Bram Moolenaar071d4272004-06-13 20:20:40 +00007889 else if ((int *)varp == &curbuf->b_p_ro)
7890 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007891 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7893 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007894
7895 /* when 'readonly' is set may give W10 again */
7896 if (curbuf->b_p_ro)
7897 curbuf->b_did_warn = FALSE;
7898
Bram Moolenaar071d4272004-06-13 20:20:40 +00007899#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007900 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007901#endif
7902 }
7903
Bram Moolenaar9c449722010-07-20 18:44:27 +02007904#ifdef FEAT_GUI
7905 else if ((int *)varp == &p_mh)
7906 {
7907 if (!p_mh)
7908 gui_mch_mousehide(FALSE);
7909 }
7910#endif
7911
Bram Moolenaara539df02010-08-01 14:35:05 +02007912#ifdef FEAT_TITLE
7913 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007915 {
7916 redraw_titles();
7917 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 /* when 'endofline' is changed, redraw the window title */
7919 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007920 {
7921 redraw_titles();
7922 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007923 /* when 'fixeol' is changed, redraw the window title */
7924 else if ((int *)varp == &curbuf->b_p_fixeol)
7925 {
7926 redraw_titles();
7927 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007928# ifdef FEAT_MBYTE
7929 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007930 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007931 {
7932 redraw_titles();
7933 }
7934# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935#endif
7936
7937 /* when 'bin' is set also set some other options */
7938 else if ((int *)varp == &curbuf->b_p_bin)
7939 {
7940 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7941#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007942 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943#endif
7944 }
7945
7946#ifdef FEAT_AUTOCMD
7947 /* when 'buflisted' changes, trigger autocommands */
7948 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7949 {
7950 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7951 NULL, NULL, TRUE, curbuf);
7952 }
7953#endif
7954
7955 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7956 else if ((int *)varp == &curbuf->b_p_swf)
7957 {
7958 if (curbuf->b_p_swf && p_uc)
7959 ml_open_file(curbuf); /* create the swap file */
7960 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007961 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7962 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963 mf_close_file(curbuf, TRUE); /* remove the swap file */
7964 }
7965
7966 /* when 'terse' is set change 'shortmess' */
7967 else if ((int *)varp == &p_terse)
7968 {
7969 char_u *p;
7970
7971 p = vim_strchr(p_shm, SHM_SEARCH);
7972
7973 /* insert 's' in p_shm */
7974 if (p_terse && p == NULL)
7975 {
7976 STRCPY(IObuff, p_shm);
7977 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007978 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007979 }
7980 /* remove 's' from p_shm */
7981 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007982 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 }
7984
7985 /* when 'paste' is set or reset also change other options */
7986 else if ((int *)varp == &p_paste)
7987 {
7988 paste_option_changed();
7989 }
7990
7991 /* when 'insertmode' is set from an autocommand need to do work here */
7992 else if ((int *)varp == &p_im)
7993 {
7994 if (p_im)
7995 {
7996 if ((State & INSERT) == 0)
7997 need_start_insertmode = TRUE;
7998 stop_insert_mode = FALSE;
7999 }
8000 else
8001 {
8002 need_start_insertmode = FALSE;
8003 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008004 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008005 clear_cmdline = TRUE; /* remove "(insert)" */
8006 restart_edit = 0;
8007 }
8008 }
8009
8010 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8011 else if ((int *)varp == &p_ic && p_hls)
8012 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008013 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014 }
8015
8016#ifdef FEAT_SEARCH_EXTRA
8017 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8018 else if ((int *)varp == &p_hls)
8019 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008020 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 }
8022#endif
8023
8024#ifdef FEAT_SCROLLBIND
8025 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8026 * at the end of normal_cmd() */
8027 else if ((int *)varp == &curwin->w_p_scb)
8028 {
8029 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008030 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008031 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008032 curwin->w_scbind_pos = curwin->w_topline;
8033 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008034 }
8035#endif
8036
8037#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8038 /* There can be only one window with 'previewwindow' set. */
8039 else if ((int *)varp == &curwin->w_p_pvw)
8040 {
8041 if (curwin->w_p_pvw)
8042 {
8043 win_T *win;
8044
8045 for (win = firstwin; win != NULL; win = win->w_next)
8046 if (win->w_p_pvw && win != curwin)
8047 {
8048 curwin->w_p_pvw = FALSE;
8049 return (char_u *)N_("E590: A preview window already exists");
8050 }
8051 }
8052 }
8053#endif
8054
8055 /* when 'textmode' is set or reset also change 'fileformat' */
8056 else if ((int *)varp == &curbuf->b_p_tx)
8057 {
8058 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8059 }
8060
8061 /* when 'textauto' is set or reset also change 'fileformats' */
8062 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008063 set_string_option_direct((char_u *)"ffs", -1,
8064 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008065 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066
8067 /*
8068 * When 'lisp' option changes include/exclude '-' in
8069 * keyword characters.
8070 */
8071#ifdef FEAT_LISP
8072 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8073 {
8074 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8075 }
8076#endif
8077
8078#ifdef FEAT_TITLE
8079 /* when 'title' changed, may need to change the title; same for 'icon' */
8080 else if ((int *)varp == &p_title)
8081 {
8082 did_set_title(FALSE);
8083 }
8084
8085 else if ((int *)varp == &p_icon)
8086 {
8087 did_set_title(TRUE);
8088 }
8089#endif
8090
8091 else if ((int *)varp == &curbuf->b_changed)
8092 {
8093 if (!value)
8094 save_file_ff(curbuf); /* Buffer is unchanged */
8095#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008096 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008097#endif
8098#ifdef FEAT_AUTOCMD
8099 modified_was_set = value;
8100#endif
8101 }
8102
8103#ifdef BACKSLASH_IN_FILENAME
8104 else if ((int *)varp == &p_ssl)
8105 {
8106 if (p_ssl)
8107 {
8108 psepc = '/';
8109 psepcN = '\\';
8110 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008111 }
8112 else
8113 {
8114 psepc = '\\';
8115 psepcN = '/';
8116 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 }
8118
8119 /* need to adjust the file name arguments and buffer names. */
8120 buflist_slash_adjust();
8121 alist_slash_adjust();
8122# ifdef FEAT_EVAL
8123 scriptnames_slash_adjust();
8124# endif
8125 }
8126#endif
8127
8128 /* If 'wrap' is set, set w_leftcol to zero. */
8129 else if ((int *)varp == &curwin->w_p_wrap)
8130 {
8131 if (curwin->w_p_wrap)
8132 curwin->w_leftcol = 0;
8133 }
8134
8135#ifdef FEAT_WINDOWS
8136 else if ((int *)varp == &p_ea)
8137 {
8138 if (p_ea && !old_value)
8139 win_equal(curwin, FALSE, 0);
8140 }
8141#endif
8142
8143 else if ((int *)varp == &p_wiv)
8144 {
8145 /*
8146 * When 'weirdinvert' changed, set/reset 't_xs'.
8147 * Then set 'weirdinvert' according to value of 't_xs'.
8148 */
8149 if (p_wiv && !old_value)
8150 T_XS = (char_u *)"y";
8151 else if (!p_wiv && old_value)
8152 T_XS = empty_option;
8153 p_wiv = (*T_XS != NUL);
8154 }
8155
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008156#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 else if ((int *)varp == &p_beval)
8158 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008159 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008161 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008162 gui_mch_disable_beval_area(balloonEval);
8163 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008164#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008166#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 else if ((int *)varp == &p_acd)
8168 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008169 /* Change directories when the 'acd' option is set now. */
8170 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 }
8172#endif
8173
8174#ifdef FEAT_DIFF
8175 /* 'diff' */
8176 else if ((int *)varp == &curwin->w_p_diff)
8177 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008178 /* May add or remove the buffer from the list of diff buffers. */
8179 diff_buf_adjust(curwin);
8180# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181 if (foldmethodIsDiff(curwin))
8182 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008183# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184 }
8185#endif
8186
8187#ifdef USE_IM_CONTROL
8188 /* 'imdisable' */
8189 else if ((int *)varp == &p_imdisable)
8190 {
8191 /* Only de-activate it here, it will be enabled when changing mode. */
8192 if (p_imdisable)
8193 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008194 else if (State & INSERT)
8195 /* When the option is set from an autocommand, it may need to take
8196 * effect right away. */
8197 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198 }
8199#endif
8200
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008201#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008202 /* 'spell' */
8203 else if ((int *)varp == &curwin->w_p_spell)
8204 {
8205 if (curwin->w_p_spell)
8206 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008207 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008208 if (errmsg != NULL)
8209 EMSG(_(errmsg));
8210 }
8211 }
8212#endif
8213
Bram Moolenaar071d4272004-06-13 20:20:40 +00008214#ifdef FEAT_FKMAP
8215 else if ((int *)varp == &p_altkeymap)
8216 {
8217 if (old_value != p_altkeymap)
8218 {
8219 if (!p_altkeymap)
8220 {
8221 p_hkmap = p_fkmap;
8222 p_fkmap = 0;
8223 }
8224 else
8225 {
8226 p_fkmap = p_hkmap;
8227 p_hkmap = 0;
8228 }
8229 (void)init_chartab();
8230 }
8231 }
8232
8233 /*
8234 * In case some second language keymapping options have changed, check
8235 * and correct the setting in a consistent way.
8236 */
8237
8238 /*
8239 * If hkmap or fkmap are set, reset Arabic keymapping.
8240 */
8241 if ((p_hkmap || p_fkmap) && p_altkeymap)
8242 {
8243 p_altkeymap = p_fkmap;
8244# ifdef FEAT_ARABIC
8245 curwin->w_p_arab = FALSE;
8246# endif
8247 (void)init_chartab();
8248 }
8249
8250 /*
8251 * If hkmap set, reset Farsi keymapping.
8252 */
8253 if (p_hkmap && p_altkeymap)
8254 {
8255 p_altkeymap = 0;
8256 p_fkmap = 0;
8257# ifdef FEAT_ARABIC
8258 curwin->w_p_arab = FALSE;
8259# endif
8260 (void)init_chartab();
8261 }
8262
8263 /*
8264 * If fkmap set, reset Hebrew keymapping.
8265 */
8266 if (p_fkmap && !p_altkeymap)
8267 {
8268 p_altkeymap = 1;
8269 p_hkmap = 0;
8270# ifdef FEAT_ARABIC
8271 curwin->w_p_arab = FALSE;
8272# endif
8273 (void)init_chartab();
8274 }
8275#endif
8276
8277#ifdef FEAT_ARABIC
8278 if ((int *)varp == &curwin->w_p_arab)
8279 {
8280 if (curwin->w_p_arab)
8281 {
8282 /*
8283 * 'arabic' is set, handle various sub-settings.
8284 */
8285 if (!p_tbidi)
8286 {
8287 /* set rightleft mode */
8288 if (!curwin->w_p_rl)
8289 {
8290 curwin->w_p_rl = TRUE;
8291 changed_window_setting();
8292 }
8293
8294 /* Enable Arabic shaping (major part of what Arabic requires) */
8295 if (!p_arshape)
8296 {
8297 p_arshape = TRUE;
8298 redraw_later_clear();
8299 }
8300 }
8301
8302 /* Arabic requires a utf-8 encoding, inform the user if its not
8303 * set. */
8304 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008305 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008306 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8307
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008308 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008309 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8310#ifdef FEAT_EVAL
8311 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8312#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008313 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314
8315# ifdef FEAT_MBYTE
8316 /* set 'delcombine' */
8317 p_deco = TRUE;
8318# endif
8319
8320# ifdef FEAT_KEYMAP
8321 /* Force-set the necessary keymap for arabic */
8322 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8323 OPT_LOCAL);
8324# endif
8325# ifdef FEAT_FKMAP
8326 p_altkeymap = 0;
8327 p_hkmap = 0;
8328 p_fkmap = 0;
8329 (void)init_chartab();
8330# endif
8331 }
8332 else
8333 {
8334 /*
8335 * 'arabic' is reset, handle various sub-settings.
8336 */
8337 if (!p_tbidi)
8338 {
8339 /* reset rightleft mode */
8340 if (curwin->w_p_rl)
8341 {
8342 curwin->w_p_rl = FALSE;
8343 changed_window_setting();
8344 }
8345
8346 /* 'arabicshape' isn't reset, it is a global option and
8347 * another window may still need it "on". */
8348 }
8349
8350 /* 'delcombine' isn't reset, it is a global option and another
8351 * window may still want it "on". */
8352
8353# ifdef FEAT_KEYMAP
8354 /* Revert to the default keymap */
8355 curbuf->b_p_iminsert = B_IMODE_NONE;
8356 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8357# endif
8358 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008359 }
8360
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008361#endif
8362
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363 /*
8364 * End of handling side effects for bool options.
8365 */
8366
Bram Moolenaar53744302015-07-17 17:38:22 +02008367 /* after handling side effects, call autocommand */
8368
Bram Moolenaar071d4272004-06-13 20:20:40 +00008369 options[opt_idx].flags |= P_WAS_SET;
8370
Bram Moolenaar53744302015-07-17 17:38:22 +02008371#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8372 if (!starting)
8373 {
8374 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008375 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8376 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8377 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008378 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8379 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8380 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8381 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8382 reset_v_option_vars();
8383 }
8384#endif
8385
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008387 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008388 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008389 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008390 check_redraw(options[opt_idx].flags);
8391
8392 return NULL;
8393}
8394
8395/*
8396 * Set the value of a number option, and take care of side effects.
8397 * Returns NULL for success, or an error message for an error.
8398 */
8399 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008400set_num_option(
8401 int opt_idx, /* index in options[] table */
8402 char_u *varp, /* pointer to the option variable */
8403 long value, /* new value */
8404 char_u *errbuf, /* buffer for error messages */
8405 size_t errbuflen, /* length of "errbuf" */
8406 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 OPT_MODELINE */
8408{
8409 char_u *errmsg = NULL;
8410 long old_value = *(long *)varp;
8411 long old_Rows = Rows; /* remember old Rows */
8412 long old_Columns = Columns; /* remember old Columns */
8413 long *pp = (long *)varp;
8414
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008415 /* Disallow changing some options from secure mode. */
8416 if ((secure
8417#ifdef HAVE_SANDBOX
8418 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008419#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008420 ) && (options[opt_idx].flags & P_SECURE))
8421 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008422
8423 *pp = value;
8424#ifdef FEAT_EVAL
8425 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008426 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008427#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008428#ifdef FEAT_GUI
8429 need_mouse_correct = TRUE;
8430#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008431
Bram Moolenaar14f24742012-08-08 18:01:05 +02008432 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433 {
8434 errmsg = e_positive;
8435 curbuf->b_p_sw = curbuf->b_p_ts;
8436 }
8437
8438 /*
8439 * Number options that need some action when changed
8440 */
8441#ifdef FEAT_WINDOWS
8442 if (pp == &p_wh || pp == &p_hh)
8443 {
8444 if (p_wh < 1)
8445 {
8446 errmsg = e_positive;
8447 p_wh = 1;
8448 }
8449 if (p_wmh > p_wh)
8450 {
8451 errmsg = e_winheight;
8452 p_wh = p_wmh;
8453 }
8454 if (p_hh < 0)
8455 {
8456 errmsg = e_positive;
8457 p_hh = 0;
8458 }
8459
8460 /* Change window height NOW */
8461 if (lastwin != firstwin)
8462 {
8463 if (pp == &p_wh && curwin->w_height < p_wh)
8464 win_setheight((int)p_wh);
8465 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8466 win_setheight((int)p_hh);
8467 }
8468 }
8469
8470 /* 'winminheight' */
8471 else if (pp == &p_wmh)
8472 {
8473 if (p_wmh < 0)
8474 {
8475 errmsg = e_positive;
8476 p_wmh = 0;
8477 }
8478 if (p_wmh > p_wh)
8479 {
8480 errmsg = e_winheight;
8481 p_wmh = p_wh;
8482 }
8483 win_setminheight();
8484 }
8485
8486# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008487 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008488 {
8489 if (p_wiw < 1)
8490 {
8491 errmsg = e_positive;
8492 p_wiw = 1;
8493 }
8494 if (p_wmw > p_wiw)
8495 {
8496 errmsg = e_winwidth;
8497 p_wiw = p_wmw;
8498 }
8499
8500 /* Change window width NOW */
8501 if (lastwin != firstwin && curwin->w_width < p_wiw)
8502 win_setwidth((int)p_wiw);
8503 }
8504
8505 /* 'winminwidth' */
8506 else if (pp == &p_wmw)
8507 {
8508 if (p_wmw < 0)
8509 {
8510 errmsg = e_positive;
8511 p_wmw = 0;
8512 }
8513 if (p_wmw > p_wiw)
8514 {
8515 errmsg = e_winwidth;
8516 p_wmw = p_wiw;
8517 }
8518 win_setminheight();
8519 }
8520# endif
8521
8522#endif
8523
8524#ifdef FEAT_WINDOWS
8525 /* (re)set last window status line */
8526 else if (pp == &p_ls)
8527 {
8528 last_status(FALSE);
8529 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008530
8531 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008532 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008533 {
8534 shell_new_rows(); /* recompute window positions and heights */
8535 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008536#endif
8537
8538#ifdef FEAT_GUI
8539 else if (pp == &p_linespace)
8540 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008541 /* Recompute gui.char_height and resize the Vim window to keep the
8542 * same number of lines. */
8543 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008544 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545 }
8546#endif
8547
8548#ifdef FEAT_FOLDING
8549 /* 'foldlevel' */
8550 else if (pp == &curwin->w_p_fdl)
8551 {
8552 if (curwin->w_p_fdl < 0)
8553 curwin->w_p_fdl = 0;
8554 newFoldLevel();
8555 }
8556
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008557 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008558 else if (pp == &curwin->w_p_fml)
8559 {
8560 foldUpdateAll(curwin);
8561 }
8562
8563 /* 'foldnestmax' */
8564 else if (pp == &curwin->w_p_fdn)
8565 {
8566 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8567 foldUpdateAll(curwin);
8568 }
8569
8570 /* 'foldcolumn' */
8571 else if (pp == &curwin->w_p_fdc)
8572 {
8573 if (curwin->w_p_fdc < 0)
8574 {
8575 errmsg = e_positive;
8576 curwin->w_p_fdc = 0;
8577 }
8578 else if (curwin->w_p_fdc > 12)
8579 {
8580 errmsg = e_invarg;
8581 curwin->w_p_fdc = 12;
8582 }
8583 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008584#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008585
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008586#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587 /* 'shiftwidth' or 'tabstop' */
8588 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8589 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008590# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 if (foldmethodIsIndent(curwin))
8592 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008593# endif
8594# ifdef FEAT_CINDENT
8595 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8596 * parse 'cinoptions'. */
8597 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8598 parse_cino(curbuf);
8599# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008600 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008601#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008602
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008603#ifdef FEAT_MBYTE
8604 /* 'maxcombine' */
8605 else if (pp == &p_mco)
8606 {
8607 if (p_mco > MAX_MCO)
8608 p_mco = MAX_MCO;
8609 else if (p_mco < 0)
8610 p_mco = 0;
8611 screenclear(); /* will re-allocate the screen */
8612 }
8613#endif
8614
Bram Moolenaar071d4272004-06-13 20:20:40 +00008615 else if (pp == &curbuf->b_p_iminsert)
8616 {
8617 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8618 {
8619 errmsg = e_invarg;
8620 curbuf->b_p_iminsert = B_IMODE_NONE;
8621 }
8622 p_iminsert = curbuf->b_p_iminsert;
8623 if (termcap_active) /* don't do this in the alternate screen */
8624 showmode();
8625#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8626 /* Show/unshow value of 'keymap' in status lines. */
8627 status_redraw_curbuf();
8628#endif
8629 }
8630
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008631 else if (pp == &p_window)
8632 {
8633 if (p_window < 1)
8634 p_window = 1;
8635 else if (p_window >= Rows)
8636 p_window = Rows - 1;
8637 }
8638
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639 else if (pp == &curbuf->b_p_imsearch)
8640 {
8641 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8642 {
8643 errmsg = e_invarg;
8644 curbuf->b_p_imsearch = B_IMODE_NONE;
8645 }
8646 p_imsearch = curbuf->b_p_imsearch;
8647 }
8648
8649#ifdef FEAT_TITLE
8650 /* if 'titlelen' has changed, redraw the title */
8651 else if (pp == &p_titlelen)
8652 {
8653 if (p_titlelen < 0)
8654 {
8655 errmsg = e_positive;
8656 p_titlelen = 85;
8657 }
8658 if (starting != NO_SCREEN && old_value != p_titlelen)
8659 need_maketitle = TRUE;
8660 }
8661#endif
8662
8663 /* if p_ch changed value, change the command line height */
8664 else if (pp == &p_ch)
8665 {
8666 if (p_ch < 1)
8667 {
8668 errmsg = e_positive;
8669 p_ch = 1;
8670 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008671 if (p_ch > Rows - min_rows() + 1)
8672 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673
8674 /* Only compute the new window layout when startup has been
8675 * completed. Otherwise the frame sizes may be wrong. */
8676 if (p_ch != old_value && full_screen
8677#ifdef FEAT_GUI
8678 && !gui.starting
8679#endif
8680 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008681 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 }
8683
8684 /* when 'updatecount' changes from zero to non-zero, open swap files */
8685 else if (pp == &p_uc)
8686 {
8687 if (p_uc < 0)
8688 {
8689 errmsg = e_positive;
8690 p_uc = 100;
8691 }
8692 if (p_uc && !old_value)
8693 ml_open_files();
8694 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008695#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008696 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008697 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008698 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008699 {
8700 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008701 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008702 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008703 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008704 {
8705 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008706 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008707 }
8708 }
8709#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008710#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008711 else if (pp == &p_mzq)
8712 mzvim_reset_timer();
8713#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714
8715 /* sync undo before 'undolevels' changes */
8716 else if (pp == &p_ul)
8717 {
8718 /* use the old value, otherwise u_sync() may not work properly */
8719 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008720 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008721 p_ul = value;
8722 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008723 else if (pp == &curbuf->b_p_ul)
8724 {
8725 /* use the old value, otherwise u_sync() may not work properly */
8726 curbuf->b_p_ul = old_value;
8727 u_sync(TRUE);
8728 curbuf->b_p_ul = value;
8729 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008730
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008731#ifdef FEAT_LINEBREAK
8732 /* 'numberwidth' must be positive */
8733 else if (pp == &curwin->w_p_nuw)
8734 {
8735 if (curwin->w_p_nuw < 1)
8736 {
8737 errmsg = e_positive;
8738 curwin->w_p_nuw = 1;
8739 }
8740 if (curwin->w_p_nuw > 10)
8741 {
8742 errmsg = e_invarg;
8743 curwin->w_p_nuw = 10;
8744 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008745 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008746 }
8747#endif
8748
Bram Moolenaar1a384422010-07-14 19:53:30 +02008749 else if (pp == &curbuf->b_p_tw)
8750 {
8751 if (curbuf->b_p_tw < 0)
8752 {
8753 errmsg = e_positive;
8754 curbuf->b_p_tw = 0;
8755 }
8756#ifdef FEAT_SYN_HL
8757# ifdef FEAT_WINDOWS
8758 {
8759 win_T *wp;
8760 tabpage_T *tp;
8761
8762 FOR_ALL_TAB_WINDOWS(tp, wp)
8763 check_colorcolumn(wp);
8764 }
8765# else
8766 check_colorcolumn(curwin);
8767# endif
8768#endif
8769 }
8770
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771 /*
8772 * Check the bounds for numeric options here
8773 */
8774 if (Rows < min_rows() && full_screen)
8775 {
8776 if (errbuf != NULL)
8777 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008778 vim_snprintf((char *)errbuf, errbuflen,
8779 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780 errmsg = errbuf;
8781 }
8782 Rows = min_rows();
8783 }
8784 if (Columns < MIN_COLUMNS && full_screen)
8785 {
8786 if (errbuf != NULL)
8787 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008788 vim_snprintf((char *)errbuf, errbuflen,
8789 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008790 errmsg = errbuf;
8791 }
8792 Columns = MIN_COLUMNS;
8793 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008794 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795
8796#ifdef DJGPP
8797 /* avoid a crash by checking for a too large value of 'columns' */
8798 if (old_Columns != Columns && full_screen && term_console)
8799 mch_check_columns();
8800#endif
8801
8802 /*
8803 * If the screen (shell) height has been changed, assume it is the
8804 * physical screenheight.
8805 */
8806 if (old_Rows != Rows || old_Columns != Columns)
8807 {
8808 /* Changing the screen size is not allowed while updating the screen. */
8809 if (updating_screen)
8810 *pp = old_value;
8811 else if (full_screen
8812#ifdef FEAT_GUI
8813 && !gui.starting
8814#endif
8815 )
8816 set_shellsize((int)Columns, (int)Rows, TRUE);
8817 else
8818 {
8819 /* Postpone the resizing; check the size and cmdline position for
8820 * messages. */
8821 check_shellsize();
8822 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8823 cmdline_row = Rows - p_ch;
8824 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008825 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008826 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008827 }
8828
Bram Moolenaar071d4272004-06-13 20:20:40 +00008829 if (curbuf->b_p_ts <= 0)
8830 {
8831 errmsg = e_positive;
8832 curbuf->b_p_ts = 8;
8833 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008834 if (p_tm < 0)
8835 {
8836 errmsg = e_positive;
8837 p_tm = 0;
8838 }
8839 if ((curwin->w_p_scr <= 0
8840 || (curwin->w_p_scr > curwin->w_height
8841 && curwin->w_height > 0))
8842 && full_screen)
8843 {
8844 if (pp == &(curwin->w_p_scr))
8845 {
8846 if (curwin->w_p_scr != 0)
8847 errmsg = e_scroll;
8848 win_comp_scroll(curwin);
8849 }
8850 /* If 'scroll' became invalid because of a side effect silently adjust
8851 * it. */
8852 else if (curwin->w_p_scr <= 0)
8853 curwin->w_p_scr = 1;
8854 else /* curwin->w_p_scr > curwin->w_height */
8855 curwin->w_p_scr = curwin->w_height;
8856 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008857 if (p_hi < 0)
8858 {
8859 errmsg = e_positive;
8860 p_hi = 0;
8861 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008862 else if (p_hi > 10000)
8863 {
8864 errmsg = e_invarg;
8865 p_hi = 10000;
8866 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008867 if (p_re < 0 || p_re > 2)
8868 {
8869 errmsg = e_invarg;
8870 p_re = 0;
8871 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872 if (p_report < 0)
8873 {
8874 errmsg = e_positive;
8875 p_report = 1;
8876 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008877 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008878 {
8879 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8880 p_sj = Rows / 2;
8881 else
8882 {
8883 errmsg = e_scroll;
8884 p_sj = 1;
8885 }
8886 }
8887 if (p_so < 0 && full_screen)
8888 {
8889 errmsg = e_scroll;
8890 p_so = 0;
8891 }
8892 if (p_siso < 0 && full_screen)
8893 {
8894 errmsg = e_positive;
8895 p_siso = 0;
8896 }
8897#ifdef FEAT_CMDWIN
8898 if (p_cwh < 1)
8899 {
8900 errmsg = e_positive;
8901 p_cwh = 1;
8902 }
8903#endif
8904 if (p_ut < 0)
8905 {
8906 errmsg = e_positive;
8907 p_ut = 2000;
8908 }
8909 if (p_ss < 0)
8910 {
8911 errmsg = e_positive;
8912 p_ss = 0;
8913 }
8914
8915 /* May set global value for local option. */
8916 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8917 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8918
8919 options[opt_idx].flags |= P_WAS_SET;
8920
Bram Moolenaar53744302015-07-17 17:38:22 +02008921#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8922 if (!starting && errmsg == NULL)
8923 {
8924 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008925 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8926 vim_snprintf((char *)buf_new, 10, "%ld", value);
8927 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008928 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8929 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8930 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8931 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8932 reset_v_option_vars();
8933 }
8934#endif
8935
Bram Moolenaar071d4272004-06-13 20:20:40 +00008936 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008937 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008938 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008939 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940 check_redraw(options[opt_idx].flags);
8941
8942 return errmsg;
8943}
8944
8945/*
8946 * Called after an option changed: check if something needs to be redrawn.
8947 */
8948 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008949check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008950{
8951 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008952 int doclear = (flags & P_RCLR) == P_RCLR;
8953 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008954
8955#ifdef FEAT_WINDOWS
8956 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8957 status_redraw_all();
8958#endif
8959
8960 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8961 changed_window_setting();
8962 if (flags & P_RBUF)
8963 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008964 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965 redraw_all_later(CLEAR);
8966 else if (all)
8967 redraw_all_later(NOT_VALID);
8968}
8969
8970/*
8971 * Find index for option 'arg'.
8972 * Return -1 if not found.
8973 */
8974 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008975findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008976{
8977 int opt_idx;
8978 char *s, *p;
8979 static short quick_tab[27] = {0, 0}; /* quick access table */
8980 int is_term_opt;
8981
8982 /*
8983 * For first call: Initialize the quick-access table.
8984 * It contains the index for the first option that starts with a certain
8985 * letter. There are 26 letters, plus the first "t_" option.
8986 */
8987 if (quick_tab[1] == 0)
8988 {
8989 p = options[0].fullname;
8990 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8991 {
8992 if (s[0] != p[0])
8993 {
8994 if (s[0] == 't' && s[1] == '_')
8995 quick_tab[26] = opt_idx;
8996 else
8997 quick_tab[CharOrdLow(s[0])] = opt_idx;
8998 }
8999 p = s;
9000 }
9001 }
9002
9003 /*
9004 * Check for name starting with an illegal character.
9005 */
9006#ifdef EBCDIC
9007 if (!islower(arg[0]))
9008#else
9009 if (arg[0] < 'a' || arg[0] > 'z')
9010#endif
9011 return -1;
9012
9013 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9014 if (is_term_opt)
9015 opt_idx = quick_tab[26];
9016 else
9017 opt_idx = quick_tab[CharOrdLow(arg[0])];
9018 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9019 {
9020 if (STRCMP(arg, s) == 0) /* match full name */
9021 break;
9022 }
9023 if (s == NULL && !is_term_opt)
9024 {
9025 opt_idx = quick_tab[CharOrdLow(arg[0])];
9026 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9027 {
9028 s = options[opt_idx].shortname;
9029 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9030 break;
9031 s = NULL;
9032 }
9033 }
9034 if (s == NULL)
9035 opt_idx = -1;
9036 return opt_idx;
9037}
9038
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009039#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009040/*
9041 * Get the value for an option.
9042 *
9043 * Returns:
9044 * Number or Toggle option: 1, *numval gets value.
9045 * String option: 0, *stringval gets allocated string.
9046 * Hidden Number or Toggle option: -1.
9047 * hidden String option: -2.
9048 * unknown option: -3.
9049 */
9050 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009051get_option_value(
9052 char_u *name,
9053 long *numval,
9054 char_u **stringval, /* NULL when only checking existence */
9055 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009056{
9057 int opt_idx;
9058 char_u *varp;
9059
9060 opt_idx = findoption(name);
9061 if (opt_idx < 0) /* unknown option */
9062 return -3;
9063
9064 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9065
9066 if (options[opt_idx].flags & P_STRING)
9067 {
9068 if (varp == NULL) /* hidden option */
9069 return -2;
9070 if (stringval != NULL)
9071 {
9072#ifdef FEAT_CRYPT
9073 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009074 if ((char_u **)varp == &curbuf->b_p_key
9075 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009076 *stringval = vim_strsave((char_u *)"*****");
9077 else
9078#endif
9079 *stringval = vim_strsave(*(char_u **)(varp));
9080 }
9081 return 0;
9082 }
9083
9084 if (varp == NULL) /* hidden option */
9085 return -1;
9086 if (options[opt_idx].flags & P_NUM)
9087 *numval = *(long *)varp;
9088 else
9089 {
9090 /* Special case: 'modified' is b_changed, but we also want to consider
9091 * it set when 'ff' or 'fenc' changed. */
9092 if ((int *)varp == &curbuf->b_changed)
9093 *numval = curbufIsChanged();
9094 else
9095 *numval = *(int *)varp;
9096 }
9097 return 1;
9098}
9099#endif
9100
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009101#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009102/*
9103 * Returns the option attributes and its value. Unlike the above function it
9104 * will return either global value or local value of the option depending on
9105 * what was requested, but it will never return global value if it was
9106 * requested to return local one and vice versa. Neither it will return
9107 * buffer-local value if it was requested to return window-local one.
9108 *
9109 * Pretends that option is absent if it is not present in the requested scope
9110 * (i.e. has no global, window-local or buffer-local value depending on
9111 * opt_type). Uses
9112 *
9113 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009114 * 0 hidden or unknown option, also option that does not have requested
9115 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009116 * see SOPT_* in vim.h for other flags
9117 *
9118 * Possible opt_type values: see SREQ_* in vim.h
9119 */
9120 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009121get_option_value_strict(
9122 char_u *name,
9123 long *numval,
9124 char_u **stringval, /* NULL when only obtaining attributes */
9125 int opt_type,
9126 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009127{
9128 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009129 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009130 struct vimoption *p;
9131 int r = 0;
9132
9133 opt_idx = findoption(name);
9134 if (opt_idx < 0)
9135 return 0;
9136
9137 p = &(options[opt_idx]);
9138
9139 /* Hidden option */
9140 if (p->var == NULL)
9141 return 0;
9142
9143 if (p->flags & P_BOOL)
9144 r |= SOPT_BOOL;
9145 else if (p->flags & P_NUM)
9146 r |= SOPT_NUM;
9147 else if (p->flags & P_STRING)
9148 r |= SOPT_STRING;
9149
9150 if (p->indir == PV_NONE)
9151 {
9152 if (opt_type == SREQ_GLOBAL)
9153 r |= SOPT_GLOBAL;
9154 else
9155 return 0; /* Did not request global-only option */
9156 }
9157 else
9158 {
9159 if (p->indir & PV_BOTH)
9160 r |= SOPT_GLOBAL;
9161 else if (opt_type == SREQ_GLOBAL)
9162 return 0; /* Requested global option */
9163
9164 if (p->indir & PV_WIN)
9165 {
9166 if (opt_type == SREQ_BUF)
9167 return 0; /* Did not request window-local option */
9168 else
9169 r |= SOPT_WIN;
9170 }
9171 else if (p->indir & PV_BUF)
9172 {
9173 if (opt_type == SREQ_WIN)
9174 return 0; /* Did not request buffer-local option */
9175 else
9176 r |= SOPT_BUF;
9177 }
9178 }
9179
9180 if (stringval == NULL)
9181 return r;
9182
9183 if (opt_type == SREQ_GLOBAL)
9184 varp = p->var;
9185 else
9186 {
9187 if (opt_type == SREQ_BUF)
9188 {
9189 /* Special case: 'modified' is b_changed, but we also want to
9190 * consider it set when 'ff' or 'fenc' changed. */
9191 if (p->indir == PV_MOD)
9192 {
9193 *numval = bufIsChanged((buf_T *) from);
9194 varp = NULL;
9195 }
9196#ifdef FEAT_CRYPT
9197 else if (p->indir == PV_KEY)
9198 {
9199 /* never return the value of the crypt key */
9200 *stringval = NULL;
9201 varp = NULL;
9202 }
9203#endif
9204 else
9205 {
9206 aco_save_T aco;
9207 aucmd_prepbuf(&aco, (buf_T *) from);
9208 varp = get_varp(p);
9209 aucmd_restbuf(&aco);
9210 }
9211 }
9212 else if (opt_type == SREQ_WIN)
9213 {
9214 win_T *save_curwin;
9215 save_curwin = curwin;
9216 curwin = (win_T *) from;
9217 curbuf = curwin->w_buffer;
9218 varp = get_varp(p);
9219 curwin = save_curwin;
9220 curbuf = curwin->w_buffer;
9221 }
9222 if (varp == p->var)
9223 return (r | SOPT_UNSET);
9224 }
9225
9226 if (varp != NULL)
9227 {
9228 if (p->flags & P_STRING)
9229 *stringval = vim_strsave(*(char_u **)(varp));
9230 else if (p->flags & P_NUM)
9231 *numval = *(long *) varp;
9232 else
9233 *numval = *(int *)varp;
9234 }
9235
9236 return r;
9237}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009238
9239/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009240 * Iterate over options. First argument is a pointer to a pointer to a
9241 * structure inside options[] array, second is option type like in the above
9242 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009243 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009244 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009245 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009246 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009247 * first argument to NULL.
9248 *
9249 * Returns full option name for current option on each call.
9250 */
9251 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009252option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009253{
9254 struct vimoption *ret = NULL;
9255 do
9256 {
9257 if (*option == NULL)
9258 *option = (void *) options;
9259 else if (((struct vimoption *) (*option))->fullname == NULL)
9260 {
9261 *option = NULL;
9262 return NULL;
9263 }
9264 else
9265 *option = (void *) (((struct vimoption *) (*option)) + 1);
9266
9267 ret = ((struct vimoption *) (*option));
9268
9269 /* Hidden option */
9270 if (ret->var == NULL)
9271 {
9272 ret = NULL;
9273 continue;
9274 }
9275
9276 switch (opt_type)
9277 {
9278 case SREQ_GLOBAL:
9279 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9280 ret = NULL;
9281 break;
9282 case SREQ_BUF:
9283 if (!(ret->indir & PV_BUF))
9284 ret = NULL;
9285 break;
9286 case SREQ_WIN:
9287 if (!(ret->indir & PV_WIN))
9288 ret = NULL;
9289 break;
9290 default:
9291 EMSG2(_(e_intern2), "option_iter_next()");
9292 return NULL;
9293 }
9294 }
9295 while (ret == NULL);
9296
9297 return (char_u *)ret->fullname;
9298}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009299#endif
9300
Bram Moolenaar071d4272004-06-13 20:20:40 +00009301/*
9302 * Set the value of option "name".
9303 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009304 *
9305 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009307 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009308set_option_value(
9309 char_u *name,
9310 long number,
9311 char_u *string,
9312 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009313{
9314 int opt_idx;
9315 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009316 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009317
9318 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009319 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009320 EMSG2(_("E355: Unknown option: %s"), name);
9321 else
9322 {
9323 flags = options[opt_idx].flags;
9324#ifdef HAVE_SANDBOX
9325 /* Disallow changing some options in the sandbox */
9326 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009327 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009328 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009329 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009330 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009331#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009332 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009333 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009334 else
9335 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009336 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009337 if (varp != NULL) /* hidden option is not changed */
9338 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009339 if (number == 0 && string != NULL)
9340 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009341 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009342
9343 /* Either we are given a string or we are setting option
9344 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009345 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009346 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009347 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009348 {
9349 /* There's another character after zeros or the string
9350 * is empty. In both cases, we are trying to set a
9351 * num option using a string. */
9352 EMSG3(_("E521: Number required: &%s = '%s'"),
9353 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009354 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009355
9356 }
9357 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009358 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009359 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009360 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009362 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009363 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364 }
9365 }
9366 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009367 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009368}
9369
9370/*
9371 * Get the terminal code for a terminal option.
9372 * Returns NULL when not found.
9373 */
9374 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009375get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009376{
9377 int opt_idx;
9378 char_u *varp;
9379
9380 if (tname[0] != 't' || tname[1] != '_' ||
9381 tname[2] == NUL || tname[3] == NUL)
9382 return NULL;
9383 if ((opt_idx = findoption(tname)) >= 0)
9384 {
9385 varp = get_varp(&(options[opt_idx]));
9386 if (varp != NULL)
9387 varp = *(char_u **)(varp);
9388 return varp;
9389 }
9390 return find_termcode(tname + 2);
9391}
9392
9393 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009394get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009395{
9396 int i;
9397
9398 i = findoption((char_u *)"hl");
9399 if (i >= 0)
9400 return options[i].def_val[VI_DEFAULT];
9401 return (char_u *)NULL;
9402}
9403
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009404#if defined(FEAT_MBYTE) || defined(PROTO)
9405 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009406get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009407{
9408 int i;
9409
9410 i = findoption((char_u *)"enc");
9411 if (i >= 0)
9412 return options[i].def_val[VI_DEFAULT];
9413 return (char_u *)NULL;
9414}
9415#endif
9416
Bram Moolenaar071d4272004-06-13 20:20:40 +00009417/*
9418 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9419 */
9420 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009421find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009422{
9423 int key;
9424 int modifiers;
9425
9426 /*
9427 * Don't use get_special_key_code() for t_xx, we don't want it to call
9428 * add_termcap_entry().
9429 */
9430 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9431 key = TERMCAP2KEY(arg[2], arg[3]);
9432 else
9433 {
9434 --arg; /* put arg at the '<' */
9435 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009436 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009437 if (modifiers) /* can't handle modifiers here */
9438 key = 0;
9439 }
9440 return key;
9441}
9442
9443/*
9444 * if 'all' == 0: show changed options
9445 * if 'all' == 1: show all normal options
9446 * if 'all' == 2: show all terminal options
9447 */
9448 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009449showoptions(
9450 int all,
9451 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009452{
9453 struct vimoption *p;
9454 int col;
9455 int isterm;
9456 char_u *varp;
9457 struct vimoption **items;
9458 int item_count;
9459 int run;
9460 int row, rows;
9461 int cols;
9462 int i;
9463 int len;
9464
9465#define INC 20
9466#define GAP 3
9467
9468 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9469 PARAM_COUNT));
9470 if (items == NULL)
9471 return;
9472
9473 /* Highlight title */
9474 if (all == 2)
9475 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9476 else if (opt_flags & OPT_GLOBAL)
9477 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9478 else if (opt_flags & OPT_LOCAL)
9479 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9480 else
9481 MSG_PUTS_TITLE(_("\n--- Options ---"));
9482
9483 /*
9484 * do the loop two times:
9485 * 1. display the short items
9486 * 2. display the long items (only strings and numbers)
9487 */
9488 for (run = 1; run <= 2 && !got_int; ++run)
9489 {
9490 /*
9491 * collect the items in items[]
9492 */
9493 item_count = 0;
9494 for (p = &options[0]; p->fullname != NULL; p++)
9495 {
9496 varp = NULL;
9497 isterm = istermoption(p);
9498 if (opt_flags != 0)
9499 {
9500 if (p->indir != PV_NONE && !isterm)
9501 varp = get_varp_scope(p, opt_flags);
9502 }
9503 else
9504 varp = get_varp(p);
9505 if (varp != NULL
9506 && ((all == 2 && isterm)
9507 || (all == 1 && !isterm)
9508 || (all == 0 && !optval_default(p, varp))))
9509 {
9510 if (p->flags & P_BOOL)
9511 len = 1; /* a toggle option fits always */
9512 else
9513 {
9514 option_value2string(p, opt_flags);
9515 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9516 }
9517 if ((len <= INC - GAP && run == 1) ||
9518 (len > INC - GAP && run == 2))
9519 items[item_count++] = p;
9520 }
9521 }
9522
9523 /*
9524 * display the items
9525 */
9526 if (run == 1)
9527 {
9528 cols = (Columns + GAP - 3) / INC;
9529 if (cols == 0)
9530 cols = 1;
9531 rows = (item_count + cols - 1) / cols;
9532 }
9533 else /* run == 2 */
9534 rows = item_count;
9535 for (row = 0; row < rows && !got_int; ++row)
9536 {
9537 msg_putchar('\n'); /* go to next line */
9538 if (got_int) /* 'q' typed in more */
9539 break;
9540 col = 0;
9541 for (i = row; i < item_count; i += rows)
9542 {
9543 msg_col = col; /* make columns */
9544 showoneopt(items[i], opt_flags);
9545 col += INC;
9546 }
9547 out_flush();
9548 ui_breakcheck();
9549 }
9550 }
9551 vim_free(items);
9552}
9553
9554/*
9555 * Return TRUE if option "p" has its default value.
9556 */
9557 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009558optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009559{
9560 int dvi;
9561
9562 if (varp == NULL)
9563 return TRUE; /* hidden option is always at default */
9564 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9565 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009566 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009567 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009568 /* the cast to long is required for Manx C, long_i is
9569 * needed for MSVC */
9570 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009571 /* P_STRING */
9572 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9573}
9574
9575/*
9576 * showoneopt: show the value of one option
9577 * must not be called with a hidden option!
9578 */
9579 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009580showoneopt(
9581 struct vimoption *p,
9582 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009583{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009584 char_u *varp;
9585 int save_silent = silent_mode;
9586
9587 silent_mode = FALSE;
9588 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009589
9590 varp = get_varp_scope(p, opt_flags);
9591
9592 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9593 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9594 ? !curbufIsChanged() : !*(int *)varp))
9595 MSG_PUTS("no");
9596 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9597 MSG_PUTS("--");
9598 else
9599 MSG_PUTS(" ");
9600 MSG_PUTS(p->fullname);
9601 if (!(p->flags & P_BOOL))
9602 {
9603 msg_putchar('=');
9604 /* put value string in NameBuff */
9605 option_value2string(p, opt_flags);
9606 msg_outtrans(NameBuff);
9607 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009608
9609 silent_mode = save_silent;
9610 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009611}
9612
9613/*
9614 * Write modified options as ":set" commands to a file.
9615 *
9616 * There are three values for "opt_flags":
9617 * OPT_GLOBAL: Write global option values and fresh values of
9618 * buffer-local options (used for start of a session
9619 * file).
9620 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9621 * curwin (used for a vimrc file).
9622 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9623 * and local values for window-local options of
9624 * curwin. Local values are also written when at the
9625 * default value, because a modeline or autocommand
9626 * may have set them when doing ":edit file" and the
9627 * user has set them back at the default or fresh
9628 * value.
9629 * When "local_only" is TRUE, don't write fresh
9630 * values, only local values (for ":mkview").
9631 * (fresh value = value used for a new buffer or window for a local option).
9632 *
9633 * Return FAIL on error, OK otherwise.
9634 */
9635 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009636makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009637{
9638 struct vimoption *p;
9639 char_u *varp; /* currently used value */
9640 char_u *varp_fresh; /* local value */
9641 char_u *varp_local = NULL; /* fresh value */
9642 char *cmd;
9643 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009644 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645
9646 /*
9647 * The options that don't have a default (terminal name, columns, lines)
9648 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009649 * Do the loop over "options[]" twice: once for options with the
9650 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009651 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009652 for (pri = 1; pri >= 0; --pri)
9653 {
9654 for (p = &options[0]; !istermoption(p); p++)
9655 if (!(p->flags & P_NO_MKRC)
9656 && !istermoption(p)
9657 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009658 {
9659 /* skip global option when only doing locals */
9660 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9661 continue;
9662
9663 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9664 * file, they are always buffer-specific. */
9665 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9666 continue;
9667
9668 /* Global values are only written when not at the default value. */
9669 varp = get_varp_scope(p, opt_flags);
9670 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9671 continue;
9672
9673 round = 2;
9674 if (p->indir != PV_NONE)
9675 {
9676 if (p->var == VAR_WIN)
9677 {
9678 /* skip window-local option when only doing globals */
9679 if (!(opt_flags & OPT_LOCAL))
9680 continue;
9681 /* When fresh value of window-local option is not at the
9682 * default, need to write it too. */
9683 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9684 {
9685 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9686 if (!optval_default(p, varp_fresh))
9687 {
9688 round = 1;
9689 varp_local = varp;
9690 varp = varp_fresh;
9691 }
9692 }
9693 }
9694 }
9695
9696 /* Round 1: fresh value for window-local options.
9697 * Round 2: other values */
9698 for ( ; round <= 2; varp = varp_local, ++round)
9699 {
9700 if (round == 1 || (opt_flags & OPT_GLOBAL))
9701 cmd = "set";
9702 else
9703 cmd = "setlocal";
9704
9705 if (p->flags & P_BOOL)
9706 {
9707 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9708 return FAIL;
9709 }
9710 else if (p->flags & P_NUM)
9711 {
9712 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9713 return FAIL;
9714 }
9715 else /* P_STRING */
9716 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009717#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9718 int do_endif = FALSE;
9719
Bram Moolenaar071d4272004-06-13 20:20:40 +00009720 /* Don't set 'syntax' and 'filetype' again if the value is
9721 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009722 if (
9723# if defined(FEAT_SYN_HL)
9724 p->indir == PV_SYN
9725# if defined(FEAT_AUTOCMD)
9726 ||
9727# endif
9728# endif
9729# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009730 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009731# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009732 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009733 {
9734 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9735 *(char_u **)(varp)) < 0
9736 || put_eol(fd) < 0)
9737 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009738 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009739 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009740#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009741 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9742 (p->flags & P_EXPAND) != 0) == FAIL)
9743 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009744#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9745 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009746 {
9747 if (put_line(fd, "endif") == FAIL)
9748 return FAIL;
9749 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009750#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009751 }
9752 }
9753 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009754 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009755 return OK;
9756}
9757
9758#if defined(FEAT_FOLDING) || defined(PROTO)
9759/*
9760 * Generate set commands for the local fold options only. Used when
9761 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9762 */
9763 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009764makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009765{
9766 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9767# ifdef FEAT_EVAL
9768 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9769 == FAIL
9770# endif
9771 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9772 == FAIL
9773 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9774 == FAIL
9775 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9776 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9777 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9778 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9779 )
9780 return FAIL;
9781
9782 return OK;
9783}
9784#endif
9785
9786 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009787put_setstring(
9788 FILE *fd,
9789 char *cmd,
9790 char *name,
9791 char_u **valuep,
9792 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009793{
9794 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009795 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009796
9797 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9798 return FAIL;
9799 if (*valuep != NULL)
9800 {
9801 /* Output 'pastetoggle' as key names. For other
9802 * options some characters have to be escaped with
9803 * CTRL-V or backslash */
9804 if (valuep == &p_pt)
9805 {
9806 s = *valuep;
9807 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009808 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009809 return FAIL;
9810 }
9811 else if (expand)
9812 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009813 buf = alloc(MAXPATHL);
9814 if (buf == NULL)
9815 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009816 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9817 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009818 {
9819 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009820 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009821 }
9822 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009823 }
9824 else if (put_escstr(fd, *valuep, 2) == FAIL)
9825 return FAIL;
9826 }
9827 if (put_eol(fd) < 0)
9828 return FAIL;
9829 return OK;
9830}
9831
9832 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009833put_setnum(
9834 FILE *fd,
9835 char *cmd,
9836 char *name,
9837 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009838{
9839 long wc;
9840
9841 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9842 return FAIL;
9843 if (wc_use_keyname((char_u *)valuep, &wc))
9844 {
9845 /* print 'wildchar' and 'wildcharm' as a key name */
9846 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9847 return FAIL;
9848 }
9849 else if (fprintf(fd, "%ld", *valuep) < 0)
9850 return FAIL;
9851 if (put_eol(fd) < 0)
9852 return FAIL;
9853 return OK;
9854}
9855
9856 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009857put_setbool(
9858 FILE *fd,
9859 char *cmd,
9860 char *name,
9861 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009862{
Bram Moolenaar893de922007-10-02 18:40:57 +00009863 if (value < 0) /* global/local option using global value */
9864 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9866 || put_eol(fd) < 0)
9867 return FAIL;
9868 return OK;
9869}
9870
9871/*
9872 * Clear all the terminal options.
9873 * If the option has been allocated, free the memory.
9874 * Terminal options are never hidden or indirect.
9875 */
9876 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009877clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009878{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009879 /*
9880 * Reset a few things before clearing the old options. This may cause
9881 * outputting a few things that the terminal doesn't understand, but the
9882 * screen will be cleared later, so this is OK.
9883 */
9884#ifdef FEAT_MOUSE_TTY
9885 mch_setmouse(FALSE); /* switch mouse off */
9886#endif
9887#ifdef FEAT_TITLE
9888 mch_restore_title(3); /* restore window titles */
9889#endif
9890#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9891 /* When starting the GUI close the display opened for the clipboard.
9892 * After restoring the title, because that will need the display. */
9893 if (gui.starting)
9894 clear_xterm_clip();
9895#endif
9896#ifdef WIN3264
9897 /*
9898 * Check if this is allowed now.
9899 */
9900 if (can_end_termcap_mode(FALSE) == TRUE)
9901#endif
9902 stoptermcap(); /* stop termcap mode */
9903
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009904 free_termoptions();
9905}
9906
9907 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009908free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009909{
9910 struct vimoption *p;
9911
Bram Moolenaar071d4272004-06-13 20:20:40 +00009912 for (p = &options[0]; p->fullname != NULL; p++)
9913 if (istermoption(p))
9914 {
9915 if (p->flags & P_ALLOCED)
9916 free_string_option(*(char_u **)(p->var));
9917 if (p->flags & P_DEF_ALLOCED)
9918 free_string_option(p->def_val[VI_DEFAULT]);
9919 *(char_u **)(p->var) = empty_option;
9920 p->def_val[VI_DEFAULT] = empty_option;
9921 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9922 }
9923 clear_termcodes();
9924}
9925
9926/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009927 * Free the string for one term option, if it was allocated.
9928 * Set the string to empty_option and clear allocated flag.
9929 * "var" points to the option value.
9930 */
9931 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009932free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009933{
9934 struct vimoption *p;
9935
9936 for (p = &options[0]; p->fullname != NULL; p++)
9937 if (p->var == var)
9938 {
9939 if (p->flags & P_ALLOCED)
9940 free_string_option(*(char_u **)(p->var));
9941 *(char_u **)(p->var) = empty_option;
9942 p->flags &= ~P_ALLOCED;
9943 break;
9944 }
9945}
9946
9947/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009948 * Set the terminal option defaults to the current value.
9949 * Used after setting the terminal name.
9950 */
9951 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009952set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009953{
9954 struct vimoption *p;
9955
9956 for (p = &options[0]; p->fullname != NULL; p++)
9957 {
9958 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9959 {
9960 if (p->flags & P_DEF_ALLOCED)
9961 {
9962 free_string_option(p->def_val[VI_DEFAULT]);
9963 p->flags &= ~P_DEF_ALLOCED;
9964 }
9965 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9966 if (p->flags & P_ALLOCED)
9967 {
9968 p->flags |= P_DEF_ALLOCED;
9969 p->flags &= ~P_ALLOCED; /* don't free the value now */
9970 }
9971 }
9972 }
9973}
9974
9975/*
9976 * return TRUE if 'p' starts with 't_'
9977 */
9978 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009979istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009980{
9981 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9982}
9983
9984/*
9985 * Compute columns for ruler and shown command. 'sc_col' is also used to
9986 * decide what the maximum length of a message on the status line can be.
9987 * If there is a status line for the last window, 'sc_col' is independent
9988 * of 'ru_col'.
9989 */
9990
9991#define COL_RULER 17 /* columns needed by standard ruler */
9992
9993 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009994comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009995{
9996#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9997 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9998
9999 sc_col = 0;
10000 ru_col = 0;
10001 if (p_ru)
10002 {
10003#ifdef FEAT_STL_OPT
10004 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10005#else
10006 ru_col = COL_RULER + 1;
10007#endif
10008 /* no last status line, adjust sc_col */
10009 if (!last_has_status)
10010 sc_col = ru_col;
10011 }
10012 if (p_sc)
10013 {
10014 sc_col += SHOWCMD_COLS;
10015 if (!p_ru || last_has_status) /* no need for separating space */
10016 ++sc_col;
10017 }
10018 sc_col = Columns - sc_col;
10019 ru_col = Columns - ru_col;
10020 if (sc_col <= 0) /* screen too narrow, will become a mess */
10021 sc_col = 1;
10022 if (ru_col <= 0)
10023 ru_col = 1;
10024#else
10025 sc_col = Columns;
10026 ru_col = Columns;
10027#endif
10028}
10029
10030/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010031 * Unset local option value, similar to ":set opt<".
10032 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010033 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010034unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010035{
10036 struct vimoption *p;
10037 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010038 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010039
10040 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010041 if (opt_idx < 0)
10042 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010043 p = &(options[opt_idx]);
10044
10045 switch ((int)p->indir)
10046 {
10047 /* global option with local value: use local value if it's been set */
10048 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010049 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010050 break;
10051 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010052 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010053 break;
10054 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010055 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010056 break;
10057 case PV_AR:
10058 buf->b_p_ar = -1;
10059 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010060 case PV_BKC:
10061 clear_string_option(&buf->b_p_bkc);
10062 buf->b_bkc_flags = 0;
10063 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010064 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010065 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010066 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010067 case PV_TC:
10068 clear_string_option(&buf->b_p_tc);
10069 buf->b_tc_flags = 0;
10070 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010071#ifdef FEAT_FIND_ID
10072 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010073 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010074 break;
10075 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010076 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010077 break;
10078#endif
10079#ifdef FEAT_INS_EXPAND
10080 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010081 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010082 break;
10083 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010084 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010085 break;
10086#endif
10087#ifdef FEAT_QUICKFIX
10088 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010089 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010090 break;
10091 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010092 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010093 break;
10094 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010095 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010096 break;
10097#endif
10098#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10099 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010100 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010101 break;
10102#endif
10103#if defined(FEAT_CRYPT)
10104 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010105 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010106 break;
10107#endif
10108#ifdef FEAT_STL_OPT
10109 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010110 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010111 break;
10112#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010113 case PV_UL:
10114 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10115 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010116#ifdef FEAT_LISP
10117 case PV_LW:
10118 clear_string_option(&buf->b_p_lw);
10119 break;
10120#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010121 }
10122}
10123
10124/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125 * Get pointer to option variable, depending on local or global scope.
10126 */
10127 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010128get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129{
10130 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10131 {
10132 if (p->var == VAR_WIN)
10133 return (char_u *)GLOBAL_WO(get_varp(p));
10134 return p->var;
10135 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010136 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010137 {
10138 switch ((int)p->indir)
10139 {
10140#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010141 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10142 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10143 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010145 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10146 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10147 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010148 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010149 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010150 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010152 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10153 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154#endif
10155#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010156 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10157 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010158#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010159#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10160 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10161#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010162#if defined(FEAT_CRYPT)
10163 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10164#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010165#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010166 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010167#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010168 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010169#ifdef FEAT_LISP
10170 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10171#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010172 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010173 }
10174 return NULL; /* "cannot happen" */
10175 }
10176 return get_varp(p);
10177}
10178
10179/*
10180 * Get pointer to option variable.
10181 */
10182 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010183get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184{
10185 /* hidden option, always return NULL */
10186 if (p->var == NULL)
10187 return NULL;
10188
10189 switch ((int)p->indir)
10190 {
10191 case PV_NONE: return p->var;
10192
10193 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010194 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010196 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010198 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010200 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010201 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010202 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010204 case PV_TC: return *curbuf->b_p_tc != NUL
10205 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010206 case PV_BKC: return *curbuf->b_p_bkc != NUL
10207 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010208#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010209 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010210 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010211 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010212 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10213#endif
10214#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010215 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010216 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010217 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10219#endif
10220#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010221 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010222 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010223 case PV_GP: return *curbuf->b_p_gp != NUL
10224 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10225 case PV_MP: return *curbuf->b_p_mp != NUL
10226 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010228#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10229 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10230 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10231#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010232#if defined(FEAT_CRYPT)
10233 case PV_CM: return *curbuf->b_p_cm != NUL
10234 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10235#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010236#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010237 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010238 ? (char_u *)&(curwin->w_p_stl) : p->var;
10239#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010240 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10241 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010242#ifdef FEAT_LISP
10243 case PV_LW: return *curbuf->b_p_lw != NUL
10244 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10245#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246
10247#ifdef FEAT_ARABIC
10248 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10249#endif
10250 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010251#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010252 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10253#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010254#ifdef FEAT_SYN_HL
10255 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10256 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010257 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010258#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259#ifdef FEAT_DIFF
10260 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10261#endif
10262#ifdef FEAT_FOLDING
10263 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10264 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10265 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10266 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10267 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10268 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10269 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10270# ifdef FEAT_EVAL
10271 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10272 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10273# endif
10274 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10275#endif
10276 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010277 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010278#ifdef FEAT_LINEBREAK
10279 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10280#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010281#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010282 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10283#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010284#ifdef FEAT_VERTSPLIT
10285 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10286#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010287#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10288 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10289#endif
10290#ifdef FEAT_RIGHTLEFT
10291 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10292 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10293#endif
10294 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10295 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10296#ifdef FEAT_LINEBREAK
10297 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010298 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10299 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300#endif
10301#ifdef FEAT_SCROLLBIND
10302 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10303#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010304#ifdef FEAT_CURSORBIND
10305 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10306#endif
10307#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010308 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10309 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010310#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311
10312 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10313 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10314#ifdef FEAT_MBYTE
10315 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10316#endif
10317#if defined(FEAT_QUICKFIX)
10318 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10319 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10320#endif
10321 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10322 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10323#ifdef FEAT_CINDENT
10324 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10325 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10326 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10327#endif
10328#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10329 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10330#endif
10331#ifdef FEAT_COMMENTS
10332 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10333#endif
10334#ifdef FEAT_FOLDING
10335 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10336#endif
10337#ifdef FEAT_INS_EXPAND
10338 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10339#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010340#ifdef FEAT_COMPL_FUNC
10341 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010342 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010345 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010346 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10347#ifdef FEAT_MBYTE
10348 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10349#endif
10350 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10351#ifdef FEAT_AUTOCMD
10352 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10353#endif
10354 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010355 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10357 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10358 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10359 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10360#ifdef FEAT_FIND_ID
10361# ifdef FEAT_EVAL
10362 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10363# endif
10364#endif
10365#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10366 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10367 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10368#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010369#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010370 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010372#ifdef FEAT_CRYPT
10373 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10374#endif
10375#ifdef FEAT_LISP
10376 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10377#endif
10378 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10379 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10380 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10381 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10382 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010384#ifdef FEAT_TEXTOBJ
10385 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010387 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10388#ifdef FEAT_SMARTINDENT
10389 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10390#endif
10391#ifndef SHORT_FNAME
10392 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10393#endif
10394 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10395#ifdef FEAT_SEARCHPATH
10396 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10397#endif
10398 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10399#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010400 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010401 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10402#endif
10403#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010404 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10405 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10406 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407#endif
10408 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10409 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10410 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10411 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010412#ifdef FEAT_PERSISTENT_UNDO
10413 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10414#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10416#ifdef FEAT_KEYMAP
10417 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10418#endif
10419 default: EMSG(_("E356: get_varp ERROR"));
10420 }
10421 /* always return a valid pointer to avoid a crash! */
10422 return (char_u *)&(curbuf->b_p_wm);
10423}
10424
10425/*
10426 * Get the value of 'equalprg', either the buffer-local one or the global one.
10427 */
10428 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010429get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010430{
10431 if (*curbuf->b_p_ep == NUL)
10432 return p_ep;
10433 return curbuf->b_p_ep;
10434}
10435
10436#if defined(FEAT_WINDOWS) || defined(PROTO)
10437/*
10438 * Copy options from one window to another.
10439 * Used when splitting a window.
10440 */
10441 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010442win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010443{
10444 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10445 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10446# ifdef FEAT_RIGHTLEFT
10447# ifdef FEAT_FKMAP
10448 /* Is this right? */
10449 wp_to->w_farsi = wp_from->w_farsi;
10450# endif
10451# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010452#if defined(FEAT_LINEBREAK)
10453 briopt_check(wp_to);
10454#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010455}
10456#endif
10457
10458/*
10459 * Copy the options from one winopt_T to another.
10460 * Doesn't free the old option values in "to", use clear_winopt() for that.
10461 * The 'scroll' option is not copied, because it depends on the window height.
10462 * The 'previewwindow' option is reset, there can be only one preview window.
10463 */
10464 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010465copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010466{
10467#ifdef FEAT_ARABIC
10468 to->wo_arab = from->wo_arab;
10469#endif
10470 to->wo_list = from->wo_list;
10471 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010472 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010473#ifdef FEAT_LINEBREAK
10474 to->wo_nuw = from->wo_nuw;
10475#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010476#ifdef FEAT_RIGHTLEFT
10477 to->wo_rl = from->wo_rl;
10478 to->wo_rlc = vim_strsave(from->wo_rlc);
10479#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010480#ifdef FEAT_STL_OPT
10481 to->wo_stl = vim_strsave(from->wo_stl);
10482#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010483 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010484#ifdef FEAT_DIFF
10485 to->wo_wrap_save = from->wo_wrap_save;
10486#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487#ifdef FEAT_LINEBREAK
10488 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010489 to->wo_bri = from->wo_bri;
10490 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010491#endif
10492#ifdef FEAT_SCROLLBIND
10493 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010494 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010495#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010496#ifdef FEAT_CURSORBIND
10497 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010498 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010499#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010500#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010501 to->wo_spell = from->wo_spell;
10502#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010503#ifdef FEAT_SYN_HL
10504 to->wo_cuc = from->wo_cuc;
10505 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010506 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010507#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010508#ifdef FEAT_DIFF
10509 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010510 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010512#ifdef FEAT_CONCEAL
10513 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010514 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010515#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516#ifdef FEAT_FOLDING
10517 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010518 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010519 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010520 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521 to->wo_fdi = vim_strsave(from->wo_fdi);
10522 to->wo_fml = from->wo_fml;
10523 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010524 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010525 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010526 to->wo_fdm_save = from->wo_diff_saved
10527 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528 to->wo_fdn = from->wo_fdn;
10529# ifdef FEAT_EVAL
10530 to->wo_fde = vim_strsave(from->wo_fde);
10531 to->wo_fdt = vim_strsave(from->wo_fdt);
10532# endif
10533 to->wo_fmr = vim_strsave(from->wo_fmr);
10534#endif
10535 check_winopt(to); /* don't want NULL pointers */
10536}
10537
10538/*
10539 * Check string options in a window for a NULL value.
10540 */
10541 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010542check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543{
10544 check_winopt(&win->w_onebuf_opt);
10545 check_winopt(&win->w_allbuf_opt);
10546}
10547
10548/*
10549 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10550 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010551 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010552check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553{
10554#ifdef FEAT_FOLDING
10555 check_string_option(&wop->wo_fdi);
10556 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010557 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010558# ifdef FEAT_EVAL
10559 check_string_option(&wop->wo_fde);
10560 check_string_option(&wop->wo_fdt);
10561# endif
10562 check_string_option(&wop->wo_fmr);
10563#endif
10564#ifdef FEAT_RIGHTLEFT
10565 check_string_option(&wop->wo_rlc);
10566#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010567#ifdef FEAT_STL_OPT
10568 check_string_option(&wop->wo_stl);
10569#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010570#ifdef FEAT_SYN_HL
10571 check_string_option(&wop->wo_cc);
10572#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010573#ifdef FEAT_CONCEAL
10574 check_string_option(&wop->wo_cocu);
10575#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010576#ifdef FEAT_LINEBREAK
10577 check_string_option(&wop->wo_briopt);
10578#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579}
10580
10581/*
10582 * Free the allocated memory inside a winopt_T.
10583 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010585clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010586{
10587#ifdef FEAT_FOLDING
10588 clear_string_option(&wop->wo_fdi);
10589 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010590 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591# ifdef FEAT_EVAL
10592 clear_string_option(&wop->wo_fde);
10593 clear_string_option(&wop->wo_fdt);
10594# endif
10595 clear_string_option(&wop->wo_fmr);
10596#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010597#ifdef FEAT_LINEBREAK
10598 clear_string_option(&wop->wo_briopt);
10599#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600#ifdef FEAT_RIGHTLEFT
10601 clear_string_option(&wop->wo_rlc);
10602#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010603#ifdef FEAT_STL_OPT
10604 clear_string_option(&wop->wo_stl);
10605#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010606#ifdef FEAT_SYN_HL
10607 clear_string_option(&wop->wo_cc);
10608#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010609#ifdef FEAT_CONCEAL
10610 clear_string_option(&wop->wo_cocu);
10611#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612}
10613
10614/*
10615 * Copy global option values to local options for one buffer.
10616 * Used when creating a new buffer and sometimes when entering a buffer.
10617 * flags:
10618 * BCO_ENTER We will enter the buf buffer.
10619 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10620 * appropriate.
10621 * BCO_NOHELP Don't copy the values to a help buffer.
10622 */
10623 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010624buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625{
10626 int should_copy = TRUE;
10627 char_u *save_p_isk = NULL; /* init for GCC */
10628 int dont_do_help;
10629 int did_isk = FALSE;
10630
10631 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010632 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010633 */
10634 if (buf == NULL || !buf_valid(buf))
10635 return;
10636
10637 /*
10638 * Skip this when the option defaults have not been set yet. Happens when
10639 * main() allocates the first buffer.
10640 */
10641 if (p_cpo != NULL)
10642 {
10643 /*
10644 * Always copy when entering and 'cpo' contains 'S'.
10645 * Don't copy when already initialized.
10646 * Don't copy when 'cpo' contains 's' and not entering.
10647 * 'S' BCO_ENTER initialized 's' should_copy
10648 * yes yes X X TRUE
10649 * yes no yes X FALSE
10650 * no X yes X FALSE
10651 * X no no yes FALSE
10652 * X no no no TRUE
10653 * no yes no X TRUE
10654 */
10655 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10656 && (buf->b_p_initialized
10657 || (!(flags & BCO_ENTER)
10658 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10659 should_copy = FALSE;
10660
10661 if (should_copy || (flags & BCO_ALWAYS))
10662 {
10663 /* Don't copy the options specific to a help buffer when
10664 * BCO_NOHELP is given or the options were initialized already
10665 * (jumping back to a help file with CTRL-T or CTRL-O) */
10666 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10667 || buf->b_p_initialized;
10668 if (dont_do_help) /* don't free b_p_isk */
10669 {
10670 save_p_isk = buf->b_p_isk;
10671 buf->b_p_isk = NULL;
10672 }
10673 /*
10674 * Always free the allocated strings.
10675 * If not already initialized, set 'readonly' and copy 'fileformat'.
10676 */
10677 if (!buf->b_p_initialized)
10678 {
10679 free_buf_options(buf, TRUE);
10680 buf->b_p_ro = FALSE; /* don't copy readonly */
10681 buf->b_p_tx = p_tx;
10682#ifdef FEAT_MBYTE
10683 buf->b_p_fenc = vim_strsave(p_fenc);
10684#endif
10685 buf->b_p_ff = vim_strsave(p_ff);
10686#if defined(FEAT_QUICKFIX)
10687 buf->b_p_bh = empty_option;
10688 buf->b_p_bt = empty_option;
10689#endif
10690 }
10691 else
10692 free_buf_options(buf, FALSE);
10693
10694 buf->b_p_ai = p_ai;
10695 buf->b_p_ai_nopaste = p_ai_nopaste;
10696 buf->b_p_sw = p_sw;
10697 buf->b_p_tw = p_tw;
10698 buf->b_p_tw_nopaste = p_tw_nopaste;
10699 buf->b_p_tw_nobin = p_tw_nobin;
10700 buf->b_p_wm = p_wm;
10701 buf->b_p_wm_nopaste = p_wm_nopaste;
10702 buf->b_p_wm_nobin = p_wm_nobin;
10703 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010704#ifdef FEAT_MBYTE
10705 buf->b_p_bomb = p_bomb;
10706#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010707 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010708 buf->b_p_et = p_et;
10709 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010710 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711 buf->b_p_ml = p_ml;
10712 buf->b_p_ml_nobin = p_ml_nobin;
10713 buf->b_p_inf = p_inf;
10714 buf->b_p_swf = p_swf;
10715#ifdef FEAT_INS_EXPAND
10716 buf->b_p_cpt = vim_strsave(p_cpt);
10717#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010718#ifdef FEAT_COMPL_FUNC
10719 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010720 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010721#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010722 buf->b_p_sts = p_sts;
10723 buf->b_p_sts_nopaste = p_sts_nopaste;
10724#ifndef SHORT_FNAME
10725 buf->b_p_sn = p_sn;
10726#endif
10727#ifdef FEAT_COMMENTS
10728 buf->b_p_com = vim_strsave(p_com);
10729#endif
10730#ifdef FEAT_FOLDING
10731 buf->b_p_cms = vim_strsave(p_cms);
10732#endif
10733 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010734 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 buf->b_p_nf = vim_strsave(p_nf);
10736 buf->b_p_mps = vim_strsave(p_mps);
10737#ifdef FEAT_SMARTINDENT
10738 buf->b_p_si = p_si;
10739#endif
10740 buf->b_p_ci = p_ci;
10741#ifdef FEAT_CINDENT
10742 buf->b_p_cin = p_cin;
10743 buf->b_p_cink = vim_strsave(p_cink);
10744 buf->b_p_cino = vim_strsave(p_cino);
10745#endif
10746#ifdef FEAT_AUTOCMD
10747 /* Don't copy 'filetype', it must be detected */
10748 buf->b_p_ft = empty_option;
10749#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750 buf->b_p_pi = p_pi;
10751#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10752 buf->b_p_cinw = vim_strsave(p_cinw);
10753#endif
10754#ifdef FEAT_LISP
10755 buf->b_p_lisp = p_lisp;
10756#endif
10757#ifdef FEAT_SYN_HL
10758 /* Don't copy 'syntax', it must be set */
10759 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010760 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010761 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010762#endif
10763#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010764 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010765 (void)compile_cap_prog(&buf->b_s);
10766 buf->b_s.b_p_spf = vim_strsave(p_spf);
10767 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768#endif
10769#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10770 buf->b_p_inde = vim_strsave(p_inde);
10771 buf->b_p_indk = vim_strsave(p_indk);
10772#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010773#if defined(FEAT_EVAL)
10774 buf->b_p_fex = vim_strsave(p_fex);
10775#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010776#ifdef FEAT_CRYPT
10777 buf->b_p_key = vim_strsave(p_key);
10778#endif
10779#ifdef FEAT_SEARCHPATH
10780 buf->b_p_sua = vim_strsave(p_sua);
10781#endif
10782#ifdef FEAT_KEYMAP
10783 buf->b_p_keymap = vim_strsave(p_keymap);
10784 buf->b_kmap_state |= KEYMAP_INIT;
10785#endif
10786 /* This isn't really an option, but copying the langmap and IME
10787 * state from the current buffer is better than resetting it. */
10788 buf->b_p_iminsert = p_iminsert;
10789 buf->b_p_imsearch = p_imsearch;
10790
10791 /* options that are normally global but also have a local value
10792 * are not copied, start using the global value */
10793 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010794 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010795 buf->b_p_bkc = empty_option;
10796 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797#ifdef FEAT_QUICKFIX
10798 buf->b_p_gp = empty_option;
10799 buf->b_p_mp = empty_option;
10800 buf->b_p_efm = empty_option;
10801#endif
10802 buf->b_p_ep = empty_option;
10803 buf->b_p_kp = empty_option;
10804 buf->b_p_path = empty_option;
10805 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010806 buf->b_p_tc = empty_option;
10807 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010808#ifdef FEAT_FIND_ID
10809 buf->b_p_def = empty_option;
10810 buf->b_p_inc = empty_option;
10811# ifdef FEAT_EVAL
10812 buf->b_p_inex = vim_strsave(p_inex);
10813# endif
10814#endif
10815#ifdef FEAT_INS_EXPAND
10816 buf->b_p_dict = empty_option;
10817 buf->b_p_tsr = empty_option;
10818#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010819#ifdef FEAT_TEXTOBJ
10820 buf->b_p_qe = vim_strsave(p_qe);
10821#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010822#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10823 buf->b_p_bexpr = empty_option;
10824#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010825#if defined(FEAT_CRYPT)
10826 buf->b_p_cm = empty_option;
10827#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010828#ifdef FEAT_PERSISTENT_UNDO
10829 buf->b_p_udf = p_udf;
10830#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010831#ifdef FEAT_LISP
10832 buf->b_p_lw = empty_option;
10833#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010834
10835 /*
10836 * Don't copy the options set by ex_help(), use the saved values,
10837 * when going from a help buffer to a non-help buffer.
10838 * Don't touch these at all when BCO_NOHELP is used and going from
10839 * or to a help buffer.
10840 */
10841 if (dont_do_help)
10842 buf->b_p_isk = save_p_isk;
10843 else
10844 {
10845 buf->b_p_isk = vim_strsave(p_isk);
10846 did_isk = TRUE;
10847 buf->b_p_ts = p_ts;
10848 buf->b_help = FALSE;
10849#ifdef FEAT_QUICKFIX
10850 if (buf->b_p_bt[0] == 'h')
10851 clear_string_option(&buf->b_p_bt);
10852#endif
10853 buf->b_p_ma = p_ma;
10854 }
10855 }
10856
10857 /*
10858 * When the options should be copied (ignoring BCO_ALWAYS), set the
10859 * flag that indicates that the options have been initialized.
10860 */
10861 if (should_copy)
10862 buf->b_p_initialized = TRUE;
10863 }
10864
10865 check_buf_options(buf); /* make sure we don't have NULLs */
10866 if (did_isk)
10867 (void)buf_init_chartab(buf, FALSE);
10868}
10869
10870/*
10871 * Reset the 'modifiable' option and its default value.
10872 */
10873 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010874reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010875{
10876 int opt_idx;
10877
10878 curbuf->b_p_ma = FALSE;
10879 p_ma = FALSE;
10880 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010881 if (opt_idx >= 0)
10882 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883}
10884
10885/*
10886 * Set the global value for 'iminsert' to the local value.
10887 */
10888 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010889set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890{
10891 p_iminsert = curbuf->b_p_iminsert;
10892}
10893
10894/*
10895 * Set the global value for 'imsearch' to the local value.
10896 */
10897 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010898set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010899{
10900 p_imsearch = curbuf->b_p_imsearch;
10901}
10902
10903#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10904static int expand_option_idx = -1;
10905static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10906static int expand_option_flags = 0;
10907
10908 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010909set_context_in_set_cmd(
10910 expand_T *xp,
10911 char_u *arg,
10912 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913{
10914 int nextchar;
10915 long_u flags = 0; /* init for GCC */
10916 int opt_idx = 0; /* init for GCC */
10917 char_u *p;
10918 char_u *s;
10919 int is_term_option = FALSE;
10920 int key;
10921
10922 expand_option_flags = opt_flags;
10923
10924 xp->xp_context = EXPAND_SETTINGS;
10925 if (*arg == NUL)
10926 {
10927 xp->xp_pattern = arg;
10928 return;
10929 }
10930 p = arg + STRLEN(arg) - 1;
10931 if (*p == ' ' && *(p - 1) != '\\')
10932 {
10933 xp->xp_pattern = p + 1;
10934 return;
10935 }
10936 while (p > arg)
10937 {
10938 s = p;
10939 /* count number of backslashes before ' ' or ',' */
10940 if (*p == ' ' || *p == ',')
10941 {
10942 while (s > arg && *(s - 1) == '\\')
10943 --s;
10944 }
10945 /* break at a space with an even number of backslashes */
10946 if (*p == ' ' && ((p - s) & 1) == 0)
10947 {
10948 ++p;
10949 break;
10950 }
10951 --p;
10952 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010953 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010954 {
10955 xp->xp_context = EXPAND_BOOL_SETTINGS;
10956 p += 2;
10957 }
10958 if (STRNCMP(p, "inv", 3) == 0)
10959 {
10960 xp->xp_context = EXPAND_BOOL_SETTINGS;
10961 p += 3;
10962 }
10963 xp->xp_pattern = arg = p;
10964 if (*arg == '<')
10965 {
10966 while (*p != '>')
10967 if (*p++ == NUL) /* expand terminal option name */
10968 return;
10969 key = get_special_key_code(arg + 1);
10970 if (key == 0) /* unknown name */
10971 {
10972 xp->xp_context = EXPAND_NOTHING;
10973 return;
10974 }
10975 nextchar = *++p;
10976 is_term_option = TRUE;
10977 expand_option_name[2] = KEY2TERMCAP0(key);
10978 expand_option_name[3] = KEY2TERMCAP1(key);
10979 }
10980 else
10981 {
10982 if (p[0] == 't' && p[1] == '_')
10983 {
10984 p += 2;
10985 if (*p != NUL)
10986 ++p;
10987 if (*p == NUL)
10988 return; /* expand option name */
10989 nextchar = *++p;
10990 is_term_option = TRUE;
10991 expand_option_name[2] = p[-2];
10992 expand_option_name[3] = p[-1];
10993 }
10994 else
10995 {
10996 /* Allow * wildcard */
10997 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10998 p++;
10999 if (*p == NUL)
11000 return;
11001 nextchar = *p;
11002 *p = NUL;
11003 opt_idx = findoption(arg);
11004 *p = nextchar;
11005 if (opt_idx == -1 || options[opt_idx].var == NULL)
11006 {
11007 xp->xp_context = EXPAND_NOTHING;
11008 return;
11009 }
11010 flags = options[opt_idx].flags;
11011 if (flags & P_BOOL)
11012 {
11013 xp->xp_context = EXPAND_NOTHING;
11014 return;
11015 }
11016 }
11017 }
11018 /* handle "-=" and "+=" */
11019 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11020 {
11021 ++p;
11022 nextchar = '=';
11023 }
11024 if ((nextchar != '=' && nextchar != ':')
11025 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11026 {
11027 xp->xp_context = EXPAND_UNSUCCESSFUL;
11028 return;
11029 }
11030 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11031 {
11032 xp->xp_context = EXPAND_OLD_SETTING;
11033 if (is_term_option)
11034 expand_option_idx = -1;
11035 else
11036 expand_option_idx = opt_idx;
11037 xp->xp_pattern = p + 1;
11038 return;
11039 }
11040 xp->xp_context = EXPAND_NOTHING;
11041 if (is_term_option || (flags & P_NUM))
11042 return;
11043
11044 xp->xp_pattern = p + 1;
11045
11046 if (flags & P_EXPAND)
11047 {
11048 p = options[opt_idx].var;
11049 if (p == (char_u *)&p_bdir
11050 || p == (char_u *)&p_dir
11051 || p == (char_u *)&p_path
11052 || p == (char_u *)&p_rtp
11053#ifdef FEAT_SEARCHPATH
11054 || p == (char_u *)&p_cdpath
11055#endif
11056#ifdef FEAT_SESSION
11057 || p == (char_u *)&p_vdir
11058#endif
11059 )
11060 {
11061 xp->xp_context = EXPAND_DIRECTORIES;
11062 if (p == (char_u *)&p_path
11063#ifdef FEAT_SEARCHPATH
11064 || p == (char_u *)&p_cdpath
11065#endif
11066 )
11067 xp->xp_backslash = XP_BS_THREE;
11068 else
11069 xp->xp_backslash = XP_BS_ONE;
11070 }
11071 else
11072 {
11073 xp->xp_context = EXPAND_FILES;
11074 /* for 'tags' need three backslashes for a space */
11075 if (p == (char_u *)&p_tags)
11076 xp->xp_backslash = XP_BS_THREE;
11077 else
11078 xp->xp_backslash = XP_BS_ONE;
11079 }
11080 }
11081
11082 /* For an option that is a list of file names, find the start of the
11083 * last file name. */
11084 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11085 {
11086 /* count number of backslashes before ' ' or ',' */
11087 if (*p == ' ' || *p == ',')
11088 {
11089 s = p;
11090 while (s > xp->xp_pattern && *(s - 1) == '\\')
11091 --s;
11092 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11093 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11094 {
11095 xp->xp_pattern = p + 1;
11096 break;
11097 }
11098 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011099
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011100#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011101 /* for 'spellsuggest' start at "file:" */
11102 if (options[opt_idx].var == (char_u *)&p_sps
11103 && STRNCMP(p, "file:", 5) == 0)
11104 {
11105 xp->xp_pattern = p + 5;
11106 break;
11107 }
11108#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109 }
11110
11111 return;
11112}
11113
11114 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011115ExpandSettings(
11116 expand_T *xp,
11117 regmatch_T *regmatch,
11118 int *num_file,
11119 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120{
11121 int num_normal = 0; /* Nr of matching non-term-code settings */
11122 int num_term = 0; /* Nr of matching terminal code settings */
11123 int opt_idx;
11124 int match;
11125 int count = 0;
11126 char_u *str;
11127 int loop;
11128 int is_term_opt;
11129 char_u name_buf[MAX_KEY_NAME_LEN];
11130 static char *(names[]) = {"all", "termcap"};
11131 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11132
11133 /* do this loop twice:
11134 * loop == 0: count the number of matching options
11135 * loop == 1: copy the matching options into allocated memory
11136 */
11137 for (loop = 0; loop <= 1; ++loop)
11138 {
11139 regmatch->rm_ic = ic;
11140 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11141 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011142 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11143 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011144 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11145 {
11146 if (loop == 0)
11147 num_normal++;
11148 else
11149 (*file)[count++] = vim_strsave((char_u *)names[match]);
11150 }
11151 }
11152 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11153 opt_idx++)
11154 {
11155 if (options[opt_idx].var == NULL)
11156 continue;
11157 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11158 && !(options[opt_idx].flags & P_BOOL))
11159 continue;
11160 is_term_opt = istermoption(&options[opt_idx]);
11161 if (is_term_opt && num_normal > 0)
11162 continue;
11163 match = FALSE;
11164 if (vim_regexec(regmatch, str, (colnr_T)0)
11165 || (options[opt_idx].shortname != NULL
11166 && vim_regexec(regmatch,
11167 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11168 match = TRUE;
11169 else if (is_term_opt)
11170 {
11171 name_buf[0] = '<';
11172 name_buf[1] = 't';
11173 name_buf[2] = '_';
11174 name_buf[3] = str[2];
11175 name_buf[4] = str[3];
11176 name_buf[5] = '>';
11177 name_buf[6] = NUL;
11178 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11179 {
11180 match = TRUE;
11181 str = name_buf;
11182 }
11183 }
11184 if (match)
11185 {
11186 if (loop == 0)
11187 {
11188 if (is_term_opt)
11189 num_term++;
11190 else
11191 num_normal++;
11192 }
11193 else
11194 (*file)[count++] = vim_strsave(str);
11195 }
11196 }
11197 /*
11198 * Check terminal key codes, these are not in the option table
11199 */
11200 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11201 {
11202 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11203 {
11204 if (!isprint(str[0]) || !isprint(str[1]))
11205 continue;
11206
11207 name_buf[0] = 't';
11208 name_buf[1] = '_';
11209 name_buf[2] = str[0];
11210 name_buf[3] = str[1];
11211 name_buf[4] = NUL;
11212
11213 match = FALSE;
11214 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11215 match = TRUE;
11216 else
11217 {
11218 name_buf[0] = '<';
11219 name_buf[1] = 't';
11220 name_buf[2] = '_';
11221 name_buf[3] = str[0];
11222 name_buf[4] = str[1];
11223 name_buf[5] = '>';
11224 name_buf[6] = NUL;
11225
11226 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11227 match = TRUE;
11228 }
11229 if (match)
11230 {
11231 if (loop == 0)
11232 num_term++;
11233 else
11234 (*file)[count++] = vim_strsave(name_buf);
11235 }
11236 }
11237
11238 /*
11239 * Check special key names.
11240 */
11241 regmatch->rm_ic = TRUE; /* ignore case here */
11242 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11243 {
11244 name_buf[0] = '<';
11245 STRCPY(name_buf + 1, str);
11246 STRCAT(name_buf, ">");
11247
11248 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11249 {
11250 if (loop == 0)
11251 num_term++;
11252 else
11253 (*file)[count++] = vim_strsave(name_buf);
11254 }
11255 }
11256 }
11257 if (loop == 0)
11258 {
11259 if (num_normal > 0)
11260 *num_file = num_normal;
11261 else if (num_term > 0)
11262 *num_file = num_term;
11263 else
11264 return OK;
11265 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11266 if (*file == NULL)
11267 {
11268 *file = (char_u **)"";
11269 return FAIL;
11270 }
11271 }
11272 }
11273 return OK;
11274}
11275
11276 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011277ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278{
11279 char_u *var = NULL; /* init for GCC */
11280 char_u *buf;
11281
11282 *num_file = 0;
11283 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11284 if (*file == NULL)
11285 return FAIL;
11286
11287 /*
11288 * For a terminal key code expand_option_idx is < 0.
11289 */
11290 if (expand_option_idx < 0)
11291 {
11292 var = find_termcode(expand_option_name + 2);
11293 if (var == NULL)
11294 expand_option_idx = findoption(expand_option_name);
11295 }
11296
11297 if (expand_option_idx >= 0)
11298 {
11299 /* put string of option value in NameBuff */
11300 option_value2string(&options[expand_option_idx], expand_option_flags);
11301 var = NameBuff;
11302 }
11303 else if (var == NULL)
11304 var = (char_u *)"";
11305
11306 /* A backslash is required before some characters. This is the reverse of
11307 * what happens in do_set(). */
11308 buf = vim_strsave_escaped(var, escape_chars);
11309
11310 if (buf == NULL)
11311 {
11312 vim_free(*file);
11313 *file = NULL;
11314 return FAIL;
11315 }
11316
11317#ifdef BACKSLASH_IN_FILENAME
11318 /* For MS-Windows et al. we don't double backslashes at the start and
11319 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011320 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011321 if (var[0] == '\\' && var[1] == '\\'
11322 && expand_option_idx >= 0
11323 && (options[expand_option_idx].flags & P_EXPAND)
11324 && vim_isfilec(var[2])
11325 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011326 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011327#endif
11328
11329 *file[0] = buf;
11330 *num_file = 1;
11331 return OK;
11332}
11333#endif
11334
11335/*
11336 * Get the value for the numeric or string option *opp in a nice format into
11337 * NameBuff[]. Must not be called with a hidden option!
11338 */
11339 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011340option_value2string(
11341 struct vimoption *opp,
11342 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011343{
11344 char_u *varp;
11345
11346 varp = get_varp_scope(opp, opt_flags);
11347
11348 if (opp->flags & P_NUM)
11349 {
11350 long wc = 0;
11351
11352 if (wc_use_keyname(varp, &wc))
11353 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11354 else if (wc != 0)
11355 STRCPY(NameBuff, transchar((int)wc));
11356 else
11357 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11358 }
11359 else /* P_STRING */
11360 {
11361 varp = *(char_u **)(varp);
11362 if (varp == NULL) /* just in case */
11363 NameBuff[0] = NUL;
11364#ifdef FEAT_CRYPT
11365 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011366 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011367 STRCPY(NameBuff, "*****");
11368#endif
11369 else if (opp->flags & P_EXPAND)
11370 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11371 /* Translate 'pastetoggle' into special key names */
11372 else if ((char_u **)opp->var == &p_pt)
11373 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11374 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011375 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376 }
11377}
11378
11379/*
11380 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11381 * printed as a keyname.
11382 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11383 */
11384 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011385wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011386{
11387 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11388 {
11389 *wcp = *(long *)varp;
11390 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11391 return TRUE;
11392 }
11393 return FALSE;
11394}
11395
Bram Moolenaar01615492015-02-03 13:00:38 +010011396#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011397/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011398 * Any character has an equivalent 'langmap' character. This is used for
11399 * keyboards that have a special language mode that sends characters above
11400 * 128 (although other characters can be translated too). The "to" field is a
11401 * Vim command character. This avoids having to switch the keyboard back to
11402 * ASCII mode when leaving Insert mode.
11403 *
11404 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11405 * commands.
11406 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11407 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11408 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011409 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011410# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011411/*
11412 * With multi-byte support use growarray for 'langmap' chars >= 256
11413 */
11414typedef struct
11415{
11416 int from;
11417 int to;
11418} langmap_entry_T;
11419
11420static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011421static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011422
11423/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011424 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11425 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011426 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011427 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011428langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011429{
11430 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011431 int a = 0;
11432 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011433
11434 /* Do a binary search for an existing entry. */
11435 while (a != b)
11436 {
11437 int i = (a + b) / 2;
11438 int d = entries[i].from - from;
11439
11440 if (d == 0)
11441 {
11442 entries[i].to = to;
11443 return;
11444 }
11445 if (d < 0)
11446 a = i + 1;
11447 else
11448 b = i;
11449 }
11450
11451 if (ga_grow(&langmap_mapga, 1) != OK)
11452 return; /* out of memory */
11453
11454 /* insert new entry at position "a" */
11455 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11456 mch_memmove(entries + 1, entries,
11457 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11458 ++langmap_mapga.ga_len;
11459 entries[0].from = from;
11460 entries[0].to = to;
11461}
11462
11463/*
11464 * Apply 'langmap' to multi-byte character "c" and return the result.
11465 */
11466 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011467langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011468{
11469 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11470 int a = 0;
11471 int b = langmap_mapga.ga_len;
11472
11473 while (a != b)
11474 {
11475 int i = (a + b) / 2;
11476 int d = entries[i].from - c;
11477
11478 if (d == 0)
11479 return entries[i].to; /* found matching entry */
11480 if (d < 0)
11481 a = i + 1;
11482 else
11483 b = i;
11484 }
11485 return c; /* no entry found, return "c" unmodified */
11486}
11487# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011488
11489 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011490langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491{
11492 int i;
11493
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011494 for (i = 0; i < 256; i++)
11495 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11496# ifdef FEAT_MBYTE
11497 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11498# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011499}
11500
11501/*
11502 * Called when langmap option is set; the language map can be
11503 * changed at any time!
11504 */
11505 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011506langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011507{
11508 char_u *p;
11509 char_u *p2;
11510 int from, to;
11511
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011512#ifdef FEAT_MBYTE
11513 ga_clear(&langmap_mapga); /* clear the previous map first */
11514#endif
11515 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011516
11517 for (p = p_langmap; p[0] != NUL; )
11518 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011519 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11520 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011521 {
11522 if (p2[0] == '\\' && p2[1] != NUL)
11523 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524 }
11525 if (p2[0] == ';')
11526 ++p2; /* abcd;ABCD form, p2 points to A */
11527 else
11528 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11529 while (p[0])
11530 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011531 if (p[0] == ',')
11532 {
11533 ++p;
11534 break;
11535 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011536 if (p[0] == '\\' && p[1] != NUL)
11537 ++p;
11538#ifdef FEAT_MBYTE
11539 from = (*mb_ptr2char)(p);
11540#else
11541 from = p[0];
11542#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011543 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011544 if (p2 == NULL)
11545 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011546 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011547 if (p[0] != ',')
11548 {
11549 if (p[0] == '\\')
11550 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011551#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011552 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011553#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011554 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011556 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011557 }
11558 else
11559 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011560 if (p2[0] != ',')
11561 {
11562 if (p2[0] == '\\')
11563 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011564#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011565 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011566#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011567 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011568#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011569 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011570 }
11571 if (to == NUL)
11572 {
11573 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11574 transchar(from));
11575 return;
11576 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011577
11578#ifdef FEAT_MBYTE
11579 if (from >= 256)
11580 langmap_set_entry(from, to);
11581 else
11582#endif
11583 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011584
11585 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011586 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011587 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011588 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011589 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011590 if (*p == ';')
11591 {
11592 p = p2;
11593 if (p[0] != NUL)
11594 {
11595 if (p[0] != ',')
11596 {
11597 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11598 return;
11599 }
11600 ++p;
11601 }
11602 break;
11603 }
11604 }
11605 }
11606 }
11607}
11608#endif
11609
11610/*
11611 * Return TRUE if format option 'x' is in effect.
11612 * Take care of no formatting when 'paste' is set.
11613 */
11614 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011615has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616{
11617 if (p_paste)
11618 return FALSE;
11619 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11620}
11621
11622/*
11623 * Return TRUE if "x" is present in 'shortmess' option, or
11624 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11625 */
11626 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011627shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011628{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011629 return p_shm != NULL &&
11630 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011631 || (vim_strchr(p_shm, 'a') != NULL
11632 && vim_strchr((char_u *)SHM_A, x) != NULL));
11633}
11634
11635/*
11636 * paste_option_changed() - Called after p_paste was set or reset.
11637 */
11638 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011639paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640{
11641 static int old_p_paste = FALSE;
11642 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011643 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011644#ifdef FEAT_CMDL_INFO
11645 static int save_ru = 0;
11646#endif
11647#ifdef FEAT_RIGHTLEFT
11648 static int save_ri = 0;
11649 static int save_hkmap = 0;
11650#endif
11651 buf_T *buf;
11652
11653 if (p_paste)
11654 {
11655 /*
11656 * Paste switched from off to on.
11657 * Save the current values, so they can be restored later.
11658 */
11659 if (!old_p_paste)
11660 {
11661 /* save options for each buffer */
11662 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11663 {
11664 buf->b_p_tw_nopaste = buf->b_p_tw;
11665 buf->b_p_wm_nopaste = buf->b_p_wm;
11666 buf->b_p_sts_nopaste = buf->b_p_sts;
11667 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011668 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011669 }
11670
11671 /* save global options */
11672 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011673 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011674#ifdef FEAT_CMDL_INFO
11675 save_ru = p_ru;
11676#endif
11677#ifdef FEAT_RIGHTLEFT
11678 save_ri = p_ri;
11679 save_hkmap = p_hkmap;
11680#endif
11681 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011682 p_ai_nopaste = p_ai;
11683 p_et_nopaste = p_et;
11684 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011685 p_tw_nopaste = p_tw;
11686 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011687 }
11688
11689 /*
11690 * Always set the option values, also when 'paste' is set when it is
11691 * already on.
11692 */
11693 /* set options for each buffer */
11694 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11695 {
11696 buf->b_p_tw = 0; /* textwidth is 0 */
11697 buf->b_p_wm = 0; /* wrapmargin is 0 */
11698 buf->b_p_sts = 0; /* softtabstop is 0 */
11699 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011700 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011701 }
11702
11703 /* set global options */
11704 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011705 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011706#ifdef FEAT_CMDL_INFO
11707# ifdef FEAT_WINDOWS
11708 if (p_ru)
11709 status_redraw_all(); /* redraw to remove the ruler */
11710# endif
11711 p_ru = 0; /* no ruler */
11712#endif
11713#ifdef FEAT_RIGHTLEFT
11714 p_ri = 0; /* no reverse insert */
11715 p_hkmap = 0; /* no Hebrew keyboard */
11716#endif
11717 /* set global values for local buffer options */
11718 p_tw = 0;
11719 p_wm = 0;
11720 p_sts = 0;
11721 p_ai = 0;
11722 }
11723
11724 /*
11725 * Paste switched from on to off: Restore saved values.
11726 */
11727 else if (old_p_paste)
11728 {
11729 /* restore options for each buffer */
11730 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11731 {
11732 buf->b_p_tw = buf->b_p_tw_nopaste;
11733 buf->b_p_wm = buf->b_p_wm_nopaste;
11734 buf->b_p_sts = buf->b_p_sts_nopaste;
11735 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011736 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011737 }
11738
11739 /* restore global options */
11740 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011741 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011742#ifdef FEAT_CMDL_INFO
11743# ifdef FEAT_WINDOWS
11744 if (p_ru != save_ru)
11745 status_redraw_all(); /* redraw to draw the ruler */
11746# endif
11747 p_ru = save_ru;
11748#endif
11749#ifdef FEAT_RIGHTLEFT
11750 p_ri = save_ri;
11751 p_hkmap = save_hkmap;
11752#endif
11753 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011754 p_ai = p_ai_nopaste;
11755 p_et = p_et_nopaste;
11756 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011757 p_tw = p_tw_nopaste;
11758 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011759 }
11760
11761 old_p_paste = p_paste;
11762}
11763
11764/*
11765 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11766 *
11767 * Reset 'compatible' and set the values for options that didn't get set yet
11768 * to the Vim defaults.
11769 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011770 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771 */
11772 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011773vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011774{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011775 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011776 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011777 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011778
11779 if (!option_was_set((char_u *)"cp"))
11780 {
11781 p_cp = FALSE;
11782 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11783 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11784 set_option_default(opt_idx, OPT_FREE, FALSE);
11785 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011786 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011787 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011788
11789 if (fname != NULL)
11790 {
11791 p = vim_getenv(envname, &dofree);
11792 if (p == NULL)
11793 {
11794 /* Set $MYVIMRC to the first vimrc file found. */
11795 p = FullName_save(fname, FALSE);
11796 if (p != NULL)
11797 {
11798 vim_setenv(envname, p);
11799 vim_free(p);
11800 }
11801 }
11802 else if (dofree)
11803 vim_free(p);
11804 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011805}
11806
11807/*
11808 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11809 */
11810 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011811change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011812{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011813 int opt_idx;
11814
Bram Moolenaar071d4272004-06-13 20:20:40 +000011815 if (p_cp != on)
11816 {
11817 p_cp = on;
11818 compatible_set();
11819 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011820 opt_idx = findoption((char_u *)"cp");
11821 if (opt_idx >= 0)
11822 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011823}
11824
11825/*
11826 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011827 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011828 */
11829 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011830option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011831{
11832 int idx;
11833
11834 idx = findoption(name);
11835 if (idx < 0) /* unknown option */
11836 return FALSE;
11837 if (options[idx].flags & P_WAS_SET)
11838 return TRUE;
11839 return FALSE;
11840}
11841
11842/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011843 * Reset the flag indicating option "name" was set.
11844 */
11845 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011846reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011847{
11848 int idx = findoption(name);
11849
11850 if (idx >= 0)
11851 options[idx].flags &= ~P_WAS_SET;
11852}
11853
11854/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855 * compatible_set() - Called when 'compatible' has been set or unset.
11856 *
11857 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11858 * flag) to a Vi compatible value.
11859 * When 'compatible' is unset: Set all options that have a different default
11860 * for Vim (without the P_VI_DEF flag) to that default.
11861 */
11862 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011863compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011864{
11865 int opt_idx;
11866
11867 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11868 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11869 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11870 set_option_default(opt_idx, OPT_FREE, p_cp);
11871 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011872 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011873}
11874
11875#ifdef FEAT_LINEBREAK
11876
11877# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11878 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011879 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011880# endif
11881
11882/*
11883 * fill_breakat_flags() -- called when 'breakat' changes value.
11884 */
11885 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011886fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011887{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011888 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889 int i;
11890
11891 for (i = 0; i < 256; i++)
11892 breakat_flags[i] = FALSE;
11893
11894 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011895 for (p = p_breakat; *p; p++)
11896 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011897}
11898
11899# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011900 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901# endif
11902
11903#endif
11904
11905/*
11906 * Check an option that can be a range of string values.
11907 *
11908 * Return OK for correct value, FAIL otherwise.
11909 * Empty is always OK.
11910 */
11911 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011912check_opt_strings(
11913 char_u *val,
11914 char **values,
11915 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011916{
11917 return opt_strings_flags(val, values, NULL, list);
11918}
11919
11920/*
11921 * Handle an option that can be a range of string values.
11922 * Set a flag in "*flagp" for each string present.
11923 *
11924 * Return OK for correct value, FAIL otherwise.
11925 * Empty is always OK.
11926 */
11927 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011928opt_strings_flags(
11929 char_u *val, /* new value */
11930 char **values, /* array of valid string values */
11931 unsigned *flagp,
11932 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011933{
11934 int i;
11935 int len;
11936 unsigned new_flags = 0;
11937
11938 while (*val)
11939 {
11940 for (i = 0; ; ++i)
11941 {
11942 if (values[i] == NULL) /* val not found in values[] */
11943 return FAIL;
11944
11945 len = (int)STRLEN(values[i]);
11946 if (STRNCMP(values[i], val, len) == 0
11947 && ((list && val[len] == ',') || val[len] == NUL))
11948 {
11949 val += len + (val[len] == ',');
11950 new_flags |= (1 << i);
11951 break; /* check next item in val list */
11952 }
11953 }
11954 }
11955 if (flagp != NULL)
11956 *flagp = new_flags;
11957
11958 return OK;
11959}
11960
11961/*
11962 * Read the 'wildmode' option, fill wim_flags[].
11963 */
11964 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011965check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011966{
11967 char_u new_wim_flags[4];
11968 char_u *p;
11969 int i;
11970 int idx = 0;
11971
11972 for (i = 0; i < 4; ++i)
11973 new_wim_flags[i] = 0;
11974
11975 for (p = p_wim; *p; ++p)
11976 {
11977 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11978 ;
11979 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11980 return FAIL;
11981 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11982 new_wim_flags[idx] |= WIM_LONGEST;
11983 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11984 new_wim_flags[idx] |= WIM_FULL;
11985 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11986 new_wim_flags[idx] |= WIM_LIST;
11987 else
11988 return FAIL;
11989 p += i;
11990 if (*p == NUL)
11991 break;
11992 if (*p == ',')
11993 {
11994 if (idx == 3)
11995 return FAIL;
11996 ++idx;
11997 }
11998 }
11999
12000 /* fill remaining entries with last flag */
12001 while (idx < 3)
12002 {
12003 new_wim_flags[idx + 1] = new_wim_flags[idx];
12004 ++idx;
12005 }
12006
12007 /* only when there are no errors, wim_flags[] is changed */
12008 for (i = 0; i < 4; ++i)
12009 wim_flags[i] = new_wim_flags[i];
12010 return OK;
12011}
12012
12013/*
12014 * Check if backspacing over something is allowed.
12015 */
12016 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012017can_bs(
12018 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012019{
12020 switch (*p_bs)
12021 {
12022 case '2': return TRUE;
12023 case '1': return (what != BS_START);
12024 case '0': return FALSE;
12025 }
12026 return vim_strchr(p_bs, what) != NULL;
12027}
12028
12029/*
12030 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12031 * the file must be considered changed when the value is different.
12032 */
12033 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012034save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012035{
12036 buf->b_start_ffc = *buf->b_p_ff;
12037 buf->b_start_eol = buf->b_p_eol;
12038#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012039 buf->b_start_bomb = buf->b_p_bomb;
12040
Bram Moolenaar071d4272004-06-13 20:20:40 +000012041 /* Only use free/alloc when necessary, they take time. */
12042 if (buf->b_start_fenc == NULL
12043 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12044 {
12045 vim_free(buf->b_start_fenc);
12046 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12047 }
12048#endif
12049}
12050
12051/*
12052 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12053 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012054 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12055 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012056 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012057 * When "ignore_empty" is true don't consider a new, empty buffer to be
12058 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012059 */
12060 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012061file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012062{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012063 /* In a buffer that was never loaded the options are not valid. */
12064 if (buf->b_flags & BF_NEVERLOADED)
12065 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012066 if (ignore_empty
12067 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012068 && buf->b_ml.ml_line_count == 1
12069 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12070 return FALSE;
12071 if (buf->b_start_ffc != *buf->b_p_ff)
12072 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012073 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012074 return TRUE;
12075#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012076 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12077 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078 if (buf->b_start_fenc == NULL)
12079 return (*buf->b_p_fenc != NUL);
12080 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12081#else
12082 return FALSE;
12083#endif
12084}
12085
12086/*
12087 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12088 */
12089 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012090check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012091{
12092 return check_opt_strings(p, p_ff_values, FALSE);
12093}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012094
12095/*
12096 * Return the effective shiftwidth value for current buffer, using the
12097 * 'tabstop' value when 'shiftwidth' is zero.
12098 */
12099 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012100get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012101{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012102 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012103}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012104
12105/*
12106 * Return the effective softtabstop value for the current buffer, using the
12107 * 'tabstop' value when 'softtabstop' is negative.
12108 */
12109 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012110get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012111{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012112 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012113}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012114
12115/*
12116 * Check matchpairs option for "*initc".
12117 * If there is a match set "*initc" to the matching character and "*findc" to
12118 * the opposite character. Set "*backwards" to the direction.
12119 * When "switchit" is TRUE swap the direction.
12120 */
12121 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012122find_mps_values(
12123 int *initc,
12124 int *findc,
12125 int *backwards,
12126 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012127{
12128 char_u *ptr;
12129
12130 ptr = curbuf->b_p_mps;
12131 while (*ptr != NUL)
12132 {
12133#ifdef FEAT_MBYTE
12134 if (has_mbyte)
12135 {
12136 char_u *prev;
12137
12138 if (mb_ptr2char(ptr) == *initc)
12139 {
12140 if (switchit)
12141 {
12142 *findc = *initc;
12143 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12144 *backwards = TRUE;
12145 }
12146 else
12147 {
12148 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12149 *backwards = FALSE;
12150 }
12151 return;
12152 }
12153 prev = ptr;
12154 ptr += mb_ptr2len(ptr) + 1;
12155 if (mb_ptr2char(ptr) == *initc)
12156 {
12157 if (switchit)
12158 {
12159 *findc = *initc;
12160 *initc = mb_ptr2char(prev);
12161 *backwards = FALSE;
12162 }
12163 else
12164 {
12165 *findc = mb_ptr2char(prev);
12166 *backwards = TRUE;
12167 }
12168 return;
12169 }
12170 ptr += mb_ptr2len(ptr);
12171 }
12172 else
12173#endif
12174 {
12175 if (*ptr == *initc)
12176 {
12177 if (switchit)
12178 {
12179 *backwards = TRUE;
12180 *findc = *initc;
12181 *initc = ptr[2];
12182 }
12183 else
12184 {
12185 *backwards = FALSE;
12186 *findc = ptr[2];
12187 }
12188 return;
12189 }
12190 ptr += 2;
12191 if (*ptr == *initc)
12192 {
12193 if (switchit)
12194 {
12195 *backwards = FALSE;
12196 *findc = *initc;
12197 *initc = ptr[-2];
12198 }
12199 else
12200 {
12201 *backwards = TRUE;
12202 *findc = ptr[-2];
12203 }
12204 return;
12205 }
12206 ++ptr;
12207 }
12208 if (*ptr == ',')
12209 ++ptr;
12210 }
12211}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012212
12213#if defined(FEAT_LINEBREAK) || defined(PROTO)
12214/*
12215 * This is called when 'breakindentopt' is changed and when a window is
12216 * initialized.
12217 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012218 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012219briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012220{
12221 char_u *p;
12222 int bri_shift = 0;
12223 long bri_min = 20;
12224 int bri_sbr = FALSE;
12225
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012226 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012227 while (*p != NUL)
12228 {
12229 if (STRNCMP(p, "shift:", 6) == 0
12230 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12231 {
12232 p += 6;
12233 bri_shift = getdigits(&p);
12234 }
12235 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12236 {
12237 p += 4;
12238 bri_min = getdigits(&p);
12239 }
12240 else if (STRNCMP(p, "sbr", 3) == 0)
12241 {
12242 p += 3;
12243 bri_sbr = TRUE;
12244 }
12245 if (*p != ',' && *p != NUL)
12246 return FAIL;
12247 if (*p == ',')
12248 ++p;
12249 }
12250
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012251 wp->w_p_brishift = bri_shift;
12252 wp->w_p_brimin = bri_min;
12253 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012254
12255 return OK;
12256}
12257#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012258
12259/*
12260 * Get the local or global value of 'backupcopy'.
12261 */
12262 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012263get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012264{
12265 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12266}