blob: 8daba63819ea9f762e0127fd2e605f095c5b85be [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 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100491static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200493 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000494#ifdef FEAT_RIGHTLEFT
495 (char_u *)&p_aleph, PV_NONE,
496#else
497 (char_u *)NULL, PV_NONE,
498#endif
499 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100500#if (defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000501 (char_u *)128L,
502#else
503 (char_u *)224L,
504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000505 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
507#if defined(FEAT_GUI) && defined(MACOS_X)
508 (char_u *)&p_antialias, PV_NONE,
509 {(char_u *)FALSE, (char_u *)FALSE}
510#else
511 (char_u *)NULL, PV_NONE,
512 {(char_u *)FALSE, (char_u *)FALSE}
513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000514 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200515 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000516#ifdef FEAT_ARABIC
517 (char_u *)VAR_WIN, PV_ARAB,
518#else
519 (char_u *)NULL, PV_NONE,
520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
523#ifdef FEAT_ARABIC
524 (char_u *)&p_arshape, PV_NONE,
525#else
526 (char_u *)NULL, PV_NONE,
527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000528 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
530#ifdef FEAT_RIGHTLEFT
531 (char_u *)&p_ari, PV_NONE,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
537#ifdef FEAT_FKMAP
538 (char_u *)&p_altkeymap, PV_NONE,
539#else
540 (char_u *)NULL, PV_NONE,
541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000543 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
544#if defined(FEAT_MBYTE)
545 (char_u *)&p_ambw, PV_NONE,
546 {(char_u *)"single", (char_u *)0L}
547#else
548 (char_u *)NULL, PV_NONE,
549 {(char_u *)0L, (char_u *)0L}
550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000551 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000552#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"autochdir", "acd", P_BOOL|P_VI_DEF,
554 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556#endif
557 {"autoindent", "ai", P_BOOL|P_VI_DEF,
558 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"autoprint", "ap", P_BOOL|P_VI_DEF,
561 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000564 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autowrite", "aw", P_BOOL|P_VI_DEF,
567 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autowriteall","awa", P_BOOL|P_VI_DEF,
570 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
573 (char_u *)&p_bg, PV_NONE,
574 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +0100575#if (defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 (char_u *)"dark",
577#else
578 (char_u *)"light",
579#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200581 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
585 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200587 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200588 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589#ifdef UNIX
590 {(char_u *)"yes", (char_u *)"auto"}
591#else
592 {(char_u *)"auto", (char_u *)"auto"}
593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000594 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200595 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
596 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000598 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000599 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600 (char_u *)&p_bex, PV_NONE,
601 {
602#ifdef VMS
603 (char_u *)"_",
604#else
605 (char_u *)"~",
606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000607 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200608 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609#ifdef FEAT_WILDIGN
610 (char_u *)&p_bsk, PV_NONE,
611 {(char_u *)"", (char_u *)0L}
612#else
613 (char_u *)NULL, PV_NONE,
614 {(char_u *)0L, (char_u *)0L}
615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000616 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617#ifdef FEAT_BEVAL
618 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
619 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000620 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
622 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000623 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000624# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000625 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000626 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000627 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000628# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629#endif
630 {"beautify", "bf", P_BOOL|P_VI_DEF,
631 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000632 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200633 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
634 (char_u *)&p_bo, PV_NONE,
635 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
637 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000638 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
640#ifdef MSDOS
641 (char_u *)&p_biosk, PV_NONE,
642#else
643 (char_u *)NULL, PV_NONE,
644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000645 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
647#ifdef FEAT_MBYTE
648 (char_u *)&p_bomb, PV_BOMB,
649#else
650 (char_u *)NULL, PV_NONE,
651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000652 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000653 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
654#ifdef FEAT_LINEBREAK
655 (char_u *)&p_breakat, PV_NONE,
656 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
657#else
658 (char_u *)NULL, PV_NONE,
659 {(char_u *)0L, (char_u *)0L}
660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000661 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200662 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
663#ifdef FEAT_LINEBREAK
664 (char_u *)VAR_WIN, PV_BRI,
665 {(char_u *)FALSE, (char_u *)0L}
666#else
667 (char_u *)NULL, PV_NONE,
668 {(char_u *)0L, (char_u *)0L}
669#endif
670 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200671 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
672 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200673#ifdef FEAT_LINEBREAK
674 (char_u *)VAR_WIN, PV_BRIOPT,
675 {(char_u *)"", (char_u *)NULL}
676#else
677 (char_u *)NULL, PV_NONE,
678 {(char_u *)"", (char_u *)NULL}
679#endif
680 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000681 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
682#ifdef FEAT_BROWSE
683 (char_u *)&p_bsdir, PV_NONE,
684 {(char_u *)"last", (char_u *)0L}
685#else
686 (char_u *)NULL, PV_NONE,
687 {(char_u *)0L, (char_u *)0L}
688#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000689 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000690 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
691#if defined(FEAT_QUICKFIX)
692 (char_u *)&p_bh, PV_BH,
693 {(char_u *)"", (char_u *)0L}
694#else
695 (char_u *)NULL, PV_NONE,
696 {(char_u *)0L, (char_u *)0L}
697#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000698 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
700 (char_u *)&p_bl, PV_BL,
701 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000702 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
704#if defined(FEAT_QUICKFIX)
705 (char_u *)&p_bt, PV_BT,
706 {(char_u *)"", (char_u *)0L}
707#else
708 (char_u *)NULL, PV_NONE,
709 {(char_u *)0L, (char_u *)0L}
710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000711 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200712 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000713#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 (char_u *)&p_cmp, PV_NONE,
715 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000716#else
717 (char_u *)NULL, PV_NONE,
718 {(char_u *)0L, (char_u *)0L}
719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000720 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
722#ifdef FEAT_SEARCHPATH
723 (char_u *)&p_cdpath, PV_NONE,
724 {(char_u *)",,", (char_u *)0L}
725#else
726 (char_u *)NULL, PV_NONE,
727 {(char_u *)0L, (char_u *)0L}
728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 {"cedit", NULL, P_STRING,
731#ifdef FEAT_CMDWIN
732 (char_u *)&p_cedit, PV_NONE,
733 {(char_u *)"", (char_u *)CTRL_F_STR}
734#else
735 (char_u *)NULL, PV_NONE,
736 {(char_u *)0L, (char_u *)0L}
737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000738 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
740#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
741 (char_u *)&p_ccv, PV_NONE,
742 {(char_u *)"", (char_u *)0L}
743#else
744 (char_u *)NULL, PV_NONE,
745 {(char_u *)0L, (char_u *)0L}
746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
749#ifdef FEAT_CINDENT
750 (char_u *)&p_cin, PV_CIN,
751#else
752 (char_u *)NULL, PV_NONE,
753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000754 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200755 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756#ifdef FEAT_CINDENT
757 (char_u *)&p_cink, PV_CINK,
758 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
759#else
760 (char_u *)NULL, PV_NONE,
761 {(char_u *)0L, (char_u *)0L}
762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000763 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200764 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765#ifdef FEAT_CINDENT
766 (char_u *)&p_cino, PV_CINO,
767#else
768 (char_u *)NULL, PV_NONE,
769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000770 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200771 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000772#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
773 (char_u *)&p_cinw, PV_CINW,
774 {(char_u *)"if,else,while,do,for,switch",
775 (char_u *)0L}
776#else
777 (char_u *)NULL, PV_NONE,
778 {(char_u *)0L, (char_u *)0L}
779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000780 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200781 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782#ifdef FEAT_CLIPBOARD
783 (char_u *)&p_cb, PV_NONE,
784# ifdef FEAT_XCLIPBOARD
785 {(char_u *)"autoselect,exclude:cons\\|linux",
786 (char_u *)0L}
787# else
788 {(char_u *)"", (char_u *)0L}
789# endif
790#else
791 (char_u *)NULL, PV_NONE,
792 {(char_u *)"", (char_u *)0L}
793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000794 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000795 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
796 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000797 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000798 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
799#ifdef FEAT_CMDWIN
800 (char_u *)&p_cwh, PV_NONE,
801#else
802 (char_u *)NULL, PV_NONE,
803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000804 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200805 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200806#ifdef FEAT_SYN_HL
807 (char_u *)VAR_WIN, PV_CC,
808#else
809 (char_u *)NULL, PV_NONE,
810#endif
811 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000812 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
813 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200815 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
816 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000817#ifdef FEAT_COMMENTS
818 (char_u *)&p_com, PV_COM,
819 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
820 (char_u *)0L}
821#else
822 (char_u *)NULL, PV_NONE,
823 {(char_u *)0L, (char_u *)0L}
824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200826 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827#ifdef FEAT_FOLDING
828 (char_u *)&p_cms, PV_CMS,
829 {(char_u *)"/*%s*/", (char_u *)0L}
830#else
831 (char_u *)NULL, PV_NONE,
832 {(char_u *)0L, (char_u *)0L}
833#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000834 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000835 /* P_PRI_MKRC isn't needed here, optval_default()
836 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837 {"compatible", "cp", P_BOOL|P_RALL,
838 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000839 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200840 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841#ifdef FEAT_INS_EXPAND
842 (char_u *)&p_cpt, PV_CPT,
843 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
844#else
845 (char_u *)NULL, PV_NONE,
846 {(char_u *)0L, (char_u *)0L}
847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000848 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200849 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200850#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200851 (char_u *)VAR_WIN, PV_COCU,
852 {(char_u *)"", (char_u *)NULL}
853#else
854 (char_u *)NULL, PV_NONE,
855 {(char_u *)NULL, (char_u *)0L}
856#endif
857 SCRIPTID_INIT},
858 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
859#ifdef FEAT_CONCEAL
860 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200861#else
862 (char_u *)NULL, PV_NONE,
863#endif
864 {(char_u *)0L, (char_u *)0L}
865 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000866 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
867#ifdef FEAT_COMPL_FUNC
868 (char_u *)&p_cfu, PV_CFU,
869 {(char_u *)"", (char_u *)0L}
870#else
871 (char_u *)NULL, PV_NONE,
872 {(char_u *)0L, (char_u *)0L}
873#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000874 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200875 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000876#ifdef FEAT_INS_EXPAND
877 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000878 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000879#else
880 (char_u *)NULL, PV_NONE,
881 {(char_u *)0L, (char_u *)0L}
882#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000883 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000884 {"confirm", "cf", P_BOOL|P_VI_DEF,
885#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
886 (char_u *)&p_confirm, PV_NONE,
887#else
888 (char_u *)NULL, PV_NONE,
889#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000890 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000891 {"conskey", "consk",P_BOOL|P_VI_DEF,
892#ifdef MSDOS
893 (char_u *)&p_consk, PV_NONE,
894#else
895 (char_u *)NULL, PV_NONE,
896#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000897 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000898 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
899 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
902 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
904 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200905 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200906#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200907 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200908 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200909#else
910 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200911 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200912#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200913 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
915#ifdef FEAT_CSCOPE
916 (char_u *)&p_cspc, PV_NONE,
917#else
918 (char_u *)NULL, PV_NONE,
919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
922#ifdef FEAT_CSCOPE
923 (char_u *)&p_csprg, PV_NONE,
924 {(char_u *)"cscope", (char_u *)0L}
925#else
926 (char_u *)NULL, PV_NONE,
927 {(char_u *)0L, (char_u *)0L}
928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000929 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200930 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
932 (char_u *)&p_csqf, PV_NONE,
933 {(char_u *)"", (char_u *)0L}
934#else
935 (char_u *)NULL, PV_NONE,
936 {(char_u *)0L, (char_u *)0L}
937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000938 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200939 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
940#ifdef FEAT_CSCOPE
941 (char_u *)&p_csre, PV_NONE,
942#else
943 (char_u *)NULL, PV_NONE,
944#endif
945 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
947#ifdef FEAT_CSCOPE
948 (char_u *)&p_cst, PV_NONE,
949#else
950 (char_u *)NULL, PV_NONE,
951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000952 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
954#ifdef FEAT_CSCOPE
955 (char_u *)&p_csto, PV_NONE,
956#else
957 (char_u *)NULL, PV_NONE,
958#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000959 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
961#ifdef FEAT_CSCOPE
962 (char_u *)&p_csverbose, PV_NONE,
963#else
964 (char_u *)NULL, PV_NONE,
965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000966 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200967 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
968#ifdef FEAT_CURSORBIND
969 (char_u *)VAR_WIN, PV_CRBIND,
970#else
971 (char_u *)NULL, PV_NONE,
972#endif
973 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000974 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
975#ifdef FEAT_SYN_HL
976 (char_u *)VAR_WIN, PV_CUC,
977#else
978 (char_u *)NULL, PV_NONE,
979#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000980 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000981 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWIN,
982#ifdef FEAT_SYN_HL
983 (char_u *)VAR_WIN, PV_CUL,
984#else
985 (char_u *)NULL, PV_NONE,
986#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000987 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988 {"debug", NULL, P_STRING|P_VI_DEF,
989 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200991 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000992#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000993 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000994 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#else
996 (char_u *)NULL, PV_NONE,
997 {(char_u *)NULL, (char_u *)0L}
998#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000999 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001000 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1001#ifdef FEAT_MBYTE
1002 (char_u *)&p_deco, PV_NONE,
1003#else
1004 (char_u *)NULL, PV_NONE,
1005#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001006 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001007 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001009 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#else
1011 (char_u *)NULL, PV_NONE,
1012#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001013 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1015#ifdef FEAT_DIFF
1016 (char_u *)VAR_WIN, PV_DIFF,
1017#else
1018 (char_u *)NULL, PV_NONE,
1019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001020 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001021 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1023 (char_u *)&p_dex, PV_NONE,
1024 {(char_u *)"", (char_u *)0L}
1025#else
1026 (char_u *)NULL, PV_NONE,
1027 {(char_u *)0L, (char_u *)0L}
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001030 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1031 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032#ifdef FEAT_DIFF
1033 (char_u *)&p_dip, PV_NONE,
1034 {(char_u *)"filler", (char_u *)NULL}
1035#else
1036 (char_u *)NULL, PV_NONE,
1037 {(char_u *)"", (char_u *)NULL}
1038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001039 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1041#ifdef FEAT_DIGRAPHS
1042 (char_u *)&p_dg, PV_NONE,
1043#else
1044 (char_u *)NULL, PV_NONE,
1045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001046 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001047 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1048 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001050 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001051 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 {"eadirection", "ead", P_STRING|P_VI_DEF,
1055#ifdef FEAT_VERTSPLIT
1056 (char_u *)&p_ead, PV_NONE,
1057 {(char_u *)"both", (char_u *)0L}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)NULL, (char_u *)0L}
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1064 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001065 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001066 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067#ifdef FEAT_MBYTE
1068 (char_u *)&p_enc, PV_NONE,
1069 {(char_u *)ENC_DFLT, (char_u *)0L}
1070#else
1071 (char_u *)NULL, PV_NONE,
1072 {(char_u *)0L, (char_u *)0L}
1073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1076 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1079 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001082 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001083 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1085 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001086 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1088#ifdef FEAT_QUICKFIX
1089 (char_u *)&p_ef, PV_NONE,
1090 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1091#else
1092 (char_u *)NULL, PV_NONE,
1093 {(char_u *)NULL, (char_u *)0L}
1094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001095 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001096 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001098 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100#else
1101 (char_u *)NULL, PV_NONE,
1102 {(char_u *)NULL, (char_u *)0L}
1103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 {"esckeys", "ek", P_BOOL|P_VIM,
1106 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001108 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109#ifdef FEAT_AUTOCMD
1110 (char_u *)&p_ei, PV_NONE,
1111#else
1112 (char_u *)NULL, PV_NONE,
1113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1116 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1119 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001120 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001121 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1122 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123#ifdef FEAT_MBYTE
1124 (char_u *)&p_fenc, PV_FENC,
1125 {(char_u *)"", (char_u *)0L}
1126#else
1127 (char_u *)NULL, PV_NONE,
1128 {(char_u *)0L, (char_u *)0L}
1129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001131 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132#ifdef FEAT_MBYTE
1133 (char_u *)&p_fencs, PV_NONE,
1134 {(char_u *)"ucs-bom", (char_u *)0L}
1135#else
1136 (char_u *)NULL, PV_NONE,
1137 {(char_u *)0L, (char_u *)0L}
1138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1141 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001144 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1147 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001148 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1149 (char_u *)&p_fic, PV_NONE,
1150 {
1151#ifdef CASE_INSENSITIVE_FILENAME
1152 (char_u *)TRUE,
1153#else
1154 (char_u *)FALSE,
1155#endif
1156 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001157 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158#ifdef FEAT_AUTOCMD
1159 (char_u *)&p_ft, PV_FT,
1160 {(char_u *)"", (char_u *)0L}
1161#else
1162 (char_u *)NULL, PV_NONE,
1163 {(char_u *)0L, (char_u *)0L}
1164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001166 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1168 (char_u *)&p_fcs, PV_NONE,
1169 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1170#else
1171 (char_u *)NULL, PV_NONE,
1172 {(char_u *)"", (char_u *)0L}
1173#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001174 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001175 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1176 (char_u *)&p_fixeol, PV_FIXEOL,
1177 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1179#ifdef FEAT_FKMAP
1180 (char_u *)&p_fkmap, PV_NONE,
1181#else
1182 (char_u *)NULL, PV_NONE,
1183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001185 {"flash", "fl", P_BOOL|P_VI_DEF,
1186 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001187 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001188#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001189 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1193 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1196 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1199# ifdef FEAT_EVAL
1200 (char_u *)VAR_WIN, PV_FDE,
1201 {(char_u *)"0", (char_u *)NULL}
1202# else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)NULL, (char_u *)0L}
1205# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1208 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1211 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001213 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001215 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001217 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)"{{{,}}}", (char_u *)NULL}
1220 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1225 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1228 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001229 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001230 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 (char_u *)&p_fdo, PV_NONE,
1232 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001233 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001234 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1235# ifdef FEAT_EVAL
1236 (char_u *)VAR_WIN, PV_FDT,
1237 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001238# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239 (char_u *)NULL, PV_NONE,
1240 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001241# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001242 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001244 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001245#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001246 (char_u *)&p_fex, PV_FEX,
1247 {(char_u *)"", (char_u *)0L}
1248#else
1249 (char_u *)NULL, PV_NONE,
1250 {(char_u *)0L, (char_u *)0L}
1251#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001252 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1254 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001255 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1256 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001257 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1258 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001259 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1260 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1262 (char_u *)&p_fp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001264 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1265#ifdef HAVE_FSYNC
1266 (char_u *)&p_fs, PV_NONE,
1267 {(char_u *)TRUE, (char_u *)0L}
1268#else
1269 (char_u *)NULL, PV_NONE,
1270 {(char_u *)FALSE, (char_u *)0L}
1271#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1274 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"graphic", "gr", P_BOOL|P_VI_DEF,
1277 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001278 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001279 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280#ifdef FEAT_QUICKFIX
1281 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001282 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283#else
1284 (char_u *)NULL, PV_NONE,
1285 {(char_u *)NULL, (char_u *)0L}
1286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001287 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1289#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001290 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291 {
1292# ifdef WIN3264
1293 /* may be changed to "grep -n" in os_win32.c */
1294 (char_u *)"findstr /n",
1295# else
1296# ifdef UNIX
1297 /* Add an extra file name so that grep will always
1298 * insert a file name in the match line. */
1299 (char_u *)"grep -n $* /dev/null",
1300# else
1301# ifdef VMS
1302 (char_u *)"SEARCH/NUMBERS ",
1303# else
1304 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001305# endif
1306# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001308 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001313 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001314 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315#ifdef CURSOR_SHAPE
1316 (char_u *)&p_guicursor, PV_NONE,
1317 {
1318# ifdef FEAT_GUI
1319 (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",
1320# else /* MSDOS or Win32 console */
1321 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1322# endif
1323 (char_u *)0L}
1324#else
1325 (char_u *)NULL, PV_NONE,
1326 {(char_u *)NULL, (char_u *)0L}
1327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001328 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001329 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330#ifdef FEAT_GUI
1331 (char_u *)&p_guifont, PV_NONE,
1332 {(char_u *)"", (char_u *)0L}
1333#else
1334 (char_u *)NULL, PV_NONE,
1335 {(char_u *)NULL, (char_u *)0L}
1336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001337 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001338 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1340 (char_u *)&p_guifontset, PV_NONE,
1341 {(char_u *)"", (char_u *)0L}
1342#else
1343 (char_u *)NULL, PV_NONE,
1344 {(char_u *)NULL, (char_u *)0L}
1345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001347 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1349 (char_u *)&p_guifontwide, PV_NONE,
1350 {(char_u *)"", (char_u *)0L}
1351#else
1352 (char_u *)NULL, PV_NONE,
1353 {(char_u *)NULL, (char_u *)0L}
1354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001357#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358 (char_u *)&p_ghr, PV_NONE,
1359#else
1360 (char_u *)NULL, PV_NONE,
1361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001362 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001364#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 (char_u *)&p_go, PV_NONE,
1366# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001367 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001369 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370# endif
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001375 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 {"guipty", NULL, P_BOOL|P_VI_DEF,
1377#if defined(FEAT_GUI)
1378 (char_u *)&p_guipty, PV_NONE,
1379#else
1380 (char_u *)NULL, PV_NONE,
1381#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001383 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001384#if defined(FEAT_GUI_TABLINE)
1385 (char_u *)&p_gtl, PV_NONE,
1386 {(char_u *)"", (char_u *)0L}
1387#else
1388 (char_u *)NULL, PV_NONE,
1389 {(char_u *)NULL, (char_u *)0L}
1390#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001391 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001392 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001393#if defined(FEAT_GUI_TABLINE)
1394 (char_u *)&p_gtt, PV_NONE,
1395 {(char_u *)"", (char_u *)0L}
1396#else
1397 (char_u *)NULL, PV_NONE,
1398 {(char_u *)NULL, (char_u *)0L}
1399#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001401 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1402 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1405 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001406 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1407 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"helpheight", "hh", P_NUM|P_VI_DEF,
1409#ifdef FEAT_WINDOWS
1410 (char_u *)&p_hh, PV_NONE,
1411#else
1412 (char_u *)NULL, PV_NONE,
1413#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001415 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#ifdef FEAT_MULTI_LANG
1417 (char_u *)&p_hlg, PV_NONE,
1418 {(char_u *)"", (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)0L, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"hidden", "hid", P_BOOL|P_VI_DEF,
1425 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001427 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001429 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1430 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"history", "hi", P_NUM|P_VIM,
1432 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001433 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1435#ifdef FEAT_RIGHTLEFT
1436 (char_u *)&p_hkmap, PV_NONE,
1437#else
1438 (char_u *)NULL, PV_NONE,
1439#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001440 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1442#ifdef FEAT_RIGHTLEFT
1443 (char_u *)&p_hkmapp, PV_NONE,
1444#else
1445 (char_u *)NULL, PV_NONE,
1446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1449 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"icon", NULL, P_BOOL|P_VI_DEF,
1452#ifdef FEAT_TITLE
1453 (char_u *)&p_icon, PV_NONE,
1454#else
1455 (char_u *)NULL, PV_NONE,
1456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001457 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"iconstring", NULL, P_STRING|P_VI_DEF,
1459#ifdef FEAT_TITLE
1460 (char_u *)&p_iconstring, PV_NONE,
1461#else
1462 (char_u *)NULL, PV_NONE,
1463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1466 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001467 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001468 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1469# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1470 (char_u *)&p_imaf, PV_NONE,
1471 {(char_u *)"", (char_u *)NULL}
1472# else
1473 (char_u *)NULL, PV_NONE,
1474 {(char_u *)NULL, (char_u *)0L}
1475# endif
1476 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001478#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 (char_u *)&p_imak, PV_NONE,
1480#else
1481 (char_u *)NULL, PV_NONE,
1482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001483 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1485#ifdef USE_IM_CONTROL
1486 (char_u *)&p_imcmdline, PV_NONE,
1487#else
1488 (char_u *)NULL, PV_NONE,
1489#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1492#ifdef USE_IM_CONTROL
1493 (char_u *)&p_imdisable, PV_NONE,
1494#else
1495 (char_u *)NULL, PV_NONE,
1496#endif
1497#ifdef __sgi
1498 {(char_u *)TRUE, (char_u *)0L}
1499#else
1500 {(char_u *)FALSE, (char_u *)0L}
1501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"iminsert", "imi", P_NUM|P_VI_DEF,
1504 (char_u *)&p_iminsert, PV_IMI,
1505#ifdef B_IMODE_IM
1506 {(char_u *)B_IMODE_IM, (char_u *)0L}
1507#else
1508 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001510 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"imsearch", "ims", P_NUM|P_VI_DEF,
1512 (char_u *)&p_imsearch, PV_IMS,
1513#ifdef B_IMODE_IM
1514 {(char_u *)B_IMODE_IM, (char_u *)0L}
1515#else
1516 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001519 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001520# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1521 (char_u *)&p_imsf, PV_NONE,
1522 {(char_u *)"", (char_u *)NULL}
1523# else
1524 (char_u *)NULL, PV_NONE,
1525 {(char_u *)NULL, (char_u *)0L}
1526# endif
1527 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1529#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001530 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1532#else
1533 (char_u *)NULL, PV_NONE,
1534 {(char_u *)0L, (char_u *)0L}
1535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1538#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1539 (char_u *)&p_inex, PV_INEX,
1540 {(char_u *)"", (char_u *)0L}
1541#else
1542 (char_u *)NULL, PV_NONE,
1543 {(char_u *)0L, (char_u *)0L}
1544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1547 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1550#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1551 (char_u *)&p_inde, PV_INDE,
1552 {(char_u *)"", (char_u *)0L}
1553#else
1554 (char_u *)NULL, PV_NONE,
1555 {(char_u *)0L, (char_u *)0L}
1556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001557 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001558 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1560 (char_u *)&p_indk, PV_INDK,
1561 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1562#else
1563 (char_u *)NULL, PV_NONE,
1564 {(char_u *)0L, (char_u *)0L}
1565#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"infercase", "inf", P_BOOL|P_VI_DEF,
1568 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1571 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001573 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1574 (char_u *)&p_isf, PV_NONE,
1575 {
1576#ifdef BACKSLASH_IN_FILENAME
1577 /* Excluded are: & and ^ are special in cmd.exe
1578 * ( and ) are used in text separating fnames */
1579 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1580#else
1581# ifdef AMIGA
1582 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1583# else
1584# ifdef VMS
1585 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1586# else /* UNIX et al. */
1587# ifdef EBCDIC
1588 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1589# else
1590 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1591# endif
1592# endif
1593# endif
1594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001595 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1597 (char_u *)&p_isi, PV_NONE,
1598 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001599#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 (char_u *)"@,48-57,_,128-167,224-235",
1601#else
1602# ifdef EBCDIC
1603 /* TODO: EBCDIC Check this! @ == isalpha()*/
1604 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1605 "112-120,128,140-142,156,158,172,"
1606 "174,186,191,203-207,219-225,235-239,"
1607 "251-254",
1608# else
1609 (char_u *)"@,48-57,_,192-255",
1610# endif
1611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001612 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1614 (char_u *)&p_isk, PV_ISK,
1615 {
1616#ifdef EBCDIC
1617 (char_u *)"@,240-249,_",
1618 /* TODO: EBCDIC Check this! @ == isalpha()*/
1619 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1620 "112-120,128,140-142,156,158,172,"
1621 "174,186,191,203-207,219-225,235-239,"
1622 "251-254",
1623#else
1624 (char_u *)"@,48-57,_",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001625# if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 (char_u *)"@,48-57,_,128-167,224-235"
1627# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001628 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629# endif
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1633 (char_u *)&p_isp, PV_NONE,
1634 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001635#if defined(MSDOS) || defined(MSWIN) \
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001636 || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001637 || defined(VMS)
1638 (char_u *)"@,~-255",
1639#else
1640# ifdef EBCDIC
1641 /* all chars above 63 are printable */
1642 (char_u *)"63-255",
1643# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001644 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645# endif
1646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001647 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001648 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1649 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001650 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1652#ifdef FEAT_CRYPT
1653 (char_u *)&p_key, PV_KEY,
1654 {(char_u *)"", (char_u *)0L}
1655#else
1656 (char_u *)NULL, PV_NONE,
1657 {(char_u *)0L, (char_u *)0L}
1658#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001659 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001660 {"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 +00001661#ifdef FEAT_KEYMAP
1662 (char_u *)&p_keymap, PV_KMAP,
1663 {(char_u *)"", (char_u *)0L}
1664#else
1665 (char_u *)NULL, PV_NONE,
1666 {(char_u *)"", (char_u *)0L}
1667#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001668 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001669 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001670 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001671 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001673 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001674 {
1675#if defined(MSDOS) || defined(MSWIN)
1676 (char_u *)":help",
1677#else
1678#ifdef VMS
1679 (char_u *)"help",
1680#else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001681# ifdef USEMAN_S
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 (char_u *)"man -s",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001683# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001684 (char_u *)"man",
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685# endif
1686#endif
1687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001688 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001689 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001690#ifdef FEAT_LANGMAP
1691 (char_u *)&p_langmap, PV_NONE,
1692 {(char_u *)"", /* unmatched } */
1693#else
1694 (char_u *)NULL, PV_NONE,
1695 {(char_u *)NULL,
1696#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001697 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001698 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1700 (char_u *)&p_lm, PV_NONE,
1701#else
1702 (char_u *)NULL, PV_NONE,
1703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001704 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001705 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1706#ifdef FEAT_LANGMAP
1707 (char_u *)&p_lnr, PV_NONE,
1708#else
1709 (char_u *)NULL, PV_NONE,
1710#endif
1711 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1713#ifdef FEAT_WINDOWS
1714 (char_u *)&p_ls, PV_NONE,
1715#else
1716 (char_u *)NULL, PV_NONE,
1717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001718 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001719 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1720 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001722 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1723#ifdef FEAT_LINEBREAK
1724 (char_u *)VAR_WIN, PV_LBR,
1725#else
1726 (char_u *)NULL, PV_NONE,
1727#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001728 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1730 (char_u *)&Rows, PV_NONE,
1731 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001732#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 (char_u *)25L,
1734#else
1735 (char_u *)24L,
1736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001737 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1739#ifdef FEAT_GUI
1740 (char_u *)&p_linespace, PV_NONE,
1741#else
1742 (char_u *)NULL, PV_NONE,
1743#endif
1744#ifdef FEAT_GUI_W32
1745 {(char_u *)1L, (char_u *)0L}
1746#else
1747 {(char_u *)0L, (char_u *)0L}
1748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"lisp", NULL, P_BOOL|P_VI_DEF,
1751#ifdef FEAT_LISP
1752 (char_u *)&p_lisp, PV_LISP,
1753#else
1754 (char_u *)NULL, PV_NONE,
1755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001757 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001758#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001759 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001760 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1761#else
1762 (char_u *)NULL, PV_NONE,
1763 {(char_u *)"", (char_u *)0L}
1764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001765 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1767 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001769 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1773 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001774 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001775#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001776 {"luadll", NULL, P_STRING|P_VI_DEF|P_SECURE,
1777 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001778 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1779 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001780#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001781#ifdef FEAT_GUI_MAC
1782 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1783 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001785#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 {"magic", NULL, P_BOOL|P_VI_DEF,
1787 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001789 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790#ifdef FEAT_QUICKFIX
1791 (char_u *)&p_mef, PV_NONE,
1792 {(char_u *)"", (char_u *)0L}
1793#else
1794 (char_u *)NULL, PV_NONE,
1795 {(char_u *)NULL, (char_u *)0L}
1796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001797 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001798 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1799#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001800 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001801# ifdef VMS
1802 {(char_u *)"MMS", (char_u *)0L}
1803# else
1804 {(char_u *)"make", (char_u *)0L}
1805# endif
1806#else
1807 (char_u *)NULL, PV_NONE,
1808 {(char_u *)NULL, (char_u *)0L}
1809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001810 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001811 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001813 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1814 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 {"matchtime", "mat", P_NUM|P_VI_DEF,
1816 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001817 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001818 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001819#ifdef FEAT_MBYTE
1820 (char_u *)&p_mco, PV_NONE,
1821#else
1822 (char_u *)NULL, PV_NONE,
1823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001824 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1826#ifdef FEAT_EVAL
1827 (char_u *)&p_mfd, PV_NONE,
1828#else
1829 (char_u *)NULL, PV_NONE,
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1833 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001835 {"maxmem", "mm", P_NUM|P_VI_DEF,
1836 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1838 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001839 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1840 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1843 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1845 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"menuitems", "mis", P_NUM|P_VI_DEF,
1847#ifdef FEAT_MENU
1848 (char_u *)&p_mis, PV_NONE,
1849#else
1850 (char_u *)NULL, PV_NONE,
1851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001852 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"mesg", NULL, P_BOOL|P_VI_DEF,
1854 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001856 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001857#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001858 (char_u *)&p_msm, PV_NONE,
1859 {(char_u *)"460000,2000,500", (char_u *)0L}
1860#else
1861 (char_u *)NULL, PV_NONE,
1862 {(char_u *)0L, (char_u *)0L}
1863#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001864 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 {"modeline", "ml", P_BOOL|P_VIM,
1866 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"modelines", "mls", P_NUM|P_VI_DEF,
1869 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1872 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001873 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1875 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"more", NULL, P_BOOL|P_VIM,
1878 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1881 (char_u *)&p_mouse, PV_NONE,
1882 {
1883#if defined(MSDOS) || defined(WIN3264)
1884 (char_u *)"a",
1885#else
1886 (char_u *)"",
1887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001888 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1890#ifdef FEAT_GUI
1891 (char_u *)&p_mousef, PV_NONE,
1892#else
1893 (char_u *)NULL, PV_NONE,
1894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1897#ifdef FEAT_GUI
1898 (char_u *)&p_mh, PV_NONE,
1899#else
1900 (char_u *)NULL, PV_NONE,
1901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1904 (char_u *)&p_mousem, PV_NONE,
1905 {
1906#if defined(MSDOS) || defined(MSWIN)
1907 (char_u *)"popup",
1908#else
1909# if defined(MACOS)
1910 (char_u *)"popup_setpos",
1911# else
1912 (char_u *)"extend",
1913# endif
1914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001916 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917#ifdef FEAT_MOUSESHAPE
1918 (char_u *)&p_mouseshape, PV_NONE,
1919 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1920#else
1921 (char_u *)NULL, PV_NONE,
1922 {(char_u *)NULL, (char_u *)0L}
1923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001924 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1926 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001928 {"mzquantum", "mzq", P_NUM,
1929#ifdef FEAT_MZSCHEME
1930 (char_u *)&p_mzq, PV_NONE,
1931#else
1932 (char_u *)NULL, PV_NONE,
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"novice", NULL, P_BOOL|P_VI_DEF,
1936 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001938 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001940 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1943 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001945 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1946#ifdef FEAT_LINEBREAK
1947 (char_u *)VAR_WIN, PV_NUW,
1948#else
1949 (char_u *)NULL, PV_NONE,
1950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001952 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001953#ifdef FEAT_COMPL_FUNC
1954 (char_u *)&p_ofu, PV_OFU,
1955 {(char_u *)"", (char_u *)0L}
1956#else
1957 (char_u *)NULL, PV_NONE,
1958 {(char_u *)0L, (char_u *)0L}
1959#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001960 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961 {"open", NULL, P_BOOL|P_VI_DEF,
1962 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001963 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001964 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001965#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001966 (char_u *)&p_odev, PV_NONE,
1967#else
1968 (char_u *)NULL, PV_NONE,
1969#endif
1970 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001971 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001972 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1973 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 {"optimize", "opt", P_BOOL|P_VI_DEF,
1976 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001980 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"paragraphs", "para", P_STRING|P_VI_DEF,
1982 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001983 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001985 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
1989 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
1992#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1993 (char_u *)&p_pex, PV_NONE,
1994 {(char_u *)"", (char_u *)0L}
1995#else
1996 (char_u *)NULL, PV_NONE,
1997 {(char_u *)0L, (char_u *)0L}
1998#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001999 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002000 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002002 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002004 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002005 {
2006#if defined AMIGA || defined MSDOS || defined MSWIN
2007 (char_u *)".,,",
2008#else
2009# if defined(__EMX__)
2010 (char_u *)".,/emx/include,,",
2011# else /* Unix, probably */
2012 (char_u *)".,/usr/include,,",
2013# endif
2014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002016#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002017 {"perldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2018 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002019 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2020 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002021#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2023 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002024 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002025 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2027 (char_u *)&p_pvh, PV_NONE,
2028#else
2029 (char_u *)NULL, PV_NONE,
2030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002031 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2033#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2034 (char_u *)VAR_WIN, PV_PVW,
2035#else
2036 (char_u *)NULL, PV_NONE,
2037#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002038 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002039 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040#ifdef FEAT_PRINTER
2041 (char_u *)&p_pdev, PV_NONE,
2042 {(char_u *)"", (char_u *)0L}
2043#else
2044 (char_u *)NULL, PV_NONE,
2045 {(char_u *)NULL, (char_u *)0L}
2046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002047 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002048 {"printencoding", "penc", P_STRING|P_VI_DEF,
2049#ifdef FEAT_POSTSCRIPT
2050 (char_u *)&p_penc, PV_NONE,
2051 {(char_u *)"", (char_u *)0L}
2052#else
2053 (char_u *)NULL, PV_NONE,
2054 {(char_u *)NULL, (char_u *)0L}
2055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002057 {"printexpr", "pexpr", P_STRING|P_VI_DEF,
2058#ifdef FEAT_POSTSCRIPT
2059 (char_u *)&p_pexpr, PV_NONE,
2060 {(char_u *)"", (char_u *)0L}
2061#else
2062 (char_u *)NULL, PV_NONE,
2063 {(char_u *)NULL, (char_u *)0L}
2064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002065 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 {"printfont", "pfn", P_STRING|P_VI_DEF,
2067#ifdef FEAT_PRINTER
2068 (char_u *)&p_pfn, PV_NONE,
2069 {
2070# ifdef MSWIN
2071 (char_u *)"Courier_New:h10",
2072# else
2073 (char_u *)"courier",
2074# endif
2075 (char_u *)0L}
2076#else
2077 (char_u *)NULL, PV_NONE,
2078 {(char_u *)NULL, (char_u *)0L}
2079#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2082#ifdef FEAT_PRINTER
2083 (char_u *)&p_header, PV_NONE,
2084 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2085#else
2086 (char_u *)NULL, PV_NONE,
2087 {(char_u *)NULL, (char_u *)0L}
2088#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002089 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002090 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2091#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2092 (char_u *)&p_pmcs, PV_NONE,
2093 {(char_u *)"", (char_u *)0L}
2094#else
2095 (char_u *)NULL, PV_NONE,
2096 {(char_u *)NULL, (char_u *)0L}
2097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002099 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2100#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2101 (char_u *)&p_pmfn, PV_NONE,
2102 {(char_u *)"", (char_u *)0L}
2103#else
2104 (char_u *)NULL, PV_NONE,
2105 {(char_u *)NULL, (char_u *)0L}
2106#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002108 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109#ifdef FEAT_PRINTER
2110 (char_u *)&p_popt, PV_NONE,
2111 {(char_u *)"", (char_u *)0L}
2112#else
2113 (char_u *)NULL, PV_NONE,
2114 {(char_u *)NULL, (char_u *)0L}
2115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002118 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002119 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002120 {"pumheight", "ph", P_NUM|P_VI_DEF,
2121#ifdef FEAT_INS_EXPAND
2122 (char_u *)&p_ph, PV_NONE,
2123#else
2124 (char_u *)NULL, PV_NONE,
2125#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002126 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002127#if defined(DYNAMIC_PYTHON3)
Bram Moolenaar0796c062015-11-10 19:41:37 +01002128 {"pythonthreedll", NULL, P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002129 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002130 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2131 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002132#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002133#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002134 {"pythondll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2135 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002136 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2137 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002138#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002139 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2140#ifdef FEAT_TEXTOBJ
2141 (char_u *)&p_qe, PV_QE,
2142 {(char_u *)"\\", (char_u *)0L}
2143#else
2144 (char_u *)NULL, PV_NONE,
2145 {(char_u *)NULL, (char_u *)0L}
2146#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002147 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002148 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2149 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002150 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002151 {"redraw", NULL, P_BOOL|P_VI_DEF,
2152 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002153 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002154 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2155#ifdef FEAT_RELTIME
2156 (char_u *)&p_rdt, PV_NONE,
2157#else
2158 (char_u *)NULL, PV_NONE,
2159#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002161 {"regexpengine", "re", P_NUM|P_VI_DEF,
2162 (char_u *)&p_re, PV_NONE,
2163 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002164 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2165 (char_u *)VAR_WIN, PV_RNU,
2166 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002167 {"remap", NULL, P_BOOL|P_VI_DEF,
2168 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002169 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002170 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002171#ifdef FEAT_RENDER_OPTIONS
2172 (char_u *)&p_rop, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)NULL, (char_u *)0L}
2177#endif
2178 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"report", NULL, P_NUM|P_VI_DEF,
2180 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002181 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2183#ifdef WIN3264
2184 (char_u *)&p_rs, PV_NONE,
2185#else
2186 (char_u *)NULL, PV_NONE,
2187#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002188 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002189 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2190#ifdef FEAT_RIGHTLEFT
2191 (char_u *)&p_ri, PV_NONE,
2192#else
2193 (char_u *)NULL, PV_NONE,
2194#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002195 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002196 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2197#ifdef FEAT_RIGHTLEFT
2198 (char_u *)VAR_WIN, PV_RL,
2199#else
2200 (char_u *)NULL, PV_NONE,
2201#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002202 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2204#ifdef FEAT_RIGHTLEFT
2205 (char_u *)VAR_WIN, PV_RLC,
2206 {(char_u *)"search", (char_u *)NULL}
2207#else
2208 (char_u *)NULL, PV_NONE,
2209 {(char_u *)NULL, (char_u *)0L}
2210#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002211 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002212#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002213 {"rubydll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2214 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002215 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2216 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002217#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002218 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2219#ifdef FEAT_CMDL_INFO
2220 (char_u *)&p_ru, PV_NONE,
2221#else
2222 (char_u *)NULL, PV_NONE,
2223#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002224 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002225 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2226#ifdef FEAT_STL_OPT
2227 (char_u *)&p_ruf, PV_NONE,
2228#else
2229 (char_u *)NULL, PV_NONE,
2230#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002231 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002232 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2233 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002235 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2236 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2238 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002239 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002240 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2241#ifdef FEAT_SCROLLBIND
2242 (char_u *)VAR_WIN, PV_SCBIND,
2243#else
2244 (char_u *)NULL, PV_NONE,
2245#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002246 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2248 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002249 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2251 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002252 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002253 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254#ifdef FEAT_SCROLLBIND
2255 (char_u *)&p_sbo, PV_NONE,
2256 {(char_u *)"ver,jump", (char_u *)0L}
2257#else
2258 (char_u *)NULL, PV_NONE,
2259 {(char_u *)0L, (char_u *)0L}
2260#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002261 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262 {"sections", "sect", P_STRING|P_VI_DEF,
2263 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002264 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2265 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2267 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)"inclusive", (char_u *)0L}
2272 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002273 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002275 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002276 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277#ifdef FEAT_SESSION
2278 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002279 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 (char_u *)0L}
2281#else
2282 (char_u *)NULL, PV_NONE,
2283 {(char_u *)0L, (char_u *)0L}
2284#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002285 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2287 (char_u *)&p_sh, PV_NONE,
2288 {
2289#ifdef VMS
2290 (char_u *)"-",
2291#else
2292# if defined(MSDOS)
2293 (char_u *)"command",
2294# else
Bram Moolenaarcf7164a2016-02-20 13:55:06 +01002295# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 (char_u *)"", /* set in set_init_1() */
Bram Moolenaarcf7164a2016-02-20 13:55:06 +01002297# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002298 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002299# endif
2300# endif
2301#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002302 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2304 (char_u *)&p_shcf, PV_NONE,
2305 {
2306#if defined(MSDOS) || defined(MSWIN)
2307 (char_u *)"/c",
2308#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002311 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2313#ifdef FEAT_QUICKFIX
2314 (char_u *)&p_sp, PV_NONE,
2315 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002316#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002318#else
2319 (char_u *)">",
2320#endif
2321 (char_u *)0L}
2322#else
2323 (char_u *)NULL, PV_NONE,
2324 {(char_u *)0L, (char_u *)0L}
2325#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002326 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2328 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2331 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2334#ifdef BACKSLASH_IN_FILENAME
2335 (char_u *)&p_ssl, PV_NONE,
2336#else
2337 (char_u *)NULL, PV_NONE,
2338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002340 {"shelltemp", "stmp", P_BOOL,
2341 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"shelltype", "st", P_NUM|P_VI_DEF,
2344#ifdef AMIGA
2345 (char_u *)&p_st, PV_NONE,
2346#else
2347 (char_u *)NULL, PV_NONE,
2348#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002349 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2351 (char_u *)&p_sxq, PV_NONE,
2352 {
2353#if defined(UNIX) && defined(USE_SYSTEM) && !defined(__EMX__)
2354 (char_u *)"\"",
2355#else
2356 (char_u *)"",
2357#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002359 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2360 (char_u *)&p_sxe, PV_NONE,
2361 {
Bram Moolenaarcf7164a2016-02-20 13:55:06 +01002362#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002363 (char_u *)"\"&|<>()@^",
2364#else
2365 (char_u *)"",
2366#endif
2367 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2369 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2372 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2375 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002376 {(char_u *)"", (char_u *)"filnxtToO"}
2377 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"shortname", "sn", P_BOOL|P_VI_DEF,
2379#ifdef SHORT_FNAME
2380 (char_u *)NULL, PV_NONE,
2381#else
2382 (char_u *)&p_sn, PV_SN,
2383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2386#ifdef FEAT_LINEBREAK
2387 (char_u *)&p_sbr, PV_NONE,
2388#else
2389 (char_u *)NULL, PV_NONE,
2390#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002391 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 {"showcmd", "sc", P_BOOL|P_VIM,
2393#ifdef FEAT_CMDL_INFO
2394 (char_u *)&p_sc, PV_NONE,
2395#else
2396 (char_u *)NULL, PV_NONE,
2397#endif
2398 {(char_u *)FALSE,
2399#ifdef UNIX
2400 (char_u *)FALSE
2401#else
2402 (char_u *)TRUE
2403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2406 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2409 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002410 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 {"showmode", "smd", P_BOOL|P_VIM,
2412 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002414 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2415#ifdef FEAT_WINDOWS
2416 (char_u *)&p_stal, PV_NONE,
2417#else
2418 (char_u *)NULL, PV_NONE,
2419#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002420 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2422 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2425 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002426 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2428 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2431 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002432 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2434#ifdef FEAT_SMARTINDENT
2435 (char_u *)&p_si, PV_SI,
2436#else
2437 (char_u *)NULL, PV_NONE,
2438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002439 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2441 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2444 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2447 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002449 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002450#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002451 (char_u *)VAR_WIN, PV_SPELL,
2452#else
2453 (char_u *)NULL, PV_NONE,
2454#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002455 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002456 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002457#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002458 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002459 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002460#else
2461 (char_u *)NULL, PV_NONE,
2462 {(char_u *)0L, (char_u *)0L}
2463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002464 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002465 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2466 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002467#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002468 (char_u *)&p_spf, PV_SPF,
2469 {(char_u *)"", (char_u *)0L}
2470#else
2471 (char_u *)NULL, PV_NONE,
2472 {(char_u *)0L, (char_u *)0L}
2473#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002474 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002475 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2476 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002477#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002478 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002479 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002480#else
2481 (char_u *)NULL, PV_NONE,
2482 {(char_u *)0L, (char_u *)0L}
2483#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002484 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002485 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002486#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002487 (char_u *)&p_sps, PV_NONE,
2488 {(char_u *)"best", (char_u *)0L}
2489#else
2490 (char_u *)NULL, PV_NONE,
2491 {(char_u *)0L, (char_u *)0L}
2492#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002493 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2495#ifdef FEAT_WINDOWS
2496 (char_u *)&p_sb, PV_NONE,
2497#else
2498 (char_u *)NULL, PV_NONE,
2499#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"splitright", "spr", P_BOOL|P_VI_DEF,
2502#ifdef FEAT_VERTSPLIT
2503 (char_u *)&p_spr, PV_NONE,
2504#else
2505 (char_u *)NULL, PV_NONE,
2506#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2509 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2512#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002513 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514#else
2515 (char_u *)NULL, PV_NONE,
2516#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002517 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002518 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 (char_u *)&p_su, PV_NONE,
2520 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002522 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002523#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 (char_u *)&p_sua, PV_SUA,
2525 {(char_u *)"", (char_u *)0L}
2526#else
2527 (char_u *)NULL, PV_NONE,
2528 {(char_u *)0L, (char_u *)0L}
2529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002530 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2532 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"swapsync", "sws", P_STRING|P_VI_DEF,
2535 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002537 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002540 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2541#ifdef FEAT_SYN_HL
2542 (char_u *)&p_smc, PV_SMC,
2543 {(char_u *)3000L, (char_u *)0L}
2544#else
2545 (char_u *)NULL, PV_NONE,
2546 {(char_u *)0L, (char_u *)0L}
2547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002548 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002549 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002550#ifdef FEAT_SYN_HL
2551 (char_u *)&p_syn, PV_SYN,
2552 {(char_u *)"", (char_u *)0L}
2553#else
2554 (char_u *)NULL, PV_NONE,
2555 {(char_u *)0L, (char_u *)0L}
2556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002558 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2559#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002560 (char_u *)&p_tal, PV_NONE,
2561#else
2562 (char_u *)NULL, PV_NONE,
2563#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002565 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2566#ifdef FEAT_WINDOWS
2567 (char_u *)&p_tpm, PV_NONE,
2568#else
2569 (char_u *)NULL, PV_NONE,
2570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2573 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2576 (char_u *)&p_tbs, PV_NONE,
2577#ifdef VMS /* binary searching doesn't appear to work on VMS */
2578 {(char_u *)0L, (char_u *)0L}
2579#else
2580 {(char_u *)TRUE, (char_u *)0L}
2581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002583 {"tagcase", "tc", P_STRING|P_VIM,
2584 (char_u *)&p_tc, PV_TC,
2585 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 {"taglength", "tl", P_NUM|P_VI_DEF,
2587 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002588 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589 {"tagrelative", "tr", P_BOOL|P_VIM,
2590 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002592 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002593 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {
2595#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2596 (char_u *)"./tags,./TAGS,tags,TAGS",
2597#else
2598 (char_u *)"./tags,tags",
2599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002600 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002601 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2602 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002604#if defined(DYNAMIC_TCL)
2605 {"tcldll", NULL, P_STRING|P_VI_DEF|P_SECURE,
2606 (char_u *)&p_tcldll, PV_NONE,
2607 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2608 SCRIPTID_INIT},
2609#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2611 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002612 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2614#ifdef FEAT_ARABIC
2615 (char_u *)&p_tbidi, PV_NONE,
2616#else
2617 (char_u *)NULL, PV_NONE,
2618#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002619 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002620 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2621#ifdef FEAT_MBYTE
2622 (char_u *)&p_tenc, PV_NONE,
2623 {(char_u *)"", (char_u *)0L}
2624#else
2625 (char_u *)NULL, PV_NONE,
2626 {(char_u *)0L, (char_u *)0L}
2627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002628 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 {"terse", NULL, P_BOOL|P_VI_DEF,
2630 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002631 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002632 {"textauto", "ta", P_BOOL|P_VIM,
2633 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2635 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2637 (char_u *)&p_tx, PV_TX,
2638 {
2639#ifdef USE_CRNL
2640 (char_u *)TRUE,
2641#else
2642 (char_u *)FALSE,
2643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002645 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002647 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002648 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002650 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651#else
2652 (char_u *)NULL, PV_NONE,
2653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2656 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 {"timeout", "to", P_BOOL|P_VI_DEF,
2659 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2662 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 {"title", NULL, P_BOOL|P_VI_DEF,
2665#ifdef FEAT_TITLE
2666 (char_u *)&p_title, PV_NONE,
2667#else
2668 (char_u *)NULL, PV_NONE,
2669#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002671 {"titlelen", NULL, P_NUM|P_VI_DEF,
2672#ifdef FEAT_TITLE
2673 (char_u *)&p_titlelen, PV_NONE,
2674#else
2675 (char_u *)NULL, PV_NONE,
2676#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002678 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679#ifdef FEAT_TITLE
2680 (char_u *)&p_titleold, PV_NONE,
2681 {(char_u *)N_("Thanks for flying Vim"),
2682 (char_u *)0L}
2683#else
2684 (char_u *)NULL, PV_NONE,
2685 {(char_u *)0L, (char_u *)0L}
2686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688 {"titlestring", NULL, P_STRING|P_VI_DEF,
2689#ifdef FEAT_TITLE
2690 (char_u *)&p_titlestring, PV_NONE,
2691#else
2692 (char_u *)NULL, PV_NONE,
2693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002695#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002696 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)"icons,tooltips", (char_u *)0L}
2699 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002701#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2703 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705#endif
2706 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2707 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002709 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2710 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2713 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2716 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002717 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2719#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2720 (char_u *)&p_ttym, PV_NONE,
2721#else
2722 (char_u *)NULL, PV_NONE,
2723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002724 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2726 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2729 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002731 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2732 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002733#ifdef FEAT_PERSISTENT_UNDO
2734 (char_u *)&p_udir, PV_NONE,
2735 {(char_u *)".", (char_u *)0L}
2736#else
2737 (char_u *)NULL, PV_NONE,
2738 {(char_u *)0L, (char_u *)0L}
2739#endif
2740 SCRIPTID_INIT},
2741 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2742#ifdef FEAT_PERSISTENT_UNDO
2743 (char_u *)&p_udf, PV_UDF,
2744#else
2745 (char_u *)NULL, PV_NONE,
2746#endif
2747 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002749 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002751#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 (char_u *)1000L,
2753#else
2754 (char_u *)100L,
2755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002756 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002757 {"undoreload", "ur", P_NUM|P_VI_DEF,
2758 (char_u *)&p_ur, PV_NONE,
2759 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"updatecount", "uc", P_NUM|P_VI_DEF,
2761 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002762 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"updatetime", "ut", P_NUM|P_VI_DEF,
2764 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002765 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766 {"verbose", "vbs", P_NUM|P_VI_DEF,
2767 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002768 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002769 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2770 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002771 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2773#ifdef FEAT_SESSION
2774 (char_u *)&p_vdir, PV_NONE,
2775 {(char_u *)DFLT_VDIR, (char_u *)0L}
2776#else
2777 (char_u *)NULL, PV_NONE,
2778 {(char_u *)0L, (char_u *)0L}
2779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002780 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002781 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782#ifdef FEAT_SESSION
2783 (char_u *)&p_vop, PV_NONE,
2784 {(char_u *)"folds,options,cursor", (char_u *)0L}
2785#else
2786 (char_u *)NULL, PV_NONE,
2787 {(char_u *)0L, (char_u *)0L}
2788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002789 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002790 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791#ifdef FEAT_VIMINFO
2792 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002793#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002794 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795#else
2796# ifdef AMIGA
2797 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002798 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002800 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002801# endif
2802#endif
2803#else
2804 (char_u *)NULL, PV_NONE,
2805 {(char_u *)0L, (char_u *)0L}
2806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002808 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2809 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810#ifdef FEAT_VIRTUALEDIT
2811 (char_u *)&p_ve, PV_NONE,
2812 {(char_u *)"", (char_u *)""}
2813#else
2814 (char_u *)NULL, PV_NONE,
2815 {(char_u *)0L, (char_u *)0L}
2816#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002817 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2819 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002820 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"w300", NULL, P_NUM|P_VI_DEF,
2822 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002823 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"w1200", NULL, P_NUM|P_VI_DEF,
2825 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"w9600", NULL, P_NUM|P_VI_DEF,
2828 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"warn", NULL, P_BOOL|P_VI_DEF,
2831 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2834 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002835 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002836 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 {"wildchar", "wc", P_NUM|P_VIM,
2840 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002841 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2842 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002843 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002846 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847#ifdef FEAT_WILDIGN
2848 (char_u *)&p_wig, PV_NONE,
2849#else
2850 (char_u *)NULL, PV_NONE,
2851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002853 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2854 (char_u *)&p_wic, PV_NONE,
2855 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2857#ifdef FEAT_WILDMENU
2858 (char_u *)&p_wmnu, PV_NONE,
2859#else
2860 (char_u *)NULL, PV_NONE,
2861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002863 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002865 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002866 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2867#ifdef FEAT_CMDL_COMPL
2868 (char_u *)&p_wop, PV_NONE,
2869 {(char_u *)"", (char_u *)0L}
2870#else
2871 (char_u *)NULL, PV_NONE,
2872 {(char_u *)NULL, (char_u *)0L}
2873#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002874 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002875 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2876#ifdef FEAT_WAK
2877 (char_u *)&p_wak, PV_NONE,
2878 {(char_u *)"menu", (char_u *)0L}
2879#else
2880 (char_u *)NULL, PV_NONE,
2881 {(char_u *)NULL, (char_u *)0L}
2882#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002883 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002885 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"winheight", "wh", P_NUM|P_VI_DEF,
2888#ifdef FEAT_WINDOWS
2889 (char_u *)&p_wh, PV_NONE,
2890#else
2891 (char_u *)NULL, PV_NONE,
2892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002895#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896 (char_u *)VAR_WIN, PV_WFH,
2897#else
2898 (char_u *)NULL, PV_NONE,
2899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002901 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
2902#ifdef FEAT_VERTSPLIT
2903 (char_u *)VAR_WIN, PV_WFW,
2904#else
2905 (char_u *)NULL, PV_NONE,
2906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002907 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2909#ifdef FEAT_WINDOWS
2910 (char_u *)&p_wmh, PV_NONE,
2911#else
2912 (char_u *)NULL, PV_NONE,
2913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002915 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
2916#ifdef FEAT_VERTSPLIT
2917 (char_u *)&p_wmw, PV_NONE,
2918#else
2919 (char_u *)NULL, PV_NONE,
2920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002921 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"winwidth", "wiw", P_NUM|P_VI_DEF,
2923#ifdef FEAT_VERTSPLIT
2924 (char_u *)&p_wiw, PV_NONE,
2925#else
2926 (char_u *)NULL, PV_NONE,
2927#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002928 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2930 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002931 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2933 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2936 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002937 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938 {"write", NULL, P_BOOL|P_VI_DEF,
2939 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002940 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 {"writeany", "wa", P_BOOL|P_VI_DEF,
2942 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002943 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2945 (char_u *)&p_wb, PV_NONE,
2946 {
2947#ifdef FEAT_WRITEBACKUP
2948 (char_u *)TRUE,
2949#else
2950 (char_u *)FALSE,
2951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002952 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953 {"writedelay", "wd", P_NUM|P_VI_DEF,
2954 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002955 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956
2957/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002958#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002960 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961
2962 p_term("t_AB", T_CAB)
2963 p_term("t_AF", T_CAF)
2964 p_term("t_AL", T_CAL)
2965 p_term("t_al", T_AL)
2966 p_term("t_bc", T_BC)
2967 p_term("t_cd", T_CD)
2968 p_term("t_ce", T_CE)
2969 p_term("t_cl", T_CL)
2970 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002971 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 p_term("t_Co", T_CCO)
2973 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002974 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975 p_term("t_cs", T_CS)
2976#ifdef FEAT_VERTSPLIT
2977 p_term("t_CV", T_CSV)
2978#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 p_term("t_da", T_DA)
2980 p_term("t_db", T_DB)
2981 p_term("t_DL", T_CDL)
2982 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02002983 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984 p_term("t_fs", T_FS)
2985 p_term("t_IE", T_CIE)
2986 p_term("t_IS", T_CIS)
2987 p_term("t_ke", T_KE)
2988 p_term("t_ks", T_KS)
2989 p_term("t_le", T_LE)
2990 p_term("t_mb", T_MB)
2991 p_term("t_md", T_MD)
2992 p_term("t_me", T_ME)
2993 p_term("t_mr", T_MR)
2994 p_term("t_ms", T_MS)
2995 p_term("t_nd", T_ND)
2996 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02002997 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 p_term("t_RI", T_CRI)
2999 p_term("t_RV", T_CRV)
3000 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003002 p_term("t_Sf", T_CSF)
3003 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003005 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 p_term("t_te", T_TE)
3008 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003009 p_term("t_ts", T_TS)
3010 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_ue", T_UE)
3012 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003013 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 p_term("t_vb", T_VB)
3015 p_term("t_ve", T_VE)
3016 p_term("t_vi", T_VI)
3017 p_term("t_vs", T_VS)
3018 p_term("t_WP", T_CWP)
3019 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003020 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 p_term("t_xs", T_XS)
3022 p_term("t_ZH", T_CZH)
3023 p_term("t_ZR", T_CZR)
3024
3025/* terminal key codes are not in here */
3026
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003027 /* end marker */
3028 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029};
3030
3031#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3032
3033#ifdef FEAT_MBYTE
3034static char *(p_ambw_values[]) = {"single", "double", NULL};
3035#endif
3036static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003037static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003039#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003040static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003041#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003042#ifdef FEAT_CMDL_COMPL
3043static char *(p_wop_values[]) = {"tagfile", NULL};
3044#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045#ifdef FEAT_WAK
3046static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3047#endif
3048static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3050static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052#ifdef FEAT_BROWSE
3053static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3054#endif
3055#ifdef FEAT_SCROLLBIND
3056static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3057#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003058static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059#ifdef FEAT_VERTSPLIT
3060static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3061#endif
3062#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003063# ifdef FEAT_AUTOCMD
3064static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3065# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003067# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3069#endif
3070static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3071#ifdef FEAT_FOLDING
3072static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003073# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003075# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 NULL};
3077static char *(p_fcl_values[]) = {"all", NULL};
3078#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003079#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003080static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003081#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003083static void set_option_default(int, int opt_flags, int compatible);
3084static void set_options_default(int opt_flags);
3085static char_u *term_bg_default(void);
3086static void did_set_option(int opt_idx, int opt_flags, int new_value);
3087static char_u *illegal_char(char_u *, int);
3088static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003090static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091#endif
3092#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003093static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003095static char_u *option_expand(int opt_idx, char_u *val);
3096static void didset_options(void);
3097static void didset_options2(void);
3098static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003099#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003100static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003101#else
3102# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3103#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003104static void set_string_option_global(int opt_idx, char_u **varp);
3105static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3106static 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);
3107static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003108#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003109static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003110#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003112static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003114#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003115static char_u *did_set_spell_option(int is_spellfile);
3116static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003117#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003118#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003119static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003120#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003121static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3122static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3123static void check_redraw(long_u flags);
3124static int findoption(char_u *);
3125static int find_key_option(char_u *);
3126static void showoptions(int all, int opt_flags);
3127static int optval_default(struct vimoption *, char_u *varp);
3128static void showoneopt(struct vimoption *, int opt_flags);
3129static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3130static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3131static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3132static int istermoption(struct vimoption *);
3133static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3134static char_u *get_varp(struct vimoption *);
3135static void option_value2string(struct vimoption *, int opt_flags);
3136static void check_winopt(winopt_T *wop);
3137static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003139static void langmap_init(void);
3140static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003142static void paste_option_changed(void);
3143static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003145static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003147static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3148static int check_opt_strings(char_u *val, char **values, int);
3149static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003150#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003151static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003152#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153
3154/*
3155 * Initialize the options, first part.
3156 *
3157 * Called only once from main(), just after creating the first buffer.
3158 */
3159 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003160set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161{
3162 char_u *p;
3163 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003164 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165
3166#ifdef FEAT_LANGMAP
3167 langmap_init();
3168#endif
3169
3170 /* Be Vi compatible by default */
3171 p_cp = TRUE;
3172
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003173 /* Use POSIX compatibility when $VIM_POSIX is set. */
3174 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003175 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003176 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003177 set_string_default("shm", (char_u *)"A");
3178 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003179
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 /*
3181 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003182 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003184 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003185#if defined(MSDOS) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186# ifdef __EMX__
Bram Moolenaar7c626922005-02-07 22:01:03 +00003187 || ((p = mch_getenv((char_u *)"EMXSHELL")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188# endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003189 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003191 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192# endif
3193#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003194 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195 set_string_default("sh", p);
3196
3197#ifdef FEAT_WILDIGN
3198 /*
3199 * Set the default for 'backupskip' to include environment variables for
3200 * temp files.
3201 */
3202 {
3203# ifdef UNIX
3204 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3205# else
3206 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3207# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003208 int len;
3209 garray_T ga;
3210 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211
3212 ga_init2(&ga, 1, 100);
3213 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3214 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003215 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216# ifdef UNIX
3217 if (*names[n] == NUL)
3218 p = (char_u *)"/tmp";
3219 else
3220# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003221 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222 if (p != NULL && *p != NUL)
3223 {
3224 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003225 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 if (ga_grow(&ga, len) == OK)
3227 {
3228 if (ga.ga_len > 0)
3229 STRCAT(ga.ga_data, ",");
3230 STRCAT(ga.ga_data, p);
3231 add_pathsep(ga.ga_data);
3232 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233 ga.ga_len += len;
3234 }
3235 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003236 if (mustfree)
3237 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 }
3239 if (ga.ga_data != NULL)
3240 {
3241 set_string_default("bsk", ga.ga_data);
3242 vim_free(ga.ga_data);
3243 }
3244 }
3245#endif
3246
3247 /*
3248 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3249 */
3250 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003251 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003253#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3254 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3255#endif
3256 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003258 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003259 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260#else
3261# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003262 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003263 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003265 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266# endif
3267#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003269 opt_idx = findoption((char_u *)"maxmem");
3270 if (opt_idx >= 0)
3271 {
3272#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003273 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3274 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003275#endif
3276 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3277 }
3278 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279 }
3280
3281#ifdef FEAT_GUI_W32
3282 /* force 'shortname' for Win32s */
3283 if (gui_is_win32s())
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003284 {
3285 opt_idx = findoption((char_u *)"shortname");
3286 if (opt_idx >= 0)
3287 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)TRUE;
3288 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289#endif
3290
3291#ifdef FEAT_SEARCHPATH
3292 {
3293 char_u *cdpath;
3294 char_u *buf;
3295 int i;
3296 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003297 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298
3299 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003300 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301 if (cdpath != NULL)
3302 {
3303 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3304 if (buf != NULL)
3305 {
3306 buf[0] = ','; /* start with ",", current dir first */
3307 j = 1;
3308 for (i = 0; cdpath[i] != NUL; ++i)
3309 {
3310 if (vim_ispathlistsep(cdpath[i]))
3311 buf[j++] = ',';
3312 else
3313 {
3314 if (cdpath[i] == ' ' || cdpath[i] == ',')
3315 buf[j++] = '\\';
3316 buf[j++] = cdpath[i];
3317 }
3318 }
3319 buf[j] = NUL;
3320 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003321 if (opt_idx >= 0)
3322 {
3323 options[opt_idx].def_val[VI_DEFAULT] = buf;
3324 options[opt_idx].flags |= P_DEF_ALLOCED;
3325 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003326 else
3327 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003329 if (mustfree)
3330 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331 }
3332 }
3333#endif
3334
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003335#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 /* Set print encoding on platforms that don't default to latin1 */
3337 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003338# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339 (char_u *)"cp1252"
3340# else
3341# ifdef VMS
3342 (char_u *)"dec-mcs"
3343# else
3344# ifdef EBCDIC
3345 (char_u *)"ebcdic-uk"
3346# else
3347# ifdef MAC
3348 (char_u *)"mac-roman"
3349# else /* HPUX */
3350 (char_u *)"hp-roman8"
3351# endif
3352# endif
3353# endif
3354# endif
3355 );
3356#endif
3357
3358#ifdef FEAT_POSTSCRIPT
3359 /* 'printexpr' must be allocated to be able to evaluate it. */
3360 set_string_default("pexpr",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003361# if defined(MSWIN) || defined(MSDOS)
Bram Moolenaared203462004-06-16 11:19:22 +00003362 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363# else
3364# ifdef VMS
3365 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3366
3367# else
3368 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3369# endif
3370# endif
3371 );
3372#endif
3373
3374 /*
3375 * Set all the options (except the terminal options) to their default
3376 * value. Also set the global value for local options.
3377 */
3378 set_options_default(0);
3379
3380#ifdef FEAT_GUI
3381 if (found_reverse_arg)
3382 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3383#endif
3384
3385 curbuf->b_p_initialized = TRUE;
3386 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003387 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388 check_buf_options(curbuf);
3389 check_win_options(curwin);
3390 check_options();
3391
3392 /* Must be before option_expand(), because that one needs vim_isIDc() */
3393 didset_options();
3394
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003395#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003396 /* Use the current chartab for the generic chartab. This is not in
3397 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003398 init_spell_chartab();
3399#endif
3400
Bram Moolenaar071d4272004-06-13 20:20:40 +00003401 /*
3402 * Expand environment variables and things like "~" for the defaults.
3403 * If option_expand() returns non-NULL the variable is expanded. This can
3404 * only happen for non-indirect options.
3405 * Also set the default to the expanded value, so ":set" does not list
3406 * them.
3407 * Don't set the P_ALLOCED flag, because we don't want to free the
3408 * default.
3409 */
3410 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3411 {
3412 if ((options[opt_idx].flags & P_GETTEXT)
3413 && options[opt_idx].var != NULL)
3414 p = (char_u *)_(*(char **)options[opt_idx].var);
3415 else
3416 p = option_expand(opt_idx, NULL);
3417 if (p != NULL && (p = vim_strsave(p)) != NULL)
3418 {
3419 *(char_u **)options[opt_idx].var = p;
3420 /* VIMEXP
3421 * Defaults for all expanded options are currently the same for Vi
3422 * and Vim. When this changes, add some code here! Also need to
3423 * split P_DEF_ALLOCED in two.
3424 */
3425 if (options[opt_idx].flags & P_DEF_ALLOCED)
3426 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3427 options[opt_idx].def_val[VI_DEFAULT] = p;
3428 options[opt_idx].flags |= P_DEF_ALLOCED;
3429 }
3430 }
3431
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 save_file_ff(curbuf); /* Buffer is unchanged */
3433
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434#if defined(FEAT_ARABIC)
3435 /* Detect use of mlterm.
3436 * Mlterm is a terminal emulator akin to xterm that has some special
3437 * abilities (bidi namely).
3438 * NOTE: mlterm's author is being asked to 'set' a variable
3439 * instead of an environment variable due to inheritance.
3440 */
3441 if (mch_getenv((char_u *)"MLTERM") != NULL)
3442 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3443#endif
3444
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003445 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003446
3447#ifdef FEAT_MBYTE
3448# if defined(WIN3264) && defined(FEAT_GETTEXT)
3449 /*
3450 * If $LANG isn't set, try to get a good value for it. This makes the
3451 * right language be used automatically. Don't do this for English.
3452 */
3453 if (mch_getenv((char_u *)"LANG") == NULL)
3454 {
3455 char buf[20];
3456
3457 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3458 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3459 * only the first two. */
3460 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3461 (LPTSTR)buf, 20);
3462 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3463 {
3464 /* There are a few exceptions (probably more) */
3465 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3466 STRCPY(buf, "zh_TW");
3467 else if (STRNICMP(buf, "chs", 3) == 0
3468 || STRNICMP(buf, "zhc", 3) == 0)
3469 STRCPY(buf, "zh_CN");
3470 else if (STRNICMP(buf, "jp", 2) == 0)
3471 STRCPY(buf, "ja");
3472 else
3473 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003474 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475 }
3476 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003477# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003478# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003479 /* Moved to os_mac_conv.c to avoid dependency problems. */
3480 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003481# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482# endif
3483
3484 /* enc_locale() will try to find the encoding of the current locale. */
3485 p = enc_locale();
3486 if (p != NULL)
3487 {
3488 char_u *save_enc;
3489
3490 /* Try setting 'encoding' and check if the value is valid.
3491 * If not, go back to the default "latin1". */
3492 save_enc = p_enc;
3493 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003494 if (STRCMP(p_enc, "gb18030") == 0)
3495 {
3496 /* We don't support "gb18030", but "cp936" is a good substitute
3497 * for practical purposes, thus use that. It's not an alias to
3498 * still support conversion between gb18030 and utf-8. */
3499 p_enc = vim_strsave((char_u *)"cp936");
3500 vim_free(p);
3501 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502 if (mb_init() == NULL)
3503 {
3504 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003505 if (opt_idx >= 0)
3506 {
3507 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3508 options[opt_idx].flags |= P_DEF_ALLOCED;
3509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003511#if defined(MSDOS) || defined(MSWIN) || defined(MACOS) \
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003512 || defined(VMS)
3513 if (STRCMP(p_enc, "latin1") == 0
3514# ifdef FEAT_MBYTE
3515 || enc_utf8
3516# endif
3517 )
3518 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003519 /* Adjust the default for 'isprint' and 'iskeyword' to match
3520 * latin1. Also set the defaults for when 'nocompatible' is
3521 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003522 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003523 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003524 set_string_option_direct((char_u *)"isk", -1,
3525 ISK_LATIN1, OPT_FREE, SID_NONE);
3526 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003527 if (opt_idx >= 0)
3528 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003529 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003530 if (opt_idx >= 0)
3531 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003532 (void)init_chartab();
3533 }
3534#endif
3535
Bram Moolenaar071d4272004-06-13 20:20:40 +00003536# if defined(WIN3264) && !defined(FEAT_GUI)
3537 /* Win32 console: When GetACP() returns a different value from
3538 * GetConsoleCP() set 'termencoding'. */
3539 if (GetACP() != GetConsoleCP())
3540 {
3541 char buf[50];
3542
3543 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3544 p_tenc = vim_strsave((char_u *)buf);
3545 if (p_tenc != NULL)
3546 {
3547 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003548 if (opt_idx >= 0)
3549 {
3550 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3551 options[opt_idx].flags |= P_DEF_ALLOCED;
3552 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 convert_setup(&input_conv, p_tenc, p_enc);
3554 convert_setup(&output_conv, p_enc, p_tenc);
3555 }
3556 else
3557 p_tenc = empty_option;
3558 }
3559# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003560# if defined(WIN3264) && defined(FEAT_MBYTE)
3561 /* $HOME may have characters in active code page. */
3562 init_homedir();
3563# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564 }
3565 else
3566 {
3567 vim_free(p_enc);
3568 p_enc = save_enc;
3569 }
3570 }
3571#endif
3572
3573#ifdef FEAT_MULTI_LANG
3574 /* Set the default for 'helplang'. */
3575 set_helplang_default(get_mess_lang());
3576#endif
3577}
3578
3579/*
3580 * Set an option to its default value.
3581 * This does not take care of side effects!
3582 */
3583 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003584set_option_default(
3585 int opt_idx,
3586 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3587 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588{
3589 char_u *varp; /* pointer to variable for current option */
3590 int dvi; /* index in def_val[] */
3591 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003592 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3594
3595 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3596 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003597 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598 {
3599 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3600 if (flags & P_STRING)
3601 {
3602 /* Use set_string_option_direct() for local options to handle
3603 * freeing and allocating the value. */
3604 if (options[opt_idx].indir != PV_NONE)
3605 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003606 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003607 else
3608 {
3609 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3610 free_string_option(*(char_u **)(varp));
3611 *(char_u **)varp = options[opt_idx].def_val[dvi];
3612 options[opt_idx].flags &= ~P_ALLOCED;
3613 }
3614 }
3615 else if (flags & P_NUM)
3616 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003617 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 win_comp_scroll(curwin);
3619 else
3620 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003621 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622 /* May also set global value for local option. */
3623 if (both)
3624 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3625 *(long *)varp;
3626 }
3627 }
3628 else /* P_BOOL */
3629 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003630 /* the cast to long is required for Manx C, long_i is needed for
3631 * MSVC */
3632 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003633#ifdef UNIX
3634 /* 'modeline' defaults to off for root */
3635 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3636 *(int *)varp = FALSE;
3637#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638 /* May also set global value for local option. */
3639 if (both)
3640 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3641 *(int *)varp;
3642 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003643
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003644 /* The default value is not insecure. */
3645 flagsp = insecure_flag(opt_idx, opt_flags);
3646 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003647 }
3648
3649#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003650 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651#endif
3652}
3653
3654/*
3655 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003656 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003657 */
3658 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003659set_options_default(
3660 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661{
3662 int i;
3663#ifdef FEAT_WINDOWS
3664 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003665 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003666#endif
3667
3668 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003669 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003670#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003671 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003672 || (TRUE
3673# if defined(FEAT_MBYTE)
3674 && options[i].var != (char_u *)&p_enc
3675# endif
3676# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003677 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003678 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003679# endif
3680 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003681#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003682 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003683 set_option_default(i, opt_flags, p_cp);
3684
3685#ifdef FEAT_WINDOWS
3686 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003687 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003688 win_comp_scroll(wp);
3689#else
3690 win_comp_scroll(curwin);
3691#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003692#ifdef FEAT_CINDENT
3693 parse_cino(curbuf);
3694#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695}
3696
3697/*
3698 * Set the Vi-default value of a string option.
3699 * Used for 'sh', 'backupskip' and 'term'.
3700 */
3701 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003702set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703{
3704 char_u *p;
3705 int opt_idx;
3706
3707 p = vim_strsave(val);
3708 if (p != NULL) /* we don't want a NULL */
3709 {
3710 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003711 if (opt_idx >= 0)
3712 {
3713 if (options[opt_idx].flags & P_DEF_ALLOCED)
3714 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3715 options[opt_idx].def_val[VI_DEFAULT] = p;
3716 options[opt_idx].flags |= P_DEF_ALLOCED;
3717 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 }
3719}
3720
3721/*
3722 * Set the Vi-default value of a number option.
3723 * Used for 'lines' and 'columns'.
3724 */
3725 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003726set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003728 int opt_idx;
3729
3730 opt_idx = findoption((char_u *)name);
3731 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003732 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733}
3734
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003735#if defined(EXITFREE) || defined(PROTO)
3736/*
3737 * Free all options.
3738 */
3739 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003740free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003741{
3742 int i;
3743
3744 for (i = 0; !istermoption(&options[i]); i++)
3745 {
3746 if (options[i].indir == PV_NONE)
3747 {
3748 /* global option: free value and default value. */
3749 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3750 free_string_option(*(char_u **)options[i].var);
3751 if (options[i].flags & P_DEF_ALLOCED)
3752 free_string_option(options[i].def_val[VI_DEFAULT]);
3753 }
3754 else if (options[i].var != VAR_WIN
3755 && (options[i].flags & P_STRING))
3756 /* buffer-local option: free global value */
3757 free_string_option(*(char_u **)options[i].var);
3758 }
3759}
3760#endif
3761
3762
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763/*
3764 * Initialize the options, part two: After getting Rows and Columns and
3765 * setting 'term'.
3766 */
3767 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003768set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003770 int idx;
3771
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 /*
3773 * 'scroll' defaults to half the window height. Note that this default is
3774 * wrong when the window height changes.
3775 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003776 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003777 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003778 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003779 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780 comp_col();
3781
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003782 /*
3783 * 'window' is only for backwards compatibility with Vi.
3784 * Default is Rows - 1.
3785 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003786 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003787 p_window = Rows - 1;
3788 set_number_default("window", Rows - 1);
3789
Bram Moolenaarf740b292006-02-16 22:11:02 +00003790 /* For DOS console the default is always black. */
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003791#if !((defined(MSDOS) || defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003792 /*
3793 * If 'background' wasn't set by the user, try guessing the value,
3794 * depending on the terminal name. Only need to check for terminals
3795 * with a dark background, that can handle color.
3796 */
3797 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003798 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3799 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003801 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003802 /* don't mark it as set, when starting the GUI it may be
3803 * changed again */
3804 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805 }
3806#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003807
3808#ifdef CURSOR_SHAPE
3809 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3810#endif
3811#ifdef FEAT_MOUSESHAPE
3812 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3813#endif
3814#ifdef FEAT_PRINTER
3815 (void)parse_printoptions(); /* parse 'printoptions' default value */
3816#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817}
3818
3819/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003820 * Return "dark" or "light" depending on the kind of terminal.
3821 * This is just guessing! Recognized are:
3822 * "linux" Linux console
3823 * "screen.linux" Linux console with screen
3824 * "cygwin" Cygwin shell
3825 * "putty" Putty program
3826 * We also check the COLORFGBG environment variable, which is set by
3827 * rxvt and derivatives. This variable contains either two or three
3828 * values separated by semicolons; we want the last value in either
3829 * case. If this value is 0-6 or 8, our background is dark.
3830 */
3831 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003832term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003833{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003834#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003835 /* DOS console nearly always black */
3836 return (char_u *)"dark";
3837#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003838 char_u *p;
3839
Bram Moolenaarf740b292006-02-16 22:11:02 +00003840 if (STRCMP(T_NAME, "linux") == 0
3841 || STRCMP(T_NAME, "screen.linux") == 0
3842 || STRCMP(T_NAME, "cygwin") == 0
3843 || STRCMP(T_NAME, "putty") == 0
3844 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3845 && (p = vim_strrchr(p, ';')) != NULL
3846 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3847 && p[2] == NUL))
3848 return (char_u *)"dark";
3849 return (char_u *)"light";
3850#endif
3851}
3852
3853/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 * Initialize the options, part three: After reading the .vimrc
3855 */
3856 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003857set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003859#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003860/*
3861 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3862 * This is done after other initializations, where 'shell' might have been
3863 * set, but only if they have not been set before.
3864 */
3865 char_u *p;
3866 int idx_srr;
3867 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003868# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 int idx_sp;
3870 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003871# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872
3873 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003874 if (idx_srr < 0)
3875 do_srr = FALSE;
3876 else
3877 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003878# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003880 if (idx_sp < 0)
3881 do_sp = FALSE;
3882 else
3883 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003884# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003885 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003886 if (p != NULL)
3887 {
3888 /*
3889 * Default for p_sp is "| tee", for p_srr is ">".
3890 * For known shells it is changed here to include stderr.
3891 */
3892 if ( fnamecmp(p, "csh") == 0
3893 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003894# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003895 || fnamecmp(p, "csh.exe") == 0
3896 || fnamecmp(p, "tcsh.exe") == 0
3897# endif
3898 )
3899 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003900# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901 if (do_sp)
3902 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003903# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003905# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003907# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3909 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003910# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 if (do_srr)
3912 {
3913 p_srr = (char_u *)">&";
3914 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3915 }
3916 }
3917 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003918 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 if ( fnamecmp(p, "sh") == 0
3920 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003921 || fnamecmp(p, "mksh") == 0
3922 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003924 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003926 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003927# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 || fnamecmp(p, "cmd") == 0
3929 || fnamecmp(p, "sh.exe") == 0
3930 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003931 || fnamecmp(p, "mksh.exe") == 0
3932 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003934 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 || fnamecmp(p, "bash.exe") == 0
3936 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003938 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003940# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 if (do_sp)
3942 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003943# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003945# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003946 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003947# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3949 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003950# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 if (do_srr)
3952 {
3953 p_srr = (char_u *)">%s 2>&1";
3954 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3955 }
3956 }
3957 vim_free(p);
3958 }
3959#endif
3960
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003961#if defined(MSDOS) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003963 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3964 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003965 * This is done after other initializations, where 'shell' might have been
3966 * set, but only if they have not been set before. Default for p_shcf is
3967 * "/c", for p_shq is "". For "sh" like shells it is changed here to
3968 * "-c" and "\"", but not for DJGPP, because it starts the shell without
3969 * command.com. And for Win32 we need to set p_sxq instead.
3970 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003971 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972 {
3973 int idx3;
3974
3975 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003976 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 {
3978 p_shcf = (char_u *)"-c";
3979 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3980 }
3981
3982# ifndef DJGPP
3983# ifdef WIN3264
3984 /* Somehow Win32 requires the quotes around the redirection too */
3985 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003986 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987 {
3988 p_sxq = (char_u *)"\"";
3989 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3990 }
3991# else
3992 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003993 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 {
3995 p_shq = (char_u *)"\"";
3996 options[idx3].def_val[VI_DEFAULT] = p_shq;
3997 }
3998# endif
3999# endif
4000 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004001 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4002 {
4003 int idx3;
4004
4005 /*
4006 * cmd.exe on Windows will strip the first and last double quote given
4007 * on the command line, e.g. most of the time things like:
4008 * cmd /c "my path/to/echo" "my args to echo"
4009 * become:
4010 * my path/to/echo" "my args to echo
4011 * when executed.
4012 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004013 * To avoid this, set shellxquote to surround the command in
4014 * parenthesis. This appears to make most commands work, without
4015 * breaking commands that worked previously, such as
4016 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004017 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004018 idx3 = findoption((char_u *)"sxq");
4019 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4020 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004021 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004022 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4023 }
4024
Bram Moolenaara64ba222012-02-12 23:23:31 +01004025 idx3 = findoption((char_u *)"shcf");
4026 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4027 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004028 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004029 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4030 }
4031 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004032#endif
4033
4034#ifdef FEAT_TITLE
4035 set_title_defaults();
4036#endif
4037}
4038
4039#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4040/*
4041 * When 'helplang' is still at its default value, set it to "lang".
4042 * Only the first two characters of "lang" are used.
4043 */
4044 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004045set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046{
4047 int idx;
4048
4049 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4050 return;
4051 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004052 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 {
4054 if (options[idx].flags & P_ALLOCED)
4055 free_string_option(p_hlg);
4056 p_hlg = vim_strsave(lang);
4057 if (p_hlg == NULL)
4058 p_hlg = empty_option;
4059 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004060 {
4061 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4062 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4063 {
4064 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4065 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4066 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004068 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 options[idx].flags |= P_ALLOCED;
4070 }
4071}
4072#endif
4073
4074#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004075static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076
4077 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004078gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079{
4080 if (gui_get_lightness(gui.back_pixel) < 127)
4081 return (char_u *)"dark";
4082 return (char_u *)"light";
4083}
4084
4085/*
4086 * Option initializations that can only be done after opening the GUI window.
4087 */
4088 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004089init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090{
4091 /* Set the 'background' option according to the lightness of the
4092 * background color, unless the user has set it already. */
4093 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4094 {
4095 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4096 highlight_changed();
4097 }
4098}
4099#endif
4100
4101#ifdef FEAT_TITLE
4102/*
4103 * 'title' and 'icon' only default to true if they have not been set or reset
4104 * in .vimrc and we can read the old value.
4105 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4106 * they can be reset. This reduces startup time when using X on a remote
4107 * machine.
4108 */
4109 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004110set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111{
4112 int idx1;
4113 long val;
4114
4115 /*
4116 * If GUI is (going to be) used, we can always set the window title and
4117 * icon name. Saves a bit of time, because the X11 display server does
4118 * not need to be contacted.
4119 */
4120 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004121 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 {
4123#ifdef FEAT_GUI
4124 if (gui.starting || gui.in_use)
4125 val = TRUE;
4126 else
4127#endif
4128 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004129 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 p_title = val;
4131 }
4132 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004133 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 {
4135#ifdef FEAT_GUI
4136 if (gui.starting || gui.in_use)
4137 val = TRUE;
4138 else
4139#endif
4140 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004141 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 p_icon = val;
4143 }
4144}
4145#endif
4146
4147/*
4148 * Parse 'arg' for option settings.
4149 *
4150 * 'arg' may be IObuff, but only when no errors can be present and option
4151 * does not need to be expanded with option_expand().
4152 * "opt_flags":
4153 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004154 * OPT_GLOBAL for ":setglobal"
4155 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004156 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004157 * OPT_WINONLY to only set window-local options
4158 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004159 *
4160 * returns FAIL if an error is detected, OK otherwise
4161 */
4162 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004163do_set(
4164 char_u *arg, /* option string (may be written to!) */
4165 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166{
4167 int opt_idx;
4168 char_u *errmsg;
4169 char_u errbuf[80];
4170 char_u *startarg;
4171 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4172 int nextchar; /* next non-white char after option name */
4173 int afterchar; /* character just after option name */
4174 int len;
4175 int i;
4176 long value;
4177 int key;
4178 long_u flags; /* flags for current option */
4179 char_u *varp = NULL; /* pointer to variable for current option */
4180 int did_show = FALSE; /* already showed one value */
4181 int adding; /* "opt+=arg" */
4182 int prepending; /* "opt^=arg" */
4183 int removing; /* "opt-=arg" */
4184 int cp_val = 0;
4185 char_u key_name[2];
4186
4187 if (*arg == NUL)
4188 {
4189 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004190 did_show = TRUE;
4191 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004192 }
4193
4194 while (*arg != NUL) /* loop to process all options */
4195 {
4196 errmsg = NULL;
4197 startarg = arg; /* remember for error message */
4198
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004199 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4200 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201 {
4202 /*
4203 * ":set all" show all options.
4204 * ":set all&" set all options to their default value.
4205 */
4206 arg += 3;
4207 if (*arg == '&')
4208 {
4209 ++arg;
4210 /* Only for :set command set global value of local options. */
4211 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004212 didset_options();
4213 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004214 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215 }
4216 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004217 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004218 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004219 did_show = TRUE;
4220 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004222 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004223 {
4224 showoptions(2, opt_flags);
4225 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004226 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 arg += 7;
4228 }
4229 else
4230 {
4231 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004232 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233 {
4234 prefix = 0;
4235 arg += 2;
4236 }
4237 else if (STRNCMP(arg, "inv", 3) == 0)
4238 {
4239 prefix = 2;
4240 arg += 3;
4241 }
4242
4243 /* find end of name */
4244 key = 0;
4245 if (*arg == '<')
4246 {
4247 nextchar = 0;
4248 opt_idx = -1;
4249 /* look out for <t_>;> */
4250 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4251 len = 5;
4252 else
4253 {
4254 len = 1;
4255 while (arg[len] != NUL && arg[len] != '>')
4256 ++len;
4257 }
4258 if (arg[len] != '>')
4259 {
4260 errmsg = e_invarg;
4261 goto skip;
4262 }
4263 arg[len] = NUL; /* put NUL after name */
4264 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4265 opt_idx = findoption(arg + 1);
4266 arg[len++] = '>'; /* restore '>' */
4267 if (opt_idx == -1)
4268 key = find_key_option(arg + 1);
4269 }
4270 else
4271 {
4272 len = 0;
4273 /*
4274 * The two characters after "t_" may not be alphanumeric.
4275 */
4276 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4277 len = 4;
4278 else
4279 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4280 ++len;
4281 nextchar = arg[len];
4282 arg[len] = NUL; /* put NUL after name */
4283 opt_idx = findoption(arg);
4284 arg[len] = nextchar; /* restore nextchar */
4285 if (opt_idx == -1)
4286 key = find_key_option(arg);
4287 }
4288
4289 /* remember character after option name */
4290 afterchar = arg[len];
4291
4292 /* skip white space, allow ":set ai ?" */
4293 while (vim_iswhite(arg[len]))
4294 ++len;
4295
4296 adding = FALSE;
4297 prepending = FALSE;
4298 removing = FALSE;
4299 if (arg[len] != NUL && arg[len + 1] == '=')
4300 {
4301 if (arg[len] == '+')
4302 {
4303 adding = TRUE; /* "+=" */
4304 ++len;
4305 }
4306 else if (arg[len] == '^')
4307 {
4308 prepending = TRUE; /* "^=" */
4309 ++len;
4310 }
4311 else if (arg[len] == '-')
4312 {
4313 removing = TRUE; /* "-=" */
4314 ++len;
4315 }
4316 }
4317 nextchar = arg[len];
4318
4319 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4320 {
4321 errmsg = (char_u *)N_("E518: Unknown option");
4322 goto skip;
4323 }
4324
4325 if (opt_idx >= 0)
4326 {
4327 if (options[opt_idx].var == NULL) /* hidden option: skip */
4328 {
4329 /* Only give an error message when requesting the value of
4330 * a hidden option, ignore setting it. */
4331 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4332 && (!(options[opt_idx].flags & P_BOOL)
4333 || nextchar == '?'))
4334 errmsg = (char_u *)N_("E519: Option not supported");
4335 goto skip;
4336 }
4337
4338 flags = options[opt_idx].flags;
4339 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4340 }
4341 else
4342 {
4343 flags = P_STRING;
4344 if (key < 0)
4345 {
4346 key_name[0] = KEY2TERMCAP0(key);
4347 key_name[1] = KEY2TERMCAP1(key);
4348 }
4349 else
4350 {
4351 key_name[0] = KS_KEY;
4352 key_name[1] = (key & 0xff);
4353 }
4354 }
4355
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004356 /* Skip all options that are not window-local (used when showing
4357 * an already loaded buffer in a window). */
4358 if ((opt_flags & OPT_WINONLY)
4359 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4360 goto skip;
4361
Bram Moolenaara3227e22006-03-08 21:32:40 +00004362 /* Skip all options that are window-local (used for :vimgrep). */
4363 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4364 && options[opt_idx].var == VAR_WIN)
4365 goto skip;
4366
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004367 /* Disallow changing some options from modelines. */
4368 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004369 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004370 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004371 {
4372 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4373 goto skip;
4374 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004375#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004376 /* In diff mode some options are overruled. This avoids that
4377 * 'foldmethod' becomes "marker" instead of "diff" and that
4378 * "wrap" gets set. */
4379 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004380 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004381 && (options[opt_idx].indir == PV_FDM
4382 || options[opt_idx].indir == PV_WRAP))
4383 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004384#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 }
4386
4387#ifdef HAVE_SANDBOX
4388 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004389 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004390 {
4391 errmsg = (char_u *)_(e_sandbox);
4392 goto skip;
4393 }
4394#endif
4395
4396 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4397 {
4398 arg += len;
4399 cp_val = p_cp;
4400 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4401 {
4402 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4403 {
4404 cp_val = FALSE;
4405 arg += 3;
4406 }
4407 else /* "opt&vi": set to Vi default */
4408 {
4409 cp_val = TRUE;
4410 arg += 2;
4411 }
4412 }
4413 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4414 && arg[1] != NUL && !vim_iswhite(arg[1]))
4415 {
4416 errmsg = e_trailing;
4417 goto skip;
4418 }
4419 }
4420
4421 /*
4422 * allow '=' and ':' as MSDOS command.com allows only one
4423 * '=' character per "set" command line. grrr. (jw)
4424 */
4425 if (nextchar == '?'
4426 || (prefix == 1
4427 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4428 && !(flags & P_BOOL)))
4429 {
4430 /*
4431 * print value
4432 */
4433 if (did_show)
4434 msg_putchar('\n'); /* cursor below last one */
4435 else
4436 {
4437 gotocmdline(TRUE); /* cursor at status line */
4438 did_show = TRUE; /* remember that we did a line */
4439 }
4440 if (opt_idx >= 0)
4441 {
4442 showoneopt(&options[opt_idx], opt_flags);
4443#ifdef FEAT_EVAL
4444 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004445 {
4446 /* Mention where the option was last set. */
4447 if (varp == options[opt_idx].var)
4448 last_set_msg(options[opt_idx].scriptID);
4449 else if ((int)options[opt_idx].indir & PV_WIN)
4450 last_set_msg(curwin->w_p_scriptID[
4451 (int)options[opt_idx].indir & PV_MASK]);
4452 else if ((int)options[opt_idx].indir & PV_BUF)
4453 last_set_msg(curbuf->b_p_scriptID[
4454 (int)options[opt_idx].indir & PV_MASK]);
4455 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004456#endif
4457 }
4458 else
4459 {
4460 char_u *p;
4461
4462 p = find_termcode(key_name);
4463 if (p == NULL)
4464 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004465 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004466 goto skip;
4467 }
4468 else
4469 (void)show_one_termcode(key_name, p, TRUE);
4470 }
4471 if (nextchar != '?'
4472 && nextchar != NUL && !vim_iswhite(afterchar))
4473 errmsg = e_trailing;
4474 }
4475 else
4476 {
4477 if (flags & P_BOOL) /* boolean */
4478 {
4479 if (nextchar == '=' || nextchar == ':')
4480 {
4481 errmsg = e_invarg;
4482 goto skip;
4483 }
4484
4485 /*
4486 * ":set opt!": invert
4487 * ":set opt&": reset to default value
4488 * ":set opt<": reset to global value
4489 */
4490 if (nextchar == '!')
4491 value = *(int *)(varp) ^ 1;
4492 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004493 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004494 ((flags & P_VI_DEF) || cp_val)
4495 ? VI_DEFAULT : VIM_DEFAULT];
4496 else if (nextchar == '<')
4497 {
4498 /* For 'autoread' -1 means to use global value. */
4499 if ((int *)varp == &curbuf->b_p_ar
4500 && opt_flags == OPT_LOCAL)
4501 value = -1;
4502 else
4503 value = *(int *)get_varp_scope(&(options[opt_idx]),
4504 OPT_GLOBAL);
4505 }
4506 else
4507 {
4508 /*
4509 * ":set invopt": invert
4510 * ":set opt" or ":set noopt": set or reset
4511 */
4512 if (nextchar != NUL && !vim_iswhite(afterchar))
4513 {
4514 errmsg = e_trailing;
4515 goto skip;
4516 }
4517 if (prefix == 2) /* inv */
4518 value = *(int *)(varp) ^ 1;
4519 else
4520 value = prefix;
4521 }
4522
4523 errmsg = set_bool_option(opt_idx, varp, (int)value,
4524 opt_flags);
4525 }
4526 else /* numeric or string */
4527 {
4528 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4529 || prefix != 1)
4530 {
4531 errmsg = e_invarg;
4532 goto skip;
4533 }
4534
4535 if (flags & P_NUM) /* numeric */
4536 {
4537 /*
4538 * Different ways to set a number option:
4539 * & set to default value
4540 * < set to global value
4541 * <xx> accept special key codes for 'wildchar'
4542 * c accept any non-digit for 'wildchar'
4543 * [-]0-9 set number
4544 * other error
4545 */
4546 ++arg;
4547 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004548 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004549 ((flags & P_VI_DEF) || cp_val)
4550 ? VI_DEFAULT : VIM_DEFAULT];
4551 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004552 {
4553 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4554 * use the global value. */
4555 if ((long *)varp == &curbuf->b_p_ul
4556 && opt_flags == OPT_LOCAL)
4557 value = NO_LOCAL_UNDOLEVEL;
4558 else
4559 value = *(long *)get_varp_scope(
4560 &(options[opt_idx]), OPT_GLOBAL);
4561 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 else if (((long *)varp == &p_wc
4563 || (long *)varp == &p_wcm)
4564 && (*arg == '<'
4565 || *arg == '^'
4566 || ((!arg[1] || vim_iswhite(arg[1]))
4567 && !VIM_ISDIGIT(*arg))))
4568 {
4569 value = string_to_key(arg);
4570 if (value == 0 && (long *)varp != &p_wcm)
4571 {
4572 errmsg = e_invarg;
4573 goto skip;
4574 }
4575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004576 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4577 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004578 /* Allow negative (for 'undolevels'), octal and
4579 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004580 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4581 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004582 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4583 {
4584 errmsg = e_invarg;
4585 goto skip;
4586 }
4587 }
4588 else
4589 {
4590 errmsg = (char_u *)N_("E521: Number required after =");
4591 goto skip;
4592 }
4593
4594 if (adding)
4595 value = *(long *)varp + value;
4596 if (prepending)
4597 value = *(long *)varp * value;
4598 if (removing)
4599 value = *(long *)varp - value;
4600 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004601 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004602 }
4603 else if (opt_idx >= 0) /* string */
4604 {
4605 char_u *save_arg = NULL;
4606 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004607 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004608 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004609 char_u *origval = NULL;
4610#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4611 char_u *saved_origval = NULL;
4612#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004613 unsigned newlen;
4614 int comma;
4615 int bs;
4616 int new_value_alloced; /* new string option
4617 was allocated */
4618
4619 /* When using ":set opt=val" for a global option
4620 * with a local value the local value will be
4621 * reset, use the global value here. */
4622 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004623 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004624 varp = options[opt_idx].var;
4625
4626 /* The old value is kept until we are sure that the
4627 * new value is valid. */
4628 oldval = *(char_u **)varp;
4629 if (nextchar == '&') /* set to default val */
4630 {
4631 newval = options[opt_idx].def_val[
4632 ((flags & P_VI_DEF) || cp_val)
4633 ? VI_DEFAULT : VIM_DEFAULT];
4634 if ((char_u **)varp == &p_bg)
4635 {
4636 /* guess the value of 'background' */
4637#ifdef FEAT_GUI
4638 if (gui.in_use)
4639 newval = gui_bg_default();
4640 else
4641#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004642 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004643 }
4644
4645 /* expand environment variables and ~ (since the
4646 * default value was already expanded, only
4647 * required when an environment variable was set
4648 * later */
4649 if (newval == NULL)
4650 newval = empty_option;
4651 else
4652 {
4653 s = option_expand(opt_idx, newval);
4654 if (s == NULL)
4655 s = newval;
4656 newval = vim_strsave(s);
4657 }
4658 new_value_alloced = TRUE;
4659 }
4660 else if (nextchar == '<') /* set to global val */
4661 {
4662 newval = vim_strsave(*(char_u **)get_varp_scope(
4663 &(options[opt_idx]), OPT_GLOBAL));
4664 new_value_alloced = TRUE;
4665 }
4666 else
4667 {
4668 ++arg; /* jump to after the '=' or ':' */
4669
4670 /*
4671 * Set 'keywordprg' to ":help" if an empty
4672 * value was passed to :set by the user.
4673 * Misuse errbuf[] for the resulting string.
4674 */
4675 if (varp == (char_u *)&p_kp
4676 && (*arg == NUL || *arg == ' '))
4677 {
4678 STRCPY(errbuf, ":help");
4679 save_arg = arg;
4680 arg = errbuf;
4681 }
4682 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004683 * Convert 'backspace' number to string, for
4684 * adding, prepending and removing string.
4685 */
4686 else if (varp == (char_u *)&p_bs
4687 && VIM_ISDIGIT(**(char_u **)varp))
4688 {
4689 i = getdigits((char_u **)varp);
4690 switch (i)
4691 {
4692 case 0:
4693 *(char_u **)varp = empty_option;
4694 break;
4695 case 1:
4696 *(char_u **)varp = vim_strsave(
4697 (char_u *)"indent,eol");
4698 break;
4699 case 2:
4700 *(char_u **)varp = vim_strsave(
4701 (char_u *)"indent,eol,start");
4702 break;
4703 }
4704 vim_free(oldval);
4705 oldval = *(char_u **)varp;
4706 }
4707 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004708 * Convert 'whichwrap' number to string, for
4709 * backwards compatibility with Vim 3.0.
4710 * Misuse errbuf[] for the resulting string.
4711 */
4712 else if (varp == (char_u *)&p_ww
4713 && VIM_ISDIGIT(*arg))
4714 {
4715 *errbuf = NUL;
4716 i = getdigits(&arg);
4717 if (i & 1)
4718 STRCAT(errbuf, "b,");
4719 if (i & 2)
4720 STRCAT(errbuf, "s,");
4721 if (i & 4)
4722 STRCAT(errbuf, "h,l,");
4723 if (i & 8)
4724 STRCAT(errbuf, "<,>,");
4725 if (i & 16)
4726 STRCAT(errbuf, "[,],");
4727 if (*errbuf != NUL) /* remove trailing , */
4728 errbuf[STRLEN(errbuf) - 1] = NUL;
4729 save_arg = arg;
4730 arg = errbuf;
4731 }
4732 /*
4733 * Remove '>' before 'dir' and 'bdir', for
4734 * backwards compatibility with version 3.0
4735 */
4736 else if ( *arg == '>'
4737 && (varp == (char_u *)&p_dir
4738 || varp == (char_u *)&p_bdir))
4739 {
4740 ++arg;
4741 }
4742
4743 /* When setting the local value of a global
4744 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004745 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004746 && (opt_flags & OPT_LOCAL))
4747 origval = *(char_u **)get_varp(
4748 &options[opt_idx]);
4749 else
4750 origval = oldval;
4751
4752 /*
4753 * Copy the new string into allocated memory.
4754 * Can't use set_string_option_direct(), because
4755 * we need to remove the backslashes.
4756 */
4757 /* get a bit too much */
4758 newlen = (unsigned)STRLEN(arg) + 1;
4759 if (adding || prepending || removing)
4760 newlen += (unsigned)STRLEN(origval) + 1;
4761 newval = alloc(newlen);
4762 if (newval == NULL) /* out of mem, don't change */
4763 break;
4764 s = newval;
4765
4766 /*
4767 * Copy the string, skip over escaped chars.
4768 * For MS-DOS and WIN32 backslashes before normal
4769 * file name characters are not removed, and keep
4770 * backslash at start, for "\\machine\path", but
4771 * do remove it for "\\\\machine\\path".
4772 * The reverse is found in ExpandOldSetting().
4773 */
4774 while (*arg && !vim_iswhite(*arg))
4775 {
4776 if (*arg == '\\' && arg[1] != NUL
4777#ifdef BACKSLASH_IN_FILENAME
4778 && !((flags & P_EXPAND)
4779 && vim_isfilec(arg[1])
4780 && (arg[1] != '\\'
4781 || (s == newval
4782 && arg[2] != '\\')))
4783#endif
4784 )
4785 ++arg; /* remove backslash */
4786#ifdef FEAT_MBYTE
4787 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004788 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004789 {
4790 /* copy multibyte char */
4791 mch_memmove(s, arg, (size_t)i);
4792 arg += i;
4793 s += i;
4794 }
4795 else
4796#endif
4797 *s++ = *arg++;
4798 }
4799 *s = NUL;
4800
4801 /*
4802 * Expand environment variables and ~.
4803 * Don't do it when adding without inserting a
4804 * comma.
4805 */
4806 if (!(adding || prepending || removing)
4807 || (flags & P_COMMA))
4808 {
4809 s = option_expand(opt_idx, newval);
4810 if (s != NULL)
4811 {
4812 vim_free(newval);
4813 newlen = (unsigned)STRLEN(s) + 1;
4814 if (adding || prepending || removing)
4815 newlen += (unsigned)STRLEN(origval) + 1;
4816 newval = alloc(newlen);
4817 if (newval == NULL)
4818 break;
4819 STRCPY(newval, s);
4820 }
4821 }
4822
4823 /* locate newval[] in origval[] when removing it
4824 * and when adding to avoid duplicates */
4825 i = 0; /* init for GCC */
4826 if (removing || (flags & P_NODUP))
4827 {
4828 i = (int)STRLEN(newval);
4829 bs = 0;
4830 for (s = origval; *s; ++s)
4831 {
4832 if ((!(flags & P_COMMA)
4833 || s == origval
4834 || (s[-1] == ',' && !(bs & 1)))
4835 && STRNCMP(s, newval, i) == 0
4836 && (!(flags & P_COMMA)
4837 || s[i] == ','
4838 || s[i] == NUL))
4839 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004840 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004841 * even number of backslashes or a single
4842 * backslash preceded by a comma before it
4843 * is recognized as a separator */
4844 if ((s > origval + 1
4845 && s[-1] == '\\'
4846 && s[-2] != ',')
4847 || (s == origval + 1
4848 && s[-1] == '\\'))
4849
Bram Moolenaar071d4272004-06-13 20:20:40 +00004850 ++bs;
4851 else
4852 bs = 0;
4853 }
4854
4855 /* do not add if already there */
4856 if ((adding || prepending) && *s)
4857 {
4858 prepending = FALSE;
4859 adding = FALSE;
4860 STRCPY(newval, origval);
4861 }
4862 }
4863
4864 /* concatenate the two strings; add a ',' if
4865 * needed */
4866 if (adding || prepending)
4867 {
4868 comma = ((flags & P_COMMA) && *origval != NUL
4869 && *newval != NUL);
4870 if (adding)
4871 {
4872 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004873 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004874 if (comma && i > 1
4875 && (flags & P_ONECOMMA) == P_ONECOMMA
4876 && origval[i - 1] == ','
4877 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004878 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004879 mch_memmove(newval + i + comma, newval,
4880 STRLEN(newval) + 1);
4881 mch_memmove(newval, origval, (size_t)i);
4882 }
4883 else
4884 {
4885 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004886 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004887 }
4888 if (comma)
4889 newval[i] = ',';
4890 }
4891
4892 /* Remove newval[] from origval[]. (Note: "i" has
4893 * been set above and is used here). */
4894 if (removing)
4895 {
4896 STRCPY(newval, origval);
4897 if (*s)
4898 {
4899 /* may need to remove a comma */
4900 if (flags & P_COMMA)
4901 {
4902 if (s == origval)
4903 {
4904 /* include comma after string */
4905 if (s[i] == ',')
4906 ++i;
4907 }
4908 else
4909 {
4910 /* include comma before string */
4911 --s;
4912 ++i;
4913 }
4914 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004915 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004916 }
4917 }
4918
4919 if (flags & P_FLAGLIST)
4920 {
4921 /* Remove flags that appear twice. */
4922 for (s = newval; *s; ++s)
4923 if ((!(flags & P_COMMA) || *s != ',')
4924 && vim_strchr(s + 1, *s) != NULL)
4925 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004926 STRMOVE(s, s + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004927 --s;
4928 }
4929 }
4930
4931 if (save_arg != NULL) /* number for 'whichwrap' */
4932 arg = save_arg;
4933 new_value_alloced = TRUE;
4934 }
4935
4936 /* Set the new value. */
4937 *(char_u **)(varp) = newval;
4938
Bram Moolenaar53744302015-07-17 17:38:22 +02004939#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004940 if (!starting
4941# ifdef FEAT_CRYPT
4942 && options[opt_idx].indir != PV_KEY
4943# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004944 && origval != NULL)
4945 /* origval may be freed by
4946 * did_set_string_option(), make a copy. */
4947 saved_origval = vim_strsave(origval);
4948#endif
4949
Bram Moolenaar071d4272004-06-13 20:20:40 +00004950 /* Handle side effects, and set the global value for
4951 * ":set" on local options. */
4952 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4953 new_value_alloced, oldval, errbuf, opt_flags);
4954
4955 /* If error detected, print the error message. */
4956 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004957 {
4958#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4959 vim_free(saved_origval);
4960#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004962 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004963#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4964 if (saved_origval != NULL)
4965 {
4966 char_u buf_type[7];
4967
4968 sprintf((char *)buf_type, "%s",
4969 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02004970 set_vim_var_string(VV_OPTION_NEW,
4971 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02004972 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
4973 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4974 apply_autocmds(EVENT_OPTIONSET,
4975 (char_u *)options[opt_idx].fullname,
4976 NULL, FALSE, NULL);
4977 reset_v_option_vars();
4978 vim_free(saved_origval);
4979 }
4980#endif
4981
Bram Moolenaar071d4272004-06-13 20:20:40 +00004982 }
4983 else /* key code option */
4984 {
4985 char_u *p;
4986
4987 if (nextchar == '&')
4988 {
4989 if (add_termcap_entry(key_name, TRUE) == FAIL)
4990 errmsg = (char_u *)N_("E522: Not found in termcap");
4991 }
4992 else
4993 {
4994 ++arg; /* jump to after the '=' or ':' */
4995 for (p = arg; *p && !vim_iswhite(*p); ++p)
4996 if (*p == '\\' && p[1] != NUL)
4997 ++p;
4998 nextchar = *p;
4999 *p = NUL;
5000 add_termcode(key_name, arg, FALSE);
5001 *p = nextchar;
5002 }
5003 if (full_screen)
5004 ttest(FALSE);
5005 redraw_all_later(CLEAR);
5006 }
5007 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005008
Bram Moolenaar071d4272004-06-13 20:20:40 +00005009 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005010 did_set_option(opt_idx, opt_flags,
5011 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005012 }
5013
5014skip:
5015 /*
5016 * Advance to next argument.
5017 * - skip until a blank found, taking care of backslashes
5018 * - skip blanks
5019 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5020 */
5021 for (i = 0; i < 2 ; ++i)
5022 {
5023 while (*arg != NUL && !vim_iswhite(*arg))
5024 if (*arg++ == '\\' && *arg != NUL)
5025 ++arg;
5026 arg = skipwhite(arg);
5027 if (*arg != '=')
5028 break;
5029 }
5030 }
5031
5032 if (errmsg != NULL)
5033 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005034 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005035 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005036 if (i + (arg - startarg) < IOSIZE)
5037 {
5038 /* append the argument with the error */
5039 STRCAT(IObuff, ": ");
5040 mch_memmove(IObuff + i, startarg, (arg - startarg));
5041 IObuff[i + (arg - startarg)] = NUL;
5042 }
5043 /* make sure all characters are printable */
5044 trans_characters(IObuff, IOSIZE);
5045
5046 ++no_wait_return; /* wait_return done later */
5047 emsg(IObuff); /* show error highlighted */
5048 --no_wait_return;
5049
5050 return FAIL;
5051 }
5052
5053 arg = skipwhite(arg);
5054 }
5055
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005056theend:
5057 if (silent_mode && did_show)
5058 {
5059 /* After displaying option values in silent mode. */
5060 silent_mode = FALSE;
5061 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5062 msg_putchar('\n');
5063 cursor_on(); /* msg_start() switches it off */
5064 out_flush();
5065 silent_mode = TRUE;
5066 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5067 }
5068
Bram Moolenaar071d4272004-06-13 20:20:40 +00005069 return OK;
5070}
5071
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005072/*
5073 * Call this when an option has been given a new value through a user command.
5074 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5075 */
5076 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005077did_set_option(
5078 int opt_idx,
5079 int opt_flags, /* possibly with OPT_MODELINE */
5080 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005081{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005082 long_u *p;
5083
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005084 options[opt_idx].flags |= P_WAS_SET;
5085
5086 /* When an option is set in the sandbox, from a modeline or in secure mode
5087 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005088 * flag. */
5089 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005090 if (secure
5091#ifdef HAVE_SANDBOX
5092 || sandbox != 0
5093#endif
5094 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005095 *p = *p | P_INSECURE;
5096 else if (new_value)
5097 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005098}
5099
Bram Moolenaar071d4272004-06-13 20:20:40 +00005100 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005101illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005102{
5103 if (errbuf == NULL)
5104 return (char_u *)"";
5105 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005106 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005107 return errbuf;
5108}
5109
5110/*
5111 * Convert a key name or string into a key value.
5112 * Used for 'wildchar' and 'cedit' options.
5113 */
5114 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005115string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005116{
5117 if (*arg == '<')
5118 return find_key_option(arg + 1);
5119 if (*arg == '^')
5120 return Ctrl_chr(arg[1]);
5121 return *arg;
5122}
5123
5124#ifdef FEAT_CMDWIN
5125/*
5126 * Check value of 'cedit' and set cedit_key.
5127 * Returns NULL if value is OK, error message otherwise.
5128 */
5129 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005130check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005131{
5132 int n;
5133
5134 if (*p_cedit == NUL)
5135 cedit_key = -1;
5136 else
5137 {
5138 n = string_to_key(p_cedit);
5139 if (vim_isprintc(n))
5140 return e_invarg;
5141 cedit_key = n;
5142 }
5143 return NULL;
5144}
5145#endif
5146
5147#ifdef FEAT_TITLE
5148/*
5149 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5150 * maketitle() to create and display it.
5151 * When switching the title or icon off, call mch_restore_title() to get
5152 * the old value back.
5153 */
5154 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005155did_set_title(
5156 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005157{
5158 if (starting != NO_SCREEN
5159#ifdef FEAT_GUI
5160 && !gui.starting
5161#endif
5162 )
5163 {
5164 maketitle();
5165 if (icon)
5166 {
5167 if (!p_icon)
5168 mch_restore_title(2);
5169 }
5170 else
5171 {
5172 if (!p_title)
5173 mch_restore_title(1);
5174 }
5175 }
5176}
5177#endif
5178
5179/*
5180 * set_options_bin - called when 'bin' changes value.
5181 */
5182 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005183set_options_bin(
5184 int oldval,
5185 int newval,
5186 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005187{
5188 /*
5189 * The option values that are changed when 'bin' changes are
5190 * copied when 'bin is set and restored when 'bin' is reset.
5191 */
5192 if (newval)
5193 {
5194 if (!oldval) /* switched on */
5195 {
5196 if (!(opt_flags & OPT_GLOBAL))
5197 {
5198 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5199 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5200 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5201 curbuf->b_p_et_nobin = curbuf->b_p_et;
5202 }
5203 if (!(opt_flags & OPT_LOCAL))
5204 {
5205 p_tw_nobin = p_tw;
5206 p_wm_nobin = p_wm;
5207 p_ml_nobin = p_ml;
5208 p_et_nobin = p_et;
5209 }
5210 }
5211
5212 if (!(opt_flags & OPT_GLOBAL))
5213 {
5214 curbuf->b_p_tw = 0; /* no automatic line wrap */
5215 curbuf->b_p_wm = 0; /* no automatic line wrap */
5216 curbuf->b_p_ml = 0; /* no modelines */
5217 curbuf->b_p_et = 0; /* no expandtab */
5218 }
5219 if (!(opt_flags & OPT_LOCAL))
5220 {
5221 p_tw = 0;
5222 p_wm = 0;
5223 p_ml = FALSE;
5224 p_et = FALSE;
5225 p_bin = TRUE; /* needed when called for the "-b" argument */
5226 }
5227 }
5228 else if (oldval) /* switched off */
5229 {
5230 if (!(opt_flags & OPT_GLOBAL))
5231 {
5232 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5233 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5234 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5235 curbuf->b_p_et = curbuf->b_p_et_nobin;
5236 }
5237 if (!(opt_flags & OPT_LOCAL))
5238 {
5239 p_tw = p_tw_nobin;
5240 p_wm = p_wm_nobin;
5241 p_ml = p_ml_nobin;
5242 p_et = p_et_nobin;
5243 }
5244 }
5245}
5246
5247#ifdef FEAT_VIMINFO
5248/*
5249 * Find the parameter represented by the given character (eg ', :, ", or /),
5250 * and return its associated value in the 'viminfo' string.
5251 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005252 * If the parameter is not specified in the string or there is no following
5253 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005254 */
5255 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005256get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005257{
5258 char_u *p;
5259
5260 p = find_viminfo_parameter(type);
5261 if (p != NULL && VIM_ISDIGIT(*p))
5262 return atoi((char *)p);
5263 return -1;
5264}
5265
5266/*
5267 * Find the parameter represented by the given character (eg ''', ':', '"', or
5268 * '/') in the 'viminfo' option and return a pointer to the string after it.
5269 * Return NULL if the parameter is not specified in the string.
5270 */
5271 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005272find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005273{
5274 char_u *p;
5275
5276 for (p = p_viminfo; *p; ++p)
5277 {
5278 if (*p == type)
5279 return p + 1;
5280 if (*p == 'n') /* 'n' is always the last one */
5281 break;
5282 p = vim_strchr(p, ','); /* skip until next ',' */
5283 if (p == NULL) /* hit the end without finding parameter */
5284 break;
5285 }
5286 return NULL;
5287}
5288#endif
5289
5290/*
5291 * Expand environment variables for some string options.
5292 * These string options cannot be indirect!
5293 * If "val" is NULL expand the current value of the option.
5294 * Return pointer to NameBuff, or NULL when not expanded.
5295 */
5296 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005297option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005298{
5299 /* if option doesn't need expansion nothing to do */
5300 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5301 return NULL;
5302
5303 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5304 * expand_env() would truncate the string. */
5305 if (val != NULL && STRLEN(val) > MAXPATHL)
5306 return NULL;
5307
5308 if (val == NULL)
5309 val = *(char_u **)options[opt_idx].var;
5310
5311 /*
5312 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5313 * Escape spaces when expanding 'tags', they are used to separate file
5314 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005315 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316 */
5317 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005318 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005319#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005320 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5321#endif
5322 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005323 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5324 return NULL;
5325
5326 return NameBuff;
5327}
5328
5329/*
5330 * After setting various option values: recompute variables that depend on
5331 * option values.
5332 */
5333 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005334didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335{
5336 /* initialize the table for 'iskeyword' et.al. */
5337 (void)init_chartab();
5338
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005339#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005340 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005341#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005342 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005343 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005344#ifdef FEAT_SESSION
5345 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5346 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5347#endif
5348#ifdef FEAT_FOLDING
5349 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5350#endif
5351 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005352 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353#ifdef FEAT_VIRTUALEDIT
5354 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5355#endif
5356#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5357 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5358#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005359#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005360 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005361 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005362 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005363 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005364#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005365#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5366 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5367#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005368#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5370#endif
5371#ifdef FEAT_CMDWIN
5372 /* set cedit_key */
5373 (void)check_cedit();
5374#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005375#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005376 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005377#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005378#ifdef FEAT_LINEBREAK
5379 /* initialize the table for 'breakat'. */
5380 fill_breakat_flags();
5381#endif
5382
5383}
5384
5385/*
5386 * More side effects of setting options.
5387 */
5388 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005389didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005390{
5391 /* Initialize the highlight_attr[] table. */
5392 (void)highlight_changed();
5393
5394 /* Parse default for 'wildmode' */
5395 check_opt_wim();
5396
5397 (void)set_chars_option(&p_lcs);
5398#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5399 /* Parse default for 'fillchars'. */
5400 (void)set_chars_option(&p_fcs);
5401#endif
5402
5403#ifdef FEAT_CLIPBOARD
5404 /* Parse default for 'clipboard' */
5405 (void)check_clipboard_option();
5406#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005407}
5408
5409/*
5410 * Check for string options that are NULL (normally only termcap options).
5411 */
5412 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005413check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005414{
5415 int opt_idx;
5416
5417 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5418 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5419 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5420}
5421
5422/*
5423 * Check string options in a buffer for NULL value.
5424 */
5425 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005426check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005427{
5428#if defined(FEAT_QUICKFIX)
5429 check_string_option(&buf->b_p_bh);
5430 check_string_option(&buf->b_p_bt);
5431#endif
5432#ifdef FEAT_MBYTE
5433 check_string_option(&buf->b_p_fenc);
5434#endif
5435 check_string_option(&buf->b_p_ff);
5436#ifdef FEAT_FIND_ID
5437 check_string_option(&buf->b_p_def);
5438 check_string_option(&buf->b_p_inc);
5439# ifdef FEAT_EVAL
5440 check_string_option(&buf->b_p_inex);
5441# endif
5442#endif
5443#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5444 check_string_option(&buf->b_p_inde);
5445 check_string_option(&buf->b_p_indk);
5446#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005447#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5448 check_string_option(&buf->b_p_bexpr);
5449#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005450#if defined(FEAT_CRYPT)
5451 check_string_option(&buf->b_p_cm);
5452#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005453#if defined(FEAT_EVAL)
5454 check_string_option(&buf->b_p_fex);
5455#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005456#ifdef FEAT_CRYPT
5457 check_string_option(&buf->b_p_key);
5458#endif
5459 check_string_option(&buf->b_p_kp);
5460 check_string_option(&buf->b_p_mps);
5461 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005462 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005463 check_string_option(&buf->b_p_isk);
5464#ifdef FEAT_COMMENTS
5465 check_string_option(&buf->b_p_com);
5466#endif
5467#ifdef FEAT_FOLDING
5468 check_string_option(&buf->b_p_cms);
5469#endif
5470 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005471#ifdef FEAT_TEXTOBJ
5472 check_string_option(&buf->b_p_qe);
5473#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005474#ifdef FEAT_SYN_HL
5475 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005476 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005477#endif
5478#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005479 check_string_option(&buf->b_s.b_p_spc);
5480 check_string_option(&buf->b_s.b_p_spf);
5481 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005482#endif
5483#ifdef FEAT_SEARCHPATH
5484 check_string_option(&buf->b_p_sua);
5485#endif
5486#ifdef FEAT_CINDENT
5487 check_string_option(&buf->b_p_cink);
5488 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005489 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005490#endif
5491#ifdef FEAT_AUTOCMD
5492 check_string_option(&buf->b_p_ft);
5493#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005494#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5495 check_string_option(&buf->b_p_cinw);
5496#endif
5497#ifdef FEAT_INS_EXPAND
5498 check_string_option(&buf->b_p_cpt);
5499#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005500#ifdef FEAT_COMPL_FUNC
5501 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005502 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005503#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504#ifdef FEAT_KEYMAP
5505 check_string_option(&buf->b_p_keymap);
5506#endif
5507#ifdef FEAT_QUICKFIX
5508 check_string_option(&buf->b_p_gp);
5509 check_string_option(&buf->b_p_mp);
5510 check_string_option(&buf->b_p_efm);
5511#endif
5512 check_string_option(&buf->b_p_ep);
5513 check_string_option(&buf->b_p_path);
5514 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005515 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005516#ifdef FEAT_INS_EXPAND
5517 check_string_option(&buf->b_p_dict);
5518 check_string_option(&buf->b_p_tsr);
5519#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005520#ifdef FEAT_LISP
5521 check_string_option(&buf->b_p_lw);
5522#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005523 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005524}
5525
5526/*
5527 * Free the string allocated for an option.
5528 * Checks for the string being empty_option. This may happen if we're out of
5529 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5530 * check_options().
5531 * Does NOT check for P_ALLOCED flag!
5532 */
5533 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005534free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535{
5536 if (p != empty_option)
5537 vim_free(p);
5538}
5539
5540 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005541clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005542{
5543 if (*pp != empty_option)
5544 vim_free(*pp);
5545 *pp = empty_option;
5546}
5547
5548 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005549check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550{
5551 if (*pp == NULL)
5552 *pp = empty_option;
5553}
5554
5555/*
5556 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5557 */
5558 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005559set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005560{
5561 int opt_idx;
5562
5563 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5564 if (options[opt_idx].var == (char_u *)p)
5565 {
5566 options[opt_idx].flags |= P_ALLOCED;
5567 return;
5568 }
5569 return; /* cannot happen: didn't find it! */
5570}
5571
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005572#if defined(FEAT_EVAL) || defined(PROTO)
5573/*
5574 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5575 * Return FALSE when it wasn't.
5576 * Return -1 for an unknown option.
5577 */
5578 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005579was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005580{
5581 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005582 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005583
5584 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005585 {
5586 flagp = insecure_flag(idx, opt_flags);
5587 return (*flagp & P_INSECURE) != 0;
5588 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005589 EMSG2(_(e_intern2), "was_set_insecurely()");
5590 return -1;
5591}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005592
5593/*
5594 * Get a pointer to the flags used for the P_INSECURE flag of option
5595 * "opt_idx". For some local options a local flags field is used.
5596 */
5597 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005598insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005599{
5600 if (opt_flags & OPT_LOCAL)
5601 switch ((int)options[opt_idx].indir)
5602 {
5603#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005604 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005605#endif
5606#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005607# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005608 case PV_FDE: return &curwin->w_p_fde_flags;
5609 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005610# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005611# ifdef FEAT_BEVAL
5612 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5613# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005614# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005615 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005616# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005617 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005618# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005619 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005620# endif
5621#endif
5622 }
5623
5624 /* Nothing special, return global flags field. */
5625 return &options[opt_idx].flags;
5626}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005627#endif
5628
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005629#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005630static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005631
5632/*
5633 * Redraw the window title and/or tab page text later.
5634 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005635static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005636{
5637 need_maketitle = TRUE;
5638# ifdef FEAT_WINDOWS
5639 redraw_tabline = TRUE;
5640# endif
5641}
5642#endif
5643
Bram Moolenaar071d4272004-06-13 20:20:40 +00005644/*
5645 * Set a string option to a new value (without checking the effect).
5646 * The string is copied into allocated memory.
5647 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005648 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005649 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650 */
5651 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005652set_string_option_direct(
5653 char_u *name,
5654 int opt_idx,
5655 char_u *val,
5656 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5657 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005658{
5659 char_u *s;
5660 char_u **varp;
5661 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005662 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663
Bram Moolenaar89d40322006-08-29 15:30:07 +00005664 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005666 idx = findoption(name);
5667 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005668 {
5669 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar0b105412014-11-30 13:34:23 +01005670 EMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673 }
5674
Bram Moolenaar89d40322006-08-29 15:30:07 +00005675 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676 return;
5677
5678 s = vim_strsave(val);
5679 if (s != NULL)
5680 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005681 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005683 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684 free_string_option(*varp);
5685 *varp = s;
5686
5687 /* For buffer/window local option may also set the global value. */
5688 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005689 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690
Bram Moolenaar89d40322006-08-29 15:30:07 +00005691 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005692
5693 /* When setting both values of a global option with a local value,
5694 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005695 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696 {
5697 free_string_option(*varp);
5698 *varp = empty_option;
5699 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005700# ifdef FEAT_EVAL
5701 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005702 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005703 set_sid == 0 ? current_SID : set_sid);
5704# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705 }
5706}
5707
5708/*
5709 * Set global value for string option when it's a local option.
5710 */
5711 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005712set_string_option_global(
5713 int opt_idx, /* option index */
5714 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715{
5716 char_u **p, *s;
5717
5718 /* the global value is always allocated */
5719 if (options[opt_idx].var == VAR_WIN)
5720 p = (char_u **)GLOBAL_WO(varp);
5721 else
5722 p = (char_u **)options[opt_idx].var;
5723 if (options[opt_idx].indir != PV_NONE
5724 && p != varp
5725 && (s = vim_strsave(*varp)) != NULL)
5726 {
5727 free_string_option(*p);
5728 *p = s;
5729 }
5730}
5731
5732/*
5733 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005734 *
5735 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005737 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005738set_string_option(
5739 int opt_idx,
5740 char_u *value,
5741 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742{
5743 char_u *s;
5744 char_u **varp;
5745 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005746#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5747 char_u *saved_oldval = NULL;
5748#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005749 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005750
5751 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005752 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753
5754 s = vim_strsave(value);
5755 if (s != NULL)
5756 {
5757 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5758 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005759 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005760 ? OPT_GLOBAL : OPT_LOCAL)
5761 : opt_flags);
5762 oldval = *varp;
5763 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005764
5765#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005766 if (!starting
5767# ifdef FEAT_CRYPT
5768 && options[opt_idx].indir != PV_KEY
5769# endif
5770 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005771 saved_oldval = vim_strsave(oldval);
5772#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005773 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5774 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005775 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005776
5777 /* call autocomamnd after handling side effects */
5778#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5779 if (saved_oldval != NULL)
5780 {
5781 char_u buf_type[7];
5782 sprintf((char *)buf_type, "%s",
5783 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005784 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5785 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005786 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5787 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5788 reset_v_option_vars();
5789 vim_free(saved_oldval);
5790 }
5791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005792 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005793 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005794}
5795
5796/*
5797 * Handle string options that need some action to perform when changed.
5798 * Returns NULL for success, or an error message for an error.
5799 */
5800 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005801did_set_string_option(
5802 int opt_idx, /* index in options[] table */
5803 char_u **varp, /* pointer to the option variable */
5804 int new_value_alloced, /* new value was allocated */
5805 char_u *oldval, /* previous value of the option */
5806 char_u *errbuf, /* buffer for errors, or NULL */
5807 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005808{
5809 char_u *errmsg = NULL;
5810 char_u *s, *p;
5811 int did_chartab = FALSE;
5812 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005813 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005814#ifdef FEAT_GUI
5815 /* set when changing an option that only requires a redraw in the GUI */
5816 int redraw_gui_only = FALSE;
5817#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005818
5819 /* Get the global option to compare with, otherwise we would have to check
5820 * two values for all local options. */
5821 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5822
5823 /* Disallow changing some options from secure mode */
5824 if ((secure
5825#ifdef HAVE_SANDBOX
5826 || sandbox != 0
5827#endif
5828 ) && (options[opt_idx].flags & P_SECURE))
5829 {
5830 errmsg = e_secure;
5831 }
5832
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005833 /* Check for a "normal" file name in some options. Disallow a path
5834 * separator (slash and/or backslash), wildcards and characters that are
5835 * often illegal in a file name. */
5836 else if ((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00005837 && vim_strpbrk(*varp, (char_u *)"/\\*?[|<>") != NULL)
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005838 {
5839 errmsg = e_invarg;
5840 }
5841
Bram Moolenaar071d4272004-06-13 20:20:40 +00005842 /* 'term' */
5843 else if (varp == &T_NAME)
5844 {
5845 if (T_NAME[0] == NUL)
5846 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5847#ifdef FEAT_GUI
5848 if (gui.in_use)
5849 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5850 else if (term_is_gui(T_NAME))
5851 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5852#endif
5853 else if (set_termname(T_NAME) == FAIL)
5854 errmsg = (char_u *)N_("E522: Not found in termcap");
5855 else
5856 /* Screen colors may have changed. */
5857 redraw_later_clear();
5858 }
5859
5860 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005861 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005862 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005863 char_u *bkc = p_bkc;
5864 unsigned int *flags = &bkc_flags;
5865
5866 if (opt_flags & OPT_LOCAL)
5867 {
5868 bkc = curbuf->b_p_bkc;
5869 flags = &curbuf->b_bkc_flags;
5870 }
5871
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005872 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5873 /* make the local value empty: use the global value */
5874 *flags = 0;
5875 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005877 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5878 errmsg = e_invarg;
5879 if ((((int)*flags & BKC_AUTO) != 0)
5880 + (((int)*flags & BKC_YES) != 0)
5881 + (((int)*flags & BKC_NO) != 0) != 1)
5882 {
5883 /* Must have exactly one of "auto", "yes" and "no". */
5884 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5885 errmsg = e_invarg;
5886 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005887 }
5888 }
5889
5890 /* 'backupext' and 'patchmode' */
5891 else if (varp == &p_bex || varp == &p_pm)
5892 {
5893 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5894 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5895 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5896 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005897#ifdef FEAT_LINEBREAK
5898 /* 'breakindentopt' */
5899 else if (varp == &curwin->w_p_briopt)
5900 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005901 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005902 errmsg = e_invarg;
5903 }
5904#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005905
5906 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005907 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005908 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005909 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 */
5911 else if ( varp == &p_isi
5912 || varp == &(curbuf->b_p_isk)
5913 || varp == &p_isp
5914 || varp == &p_isf)
5915 {
5916 if (init_chartab() == FAIL)
5917 {
5918 did_chartab = TRUE; /* need to restore it below */
5919 errmsg = e_invarg; /* error in value */
5920 }
5921 }
5922
5923 /* 'helpfile' */
5924 else if (varp == &p_hf)
5925 {
5926 /* May compute new values for $VIM and $VIMRUNTIME */
5927 if (didset_vim)
5928 {
5929 vim_setenv((char_u *)"VIM", (char_u *)"");
5930 didset_vim = FALSE;
5931 }
5932 if (didset_vimruntime)
5933 {
5934 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5935 didset_vimruntime = FALSE;
5936 }
5937 }
5938
Bram Moolenaar1a384422010-07-14 19:53:30 +02005939#ifdef FEAT_SYN_HL
5940 /* 'colorcolumn' */
5941 else if (varp == &curwin->w_p_cc)
5942 errmsg = check_colorcolumn(curwin);
5943#endif
5944
Bram Moolenaar071d4272004-06-13 20:20:40 +00005945#ifdef FEAT_MULTI_LANG
5946 /* 'helplang' */
5947 else if (varp == &p_hlg)
5948 {
5949 /* Check for "", "ab", "ab,cd", etc. */
5950 for (s = p_hlg; *s != NUL; s += 3)
5951 {
5952 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
5953 {
5954 errmsg = e_invarg;
5955 break;
5956 }
5957 if (s[2] == NUL)
5958 break;
5959 }
5960 }
5961#endif
5962
5963 /* 'highlight' */
5964 else if (varp == &p_hl)
5965 {
5966 if (highlight_changed() == FAIL)
5967 errmsg = e_invarg; /* invalid flags */
5968 }
5969
5970 /* 'nrformats' */
5971 else if (gvarp == &p_nf)
5972 {
5973 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
5974 errmsg = e_invarg;
5975 }
5976
5977#ifdef FEAT_SESSION
5978 /* 'sessionoptions' */
5979 else if (varp == &p_ssop)
5980 {
5981 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
5982 errmsg = e_invarg;
5983 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
5984 {
5985 /* Don't allow both "sesdir" and "curdir". */
5986 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
5987 errmsg = e_invarg;
5988 }
5989 }
5990 /* 'viewoptions' */
5991 else if (varp == &p_vop)
5992 {
5993 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
5994 errmsg = e_invarg;
5995 }
5996#endif
5997
5998 /* 'scrollopt' */
5999#ifdef FEAT_SCROLLBIND
6000 else if (varp == &p_sbo)
6001 {
6002 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6003 errmsg = e_invarg;
6004 }
6005#endif
6006
6007 /* 'ambiwidth' */
6008#ifdef FEAT_MBYTE
6009 else if (varp == &p_ambw)
6010 {
6011 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6012 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006013 else if (set_chars_option(&p_lcs) != NULL)
6014 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6015# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6016 else if (set_chars_option(&p_fcs) != NULL)
6017 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6018# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006019 }
6020#endif
6021
6022 /* 'background' */
6023 else if (varp == &p_bg)
6024 {
6025 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6026 {
6027#ifdef FEAT_EVAL
6028 int dark = (*p_bg == 'd');
6029#endif
6030
6031 init_highlight(FALSE, FALSE);
6032
6033#ifdef FEAT_EVAL
6034 if (dark != (*p_bg == 'd')
6035 && get_var_value((char_u *)"g:colors_name") != NULL)
6036 {
6037 /* The color scheme must have set 'background' back to another
6038 * value, that's not what we want here. Disable the color
6039 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006040 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006041 free_string_option(p_bg);
6042 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6043 check_string_option(&p_bg);
6044 init_highlight(FALSE, FALSE);
6045 }
6046#endif
6047 }
6048 else
6049 errmsg = e_invarg;
6050 }
6051
6052 /* 'wildmode' */
6053 else if (varp == &p_wim)
6054 {
6055 if (check_opt_wim() == FAIL)
6056 errmsg = e_invarg;
6057 }
6058
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006059#ifdef FEAT_CMDL_COMPL
6060 /* 'wildoptions' */
6061 else if (varp == &p_wop)
6062 {
6063 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6064 errmsg = e_invarg;
6065 }
6066#endif
6067
Bram Moolenaar071d4272004-06-13 20:20:40 +00006068#ifdef FEAT_WAK
6069 /* 'winaltkeys' */
6070 else if (varp == &p_wak)
6071 {
6072 if (*p_wak == NUL
6073 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6074 errmsg = e_invarg;
6075# ifdef FEAT_MENU
6076# ifdef FEAT_GUI_MOTIF
6077 else if (gui.in_use)
6078 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6079# else
6080# ifdef FEAT_GUI_GTK
6081 else if (gui.in_use)
6082 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6083# endif
6084# endif
6085# endif
6086 }
6087#endif
6088
6089#ifdef FEAT_AUTOCMD
6090 /* 'eventignore' */
6091 else if (varp == &p_ei)
6092 {
6093 if (check_ei() == FAIL)
6094 errmsg = e_invarg;
6095 }
6096#endif
6097
6098#ifdef FEAT_MBYTE
6099 /* 'encoding' and 'fileencoding' */
6100 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6101 {
6102 if (gvarp == &p_fenc)
6103 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006104 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006105 errmsg = e_modifiable;
6106 else if (vim_strchr(*varp, ',') != NULL)
6107 /* No comma allowed in 'fileencoding'; catches confusing it
6108 * with 'fileencodings'. */
6109 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006110 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006111 {
6112# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006114 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006115# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006116 /* Add 'fileencoding' to the swap file. */
6117 ml_setflags(curbuf);
6118 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119 }
6120 if (errmsg == NULL)
6121 {
6122 /* canonize the value, so that STRCMP() can be used on it */
6123 p = enc_canonize(*varp);
6124 if (p != NULL)
6125 {
6126 vim_free(*varp);
6127 *varp = p;
6128 }
6129 if (varp == &p_enc)
6130 {
6131 errmsg = mb_init();
6132# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006133 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134# endif
6135 }
6136 }
6137
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006138# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6140 {
6141 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6142 if (STRCMP(p_tenc, "utf-8") != 0)
6143 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6144 }
6145# endif
6146
6147 if (errmsg == NULL)
6148 {
6149# ifdef FEAT_KEYMAP
6150 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6151 * (with another encoding). */
6152 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6153 (void)keymap_init();
6154# endif
6155
6156 /* When 'termencoding' is not empty and 'encoding' changes or when
6157 * 'termencoding' changes, need to setup for keyboard input and
6158 * display output conversion. */
6159 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6160 {
6161 convert_setup(&input_conv, p_tenc, p_enc);
6162 convert_setup(&output_conv, p_enc, p_tenc);
6163 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006164
6165# if defined(WIN3264) && defined(FEAT_MBYTE)
6166 /* $HOME may have characters in active code page. */
6167 if (varp == &p_enc)
6168 init_homedir();
6169# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006170 }
6171 }
6172#endif
6173
6174#if defined(FEAT_POSTSCRIPT)
6175 else if (varp == &p_penc)
6176 {
6177 /* Canonize printencoding if VIM standard one */
6178 p = enc_canonize(p_penc);
6179 if (p != NULL)
6180 {
6181 vim_free(p_penc);
6182 p_penc = p;
6183 }
6184 else
6185 {
6186 /* Ensure lower case and '-' for '_' */
6187 for (s = p_penc; *s != NUL; s++)
6188 {
6189 if (*s == '_')
6190 *s = '-';
6191 else
6192 *s = TOLOWER_ASC(*s);
6193 }
6194 }
6195 }
6196#endif
6197
Bram Moolenaar9372a112005-12-06 19:59:18 +00006198#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006199 else if (varp == &p_imak)
6200 {
6201 if (gui.in_use && !im_xim_isvalid_imactivate())
6202 errmsg = e_invarg;
6203 }
6204#endif
6205
6206#ifdef FEAT_KEYMAP
6207 else if (varp == &curbuf->b_p_keymap)
6208 {
6209 /* load or unload key mapping tables */
6210 errmsg = keymap_init();
6211
Bram Moolenaarfab06232009-03-04 03:13:35 +00006212 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006213 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006214 if (*curbuf->b_p_keymap != NUL)
6215 {
6216 /* Installed a new keymap, switch on using it. */
6217 curbuf->b_p_iminsert = B_IMODE_LMAP;
6218 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6219 curbuf->b_p_imsearch = B_IMODE_LMAP;
6220 }
6221 else
6222 {
6223 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6224 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6225 curbuf->b_p_iminsert = B_IMODE_NONE;
6226 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6227 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6228 }
6229 if ((opt_flags & OPT_LOCAL) == 0)
6230 {
6231 set_iminsert_global();
6232 set_imsearch_global();
6233 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006234# ifdef FEAT_WINDOWS
6235 status_redraw_curbuf();
6236# endif
6237 }
6238 }
6239#endif
6240
6241 /* 'fileformat' */
6242 else if (gvarp == &p_ff)
6243 {
6244 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6245 errmsg = e_modifiable;
6246 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6247 errmsg = e_invarg;
6248 else
6249 {
6250 /* may also change 'textmode' */
6251 if (get_fileformat(curbuf) == EOL_DOS)
6252 curbuf->b_p_tx = TRUE;
6253 else
6254 curbuf->b_p_tx = FALSE;
6255#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006256 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006257#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006258 /* update flag in swap file */
6259 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006260 /* Redraw needed when switching to/from "mac": a CR in the text
6261 * will be displayed differently. */
6262 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6263 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006264 }
6265 }
6266
6267 /* 'fileformats' */
6268 else if (varp == &p_ffs)
6269 {
6270 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6271 errmsg = e_invarg;
6272 else
6273 {
6274 /* also change 'textauto' */
6275 if (*p_ffs == NUL)
6276 p_ta = FALSE;
6277 else
6278 p_ta = TRUE;
6279 }
6280 }
6281
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006282#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006283 /* 'cryptkey' */
6284 else if (gvarp == &p_key)
6285 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006286# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006287 /* Make sure the ":set" command doesn't show the new value in the
6288 * history. */
6289 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006290# endif
6291 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6292 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006293 ml_set_crypt_key(curbuf, oldval,
6294 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006295 }
6296
6297 else if (gvarp == &p_cm)
6298 {
6299 if (opt_flags & OPT_LOCAL)
6300 p = curbuf->b_p_cm;
6301 else
6302 p = p_cm;
6303 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6304 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006305 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006306 errmsg = e_invarg;
6307 else
6308 {
6309 /* When setting the global value to empty, make it "zip". */
6310 if (*p_cm == NUL)
6311 {
6312 if (new_value_alloced)
6313 free_string_option(p_cm);
6314 p_cm = vim_strsave((char_u *)"zip");
6315 new_value_alloced = TRUE;
6316 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006317 /* When using ":set cm=name" the local value is going to be empty.
6318 * Do that here, otherwise the crypt functions will still use the
6319 * local value. */
6320 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6321 {
6322 free_string_option(curbuf->b_p_cm);
6323 curbuf->b_p_cm = empty_option;
6324 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006325
6326 /* Need to update the swapfile when the effective method changed.
6327 * Set "s" to the effective old value, "p" to the effective new
6328 * method and compare. */
6329 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6330 s = p_cm; /* was previously using the global value */
6331 else
6332 s = oldval;
6333 if (*curbuf->b_p_cm == NUL)
6334 p = p_cm; /* is now using the global value */
6335 else
6336 p = curbuf->b_p_cm;
6337 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006338 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006339
6340 /* If the global value changes need to update the swapfile for all
6341 * buffers using that value. */
6342 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6343 {
6344 buf_T *buf;
6345
6346 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
6347 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006348 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006349 }
6350 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351 }
6352#endif
6353
6354 /* 'matchpairs' */
6355 else if (gvarp == &p_mps)
6356 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006357#ifdef FEAT_MBYTE
6358 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006359 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006360 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006361 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006362 int x2 = -1;
6363 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006364
6365 if (*p != NUL)
6366 p += mb_ptr2len(p);
6367 if (*p != NUL)
6368 x2 = *p++;
6369 if (*p != NUL)
6370 {
6371 x3 = mb_ptr2char(p);
6372 p += mb_ptr2len(p);
6373 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006374 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006375 {
6376 errmsg = e_invarg;
6377 break;
6378 }
6379 if (*p == NUL)
6380 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006381 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006382 }
6383 else
6384#endif
6385 {
6386 /* Check for "x:y,x:y" */
6387 for (p = *varp; *p != NUL; p += 4)
6388 {
6389 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6390 {
6391 errmsg = e_invarg;
6392 break;
6393 }
6394 if (p[3] == NUL)
6395 break;
6396 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006397 }
6398 }
6399
6400#ifdef FEAT_COMMENTS
6401 /* 'comments' */
6402 else if (gvarp == &p_com)
6403 {
6404 for (s = *varp; *s; )
6405 {
6406 while (*s && *s != ':')
6407 {
6408 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6409 && !VIM_ISDIGIT(*s) && *s != '-')
6410 {
6411 errmsg = illegal_char(errbuf, *s);
6412 break;
6413 }
6414 ++s;
6415 }
6416 if (*s++ == NUL)
6417 errmsg = (char_u *)N_("E524: Missing colon");
6418 else if (*s == ',' || *s == NUL)
6419 errmsg = (char_u *)N_("E525: Zero length string");
6420 if (errmsg != NULL)
6421 break;
6422 while (*s && *s != ',')
6423 {
6424 if (*s == '\\' && s[1] != NUL)
6425 ++s;
6426 ++s;
6427 }
6428 s = skip_to_option_part(s);
6429 }
6430 }
6431#endif
6432
6433 /* 'listchars' */
6434 else if (varp == &p_lcs)
6435 {
6436 errmsg = set_chars_option(varp);
6437 }
6438
6439#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6440 /* 'fillchars' */
6441 else if (varp == &p_fcs)
6442 {
6443 errmsg = set_chars_option(varp);
6444 }
6445#endif
6446
6447#ifdef FEAT_CMDWIN
6448 /* 'cedit' */
6449 else if (varp == &p_cedit)
6450 {
6451 errmsg = check_cedit();
6452 }
6453#endif
6454
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006455 /* 'verbosefile' */
6456 else if (varp == &p_vfile)
6457 {
6458 verbose_stop();
6459 if (*p_vfile != NUL && verbose_open() == FAIL)
6460 errmsg = e_invarg;
6461 }
6462
Bram Moolenaar071d4272004-06-13 20:20:40 +00006463#ifdef FEAT_VIMINFO
6464 /* 'viminfo' */
6465 else if (varp == &p_viminfo)
6466 {
6467 for (s = p_viminfo; *s;)
6468 {
6469 /* Check it's a valid character */
6470 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6471 {
6472 errmsg = illegal_char(errbuf, *s);
6473 break;
6474 }
6475 if (*s == 'n') /* name is always last one */
6476 {
6477 break;
6478 }
6479 else if (*s == 'r') /* skip until next ',' */
6480 {
6481 while (*++s && *s != ',')
6482 ;
6483 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006484 else if (*s == '%')
6485 {
6486 /* optional number */
6487 while (vim_isdigit(*++s))
6488 ;
6489 }
6490 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006491 ++s; /* no extra chars */
6492 else /* must have a number */
6493 {
6494 while (vim_isdigit(*++s))
6495 ;
6496
6497 if (!VIM_ISDIGIT(*(s - 1)))
6498 {
6499 if (errbuf != NULL)
6500 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006501 sprintf((char *)errbuf,
6502 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006503 transchar_byte(*(s - 1)));
6504 errmsg = errbuf;
6505 }
6506 else
6507 errmsg = (char_u *)"";
6508 break;
6509 }
6510 }
6511 if (*s == ',')
6512 ++s;
6513 else if (*s)
6514 {
6515 if (errbuf != NULL)
6516 errmsg = (char_u *)N_("E527: Missing comma");
6517 else
6518 errmsg = (char_u *)"";
6519 break;
6520 }
6521 }
6522 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6523 errmsg = (char_u *)N_("E528: Must specify a ' value");
6524 }
6525#endif /* FEAT_VIMINFO */
6526
6527 /* terminal options */
6528 else if (istermoption(&options[opt_idx]) && full_screen)
6529 {
6530 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6531 if (varp == &T_CCO)
6532 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006533 int colors = atoi((char *)T_CCO);
6534
6535 /* Only reinitialize colors if t_Co value has really changed to
6536 * avoid expensive reload of colorscheme if t_Co is set to the
6537 * same value multiple times. */
6538 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006539 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006540 t_colors = colors;
6541 if (t_colors <= 1)
6542 {
6543 if (new_value_alloced)
6544 vim_free(T_CCO);
6545 T_CCO = empty_option;
6546 }
6547 /* We now have a different color setup, initialize it again. */
6548 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006549 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006550 }
6551 ttest(FALSE);
6552 if (varp == &T_ME)
6553 {
6554 out_str(T_ME);
6555 redraw_later(CLEAR);
6556#if defined(MSDOS) || (defined(WIN3264) && !defined(FEAT_GUI_W32))
6557 /* Since t_me has been set, this probably means that the user
6558 * wants to use this as default colors. Need to reset default
6559 * background/foreground colors. */
6560 mch_set_normal_colors();
6561#endif
6562 }
6563 }
6564
6565#ifdef FEAT_LINEBREAK
6566 /* 'showbreak' */
6567 else if (varp == &p_sbr)
6568 {
6569 for (s = p_sbr; *s; )
6570 {
6571 if (ptr2cells(s) != 1)
6572 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006573 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006574 }
6575 }
6576#endif
6577
6578#ifdef FEAT_GUI
6579 /* 'guifont' */
6580 else if (varp == &p_guifont)
6581 {
6582 if (gui.in_use)
6583 {
6584 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006585# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006586 /*
6587 * Put up a font dialog and let the user select a new value.
6588 * If this is cancelled go back to the old value but don't
6589 * give an error message.
6590 */
6591 if (STRCMP(p, "*") == 0)
6592 {
6593 p = gui_mch_font_dialog(oldval);
6594
6595 if (new_value_alloced)
6596 free_string_option(p_guifont);
6597
6598 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6599 new_value_alloced = TRUE;
6600 }
6601# endif
6602 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6603 {
6604# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6605 if (STRCMP(p_guifont, "*") == 0)
6606 {
6607 /* Dialog was cancelled: Keep the old value without giving
6608 * an error message. */
6609 if (new_value_alloced)
6610 free_string_option(p_guifont);
6611 p_guifont = vim_strsave(oldval);
6612 new_value_alloced = TRUE;
6613 }
6614 else
6615# endif
6616 errmsg = (char_u *)N_("E596: Invalid font(s)");
6617 }
6618 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006619 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006620 }
6621# ifdef FEAT_XFONTSET
6622 else if (varp == &p_guifontset)
6623 {
6624 if (STRCMP(p_guifontset, "*") == 0)
6625 errmsg = (char_u *)N_("E597: can't select fontset");
6626 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6627 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006628 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006629 }
6630# endif
6631# ifdef FEAT_MBYTE
6632 else if (varp == &p_guifontwide)
6633 {
6634 if (STRCMP(p_guifontwide, "*") == 0)
6635 errmsg = (char_u *)N_("E533: can't select wide font");
6636 else if (gui_get_wide_font() == FAIL)
6637 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006638 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006639 }
6640# endif
6641#endif
6642
6643#ifdef CURSOR_SHAPE
6644 /* 'guicursor' */
6645 else if (varp == &p_guicursor)
6646 errmsg = parse_shape_opt(SHAPE_CURSOR);
6647#endif
6648
6649#ifdef FEAT_MOUSESHAPE
6650 /* 'mouseshape' */
6651 else if (varp == &p_mouseshape)
6652 {
6653 errmsg = parse_shape_opt(SHAPE_MOUSE);
6654 update_mouseshape(-1);
6655 }
6656#endif
6657
6658#ifdef FEAT_PRINTER
6659 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006660 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006661# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006662 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006663 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006664# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665#endif
6666
6667#ifdef FEAT_LANGMAP
6668 /* 'langmap' */
6669 else if (varp == &p_langmap)
6670 langmap_set();
6671#endif
6672
6673#ifdef FEAT_LINEBREAK
6674 /* 'breakat' */
6675 else if (varp == &p_breakat)
6676 fill_breakat_flags();
6677#endif
6678
6679#ifdef FEAT_TITLE
6680 /* 'titlestring' and 'iconstring' */
6681 else if (varp == &p_titlestring || varp == &p_iconstring)
6682 {
6683# ifdef FEAT_STL_OPT
6684 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6685
6686 /* NULL => statusline syntax */
6687 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6688 stl_syntax |= flagval;
6689 else
6690 stl_syntax &= ~flagval;
6691# endif
6692 did_set_title(varp == &p_iconstring);
6693
6694 }
6695#endif
6696
6697#ifdef FEAT_GUI
6698 /* 'guioptions' */
6699 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006700 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006701 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006702 redraw_gui_only = TRUE;
6703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006704#endif
6705
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006706#if defined(FEAT_GUI_TABLINE)
6707 /* 'guitablabel' */
6708 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006709 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006710 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006711 redraw_gui_only = TRUE;
6712 }
6713 /* 'guitabtooltip' */
6714 else if (varp == &p_gtt)
6715 {
6716 redraw_gui_only = TRUE;
6717 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006718#endif
6719
Bram Moolenaar071d4272004-06-13 20:20:40 +00006720#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6721 /* 'ttymouse' */
6722 else if (varp == &p_ttym)
6723 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006724 /* Switch the mouse off before changing the escape sequences used for
6725 * that. */
6726 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006727 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6728 errmsg = e_invarg;
6729 else
6730 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006731 if (termcap_active)
6732 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006733 }
6734#endif
6735
Bram Moolenaar071d4272004-06-13 20:20:40 +00006736 /* 'selection' */
6737 else if (varp == &p_sel)
6738 {
6739 if (*p_sel == NUL
6740 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6741 errmsg = e_invarg;
6742 }
6743
6744 /* 'selectmode' */
6745 else if (varp == &p_slm)
6746 {
6747 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6748 errmsg = e_invarg;
6749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006750
6751#ifdef FEAT_BROWSE
6752 /* 'browsedir' */
6753 else if (varp == &p_bsdir)
6754 {
6755 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6756 && !mch_isdir(p_bsdir))
6757 errmsg = e_invarg;
6758 }
6759#endif
6760
Bram Moolenaar071d4272004-06-13 20:20:40 +00006761 /* 'keymodel' */
6762 else if (varp == &p_km)
6763 {
6764 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6765 errmsg = e_invarg;
6766 else
6767 {
6768 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6769 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6770 }
6771 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006772
6773 /* 'mousemodel' */
6774 else if (varp == &p_mousem)
6775 {
6776 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6777 errmsg = e_invarg;
6778#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6779 else if (*p_mousem != *oldval)
6780 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6781 * to create or delete the popup menus. */
6782 gui_motif_update_mousemodel(root_menu);
6783#endif
6784 }
6785
6786 /* 'switchbuf' */
6787 else if (varp == &p_swb)
6788 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006789 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 errmsg = e_invarg;
6791 }
6792
6793 /* 'debug' */
6794 else if (varp == &p_debug)
6795 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006796 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006797 errmsg = e_invarg;
6798 }
6799
6800 /* 'display' */
6801 else if (varp == &p_dy)
6802 {
6803 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6804 errmsg = e_invarg;
6805 else
6806 (void)init_chartab();
6807
6808 }
6809
6810#ifdef FEAT_VERTSPLIT
6811 /* 'eadirection' */
6812 else if (varp == &p_ead)
6813 {
6814 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6815 errmsg = e_invarg;
6816 }
6817#endif
6818
6819#ifdef FEAT_CLIPBOARD
6820 /* 'clipboard' */
6821 else if (varp == &p_cb)
6822 errmsg = check_clipboard_option();
6823#endif
6824
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006825#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006826 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6827 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006828 else if (varp == &(curwin->w_s->b_p_spl)
6829 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006830 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006831 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006832 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006833 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006834 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006835 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006836 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006837 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006838 /* 'spellsuggest' */
6839 else if (varp == &p_sps)
6840 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006841 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006842 errmsg = e_invarg;
6843 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006844 /* 'mkspellmem' */
6845 else if (varp == &p_msm)
6846 {
6847 if (spell_check_msm() != OK)
6848 errmsg = e_invarg;
6849 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006850#endif
6851
Bram Moolenaar071d4272004-06-13 20:20:40 +00006852#ifdef FEAT_QUICKFIX
6853 /* When 'bufhidden' is set, check for valid value. */
6854 else if (gvarp == &p_bh)
6855 {
6856 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6857 errmsg = e_invarg;
6858 }
6859
6860 /* When 'buftype' is set, check for valid value. */
6861 else if (gvarp == &p_bt)
6862 {
6863 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6864 errmsg = e_invarg;
6865 else
6866 {
6867# ifdef FEAT_WINDOWS
6868 if (curwin->w_status_height)
6869 {
6870 curwin->w_redr_status = TRUE;
6871 redraw_later(VALID);
6872 }
6873# endif
6874 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006875# ifdef FEAT_TITLE
6876 redraw_titles();
6877# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006878 }
6879 }
6880#endif
6881
6882#ifdef FEAT_STL_OPT
6883 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006884 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006885 {
6886 int wid;
6887
6888 if (varp == &p_ruf) /* reset ru_wid first */
6889 ru_wid = 0;
6890 s = *varp;
6891 if (varp == &p_ruf && *s == '%')
6892 {
6893 /* set ru_wid if 'ruf' starts with "%99(" */
6894 if (*++s == '-') /* ignore a '-' */
6895 s++;
6896 wid = getdigits(&s);
6897 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6898 ru_wid = wid;
6899 else
6900 errmsg = check_stl_option(p_ruf);
6901 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006902 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006903 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006904 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006905 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906 comp_col();
6907 }
6908#endif
6909
6910#ifdef FEAT_INS_EXPAND
6911 /* check if it is a valid value for 'complete' -- Acevedo */
6912 else if (gvarp == &p_cpt)
6913 {
6914 for (s = *varp; *s;)
6915 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006916 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006917 s++;
6918 if (!*s)
6919 break;
6920 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6921 {
6922 errmsg = illegal_char(errbuf, *s);
6923 break;
6924 }
6925 if (*++s != NUL && *s != ',' && *s != ' ')
6926 {
6927 if (s[-1] == 'k' || s[-1] == 's')
6928 {
6929 /* skip optional filename after 'k' and 's' */
6930 while (*s && *s != ',' && *s != ' ')
6931 {
6932 if (*s == '\\')
6933 ++s;
6934 ++s;
6935 }
6936 }
6937 else
6938 {
6939 if (errbuf != NULL)
6940 {
6941 sprintf((char *)errbuf,
6942 _("E535: Illegal character after <%c>"),
6943 *--s);
6944 errmsg = errbuf;
6945 }
6946 else
6947 errmsg = (char_u *)"";
6948 break;
6949 }
6950 }
6951 }
6952 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00006953
6954 /* 'completeopt' */
6955 else if (varp == &p_cot)
6956 {
6957 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
6958 errmsg = e_invarg;
6959 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006960#endif /* FEAT_INS_EXPAND */
6961
6962
6963#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
6964 else if (varp == &p_toolbar)
6965 {
6966 if (opt_strings_flags(p_toolbar, p_toolbar_values,
6967 &toolbar_flags, TRUE) != OK)
6968 errmsg = e_invarg;
6969 else
6970 {
6971 out_flush();
6972 gui_mch_show_toolbar((toolbar_flags &
6973 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6974 }
6975 }
6976#endif
6977
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006978#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 /* 'toolbariconsize': GTK+ 2 only */
6980 else if (varp == &p_tbis)
6981 {
6982 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
6983 errmsg = e_invarg;
6984 else
6985 {
6986 out_flush();
6987 gui_mch_show_toolbar((toolbar_flags &
6988 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
6989 }
6990 }
6991#endif
6992
6993 /* 'pastetoggle': translate key codes like in a mapping */
6994 else if (varp == &p_pt)
6995 {
6996 if (*p_pt)
6997 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00006998 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006999 if (p != NULL)
7000 {
7001 if (new_value_alloced)
7002 free_string_option(p_pt);
7003 p_pt = p;
7004 new_value_alloced = TRUE;
7005 }
7006 }
7007 }
7008
7009 /* 'backspace' */
7010 else if (varp == &p_bs)
7011 {
7012 if (VIM_ISDIGIT(*p_bs))
7013 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007014 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015 errmsg = e_invarg;
7016 }
7017 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7018 errmsg = e_invarg;
7019 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007020 else if (varp == &p_bo)
7021 {
7022 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7023 errmsg = e_invarg;
7024 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007025
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007026 /* 'tagcase' */
7027 else if (gvarp == &p_tc)
7028 {
7029 unsigned int *flags;
7030
7031 if (opt_flags & OPT_LOCAL)
7032 {
7033 p = curbuf->b_p_tc;
7034 flags = &curbuf->b_tc_flags;
7035 }
7036 else
7037 {
7038 p = p_tc;
7039 flags = &tc_flags;
7040 }
7041
7042 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7043 /* make the local value empty: use the global value */
7044 *flags = 0;
7045 else if (*p == NUL
7046 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7047 errmsg = e_invarg;
7048 }
7049
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007050#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007051 /* 'casemap' */
7052 else if (varp == &p_cmp)
7053 {
7054 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7055 errmsg = e_invarg;
7056 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007057#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007058
7059#ifdef FEAT_DIFF
7060 /* 'diffopt' */
7061 else if (varp == &p_dip)
7062 {
7063 if (diffopt_changed() == FAIL)
7064 errmsg = e_invarg;
7065 }
7066#endif
7067
7068#ifdef FEAT_FOLDING
7069 /* 'foldmethod' */
7070 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7071 {
7072 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7073 || *curwin->w_p_fdm == NUL)
7074 errmsg = e_invarg;
7075 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007076 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007077 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007078 if (foldmethodIsDiff(curwin))
7079 newFoldLevel();
7080 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007081 }
7082# ifdef FEAT_EVAL
7083 /* 'foldexpr' */
7084 else if (varp == &curwin->w_p_fde)
7085 {
7086 if (foldmethodIsExpr(curwin))
7087 foldUpdateAll(curwin);
7088 }
7089# endif
7090 /* 'foldmarker' */
7091 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7092 {
7093 p = vim_strchr(*varp, ',');
7094 if (p == NULL)
7095 errmsg = (char_u *)N_("E536: comma required");
7096 else if (p == *varp || p[1] == NUL)
7097 errmsg = e_invarg;
7098 else if (foldmethodIsMarker(curwin))
7099 foldUpdateAll(curwin);
7100 }
7101 /* 'commentstring' */
7102 else if (gvarp == &p_cms)
7103 {
7104 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7105 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7106 }
7107 /* 'foldopen' */
7108 else if (varp == &p_fdo)
7109 {
7110 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7111 errmsg = e_invarg;
7112 }
7113 /* 'foldclose' */
7114 else if (varp == &p_fcl)
7115 {
7116 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7117 errmsg = e_invarg;
7118 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007119 /* 'foldignore' */
7120 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7121 {
7122 if (foldmethodIsIndent(curwin))
7123 foldUpdateAll(curwin);
7124 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125#endif
7126
7127#ifdef FEAT_VIRTUALEDIT
7128 /* 'virtualedit' */
7129 else if (varp == &p_ve)
7130 {
7131 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7132 errmsg = e_invarg;
7133 else if (STRCMP(p_ve, oldval) != 0)
7134 {
7135 /* Recompute cursor position in case the new 've' setting
7136 * changes something. */
7137 validate_virtcol();
7138 coladvance(curwin->w_virtcol);
7139 }
7140 }
7141#endif
7142
7143#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7144 else if (varp == &p_csqf)
7145 {
7146 if (p_csqf != NULL)
7147 {
7148 p = p_csqf;
7149 while (*p != NUL)
7150 {
7151 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7152 || p[1] == NUL
7153 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7154 || (p[2] != NUL && p[2] != ','))
7155 {
7156 errmsg = e_invarg;
7157 break;
7158 }
7159 else if (p[2] == NUL)
7160 break;
7161 else
7162 p += 3;
7163 }
7164 }
7165 }
7166#endif
7167
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007168#ifdef FEAT_CINDENT
7169 /* 'cinoptions' */
7170 else if (gvarp == &p_cino)
7171 {
7172 /* TODO: recognize errors */
7173 parse_cino(curbuf);
7174 }
7175#endif
7176
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007177#if defined(FEAT_RENDER_OPTIONS)
7178 else if (varp == &p_rop && gui.in_use)
7179 {
7180 if (!gui_mch_set_rendering_options(p_rop))
7181 errmsg = e_invarg;
7182 }
7183#endif
7184
Bram Moolenaar071d4272004-06-13 20:20:40 +00007185 /* Options that are a list of flags. */
7186 else
7187 {
7188 p = NULL;
7189 if (varp == &p_ww)
7190 p = (char_u *)WW_ALL;
7191 if (varp == &p_shm)
7192 p = (char_u *)SHM_ALL;
7193 else if (varp == &(p_cpo))
7194 p = (char_u *)CPO_ALL;
7195 else if (varp == &(curbuf->b_p_fo))
7196 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007197#ifdef FEAT_CONCEAL
7198 else if (varp == &curwin->w_p_cocu)
7199 p = (char_u *)COCU_ALL;
7200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007201 else if (varp == &p_mouse)
7202 {
7203#ifdef FEAT_MOUSE
7204 p = (char_u *)MOUSE_ALL;
7205#else
7206 if (*p_mouse != NUL)
7207 errmsg = (char_u *)N_("E538: No mouse support");
7208#endif
7209 }
7210#if defined(FEAT_GUI)
7211 else if (varp == &p_go)
7212 p = (char_u *)GO_ALL;
7213#endif
7214 if (p != NULL)
7215 {
7216 for (s = *varp; *s; ++s)
7217 if (vim_strchr(p, *s) == NULL)
7218 {
7219 errmsg = illegal_char(errbuf, *s);
7220 break;
7221 }
7222 }
7223 }
7224
7225 /*
7226 * If error detected, restore the previous value.
7227 */
7228 if (errmsg != NULL)
7229 {
7230 if (new_value_alloced)
7231 free_string_option(*varp);
7232 *varp = oldval;
7233 /*
7234 * When resetting some values, need to act on it.
7235 */
7236 if (did_chartab)
7237 (void)init_chartab();
7238 if (varp == &p_hl)
7239 (void)highlight_changed();
7240 }
7241 else
7242 {
7243#ifdef FEAT_EVAL
7244 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007245 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007246#endif
7247 /*
7248 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007249 * Use "free_oldval", because recursiveness may change the flags under
7250 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007252 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007253 free_string_option(oldval);
7254 if (new_value_alloced)
7255 options[opt_idx].flags |= P_ALLOCED;
7256 else
7257 options[opt_idx].flags &= ~P_ALLOCED;
7258
7259 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007260 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007261 {
7262 /* global option with local value set to use global value; free
7263 * the local value and make it empty */
7264 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7265 free_string_option(*(char_u **)p);
7266 *(char_u **)p = empty_option;
7267 }
7268
7269 /* May set global value for local option. */
7270 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7271 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007272
7273#ifdef FEAT_AUTOCMD
7274 /*
7275 * Trigger the autocommand only after setting the flags.
7276 */
7277# ifdef FEAT_SYN_HL
7278 /* When 'syntax' is set, load the syntax of that name */
7279 if (varp == &(curbuf->b_p_syn))
7280 {
7281 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7282 curbuf->b_fname, TRUE, curbuf);
7283 }
7284# endif
7285 else if (varp == &(curbuf->b_p_ft))
7286 {
7287 /* 'filetype' is set, trigger the FileType autocommand */
7288 did_filetype = TRUE;
7289 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7290 curbuf->b_fname, TRUE, curbuf);
7291 }
7292#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007293#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007294 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007295 {
7296 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007297 char_u *q = curwin->w_s->b_p_spl;
7298
7299 /* Skip the first name if it is "cjk". */
7300 if (STRNCMP(q, "cjk,", 4) == 0)
7301 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007302
7303 /*
7304 * Source the spell/LANG.vim in 'runtimepath'.
7305 * They could set 'spellcapcheck' depending on the language.
7306 * Use the first name in 'spelllang' up to '_region' or
7307 * '.encoding'.
7308 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007309 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007310 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7311 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007312 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007313 source_runtime(fname, TRUE);
7314 }
7315#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007316 }
7317
7318#ifdef FEAT_MOUSE
7319 if (varp == &p_mouse)
7320 {
7321# ifdef FEAT_MOUSE_TTY
7322 if (*p_mouse == NUL)
7323 mch_setmouse(FALSE); /* switch mouse off */
7324 else
7325# endif
7326 setmouse(); /* in case 'mouse' changed */
7327 }
7328#endif
7329
Bram Moolenaar913077c2012-03-28 19:59:04 +02007330 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007331 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007332 curwin->w_set_curswant = TRUE;
7333
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007334#ifdef FEAT_GUI
7335 /* check redraw when it's not a GUI option or the GUI is active. */
7336 if (!redraw_gui_only || gui.in_use)
7337#endif
7338 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007339
7340 return errmsg;
7341}
7342
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007343#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007344/*
7345 * Simple int comparison function for use with qsort()
7346 */
7347 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007348int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007349{
7350 return *(const int *)a - *(const int *)b;
7351}
7352
7353/*
7354 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7355 * Returns error message, NULL if it's OK.
7356 */
7357 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007358check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007359{
7360 char_u *s;
7361 int col;
7362 int count = 0;
7363 int color_cols[256];
7364 int i;
7365 int j = 0;
7366
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007367 if (wp->w_buffer == NULL)
7368 return NULL; /* buffer was closed */
7369
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007370 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007371 {
7372 if (*s == '-' || *s == '+')
7373 {
7374 /* -N and +N: add to 'textwidth' */
7375 col = (*s == '-') ? -1 : 1;
7376 ++s;
7377 if (!VIM_ISDIGIT(*s))
7378 return e_invarg;
7379 col = col * getdigits(&s);
7380 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007381 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007382 col += wp->w_buffer->b_p_tw;
7383 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007384 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007385 }
7386 else if (VIM_ISDIGIT(*s))
7387 col = getdigits(&s);
7388 else
7389 return e_invarg;
7390 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007391skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007392 if (*s == NUL)
7393 break;
7394 if (*s != ',')
7395 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007396 if (*++s == NUL)
7397 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007398 }
7399
7400 vim_free(wp->w_p_cc_cols);
7401 if (count == 0)
7402 wp->w_p_cc_cols = NULL;
7403 else
7404 {
7405 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7406 if (wp->w_p_cc_cols != NULL)
7407 {
7408 /* sort the columns for faster usage on screen redraw inside
7409 * win_line() */
7410 qsort(color_cols, count, sizeof(int), int_cmp);
7411
7412 for (i = 0; i < count; ++i)
7413 /* skip duplicates */
7414 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7415 wp->w_p_cc_cols[j++] = color_cols[i];
7416 wp->w_p_cc_cols[j] = -1; /* end marker */
7417 }
7418 }
7419
7420 return NULL; /* no error */
7421}
7422#endif
7423
Bram Moolenaar071d4272004-06-13 20:20:40 +00007424/*
7425 * Handle setting 'listchars' or 'fillchars'.
7426 * Returns error message, NULL if it's OK.
7427 */
7428 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007429set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007430{
7431 int round, i, len, entries;
7432 char_u *p, *s;
7433 int c1, c2 = 0;
7434 struct charstab
7435 {
7436 int *cp;
7437 char *name;
7438 };
7439#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7440 static struct charstab filltab[] =
7441 {
7442 {&fill_stl, "stl"},
7443 {&fill_stlnc, "stlnc"},
7444 {&fill_vert, "vert"},
7445 {&fill_fold, "fold"},
7446 {&fill_diff, "diff"},
7447 };
7448#endif
7449 static struct charstab lcstab[] =
7450 {
7451 {&lcs_eol, "eol"},
7452 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007453 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007454 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007455 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007456 {&lcs_tab2, "tab"},
7457 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007458#ifdef FEAT_CONCEAL
7459 {&lcs_conceal, "conceal"},
7460#else
7461 {NULL, "conceal"},
7462#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463 };
7464 struct charstab *tab;
7465
7466#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7467 if (varp == &p_lcs)
7468#endif
7469 {
7470 tab = lcstab;
7471 entries = sizeof(lcstab) / sizeof(struct charstab);
7472 }
7473#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7474 else
7475 {
7476 tab = filltab;
7477 entries = sizeof(filltab) / sizeof(struct charstab);
7478 }
7479#endif
7480
7481 /* first round: check for valid value, second round: assign values */
7482 for (round = 0; round <= 1; ++round)
7483 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007484 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007485 {
7486 /* After checking that the value is valid: set defaults: space for
7487 * 'fillchars', NUL for 'listchars' */
7488 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007489 if (tab[i].cp != NULL)
7490 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491 if (varp == &p_lcs)
7492 lcs_tab1 = NUL;
7493#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7494 else
7495 fill_diff = '-';
7496#endif
7497 }
7498 p = *varp;
7499 while (*p)
7500 {
7501 for (i = 0; i < entries; ++i)
7502 {
7503 len = (int)STRLEN(tab[i].name);
7504 if (STRNCMP(p, tab[i].name, len) == 0
7505 && p[len] == ':'
7506 && p[len + 1] != NUL)
7507 {
7508 s = p + len + 1;
7509#ifdef FEAT_MBYTE
7510 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007511 if (mb_char2cells(c1) > 1)
7512 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007513#else
7514 c1 = *s++;
7515#endif
7516 if (tab[i].cp == &lcs_tab2)
7517 {
7518 if (*s == NUL)
7519 continue;
7520#ifdef FEAT_MBYTE
7521 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007522 if (mb_char2cells(c2) > 1)
7523 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007524#else
7525 c2 = *s++;
7526#endif
7527 }
7528 if (*s == ',' || *s == NUL)
7529 {
7530 if (round)
7531 {
7532 if (tab[i].cp == &lcs_tab2)
7533 {
7534 lcs_tab1 = c1;
7535 lcs_tab2 = c2;
7536 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007537 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007538 *(tab[i].cp) = c1;
7539
7540 }
7541 p = s;
7542 break;
7543 }
7544 }
7545 }
7546
7547 if (i == entries)
7548 return e_invarg;
7549 if (*p == ',')
7550 ++p;
7551 }
7552 }
7553
7554 return NULL; /* no error */
7555}
7556
7557#ifdef FEAT_STL_OPT
7558/*
7559 * Check validity of options with the 'statusline' format.
7560 * Return error message or NULL.
7561 */
7562 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007563check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007564{
7565 int itemcnt = 0;
7566 int groupdepth = 0;
7567 static char_u errbuf[80];
7568
7569 while (*s && itemcnt < STL_MAX_ITEM)
7570 {
7571 /* Check for valid keys after % sequences */
7572 while (*s && *s != '%')
7573 s++;
7574 if (!*s)
7575 break;
7576 s++;
7577 if (*s != '%' && *s != ')')
7578 ++itemcnt;
7579 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7580 {
7581 s++;
7582 continue;
7583 }
7584 if (*s == ')')
7585 {
7586 s++;
7587 if (--groupdepth < 0)
7588 break;
7589 continue;
7590 }
7591 if (*s == '-')
7592 s++;
7593 while (VIM_ISDIGIT(*s))
7594 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007595 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007596 continue;
7597 if (*s == '.')
7598 {
7599 s++;
7600 while (*s && VIM_ISDIGIT(*s))
7601 s++;
7602 }
7603 if (*s == '(')
7604 {
7605 groupdepth++;
7606 continue;
7607 }
7608 if (vim_strchr(STL_ALL, *s) == NULL)
7609 {
7610 return illegal_char(errbuf, *s);
7611 }
7612 if (*s == '{')
7613 {
7614 s++;
7615 while (*s != '}' && *s)
7616 s++;
7617 if (*s != '}')
7618 return (char_u *)N_("E540: Unclosed expression sequence");
7619 }
7620 }
7621 if (itemcnt >= STL_MAX_ITEM)
7622 return (char_u *)N_("E541: too many items");
7623 if (groupdepth != 0)
7624 return (char_u *)N_("E542: unbalanced groups");
7625 return NULL;
7626}
7627#endif
7628
7629#ifdef FEAT_CLIPBOARD
7630/*
7631 * Extract the items in the 'clipboard' option and set global values.
7632 */
7633 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007634check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007635{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007636 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007637 int new_autoselect_star = FALSE;
7638 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007639 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007640 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007641 regprog_T *new_exclude_prog = NULL;
7642 char_u *errmsg = NULL;
7643 char_u *p;
7644
7645 for (p = p_cb; *p != NUL; )
7646 {
7647 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7648 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007649 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007650 p += 7;
7651 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007652 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007653 && (p[11] == ',' || p[11] == NUL))
7654 {
7655 new_unnamed |= CLIP_UNNAMED_PLUS;
7656 p += 11;
7657 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007658 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007659 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007660 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007661 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007662 p += 10;
7663 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007664 else if (STRNCMP(p, "autoselectplus", 14) == 0
7665 && (p[14] == ',' || p[14] == NUL))
7666 {
7667 new_autoselect_plus = TRUE;
7668 p += 14;
7669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007670 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007671 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007672 {
7673 new_autoselectml = TRUE;
7674 p += 12;
7675 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007676 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7677 {
7678 new_html = TRUE;
7679 p += 4;
7680 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007681 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7682 {
7683 p += 8;
7684 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7685 if (new_exclude_prog == NULL)
7686 errmsg = e_invarg;
7687 break;
7688 }
7689 else
7690 {
7691 errmsg = e_invarg;
7692 break;
7693 }
7694 if (*p == ',')
7695 ++p;
7696 }
7697 if (errmsg == NULL)
7698 {
7699 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007700 clip_autoselect_star = new_autoselect_star;
7701 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007702 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007703 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007704 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007705 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007706#ifdef FEAT_GUI_GTK
7707 if (gui.in_use)
7708 {
7709 gui_gtk_set_selection_targets();
7710 gui_gtk_set_dnd_targets();
7711 }
7712#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 }
7714 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007715 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007716
7717 return errmsg;
7718}
7719#endif
7720
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007721#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007722 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007723did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007724{
7725 char_u *errmsg = NULL;
7726 win_T *wp;
7727 int l;
7728
7729 if (is_spellfile)
7730 {
7731 l = (int)STRLEN(curwin->w_s->b_p_spf);
7732 if (l > 0 && (l < 4
7733 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7734 errmsg = e_invarg;
7735 }
7736
7737 if (errmsg == NULL)
7738 {
7739 FOR_ALL_WINDOWS(wp)
7740 if (wp->w_buffer == curbuf && wp->w_p_spell)
7741 {
7742 errmsg = did_set_spelllang(wp);
7743# ifdef FEAT_WINDOWS
7744 break;
7745# endif
7746 }
7747 }
7748 return errmsg;
7749}
7750
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007751/*
7752 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7753 * Return error message when failed, NULL when OK.
7754 */
7755 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007756compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007757{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007758 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007759 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007760
Bram Moolenaar860cae12010-06-05 23:22:07 +02007761 if (*synblock->b_p_spc == NUL)
7762 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007763 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007764 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007765 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007766 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007767 if (re != NULL)
7768 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007769 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007770 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007771 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007772 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007773 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007774 return e_invarg;
7775 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007776 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007777 }
7778
Bram Moolenaar473de612013-06-08 18:19:48 +02007779 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007780 return NULL;
7781}
7782#endif
7783
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007784#if defined(FEAT_EVAL) || defined(PROTO)
7785/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007786 * Set the scriptID for an option, taking care of setting the buffer- or
7787 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007788 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007789 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007790set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007791{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007792 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7793 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007794
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007795 /* Remember where the option was set. For local options need to do that
7796 * in the buffer or window structure. */
7797 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007798 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007799 if (both || (opt_flags & OPT_LOCAL))
7800 {
7801 if (indir & PV_BUF)
7802 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7803 else if (indir & PV_WIN)
7804 curwin->w_p_scriptID[indir & PV_MASK] = id;
7805 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007806}
7807#endif
7808
Bram Moolenaar071d4272004-06-13 20:20:40 +00007809/*
7810 * Set the value of a boolean option, and take care of side effects.
7811 * Returns NULL for success, or an error message for an error.
7812 */
7813 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007814set_bool_option(
7815 int opt_idx, /* index in options[] table */
7816 char_u *varp, /* pointer to the option variable */
7817 int value, /* new value */
7818 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819{
7820 int old_value = *(int *)varp;
7821
Bram Moolenaar071d4272004-06-13 20:20:40 +00007822 /* Disallow changing some options from secure mode */
7823 if ((secure
7824#ifdef HAVE_SANDBOX
7825 || sandbox != 0
7826#endif
7827 ) && (options[opt_idx].flags & P_SECURE))
7828 return e_secure;
7829
7830 *(int *)varp = value; /* set the new value */
7831#ifdef FEAT_EVAL
7832 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007833 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007834#endif
7835
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007836#ifdef FEAT_GUI
7837 need_mouse_correct = TRUE;
7838#endif
7839
Bram Moolenaar071d4272004-06-13 20:20:40 +00007840 /* May set global value for local option. */
7841 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7842 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7843
7844 /*
7845 * Handle side effects of changing a bool option.
7846 */
7847
7848 /* 'compatible' */
7849 if ((int *)varp == &p_cp)
7850 {
7851 compatible_set();
7852 }
7853
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007854#ifdef FEAT_PERSISTENT_UNDO
7855 /* 'undofile' */
7856 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7857 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007858 /* Only take action when the option was set. When reset we do not
7859 * delete the undo file, the option may be set again without making
7860 * any changes in between. */
7861 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007862 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007863 char_u hash[UNDO_HASH_SIZE];
7864 buf_T *save_curbuf = curbuf;
7865
7866 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007867 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007868 /* When 'undofile' is set globally: for every buffer, otherwise
7869 * only for the current buffer: Try to read in the undofile,
7870 * if one exists, the buffer wasn't changed and the buffer was
7871 * loaded */
7872 if ((curbuf == save_curbuf
7873 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7874 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7875 {
7876 u_compute_hash(hash);
7877 u_read_undo(NULL, hash, curbuf->b_fname);
7878 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007879 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007880 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007881 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007882 }
7883#endif
7884
Bram Moolenaar071d4272004-06-13 20:20:40 +00007885 else if ((int *)varp == &curbuf->b_p_ro)
7886 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007887 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007888 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7889 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007890
7891 /* when 'readonly' is set may give W10 again */
7892 if (curbuf->b_p_ro)
7893 curbuf->b_did_warn = FALSE;
7894
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007896 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007897#endif
7898 }
7899
Bram Moolenaar9c449722010-07-20 18:44:27 +02007900#ifdef FEAT_GUI
7901 else if ((int *)varp == &p_mh)
7902 {
7903 if (!p_mh)
7904 gui_mch_mousehide(FALSE);
7905 }
7906#endif
7907
Bram Moolenaara539df02010-08-01 14:35:05 +02007908#ifdef FEAT_TITLE
7909 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007910 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007911 {
7912 redraw_titles();
7913 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 /* when 'endofline' is changed, redraw the window title */
7915 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007916 {
7917 redraw_titles();
7918 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02007919 /* when 'fixeol' is changed, redraw the window title */
7920 else if ((int *)varp == &curbuf->b_p_fixeol)
7921 {
7922 redraw_titles();
7923 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007924# ifdef FEAT_MBYTE
7925 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00007926 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007927 {
7928 redraw_titles();
7929 }
7930# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007931#endif
7932
7933 /* when 'bin' is set also set some other options */
7934 else if ((int *)varp == &curbuf->b_p_bin)
7935 {
7936 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
7937#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007938 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939#endif
7940 }
7941
7942#ifdef FEAT_AUTOCMD
7943 /* when 'buflisted' changes, trigger autocommands */
7944 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
7945 {
7946 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
7947 NULL, NULL, TRUE, curbuf);
7948 }
7949#endif
7950
7951 /* when 'swf' is set, create swapfile, when reset remove swapfile */
7952 else if ((int *)varp == &curbuf->b_p_swf)
7953 {
7954 if (curbuf->b_p_swf && p_uc)
7955 ml_open_file(curbuf); /* create the swap file */
7956 else
Bram Moolenaard55de222007-05-06 13:38:48 +00007957 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
7958 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007959 mf_close_file(curbuf, TRUE); /* remove the swap file */
7960 }
7961
7962 /* when 'terse' is set change 'shortmess' */
7963 else if ((int *)varp == &p_terse)
7964 {
7965 char_u *p;
7966
7967 p = vim_strchr(p_shm, SHM_SEARCH);
7968
7969 /* insert 's' in p_shm */
7970 if (p_terse && p == NULL)
7971 {
7972 STRCPY(IObuff, p_shm);
7973 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007974 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007975 }
7976 /* remove 's' from p_shm */
7977 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007978 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007979 }
7980
7981 /* when 'paste' is set or reset also change other options */
7982 else if ((int *)varp == &p_paste)
7983 {
7984 paste_option_changed();
7985 }
7986
7987 /* when 'insertmode' is set from an autocommand need to do work here */
7988 else if ((int *)varp == &p_im)
7989 {
7990 if (p_im)
7991 {
7992 if ((State & INSERT) == 0)
7993 need_start_insertmode = TRUE;
7994 stop_insert_mode = FALSE;
7995 }
7996 else
7997 {
7998 need_start_insertmode = FALSE;
7999 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008000 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001 clear_cmdline = TRUE; /* remove "(insert)" */
8002 restart_edit = 0;
8003 }
8004 }
8005
8006 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8007 else if ((int *)varp == &p_ic && p_hls)
8008 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008009 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 }
8011
8012#ifdef FEAT_SEARCH_EXTRA
8013 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8014 else if ((int *)varp == &p_hls)
8015 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008016 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 }
8018#endif
8019
8020#ifdef FEAT_SCROLLBIND
8021 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8022 * at the end of normal_cmd() */
8023 else if ((int *)varp == &curwin->w_p_scb)
8024 {
8025 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008026 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008027 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008028 curwin->w_scbind_pos = curwin->w_topline;
8029 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008030 }
8031#endif
8032
8033#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8034 /* There can be only one window with 'previewwindow' set. */
8035 else if ((int *)varp == &curwin->w_p_pvw)
8036 {
8037 if (curwin->w_p_pvw)
8038 {
8039 win_T *win;
8040
8041 for (win = firstwin; win != NULL; win = win->w_next)
8042 if (win->w_p_pvw && win != curwin)
8043 {
8044 curwin->w_p_pvw = FALSE;
8045 return (char_u *)N_("E590: A preview window already exists");
8046 }
8047 }
8048 }
8049#endif
8050
8051 /* when 'textmode' is set or reset also change 'fileformat' */
8052 else if ((int *)varp == &curbuf->b_p_tx)
8053 {
8054 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8055 }
8056
8057 /* when 'textauto' is set or reset also change 'fileformats' */
8058 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008059 set_string_option_direct((char_u *)"ffs", -1,
8060 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008061 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008062
8063 /*
8064 * When 'lisp' option changes include/exclude '-' in
8065 * keyword characters.
8066 */
8067#ifdef FEAT_LISP
8068 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8069 {
8070 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8071 }
8072#endif
8073
8074#ifdef FEAT_TITLE
8075 /* when 'title' changed, may need to change the title; same for 'icon' */
8076 else if ((int *)varp == &p_title)
8077 {
8078 did_set_title(FALSE);
8079 }
8080
8081 else if ((int *)varp == &p_icon)
8082 {
8083 did_set_title(TRUE);
8084 }
8085#endif
8086
8087 else if ((int *)varp == &curbuf->b_changed)
8088 {
8089 if (!value)
8090 save_file_ff(curbuf); /* Buffer is unchanged */
8091#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008092 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093#endif
8094#ifdef FEAT_AUTOCMD
8095 modified_was_set = value;
8096#endif
8097 }
8098
8099#ifdef BACKSLASH_IN_FILENAME
8100 else if ((int *)varp == &p_ssl)
8101 {
8102 if (p_ssl)
8103 {
8104 psepc = '/';
8105 psepcN = '\\';
8106 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008107 }
8108 else
8109 {
8110 psepc = '\\';
8111 psepcN = '/';
8112 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008113 }
8114
8115 /* need to adjust the file name arguments and buffer names. */
8116 buflist_slash_adjust();
8117 alist_slash_adjust();
8118# ifdef FEAT_EVAL
8119 scriptnames_slash_adjust();
8120# endif
8121 }
8122#endif
8123
8124 /* If 'wrap' is set, set w_leftcol to zero. */
8125 else if ((int *)varp == &curwin->w_p_wrap)
8126 {
8127 if (curwin->w_p_wrap)
8128 curwin->w_leftcol = 0;
8129 }
8130
8131#ifdef FEAT_WINDOWS
8132 else if ((int *)varp == &p_ea)
8133 {
8134 if (p_ea && !old_value)
8135 win_equal(curwin, FALSE, 0);
8136 }
8137#endif
8138
8139 else if ((int *)varp == &p_wiv)
8140 {
8141 /*
8142 * When 'weirdinvert' changed, set/reset 't_xs'.
8143 * Then set 'weirdinvert' according to value of 't_xs'.
8144 */
8145 if (p_wiv && !old_value)
8146 T_XS = (char_u *)"y";
8147 else if (!p_wiv && old_value)
8148 T_XS = empty_option;
8149 p_wiv = (*T_XS != NUL);
8150 }
8151
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008152#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153 else if ((int *)varp == &p_beval)
8154 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008155 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008157 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 gui_mch_disable_beval_area(balloonEval);
8159 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008160#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008162#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 else if ((int *)varp == &p_acd)
8164 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008165 /* Change directories when the 'acd' option is set now. */
8166 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 }
8168#endif
8169
8170#ifdef FEAT_DIFF
8171 /* 'diff' */
8172 else if ((int *)varp == &curwin->w_p_diff)
8173 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008174 /* May add or remove the buffer from the list of diff buffers. */
8175 diff_buf_adjust(curwin);
8176# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008177 if (foldmethodIsDiff(curwin))
8178 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008179# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008180 }
8181#endif
8182
8183#ifdef USE_IM_CONTROL
8184 /* 'imdisable' */
8185 else if ((int *)varp == &p_imdisable)
8186 {
8187 /* Only de-activate it here, it will be enabled when changing mode. */
8188 if (p_imdisable)
8189 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008190 else if (State & INSERT)
8191 /* When the option is set from an autocommand, it may need to take
8192 * effect right away. */
8193 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008194 }
8195#endif
8196
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008197#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008198 /* 'spell' */
8199 else if ((int *)varp == &curwin->w_p_spell)
8200 {
8201 if (curwin->w_p_spell)
8202 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008203 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008204 if (errmsg != NULL)
8205 EMSG(_(errmsg));
8206 }
8207 }
8208#endif
8209
Bram Moolenaar071d4272004-06-13 20:20:40 +00008210#ifdef FEAT_FKMAP
8211 else if ((int *)varp == &p_altkeymap)
8212 {
8213 if (old_value != p_altkeymap)
8214 {
8215 if (!p_altkeymap)
8216 {
8217 p_hkmap = p_fkmap;
8218 p_fkmap = 0;
8219 }
8220 else
8221 {
8222 p_fkmap = p_hkmap;
8223 p_hkmap = 0;
8224 }
8225 (void)init_chartab();
8226 }
8227 }
8228
8229 /*
8230 * In case some second language keymapping options have changed, check
8231 * and correct the setting in a consistent way.
8232 */
8233
8234 /*
8235 * If hkmap or fkmap are set, reset Arabic keymapping.
8236 */
8237 if ((p_hkmap || p_fkmap) && p_altkeymap)
8238 {
8239 p_altkeymap = p_fkmap;
8240# ifdef FEAT_ARABIC
8241 curwin->w_p_arab = FALSE;
8242# endif
8243 (void)init_chartab();
8244 }
8245
8246 /*
8247 * If hkmap set, reset Farsi keymapping.
8248 */
8249 if (p_hkmap && p_altkeymap)
8250 {
8251 p_altkeymap = 0;
8252 p_fkmap = 0;
8253# ifdef FEAT_ARABIC
8254 curwin->w_p_arab = FALSE;
8255# endif
8256 (void)init_chartab();
8257 }
8258
8259 /*
8260 * If fkmap set, reset Hebrew keymapping.
8261 */
8262 if (p_fkmap && !p_altkeymap)
8263 {
8264 p_altkeymap = 1;
8265 p_hkmap = 0;
8266# ifdef FEAT_ARABIC
8267 curwin->w_p_arab = FALSE;
8268# endif
8269 (void)init_chartab();
8270 }
8271#endif
8272
8273#ifdef FEAT_ARABIC
8274 if ((int *)varp == &curwin->w_p_arab)
8275 {
8276 if (curwin->w_p_arab)
8277 {
8278 /*
8279 * 'arabic' is set, handle various sub-settings.
8280 */
8281 if (!p_tbidi)
8282 {
8283 /* set rightleft mode */
8284 if (!curwin->w_p_rl)
8285 {
8286 curwin->w_p_rl = TRUE;
8287 changed_window_setting();
8288 }
8289
8290 /* Enable Arabic shaping (major part of what Arabic requires) */
8291 if (!p_arshape)
8292 {
8293 p_arshape = TRUE;
8294 redraw_later_clear();
8295 }
8296 }
8297
8298 /* Arabic requires a utf-8 encoding, inform the user if its not
8299 * set. */
8300 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008301 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008302 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8303
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008304 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008305 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8306#ifdef FEAT_EVAL
8307 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8308#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008309 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008310
8311# ifdef FEAT_MBYTE
8312 /* set 'delcombine' */
8313 p_deco = TRUE;
8314# endif
8315
8316# ifdef FEAT_KEYMAP
8317 /* Force-set the necessary keymap for arabic */
8318 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8319 OPT_LOCAL);
8320# endif
8321# ifdef FEAT_FKMAP
8322 p_altkeymap = 0;
8323 p_hkmap = 0;
8324 p_fkmap = 0;
8325 (void)init_chartab();
8326# endif
8327 }
8328 else
8329 {
8330 /*
8331 * 'arabic' is reset, handle various sub-settings.
8332 */
8333 if (!p_tbidi)
8334 {
8335 /* reset rightleft mode */
8336 if (curwin->w_p_rl)
8337 {
8338 curwin->w_p_rl = FALSE;
8339 changed_window_setting();
8340 }
8341
8342 /* 'arabicshape' isn't reset, it is a global option and
8343 * another window may still need it "on". */
8344 }
8345
8346 /* 'delcombine' isn't reset, it is a global option and another
8347 * window may still want it "on". */
8348
8349# ifdef FEAT_KEYMAP
8350 /* Revert to the default keymap */
8351 curbuf->b_p_iminsert = B_IMODE_NONE;
8352 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8353# endif
8354 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008355 }
8356
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008357#endif
8358
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359 /*
8360 * End of handling side effects for bool options.
8361 */
8362
Bram Moolenaar53744302015-07-17 17:38:22 +02008363 /* after handling side effects, call autocommand */
8364
Bram Moolenaar071d4272004-06-13 20:20:40 +00008365 options[opt_idx].flags |= P_WAS_SET;
8366
Bram Moolenaar53744302015-07-17 17:38:22 +02008367#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8368 if (!starting)
8369 {
8370 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008371 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8372 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8373 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008374 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8375 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8376 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8377 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8378 reset_v_option_vars();
8379 }
8380#endif
8381
Bram Moolenaar071d4272004-06-13 20:20:40 +00008382 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008383 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008384 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008385 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008386 check_redraw(options[opt_idx].flags);
8387
8388 return NULL;
8389}
8390
8391/*
8392 * Set the value of a number option, and take care of side effects.
8393 * Returns NULL for success, or an error message for an error.
8394 */
8395 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008396set_num_option(
8397 int opt_idx, /* index in options[] table */
8398 char_u *varp, /* pointer to the option variable */
8399 long value, /* new value */
8400 char_u *errbuf, /* buffer for error messages */
8401 size_t errbuflen, /* length of "errbuf" */
8402 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403 OPT_MODELINE */
8404{
8405 char_u *errmsg = NULL;
8406 long old_value = *(long *)varp;
8407 long old_Rows = Rows; /* remember old Rows */
8408 long old_Columns = Columns; /* remember old Columns */
8409 long *pp = (long *)varp;
8410
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008411 /* Disallow changing some options from secure mode. */
8412 if ((secure
8413#ifdef HAVE_SANDBOX
8414 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008416 ) && (options[opt_idx].flags & P_SECURE))
8417 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418
8419 *pp = value;
8420#ifdef FEAT_EVAL
8421 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008422 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008424#ifdef FEAT_GUI
8425 need_mouse_correct = TRUE;
8426#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008427
Bram Moolenaar14f24742012-08-08 18:01:05 +02008428 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008429 {
8430 errmsg = e_positive;
8431 curbuf->b_p_sw = curbuf->b_p_ts;
8432 }
8433
8434 /*
8435 * Number options that need some action when changed
8436 */
8437#ifdef FEAT_WINDOWS
8438 if (pp == &p_wh || pp == &p_hh)
8439 {
8440 if (p_wh < 1)
8441 {
8442 errmsg = e_positive;
8443 p_wh = 1;
8444 }
8445 if (p_wmh > p_wh)
8446 {
8447 errmsg = e_winheight;
8448 p_wh = p_wmh;
8449 }
8450 if (p_hh < 0)
8451 {
8452 errmsg = e_positive;
8453 p_hh = 0;
8454 }
8455
8456 /* Change window height NOW */
8457 if (lastwin != firstwin)
8458 {
8459 if (pp == &p_wh && curwin->w_height < p_wh)
8460 win_setheight((int)p_wh);
8461 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8462 win_setheight((int)p_hh);
8463 }
8464 }
8465
8466 /* 'winminheight' */
8467 else if (pp == &p_wmh)
8468 {
8469 if (p_wmh < 0)
8470 {
8471 errmsg = e_positive;
8472 p_wmh = 0;
8473 }
8474 if (p_wmh > p_wh)
8475 {
8476 errmsg = e_winheight;
8477 p_wmh = p_wh;
8478 }
8479 win_setminheight();
8480 }
8481
8482# ifdef FEAT_VERTSPLIT
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008483 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008484 {
8485 if (p_wiw < 1)
8486 {
8487 errmsg = e_positive;
8488 p_wiw = 1;
8489 }
8490 if (p_wmw > p_wiw)
8491 {
8492 errmsg = e_winwidth;
8493 p_wiw = p_wmw;
8494 }
8495
8496 /* Change window width NOW */
8497 if (lastwin != firstwin && curwin->w_width < p_wiw)
8498 win_setwidth((int)p_wiw);
8499 }
8500
8501 /* 'winminwidth' */
8502 else if (pp == &p_wmw)
8503 {
8504 if (p_wmw < 0)
8505 {
8506 errmsg = e_positive;
8507 p_wmw = 0;
8508 }
8509 if (p_wmw > p_wiw)
8510 {
8511 errmsg = e_winwidth;
8512 p_wmw = p_wiw;
8513 }
8514 win_setminheight();
8515 }
8516# endif
8517
8518#endif
8519
8520#ifdef FEAT_WINDOWS
8521 /* (re)set last window status line */
8522 else if (pp == &p_ls)
8523 {
8524 last_status(FALSE);
8525 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008526
8527 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008528 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008529 {
8530 shell_new_rows(); /* recompute window positions and heights */
8531 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532#endif
8533
8534#ifdef FEAT_GUI
8535 else if (pp == &p_linespace)
8536 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008537 /* Recompute gui.char_height and resize the Vim window to keep the
8538 * same number of lines. */
8539 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008540 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008541 }
8542#endif
8543
8544#ifdef FEAT_FOLDING
8545 /* 'foldlevel' */
8546 else if (pp == &curwin->w_p_fdl)
8547 {
8548 if (curwin->w_p_fdl < 0)
8549 curwin->w_p_fdl = 0;
8550 newFoldLevel();
8551 }
8552
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008553 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008554 else if (pp == &curwin->w_p_fml)
8555 {
8556 foldUpdateAll(curwin);
8557 }
8558
8559 /* 'foldnestmax' */
8560 else if (pp == &curwin->w_p_fdn)
8561 {
8562 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8563 foldUpdateAll(curwin);
8564 }
8565
8566 /* 'foldcolumn' */
8567 else if (pp == &curwin->w_p_fdc)
8568 {
8569 if (curwin->w_p_fdc < 0)
8570 {
8571 errmsg = e_positive;
8572 curwin->w_p_fdc = 0;
8573 }
8574 else if (curwin->w_p_fdc > 12)
8575 {
8576 errmsg = e_invarg;
8577 curwin->w_p_fdc = 12;
8578 }
8579 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008580#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008581
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008582#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008583 /* 'shiftwidth' or 'tabstop' */
8584 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8585 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008586# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008587 if (foldmethodIsIndent(curwin))
8588 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008589# endif
8590# ifdef FEAT_CINDENT
8591 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8592 * parse 'cinoptions'. */
8593 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8594 parse_cino(curbuf);
8595# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008596 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008597#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008598
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008599#ifdef FEAT_MBYTE
8600 /* 'maxcombine' */
8601 else if (pp == &p_mco)
8602 {
8603 if (p_mco > MAX_MCO)
8604 p_mco = MAX_MCO;
8605 else if (p_mco < 0)
8606 p_mco = 0;
8607 screenclear(); /* will re-allocate the screen */
8608 }
8609#endif
8610
Bram Moolenaar071d4272004-06-13 20:20:40 +00008611 else if (pp == &curbuf->b_p_iminsert)
8612 {
8613 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8614 {
8615 errmsg = e_invarg;
8616 curbuf->b_p_iminsert = B_IMODE_NONE;
8617 }
8618 p_iminsert = curbuf->b_p_iminsert;
8619 if (termcap_active) /* don't do this in the alternate screen */
8620 showmode();
8621#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8622 /* Show/unshow value of 'keymap' in status lines. */
8623 status_redraw_curbuf();
8624#endif
8625 }
8626
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008627 else if (pp == &p_window)
8628 {
8629 if (p_window < 1)
8630 p_window = 1;
8631 else if (p_window >= Rows)
8632 p_window = Rows - 1;
8633 }
8634
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635 else if (pp == &curbuf->b_p_imsearch)
8636 {
8637 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8638 {
8639 errmsg = e_invarg;
8640 curbuf->b_p_imsearch = B_IMODE_NONE;
8641 }
8642 p_imsearch = curbuf->b_p_imsearch;
8643 }
8644
8645#ifdef FEAT_TITLE
8646 /* if 'titlelen' has changed, redraw the title */
8647 else if (pp == &p_titlelen)
8648 {
8649 if (p_titlelen < 0)
8650 {
8651 errmsg = e_positive;
8652 p_titlelen = 85;
8653 }
8654 if (starting != NO_SCREEN && old_value != p_titlelen)
8655 need_maketitle = TRUE;
8656 }
8657#endif
8658
8659 /* if p_ch changed value, change the command line height */
8660 else if (pp == &p_ch)
8661 {
8662 if (p_ch < 1)
8663 {
8664 errmsg = e_positive;
8665 p_ch = 1;
8666 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008667 if (p_ch > Rows - min_rows() + 1)
8668 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008669
8670 /* Only compute the new window layout when startup has been
8671 * completed. Otherwise the frame sizes may be wrong. */
8672 if (p_ch != old_value && full_screen
8673#ifdef FEAT_GUI
8674 && !gui.starting
8675#endif
8676 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008677 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008678 }
8679
8680 /* when 'updatecount' changes from zero to non-zero, open swap files */
8681 else if (pp == &p_uc)
8682 {
8683 if (p_uc < 0)
8684 {
8685 errmsg = e_positive;
8686 p_uc = 100;
8687 }
8688 if (p_uc && !old_value)
8689 ml_open_files();
8690 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008691#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008692 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008693 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008694 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008695 {
8696 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008697 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008698 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008699 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008700 {
8701 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008702 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008703 }
8704 }
8705#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008706#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008707 else if (pp == &p_mzq)
8708 mzvim_reset_timer();
8709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008710
8711 /* sync undo before 'undolevels' changes */
8712 else if (pp == &p_ul)
8713 {
8714 /* use the old value, otherwise u_sync() may not work properly */
8715 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008716 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008717 p_ul = value;
8718 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008719 else if (pp == &curbuf->b_p_ul)
8720 {
8721 /* use the old value, otherwise u_sync() may not work properly */
8722 curbuf->b_p_ul = old_value;
8723 u_sync(TRUE);
8724 curbuf->b_p_ul = value;
8725 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008727#ifdef FEAT_LINEBREAK
8728 /* 'numberwidth' must be positive */
8729 else if (pp == &curwin->w_p_nuw)
8730 {
8731 if (curwin->w_p_nuw < 1)
8732 {
8733 errmsg = e_positive;
8734 curwin->w_p_nuw = 1;
8735 }
8736 if (curwin->w_p_nuw > 10)
8737 {
8738 errmsg = e_invarg;
8739 curwin->w_p_nuw = 10;
8740 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008741 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008742 }
8743#endif
8744
Bram Moolenaar1a384422010-07-14 19:53:30 +02008745 else if (pp == &curbuf->b_p_tw)
8746 {
8747 if (curbuf->b_p_tw < 0)
8748 {
8749 errmsg = e_positive;
8750 curbuf->b_p_tw = 0;
8751 }
8752#ifdef FEAT_SYN_HL
8753# ifdef FEAT_WINDOWS
8754 {
8755 win_T *wp;
8756 tabpage_T *tp;
8757
8758 FOR_ALL_TAB_WINDOWS(tp, wp)
8759 check_colorcolumn(wp);
8760 }
8761# else
8762 check_colorcolumn(curwin);
8763# endif
8764#endif
8765 }
8766
Bram Moolenaar071d4272004-06-13 20:20:40 +00008767 /*
8768 * Check the bounds for numeric options here
8769 */
8770 if (Rows < min_rows() && full_screen)
8771 {
8772 if (errbuf != NULL)
8773 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008774 vim_snprintf((char *)errbuf, errbuflen,
8775 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776 errmsg = errbuf;
8777 }
8778 Rows = min_rows();
8779 }
8780 if (Columns < MIN_COLUMNS && full_screen)
8781 {
8782 if (errbuf != NULL)
8783 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008784 vim_snprintf((char *)errbuf, errbuflen,
8785 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008786 errmsg = errbuf;
8787 }
8788 Columns = MIN_COLUMNS;
8789 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008790 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008791
8792#ifdef DJGPP
8793 /* avoid a crash by checking for a too large value of 'columns' */
8794 if (old_Columns != Columns && full_screen && term_console)
8795 mch_check_columns();
8796#endif
8797
8798 /*
8799 * If the screen (shell) height has been changed, assume it is the
8800 * physical screenheight.
8801 */
8802 if (old_Rows != Rows || old_Columns != Columns)
8803 {
8804 /* Changing the screen size is not allowed while updating the screen. */
8805 if (updating_screen)
8806 *pp = old_value;
8807 else if (full_screen
8808#ifdef FEAT_GUI
8809 && !gui.starting
8810#endif
8811 )
8812 set_shellsize((int)Columns, (int)Rows, TRUE);
8813 else
8814 {
8815 /* Postpone the resizing; check the size and cmdline position for
8816 * messages. */
8817 check_shellsize();
8818 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8819 cmdline_row = Rows - p_ch;
8820 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008821 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008822 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 }
8824
Bram Moolenaar071d4272004-06-13 20:20:40 +00008825 if (curbuf->b_p_ts <= 0)
8826 {
8827 errmsg = e_positive;
8828 curbuf->b_p_ts = 8;
8829 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008830 if (p_tm < 0)
8831 {
8832 errmsg = e_positive;
8833 p_tm = 0;
8834 }
8835 if ((curwin->w_p_scr <= 0
8836 || (curwin->w_p_scr > curwin->w_height
8837 && curwin->w_height > 0))
8838 && full_screen)
8839 {
8840 if (pp == &(curwin->w_p_scr))
8841 {
8842 if (curwin->w_p_scr != 0)
8843 errmsg = e_scroll;
8844 win_comp_scroll(curwin);
8845 }
8846 /* If 'scroll' became invalid because of a side effect silently adjust
8847 * it. */
8848 else if (curwin->w_p_scr <= 0)
8849 curwin->w_p_scr = 1;
8850 else /* curwin->w_p_scr > curwin->w_height */
8851 curwin->w_p_scr = curwin->w_height;
8852 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008853 if (p_hi < 0)
8854 {
8855 errmsg = e_positive;
8856 p_hi = 0;
8857 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008858 else if (p_hi > 10000)
8859 {
8860 errmsg = e_invarg;
8861 p_hi = 10000;
8862 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008863 if (p_re < 0 || p_re > 2)
8864 {
8865 errmsg = e_invarg;
8866 p_re = 0;
8867 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008868 if (p_report < 0)
8869 {
8870 errmsg = e_positive;
8871 p_report = 1;
8872 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008873 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874 {
8875 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8876 p_sj = Rows / 2;
8877 else
8878 {
8879 errmsg = e_scroll;
8880 p_sj = 1;
8881 }
8882 }
8883 if (p_so < 0 && full_screen)
8884 {
8885 errmsg = e_scroll;
8886 p_so = 0;
8887 }
8888 if (p_siso < 0 && full_screen)
8889 {
8890 errmsg = e_positive;
8891 p_siso = 0;
8892 }
8893#ifdef FEAT_CMDWIN
8894 if (p_cwh < 1)
8895 {
8896 errmsg = e_positive;
8897 p_cwh = 1;
8898 }
8899#endif
8900 if (p_ut < 0)
8901 {
8902 errmsg = e_positive;
8903 p_ut = 2000;
8904 }
8905 if (p_ss < 0)
8906 {
8907 errmsg = e_positive;
8908 p_ss = 0;
8909 }
8910
8911 /* May set global value for local option. */
8912 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8913 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
8914
8915 options[opt_idx].flags |= P_WAS_SET;
8916
Bram Moolenaar53744302015-07-17 17:38:22 +02008917#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8918 if (!starting && errmsg == NULL)
8919 {
8920 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008921 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
8922 vim_snprintf((char *)buf_new, 10, "%ld", value);
8923 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008924 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8925 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8926 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8927 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8928 reset_v_option_vars();
8929 }
8930#endif
8931
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008933 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008934 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008935 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008936 check_redraw(options[opt_idx].flags);
8937
8938 return errmsg;
8939}
8940
8941/*
8942 * Called after an option changed: check if something needs to be redrawn.
8943 */
8944 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008945check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008946{
8947 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008948 int doclear = (flags & P_RCLR) == P_RCLR;
8949 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008950
8951#ifdef FEAT_WINDOWS
8952 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
8953 status_redraw_all();
8954#endif
8955
8956 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
8957 changed_window_setting();
8958 if (flags & P_RBUF)
8959 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01008960 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008961 redraw_all_later(CLEAR);
8962 else if (all)
8963 redraw_all_later(NOT_VALID);
8964}
8965
8966/*
8967 * Find index for option 'arg'.
8968 * Return -1 if not found.
8969 */
8970 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008971findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008972{
8973 int opt_idx;
8974 char *s, *p;
8975 static short quick_tab[27] = {0, 0}; /* quick access table */
8976 int is_term_opt;
8977
8978 /*
8979 * For first call: Initialize the quick-access table.
8980 * It contains the index for the first option that starts with a certain
8981 * letter. There are 26 letters, plus the first "t_" option.
8982 */
8983 if (quick_tab[1] == 0)
8984 {
8985 p = options[0].fullname;
8986 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
8987 {
8988 if (s[0] != p[0])
8989 {
8990 if (s[0] == 't' && s[1] == '_')
8991 quick_tab[26] = opt_idx;
8992 else
8993 quick_tab[CharOrdLow(s[0])] = opt_idx;
8994 }
8995 p = s;
8996 }
8997 }
8998
8999 /*
9000 * Check for name starting with an illegal character.
9001 */
9002#ifdef EBCDIC
9003 if (!islower(arg[0]))
9004#else
9005 if (arg[0] < 'a' || arg[0] > 'z')
9006#endif
9007 return -1;
9008
9009 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9010 if (is_term_opt)
9011 opt_idx = quick_tab[26];
9012 else
9013 opt_idx = quick_tab[CharOrdLow(arg[0])];
9014 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9015 {
9016 if (STRCMP(arg, s) == 0) /* match full name */
9017 break;
9018 }
9019 if (s == NULL && !is_term_opt)
9020 {
9021 opt_idx = quick_tab[CharOrdLow(arg[0])];
9022 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9023 {
9024 s = options[opt_idx].shortname;
9025 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9026 break;
9027 s = NULL;
9028 }
9029 }
9030 if (s == NULL)
9031 opt_idx = -1;
9032 return opt_idx;
9033}
9034
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009035#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009036/*
9037 * Get the value for an option.
9038 *
9039 * Returns:
9040 * Number or Toggle option: 1, *numval gets value.
9041 * String option: 0, *stringval gets allocated string.
9042 * Hidden Number or Toggle option: -1.
9043 * hidden String option: -2.
9044 * unknown option: -3.
9045 */
9046 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009047get_option_value(
9048 char_u *name,
9049 long *numval,
9050 char_u **stringval, /* NULL when only checking existence */
9051 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009052{
9053 int opt_idx;
9054 char_u *varp;
9055
9056 opt_idx = findoption(name);
9057 if (opt_idx < 0) /* unknown option */
9058 return -3;
9059
9060 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9061
9062 if (options[opt_idx].flags & P_STRING)
9063 {
9064 if (varp == NULL) /* hidden option */
9065 return -2;
9066 if (stringval != NULL)
9067 {
9068#ifdef FEAT_CRYPT
9069 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009070 if ((char_u **)varp == &curbuf->b_p_key
9071 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009072 *stringval = vim_strsave((char_u *)"*****");
9073 else
9074#endif
9075 *stringval = vim_strsave(*(char_u **)(varp));
9076 }
9077 return 0;
9078 }
9079
9080 if (varp == NULL) /* hidden option */
9081 return -1;
9082 if (options[opt_idx].flags & P_NUM)
9083 *numval = *(long *)varp;
9084 else
9085 {
9086 /* Special case: 'modified' is b_changed, but we also want to consider
9087 * it set when 'ff' or 'fenc' changed. */
9088 if ((int *)varp == &curbuf->b_changed)
9089 *numval = curbufIsChanged();
9090 else
9091 *numval = *(int *)varp;
9092 }
9093 return 1;
9094}
9095#endif
9096
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009097#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009098/*
9099 * Returns the option attributes and its value. Unlike the above function it
9100 * will return either global value or local value of the option depending on
9101 * what was requested, but it will never return global value if it was
9102 * requested to return local one and vice versa. Neither it will return
9103 * buffer-local value if it was requested to return window-local one.
9104 *
9105 * Pretends that option is absent if it is not present in the requested scope
9106 * (i.e. has no global, window-local or buffer-local value depending on
9107 * opt_type). Uses
9108 *
9109 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009110 * 0 hidden or unknown option, also option that does not have requested
9111 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009112 * see SOPT_* in vim.h for other flags
9113 *
9114 * Possible opt_type values: see SREQ_* in vim.h
9115 */
9116 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009117get_option_value_strict(
9118 char_u *name,
9119 long *numval,
9120 char_u **stringval, /* NULL when only obtaining attributes */
9121 int opt_type,
9122 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009123{
9124 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009125 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009126 struct vimoption *p;
9127 int r = 0;
9128
9129 opt_idx = findoption(name);
9130 if (opt_idx < 0)
9131 return 0;
9132
9133 p = &(options[opt_idx]);
9134
9135 /* Hidden option */
9136 if (p->var == NULL)
9137 return 0;
9138
9139 if (p->flags & P_BOOL)
9140 r |= SOPT_BOOL;
9141 else if (p->flags & P_NUM)
9142 r |= SOPT_NUM;
9143 else if (p->flags & P_STRING)
9144 r |= SOPT_STRING;
9145
9146 if (p->indir == PV_NONE)
9147 {
9148 if (opt_type == SREQ_GLOBAL)
9149 r |= SOPT_GLOBAL;
9150 else
9151 return 0; /* Did not request global-only option */
9152 }
9153 else
9154 {
9155 if (p->indir & PV_BOTH)
9156 r |= SOPT_GLOBAL;
9157 else if (opt_type == SREQ_GLOBAL)
9158 return 0; /* Requested global option */
9159
9160 if (p->indir & PV_WIN)
9161 {
9162 if (opt_type == SREQ_BUF)
9163 return 0; /* Did not request window-local option */
9164 else
9165 r |= SOPT_WIN;
9166 }
9167 else if (p->indir & PV_BUF)
9168 {
9169 if (opt_type == SREQ_WIN)
9170 return 0; /* Did not request buffer-local option */
9171 else
9172 r |= SOPT_BUF;
9173 }
9174 }
9175
9176 if (stringval == NULL)
9177 return r;
9178
9179 if (opt_type == SREQ_GLOBAL)
9180 varp = p->var;
9181 else
9182 {
9183 if (opt_type == SREQ_BUF)
9184 {
9185 /* Special case: 'modified' is b_changed, but we also want to
9186 * consider it set when 'ff' or 'fenc' changed. */
9187 if (p->indir == PV_MOD)
9188 {
9189 *numval = bufIsChanged((buf_T *) from);
9190 varp = NULL;
9191 }
9192#ifdef FEAT_CRYPT
9193 else if (p->indir == PV_KEY)
9194 {
9195 /* never return the value of the crypt key */
9196 *stringval = NULL;
9197 varp = NULL;
9198 }
9199#endif
9200 else
9201 {
9202 aco_save_T aco;
9203 aucmd_prepbuf(&aco, (buf_T *) from);
9204 varp = get_varp(p);
9205 aucmd_restbuf(&aco);
9206 }
9207 }
9208 else if (opt_type == SREQ_WIN)
9209 {
9210 win_T *save_curwin;
9211 save_curwin = curwin;
9212 curwin = (win_T *) from;
9213 curbuf = curwin->w_buffer;
9214 varp = get_varp(p);
9215 curwin = save_curwin;
9216 curbuf = curwin->w_buffer;
9217 }
9218 if (varp == p->var)
9219 return (r | SOPT_UNSET);
9220 }
9221
9222 if (varp != NULL)
9223 {
9224 if (p->flags & P_STRING)
9225 *stringval = vim_strsave(*(char_u **)(varp));
9226 else if (p->flags & P_NUM)
9227 *numval = *(long *) varp;
9228 else
9229 *numval = *(int *)varp;
9230 }
9231
9232 return r;
9233}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009234
9235/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009236 * Iterate over options. First argument is a pointer to a pointer to a
9237 * structure inside options[] array, second is option type like in the above
9238 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009239 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009240 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009241 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009242 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009243 * first argument to NULL.
9244 *
9245 * Returns full option name for current option on each call.
9246 */
9247 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009248option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009249{
9250 struct vimoption *ret = NULL;
9251 do
9252 {
9253 if (*option == NULL)
9254 *option = (void *) options;
9255 else if (((struct vimoption *) (*option))->fullname == NULL)
9256 {
9257 *option = NULL;
9258 return NULL;
9259 }
9260 else
9261 *option = (void *) (((struct vimoption *) (*option)) + 1);
9262
9263 ret = ((struct vimoption *) (*option));
9264
9265 /* Hidden option */
9266 if (ret->var == NULL)
9267 {
9268 ret = NULL;
9269 continue;
9270 }
9271
9272 switch (opt_type)
9273 {
9274 case SREQ_GLOBAL:
9275 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9276 ret = NULL;
9277 break;
9278 case SREQ_BUF:
9279 if (!(ret->indir & PV_BUF))
9280 ret = NULL;
9281 break;
9282 case SREQ_WIN:
9283 if (!(ret->indir & PV_WIN))
9284 ret = NULL;
9285 break;
9286 default:
9287 EMSG2(_(e_intern2), "option_iter_next()");
9288 return NULL;
9289 }
9290 }
9291 while (ret == NULL);
9292
9293 return (char_u *)ret->fullname;
9294}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009295#endif
9296
Bram Moolenaar071d4272004-06-13 20:20:40 +00009297/*
9298 * Set the value of option "name".
9299 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009300 *
9301 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009302 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009303 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009304set_option_value(
9305 char_u *name,
9306 long number,
9307 char_u *string,
9308 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009309{
9310 int opt_idx;
9311 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009312 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009313
9314 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009315 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009316 EMSG2(_("E355: Unknown option: %s"), name);
9317 else
9318 {
9319 flags = options[opt_idx].flags;
9320#ifdef HAVE_SANDBOX
9321 /* Disallow changing some options in the sandbox */
9322 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009323 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009324 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009325 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009326 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009328 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009329 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009330 else
9331 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009332 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009333 if (varp != NULL) /* hidden option is not changed */
9334 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009335 if (number == 0 && string != NULL)
9336 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009337 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009338
9339 /* Either we are given a string or we are setting option
9340 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009341 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009342 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009343 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009344 {
9345 /* There's another character after zeros or the string
9346 * is empty. In both cases, we are trying to set a
9347 * num option using a string. */
9348 EMSG3(_("E521: Number required: &%s = '%s'"),
9349 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009350 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009351
9352 }
9353 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009354 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009355 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009356 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009357 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009358 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009359 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009360 }
9361 }
9362 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009363 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364}
9365
9366/*
9367 * Get the terminal code for a terminal option.
9368 * Returns NULL when not found.
9369 */
9370 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009371get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009372{
9373 int opt_idx;
9374 char_u *varp;
9375
9376 if (tname[0] != 't' || tname[1] != '_' ||
9377 tname[2] == NUL || tname[3] == NUL)
9378 return NULL;
9379 if ((opt_idx = findoption(tname)) >= 0)
9380 {
9381 varp = get_varp(&(options[opt_idx]));
9382 if (varp != NULL)
9383 varp = *(char_u **)(varp);
9384 return varp;
9385 }
9386 return find_termcode(tname + 2);
9387}
9388
9389 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009390get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009391{
9392 int i;
9393
9394 i = findoption((char_u *)"hl");
9395 if (i >= 0)
9396 return options[i].def_val[VI_DEFAULT];
9397 return (char_u *)NULL;
9398}
9399
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009400#if defined(FEAT_MBYTE) || defined(PROTO)
9401 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009402get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009403{
9404 int i;
9405
9406 i = findoption((char_u *)"enc");
9407 if (i >= 0)
9408 return options[i].def_val[VI_DEFAULT];
9409 return (char_u *)NULL;
9410}
9411#endif
9412
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413/*
9414 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9415 */
9416 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009417find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418{
9419 int key;
9420 int modifiers;
9421
9422 /*
9423 * Don't use get_special_key_code() for t_xx, we don't want it to call
9424 * add_termcap_entry().
9425 */
9426 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9427 key = TERMCAP2KEY(arg[2], arg[3]);
9428 else
9429 {
9430 --arg; /* put arg at the '<' */
9431 modifiers = 0;
Bram Moolenaar2a8ced02008-12-24 11:54:31 +00009432 key = find_special_key(&arg, &modifiers, TRUE, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 if (modifiers) /* can't handle modifiers here */
9434 key = 0;
9435 }
9436 return key;
9437}
9438
9439/*
9440 * if 'all' == 0: show changed options
9441 * if 'all' == 1: show all normal options
9442 * if 'all' == 2: show all terminal options
9443 */
9444 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009445showoptions(
9446 int all,
9447 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009448{
9449 struct vimoption *p;
9450 int col;
9451 int isterm;
9452 char_u *varp;
9453 struct vimoption **items;
9454 int item_count;
9455 int run;
9456 int row, rows;
9457 int cols;
9458 int i;
9459 int len;
9460
9461#define INC 20
9462#define GAP 3
9463
9464 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9465 PARAM_COUNT));
9466 if (items == NULL)
9467 return;
9468
9469 /* Highlight title */
9470 if (all == 2)
9471 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9472 else if (opt_flags & OPT_GLOBAL)
9473 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9474 else if (opt_flags & OPT_LOCAL)
9475 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9476 else
9477 MSG_PUTS_TITLE(_("\n--- Options ---"));
9478
9479 /*
9480 * do the loop two times:
9481 * 1. display the short items
9482 * 2. display the long items (only strings and numbers)
9483 */
9484 for (run = 1; run <= 2 && !got_int; ++run)
9485 {
9486 /*
9487 * collect the items in items[]
9488 */
9489 item_count = 0;
9490 for (p = &options[0]; p->fullname != NULL; p++)
9491 {
9492 varp = NULL;
9493 isterm = istermoption(p);
9494 if (opt_flags != 0)
9495 {
9496 if (p->indir != PV_NONE && !isterm)
9497 varp = get_varp_scope(p, opt_flags);
9498 }
9499 else
9500 varp = get_varp(p);
9501 if (varp != NULL
9502 && ((all == 2 && isterm)
9503 || (all == 1 && !isterm)
9504 || (all == 0 && !optval_default(p, varp))))
9505 {
9506 if (p->flags & P_BOOL)
9507 len = 1; /* a toggle option fits always */
9508 else
9509 {
9510 option_value2string(p, opt_flags);
9511 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9512 }
9513 if ((len <= INC - GAP && run == 1) ||
9514 (len > INC - GAP && run == 2))
9515 items[item_count++] = p;
9516 }
9517 }
9518
9519 /*
9520 * display the items
9521 */
9522 if (run == 1)
9523 {
9524 cols = (Columns + GAP - 3) / INC;
9525 if (cols == 0)
9526 cols = 1;
9527 rows = (item_count + cols - 1) / cols;
9528 }
9529 else /* run == 2 */
9530 rows = item_count;
9531 for (row = 0; row < rows && !got_int; ++row)
9532 {
9533 msg_putchar('\n'); /* go to next line */
9534 if (got_int) /* 'q' typed in more */
9535 break;
9536 col = 0;
9537 for (i = row; i < item_count; i += rows)
9538 {
9539 msg_col = col; /* make columns */
9540 showoneopt(items[i], opt_flags);
9541 col += INC;
9542 }
9543 out_flush();
9544 ui_breakcheck();
9545 }
9546 }
9547 vim_free(items);
9548}
9549
9550/*
9551 * Return TRUE if option "p" has its default value.
9552 */
9553 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009554optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009555{
9556 int dvi;
9557
9558 if (varp == NULL)
9559 return TRUE; /* hidden option is always at default */
9560 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9561 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009562 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009563 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009564 /* the cast to long is required for Manx C, long_i is
9565 * needed for MSVC */
9566 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009567 /* P_STRING */
9568 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9569}
9570
9571/*
9572 * showoneopt: show the value of one option
9573 * must not be called with a hidden option!
9574 */
9575 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009576showoneopt(
9577 struct vimoption *p,
9578 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009579{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009580 char_u *varp;
9581 int save_silent = silent_mode;
9582
9583 silent_mode = FALSE;
9584 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585
9586 varp = get_varp_scope(p, opt_flags);
9587
9588 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9589 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9590 ? !curbufIsChanged() : !*(int *)varp))
9591 MSG_PUTS("no");
9592 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9593 MSG_PUTS("--");
9594 else
9595 MSG_PUTS(" ");
9596 MSG_PUTS(p->fullname);
9597 if (!(p->flags & P_BOOL))
9598 {
9599 msg_putchar('=');
9600 /* put value string in NameBuff */
9601 option_value2string(p, opt_flags);
9602 msg_outtrans(NameBuff);
9603 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009604
9605 silent_mode = save_silent;
9606 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009607}
9608
9609/*
9610 * Write modified options as ":set" commands to a file.
9611 *
9612 * There are three values for "opt_flags":
9613 * OPT_GLOBAL: Write global option values and fresh values of
9614 * buffer-local options (used for start of a session
9615 * file).
9616 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9617 * curwin (used for a vimrc file).
9618 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9619 * and local values for window-local options of
9620 * curwin. Local values are also written when at the
9621 * default value, because a modeline or autocommand
9622 * may have set them when doing ":edit file" and the
9623 * user has set them back at the default or fresh
9624 * value.
9625 * When "local_only" is TRUE, don't write fresh
9626 * values, only local values (for ":mkview").
9627 * (fresh value = value used for a new buffer or window for a local option).
9628 *
9629 * Return FAIL on error, OK otherwise.
9630 */
9631 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009632makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009633{
9634 struct vimoption *p;
9635 char_u *varp; /* currently used value */
9636 char_u *varp_fresh; /* local value */
9637 char_u *varp_local = NULL; /* fresh value */
9638 char *cmd;
9639 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009640 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009641
9642 /*
9643 * The options that don't have a default (terminal name, columns, lines)
9644 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009645 * Do the loop over "options[]" twice: once for options with the
9646 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009647 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009648 for (pri = 1; pri >= 0; --pri)
9649 {
9650 for (p = &options[0]; !istermoption(p); p++)
9651 if (!(p->flags & P_NO_MKRC)
9652 && !istermoption(p)
9653 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654 {
9655 /* skip global option when only doing locals */
9656 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9657 continue;
9658
9659 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9660 * file, they are always buffer-specific. */
9661 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9662 continue;
9663
9664 /* Global values are only written when not at the default value. */
9665 varp = get_varp_scope(p, opt_flags);
9666 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9667 continue;
9668
9669 round = 2;
9670 if (p->indir != PV_NONE)
9671 {
9672 if (p->var == VAR_WIN)
9673 {
9674 /* skip window-local option when only doing globals */
9675 if (!(opt_flags & OPT_LOCAL))
9676 continue;
9677 /* When fresh value of window-local option is not at the
9678 * default, need to write it too. */
9679 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9680 {
9681 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9682 if (!optval_default(p, varp_fresh))
9683 {
9684 round = 1;
9685 varp_local = varp;
9686 varp = varp_fresh;
9687 }
9688 }
9689 }
9690 }
9691
9692 /* Round 1: fresh value for window-local options.
9693 * Round 2: other values */
9694 for ( ; round <= 2; varp = varp_local, ++round)
9695 {
9696 if (round == 1 || (opt_flags & OPT_GLOBAL))
9697 cmd = "set";
9698 else
9699 cmd = "setlocal";
9700
9701 if (p->flags & P_BOOL)
9702 {
9703 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9704 return FAIL;
9705 }
9706 else if (p->flags & P_NUM)
9707 {
9708 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9709 return FAIL;
9710 }
9711 else /* P_STRING */
9712 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009713#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9714 int do_endif = FALSE;
9715
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716 /* Don't set 'syntax' and 'filetype' again if the value is
9717 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009718 if (
9719# if defined(FEAT_SYN_HL)
9720 p->indir == PV_SYN
9721# if defined(FEAT_AUTOCMD)
9722 ||
9723# endif
9724# endif
9725# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009726 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009727# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009728 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009729 {
9730 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9731 *(char_u **)(varp)) < 0
9732 || put_eol(fd) < 0)
9733 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009734 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009735 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009737 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9738 (p->flags & P_EXPAND) != 0) == FAIL)
9739 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009740#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9741 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742 {
9743 if (put_line(fd, "endif") == FAIL)
9744 return FAIL;
9745 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009746#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009747 }
9748 }
9749 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009750 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009751 return OK;
9752}
9753
9754#if defined(FEAT_FOLDING) || defined(PROTO)
9755/*
9756 * Generate set commands for the local fold options only. Used when
9757 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9758 */
9759 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009760makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009761{
9762 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9763# ifdef FEAT_EVAL
9764 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9765 == FAIL
9766# endif
9767 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9768 == FAIL
9769 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9770 == FAIL
9771 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9772 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9773 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9774 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9775 )
9776 return FAIL;
9777
9778 return OK;
9779}
9780#endif
9781
9782 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009783put_setstring(
9784 FILE *fd,
9785 char *cmd,
9786 char *name,
9787 char_u **valuep,
9788 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009789{
9790 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009791 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009792
9793 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9794 return FAIL;
9795 if (*valuep != NULL)
9796 {
9797 /* Output 'pastetoggle' as key names. For other
9798 * options some characters have to be escaped with
9799 * CTRL-V or backslash */
9800 if (valuep == &p_pt)
9801 {
9802 s = *valuep;
9803 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009804 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009805 return FAIL;
9806 }
9807 else if (expand)
9808 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009809 buf = alloc(MAXPATHL);
9810 if (buf == NULL)
9811 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009812 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9813 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009814 {
9815 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009816 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009817 }
9818 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009819 }
9820 else if (put_escstr(fd, *valuep, 2) == FAIL)
9821 return FAIL;
9822 }
9823 if (put_eol(fd) < 0)
9824 return FAIL;
9825 return OK;
9826}
9827
9828 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009829put_setnum(
9830 FILE *fd,
9831 char *cmd,
9832 char *name,
9833 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009834{
9835 long wc;
9836
9837 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9838 return FAIL;
9839 if (wc_use_keyname((char_u *)valuep, &wc))
9840 {
9841 /* print 'wildchar' and 'wildcharm' as a key name */
9842 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9843 return FAIL;
9844 }
9845 else if (fprintf(fd, "%ld", *valuep) < 0)
9846 return FAIL;
9847 if (put_eol(fd) < 0)
9848 return FAIL;
9849 return OK;
9850}
9851
9852 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009853put_setbool(
9854 FILE *fd,
9855 char *cmd,
9856 char *name,
9857 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009858{
Bram Moolenaar893de922007-10-02 18:40:57 +00009859 if (value < 0) /* global/local option using global value */
9860 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009861 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9862 || put_eol(fd) < 0)
9863 return FAIL;
9864 return OK;
9865}
9866
9867/*
9868 * Clear all the terminal options.
9869 * If the option has been allocated, free the memory.
9870 * Terminal options are never hidden or indirect.
9871 */
9872 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009873clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009874{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009875 /*
9876 * Reset a few things before clearing the old options. This may cause
9877 * outputting a few things that the terminal doesn't understand, but the
9878 * screen will be cleared later, so this is OK.
9879 */
9880#ifdef FEAT_MOUSE_TTY
9881 mch_setmouse(FALSE); /* switch mouse off */
9882#endif
9883#ifdef FEAT_TITLE
9884 mch_restore_title(3); /* restore window titles */
9885#endif
9886#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9887 /* When starting the GUI close the display opened for the clipboard.
9888 * After restoring the title, because that will need the display. */
9889 if (gui.starting)
9890 clear_xterm_clip();
9891#endif
9892#ifdef WIN3264
9893 /*
9894 * Check if this is allowed now.
9895 */
9896 if (can_end_termcap_mode(FALSE) == TRUE)
9897#endif
9898 stoptermcap(); /* stop termcap mode */
9899
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009900 free_termoptions();
9901}
9902
9903 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009904free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009905{
9906 struct vimoption *p;
9907
Bram Moolenaar071d4272004-06-13 20:20:40 +00009908 for (p = &options[0]; p->fullname != NULL; p++)
9909 if (istermoption(p))
9910 {
9911 if (p->flags & P_ALLOCED)
9912 free_string_option(*(char_u **)(p->var));
9913 if (p->flags & P_DEF_ALLOCED)
9914 free_string_option(p->def_val[VI_DEFAULT]);
9915 *(char_u **)(p->var) = empty_option;
9916 p->def_val[VI_DEFAULT] = empty_option;
9917 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
9918 }
9919 clear_termcodes();
9920}
9921
9922/*
Bram Moolenaar363cb672009-07-22 12:28:17 +00009923 * Free the string for one term option, if it was allocated.
9924 * Set the string to empty_option and clear allocated flag.
9925 * "var" points to the option value.
9926 */
9927 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009928free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +00009929{
9930 struct vimoption *p;
9931
9932 for (p = &options[0]; p->fullname != NULL; p++)
9933 if (p->var == var)
9934 {
9935 if (p->flags & P_ALLOCED)
9936 free_string_option(*(char_u **)(p->var));
9937 *(char_u **)(p->var) = empty_option;
9938 p->flags &= ~P_ALLOCED;
9939 break;
9940 }
9941}
9942
9943/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00009944 * Set the terminal option defaults to the current value.
9945 * Used after setting the terminal name.
9946 */
9947 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009948set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009949{
9950 struct vimoption *p;
9951
9952 for (p = &options[0]; p->fullname != NULL; p++)
9953 {
9954 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
9955 {
9956 if (p->flags & P_DEF_ALLOCED)
9957 {
9958 free_string_option(p->def_val[VI_DEFAULT]);
9959 p->flags &= ~P_DEF_ALLOCED;
9960 }
9961 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
9962 if (p->flags & P_ALLOCED)
9963 {
9964 p->flags |= P_DEF_ALLOCED;
9965 p->flags &= ~P_ALLOCED; /* don't free the value now */
9966 }
9967 }
9968 }
9969}
9970
9971/*
9972 * return TRUE if 'p' starts with 't_'
9973 */
9974 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009975istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009976{
9977 return (p->fullname[0] == 't' && p->fullname[1] == '_');
9978}
9979
9980/*
9981 * Compute columns for ruler and shown command. 'sc_col' is also used to
9982 * decide what the maximum length of a message on the status line can be.
9983 * If there is a status line for the last window, 'sc_col' is independent
9984 * of 'ru_col'.
9985 */
9986
9987#define COL_RULER 17 /* columns needed by standard ruler */
9988
9989 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009990comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009991{
9992#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
9993 int last_has_status = (p_ls == 2 || (p_ls == 1 && firstwin != lastwin));
9994
9995 sc_col = 0;
9996 ru_col = 0;
9997 if (p_ru)
9998 {
9999#ifdef FEAT_STL_OPT
10000 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10001#else
10002 ru_col = COL_RULER + 1;
10003#endif
10004 /* no last status line, adjust sc_col */
10005 if (!last_has_status)
10006 sc_col = ru_col;
10007 }
10008 if (p_sc)
10009 {
10010 sc_col += SHOWCMD_COLS;
10011 if (!p_ru || last_has_status) /* no need for separating space */
10012 ++sc_col;
10013 }
10014 sc_col = Columns - sc_col;
10015 ru_col = Columns - ru_col;
10016 if (sc_col <= 0) /* screen too narrow, will become a mess */
10017 sc_col = 1;
10018 if (ru_col <= 0)
10019 ru_col = 1;
10020#else
10021 sc_col = Columns;
10022 ru_col = Columns;
10023#endif
10024}
10025
10026/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010027 * Unset local option value, similar to ":set opt<".
10028 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010029 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010030unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010031{
10032 struct vimoption *p;
10033 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010034 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010035
10036 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010037 if (opt_idx < 0)
10038 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010039 p = &(options[opt_idx]);
10040
10041 switch ((int)p->indir)
10042 {
10043 /* global option with local value: use local value if it's been set */
10044 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010045 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010046 break;
10047 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010048 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010049 break;
10050 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010051 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010052 break;
10053 case PV_AR:
10054 buf->b_p_ar = -1;
10055 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010056 case PV_BKC:
10057 clear_string_option(&buf->b_p_bkc);
10058 buf->b_bkc_flags = 0;
10059 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010060 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010061 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010062 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010063 case PV_TC:
10064 clear_string_option(&buf->b_p_tc);
10065 buf->b_tc_flags = 0;
10066 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010067#ifdef FEAT_FIND_ID
10068 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010069 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010070 break;
10071 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010072 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010073 break;
10074#endif
10075#ifdef FEAT_INS_EXPAND
10076 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010077 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010078 break;
10079 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010080 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010081 break;
10082#endif
10083#ifdef FEAT_QUICKFIX
10084 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010085 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010086 break;
10087 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010088 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010089 break;
10090 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010091 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010092 break;
10093#endif
10094#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10095 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010096 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010097 break;
10098#endif
10099#if defined(FEAT_CRYPT)
10100 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010101 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010102 break;
10103#endif
10104#ifdef FEAT_STL_OPT
10105 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010106 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010107 break;
10108#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010109 case PV_UL:
10110 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10111 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010112#ifdef FEAT_LISP
10113 case PV_LW:
10114 clear_string_option(&buf->b_p_lw);
10115 break;
10116#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010117 }
10118}
10119
10120/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010121 * Get pointer to option variable, depending on local or global scope.
10122 */
10123 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010124get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125{
10126 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10127 {
10128 if (p->var == VAR_WIN)
10129 return (char_u *)GLOBAL_WO(get_varp(p));
10130 return p->var;
10131 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010132 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133 {
10134 switch ((int)p->indir)
10135 {
10136#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010137 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10138 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10139 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010140#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010141 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10142 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10143 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010144 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010145 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010146 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010148 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10149 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010150#endif
10151#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010152 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10153 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010155#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10156 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10157#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010158#if defined(FEAT_CRYPT)
10159 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10160#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010161#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010162 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010163#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010164 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010165#ifdef FEAT_LISP
10166 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10167#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010168 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169 }
10170 return NULL; /* "cannot happen" */
10171 }
10172 return get_varp(p);
10173}
10174
10175/*
10176 * Get pointer to option variable.
10177 */
10178 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010179get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180{
10181 /* hidden option, always return NULL */
10182 if (p->var == NULL)
10183 return NULL;
10184
10185 switch ((int)p->indir)
10186 {
10187 case PV_NONE: return p->var;
10188
10189 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010190 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010192 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010194 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010195 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010196 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010197 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010198 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010200 case PV_TC: return *curbuf->b_p_tc != NUL
10201 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010202 case PV_BKC: return *curbuf->b_p_bkc != NUL
10203 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010204#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010205 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010206 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010207 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010208 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10209#endif
10210#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010211 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010212 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010213 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010214 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10215#endif
10216#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010217 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010218 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010219 case PV_GP: return *curbuf->b_p_gp != NUL
10220 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10221 case PV_MP: return *curbuf->b_p_mp != NUL
10222 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010223#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010224#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10225 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10226 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10227#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010228#if defined(FEAT_CRYPT)
10229 case PV_CM: return *curbuf->b_p_cm != NUL
10230 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10231#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010232#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010233 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010234 ? (char_u *)&(curwin->w_p_stl) : p->var;
10235#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010236 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10237 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010238#ifdef FEAT_LISP
10239 case PV_LW: return *curbuf->b_p_lw != NUL
10240 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10241#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010242
10243#ifdef FEAT_ARABIC
10244 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10245#endif
10246 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010247#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010248 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10249#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010250#ifdef FEAT_SYN_HL
10251 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10252 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010253 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010254#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255#ifdef FEAT_DIFF
10256 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10257#endif
10258#ifdef FEAT_FOLDING
10259 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10260 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10261 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10262 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10263 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10264 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10265 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10266# ifdef FEAT_EVAL
10267 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10268 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10269# endif
10270 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10271#endif
10272 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010273 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010274#ifdef FEAT_LINEBREAK
10275 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10276#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010277#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010278 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
10279#endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010280#ifdef FEAT_VERTSPLIT
10281 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010283#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10284 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10285#endif
10286#ifdef FEAT_RIGHTLEFT
10287 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10288 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10289#endif
10290 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10291 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10292#ifdef FEAT_LINEBREAK
10293 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010294 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10295 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010296#endif
10297#ifdef FEAT_SCROLLBIND
10298 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10299#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010300#ifdef FEAT_CURSORBIND
10301 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10302#endif
10303#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010304 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10305 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307
10308 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10309 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10310#ifdef FEAT_MBYTE
10311 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10312#endif
10313#if defined(FEAT_QUICKFIX)
10314 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10315 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10316#endif
10317 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10318 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10319#ifdef FEAT_CINDENT
10320 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10321 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10322 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10323#endif
10324#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10325 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10326#endif
10327#ifdef FEAT_COMMENTS
10328 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10329#endif
10330#ifdef FEAT_FOLDING
10331 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10332#endif
10333#ifdef FEAT_INS_EXPAND
10334 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10335#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010336#ifdef FEAT_COMPL_FUNC
10337 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010338 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010339#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010340 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010341 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10343#ifdef FEAT_MBYTE
10344 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10345#endif
10346 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10347#ifdef FEAT_AUTOCMD
10348 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10349#endif
10350 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010351 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10353 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10354 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10355 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10356#ifdef FEAT_FIND_ID
10357# ifdef FEAT_EVAL
10358 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10359# endif
10360#endif
10361#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10362 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10363 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10364#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010365#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010366 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10367#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010368#ifdef FEAT_CRYPT
10369 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10370#endif
10371#ifdef FEAT_LISP
10372 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10373#endif
10374 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10375 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10376 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10377 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10378 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010379 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010380#ifdef FEAT_TEXTOBJ
10381 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10382#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10384#ifdef FEAT_SMARTINDENT
10385 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10386#endif
10387#ifndef SHORT_FNAME
10388 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
10389#endif
10390 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10391#ifdef FEAT_SEARCHPATH
10392 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10393#endif
10394 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10395#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010396 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010397 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10398#endif
10399#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010400 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10401 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10402 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403#endif
10404 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10405 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10406 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10407 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010408#ifdef FEAT_PERSISTENT_UNDO
10409 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10410#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010411 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10412#ifdef FEAT_KEYMAP
10413 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10414#endif
10415 default: EMSG(_("E356: get_varp ERROR"));
10416 }
10417 /* always return a valid pointer to avoid a crash! */
10418 return (char_u *)&(curbuf->b_p_wm);
10419}
10420
10421/*
10422 * Get the value of 'equalprg', either the buffer-local one or the global one.
10423 */
10424 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010425get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426{
10427 if (*curbuf->b_p_ep == NUL)
10428 return p_ep;
10429 return curbuf->b_p_ep;
10430}
10431
10432#if defined(FEAT_WINDOWS) || defined(PROTO)
10433/*
10434 * Copy options from one window to another.
10435 * Used when splitting a window.
10436 */
10437 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010438win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439{
10440 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10441 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10442# ifdef FEAT_RIGHTLEFT
10443# ifdef FEAT_FKMAP
10444 /* Is this right? */
10445 wp_to->w_farsi = wp_from->w_farsi;
10446# endif
10447# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010448#if defined(FEAT_LINEBREAK)
10449 briopt_check(wp_to);
10450#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010451}
10452#endif
10453
10454/*
10455 * Copy the options from one winopt_T to another.
10456 * Doesn't free the old option values in "to", use clear_winopt() for that.
10457 * The 'scroll' option is not copied, because it depends on the window height.
10458 * The 'previewwindow' option is reset, there can be only one preview window.
10459 */
10460 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010461copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010462{
10463#ifdef FEAT_ARABIC
10464 to->wo_arab = from->wo_arab;
10465#endif
10466 to->wo_list = from->wo_list;
10467 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010468 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010469#ifdef FEAT_LINEBREAK
10470 to->wo_nuw = from->wo_nuw;
10471#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010472#ifdef FEAT_RIGHTLEFT
10473 to->wo_rl = from->wo_rl;
10474 to->wo_rlc = vim_strsave(from->wo_rlc);
10475#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010476#ifdef FEAT_STL_OPT
10477 to->wo_stl = vim_strsave(from->wo_stl);
10478#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010479 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010480#ifdef FEAT_DIFF
10481 to->wo_wrap_save = from->wo_wrap_save;
10482#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010483#ifdef FEAT_LINEBREAK
10484 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010485 to->wo_bri = from->wo_bri;
10486 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487#endif
10488#ifdef FEAT_SCROLLBIND
10489 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010490 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010491#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010492#ifdef FEAT_CURSORBIND
10493 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010494 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010495#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010496#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010497 to->wo_spell = from->wo_spell;
10498#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010499#ifdef FEAT_SYN_HL
10500 to->wo_cuc = from->wo_cuc;
10501 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010502 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010503#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504#ifdef FEAT_DIFF
10505 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010506 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010508#ifdef FEAT_CONCEAL
10509 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010510 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010511#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512#ifdef FEAT_FOLDING
10513 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010514 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010516 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010517 to->wo_fdi = vim_strsave(from->wo_fdi);
10518 to->wo_fml = from->wo_fml;
10519 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010520 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010522 to->wo_fdm_save = from->wo_diff_saved
10523 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524 to->wo_fdn = from->wo_fdn;
10525# ifdef FEAT_EVAL
10526 to->wo_fde = vim_strsave(from->wo_fde);
10527 to->wo_fdt = vim_strsave(from->wo_fdt);
10528# endif
10529 to->wo_fmr = vim_strsave(from->wo_fmr);
10530#endif
10531 check_winopt(to); /* don't want NULL pointers */
10532}
10533
10534/*
10535 * Check string options in a window for a NULL value.
10536 */
10537 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010538check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539{
10540 check_winopt(&win->w_onebuf_opt);
10541 check_winopt(&win->w_allbuf_opt);
10542}
10543
10544/*
10545 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10546 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010547 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010548check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549{
10550#ifdef FEAT_FOLDING
10551 check_string_option(&wop->wo_fdi);
10552 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010553 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554# ifdef FEAT_EVAL
10555 check_string_option(&wop->wo_fde);
10556 check_string_option(&wop->wo_fdt);
10557# endif
10558 check_string_option(&wop->wo_fmr);
10559#endif
10560#ifdef FEAT_RIGHTLEFT
10561 check_string_option(&wop->wo_rlc);
10562#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010563#ifdef FEAT_STL_OPT
10564 check_string_option(&wop->wo_stl);
10565#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010566#ifdef FEAT_SYN_HL
10567 check_string_option(&wop->wo_cc);
10568#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010569#ifdef FEAT_CONCEAL
10570 check_string_option(&wop->wo_cocu);
10571#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010572#ifdef FEAT_LINEBREAK
10573 check_string_option(&wop->wo_briopt);
10574#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575}
10576
10577/*
10578 * Free the allocated memory inside a winopt_T.
10579 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010581clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582{
10583#ifdef FEAT_FOLDING
10584 clear_string_option(&wop->wo_fdi);
10585 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010586 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587# ifdef FEAT_EVAL
10588 clear_string_option(&wop->wo_fde);
10589 clear_string_option(&wop->wo_fdt);
10590# endif
10591 clear_string_option(&wop->wo_fmr);
10592#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010593#ifdef FEAT_LINEBREAK
10594 clear_string_option(&wop->wo_briopt);
10595#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596#ifdef FEAT_RIGHTLEFT
10597 clear_string_option(&wop->wo_rlc);
10598#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010599#ifdef FEAT_STL_OPT
10600 clear_string_option(&wop->wo_stl);
10601#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010602#ifdef FEAT_SYN_HL
10603 clear_string_option(&wop->wo_cc);
10604#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010605#ifdef FEAT_CONCEAL
10606 clear_string_option(&wop->wo_cocu);
10607#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608}
10609
10610/*
10611 * Copy global option values to local options for one buffer.
10612 * Used when creating a new buffer and sometimes when entering a buffer.
10613 * flags:
10614 * BCO_ENTER We will enter the buf buffer.
10615 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10616 * appropriate.
10617 * BCO_NOHELP Don't copy the values to a help buffer.
10618 */
10619 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010620buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621{
10622 int should_copy = TRUE;
10623 char_u *save_p_isk = NULL; /* init for GCC */
10624 int dont_do_help;
10625 int did_isk = FALSE;
10626
10627 /*
Bram Moolenaar1a384422010-07-14 19:53:30 +020010628 * Don't do anything if the buffer is invalid.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629 */
10630 if (buf == NULL || !buf_valid(buf))
10631 return;
10632
10633 /*
10634 * Skip this when the option defaults have not been set yet. Happens when
10635 * main() allocates the first buffer.
10636 */
10637 if (p_cpo != NULL)
10638 {
10639 /*
10640 * Always copy when entering and 'cpo' contains 'S'.
10641 * Don't copy when already initialized.
10642 * Don't copy when 'cpo' contains 's' and not entering.
10643 * 'S' BCO_ENTER initialized 's' should_copy
10644 * yes yes X X TRUE
10645 * yes no yes X FALSE
10646 * no X yes X FALSE
10647 * X no no yes FALSE
10648 * X no no no TRUE
10649 * no yes no X TRUE
10650 */
10651 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10652 && (buf->b_p_initialized
10653 || (!(flags & BCO_ENTER)
10654 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10655 should_copy = FALSE;
10656
10657 if (should_copy || (flags & BCO_ALWAYS))
10658 {
10659 /* Don't copy the options specific to a help buffer when
10660 * BCO_NOHELP is given or the options were initialized already
10661 * (jumping back to a help file with CTRL-T or CTRL-O) */
10662 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10663 || buf->b_p_initialized;
10664 if (dont_do_help) /* don't free b_p_isk */
10665 {
10666 save_p_isk = buf->b_p_isk;
10667 buf->b_p_isk = NULL;
10668 }
10669 /*
10670 * Always free the allocated strings.
10671 * If not already initialized, set 'readonly' and copy 'fileformat'.
10672 */
10673 if (!buf->b_p_initialized)
10674 {
10675 free_buf_options(buf, TRUE);
10676 buf->b_p_ro = FALSE; /* don't copy readonly */
10677 buf->b_p_tx = p_tx;
10678#ifdef FEAT_MBYTE
10679 buf->b_p_fenc = vim_strsave(p_fenc);
10680#endif
10681 buf->b_p_ff = vim_strsave(p_ff);
10682#if defined(FEAT_QUICKFIX)
10683 buf->b_p_bh = empty_option;
10684 buf->b_p_bt = empty_option;
10685#endif
10686 }
10687 else
10688 free_buf_options(buf, FALSE);
10689
10690 buf->b_p_ai = p_ai;
10691 buf->b_p_ai_nopaste = p_ai_nopaste;
10692 buf->b_p_sw = p_sw;
10693 buf->b_p_tw = p_tw;
10694 buf->b_p_tw_nopaste = p_tw_nopaste;
10695 buf->b_p_tw_nobin = p_tw_nobin;
10696 buf->b_p_wm = p_wm;
10697 buf->b_p_wm_nopaste = p_wm_nopaste;
10698 buf->b_p_wm_nobin = p_wm_nobin;
10699 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010700#ifdef FEAT_MBYTE
10701 buf->b_p_bomb = p_bomb;
10702#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010703 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704 buf->b_p_et = p_et;
10705 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010706 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707 buf->b_p_ml = p_ml;
10708 buf->b_p_ml_nobin = p_ml_nobin;
10709 buf->b_p_inf = p_inf;
10710 buf->b_p_swf = p_swf;
10711#ifdef FEAT_INS_EXPAND
10712 buf->b_p_cpt = vim_strsave(p_cpt);
10713#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010714#ifdef FEAT_COMPL_FUNC
10715 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010716 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010717#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718 buf->b_p_sts = p_sts;
10719 buf->b_p_sts_nopaste = p_sts_nopaste;
10720#ifndef SHORT_FNAME
10721 buf->b_p_sn = p_sn;
10722#endif
10723#ifdef FEAT_COMMENTS
10724 buf->b_p_com = vim_strsave(p_com);
10725#endif
10726#ifdef FEAT_FOLDING
10727 buf->b_p_cms = vim_strsave(p_cms);
10728#endif
10729 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010730 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010731 buf->b_p_nf = vim_strsave(p_nf);
10732 buf->b_p_mps = vim_strsave(p_mps);
10733#ifdef FEAT_SMARTINDENT
10734 buf->b_p_si = p_si;
10735#endif
10736 buf->b_p_ci = p_ci;
10737#ifdef FEAT_CINDENT
10738 buf->b_p_cin = p_cin;
10739 buf->b_p_cink = vim_strsave(p_cink);
10740 buf->b_p_cino = vim_strsave(p_cino);
10741#endif
10742#ifdef FEAT_AUTOCMD
10743 /* Don't copy 'filetype', it must be detected */
10744 buf->b_p_ft = empty_option;
10745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010746 buf->b_p_pi = p_pi;
10747#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10748 buf->b_p_cinw = vim_strsave(p_cinw);
10749#endif
10750#ifdef FEAT_LISP
10751 buf->b_p_lisp = p_lisp;
10752#endif
10753#ifdef FEAT_SYN_HL
10754 /* Don't copy 'syntax', it must be set */
10755 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010756 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010757 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010758#endif
10759#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010760 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010761 (void)compile_cap_prog(&buf->b_s);
10762 buf->b_s.b_p_spf = vim_strsave(p_spf);
10763 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764#endif
10765#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10766 buf->b_p_inde = vim_strsave(p_inde);
10767 buf->b_p_indk = vim_strsave(p_indk);
10768#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010769#if defined(FEAT_EVAL)
10770 buf->b_p_fex = vim_strsave(p_fex);
10771#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772#ifdef FEAT_CRYPT
10773 buf->b_p_key = vim_strsave(p_key);
10774#endif
10775#ifdef FEAT_SEARCHPATH
10776 buf->b_p_sua = vim_strsave(p_sua);
10777#endif
10778#ifdef FEAT_KEYMAP
10779 buf->b_p_keymap = vim_strsave(p_keymap);
10780 buf->b_kmap_state |= KEYMAP_INIT;
10781#endif
10782 /* This isn't really an option, but copying the langmap and IME
10783 * state from the current buffer is better than resetting it. */
10784 buf->b_p_iminsert = p_iminsert;
10785 buf->b_p_imsearch = p_imsearch;
10786
10787 /* options that are normally global but also have a local value
10788 * are not copied, start using the global value */
10789 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010790 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010791 buf->b_p_bkc = empty_option;
10792 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010793#ifdef FEAT_QUICKFIX
10794 buf->b_p_gp = empty_option;
10795 buf->b_p_mp = empty_option;
10796 buf->b_p_efm = empty_option;
10797#endif
10798 buf->b_p_ep = empty_option;
10799 buf->b_p_kp = empty_option;
10800 buf->b_p_path = empty_option;
10801 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010802 buf->b_p_tc = empty_option;
10803 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010804#ifdef FEAT_FIND_ID
10805 buf->b_p_def = empty_option;
10806 buf->b_p_inc = empty_option;
10807# ifdef FEAT_EVAL
10808 buf->b_p_inex = vim_strsave(p_inex);
10809# endif
10810#endif
10811#ifdef FEAT_INS_EXPAND
10812 buf->b_p_dict = empty_option;
10813 buf->b_p_tsr = empty_option;
10814#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010815#ifdef FEAT_TEXTOBJ
10816 buf->b_p_qe = vim_strsave(p_qe);
10817#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010818#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10819 buf->b_p_bexpr = empty_option;
10820#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010821#if defined(FEAT_CRYPT)
10822 buf->b_p_cm = empty_option;
10823#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010824#ifdef FEAT_PERSISTENT_UNDO
10825 buf->b_p_udf = p_udf;
10826#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010827#ifdef FEAT_LISP
10828 buf->b_p_lw = empty_option;
10829#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010830
10831 /*
10832 * Don't copy the options set by ex_help(), use the saved values,
10833 * when going from a help buffer to a non-help buffer.
10834 * Don't touch these at all when BCO_NOHELP is used and going from
10835 * or to a help buffer.
10836 */
10837 if (dont_do_help)
10838 buf->b_p_isk = save_p_isk;
10839 else
10840 {
10841 buf->b_p_isk = vim_strsave(p_isk);
10842 did_isk = TRUE;
10843 buf->b_p_ts = p_ts;
10844 buf->b_help = FALSE;
10845#ifdef FEAT_QUICKFIX
10846 if (buf->b_p_bt[0] == 'h')
10847 clear_string_option(&buf->b_p_bt);
10848#endif
10849 buf->b_p_ma = p_ma;
10850 }
10851 }
10852
10853 /*
10854 * When the options should be copied (ignoring BCO_ALWAYS), set the
10855 * flag that indicates that the options have been initialized.
10856 */
10857 if (should_copy)
10858 buf->b_p_initialized = TRUE;
10859 }
10860
10861 check_buf_options(buf); /* make sure we don't have NULLs */
10862 if (did_isk)
10863 (void)buf_init_chartab(buf, FALSE);
10864}
10865
10866/*
10867 * Reset the 'modifiable' option and its default value.
10868 */
10869 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010870reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871{
10872 int opt_idx;
10873
10874 curbuf->b_p_ma = FALSE;
10875 p_ma = FALSE;
10876 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010877 if (opt_idx >= 0)
10878 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879}
10880
10881/*
10882 * Set the global value for 'iminsert' to the local value.
10883 */
10884 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010885set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010886{
10887 p_iminsert = curbuf->b_p_iminsert;
10888}
10889
10890/*
10891 * Set the global value for 'imsearch' to the local value.
10892 */
10893 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010894set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895{
10896 p_imsearch = curbuf->b_p_imsearch;
10897}
10898
10899#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
10900static int expand_option_idx = -1;
10901static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
10902static int expand_option_flags = 0;
10903
10904 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010905set_context_in_set_cmd(
10906 expand_T *xp,
10907 char_u *arg,
10908 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909{
10910 int nextchar;
10911 long_u flags = 0; /* init for GCC */
10912 int opt_idx = 0; /* init for GCC */
10913 char_u *p;
10914 char_u *s;
10915 int is_term_option = FALSE;
10916 int key;
10917
10918 expand_option_flags = opt_flags;
10919
10920 xp->xp_context = EXPAND_SETTINGS;
10921 if (*arg == NUL)
10922 {
10923 xp->xp_pattern = arg;
10924 return;
10925 }
10926 p = arg + STRLEN(arg) - 1;
10927 if (*p == ' ' && *(p - 1) != '\\')
10928 {
10929 xp->xp_pattern = p + 1;
10930 return;
10931 }
10932 while (p > arg)
10933 {
10934 s = p;
10935 /* count number of backslashes before ' ' or ',' */
10936 if (*p == ' ' || *p == ',')
10937 {
10938 while (s > arg && *(s - 1) == '\\')
10939 --s;
10940 }
10941 /* break at a space with an even number of backslashes */
10942 if (*p == ' ' && ((p - s) & 1) == 0)
10943 {
10944 ++p;
10945 break;
10946 }
10947 --p;
10948 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000010949 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010950 {
10951 xp->xp_context = EXPAND_BOOL_SETTINGS;
10952 p += 2;
10953 }
10954 if (STRNCMP(p, "inv", 3) == 0)
10955 {
10956 xp->xp_context = EXPAND_BOOL_SETTINGS;
10957 p += 3;
10958 }
10959 xp->xp_pattern = arg = p;
10960 if (*arg == '<')
10961 {
10962 while (*p != '>')
10963 if (*p++ == NUL) /* expand terminal option name */
10964 return;
10965 key = get_special_key_code(arg + 1);
10966 if (key == 0) /* unknown name */
10967 {
10968 xp->xp_context = EXPAND_NOTHING;
10969 return;
10970 }
10971 nextchar = *++p;
10972 is_term_option = TRUE;
10973 expand_option_name[2] = KEY2TERMCAP0(key);
10974 expand_option_name[3] = KEY2TERMCAP1(key);
10975 }
10976 else
10977 {
10978 if (p[0] == 't' && p[1] == '_')
10979 {
10980 p += 2;
10981 if (*p != NUL)
10982 ++p;
10983 if (*p == NUL)
10984 return; /* expand option name */
10985 nextchar = *++p;
10986 is_term_option = TRUE;
10987 expand_option_name[2] = p[-2];
10988 expand_option_name[3] = p[-1];
10989 }
10990 else
10991 {
10992 /* Allow * wildcard */
10993 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
10994 p++;
10995 if (*p == NUL)
10996 return;
10997 nextchar = *p;
10998 *p = NUL;
10999 opt_idx = findoption(arg);
11000 *p = nextchar;
11001 if (opt_idx == -1 || options[opt_idx].var == NULL)
11002 {
11003 xp->xp_context = EXPAND_NOTHING;
11004 return;
11005 }
11006 flags = options[opt_idx].flags;
11007 if (flags & P_BOOL)
11008 {
11009 xp->xp_context = EXPAND_NOTHING;
11010 return;
11011 }
11012 }
11013 }
11014 /* handle "-=" and "+=" */
11015 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11016 {
11017 ++p;
11018 nextchar = '=';
11019 }
11020 if ((nextchar != '=' && nextchar != ':')
11021 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11022 {
11023 xp->xp_context = EXPAND_UNSUCCESSFUL;
11024 return;
11025 }
11026 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11027 {
11028 xp->xp_context = EXPAND_OLD_SETTING;
11029 if (is_term_option)
11030 expand_option_idx = -1;
11031 else
11032 expand_option_idx = opt_idx;
11033 xp->xp_pattern = p + 1;
11034 return;
11035 }
11036 xp->xp_context = EXPAND_NOTHING;
11037 if (is_term_option || (flags & P_NUM))
11038 return;
11039
11040 xp->xp_pattern = p + 1;
11041
11042 if (flags & P_EXPAND)
11043 {
11044 p = options[opt_idx].var;
11045 if (p == (char_u *)&p_bdir
11046 || p == (char_u *)&p_dir
11047 || p == (char_u *)&p_path
11048 || p == (char_u *)&p_rtp
11049#ifdef FEAT_SEARCHPATH
11050 || p == (char_u *)&p_cdpath
11051#endif
11052#ifdef FEAT_SESSION
11053 || p == (char_u *)&p_vdir
11054#endif
11055 )
11056 {
11057 xp->xp_context = EXPAND_DIRECTORIES;
11058 if (p == (char_u *)&p_path
11059#ifdef FEAT_SEARCHPATH
11060 || p == (char_u *)&p_cdpath
11061#endif
11062 )
11063 xp->xp_backslash = XP_BS_THREE;
11064 else
11065 xp->xp_backslash = XP_BS_ONE;
11066 }
11067 else
11068 {
11069 xp->xp_context = EXPAND_FILES;
11070 /* for 'tags' need three backslashes for a space */
11071 if (p == (char_u *)&p_tags)
11072 xp->xp_backslash = XP_BS_THREE;
11073 else
11074 xp->xp_backslash = XP_BS_ONE;
11075 }
11076 }
11077
11078 /* For an option that is a list of file names, find the start of the
11079 * last file name. */
11080 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11081 {
11082 /* count number of backslashes before ' ' or ',' */
11083 if (*p == ' ' || *p == ',')
11084 {
11085 s = p;
11086 while (s > xp->xp_pattern && *(s - 1) == '\\')
11087 --s;
11088 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11089 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11090 {
11091 xp->xp_pattern = p + 1;
11092 break;
11093 }
11094 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011095
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011096#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011097 /* for 'spellsuggest' start at "file:" */
11098 if (options[opt_idx].var == (char_u *)&p_sps
11099 && STRNCMP(p, "file:", 5) == 0)
11100 {
11101 xp->xp_pattern = p + 5;
11102 break;
11103 }
11104#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011105 }
11106
11107 return;
11108}
11109
11110 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011111ExpandSettings(
11112 expand_T *xp,
11113 regmatch_T *regmatch,
11114 int *num_file,
11115 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011116{
11117 int num_normal = 0; /* Nr of matching non-term-code settings */
11118 int num_term = 0; /* Nr of matching terminal code settings */
11119 int opt_idx;
11120 int match;
11121 int count = 0;
11122 char_u *str;
11123 int loop;
11124 int is_term_opt;
11125 char_u name_buf[MAX_KEY_NAME_LEN];
11126 static char *(names[]) = {"all", "termcap"};
11127 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11128
11129 /* do this loop twice:
11130 * loop == 0: count the number of matching options
11131 * loop == 1: copy the matching options into allocated memory
11132 */
11133 for (loop = 0; loop <= 1; ++loop)
11134 {
11135 regmatch->rm_ic = ic;
11136 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11137 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011138 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11139 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011140 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11141 {
11142 if (loop == 0)
11143 num_normal++;
11144 else
11145 (*file)[count++] = vim_strsave((char_u *)names[match]);
11146 }
11147 }
11148 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11149 opt_idx++)
11150 {
11151 if (options[opt_idx].var == NULL)
11152 continue;
11153 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11154 && !(options[opt_idx].flags & P_BOOL))
11155 continue;
11156 is_term_opt = istermoption(&options[opt_idx]);
11157 if (is_term_opt && num_normal > 0)
11158 continue;
11159 match = FALSE;
11160 if (vim_regexec(regmatch, str, (colnr_T)0)
11161 || (options[opt_idx].shortname != NULL
11162 && vim_regexec(regmatch,
11163 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11164 match = TRUE;
11165 else if (is_term_opt)
11166 {
11167 name_buf[0] = '<';
11168 name_buf[1] = 't';
11169 name_buf[2] = '_';
11170 name_buf[3] = str[2];
11171 name_buf[4] = str[3];
11172 name_buf[5] = '>';
11173 name_buf[6] = NUL;
11174 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11175 {
11176 match = TRUE;
11177 str = name_buf;
11178 }
11179 }
11180 if (match)
11181 {
11182 if (loop == 0)
11183 {
11184 if (is_term_opt)
11185 num_term++;
11186 else
11187 num_normal++;
11188 }
11189 else
11190 (*file)[count++] = vim_strsave(str);
11191 }
11192 }
11193 /*
11194 * Check terminal key codes, these are not in the option table
11195 */
11196 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11197 {
11198 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11199 {
11200 if (!isprint(str[0]) || !isprint(str[1]))
11201 continue;
11202
11203 name_buf[0] = 't';
11204 name_buf[1] = '_';
11205 name_buf[2] = str[0];
11206 name_buf[3] = str[1];
11207 name_buf[4] = NUL;
11208
11209 match = FALSE;
11210 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11211 match = TRUE;
11212 else
11213 {
11214 name_buf[0] = '<';
11215 name_buf[1] = 't';
11216 name_buf[2] = '_';
11217 name_buf[3] = str[0];
11218 name_buf[4] = str[1];
11219 name_buf[5] = '>';
11220 name_buf[6] = NUL;
11221
11222 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11223 match = TRUE;
11224 }
11225 if (match)
11226 {
11227 if (loop == 0)
11228 num_term++;
11229 else
11230 (*file)[count++] = vim_strsave(name_buf);
11231 }
11232 }
11233
11234 /*
11235 * Check special key names.
11236 */
11237 regmatch->rm_ic = TRUE; /* ignore case here */
11238 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11239 {
11240 name_buf[0] = '<';
11241 STRCPY(name_buf + 1, str);
11242 STRCAT(name_buf, ">");
11243
11244 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11245 {
11246 if (loop == 0)
11247 num_term++;
11248 else
11249 (*file)[count++] = vim_strsave(name_buf);
11250 }
11251 }
11252 }
11253 if (loop == 0)
11254 {
11255 if (num_normal > 0)
11256 *num_file = num_normal;
11257 else if (num_term > 0)
11258 *num_file = num_term;
11259 else
11260 return OK;
11261 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11262 if (*file == NULL)
11263 {
11264 *file = (char_u **)"";
11265 return FAIL;
11266 }
11267 }
11268 }
11269 return OK;
11270}
11271
11272 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011273ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011274{
11275 char_u *var = NULL; /* init for GCC */
11276 char_u *buf;
11277
11278 *num_file = 0;
11279 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11280 if (*file == NULL)
11281 return FAIL;
11282
11283 /*
11284 * For a terminal key code expand_option_idx is < 0.
11285 */
11286 if (expand_option_idx < 0)
11287 {
11288 var = find_termcode(expand_option_name + 2);
11289 if (var == NULL)
11290 expand_option_idx = findoption(expand_option_name);
11291 }
11292
11293 if (expand_option_idx >= 0)
11294 {
11295 /* put string of option value in NameBuff */
11296 option_value2string(&options[expand_option_idx], expand_option_flags);
11297 var = NameBuff;
11298 }
11299 else if (var == NULL)
11300 var = (char_u *)"";
11301
11302 /* A backslash is required before some characters. This is the reverse of
11303 * what happens in do_set(). */
11304 buf = vim_strsave_escaped(var, escape_chars);
11305
11306 if (buf == NULL)
11307 {
11308 vim_free(*file);
11309 *file = NULL;
11310 return FAIL;
11311 }
11312
11313#ifdef BACKSLASH_IN_FILENAME
11314 /* For MS-Windows et al. we don't double backslashes at the start and
11315 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011316 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011317 if (var[0] == '\\' && var[1] == '\\'
11318 && expand_option_idx >= 0
11319 && (options[expand_option_idx].flags & P_EXPAND)
11320 && vim_isfilec(var[2])
11321 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011322 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323#endif
11324
11325 *file[0] = buf;
11326 *num_file = 1;
11327 return OK;
11328}
11329#endif
11330
11331/*
11332 * Get the value for the numeric or string option *opp in a nice format into
11333 * NameBuff[]. Must not be called with a hidden option!
11334 */
11335 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011336option_value2string(
11337 struct vimoption *opp,
11338 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011339{
11340 char_u *varp;
11341
11342 varp = get_varp_scope(opp, opt_flags);
11343
11344 if (opp->flags & P_NUM)
11345 {
11346 long wc = 0;
11347
11348 if (wc_use_keyname(varp, &wc))
11349 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11350 else if (wc != 0)
11351 STRCPY(NameBuff, transchar((int)wc));
11352 else
11353 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11354 }
11355 else /* P_STRING */
11356 {
11357 varp = *(char_u **)(varp);
11358 if (varp == NULL) /* just in case */
11359 NameBuff[0] = NUL;
11360#ifdef FEAT_CRYPT
11361 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011362 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011363 STRCPY(NameBuff, "*****");
11364#endif
11365 else if (opp->flags & P_EXPAND)
11366 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11367 /* Translate 'pastetoggle' into special key names */
11368 else if ((char_u **)opp->var == &p_pt)
11369 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11370 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011371 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372 }
11373}
11374
11375/*
11376 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11377 * printed as a keyname.
11378 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11379 */
11380 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011381wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011382{
11383 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11384 {
11385 *wcp = *(long *)varp;
11386 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11387 return TRUE;
11388 }
11389 return FALSE;
11390}
11391
Bram Moolenaar01615492015-02-03 13:00:38 +010011392#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011393/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011394 * Any character has an equivalent 'langmap' character. This is used for
11395 * keyboards that have a special language mode that sends characters above
11396 * 128 (although other characters can be translated too). The "to" field is a
11397 * Vim command character. This avoids having to switch the keyboard back to
11398 * ASCII mode when leaving Insert mode.
11399 *
11400 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11401 * commands.
11402 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11403 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11404 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011405 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011406# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011407/*
11408 * With multi-byte support use growarray for 'langmap' chars >= 256
11409 */
11410typedef struct
11411{
11412 int from;
11413 int to;
11414} langmap_entry_T;
11415
11416static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011417static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011418
11419/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011420 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11421 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011422 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011423 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011424langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011425{
11426 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011427 int a = 0;
11428 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011429
11430 /* Do a binary search for an existing entry. */
11431 while (a != b)
11432 {
11433 int i = (a + b) / 2;
11434 int d = entries[i].from - from;
11435
11436 if (d == 0)
11437 {
11438 entries[i].to = to;
11439 return;
11440 }
11441 if (d < 0)
11442 a = i + 1;
11443 else
11444 b = i;
11445 }
11446
11447 if (ga_grow(&langmap_mapga, 1) != OK)
11448 return; /* out of memory */
11449
11450 /* insert new entry at position "a" */
11451 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11452 mch_memmove(entries + 1, entries,
11453 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11454 ++langmap_mapga.ga_len;
11455 entries[0].from = from;
11456 entries[0].to = to;
11457}
11458
11459/*
11460 * Apply 'langmap' to multi-byte character "c" and return the result.
11461 */
11462 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011463langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011464{
11465 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11466 int a = 0;
11467 int b = langmap_mapga.ga_len;
11468
11469 while (a != b)
11470 {
11471 int i = (a + b) / 2;
11472 int d = entries[i].from - c;
11473
11474 if (d == 0)
11475 return entries[i].to; /* found matching entry */
11476 if (d < 0)
11477 a = i + 1;
11478 else
11479 b = i;
11480 }
11481 return c; /* no entry found, return "c" unmodified */
11482}
11483# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011484
11485 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011486langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011487{
11488 int i;
11489
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011490 for (i = 0; i < 256; i++)
11491 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11492# ifdef FEAT_MBYTE
11493 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11494# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011495}
11496
11497/*
11498 * Called when langmap option is set; the language map can be
11499 * changed at any time!
11500 */
11501 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011502langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011503{
11504 char_u *p;
11505 char_u *p2;
11506 int from, to;
11507
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011508#ifdef FEAT_MBYTE
11509 ga_clear(&langmap_mapga); /* clear the previous map first */
11510#endif
11511 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011512
11513 for (p = p_langmap; p[0] != NUL; )
11514 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011515 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11516 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011517 {
11518 if (p2[0] == '\\' && p2[1] != NUL)
11519 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011520 }
11521 if (p2[0] == ';')
11522 ++p2; /* abcd;ABCD form, p2 points to A */
11523 else
11524 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11525 while (p[0])
11526 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011527 if (p[0] == ',')
11528 {
11529 ++p;
11530 break;
11531 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011532 if (p[0] == '\\' && p[1] != NUL)
11533 ++p;
11534#ifdef FEAT_MBYTE
11535 from = (*mb_ptr2char)(p);
11536#else
11537 from = p[0];
11538#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011539 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011540 if (p2 == NULL)
11541 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011542 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011543 if (p[0] != ',')
11544 {
11545 if (p[0] == '\\')
11546 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011547#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011548 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011549#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011550 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011551#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011552 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011553 }
11554 else
11555 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011556 if (p2[0] != ',')
11557 {
11558 if (p2[0] == '\\')
11559 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011560#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011561 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011562#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011563 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011564#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011565 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011566 }
11567 if (to == NUL)
11568 {
11569 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11570 transchar(from));
11571 return;
11572 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011573
11574#ifdef FEAT_MBYTE
11575 if (from >= 256)
11576 langmap_set_entry(from, to);
11577 else
11578#endif
11579 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580
11581 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011582 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011583 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011584 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011585 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011586 if (*p == ';')
11587 {
11588 p = p2;
11589 if (p[0] != NUL)
11590 {
11591 if (p[0] != ',')
11592 {
11593 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11594 return;
11595 }
11596 ++p;
11597 }
11598 break;
11599 }
11600 }
11601 }
11602 }
11603}
11604#endif
11605
11606/*
11607 * Return TRUE if format option 'x' is in effect.
11608 * Take care of no formatting when 'paste' is set.
11609 */
11610 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011611has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011612{
11613 if (p_paste)
11614 return FALSE;
11615 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11616}
11617
11618/*
11619 * Return TRUE if "x" is present in 'shortmess' option, or
11620 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11621 */
11622 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011623shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011624{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011625 return p_shm != NULL &&
11626 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011627 || (vim_strchr(p_shm, 'a') != NULL
11628 && vim_strchr((char_u *)SHM_A, x) != NULL));
11629}
11630
11631/*
11632 * paste_option_changed() - Called after p_paste was set or reset.
11633 */
11634 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011635paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011636{
11637 static int old_p_paste = FALSE;
11638 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011639 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640#ifdef FEAT_CMDL_INFO
11641 static int save_ru = 0;
11642#endif
11643#ifdef FEAT_RIGHTLEFT
11644 static int save_ri = 0;
11645 static int save_hkmap = 0;
11646#endif
11647 buf_T *buf;
11648
11649 if (p_paste)
11650 {
11651 /*
11652 * Paste switched from off to on.
11653 * Save the current values, so they can be restored later.
11654 */
11655 if (!old_p_paste)
11656 {
11657 /* save options for each buffer */
11658 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11659 {
11660 buf->b_p_tw_nopaste = buf->b_p_tw;
11661 buf->b_p_wm_nopaste = buf->b_p_wm;
11662 buf->b_p_sts_nopaste = buf->b_p_sts;
11663 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011664 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011665 }
11666
11667 /* save global options */
11668 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011669 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011670#ifdef FEAT_CMDL_INFO
11671 save_ru = p_ru;
11672#endif
11673#ifdef FEAT_RIGHTLEFT
11674 save_ri = p_ri;
11675 save_hkmap = p_hkmap;
11676#endif
11677 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011678 p_ai_nopaste = p_ai;
11679 p_et_nopaste = p_et;
11680 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011681 p_tw_nopaste = p_tw;
11682 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011683 }
11684
11685 /*
11686 * Always set the option values, also when 'paste' is set when it is
11687 * already on.
11688 */
11689 /* set options for each buffer */
11690 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11691 {
11692 buf->b_p_tw = 0; /* textwidth is 0 */
11693 buf->b_p_wm = 0; /* wrapmargin is 0 */
11694 buf->b_p_sts = 0; /* softtabstop is 0 */
11695 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011696 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011697 }
11698
11699 /* set global options */
11700 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011701 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011702#ifdef FEAT_CMDL_INFO
11703# ifdef FEAT_WINDOWS
11704 if (p_ru)
11705 status_redraw_all(); /* redraw to remove the ruler */
11706# endif
11707 p_ru = 0; /* no ruler */
11708#endif
11709#ifdef FEAT_RIGHTLEFT
11710 p_ri = 0; /* no reverse insert */
11711 p_hkmap = 0; /* no Hebrew keyboard */
11712#endif
11713 /* set global values for local buffer options */
11714 p_tw = 0;
11715 p_wm = 0;
11716 p_sts = 0;
11717 p_ai = 0;
11718 }
11719
11720 /*
11721 * Paste switched from on to off: Restore saved values.
11722 */
11723 else if (old_p_paste)
11724 {
11725 /* restore options for each buffer */
11726 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
11727 {
11728 buf->b_p_tw = buf->b_p_tw_nopaste;
11729 buf->b_p_wm = buf->b_p_wm_nopaste;
11730 buf->b_p_sts = buf->b_p_sts_nopaste;
11731 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011732 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011733 }
11734
11735 /* restore global options */
11736 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011737 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011738#ifdef FEAT_CMDL_INFO
11739# ifdef FEAT_WINDOWS
11740 if (p_ru != save_ru)
11741 status_redraw_all(); /* redraw to draw the ruler */
11742# endif
11743 p_ru = save_ru;
11744#endif
11745#ifdef FEAT_RIGHTLEFT
11746 p_ri = save_ri;
11747 p_hkmap = save_hkmap;
11748#endif
11749 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011750 p_ai = p_ai_nopaste;
11751 p_et = p_et_nopaste;
11752 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011753 p_tw = p_tw_nopaste;
11754 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011755 }
11756
11757 old_p_paste = p_paste;
11758}
11759
11760/*
11761 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11762 *
11763 * Reset 'compatible' and set the values for options that didn't get set yet
11764 * to the Vim defaults.
11765 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011766 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767 */
11768 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011769vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011770{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011771 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011772 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011773 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011774
11775 if (!option_was_set((char_u *)"cp"))
11776 {
11777 p_cp = FALSE;
11778 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11779 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11780 set_option_default(opt_idx, OPT_FREE, FALSE);
11781 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011782 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011783 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011784
11785 if (fname != NULL)
11786 {
11787 p = vim_getenv(envname, &dofree);
11788 if (p == NULL)
11789 {
11790 /* Set $MYVIMRC to the first vimrc file found. */
11791 p = FullName_save(fname, FALSE);
11792 if (p != NULL)
11793 {
11794 vim_setenv(envname, p);
11795 vim_free(p);
11796 }
11797 }
11798 else if (dofree)
11799 vim_free(p);
11800 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011801}
11802
11803/*
11804 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11805 */
11806 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011807change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011808{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011809 int opt_idx;
11810
Bram Moolenaar071d4272004-06-13 20:20:40 +000011811 if (p_cp != on)
11812 {
11813 p_cp = on;
11814 compatible_set();
11815 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011816 opt_idx = findoption((char_u *)"cp");
11817 if (opt_idx >= 0)
11818 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819}
11820
11821/*
11822 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011823 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011824 */
11825 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011826option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011827{
11828 int idx;
11829
11830 idx = findoption(name);
11831 if (idx < 0) /* unknown option */
11832 return FALSE;
11833 if (options[idx].flags & P_WAS_SET)
11834 return TRUE;
11835 return FALSE;
11836}
11837
11838/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011839 * Reset the flag indicating option "name" was set.
11840 */
11841 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011842reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011843{
11844 int idx = findoption(name);
11845
11846 if (idx >= 0)
11847 options[idx].flags &= ~P_WAS_SET;
11848}
11849
11850/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011851 * compatible_set() - Called when 'compatible' has been set or unset.
11852 *
11853 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11854 * flag) to a Vi compatible value.
11855 * When 'compatible' is unset: Set all options that have a different default
11856 * for Vim (without the P_VI_DEF flag) to that default.
11857 */
11858 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011859compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011860{
11861 int opt_idx;
11862
11863 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11864 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11865 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11866 set_option_default(opt_idx, OPT_FREE, p_cp);
11867 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011868 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011869}
11870
11871#ifdef FEAT_LINEBREAK
11872
11873# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11874 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011875 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011876# endif
11877
11878/*
11879 * fill_breakat_flags() -- called when 'breakat' changes value.
11880 */
11881 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011882fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011884 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011885 int i;
11886
11887 for (i = 0; i < 256; i++)
11888 breakat_flags[i] = FALSE;
11889
11890 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000011891 for (p = p_breakat; *p; p++)
11892 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893}
11894
11895# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011896 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011897# endif
11898
11899#endif
11900
11901/*
11902 * Check an option that can be a range of string values.
11903 *
11904 * Return OK for correct value, FAIL otherwise.
11905 * Empty is always OK.
11906 */
11907 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011908check_opt_strings(
11909 char_u *val,
11910 char **values,
11911 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011912{
11913 return opt_strings_flags(val, values, NULL, list);
11914}
11915
11916/*
11917 * Handle an option that can be a range of string values.
11918 * Set a flag in "*flagp" for each string present.
11919 *
11920 * Return OK for correct value, FAIL otherwise.
11921 * Empty is always OK.
11922 */
11923 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011924opt_strings_flags(
11925 char_u *val, /* new value */
11926 char **values, /* array of valid string values */
11927 unsigned *flagp,
11928 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011929{
11930 int i;
11931 int len;
11932 unsigned new_flags = 0;
11933
11934 while (*val)
11935 {
11936 for (i = 0; ; ++i)
11937 {
11938 if (values[i] == NULL) /* val not found in values[] */
11939 return FAIL;
11940
11941 len = (int)STRLEN(values[i]);
11942 if (STRNCMP(values[i], val, len) == 0
11943 && ((list && val[len] == ',') || val[len] == NUL))
11944 {
11945 val += len + (val[len] == ',');
11946 new_flags |= (1 << i);
11947 break; /* check next item in val list */
11948 }
11949 }
11950 }
11951 if (flagp != NULL)
11952 *flagp = new_flags;
11953
11954 return OK;
11955}
11956
11957/*
11958 * Read the 'wildmode' option, fill wim_flags[].
11959 */
11960 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011961check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011962{
11963 char_u new_wim_flags[4];
11964 char_u *p;
11965 int i;
11966 int idx = 0;
11967
11968 for (i = 0; i < 4; ++i)
11969 new_wim_flags[i] = 0;
11970
11971 for (p = p_wim; *p; ++p)
11972 {
11973 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
11974 ;
11975 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
11976 return FAIL;
11977 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
11978 new_wim_flags[idx] |= WIM_LONGEST;
11979 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
11980 new_wim_flags[idx] |= WIM_FULL;
11981 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
11982 new_wim_flags[idx] |= WIM_LIST;
11983 else
11984 return FAIL;
11985 p += i;
11986 if (*p == NUL)
11987 break;
11988 if (*p == ',')
11989 {
11990 if (idx == 3)
11991 return FAIL;
11992 ++idx;
11993 }
11994 }
11995
11996 /* fill remaining entries with last flag */
11997 while (idx < 3)
11998 {
11999 new_wim_flags[idx + 1] = new_wim_flags[idx];
12000 ++idx;
12001 }
12002
12003 /* only when there are no errors, wim_flags[] is changed */
12004 for (i = 0; i < 4; ++i)
12005 wim_flags[i] = new_wim_flags[i];
12006 return OK;
12007}
12008
12009/*
12010 * Check if backspacing over something is allowed.
12011 */
12012 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012013can_bs(
12014 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012015{
12016 switch (*p_bs)
12017 {
12018 case '2': return TRUE;
12019 case '1': return (what != BS_START);
12020 case '0': return FALSE;
12021 }
12022 return vim_strchr(p_bs, what) != NULL;
12023}
12024
12025/*
12026 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12027 * the file must be considered changed when the value is different.
12028 */
12029 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012030save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012031{
12032 buf->b_start_ffc = *buf->b_p_ff;
12033 buf->b_start_eol = buf->b_p_eol;
12034#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012035 buf->b_start_bomb = buf->b_p_bomb;
12036
Bram Moolenaar071d4272004-06-13 20:20:40 +000012037 /* Only use free/alloc when necessary, they take time. */
12038 if (buf->b_start_fenc == NULL
12039 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12040 {
12041 vim_free(buf->b_start_fenc);
12042 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12043 }
12044#endif
12045}
12046
12047/*
12048 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12049 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012050 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12051 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012052 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012053 * When "ignore_empty" is true don't consider a new, empty buffer to be
12054 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012055 */
12056 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012057file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012058{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012059 /* In a buffer that was never loaded the options are not valid. */
12060 if (buf->b_flags & BF_NEVERLOADED)
12061 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012062 if (ignore_empty
12063 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012064 && buf->b_ml.ml_line_count == 1
12065 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12066 return FALSE;
12067 if (buf->b_start_ffc != *buf->b_p_ff)
12068 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012069 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070 return TRUE;
12071#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012072 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12073 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012074 if (buf->b_start_fenc == NULL)
12075 return (*buf->b_p_fenc != NUL);
12076 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12077#else
12078 return FALSE;
12079#endif
12080}
12081
12082/*
12083 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12084 */
12085 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012086check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012087{
12088 return check_opt_strings(p, p_ff_values, FALSE);
12089}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012090
12091/*
12092 * Return the effective shiftwidth value for current buffer, using the
12093 * 'tabstop' value when 'shiftwidth' is zero.
12094 */
12095 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012096get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012097{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012098 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012099}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012100
12101/*
12102 * Return the effective softtabstop value for the current buffer, using the
12103 * 'tabstop' value when 'softtabstop' is negative.
12104 */
12105 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012106get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012107{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012108 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012109}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012110
12111/*
12112 * Check matchpairs option for "*initc".
12113 * If there is a match set "*initc" to the matching character and "*findc" to
12114 * the opposite character. Set "*backwards" to the direction.
12115 * When "switchit" is TRUE swap the direction.
12116 */
12117 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012118find_mps_values(
12119 int *initc,
12120 int *findc,
12121 int *backwards,
12122 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012123{
12124 char_u *ptr;
12125
12126 ptr = curbuf->b_p_mps;
12127 while (*ptr != NUL)
12128 {
12129#ifdef FEAT_MBYTE
12130 if (has_mbyte)
12131 {
12132 char_u *prev;
12133
12134 if (mb_ptr2char(ptr) == *initc)
12135 {
12136 if (switchit)
12137 {
12138 *findc = *initc;
12139 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12140 *backwards = TRUE;
12141 }
12142 else
12143 {
12144 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12145 *backwards = FALSE;
12146 }
12147 return;
12148 }
12149 prev = ptr;
12150 ptr += mb_ptr2len(ptr) + 1;
12151 if (mb_ptr2char(ptr) == *initc)
12152 {
12153 if (switchit)
12154 {
12155 *findc = *initc;
12156 *initc = mb_ptr2char(prev);
12157 *backwards = FALSE;
12158 }
12159 else
12160 {
12161 *findc = mb_ptr2char(prev);
12162 *backwards = TRUE;
12163 }
12164 return;
12165 }
12166 ptr += mb_ptr2len(ptr);
12167 }
12168 else
12169#endif
12170 {
12171 if (*ptr == *initc)
12172 {
12173 if (switchit)
12174 {
12175 *backwards = TRUE;
12176 *findc = *initc;
12177 *initc = ptr[2];
12178 }
12179 else
12180 {
12181 *backwards = FALSE;
12182 *findc = ptr[2];
12183 }
12184 return;
12185 }
12186 ptr += 2;
12187 if (*ptr == *initc)
12188 {
12189 if (switchit)
12190 {
12191 *backwards = FALSE;
12192 *findc = *initc;
12193 *initc = ptr[-2];
12194 }
12195 else
12196 {
12197 *backwards = TRUE;
12198 *findc = ptr[-2];
12199 }
12200 return;
12201 }
12202 ++ptr;
12203 }
12204 if (*ptr == ',')
12205 ++ptr;
12206 }
12207}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012208
12209#if defined(FEAT_LINEBREAK) || defined(PROTO)
12210/*
12211 * This is called when 'breakindentopt' is changed and when a window is
12212 * initialized.
12213 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012214 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012215briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012216{
12217 char_u *p;
12218 int bri_shift = 0;
12219 long bri_min = 20;
12220 int bri_sbr = FALSE;
12221
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012222 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012223 while (*p != NUL)
12224 {
12225 if (STRNCMP(p, "shift:", 6) == 0
12226 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12227 {
12228 p += 6;
12229 bri_shift = getdigits(&p);
12230 }
12231 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12232 {
12233 p += 4;
12234 bri_min = getdigits(&p);
12235 }
12236 else if (STRNCMP(p, "sbr", 3) == 0)
12237 {
12238 p += 3;
12239 bri_sbr = TRUE;
12240 }
12241 if (*p != ',' && *p != NUL)
12242 return FAIL;
12243 if (*p == ',')
12244 ++p;
12245 }
12246
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012247 wp->w_p_brishift = bri_shift;
12248 wp->w_p_brimin = bri_min;
12249 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012250
12251 return OK;
12252}
12253#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012254
12255/*
12256 * Get the local or global value of 'backupcopy'.
12257 */
12258 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012259get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012260{
12261 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12262}