blob: a1304c9447cb400784dc12e1e96fcfaa7f400b9d [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
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.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * 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 Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# 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 Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
225#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#ifdef FEAT_WINDOWS
249# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000250# 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 Moolenaare4f25e42017-07-07 11:54:15 +0200260#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +0200261# define PV_TK OPT_WIN(WV_TK)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200262# define PV_TMS OPT_WIN(WV_TMS)
263#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200264#ifdef FEAT_SIGNS
265# define PV_SCL OPT_WIN(WV_SCL)
266#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000267
268/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269typedef enum
270{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000271 PV_NONE = 0,
272 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273} idopt_T;
274
275/*
276 * Options local to a window have a value local to a buffer and global to all
277 * buffers. Indicate this by setting "var" to VAR_WIN.
278 */
279#define VAR_WIN ((char_u *)-1)
280
281/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000282 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283 * Only to be used in option.c!
284 */
285static int p_ai;
286static int p_bin;
287#ifdef FEAT_MBYTE
288static int p_bomb;
289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290static char_u *p_bh;
291static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000292static int p_bl;
293static int p_ci;
294#ifdef FEAT_CINDENT
295static int p_cin;
296static char_u *p_cink;
297static char_u *p_cino;
298#endif
299#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
300static char_u *p_cinw;
301#endif
302#ifdef FEAT_COMMENTS
303static char_u *p_com;
304#endif
305#ifdef FEAT_FOLDING
306static char_u *p_cms;
307#endif
308#ifdef FEAT_INS_EXPAND
309static char_u *p_cpt;
310#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000311#ifdef FEAT_COMPL_FUNC
312static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000313static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000314#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200316static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static int p_et;
318#ifdef FEAT_MBYTE
319static char_u *p_fenc;
320#endif
321static char_u *p_ff;
322static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000323static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324#ifdef FEAT_AUTOCMD
325static char_u *p_ft;
326#endif
327static long p_iminsert;
328static long p_imsearch;
329#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
330static char_u *p_inex;
331#endif
332#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
333static char_u *p_inde;
334static char_u *p_indk;
335#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000336#if defined(FEAT_EVAL)
337static char_u *p_fex;
338#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339static int p_inf;
340static char_u *p_isk;
341#ifdef FEAT_CRYPT
342static char_u *p_key;
343#endif
344#ifdef FEAT_LISP
345static int p_lisp;
346#endif
347static int p_ml;
348static int p_ma;
349static int p_mod;
350static char_u *p_mps;
351static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000353#ifdef FEAT_TEXTOBJ
354static char_u *p_qe;
355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static int p_ro;
357#ifdef FEAT_SMARTINDENT
358static int p_si;
359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361static long p_sts;
362#if defined(FEAT_SEARCHPATH)
363static char_u *p_sua;
364#endif
365static long p_sw;
366static int p_swf;
367#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000368static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000370#endif
371#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000372static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000373static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000374static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375#endif
376static long p_ts;
377static long p_tw;
378static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200379#ifdef FEAT_PERSISTENT_UNDO
380static int p_udf;
381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382static long p_wm;
383#ifdef FEAT_KEYMAP
384static char_u *p_keymap;
385#endif
386
387/* Saved values for when 'bin' is set. */
388static int p_et_nobin;
389static int p_ml_nobin;
390static long p_tw_nobin;
391static long p_wm_nobin;
392
393/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200394static int p_ai_nopaste;
395static int p_et_nopaste;
396static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397static long p_tw_nopaste;
398static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399
400struct vimoption
401{
402 char *fullname; /* full option name */
403 char *shortname; /* permissible abbreviation */
404 long_u flags; /* see below */
405 char_u *var; /* global option: pointer to variable;
406 * window-local option: VAR_WIN;
407 * buffer-local option: global value */
408 idopt_T indir; /* global option: PV_NONE;
409 * local option: indirect option index */
410 char_u *def_val[2]; /* default values for variable (vi and vim) */
411#ifdef FEAT_EVAL
412 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000413# define SCRIPTID_INIT , 0
414#else
415# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416#endif
417};
418
419#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
420#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
421
422/*
423 * Flags
424 */
425#define P_BOOL 0x01 /* the option is boolean */
426#define P_NUM 0x02 /* the option is numeric */
427#define P_STRING 0x04 /* the option is a string */
428#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000429 must use free_string_option() when
430 assigning new value. Not set if default is
431 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000432#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
433 never be used for local or hidden options! */
434#define P_NODEFAULT 0x40 /* don't set to default value */
435#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
436 use vim_free() when assigning new value */
437#define P_WAS_SET 0x100 /* option has been set/reset */
438#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
439#define P_VI_DEF 0x400 /* Use Vi default for Vim */
440#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
441
442 /* when option changed, what to display: */
443#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100444#define P_RWIN 0x2000 /* redraw current window and recompute text */
445#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000446#define P_RALL 0x6000 /* redraw all windows */
447#define P_RCLR 0x7000 /* clear and redraw all */
448
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200449#define P_COMMA 0x8000 /* comma separated list */
450#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
451 * commas */
452#define P_NODUP 0x20000L /* don't allow duplicate strings */
453#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000454
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200455#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
456#define P_GETTEXT 0x100000L /* expand default value with _() */
457#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
458#define P_NFNAME 0x400000L /* only normal file name chars allowed */
459#define P_INSECURE 0x800000L /* option was set from a modeline */
460#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100461 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200462#define P_NO_ML 0x2000000L /* not allowed in modeline */
463#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200464 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100465#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100466#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000467
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000468#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
469
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000470/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
471 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100472#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000473# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000474#else
475# define ISP_LATIN1 (char_u *)"@,161-255"
476#endif
477
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100478/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000479#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100480 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar21020352017-06-13 17:21:04 +0200481 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) \
Bram Moolenaar3633cf52017-07-31 22:29:35 +0200482 || defined(FEAT_CONCEAL) || defined(FEAT_QUICKFIX) \
483 || defined(FEAT_TERMINAL)
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200484# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@: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,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000485#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100486# 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 +0000487#endif
488
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100489/* Default python version for pyx* commands */
490#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
491# define DEFAULT_PYTHON_VER 0
492#elif defined(FEAT_PYTHON3)
493# define DEFAULT_PYTHON_VER 3
494#elif defined(FEAT_PYTHON)
495# define DEFAULT_PYTHON_VER 2
496#else
497# define DEFAULT_PYTHON_VER 0
498#endif
499
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500/*
501 * options[] is initialized here.
502 * The order of the options MUST be alphabetic for ":set all" and findoption().
503 * All option names MUST start with a lowercase letter (for findoption()).
504 * Exception: "t_" options are at the end.
505 * The options with a NULL variable are 'hidden': a set command for them is
506 * ignored and they are not printed.
507 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100508static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200510 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511#ifdef FEAT_RIGHTLEFT
512 (char_u *)&p_aleph, PV_NONE,
513#else
514 (char_u *)NULL, PV_NONE,
515#endif
516 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100517#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000518 (char_u *)128L,
519#else
520 (char_u *)224L,
521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000522 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000523 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
524#if defined(FEAT_GUI) && defined(MACOS_X)
525 (char_u *)&p_antialias, PV_NONE,
526 {(char_u *)FALSE, (char_u *)FALSE}
527#else
528 (char_u *)NULL, PV_NONE,
529 {(char_u *)FALSE, (char_u *)FALSE}
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200532 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533#ifdef FEAT_ARABIC
534 (char_u *)VAR_WIN, PV_ARAB,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000538 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
540#ifdef FEAT_ARABIC
541 (char_u *)&p_arshape, PV_NONE,
542#else
543 (char_u *)NULL, PV_NONE,
544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000545 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
547#ifdef FEAT_RIGHTLEFT
548 (char_u *)&p_ari, PV_NONE,
549#else
550 (char_u *)NULL, PV_NONE,
551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
554#ifdef FEAT_FKMAP
555 (char_u *)&p_altkeymap, PV_NONE,
556#else
557 (char_u *)NULL, PV_NONE,
558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
561#if defined(FEAT_MBYTE)
562 (char_u *)&p_ambw, PV_NONE,
563 {(char_u *)"single", (char_u *)0L}
564#else
565 (char_u *)NULL, PV_NONE,
566 {(char_u *)0L, (char_u *)0L}
567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000568 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100570#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100572 {(char_u *)FALSE, (char_u *)0L}
573#else
574 (char_u *)NULL, PV_NONE,
575 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100577 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"autoindent", "ai", P_BOOL|P_VI_DEF,
579 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000580 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"autoprint", "ap", P_BOOL|P_VI_DEF,
582 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000585 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 {"autowrite", "aw", P_BOOL|P_VI_DEF,
588 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000589 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 {"autowriteall","awa", P_BOOL|P_VI_DEF,
591 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000592 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
594 (char_u *)&p_bg, PV_NONE,
595 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100596#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 (char_u *)"dark",
598#else
599 (char_u *)"light",
600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000601 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200602 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
606 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000607 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200608 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200609 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610#ifdef UNIX
611 {(char_u *)"yes", (char_u *)"auto"}
612#else
613 {(char_u *)"auto", (char_u *)"auto"}
614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200616 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
617 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000620 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 (char_u *)&p_bex, PV_NONE,
622 {
623#ifdef VMS
624 (char_u *)"_",
625#else
626 (char_u *)"~",
627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000628 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200629 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630#ifdef FEAT_WILDIGN
631 (char_u *)&p_bsk, PV_NONE,
632 {(char_u *)"", (char_u *)0L}
633#else
634 (char_u *)NULL, PV_NONE,
635 {(char_u *)0L, (char_u *)0L}
636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100639#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100641 {(char_u *)600L, (char_u *)0L}
642#else
643 (char_u *)NULL, PV_NONE,
644 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100646 SCRIPTID_INIT},
647 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
648#ifdef FEAT_BEVAL
649 (char_u *)&p_beval, PV_NONE,
650 {(char_u *)FALSE, (char_u *)0L}
651#else
652 (char_u *)NULL, PV_NONE,
653 {(char_u *)0L, (char_u *)0L}
654#endif
655 SCRIPTID_INIT},
656 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
657#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
658 (char_u *)&p_bexpr, PV_BEXPR,
659 {(char_u *)"", (char_u *)0L}
660#else
661 (char_u *)NULL, PV_NONE,
662 {(char_u *)0L, (char_u *)0L}
663#endif
664 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 {"beautify", "bf", P_BOOL|P_VI_DEF,
666 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200668 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
669 (char_u *)&p_bo, PV_NONE,
670 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
672 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000673 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000676 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
678#ifdef FEAT_MBYTE
679 (char_u *)&p_bomb, PV_BOMB,
680#else
681 (char_u *)NULL, PV_NONE,
682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000683 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
685#ifdef FEAT_LINEBREAK
686 (char_u *)&p_breakat, PV_NONE,
687 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
688#else
689 (char_u *)NULL, PV_NONE,
690 {(char_u *)0L, (char_u *)0L}
691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000692 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200693 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
694#ifdef FEAT_LINEBREAK
695 (char_u *)VAR_WIN, PV_BRI,
696 {(char_u *)FALSE, (char_u *)0L}
697#else
698 (char_u *)NULL, PV_NONE,
699 {(char_u *)0L, (char_u *)0L}
700#endif
701 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200702 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
703 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200704#ifdef FEAT_LINEBREAK
705 (char_u *)VAR_WIN, PV_BRIOPT,
706 {(char_u *)"", (char_u *)NULL}
707#else
708 (char_u *)NULL, PV_NONE,
709 {(char_u *)"", (char_u *)NULL}
710#endif
711 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
713#ifdef FEAT_BROWSE
714 (char_u *)&p_bsdir, PV_NONE,
715 {(char_u *)"last", (char_u *)0L}
716#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 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 (char_u *)&p_bh, PV_BH,
723 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
726 (char_u *)&p_bl, PV_BL,
727 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000728 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 (char_u *)&p_bt, PV_BT,
731 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000732 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200733 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000734#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735 (char_u *)&p_cmp, PV_NONE,
736 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000737#else
738 (char_u *)NULL, PV_NONE,
739 {(char_u *)0L, (char_u *)0L}
740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000741 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
743#ifdef FEAT_SEARCHPATH
744 (char_u *)&p_cdpath, PV_NONE,
745 {(char_u *)",,", (char_u *)0L}
746#else
747 (char_u *)NULL, PV_NONE,
748 {(char_u *)0L, (char_u *)0L}
749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000750 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 {"cedit", NULL, P_STRING,
752#ifdef FEAT_CMDWIN
753 (char_u *)&p_cedit, PV_NONE,
754 {(char_u *)"", (char_u *)CTRL_F_STR}
755#else
756 (char_u *)NULL, PV_NONE,
757 {(char_u *)0L, (char_u *)0L}
758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000759 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
761#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
762 (char_u *)&p_ccv, PV_NONE,
763 {(char_u *)"", (char_u *)0L}
764#else
765 (char_u *)NULL, PV_NONE,
766 {(char_u *)0L, (char_u *)0L}
767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000768 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
770#ifdef FEAT_CINDENT
771 (char_u *)&p_cin, PV_CIN,
772#else
773 (char_u *)NULL, PV_NONE,
774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000775 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200776 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777#ifdef FEAT_CINDENT
778 (char_u *)&p_cink, PV_CINK,
779 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
780#else
781 (char_u *)NULL, PV_NONE,
782 {(char_u *)0L, (char_u *)0L}
783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000784 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200785 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786#ifdef FEAT_CINDENT
787 (char_u *)&p_cino, PV_CINO,
788#else
789 (char_u *)NULL, PV_NONE,
790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000791 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200792 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
794 (char_u *)&p_cinw, PV_CINW,
795 {(char_u *)"if,else,while,do,for,switch",
796 (char_u *)0L}
797#else
798 (char_u *)NULL, PV_NONE,
799 {(char_u *)0L, (char_u *)0L}
800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000801 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200802 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000803#ifdef FEAT_CLIPBOARD
804 (char_u *)&p_cb, PV_NONE,
805# ifdef FEAT_XCLIPBOARD
806 {(char_u *)"autoselect,exclude:cons\\|linux",
807 (char_u *)0L}
808# else
809 {(char_u *)"", (char_u *)0L}
810# endif
811#else
812 (char_u *)NULL, PV_NONE,
813 {(char_u *)"", (char_u *)0L}
814#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000815 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000816 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
817 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000818 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
820#ifdef FEAT_CMDWIN
821 (char_u *)&p_cwh, PV_NONE,
822#else
823 (char_u *)NULL, PV_NONE,
824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000825 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200826 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200827#ifdef FEAT_SYN_HL
828 (char_u *)VAR_WIN, PV_CC,
829#else
830 (char_u *)NULL, PV_NONE,
831#endif
832 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
834 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000835 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200836 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
837 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838#ifdef FEAT_COMMENTS
839 (char_u *)&p_com, PV_COM,
840 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
841 (char_u *)0L}
842#else
843 (char_u *)NULL, PV_NONE,
844 {(char_u *)0L, (char_u *)0L}
845#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000846 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200847 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848#ifdef FEAT_FOLDING
849 (char_u *)&p_cms, PV_CMS,
850 {(char_u *)"/*%s*/", (char_u *)0L}
851#else
852 (char_u *)NULL, PV_NONE,
853 {(char_u *)0L, (char_u *)0L}
854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000855 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000856 /* P_PRI_MKRC isn't needed here, optval_default()
857 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000858 {"compatible", "cp", P_BOOL|P_RALL,
859 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000860 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200861 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000862#ifdef FEAT_INS_EXPAND
863 (char_u *)&p_cpt, PV_CPT,
864 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
865#else
866 (char_u *)NULL, PV_NONE,
867 {(char_u *)0L, (char_u *)0L}
868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000869 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200870 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200871#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200872 (char_u *)VAR_WIN, PV_COCU,
873 {(char_u *)"", (char_u *)NULL}
874#else
875 (char_u *)NULL, PV_NONE,
876 {(char_u *)NULL, (char_u *)0L}
877#endif
878 SCRIPTID_INIT},
879 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
880#ifdef FEAT_CONCEAL
881 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200882#else
883 (char_u *)NULL, PV_NONE,
884#endif
885 {(char_u *)0L, (char_u *)0L}
886 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000887 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
888#ifdef FEAT_COMPL_FUNC
889 (char_u *)&p_cfu, PV_CFU,
890 {(char_u *)"", (char_u *)0L}
891#else
892 (char_u *)NULL, PV_NONE,
893 {(char_u *)0L, (char_u *)0L}
894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000895 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200896 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000897#ifdef FEAT_INS_EXPAND
898 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000899 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000900#else
901 (char_u *)NULL, PV_NONE,
902 {(char_u *)0L, (char_u *)0L}
903#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000904 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"confirm", "cf", P_BOOL|P_VI_DEF,
906#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
907 (char_u *)&p_confirm, PV_NONE,
908#else
909 (char_u *)NULL, PV_NONE,
910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
916 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
919 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
921 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200922 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200923#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200924 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200925 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200926#else
927 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200929#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200930 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000931 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
932#ifdef FEAT_CSCOPE
933 (char_u *)&p_cspc, PV_NONE,
934#else
935 (char_u *)NULL, PV_NONE,
936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
939#ifdef FEAT_CSCOPE
940 (char_u *)&p_csprg, PV_NONE,
941 {(char_u *)"cscope", (char_u *)0L}
942#else
943 (char_u *)NULL, PV_NONE,
944 {(char_u *)0L, (char_u *)0L}
945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000946 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200947 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
949 (char_u *)&p_csqf, PV_NONE,
950 {(char_u *)"", (char_u *)0L}
951#else
952 (char_u *)NULL, PV_NONE,
953 {(char_u *)0L, (char_u *)0L}
954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000955 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200956 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
957#ifdef FEAT_CSCOPE
958 (char_u *)&p_csre, PV_NONE,
959#else
960 (char_u *)NULL, PV_NONE,
961#endif
962 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
964#ifdef FEAT_CSCOPE
965 (char_u *)&p_cst, PV_NONE,
966#else
967 (char_u *)NULL, PV_NONE,
968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000969 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000970 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
971#ifdef FEAT_CSCOPE
972 (char_u *)&p_csto, PV_NONE,
973#else
974 (char_u *)NULL, PV_NONE,
975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000976 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
978#ifdef FEAT_CSCOPE
979 (char_u *)&p_csverbose, PV_NONE,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000983 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200984 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
985#ifdef FEAT_CURSORBIND
986 (char_u *)VAR_WIN, PV_CRBIND,
987#else
988 (char_u *)NULL, PV_NONE,
989#endif
990 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000991 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
992#ifdef FEAT_SYN_HL
993 (char_u *)VAR_WIN, PV_CUC,
994#else
995 (char_u *)NULL, PV_NONE,
996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100998 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000999#ifdef FEAT_SYN_HL
1000 (char_u *)VAR_WIN, PV_CUL,
1001#else
1002 (char_u *)NULL, PV_NONE,
1003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"debug", NULL, P_STRING|P_VI_DEF,
1006 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001007 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001008 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001010 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001011 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#else
1013 (char_u *)NULL, PV_NONE,
1014 {(char_u *)NULL, (char_u *)0L}
1015#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1018#ifdef FEAT_MBYTE
1019 (char_u *)&p_deco, PV_NONE,
1020#else
1021 (char_u *)NULL, PV_NONE,
1022#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001023 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001024 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001026 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001027#else
1028 (char_u *)NULL, PV_NONE,
1029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1032#ifdef FEAT_DIFF
1033 (char_u *)VAR_WIN, PV_DIFF,
1034#else
1035 (char_u *)NULL, PV_NONE,
1036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001038 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1040 (char_u *)&p_dex, PV_NONE,
1041 {(char_u *)"", (char_u *)0L}
1042#else
1043 (char_u *)NULL, PV_NONE,
1044 {(char_u *)0L, (char_u *)0L}
1045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001046 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001047 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1048 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049#ifdef FEAT_DIFF
1050 (char_u *)&p_dip, PV_NONE,
1051 {(char_u *)"filler", (char_u *)NULL}
1052#else
1053 (char_u *)NULL, PV_NONE,
1054 {(char_u *)"", (char_u *)NULL}
1055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1058#ifdef FEAT_DIGRAPHS
1059 (char_u *)&p_dg, PV_NONE,
1060#else
1061 (char_u *)NULL, PV_NONE,
1062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001063 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001064 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1065 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001068 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001072#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 (char_u *)&p_ead, PV_NONE,
1074 {(char_u *)"both", (char_u *)0L}
1075#else
1076 (char_u *)NULL, PV_NONE,
1077 {(char_u *)NULL, (char_u *)0L}
1078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001079 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1081 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001083 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1084#if defined(FEAT_MBYTE)
1085 (char_u *)&p_emoji, PV_NONE,
1086 {(char_u *)TRUE, (char_u *)0L}
1087#else
1088 (char_u *)NULL, PV_NONE,
1089 {(char_u *)0L, (char_u *)0L}
1090#endif
1091 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001092 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093#ifdef FEAT_MBYTE
1094 (char_u *)&p_enc, PV_NONE,
1095 {(char_u *)ENC_DFLT, (char_u *)0L}
1096#else
1097 (char_u *)NULL, PV_NONE,
1098 {(char_u *)0L, (char_u *)0L}
1099#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001100 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1102 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1105 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001108 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1111 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001112 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1114#ifdef FEAT_QUICKFIX
1115 (char_u *)&p_ef, PV_NONE,
1116 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1117#else
1118 (char_u *)NULL, PV_NONE,
1119 {(char_u *)NULL, (char_u *)0L}
1120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001121 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001122 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001124 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#else
1127 (char_u *)NULL, PV_NONE,
1128 {(char_u *)NULL, (char_u *)0L}
1129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001131 {"esckeys", "ek", P_BOOL|P_VIM,
1132 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001134 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135#ifdef FEAT_AUTOCMD
1136 (char_u *)&p_ei, PV_NONE,
1137#else
1138 (char_u *)NULL, PV_NONE,
1139#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001140 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1142 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1145 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001147 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1148 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149#ifdef FEAT_MBYTE
1150 (char_u *)&p_fenc, PV_FENC,
1151 {(char_u *)"", (char_u *)0L}
1152#else
1153 (char_u *)NULL, PV_NONE,
1154 {(char_u *)0L, (char_u *)0L}
1155#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001156 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001157 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158#ifdef FEAT_MBYTE
1159 (char_u *)&p_fencs, PV_NONE,
1160 {(char_u *)"ucs-bom", (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 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1167 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001168 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001169 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001170 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1173 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001174 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1175 (char_u *)&p_fic, PV_NONE,
1176 {
1177#ifdef CASE_INSENSITIVE_FILENAME
1178 (char_u *)TRUE,
1179#else
1180 (char_u *)FALSE,
1181#endif
1182 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001183 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184#ifdef FEAT_AUTOCMD
1185 (char_u *)&p_ft, PV_FT,
1186 {(char_u *)"", (char_u *)0L}
1187#else
1188 (char_u *)NULL, PV_NONE,
1189 {(char_u *)0L, (char_u *)0L}
1190#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001192 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1194 (char_u *)&p_fcs, PV_NONE,
1195 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1196#else
1197 (char_u *)NULL, PV_NONE,
1198 {(char_u *)"", (char_u *)0L}
1199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001200 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001201 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1202 (char_u *)&p_fixeol, PV_FIXEOL,
1203 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1205#ifdef FEAT_FKMAP
1206 (char_u *)&p_fkmap, PV_NONE,
1207#else
1208 (char_u *)NULL, PV_NONE,
1209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001210 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"flash", "fl", P_BOOL|P_VI_DEF,
1212 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001214 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001215#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001217 {(char_u *)"", (char_u *)0L}
1218#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)NULL, PV_NONE,
1220 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221#endif
1222 SCRIPTID_INIT},
1223 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1224#ifdef FEAT_FOLDING
1225 (char_u *)VAR_WIN, PV_FDC,
1226 {(char_u *)FALSE, (char_u *)0L}
1227#else
1228 (char_u *)NULL, PV_NONE,
1229 {(char_u *)NULL, (char_u *)0L}
1230#endif
1231 SCRIPTID_INIT},
1232 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1233#ifdef FEAT_FOLDING
1234 (char_u *)VAR_WIN, PV_FEN,
1235 {(char_u *)TRUE, (char_u *)0L}
1236#else
1237 (char_u *)NULL, PV_NONE,
1238 {(char_u *)NULL, (char_u *)0L}
1239#endif
1240 SCRIPTID_INIT},
1241 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1242#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1243 (char_u *)VAR_WIN, PV_FDE,
1244 {(char_u *)"0", (char_u *)NULL}
1245#else
1246 (char_u *)NULL, PV_NONE,
1247 {(char_u *)NULL, (char_u *)0L}
1248#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001249 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001251#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253 {(char_u *)"#", (char_u *)NULL}
1254#else
1255 (char_u *)NULL, PV_NONE,
1256 {(char_u *)NULL, (char_u *)0L}
1257#endif
1258 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001260#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001262 {(char_u *)0L, (char_u *)0L}
1263#else
1264 (char_u *)NULL, PV_NONE,
1265 {(char_u *)NULL, (char_u *)0L}
1266#endif
1267 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001268 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001269#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001270 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001271 {(char_u *)-1L, (char_u *)0L}
1272#else
1273 (char_u *)NULL, PV_NONE,
1274 {(char_u *)NULL, (char_u *)0L}
1275#endif
1276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001277 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001278 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001279#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001282#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283 (char_u *)NULL, PV_NONE,
1284 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001285#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001286 SCRIPTID_INIT},
1287 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1288#ifdef FEAT_FOLDING
1289 (char_u *)VAR_WIN, PV_FDM,
1290 {(char_u *)"manual", (char_u *)NULL}
1291#else
1292 (char_u *)NULL, PV_NONE,
1293 {(char_u *)NULL, (char_u *)0L}
1294#endif
1295 SCRIPTID_INIT},
1296 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1297#ifdef FEAT_FOLDING
1298 (char_u *)VAR_WIN, PV_FML,
1299 {(char_u *)1L, (char_u *)0L}
1300#else
1301 (char_u *)NULL, PV_NONE,
1302 {(char_u *)NULL, (char_u *)0L}
1303#endif
1304 SCRIPTID_INIT},
1305 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1306#ifdef FEAT_FOLDING
1307 (char_u *)VAR_WIN, PV_FDN,
1308 {(char_u *)20L, (char_u *)0L}
1309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
1313 SCRIPTID_INIT},
1314 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1315#ifdef FEAT_FOLDING
1316 (char_u *)&p_fdo, PV_NONE,
1317 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1318 (char_u *)0L}
1319#else
1320 (char_u *)NULL, PV_NONE,
1321 {(char_u *)NULL, (char_u *)0L}
1322#endif
1323 SCRIPTID_INIT},
1324 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1325#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1326 (char_u *)VAR_WIN, PV_FDT,
1327 {(char_u *)"foldtext()", (char_u *)NULL}
1328#else
1329 (char_u *)NULL, PV_NONE,
1330 {(char_u *)NULL, (char_u *)0L}
1331#endif
1332 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001333 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001334#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001335 (char_u *)&p_fex, PV_FEX,
1336 {(char_u *)"", (char_u *)0L}
1337#else
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)0L, (char_u *)0L}
1340#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001341 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1343 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1345 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001346 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1347 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1349 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001351 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001352 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001353 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1354#ifdef HAVE_FSYNC
1355 (char_u *)&p_fs, PV_NONE,
1356 {(char_u *)TRUE, (char_u *)0L}
1357#else
1358 (char_u *)NULL, PV_NONE,
1359 {(char_u *)FALSE, (char_u *)0L}
1360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001361 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1363 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"graphic", "gr", P_BOOL|P_VI_DEF,
1366 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001368 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369#ifdef FEAT_QUICKFIX
1370 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372#else
1373 (char_u *)NULL, PV_NONE,
1374 {(char_u *)NULL, (char_u *)0L}
1375#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001376 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1378#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001379 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {
1381# ifdef WIN3264
1382 /* may be changed to "grep -n" in os_win32.c */
1383 (char_u *)"findstr /n",
1384# else
1385# ifdef UNIX
1386 /* Add an extra file name so that grep will always
1387 * insert a file name in the match line. */
1388 (char_u *)"grep -n $* /dev/null",
1389# else
1390# ifdef VMS
1391 (char_u *)"SEARCH/NUMBERS ",
1392# else
1393 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001394# endif
1395# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001403 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404#ifdef CURSOR_SHAPE
1405 (char_u *)&p_guicursor, PV_NONE,
1406 {
1407# ifdef FEAT_GUI
1408 (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",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001409# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1411# endif
1412 (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)NULL, (char_u *)0L}
1416#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001418 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419#ifdef FEAT_GUI
1420 (char_u *)&p_guifont, PV_NONE,
1421 {(char_u *)"", (char_u *)0L}
1422#else
1423 (char_u *)NULL, PV_NONE,
1424 {(char_u *)NULL, (char_u *)0L}
1425#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001427 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1429 (char_u *)&p_guifontset, PV_NONE,
1430 {(char_u *)"", (char_u *)0L}
1431#else
1432 (char_u *)NULL, PV_NONE,
1433 {(char_u *)NULL, (char_u *)0L}
1434#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001436 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1438 (char_u *)&p_guifontwide, PV_NONE,
1439 {(char_u *)"", (char_u *)0L}
1440#else
1441 (char_u *)NULL, PV_NONE,
1442 {(char_u *)NULL, (char_u *)0L}
1443#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001444 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001446#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 (char_u *)&p_ghr, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001453#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454 (char_u *)&p_go, PV_NONE,
1455# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001456 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001458 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459# endif
1460#else
1461 (char_u *)NULL, PV_NONE,
1462 {(char_u *)NULL, (char_u *)0L}
1463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"guipty", NULL, P_BOOL|P_VI_DEF,
1466#if defined(FEAT_GUI)
1467 (char_u *)&p_guipty, PV_NONE,
1468#else
1469 (char_u *)NULL, PV_NONE,
1470#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001471 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001472 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001473#if defined(FEAT_GUI_TABLINE)
1474 (char_u *)&p_gtl, PV_NONE,
1475 {(char_u *)"", (char_u *)0L}
1476#else
1477 (char_u *)NULL, PV_NONE,
1478 {(char_u *)NULL, (char_u *)0L}
1479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001480 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001481 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001482#if defined(FEAT_GUI_TABLINE)
1483 (char_u *)&p_gtt, PV_NONE,
1484 {(char_u *)"", (char_u *)0L}
1485#else
1486 (char_u *)NULL, PV_NONE,
1487 {(char_u *)NULL, (char_u *)0L}
1488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001489 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1491 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1494 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001495 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1496 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001497 {"helpheight", "hh", P_NUM|P_VI_DEF,
1498#ifdef FEAT_WINDOWS
1499 (char_u *)&p_hh, PV_NONE,
1500#else
1501 (char_u *)NULL, PV_NONE,
1502#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001503 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001504 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001505#ifdef FEAT_MULTI_LANG
1506 (char_u *)&p_hlg, PV_NONE,
1507 {(char_u *)"", (char_u *)0L}
1508#else
1509 (char_u *)NULL, PV_NONE,
1510 {(char_u *)0L, (char_u *)0L}
1511#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001512 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 {"hidden", "hid", P_BOOL|P_VI_DEF,
1514 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001516 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1519 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"history", "hi", P_NUM|P_VIM,
1521 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001522 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1524#ifdef FEAT_RIGHTLEFT
1525 (char_u *)&p_hkmap, PV_NONE,
1526#else
1527 (char_u *)NULL, PV_NONE,
1528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001529 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1531#ifdef FEAT_RIGHTLEFT
1532 (char_u *)&p_hkmapp, PV_NONE,
1533#else
1534 (char_u *)NULL, PV_NONE,
1535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1538 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"icon", NULL, P_BOOL|P_VI_DEF,
1541#ifdef FEAT_TITLE
1542 (char_u *)&p_icon, PV_NONE,
1543#else
1544 (char_u *)NULL, PV_NONE,
1545#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001546 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 {"iconstring", NULL, P_STRING|P_VI_DEF,
1548#ifdef FEAT_TITLE
1549 (char_u *)&p_iconstring, PV_NONE,
1550#else
1551 (char_u *)NULL, PV_NONE,
1552#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001553 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1555 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001557 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1558# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1559 (char_u *)&p_imaf, PV_NONE,
1560 {(char_u *)"", (char_u *)NULL}
1561# else
1562 (char_u *)NULL, PV_NONE,
1563 {(char_u *)NULL, (char_u *)0L}
1564# endif
1565 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001567#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568 (char_u *)&p_imak, PV_NONE,
1569#else
1570 (char_u *)NULL, PV_NONE,
1571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001572 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001573 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1574#ifdef USE_IM_CONTROL
1575 (char_u *)&p_imcmdline, PV_NONE,
1576#else
1577 (char_u *)NULL, PV_NONE,
1578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1581#ifdef USE_IM_CONTROL
1582 (char_u *)&p_imdisable, PV_NONE,
1583#else
1584 (char_u *)NULL, PV_NONE,
1585#endif
1586#ifdef __sgi
1587 {(char_u *)TRUE, (char_u *)0L}
1588#else
1589 {(char_u *)FALSE, (char_u *)0L}
1590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001592 {"iminsert", "imi", P_NUM|P_VI_DEF,
1593 (char_u *)&p_iminsert, PV_IMI,
1594#ifdef B_IMODE_IM
1595 {(char_u *)B_IMODE_IM, (char_u *)0L}
1596#else
1597 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001599 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 {"imsearch", "ims", P_NUM|P_VI_DEF,
1601 (char_u *)&p_imsearch, PV_IMS,
1602#ifdef B_IMODE_IM
1603 {(char_u *)B_IMODE_IM, (char_u *)0L}
1604#else
1605 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1606#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001607 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001608 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001609#if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001610 (char_u *)&p_imsf, PV_NONE,
1611 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001612#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001613 (char_u *)NULL, PV_NONE,
1614 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001615#endif
1616 SCRIPTID_INIT},
1617 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1618#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1619 (char_u *)&p_imst, PV_NONE,
1620 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1621#else
1622 (char_u *)NULL, PV_NONE,
1623 {(char_u *)0L, (char_u *)0L}
1624#endif
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001625 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1627#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001628 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1630#else
1631 (char_u *)NULL, PV_NONE,
1632 {(char_u *)0L, (char_u *)0L}
1633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001634 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001635 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1636#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1637 (char_u *)&p_inex, PV_INEX,
1638 {(char_u *)"", (char_u *)0L}
1639#else
1640 (char_u *)NULL, PV_NONE,
1641 {(char_u *)0L, (char_u *)0L}
1642#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1645 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1648#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1649 (char_u *)&p_inde, PV_INDE,
1650 {(char_u *)"", (char_u *)0L}
1651#else
1652 (char_u *)NULL, PV_NONE,
1653 {(char_u *)0L, (char_u *)0L}
1654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001655 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001656 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1658 (char_u *)&p_indk, PV_INDK,
1659 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1660#else
1661 (char_u *)NULL, PV_NONE,
1662 {(char_u *)0L, (char_u *)0L}
1663#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"infercase", "inf", P_BOOL|P_VI_DEF,
1666 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1669 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001670 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1672 (char_u *)&p_isf, PV_NONE,
1673 {
1674#ifdef BACKSLASH_IN_FILENAME
1675 /* Excluded are: & and ^ are special in cmd.exe
1676 * ( and ) are used in text separating fnames */
1677 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1678#else
1679# ifdef AMIGA
1680 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1681# else
1682# ifdef VMS
1683 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1684# else /* UNIX et al. */
1685# ifdef EBCDIC
1686 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1687# else
1688 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1689# endif
1690# endif
1691# endif
1692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001693 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1695 (char_u *)&p_isi, PV_NONE,
1696 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001697#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698 (char_u *)"@,48-57,_,128-167,224-235",
1699#else
1700# ifdef EBCDIC
1701 /* TODO: EBCDIC Check this! @ == isalpha()*/
1702 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1703 "112-120,128,140-142,156,158,172,"
1704 "174,186,191,203-207,219-225,235-239,"
1705 "251-254",
1706# else
1707 (char_u *)"@,48-57,_,192-255",
1708# endif
1709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001710 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1712 (char_u *)&p_isk, PV_ISK,
1713 {
1714#ifdef EBCDIC
1715 (char_u *)"@,240-249,_",
1716 /* TODO: EBCDIC Check this! @ == isalpha()*/
1717 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1718 "112-120,128,140-142,156,158,172,"
1719 "174,186,191,203-207,219-225,235-239,"
1720 "251-254",
1721#else
1722 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001723# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724 (char_u *)"@,48-57,_,128-167,224-235"
1725# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001726 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727# endif
1728#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001729 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1731 (char_u *)&p_isp, PV_NONE,
1732 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001733#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 || defined(VMS)
1735 (char_u *)"@,~-255",
1736#else
1737# ifdef EBCDIC
1738 /* all chars above 63 are printable */
1739 (char_u *)"63-255",
1740# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001741 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742# endif
1743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001744 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1746 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001747 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1749#ifdef FEAT_CRYPT
1750 (char_u *)&p_key, PV_KEY,
1751 {(char_u *)"", (char_u *)0L}
1752#else
1753 (char_u *)NULL, PV_NONE,
1754 {(char_u *)0L, (char_u *)0L}
1755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001756 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001757 {"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 +00001758#ifdef FEAT_KEYMAP
1759 (char_u *)&p_keymap, PV_KMAP,
1760 {(char_u *)"", (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 Moolenaar0e7c4b92015-06-20 15:30:03 +02001766 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001770 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001772#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 (char_u *)":help",
1774#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001775# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001777# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001778# ifdef USEMAN_S
1779 (char_u *)"man -s",
1780# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001782# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783# endif
1784#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001786 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787#ifdef FEAT_LANGMAP
1788 (char_u *)&p_langmap, PV_NONE,
1789 {(char_u *)"", /* unmatched } */
1790#else
1791 (char_u *)NULL, PV_NONE,
1792 {(char_u *)NULL,
1793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001795 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1797 (char_u *)&p_lm, PV_NONE,
1798#else
1799 (char_u *)NULL, PV_NONE,
1800#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001801 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001802 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1803#ifdef FEAT_LANGMAP
1804 (char_u *)&p_lnr, PV_NONE,
1805#else
1806 (char_u *)NULL, PV_NONE,
1807#endif
1808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001809 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1810#ifdef FEAT_LANGMAP
1811 (char_u *)&p_lrm, PV_NONE,
1812#else
1813 (char_u *)NULL, PV_NONE,
1814#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001815 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1817#ifdef FEAT_WINDOWS
1818 (char_u *)&p_ls, PV_NONE,
1819#else
1820 (char_u *)NULL, PV_NONE,
1821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1824 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001825 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1827#ifdef FEAT_LINEBREAK
1828 (char_u *)VAR_WIN, PV_LBR,
1829#else
1830 (char_u *)NULL, PV_NONE,
1831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001832 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001833 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1834 (char_u *)&Rows, PV_NONE,
1835 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001836#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001837 (char_u *)25L,
1838#else
1839 (char_u *)24L,
1840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1843#ifdef FEAT_GUI
1844 (char_u *)&p_linespace, PV_NONE,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
1848#ifdef FEAT_GUI_W32
1849 {(char_u *)1L, (char_u *)0L}
1850#else
1851 {(char_u *)0L, (char_u *)0L}
1852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001853 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001854 {"lisp", NULL, P_BOOL|P_VI_DEF,
1855#ifdef FEAT_LISP
1856 (char_u *)&p_lisp, PV_LISP,
1857#else
1858 (char_u *)NULL, PV_NONE,
1859#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001861 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001863 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1865#else
1866 (char_u *)NULL, PV_NONE,
1867 {(char_u *)"", (char_u *)0L}
1868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1871 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001873 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1877 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001878 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001879 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001880#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001881 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001882 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001883#else
1884 (char_u *)NULL, PV_NONE,
1885 {(char_u *)"", (char_u *)0L}
1886#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001887 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001888 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001889#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001890 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001891 {(char_u *)TRUE, (char_u *)0L}
1892#else
1893 (char_u *)NULL, PV_NONE,
1894 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001895#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001896 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"magic", NULL, P_BOOL|P_VI_DEF,
1898 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001899 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001900 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901#ifdef FEAT_QUICKFIX
1902 (char_u *)&p_mef, PV_NONE,
1903 {(char_u *)"", (char_u *)0L}
1904#else
1905 (char_u *)NULL, PV_NONE,
1906 {(char_u *)NULL, (char_u *)0L}
1907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001909 {"makeencoding","menc", P_STRING|P_VI_DEF,
1910#ifdef FEAT_MBYTE
1911 (char_u *)&p_menc, PV_MENC,
1912 {(char_u *)"", (char_u *)0L}
1913#else
1914 (char_u *)NULL, PV_NONE,
1915 {(char_u *)0L, (char_u *)0L}
1916#endif
1917 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1919#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001920 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921# ifdef VMS
1922 {(char_u *)"MMS", (char_u *)0L}
1923# else
1924 {(char_u *)"make", (char_u *)0L}
1925# endif
1926#else
1927 (char_u *)NULL, PV_NONE,
1928 {(char_u *)NULL, (char_u *)0L}
1929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001931 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001933 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1934 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"matchtime", "mat", P_NUM|P_VI_DEF,
1936 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001937 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001938 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001939#ifdef FEAT_MBYTE
1940 (char_u *)&p_mco, PV_NONE,
1941#else
1942 (char_u *)NULL, PV_NONE,
1943#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1946#ifdef FEAT_EVAL
1947 (char_u *)&p_mfd, PV_NONE,
1948#else
1949 (char_u *)NULL, PV_NONE,
1950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1953 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001955 {"maxmem", "mm", P_NUM|P_VI_DEF,
1956 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001957 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1958 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001959 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1960 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1963 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001964 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1965 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 {"menuitems", "mis", P_NUM|P_VI_DEF,
1967#ifdef FEAT_MENU
1968 (char_u *)&p_mis, PV_NONE,
1969#else
1970 (char_u *)NULL, PV_NONE,
1971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"mesg", NULL, P_BOOL|P_VI_DEF,
1974 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001976 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001977#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001978 (char_u *)&p_msm, PV_NONE,
1979 {(char_u *)"460000,2000,500", (char_u *)0L}
1980#else
1981 (char_u *)NULL, PV_NONE,
1982 {(char_u *)0L, (char_u *)0L}
1983#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"modeline", "ml", P_BOOL|P_VIM,
1986 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"modelines", "mls", P_NUM|P_VI_DEF,
1989 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1992 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1995 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {"more", NULL, P_BOOL|P_VIM,
1998 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001999 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002000 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
2001 (char_u *)&p_mouse, PV_NONE,
2002 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002003#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004 (char_u *)"a",
2005#else
2006 (char_u *)"",
2007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002008 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
2010#ifdef FEAT_GUI
2011 (char_u *)&p_mousef, PV_NONE,
2012#else
2013 (char_u *)NULL, PV_NONE,
2014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002015 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2017#ifdef FEAT_GUI
2018 (char_u *)&p_mh, PV_NONE,
2019#else
2020 (char_u *)NULL, PV_NONE,
2021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2024 (char_u *)&p_mousem, PV_NONE,
2025 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002026#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 (char_u *)"popup",
2028#else
2029# if defined(MACOS)
2030 (char_u *)"popup_setpos",
2031# else
2032 (char_u *)"extend",
2033# endif
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002036 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037#ifdef FEAT_MOUSESHAPE
2038 (char_u *)&p_mouseshape, PV_NONE,
2039 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2040#else
2041 (char_u *)NULL, PV_NONE,
2042 {(char_u *)NULL, (char_u *)0L}
2043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2046 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002047 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002048 {"mzquantum", "mzq", P_NUM,
2049#ifdef FEAT_MZSCHEME
2050 (char_u *)&p_mzq, PV_NONE,
2051#else
2052 (char_u *)NULL, PV_NONE,
2053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 {"novice", NULL, P_BOOL|P_VI_DEF,
2056 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002057 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002058 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002060 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2063 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002064 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002065 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2066#ifdef FEAT_LINEBREAK
2067 (char_u *)VAR_WIN, PV_NUW,
2068#else
2069 (char_u *)NULL, PV_NONE,
2070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002071 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002072 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002073#ifdef FEAT_COMPL_FUNC
2074 (char_u *)&p_ofu, PV_OFU,
2075 {(char_u *)"", (char_u *)0L}
2076#else
2077 (char_u *)NULL, PV_NONE,
2078 {(char_u *)0L, (char_u *)0L}
2079#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 {"open", NULL, P_BOOL|P_VI_DEF,
2082 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002084 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002085#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002086 (char_u *)&p_odev, PV_NONE,
2087#else
2088 (char_u *)NULL, PV_NONE,
2089#endif
2090 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002092 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2093 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002094 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"optimize", "opt", P_BOOL|P_VI_DEF,
2096 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002100 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002101 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2102 |P_SECURE,
2103 (char_u *)&p_pp, PV_NONE,
2104 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2105 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 {"paragraphs", "para", P_STRING|P_VI_DEF,
2107 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002108 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002109 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002110 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2114 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002115 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2117#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2118 (char_u *)&p_pex, PV_NONE,
2119 {(char_u *)"", (char_u *)0L}
2120#else
2121 (char_u *)NULL, PV_NONE,
2122 {(char_u *)0L, (char_u *)0L}
2123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002125 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002127 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002129 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002131#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 (char_u *)".,,",
2133#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002136 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002137 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002138#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002139 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002140 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002141#else
2142 (char_u *)NULL, PV_NONE,
2143 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002144#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002145 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2147 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002149 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002150#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2151 (char_u *)&p_pvh, PV_NONE,
2152#else
2153 (char_u *)NULL, PV_NONE,
2154#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002155 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2157#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2158 (char_u *)VAR_WIN, PV_PVW,
2159#else
2160 (char_u *)NULL, PV_NONE,
2161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002162 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002163 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002164#ifdef FEAT_PRINTER
2165 (char_u *)&p_pdev, PV_NONE,
2166 {(char_u *)"", (char_u *)0L}
2167#else
2168 (char_u *)NULL, PV_NONE,
2169 {(char_u *)NULL, (char_u *)0L}
2170#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002171 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 {"printencoding", "penc", P_STRING|P_VI_DEF,
2173#ifdef FEAT_POSTSCRIPT
2174 (char_u *)&p_penc, PV_NONE,
2175 {(char_u *)"", (char_u *)0L}
2176#else
2177 (char_u *)NULL, PV_NONE,
2178 {(char_u *)NULL, (char_u *)0L}
2179#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002180 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002181 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182#ifdef FEAT_POSTSCRIPT
2183 (char_u *)&p_pexpr, PV_NONE,
2184 {(char_u *)"", (char_u *)0L}
2185#else
2186 (char_u *)NULL, PV_NONE,
2187 {(char_u *)NULL, (char_u *)0L}
2188#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002189 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 {"printfont", "pfn", P_STRING|P_VI_DEF,
2191#ifdef FEAT_PRINTER
2192 (char_u *)&p_pfn, PV_NONE,
2193 {
2194# ifdef MSWIN
2195 (char_u *)"Courier_New:h10",
2196# else
2197 (char_u *)"courier",
2198# endif
2199 (char_u *)0L}
2200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
2203#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2206#ifdef FEAT_PRINTER
2207 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002208 /* untranslated to avoid problems when 'encoding'
2209 * is changed */
2210 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002211#else
2212 (char_u *)NULL, PV_NONE,
2213 {(char_u *)NULL, (char_u *)0L}
2214#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002215 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002216 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2217#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2218 (char_u *)&p_pmcs, PV_NONE,
2219 {(char_u *)"", (char_u *)0L}
2220#else
2221 (char_u *)NULL, PV_NONE,
2222 {(char_u *)NULL, (char_u *)0L}
2223#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002224 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002225 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2226#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2227 (char_u *)&p_pmfn, PV_NONE,
2228 {(char_u *)"", (char_u *)0L}
2229#else
2230 (char_u *)NULL, PV_NONE,
2231 {(char_u *)NULL, (char_u *)0L}
2232#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002234 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002235#ifdef FEAT_PRINTER
2236 (char_u *)&p_popt, PV_NONE,
2237 {(char_u *)"", (char_u *)0L}
2238#else
2239 (char_u *)NULL, PV_NONE,
2240 {(char_u *)NULL, (char_u *)0L}
2241#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002242 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002244 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002245 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002246 {"pumheight", "ph", P_NUM|P_VI_DEF,
2247#ifdef FEAT_INS_EXPAND
2248 (char_u *)&p_ph, PV_NONE,
2249#else
2250 (char_u *)NULL, PV_NONE,
2251#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002252 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002253 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002254#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002255 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002256 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002257#else
2258 (char_u *)NULL, PV_NONE,
2259 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002260#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002261 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002262 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002263#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002264 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002265 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002266#else
2267 (char_u *)NULL, PV_NONE,
2268 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002269#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002270 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002271 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2272#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2273 (char_u *)&p_pyx, PV_NONE,
2274#else
2275 (char_u *)NULL, PV_NONE,
2276#endif
2277 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2278 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002279 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2280#ifdef FEAT_TEXTOBJ
2281 (char_u *)&p_qe, PV_QE,
2282 {(char_u *)"\\", (char_u *)0L}
2283#else
2284 (char_u *)NULL, PV_NONE,
2285 {(char_u *)NULL, (char_u *)0L}
2286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2289 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002291 {"redraw", NULL, P_BOOL|P_VI_DEF,
2292 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002293 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002294 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2295#ifdef FEAT_RELTIME
2296 (char_u *)&p_rdt, PV_NONE,
2297#else
2298 (char_u *)NULL, PV_NONE,
2299#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002300 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002301 {"regexpengine", "re", P_NUM|P_VI_DEF,
2302 (char_u *)&p_re, PV_NONE,
2303 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002304 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2305 (char_u *)VAR_WIN, PV_RNU,
2306 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 {"remap", NULL, P_BOOL|P_VI_DEF,
2308 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002310 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002311#ifdef FEAT_RENDER_OPTIONS
2312 (char_u *)&p_rop, PV_NONE,
2313 {(char_u *)"", (char_u *)0L}
2314#else
2315 (char_u *)NULL, PV_NONE,
2316 {(char_u *)NULL, (char_u *)0L}
2317#endif
2318 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 {"report", NULL, P_NUM|P_VI_DEF,
2320 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002321 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2323#ifdef WIN3264
2324 (char_u *)&p_rs, PV_NONE,
2325#else
2326 (char_u *)NULL, PV_NONE,
2327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2330#ifdef FEAT_RIGHTLEFT
2331 (char_u *)&p_ri, PV_NONE,
2332#else
2333 (char_u *)NULL, PV_NONE,
2334#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2337#ifdef FEAT_RIGHTLEFT
2338 (char_u *)VAR_WIN, PV_RL,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2344#ifdef FEAT_RIGHTLEFT
2345 (char_u *)VAR_WIN, PV_RLC,
2346 {(char_u *)"search", (char_u *)NULL}
2347#else
2348 (char_u *)NULL, PV_NONE,
2349 {(char_u *)NULL, (char_u *)0L}
2350#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002352 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002353#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002354 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002355 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002356#else
2357 (char_u *)NULL, PV_NONE,
2358 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002359#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002360 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2362#ifdef FEAT_CMDL_INFO
2363 (char_u *)&p_ru, PV_NONE,
2364#else
2365 (char_u *)NULL, PV_NONE,
2366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2369#ifdef FEAT_STL_OPT
2370 (char_u *)&p_ruf, PV_NONE,
2371#else
2372 (char_u *)NULL, PV_NONE,
2373#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002374 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002375 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2376 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2379 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2381 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002382 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2384#ifdef FEAT_SCROLLBIND
2385 (char_u *)VAR_WIN, PV_SCBIND,
2386#else
2387 (char_u *)NULL, PV_NONE,
2388#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002389 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2391 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2394 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002396 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397#ifdef FEAT_SCROLLBIND
2398 (char_u *)&p_sbo, PV_NONE,
2399 {(char_u *)"ver,jump", (char_u *)0L}
2400#else
2401 (char_u *)NULL, PV_NONE,
2402 {(char_u *)0L, (char_u *)0L}
2403#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002404 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 {"sections", "sect", P_STRING|P_VI_DEF,
2406 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002407 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2408 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2410 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002411 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002414 {(char_u *)"inclusive", (char_u *)0L}
2415 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002416 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002418 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002419 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420#ifdef FEAT_SESSION
2421 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002422 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 (char_u *)0L}
2424#else
2425 (char_u *)NULL, PV_NONE,
2426 {(char_u *)0L, (char_u *)0L}
2427#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2430 (char_u *)&p_sh, PV_NONE,
2431 {
2432#ifdef VMS
2433 (char_u *)"-",
2434#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002435# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002437# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439# endif
2440#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2443 (char_u *)&p_shcf, PV_NONE,
2444 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002445#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 (char_u *)"/c",
2447#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2452#ifdef FEAT_QUICKFIX
2453 (char_u *)&p_sp, PV_NONE,
2454 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002455#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457#else
2458 (char_u *)">",
2459#endif
2460 (char_u *)0L}
2461#else
2462 (char_u *)NULL, PV_NONE,
2463 {(char_u *)0L, (char_u *)0L}
2464#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002465 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002466 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2467 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002468 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2470 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002471 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002472 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2473#ifdef BACKSLASH_IN_FILENAME
2474 (char_u *)&p_ssl, PV_NONE,
2475#else
2476 (char_u *)NULL, PV_NONE,
2477#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002478 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002479 {"shelltemp", "stmp", P_BOOL,
2480 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002481 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002482 {"shelltype", "st", P_NUM|P_VI_DEF,
2483#ifdef AMIGA
2484 (char_u *)&p_st, PV_NONE,
2485#else
2486 (char_u *)NULL, PV_NONE,
2487#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002488 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2490 (char_u *)&p_sxq, PV_NONE,
2491 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002492#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 (char_u *)"\"",
2494#else
2495 (char_u *)"",
2496#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002498 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2499 (char_u *)&p_sxe, PV_NONE,
2500 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002501#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002502 (char_u *)"\"&|<>()@^",
2503#else
2504 (char_u *)"",
2505#endif
2506 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2508 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002509 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2511 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002512 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2514 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)"", (char_u *)"filnxtToO"}
2516 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002519 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2521#ifdef FEAT_LINEBREAK
2522 (char_u *)&p_sbr, PV_NONE,
2523#else
2524 (char_u *)NULL, PV_NONE,
2525#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002526 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"showcmd", "sc", P_BOOL|P_VIM,
2528#ifdef FEAT_CMDL_INFO
2529 (char_u *)&p_sc, PV_NONE,
2530#else
2531 (char_u *)NULL, PV_NONE,
2532#endif
2533 {(char_u *)FALSE,
2534#ifdef UNIX
2535 (char_u *)FALSE
2536#else
2537 (char_u *)TRUE
2538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002539 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002540 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2541 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2544 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 {"showmode", "smd", P_BOOL|P_VIM,
2547 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002548 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002549 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2550#ifdef FEAT_WINDOWS
2551 (char_u *)&p_stal, PV_NONE,
2552#else
2553 (char_u *)NULL, PV_NONE,
2554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002555 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2557 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2560 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002562 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2563#ifdef FEAT_SIGNS
2564 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002565 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002566#else
2567 (char_u *)NULL, PV_NONE,
2568 {(char_u *)NULL, (char_u *)0L}
2569#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2572 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2575 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2578#ifdef FEAT_SMARTINDENT
2579 (char_u *)&p_si, PV_SI,
2580#else
2581 (char_u *)NULL, PV_NONE,
2582#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2585 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002586 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2588 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002589 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2591 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002592 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002593 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002594#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002595 (char_u *)VAR_WIN, PV_SPELL,
2596#else
2597 (char_u *)NULL, PV_NONE,
2598#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002599 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002600 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002601#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002602 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002603 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002604#else
2605 (char_u *)NULL, PV_NONE,
2606 {(char_u *)0L, (char_u *)0L}
2607#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002608 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002609 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2610 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002611#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002612 (char_u *)&p_spf, PV_SPF,
2613 {(char_u *)"", (char_u *)0L}
2614#else
2615 (char_u *)NULL, PV_NONE,
2616 {(char_u *)0L, (char_u *)0L}
2617#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002619 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2620 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002621#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002622 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002623 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002624#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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002629 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002630#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002631 (char_u *)&p_sps, PV_NONE,
2632 {(char_u *)"best", (char_u *)0L}
2633#else
2634 (char_u *)NULL, PV_NONE,
2635 {(char_u *)0L, (char_u *)0L}
2636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2639#ifdef FEAT_WINDOWS
2640 (char_u *)&p_sb, PV_NONE,
2641#else
2642 (char_u *)NULL, PV_NONE,
2643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002645 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002646#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 (char_u *)&p_spr, PV_NONE,
2648#else
2649 (char_u *)NULL, PV_NONE,
2650#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2653 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002654 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2656#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002657 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658#else
2659 (char_u *)NULL, PV_NONE,
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002662 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 (char_u *)&p_su, PV_NONE,
2664 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002666 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002667#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 (char_u *)&p_sua, PV_SUA,
2669 {(char_u *)"", (char_u *)0L}
2670#else
2671 (char_u *)NULL, PV_NONE,
2672 {(char_u *)0L, (char_u *)0L}
2673#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002674 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2676 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"swapsync", "sws", P_STRING|P_VI_DEF,
2679 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002681 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002684 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2685#ifdef FEAT_SYN_HL
2686 (char_u *)&p_smc, PV_SMC,
2687 {(char_u *)3000L, (char_u *)0L}
2688#else
2689 (char_u *)NULL, PV_NONE,
2690 {(char_u *)0L, (char_u *)0L}
2691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002692 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002693 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694#ifdef FEAT_SYN_HL
2695 (char_u *)&p_syn, PV_SYN,
2696 {(char_u *)"", (char_u *)0L}
2697#else
2698 (char_u *)NULL, PV_NONE,
2699 {(char_u *)0L, (char_u *)0L}
2700#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002702 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2703#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002704 (char_u *)&p_tal, PV_NONE,
2705#else
2706 (char_u *)NULL, PV_NONE,
2707#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002708 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002709 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2710#ifdef FEAT_WINDOWS
2711 (char_u *)&p_tpm, PV_NONE,
2712#else
2713 (char_u *)NULL, PV_NONE,
2714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2717 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2720 (char_u *)&p_tbs, PV_NONE,
2721#ifdef VMS /* binary searching doesn't appear to work on VMS */
2722 {(char_u *)0L, (char_u *)0L}
2723#else
2724 {(char_u *)TRUE, (char_u *)0L}
2725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002726 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002727 {"tagcase", "tc", P_STRING|P_VIM,
2728 (char_u *)&p_tc, PV_TC,
2729 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002730 {"taglength", "tl", P_NUM|P_VI_DEF,
2731 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"tagrelative", "tr", P_BOOL|P_VIM,
2734 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002736 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002737 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {
2739#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2740 (char_u *)"./tags,./TAGS,tags,TAGS",
2741#else
2742 (char_u *)"./tags,tags",
2743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2746 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002748 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002749#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002750 (char_u *)&p_tcldll, PV_NONE,
2751 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002752#else
2753 (char_u *)NULL, PV_NONE,
2754 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002755#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002756 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2758 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002759 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2761#ifdef FEAT_ARABIC
2762 (char_u *)&p_tbidi, PV_NONE,
2763#else
2764 (char_u *)NULL, PV_NONE,
2765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2768#ifdef FEAT_MBYTE
2769 (char_u *)&p_tenc, PV_NONE,
2770 {(char_u *)"", (char_u *)0L}
2771#else
2772 (char_u *)NULL, PV_NONE,
2773 {(char_u *)0L, (char_u *)0L}
2774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002775 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002776 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2777#ifdef FEAT_TERMGUICOLORS
2778 (char_u *)&p_tgc, PV_NONE,
2779 {(char_u *)FALSE, (char_u *)FALSE}
2780#else
2781 (char_u*)NULL, PV_NONE,
2782 {(char_u *)FALSE, (char_u *)FALSE}
2783#endif
2784 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002785 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2786#ifdef FEAT_TERMINAL
2787 (char_u *)VAR_WIN, PV_TK,
Bram Moolenaar1f28b4c2017-07-28 13:48:34 +02002788 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002789#else
2790 (char_u *)NULL, PV_NONE,
2791 {(char_u *)NULL, (char_u *)0L}
2792#endif
2793 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002794 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2795#ifdef FEAT_TERMINAL
2796 (char_u *)VAR_WIN, PV_TMS,
2797 {(char_u *)"", (char_u *)NULL}
2798#else
2799 (char_u *)NULL, PV_NONE,
2800 {(char_u *)NULL, (char_u *)0L}
2801#endif
2802 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"terse", NULL, P_BOOL|P_VI_DEF,
2804 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"textauto", "ta", P_BOOL|P_VIM,
2807 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2809 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2811 (char_u *)&p_tx, PV_TX,
2812 {
2813#ifdef USE_CRNL
2814 (char_u *)TRUE,
2815#else
2816 (char_u *)FALSE,
2817#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002819 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002822 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002824 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825#else
2826 (char_u *)NULL, PV_NONE,
2827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2830 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002831 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"timeout", "to", P_BOOL|P_VI_DEF,
2833 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2836 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"title", NULL, P_BOOL|P_VI_DEF,
2839#ifdef FEAT_TITLE
2840 (char_u *)&p_title, PV_NONE,
2841#else
2842 (char_u *)NULL, PV_NONE,
2843#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002844 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 {"titlelen", NULL, P_NUM|P_VI_DEF,
2846#ifdef FEAT_TITLE
2847 (char_u *)&p_titlelen, PV_NONE,
2848#else
2849 (char_u *)NULL, PV_NONE,
2850#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002851 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002852 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853#ifdef FEAT_TITLE
2854 (char_u *)&p_titleold, PV_NONE,
2855 {(char_u *)N_("Thanks for flying Vim"),
2856 (char_u *)0L}
2857#else
2858 (char_u *)NULL, PV_NONE,
2859 {(char_u *)0L, (char_u *)0L}
2860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002861 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862 {"titlestring", NULL, P_STRING|P_VI_DEF,
2863#ifdef FEAT_TITLE
2864 (char_u *)&p_titlestring, PV_NONE,
2865#else
2866 (char_u *)NULL, PV_NONE,
2867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002868 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002869 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002870#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002873#else
2874 (char_u *)NULL, PV_NONE,
2875 {(char_u *)0L, (char_u *)0L}
2876#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002877 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002879#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002881 {(char_u *)"small", (char_u *)0L}
2882#else
2883 (char_u *)NULL, PV_NONE,
2884 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002886 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2888 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002889 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2891 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002892 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2894 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002895 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2897 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002898 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002899 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2900#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2901 (char_u *)&p_ttym, PV_NONE,
2902#else
2903 (char_u *)NULL, PV_NONE,
2904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002905 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2907 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002908 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2910 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002911 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002912 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2913 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002914#ifdef FEAT_PERSISTENT_UNDO
2915 (char_u *)&p_udir, PV_NONE,
2916 {(char_u *)".", (char_u *)0L}
2917#else
2918 (char_u *)NULL, PV_NONE,
2919 {(char_u *)0L, (char_u *)0L}
2920#endif
2921 SCRIPTID_INIT},
2922 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2923#ifdef FEAT_PERSISTENT_UNDO
2924 (char_u *)&p_udf, PV_UDF,
2925#else
2926 (char_u *)NULL, PV_NONE,
2927#endif
2928 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002930 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002932#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002933 (char_u *)1000L,
2934#else
2935 (char_u *)100L,
2936#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002937 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002938 {"undoreload", "ur", P_NUM|P_VI_DEF,
2939 (char_u *)&p_ur, PV_NONE,
2940 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 {"updatecount", "uc", P_NUM|P_VI_DEF,
2942 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002943 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 {"updatetime", "ut", P_NUM|P_VI_DEF,
2945 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002946 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947 {"verbose", "vbs", P_NUM|P_VI_DEF,
2948 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002949 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002950 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2951 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002952 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2954#ifdef FEAT_SESSION
2955 (char_u *)&p_vdir, PV_NONE,
2956 {(char_u *)DFLT_VDIR, (char_u *)0L}
2957#else
2958 (char_u *)NULL, PV_NONE,
2959 {(char_u *)0L, (char_u *)0L}
2960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002961 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002962 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963#ifdef FEAT_SESSION
2964 (char_u *)&p_vop, PV_NONE,
2965 {(char_u *)"folds,options,cursor", (char_u *)0L}
2966#else
2967 (char_u *)NULL, PV_NONE,
2968 {(char_u *)0L, (char_u *)0L}
2969#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002970 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002971 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972#ifdef FEAT_VIMINFO
2973 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002974#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002975 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976#else
2977# ifdef AMIGA
2978 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002979 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002981 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982# endif
2983#endif
2984#else
2985 (char_u *)NULL, PV_NONE,
2986 {(char_u *)0L, (char_u *)0L}
2987#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002988 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002989 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2990#ifdef FEAT_VIMINFO
2991 (char_u *)&p_viminfofile, PV_NONE,
2992 {(char_u *)"", (char_u *)0L}
2993#else
2994 (char_u *)NULL, PV_NONE,
2995 {(char_u *)0L, (char_u *)0L}
2996#endif
2997 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002998 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2999 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003000#ifdef FEAT_VIRTUALEDIT
3001 (char_u *)&p_ve, PV_NONE,
3002 {(char_u *)"", (char_u *)""}
3003#else
3004 (char_u *)NULL, PV_NONE,
3005 {(char_u *)0L, (char_u *)0L}
3006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003007 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 {"visualbell", "vb", P_BOOL|P_VI_DEF,
3009 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 {"w300", NULL, P_NUM|P_VI_DEF,
3012 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003013 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 {"w1200", NULL, P_NUM|P_VI_DEF,
3015 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003016 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 {"w9600", NULL, P_NUM|P_VI_DEF,
3018 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003019 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 {"warn", NULL, P_BOOL|P_VI_DEF,
3021 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003022 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3024 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003025 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003026 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003028 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"wildchar", "wc", P_NUM|P_VIM,
3030 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003031 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3032 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003033 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003035 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003036 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037#ifdef FEAT_WILDIGN
3038 (char_u *)&p_wig, PV_NONE,
3039#else
3040 (char_u *)NULL, PV_NONE,
3041#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003042 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003043 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3044 (char_u *)&p_wic, PV_NONE,
3045 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3047#ifdef FEAT_WILDMENU
3048 (char_u *)&p_wmnu, PV_NONE,
3049#else
3050 (char_u *)NULL, PV_NONE,
3051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003052 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003053 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003055 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003056 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3057#ifdef FEAT_CMDL_COMPL
3058 (char_u *)&p_wop, PV_NONE,
3059 {(char_u *)"", (char_u *)0L}
3060#else
3061 (char_u *)NULL, PV_NONE,
3062 {(char_u *)NULL, (char_u *)0L}
3063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003064 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3066#ifdef FEAT_WAK
3067 (char_u *)&p_wak, PV_NONE,
3068 {(char_u *)"menu", (char_u *)0L}
3069#else
3070 (char_u *)NULL, PV_NONE,
3071 {(char_u *)NULL, (char_u *)0L}
3072#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003073 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003075 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003076 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 {"winheight", "wh", P_NUM|P_VI_DEF,
3078#ifdef FEAT_WINDOWS
3079 (char_u *)&p_wh, PV_NONE,
3080#else
3081 (char_u *)NULL, PV_NONE,
3082#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003083 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003085#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 (char_u *)VAR_WIN, PV_WFH,
3087#else
3088 (char_u *)NULL, PV_NONE,
3089#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003090 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003091 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003092#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003093 (char_u *)VAR_WIN, PV_WFW,
3094#else
3095 (char_u *)NULL, PV_NONE,
3096#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098 {"winminheight", "wmh", P_NUM|P_VI_DEF,
3099#ifdef FEAT_WINDOWS
3100 (char_u *)&p_wmh, PV_NONE,
3101#else
3102 (char_u *)NULL, PV_NONE,
3103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003104 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003106#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 (char_u *)&p_wmw, PV_NONE,
3108#else
3109 (char_u *)NULL, PV_NONE,
3110#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003111 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003112 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003113#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003114 (char_u *)&p_winptydll, PV_NONE, {
3115# ifdef _WIN64
3116 (char_u *)"winpty64.dll",
3117# else
3118 (char_u *)"winpty32.dll",
3119# endif
3120 (char_u *)0L}
3121#else
3122 (char_u *)NULL, PV_NONE,
3123 {(char_u *)0L, (char_u *)0L}
3124#endif
3125 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003127#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 (char_u *)&p_wiw, PV_NONE,
3129#else
3130 (char_u *)NULL, PV_NONE,
3131#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003132 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3134 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003135 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3137 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003138 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3140 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003141 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 {"write", NULL, P_BOOL|P_VI_DEF,
3143 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003144 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145 {"writeany", "wa", P_BOOL|P_VI_DEF,
3146 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003147 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3149 (char_u *)&p_wb, PV_NONE,
3150 {
3151#ifdef FEAT_WRITEBACKUP
3152 (char_u *)TRUE,
3153#else
3154 (char_u *)FALSE,
3155#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003156 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 {"writedelay", "wd", P_NUM|P_VI_DEF,
3158 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003159 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160
3161/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003162#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003164 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165
3166 p_term("t_AB", T_CAB)
3167 p_term("t_AF", T_CAF)
3168 p_term("t_AL", T_CAL)
3169 p_term("t_al", T_AL)
3170 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003171 p_term("t_BE", T_BE)
3172 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 p_term("t_cd", T_CD)
3174 p_term("t_ce", T_CE)
3175 p_term("t_cl", T_CL)
3176 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003177 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178 p_term("t_Co", T_CCO)
3179 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003180 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003182#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 p_term("t_CV", T_CSV)
3184#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_da", T_DA)
3186 p_term("t_db", T_DB)
3187 p_term("t_DL", T_CDL)
3188 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003189 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003190 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003192 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193 p_term("t_IE", T_CIE)
3194 p_term("t_IS", T_CIS)
3195 p_term("t_ke", T_KE)
3196 p_term("t_ks", T_KS)
3197 p_term("t_le", T_LE)
3198 p_term("t_mb", T_MB)
3199 p_term("t_md", T_MD)
3200 p_term("t_me", T_ME)
3201 p_term("t_mr", T_MR)
3202 p_term("t_ms", T_MS)
3203 p_term("t_nd", T_ND)
3204 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003205 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003206 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207 p_term("t_RI", T_CRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003208 p_term("t_RS", T_CRS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209 p_term("t_RV", T_CRV)
3210 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003211 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003213 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003214 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003215 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003217 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218 p_term("t_sr", T_SR)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003219 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220 p_term("t_te", T_TE)
3221 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003222 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003223 p_term("t_ts", T_TS)
3224 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225 p_term("t_ue", T_UE)
3226 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003227 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 p_term("t_vb", T_VB)
3229 p_term("t_ve", T_VE)
3230 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003231 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232 p_term("t_vs", T_VS)
3233 p_term("t_WP", T_CWP)
3234 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003235 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 p_term("t_xs", T_XS)
3237 p_term("t_ZH", T_CZH)
3238 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003239 p_term("t_8f", T_8F)
3240 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003241
3242/* terminal key codes are not in here */
3243
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003244 /* end marker */
3245 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246};
3247
3248#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3249
3250#ifdef FEAT_MBYTE
3251static char *(p_ambw_values[]) = {"single", "double", NULL};
3252#endif
3253static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003254static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003256#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003257static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003258#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003259#ifdef FEAT_CMDL_COMPL
3260static char *(p_wop_values[]) = {"tagfile", NULL};
3261#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262#ifdef FEAT_WAK
3263static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3264#endif
3265static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3267static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003268static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003269#ifdef FEAT_BROWSE
3270static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3271#endif
3272#ifdef FEAT_SCROLLBIND
3273static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3274#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003275static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003276#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3278#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003279#ifdef FEAT_AUTOCMD
3280static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3281#else
3282static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003284static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3286#ifdef FEAT_FOLDING
3287static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003288# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003290# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291 NULL};
3292static char *(p_fcl_values[]) = {"all", NULL};
3293#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003294#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003295static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003296#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003297#ifdef FEAT_SIGNS
3298static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3299#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003301static void set_option_default(int, int opt_flags, int compatible);
3302static void set_options_default(int opt_flags);
3303static char_u *term_bg_default(void);
3304static void did_set_option(int opt_idx, int opt_flags, int new_value);
3305static char_u *illegal_char(char_u *, int);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003307static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308#endif
3309#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003310static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static char_u *option_expand(int opt_idx, char_u *val);
3313static void didset_options(void);
3314static void didset_options2(void);
3315static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003316#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003317static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003318#else
3319# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3320#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003321static void set_string_option_global(int opt_idx, char_u **varp);
3322static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3323static 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);
3324static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003325#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003326static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003327#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003329static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003331#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003332static char_u *did_set_spell_option(int is_spellfile);
3333static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003334#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003335#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003336static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003337#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003338static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3339static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3340static void check_redraw(long_u flags);
3341static int findoption(char_u *);
3342static int find_key_option(char_u *);
3343static void showoptions(int all, int opt_flags);
3344static int optval_default(struct vimoption *, char_u *varp);
3345static void showoneopt(struct vimoption *, int opt_flags);
3346static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3347static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3348static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3349static int istermoption(struct vimoption *);
3350static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3351static char_u *get_varp(struct vimoption *);
3352static void option_value2string(struct vimoption *, int opt_flags);
3353static void check_winopt(winopt_T *wop);
3354static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003356static void langmap_init(void);
3357static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003359static void paste_option_changed(void);
3360static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003362static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003364static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3365static int check_opt_strings(char_u *val, char **values, int);
3366static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003367#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003368static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003369#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003370
3371/*
3372 * Initialize the options, first part.
3373 *
3374 * Called only once from main(), just after creating the first buffer.
3375 */
3376 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003377set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378{
3379 char_u *p;
3380 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003381 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382
3383#ifdef FEAT_LANGMAP
3384 langmap_init();
3385#endif
3386
3387 /* Be Vi compatible by default */
3388 p_cp = TRUE;
3389
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003390 /* Use POSIX compatibility when $VIM_POSIX is set. */
3391 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003392 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003393 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003394 set_string_default("shm", (char_u *)"A");
3395 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003396
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397 /*
3398 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003399 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003401 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003402#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003403 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003405 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406# endif
3407#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003408 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409 set_string_default("sh", p);
3410
3411#ifdef FEAT_WILDIGN
3412 /*
3413 * Set the default for 'backupskip' to include environment variables for
3414 * temp files.
3415 */
3416 {
3417# ifdef UNIX
3418 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3419# else
3420 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3421# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003422 int len;
3423 garray_T ga;
3424 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003425
3426 ga_init2(&ga, 1, 100);
3427 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3428 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003429 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430# ifdef UNIX
3431 if (*names[n] == NUL)
3432 p = (char_u *)"/tmp";
3433 else
3434# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003435 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003436 if (p != NULL && *p != NUL)
3437 {
3438 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003439 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440 if (ga_grow(&ga, len) == OK)
3441 {
3442 if (ga.ga_len > 0)
3443 STRCAT(ga.ga_data, ",");
3444 STRCAT(ga.ga_data, p);
3445 add_pathsep(ga.ga_data);
3446 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447 ga.ga_len += len;
3448 }
3449 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003450 if (mustfree)
3451 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452 }
3453 if (ga.ga_data != NULL)
3454 {
3455 set_string_default("bsk", ga.ga_data);
3456 vim_free(ga.ga_data);
3457 }
3458 }
3459#endif
3460
3461 /*
3462 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3463 */
3464 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003465 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003467#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3468 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3469#endif
3470 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003472 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003473 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003474#else
3475# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003476 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003477 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003479 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480# endif
3481#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003482 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003483 opt_idx = findoption((char_u *)"maxmem");
3484 if (opt_idx >= 0)
3485 {
3486#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003487 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3488 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003489#endif
3490 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3491 }
3492 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003493 }
3494
Bram Moolenaar071d4272004-06-13 20:20:40 +00003495#ifdef FEAT_SEARCHPATH
3496 {
3497 char_u *cdpath;
3498 char_u *buf;
3499 int i;
3500 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003501 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502
3503 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003504 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505 if (cdpath != NULL)
3506 {
3507 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3508 if (buf != NULL)
3509 {
3510 buf[0] = ','; /* start with ",", current dir first */
3511 j = 1;
3512 for (i = 0; cdpath[i] != NUL; ++i)
3513 {
3514 if (vim_ispathlistsep(cdpath[i]))
3515 buf[j++] = ',';
3516 else
3517 {
3518 if (cdpath[i] == ' ' || cdpath[i] == ',')
3519 buf[j++] = '\\';
3520 buf[j++] = cdpath[i];
3521 }
3522 }
3523 buf[j] = NUL;
3524 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003525 if (opt_idx >= 0)
3526 {
3527 options[opt_idx].def_val[VI_DEFAULT] = buf;
3528 options[opt_idx].flags |= P_DEF_ALLOCED;
3529 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003530 else
3531 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003532 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003533 if (mustfree)
3534 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003535 }
3536 }
3537#endif
3538
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003539#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540 /* Set print encoding on platforms that don't default to latin1 */
3541 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003542# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003543 (char_u *)"cp1252"
3544# else
3545# ifdef VMS
3546 (char_u *)"dec-mcs"
3547# else
3548# ifdef EBCDIC
3549 (char_u *)"ebcdic-uk"
3550# else
3551# ifdef MAC
3552 (char_u *)"mac-roman"
3553# else /* HPUX */
3554 (char_u *)"hp-roman8"
3555# endif
3556# endif
3557# endif
3558# endif
3559 );
3560#endif
3561
3562#ifdef FEAT_POSTSCRIPT
3563 /* 'printexpr' must be allocated to be able to evaluate it. */
3564 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003565# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003566 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003567# else
3568# ifdef VMS
3569 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3570
3571# else
3572 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3573# endif
3574# endif
3575 );
3576#endif
3577
3578 /*
3579 * Set all the options (except the terminal options) to their default
3580 * value. Also set the global value for local options.
3581 */
3582 set_options_default(0);
3583
3584#ifdef FEAT_GUI
3585 if (found_reverse_arg)
3586 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3587#endif
3588
3589 curbuf->b_p_initialized = TRUE;
3590 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003591 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592 check_buf_options(curbuf);
3593 check_win_options(curwin);
3594 check_options();
3595
3596 /* Must be before option_expand(), because that one needs vim_isIDc() */
3597 didset_options();
3598
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003599#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003600 /* Use the current chartab for the generic chartab. This is not in
3601 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003602 init_spell_chartab();
3603#endif
3604
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605 /*
3606 * Expand environment variables and things like "~" for the defaults.
3607 * If option_expand() returns non-NULL the variable is expanded. This can
3608 * only happen for non-indirect options.
3609 * Also set the default to the expanded value, so ":set" does not list
3610 * them.
3611 * Don't set the P_ALLOCED flag, because we don't want to free the
3612 * default.
3613 */
3614 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3615 {
3616 if ((options[opt_idx].flags & P_GETTEXT)
3617 && options[opt_idx].var != NULL)
3618 p = (char_u *)_(*(char **)options[opt_idx].var);
3619 else
3620 p = option_expand(opt_idx, NULL);
3621 if (p != NULL && (p = vim_strsave(p)) != NULL)
3622 {
3623 *(char_u **)options[opt_idx].var = p;
3624 /* VIMEXP
3625 * Defaults for all expanded options are currently the same for Vi
3626 * and Vim. When this changes, add some code here! Also need to
3627 * split P_DEF_ALLOCED in two.
3628 */
3629 if (options[opt_idx].flags & P_DEF_ALLOCED)
3630 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3631 options[opt_idx].def_val[VI_DEFAULT] = p;
3632 options[opt_idx].flags |= P_DEF_ALLOCED;
3633 }
3634 }
3635
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636 save_file_ff(curbuf); /* Buffer is unchanged */
3637
Bram Moolenaar071d4272004-06-13 20:20:40 +00003638#if defined(FEAT_ARABIC)
3639 /* Detect use of mlterm.
3640 * Mlterm is a terminal emulator akin to xterm that has some special
3641 * abilities (bidi namely).
3642 * NOTE: mlterm's author is being asked to 'set' a variable
3643 * instead of an environment variable due to inheritance.
3644 */
3645 if (mch_getenv((char_u *)"MLTERM") != NULL)
3646 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3647#endif
3648
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003649 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650
3651#ifdef FEAT_MBYTE
3652# if defined(WIN3264) && defined(FEAT_GETTEXT)
3653 /*
3654 * If $LANG isn't set, try to get a good value for it. This makes the
3655 * right language be used automatically. Don't do this for English.
3656 */
3657 if (mch_getenv((char_u *)"LANG") == NULL)
3658 {
3659 char buf[20];
3660
3661 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3662 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3663 * only the first two. */
3664 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3665 (LPTSTR)buf, 20);
3666 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3667 {
3668 /* There are a few exceptions (probably more) */
3669 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3670 STRCPY(buf, "zh_TW");
3671 else if (STRNICMP(buf, "chs", 3) == 0
3672 || STRNICMP(buf, "zhc", 3) == 0)
3673 STRCPY(buf, "zh_CN");
3674 else if (STRNICMP(buf, "jp", 2) == 0)
3675 STRCPY(buf, "ja");
3676 else
3677 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003678 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003679 }
3680 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003681# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003682# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003683 /* Moved to os_mac_conv.c to avoid dependency problems. */
3684 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003685# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686# endif
3687
3688 /* enc_locale() will try to find the encoding of the current locale. */
3689 p = enc_locale();
3690 if (p != NULL)
3691 {
3692 char_u *save_enc;
3693
3694 /* Try setting 'encoding' and check if the value is valid.
3695 * If not, go back to the default "latin1". */
3696 save_enc = p_enc;
3697 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003698 if (STRCMP(p_enc, "gb18030") == 0)
3699 {
3700 /* We don't support "gb18030", but "cp936" is a good substitute
3701 * for practical purposes, thus use that. It's not an alias to
3702 * still support conversion between gb18030 and utf-8. */
3703 p_enc = vim_strsave((char_u *)"cp936");
3704 vim_free(p);
3705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706 if (mb_init() == NULL)
3707 {
3708 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003709 if (opt_idx >= 0)
3710 {
3711 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3712 options[opt_idx].flags |= P_DEF_ALLOCED;
3713 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003714
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003715#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003716 if (STRCMP(p_enc, "latin1") == 0
3717# ifdef FEAT_MBYTE
3718 || enc_utf8
3719# endif
3720 )
3721 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003722 /* Adjust the default for 'isprint' and 'iskeyword' to match
3723 * latin1. Also set the defaults for when 'nocompatible' is
3724 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003725 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003726 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003727 set_string_option_direct((char_u *)"isk", -1,
3728 ISK_LATIN1, OPT_FREE, SID_NONE);
3729 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003730 if (opt_idx >= 0)
3731 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003732 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003733 if (opt_idx >= 0)
3734 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003735 (void)init_chartab();
3736 }
3737#endif
3738
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739# if defined(WIN3264) && !defined(FEAT_GUI)
3740 /* Win32 console: When GetACP() returns a different value from
3741 * GetConsoleCP() set 'termencoding'. */
3742 if (GetACP() != GetConsoleCP())
3743 {
3744 char buf[50];
3745
3746 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3747 p_tenc = vim_strsave((char_u *)buf);
3748 if (p_tenc != NULL)
3749 {
3750 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003751 if (opt_idx >= 0)
3752 {
3753 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3754 options[opt_idx].flags |= P_DEF_ALLOCED;
3755 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756 convert_setup(&input_conv, p_tenc, p_enc);
3757 convert_setup(&output_conv, p_enc, p_tenc);
3758 }
3759 else
3760 p_tenc = empty_option;
3761 }
3762# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003763# if defined(WIN3264) && defined(FEAT_MBYTE)
3764 /* $HOME may have characters in active code page. */
3765 init_homedir();
3766# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003767 }
3768 else
3769 {
3770 vim_free(p_enc);
3771 p_enc = save_enc;
3772 }
3773 }
3774#endif
3775
3776#ifdef FEAT_MULTI_LANG
3777 /* Set the default for 'helplang'. */
3778 set_helplang_default(get_mess_lang());
3779#endif
3780}
3781
3782/*
3783 * Set an option to its default value.
3784 * This does not take care of side effects!
3785 */
3786 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003787set_option_default(
3788 int opt_idx,
3789 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3790 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003791{
3792 char_u *varp; /* pointer to variable for current option */
3793 int dvi; /* index in def_val[] */
3794 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003795 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003796 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3797
3798 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3799 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003800 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 {
3802 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3803 if (flags & P_STRING)
3804 {
3805 /* Use set_string_option_direct() for local options to handle
3806 * freeing and allocating the value. */
3807 if (options[opt_idx].indir != PV_NONE)
3808 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003809 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 else
3811 {
3812 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3813 free_string_option(*(char_u **)(varp));
3814 *(char_u **)varp = options[opt_idx].def_val[dvi];
3815 options[opt_idx].flags &= ~P_ALLOCED;
3816 }
3817 }
3818 else if (flags & P_NUM)
3819 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003820 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821 win_comp_scroll(curwin);
3822 else
3823 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003824 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 /* May also set global value for local option. */
3826 if (both)
3827 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3828 *(long *)varp;
3829 }
3830 }
3831 else /* P_BOOL */
3832 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003833 /* the cast to long is required for Manx C, long_i is needed for
3834 * MSVC */
3835 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003836#ifdef UNIX
3837 /* 'modeline' defaults to off for root */
3838 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3839 *(int *)varp = FALSE;
3840#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841 /* May also set global value for local option. */
3842 if (both)
3843 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3844 *(int *)varp;
3845 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003846
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003847 /* The default value is not insecure. */
3848 flagsp = insecure_flag(opt_idx, opt_flags);
3849 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850 }
3851
3852#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003853 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854#endif
3855}
3856
3857/*
3858 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003859 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003860 */
3861 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003862set_options_default(
3863 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864{
3865 int i;
3866#ifdef FEAT_WINDOWS
3867 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003868 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869#endif
3870
3871 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003872 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003873#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003874 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003875 || (TRUE
3876# if defined(FEAT_MBYTE)
3877 && options[i].var != (char_u *)&p_enc
3878# endif
3879# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003880 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003881 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003882# endif
3883 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003884#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003885 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003886 set_option_default(i, opt_flags, p_cp);
3887
3888#ifdef FEAT_WINDOWS
3889 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003890 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891 win_comp_scroll(wp);
3892#else
3893 win_comp_scroll(curwin);
3894#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003895#ifdef FEAT_CINDENT
3896 parse_cino(curbuf);
3897#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898}
3899
3900/*
3901 * Set the Vi-default value of a string option.
3902 * Used for 'sh', 'backupskip' and 'term'.
3903 */
3904 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003905set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003906{
3907 char_u *p;
3908 int opt_idx;
3909
3910 p = vim_strsave(val);
3911 if (p != NULL) /* we don't want a NULL */
3912 {
3913 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003914 if (opt_idx >= 0)
3915 {
3916 if (options[opt_idx].flags & P_DEF_ALLOCED)
3917 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3918 options[opt_idx].def_val[VI_DEFAULT] = p;
3919 options[opt_idx].flags |= P_DEF_ALLOCED;
3920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003921 }
3922}
3923
3924/*
3925 * Set the Vi-default value of a number option.
3926 * Used for 'lines' and 'columns'.
3927 */
3928 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003929set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003931 int opt_idx;
3932
3933 opt_idx = findoption((char_u *)name);
3934 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003935 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003936}
3937
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003938#if defined(EXITFREE) || defined(PROTO)
3939/*
3940 * Free all options.
3941 */
3942 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003943free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003944{
3945 int i;
3946
3947 for (i = 0; !istermoption(&options[i]); i++)
3948 {
3949 if (options[i].indir == PV_NONE)
3950 {
3951 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003952 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003953 free_string_option(*(char_u **)options[i].var);
3954 if (options[i].flags & P_DEF_ALLOCED)
3955 free_string_option(options[i].def_val[VI_DEFAULT]);
3956 }
3957 else if (options[i].var != VAR_WIN
3958 && (options[i].flags & P_STRING))
3959 /* buffer-local option: free global value */
3960 free_string_option(*(char_u **)options[i].var);
3961 }
3962}
3963#endif
3964
3965
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966/*
3967 * Initialize the options, part two: After getting Rows and Columns and
3968 * setting 'term'.
3969 */
3970 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003971set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003973 int idx;
3974
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 /*
3976 * 'scroll' defaults to half the window height. Note that this default is
3977 * wrong when the window height changes.
3978 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003979 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003980 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003981 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003982 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003983 comp_col();
3984
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003985 /*
3986 * 'window' is only for backwards compatibility with Vi.
3987 * Default is Rows - 1.
3988 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003989 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003990 p_window = Rows - 1;
3991 set_number_default("window", Rows - 1);
3992
Bram Moolenaarf740b292006-02-16 22:11:02 +00003993 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003994#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003995 /*
3996 * If 'background' wasn't set by the user, try guessing the value,
3997 * depending on the terminal name. Only need to check for terminals
3998 * with a dark background, that can handle color.
3999 */
4000 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004001 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
4002 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004004 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004005 /* don't mark it as set, when starting the GUI it may be
4006 * changed again */
4007 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004008 }
4009#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004010
4011#ifdef CURSOR_SHAPE
4012 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4013#endif
4014#ifdef FEAT_MOUSESHAPE
4015 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4016#endif
4017#ifdef FEAT_PRINTER
4018 (void)parse_printoptions(); /* parse 'printoptions' default value */
4019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020}
4021
4022/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004023 * Return "dark" or "light" depending on the kind of terminal.
4024 * This is just guessing! Recognized are:
4025 * "linux" Linux console
4026 * "screen.linux" Linux console with screen
4027 * "cygwin" Cygwin shell
4028 * "putty" Putty program
4029 * We also check the COLORFGBG environment variable, which is set by
4030 * rxvt and derivatives. This variable contains either two or three
4031 * values separated by semicolons; we want the last value in either
4032 * case. If this value is 0-6 or 8, our background is dark.
4033 */
4034 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004035term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004036{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004037#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004038 /* DOS console nearly always black */
4039 return (char_u *)"dark";
4040#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004041 char_u *p;
4042
Bram Moolenaarf740b292006-02-16 22:11:02 +00004043 if (STRCMP(T_NAME, "linux") == 0
4044 || STRCMP(T_NAME, "screen.linux") == 0
4045 || STRCMP(T_NAME, "cygwin") == 0
4046 || STRCMP(T_NAME, "putty") == 0
4047 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4048 && (p = vim_strrchr(p, ';')) != NULL
4049 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4050 && p[2] == NUL))
4051 return (char_u *)"dark";
4052 return (char_u *)"light";
4053#endif
4054}
4055
4056/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 * Initialize the options, part three: After reading the .vimrc
4058 */
4059 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004060set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004062#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063/*
4064 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4065 * This is done after other initializations, where 'shell' might have been
4066 * set, but only if they have not been set before.
4067 */
4068 char_u *p;
4069 int idx_srr;
4070 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004071# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 int idx_sp;
4073 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004074# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004075
4076 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004077 if (idx_srr < 0)
4078 do_srr = FALSE;
4079 else
4080 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004081# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004083 if (idx_sp < 0)
4084 do_sp = FALSE;
4085 else
4086 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004087# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004088 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 if (p != NULL)
4090 {
4091 /*
4092 * Default for p_sp is "| tee", for p_srr is ">".
4093 * For known shells it is changed here to include stderr.
4094 */
4095 if ( fnamecmp(p, "csh") == 0
4096 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004097# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 || fnamecmp(p, "csh.exe") == 0
4099 || fnamecmp(p, "tcsh.exe") == 0
4100# endif
4101 )
4102 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004103# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 if (do_sp)
4105 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004106# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004108# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004110# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4112 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004113# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 if (do_srr)
4115 {
4116 p_srr = (char_u *)">&";
4117 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4118 }
4119 }
4120 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004121 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 if ( fnamecmp(p, "sh") == 0
4123 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004124 || fnamecmp(p, "mksh") == 0
4125 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004127 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004129 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004130# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 || fnamecmp(p, "cmd") == 0
4132 || fnamecmp(p, "sh.exe") == 0
4133 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004134 || fnamecmp(p, "mksh.exe") == 0
4135 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004137 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 || fnamecmp(p, "bash.exe") == 0
4139 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004141 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004142 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004143# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 if (do_sp)
4145 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004146# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004148# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004149 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004150# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4152 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004153# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 if (do_srr)
4155 {
4156 p_srr = (char_u *)">%s 2>&1";
4157 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4158 }
4159 }
4160 vim_free(p);
4161 }
4162#endif
4163
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004164#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004166 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4167 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004168 * This is done after other initializations, where 'shell' might have been
4169 * set, but only if they have not been set before. Default for p_shcf is
4170 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004171 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004173 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 {
4175 int idx3;
4176
4177 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004178 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 {
4180 p_shcf = (char_u *)"-c";
4181 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4182 }
4183
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184 /* Somehow Win32 requires the quotes around the redirection too */
4185 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004186 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 {
4188 p_sxq = (char_u *)"\"";
4189 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4190 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004192 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4193 {
4194 int idx3;
4195
4196 /*
4197 * cmd.exe on Windows will strip the first and last double quote given
4198 * on the command line, e.g. most of the time things like:
4199 * cmd /c "my path/to/echo" "my args to echo"
4200 * become:
4201 * my path/to/echo" "my args to echo
4202 * when executed.
4203 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004204 * To avoid this, set shellxquote to surround the command in
4205 * parenthesis. This appears to make most commands work, without
4206 * breaking commands that worked previously, such as
4207 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004208 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004209 idx3 = findoption((char_u *)"sxq");
4210 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4211 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004212 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004213 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4214 }
4215
Bram Moolenaara64ba222012-02-12 23:23:31 +01004216 idx3 = findoption((char_u *)"shcf");
4217 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4218 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004219 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004220 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4221 }
4222 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004223#endif
4224
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004225 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004226 {
4227 int idx_ffs = findoption((char_u *)"ffs");
4228
4229 /* Apply the first entry of 'fileformats' to the initial buffer. */
4230 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4231 set_fileformat(default_fileformat(), OPT_LOCAL);
4232 }
4233
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234#ifdef FEAT_TITLE
4235 set_title_defaults();
4236#endif
4237}
4238
4239#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4240/*
4241 * When 'helplang' is still at its default value, set it to "lang".
4242 * Only the first two characters of "lang" are used.
4243 */
4244 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004245set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246{
4247 int idx;
4248
4249 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4250 return;
4251 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004252 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004253 {
4254 if (options[idx].flags & P_ALLOCED)
4255 free_string_option(p_hlg);
4256 p_hlg = vim_strsave(lang);
4257 if (p_hlg == NULL)
4258 p_hlg = empty_option;
4259 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004260 {
4261 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4262 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4263 {
4264 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4265 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4266 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004267 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004268 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004269 options[idx].flags |= P_ALLOCED;
4270 }
4271}
4272#endif
4273
4274#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004275static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004276
4277 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004278gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279{
4280 if (gui_get_lightness(gui.back_pixel) < 127)
4281 return (char_u *)"dark";
4282 return (char_u *)"light";
4283}
4284
4285/*
4286 * Option initializations that can only be done after opening the GUI window.
4287 */
4288 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004289init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004290{
4291 /* Set the 'background' option according to the lightness of the
4292 * background color, unless the user has set it already. */
4293 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4294 {
4295 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4296 highlight_changed();
4297 }
4298}
4299#endif
4300
4301#ifdef FEAT_TITLE
4302/*
4303 * 'title' and 'icon' only default to true if they have not been set or reset
4304 * in .vimrc and we can read the old value.
4305 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4306 * they can be reset. This reduces startup time when using X on a remote
4307 * machine.
4308 */
4309 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004310set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311{
4312 int idx1;
4313 long val;
4314
4315 /*
4316 * If GUI is (going to be) used, we can always set the window title and
4317 * icon name. Saves a bit of time, because the X11 display server does
4318 * not need to be contacted.
4319 */
4320 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004321 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004322 {
4323#ifdef FEAT_GUI
4324 if (gui.starting || gui.in_use)
4325 val = TRUE;
4326 else
4327#endif
4328 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004329 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004330 p_title = val;
4331 }
4332 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004333 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334 {
4335#ifdef FEAT_GUI
4336 if (gui.starting || gui.in_use)
4337 val = TRUE;
4338 else
4339#endif
4340 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004341 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004342 p_icon = val;
4343 }
4344}
4345#endif
4346
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004347#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4348 static void
4349trigger_optionsset_string(
4350 int opt_idx,
4351 int opt_flags,
4352 char_u *oldval,
4353 char_u *newval)
4354{
4355 if (oldval != NULL && newval != NULL)
4356 {
4357 char_u buf_type[7];
4358
4359 sprintf((char *)buf_type, "%s",
4360 (opt_flags & OPT_LOCAL) ? "local" : "global");
4361 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4362 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4363 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4364 apply_autocmds(EVENT_OPTIONSET,
4365 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4366 reset_v_option_vars();
4367 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004368}
4369#endif
4370
Bram Moolenaar071d4272004-06-13 20:20:40 +00004371/*
4372 * Parse 'arg' for option settings.
4373 *
4374 * 'arg' may be IObuff, but only when no errors can be present and option
4375 * does not need to be expanded with option_expand().
4376 * "opt_flags":
4377 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004378 * OPT_GLOBAL for ":setglobal"
4379 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004380 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004381 * OPT_WINONLY to only set window-local options
4382 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383 *
4384 * returns FAIL if an error is detected, OK otherwise
4385 */
4386 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004387do_set(
4388 char_u *arg, /* option string (may be written to!) */
4389 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004390{
4391 int opt_idx;
4392 char_u *errmsg;
4393 char_u errbuf[80];
4394 char_u *startarg;
4395 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4396 int nextchar; /* next non-white char after option name */
4397 int afterchar; /* character just after option name */
4398 int len;
4399 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004400 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004401 int key;
4402 long_u flags; /* flags for current option */
4403 char_u *varp = NULL; /* pointer to variable for current option */
4404 int did_show = FALSE; /* already showed one value */
4405 int adding; /* "opt+=arg" */
4406 int prepending; /* "opt^=arg" */
4407 int removing; /* "opt-=arg" */
4408 int cp_val = 0;
4409 char_u key_name[2];
4410
4411 if (*arg == NUL)
4412 {
4413 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004414 did_show = TRUE;
4415 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004416 }
4417
4418 while (*arg != NUL) /* loop to process all options */
4419 {
4420 errmsg = NULL;
4421 startarg = arg; /* remember for error message */
4422
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004423 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4424 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425 {
4426 /*
4427 * ":set all" show all options.
4428 * ":set all&" set all options to their default value.
4429 */
4430 arg += 3;
4431 if (*arg == '&')
4432 {
4433 ++arg;
4434 /* Only for :set command set global value of local options. */
4435 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004436 didset_options();
4437 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004438 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439 }
4440 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004441 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004442 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004443 did_show = TRUE;
4444 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004445 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004446 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004447 {
4448 showoptions(2, opt_flags);
4449 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004450 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004451 arg += 7;
4452 }
4453 else
4454 {
4455 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004456 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004457 {
4458 prefix = 0;
4459 arg += 2;
4460 }
4461 else if (STRNCMP(arg, "inv", 3) == 0)
4462 {
4463 prefix = 2;
4464 arg += 3;
4465 }
4466
4467 /* find end of name */
4468 key = 0;
4469 if (*arg == '<')
4470 {
4471 nextchar = 0;
4472 opt_idx = -1;
4473 /* look out for <t_>;> */
4474 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4475 len = 5;
4476 else
4477 {
4478 len = 1;
4479 while (arg[len] != NUL && arg[len] != '>')
4480 ++len;
4481 }
4482 if (arg[len] != '>')
4483 {
4484 errmsg = e_invarg;
4485 goto skip;
4486 }
4487 arg[len] = NUL; /* put NUL after name */
4488 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4489 opt_idx = findoption(arg + 1);
4490 arg[len++] = '>'; /* restore '>' */
4491 if (opt_idx == -1)
4492 key = find_key_option(arg + 1);
4493 }
4494 else
4495 {
4496 len = 0;
4497 /*
4498 * The two characters after "t_" may not be alphanumeric.
4499 */
4500 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4501 len = 4;
4502 else
4503 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4504 ++len;
4505 nextchar = arg[len];
4506 arg[len] = NUL; /* put NUL after name */
4507 opt_idx = findoption(arg);
4508 arg[len] = nextchar; /* restore nextchar */
4509 if (opt_idx == -1)
4510 key = find_key_option(arg);
4511 }
4512
4513 /* remember character after option name */
4514 afterchar = arg[len];
4515
4516 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004517 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004518 ++len;
4519
4520 adding = FALSE;
4521 prepending = FALSE;
4522 removing = FALSE;
4523 if (arg[len] != NUL && arg[len + 1] == '=')
4524 {
4525 if (arg[len] == '+')
4526 {
4527 adding = TRUE; /* "+=" */
4528 ++len;
4529 }
4530 else if (arg[len] == '^')
4531 {
4532 prepending = TRUE; /* "^=" */
4533 ++len;
4534 }
4535 else if (arg[len] == '-')
4536 {
4537 removing = TRUE; /* "-=" */
4538 ++len;
4539 }
4540 }
4541 nextchar = arg[len];
4542
4543 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4544 {
4545 errmsg = (char_u *)N_("E518: Unknown option");
4546 goto skip;
4547 }
4548
4549 if (opt_idx >= 0)
4550 {
4551 if (options[opt_idx].var == NULL) /* hidden option: skip */
4552 {
4553 /* Only give an error message when requesting the value of
4554 * a hidden option, ignore setting it. */
4555 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4556 && (!(options[opt_idx].flags & P_BOOL)
4557 || nextchar == '?'))
4558 errmsg = (char_u *)N_("E519: Option not supported");
4559 goto skip;
4560 }
4561
4562 flags = options[opt_idx].flags;
4563 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4564 }
4565 else
4566 {
4567 flags = P_STRING;
4568 if (key < 0)
4569 {
4570 key_name[0] = KEY2TERMCAP0(key);
4571 key_name[1] = KEY2TERMCAP1(key);
4572 }
4573 else
4574 {
4575 key_name[0] = KS_KEY;
4576 key_name[1] = (key & 0xff);
4577 }
4578 }
4579
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004580 /* Skip all options that are not window-local (used when showing
4581 * an already loaded buffer in a window). */
4582 if ((opt_flags & OPT_WINONLY)
4583 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4584 goto skip;
4585
Bram Moolenaara3227e22006-03-08 21:32:40 +00004586 /* Skip all options that are window-local (used for :vimgrep). */
4587 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4588 && options[opt_idx].var == VAR_WIN)
4589 goto skip;
4590
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004591 /* Disallow changing some options from modelines. */
4592 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004593 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004594 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004595 {
4596 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4597 goto skip;
4598 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004599#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004600 /* In diff mode some options are overruled. This avoids that
4601 * 'foldmethod' becomes "marker" instead of "diff" and that
4602 * "wrap" gets set. */
4603 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004604 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004605 && (
4606#ifdef FEAT_FOLDING
4607 options[opt_idx].indir == PV_FDM ||
4608#endif
4609 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004610 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004611#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004612 }
4613
4614#ifdef HAVE_SANDBOX
4615 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004616 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004617 {
4618 errmsg = (char_u *)_(e_sandbox);
4619 goto skip;
4620 }
4621#endif
4622
4623 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4624 {
4625 arg += len;
4626 cp_val = p_cp;
4627 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4628 {
4629 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4630 {
4631 cp_val = FALSE;
4632 arg += 3;
4633 }
4634 else /* "opt&vi": set to Vi default */
4635 {
4636 cp_val = TRUE;
4637 arg += 2;
4638 }
4639 }
4640 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004641 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004642 {
4643 errmsg = e_trailing;
4644 goto skip;
4645 }
4646 }
4647
4648 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004649 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4650 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004651 */
4652 if (nextchar == '?'
4653 || (prefix == 1
4654 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4655 && !(flags & P_BOOL)))
4656 {
4657 /*
4658 * print value
4659 */
4660 if (did_show)
4661 msg_putchar('\n'); /* cursor below last one */
4662 else
4663 {
4664 gotocmdline(TRUE); /* cursor at status line */
4665 did_show = TRUE; /* remember that we did a line */
4666 }
4667 if (opt_idx >= 0)
4668 {
4669 showoneopt(&options[opt_idx], opt_flags);
4670#ifdef FEAT_EVAL
4671 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004672 {
4673 /* Mention where the option was last set. */
4674 if (varp == options[opt_idx].var)
4675 last_set_msg(options[opt_idx].scriptID);
4676 else if ((int)options[opt_idx].indir & PV_WIN)
4677 last_set_msg(curwin->w_p_scriptID[
4678 (int)options[opt_idx].indir & PV_MASK]);
4679 else if ((int)options[opt_idx].indir & PV_BUF)
4680 last_set_msg(curbuf->b_p_scriptID[
4681 (int)options[opt_idx].indir & PV_MASK]);
4682 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004683#endif
4684 }
4685 else
4686 {
4687 char_u *p;
4688
4689 p = find_termcode(key_name);
4690 if (p == NULL)
4691 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004692 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004693 goto skip;
4694 }
4695 else
4696 (void)show_one_termcode(key_name, p, TRUE);
4697 }
4698 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004699 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004700 errmsg = e_trailing;
4701 }
4702 else
4703 {
4704 if (flags & P_BOOL) /* boolean */
4705 {
4706 if (nextchar == '=' || nextchar == ':')
4707 {
4708 errmsg = e_invarg;
4709 goto skip;
4710 }
4711
4712 /*
4713 * ":set opt!": invert
4714 * ":set opt&": reset to default value
4715 * ":set opt<": reset to global value
4716 */
4717 if (nextchar == '!')
4718 value = *(int *)(varp) ^ 1;
4719 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004720 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004721 ((flags & P_VI_DEF) || cp_val)
4722 ? VI_DEFAULT : VIM_DEFAULT];
4723 else if (nextchar == '<')
4724 {
4725 /* For 'autoread' -1 means to use global value. */
4726 if ((int *)varp == &curbuf->b_p_ar
4727 && opt_flags == OPT_LOCAL)
4728 value = -1;
4729 else
4730 value = *(int *)get_varp_scope(&(options[opt_idx]),
4731 OPT_GLOBAL);
4732 }
4733 else
4734 {
4735 /*
4736 * ":set invopt": invert
4737 * ":set opt" or ":set noopt": set or reset
4738 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004739 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004740 {
4741 errmsg = e_trailing;
4742 goto skip;
4743 }
4744 if (prefix == 2) /* inv */
4745 value = *(int *)(varp) ^ 1;
4746 else
4747 value = prefix;
4748 }
4749
4750 errmsg = set_bool_option(opt_idx, varp, (int)value,
4751 opt_flags);
4752 }
4753 else /* numeric or string */
4754 {
4755 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4756 || prefix != 1)
4757 {
4758 errmsg = e_invarg;
4759 goto skip;
4760 }
4761
4762 if (flags & P_NUM) /* numeric */
4763 {
4764 /*
4765 * Different ways to set a number option:
4766 * & set to default value
4767 * < set to global value
4768 * <xx> accept special key codes for 'wildchar'
4769 * c accept any non-digit for 'wildchar'
4770 * [-]0-9 set number
4771 * other error
4772 */
4773 ++arg;
4774 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004775 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004776 ((flags & P_VI_DEF) || cp_val)
4777 ? VI_DEFAULT : VIM_DEFAULT];
4778 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004779 {
4780 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4781 * use the global value. */
4782 if ((long *)varp == &curbuf->b_p_ul
4783 && opt_flags == OPT_LOCAL)
4784 value = NO_LOCAL_UNDOLEVEL;
4785 else
4786 value = *(long *)get_varp_scope(
4787 &(options[opt_idx]), OPT_GLOBAL);
4788 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004789 else if (((long *)varp == &p_wc
4790 || (long *)varp == &p_wcm)
4791 && (*arg == '<'
4792 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004793 || (*arg != NUL
4794 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 && !VIM_ISDIGIT(*arg))))
4796 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004797 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004798 if (value == 0 && (long *)varp != &p_wcm)
4799 {
4800 errmsg = e_invarg;
4801 goto skip;
4802 }
4803 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004804 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4805 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004806 /* Allow negative (for 'undolevels'), octal and
4807 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004808 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4809 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004810 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004811 {
4812 errmsg = e_invarg;
4813 goto skip;
4814 }
4815 }
4816 else
4817 {
4818 errmsg = (char_u *)N_("E521: Number required after =");
4819 goto skip;
4820 }
4821
4822 if (adding)
4823 value = *(long *)varp + value;
4824 if (prepending)
4825 value = *(long *)varp * value;
4826 if (removing)
4827 value = *(long *)varp - value;
4828 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004829 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004830 }
4831 else if (opt_idx >= 0) /* string */
4832 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004833 char_u *save_arg = NULL;
4834 char_u *s = NULL;
4835 char_u *oldval = NULL; /* previous value if *varp */
4836 char_u *newval;
4837 char_u *origval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004838#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004839 char_u *saved_origval = NULL;
4840 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004841#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004842 unsigned newlen;
4843 int comma;
4844 int bs;
4845 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004846 was allocated */
4847
4848 /* When using ":set opt=val" for a global option
4849 * with a local value the local value will be
4850 * reset, use the global value here. */
4851 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004852 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004853 varp = options[opt_idx].var;
4854
4855 /* The old value is kept until we are sure that the
4856 * new value is valid. */
4857 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004858
4859 /* When setting the local value of a global
4860 * option, the old value may be the global value. */
4861 if (((int)options[opt_idx].indir & PV_BOTH)
4862 && (opt_flags & OPT_LOCAL))
4863 origval = *(char_u **)get_varp(
4864 &options[opt_idx]);
4865 else
4866 origval = oldval;
4867
Bram Moolenaar071d4272004-06-13 20:20:40 +00004868 if (nextchar == '&') /* set to default val */
4869 {
4870 newval = options[opt_idx].def_val[
4871 ((flags & P_VI_DEF) || cp_val)
4872 ? VI_DEFAULT : VIM_DEFAULT];
4873 if ((char_u **)varp == &p_bg)
4874 {
4875 /* guess the value of 'background' */
4876#ifdef FEAT_GUI
4877 if (gui.in_use)
4878 newval = gui_bg_default();
4879 else
4880#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004881 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004882 }
4883
4884 /* expand environment variables and ~ (since the
4885 * default value was already expanded, only
4886 * required when an environment variable was set
4887 * later */
4888 if (newval == NULL)
4889 newval = empty_option;
4890 else
4891 {
4892 s = option_expand(opt_idx, newval);
4893 if (s == NULL)
4894 s = newval;
4895 newval = vim_strsave(s);
4896 }
4897 new_value_alloced = TRUE;
4898 }
4899 else if (nextchar == '<') /* set to global val */
4900 {
4901 newval = vim_strsave(*(char_u **)get_varp_scope(
4902 &(options[opt_idx]), OPT_GLOBAL));
4903 new_value_alloced = TRUE;
4904 }
4905 else
4906 {
4907 ++arg; /* jump to after the '=' or ':' */
4908
4909 /*
4910 * Set 'keywordprg' to ":help" if an empty
4911 * value was passed to :set by the user.
4912 * Misuse errbuf[] for the resulting string.
4913 */
4914 if (varp == (char_u *)&p_kp
4915 && (*arg == NUL || *arg == ' '))
4916 {
4917 STRCPY(errbuf, ":help");
4918 save_arg = arg;
4919 arg = errbuf;
4920 }
4921 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004922 * Convert 'backspace' number to string, for
4923 * adding, prepending and removing string.
4924 */
4925 else if (varp == (char_u *)&p_bs
4926 && VIM_ISDIGIT(**(char_u **)varp))
4927 {
4928 i = getdigits((char_u **)varp);
4929 switch (i)
4930 {
4931 case 0:
4932 *(char_u **)varp = empty_option;
4933 break;
4934 case 1:
4935 *(char_u **)varp = vim_strsave(
4936 (char_u *)"indent,eol");
4937 break;
4938 case 2:
4939 *(char_u **)varp = vim_strsave(
4940 (char_u *)"indent,eol,start");
4941 break;
4942 }
4943 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004944 if (origval == oldval)
4945 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004946 oldval = *(char_u **)varp;
4947 }
4948 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004949 * Convert 'whichwrap' number to string, for
4950 * backwards compatibility with Vim 3.0.
4951 * Misuse errbuf[] for the resulting string.
4952 */
4953 else if (varp == (char_u *)&p_ww
4954 && VIM_ISDIGIT(*arg))
4955 {
4956 *errbuf = NUL;
4957 i = getdigits(&arg);
4958 if (i & 1)
4959 STRCAT(errbuf, "b,");
4960 if (i & 2)
4961 STRCAT(errbuf, "s,");
4962 if (i & 4)
4963 STRCAT(errbuf, "h,l,");
4964 if (i & 8)
4965 STRCAT(errbuf, "<,>,");
4966 if (i & 16)
4967 STRCAT(errbuf, "[,],");
4968 if (*errbuf != NUL) /* remove trailing , */
4969 errbuf[STRLEN(errbuf) - 1] = NUL;
4970 save_arg = arg;
4971 arg = errbuf;
4972 }
4973 /*
4974 * Remove '>' before 'dir' and 'bdir', for
4975 * backwards compatibility with version 3.0
4976 */
4977 else if ( *arg == '>'
4978 && (varp == (char_u *)&p_dir
4979 || varp == (char_u *)&p_bdir))
4980 {
4981 ++arg;
4982 }
4983
Bram Moolenaar071d4272004-06-13 20:20:40 +00004984 /*
4985 * Copy the new string into allocated memory.
4986 * Can't use set_string_option_direct(), because
4987 * we need to remove the backslashes.
4988 */
4989 /* get a bit too much */
4990 newlen = (unsigned)STRLEN(arg) + 1;
4991 if (adding || prepending || removing)
4992 newlen += (unsigned)STRLEN(origval) + 1;
4993 newval = alloc(newlen);
4994 if (newval == NULL) /* out of mem, don't change */
4995 break;
4996 s = newval;
4997
4998 /*
4999 * Copy the string, skip over escaped chars.
5000 * For MS-DOS and WIN32 backslashes before normal
5001 * file name characters are not removed, and keep
5002 * backslash at start, for "\\machine\path", but
5003 * do remove it for "\\\\machine\\path".
5004 * The reverse is found in ExpandOldSetting().
5005 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005006 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005007 {
5008 if (*arg == '\\' && arg[1] != NUL
5009#ifdef BACKSLASH_IN_FILENAME
5010 && !((flags & P_EXPAND)
5011 && vim_isfilec(arg[1])
5012 && (arg[1] != '\\'
5013 || (s == newval
5014 && arg[2] != '\\')))
5015#endif
5016 )
5017 ++arg; /* remove backslash */
5018#ifdef FEAT_MBYTE
5019 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005020 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005021 {
5022 /* copy multibyte char */
5023 mch_memmove(s, arg, (size_t)i);
5024 arg += i;
5025 s += i;
5026 }
5027 else
5028#endif
5029 *s++ = *arg++;
5030 }
5031 *s = NUL;
5032
5033 /*
5034 * Expand environment variables and ~.
5035 * Don't do it when adding without inserting a
5036 * comma.
5037 */
5038 if (!(adding || prepending || removing)
5039 || (flags & P_COMMA))
5040 {
5041 s = option_expand(opt_idx, newval);
5042 if (s != NULL)
5043 {
5044 vim_free(newval);
5045 newlen = (unsigned)STRLEN(s) + 1;
5046 if (adding || prepending || removing)
5047 newlen += (unsigned)STRLEN(origval) + 1;
5048 newval = alloc(newlen);
5049 if (newval == NULL)
5050 break;
5051 STRCPY(newval, s);
5052 }
5053 }
5054
5055 /* locate newval[] in origval[] when removing it
5056 * and when adding to avoid duplicates */
5057 i = 0; /* init for GCC */
5058 if (removing || (flags & P_NODUP))
5059 {
5060 i = (int)STRLEN(newval);
5061 bs = 0;
5062 for (s = origval; *s; ++s)
5063 {
5064 if ((!(flags & P_COMMA)
5065 || s == origval
5066 || (s[-1] == ',' && !(bs & 1)))
5067 && STRNCMP(s, newval, i) == 0
5068 && (!(flags & P_COMMA)
5069 || s[i] == ','
5070 || s[i] == NUL))
5071 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005072 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005073 * even number of backslashes or a single
5074 * backslash preceded by a comma before it
5075 * is recognized as a separator */
5076 if ((s > origval + 1
5077 && s[-1] == '\\'
5078 && s[-2] != ',')
5079 || (s == origval + 1
5080 && s[-1] == '\\'))
5081
Bram Moolenaar071d4272004-06-13 20:20:40 +00005082 ++bs;
5083 else
5084 bs = 0;
5085 }
5086
5087 /* do not add if already there */
5088 if ((adding || prepending) && *s)
5089 {
5090 prepending = FALSE;
5091 adding = FALSE;
5092 STRCPY(newval, origval);
5093 }
5094 }
5095
5096 /* concatenate the two strings; add a ',' if
5097 * needed */
5098 if (adding || prepending)
5099 {
5100 comma = ((flags & P_COMMA) && *origval != NUL
5101 && *newval != NUL);
5102 if (adding)
5103 {
5104 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005105 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005106 if (comma && i > 1
5107 && (flags & P_ONECOMMA) == P_ONECOMMA
5108 && origval[i - 1] == ','
5109 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005110 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 mch_memmove(newval + i + comma, newval,
5112 STRLEN(newval) + 1);
5113 mch_memmove(newval, origval, (size_t)i);
5114 }
5115 else
5116 {
5117 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005118 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005119 }
5120 if (comma)
5121 newval[i] = ',';
5122 }
5123
5124 /* Remove newval[] from origval[]. (Note: "i" has
5125 * been set above and is used here). */
5126 if (removing)
5127 {
5128 STRCPY(newval, origval);
5129 if (*s)
5130 {
5131 /* may need to remove a comma */
5132 if (flags & P_COMMA)
5133 {
5134 if (s == origval)
5135 {
5136 /* include comma after string */
5137 if (s[i] == ',')
5138 ++i;
5139 }
5140 else
5141 {
5142 /* include comma before string */
5143 --s;
5144 ++i;
5145 }
5146 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005147 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005148 }
5149 }
5150
5151 if (flags & P_FLAGLIST)
5152 {
5153 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005154 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005155 {
5156 /* if options have P_FLAGLIST and
5157 * P_ONECOMMA such as 'whichwrap' */
5158 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005159 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005160 if (*s != ',' && *(s + 1) == ','
5161 && vim_strchr(s + 2, *s) != NULL)
5162 {
5163 /* Remove the duplicated value and
5164 * the next comma. */
5165 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005166 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005168 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005169 else
5170 {
5171 if ((!(flags & P_COMMA) || *s != ',')
5172 && vim_strchr(s + 1, *s) != NULL)
5173 {
5174 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005175 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005176 }
5177 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005178 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005180 }
5181
5182 if (save_arg != NULL) /* number for 'whichwrap' */
5183 arg = save_arg;
5184 new_value_alloced = TRUE;
5185 }
5186
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005187 /*
5188 * Set the new value.
5189 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005190 *(char_u **)(varp) = newval;
5191
Bram Moolenaar53744302015-07-17 17:38:22 +02005192#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005193 if (!starting
5194# ifdef FEAT_CRYPT
5195 && options[opt_idx].indir != PV_KEY
5196# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005197 && origval != NULL && newval != NULL)
5198 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005199 /* origval may be freed by
5200 * did_set_string_option(), make a copy. */
5201 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005202 /* newval (and varp) may become invalid if the
5203 * buffer is closed by autocommands. */
5204 saved_newval = vim_strsave(newval);
5205 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005206#endif
5207
Bram Moolenaar071d4272004-06-13 20:20:40 +00005208 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005209 * ":set" on local options. Note: when setting 'syntax'
5210 * or 'filetype' autocommands may be triggered that can
5211 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005212 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5213 new_value_alloced, oldval, errbuf, opt_flags);
5214
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005215#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5216 if (errmsg == NULL)
5217 trigger_optionsset_string(opt_idx, opt_flags,
5218 saved_origval, saved_newval);
5219 vim_free(saved_origval);
5220 vim_free(saved_newval);
5221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005222 /* If error detected, print the error message. */
5223 if (errmsg != NULL)
5224 goto skip;
5225 }
5226 else /* key code option */
5227 {
5228 char_u *p;
5229
5230 if (nextchar == '&')
5231 {
5232 if (add_termcap_entry(key_name, TRUE) == FAIL)
5233 errmsg = (char_u *)N_("E522: Not found in termcap");
5234 }
5235 else
5236 {
5237 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005238 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005239 if (*p == '\\' && p[1] != NUL)
5240 ++p;
5241 nextchar = *p;
5242 *p = NUL;
5243 add_termcode(key_name, arg, FALSE);
5244 *p = nextchar;
5245 }
5246 if (full_screen)
5247 ttest(FALSE);
5248 redraw_all_later(CLEAR);
5249 }
5250 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005251
Bram Moolenaar071d4272004-06-13 20:20:40 +00005252 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005253 did_set_option(opt_idx, opt_flags,
5254 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005255 }
5256
5257skip:
5258 /*
5259 * Advance to next argument.
5260 * - skip until a blank found, taking care of backslashes
5261 * - skip blanks
5262 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5263 */
5264 for (i = 0; i < 2 ; ++i)
5265 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005266 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005267 if (*arg++ == '\\' && *arg != NUL)
5268 ++arg;
5269 arg = skipwhite(arg);
5270 if (*arg != '=')
5271 break;
5272 }
5273 }
5274
5275 if (errmsg != NULL)
5276 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005277 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005278 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005279 if (i + (arg - startarg) < IOSIZE)
5280 {
5281 /* append the argument with the error */
5282 STRCAT(IObuff, ": ");
5283 mch_memmove(IObuff + i, startarg, (arg - startarg));
5284 IObuff[i + (arg - startarg)] = NUL;
5285 }
5286 /* make sure all characters are printable */
5287 trans_characters(IObuff, IOSIZE);
5288
5289 ++no_wait_return; /* wait_return done later */
5290 emsg(IObuff); /* show error highlighted */
5291 --no_wait_return;
5292
5293 return FAIL;
5294 }
5295
5296 arg = skipwhite(arg);
5297 }
5298
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005299theend:
5300 if (silent_mode && did_show)
5301 {
5302 /* After displaying option values in silent mode. */
5303 silent_mode = FALSE;
5304 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5305 msg_putchar('\n');
5306 cursor_on(); /* msg_start() switches it off */
5307 out_flush();
5308 silent_mode = TRUE;
5309 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5310 }
5311
Bram Moolenaar071d4272004-06-13 20:20:40 +00005312 return OK;
5313}
5314
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005315/*
5316 * Call this when an option has been given a new value through a user command.
5317 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5318 */
5319 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005320did_set_option(
5321 int opt_idx,
5322 int opt_flags, /* possibly with OPT_MODELINE */
5323 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005324{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005325 long_u *p;
5326
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005327 options[opt_idx].flags |= P_WAS_SET;
5328
5329 /* When an option is set in the sandbox, from a modeline or in secure mode
5330 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005331 * flag. */
5332 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005333 if (secure
5334#ifdef HAVE_SANDBOX
5335 || sandbox != 0
5336#endif
5337 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005338 *p = *p | P_INSECURE;
5339 else if (new_value)
5340 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005341}
5342
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005344illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005345{
5346 if (errbuf == NULL)
5347 return (char_u *)"";
5348 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005349 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005350 return errbuf;
5351}
5352
5353/*
5354 * Convert a key name or string into a key value.
5355 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005356 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005358 int
5359string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005360{
5361 if (*arg == '<')
5362 return find_key_option(arg + 1);
5363 if (*arg == '^')
5364 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005365 if (multi_byte)
5366 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005367 return *arg;
5368}
5369
5370#ifdef FEAT_CMDWIN
5371/*
5372 * Check value of 'cedit' and set cedit_key.
5373 * Returns NULL if value is OK, error message otherwise.
5374 */
5375 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005376check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005377{
5378 int n;
5379
5380 if (*p_cedit == NUL)
5381 cedit_key = -1;
5382 else
5383 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005384 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385 if (vim_isprintc(n))
5386 return e_invarg;
5387 cedit_key = n;
5388 }
5389 return NULL;
5390}
5391#endif
5392
5393#ifdef FEAT_TITLE
5394/*
5395 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5396 * maketitle() to create and display it.
5397 * When switching the title or icon off, call mch_restore_title() to get
5398 * the old value back.
5399 */
5400 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005401did_set_title(
5402 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005403{
5404 if (starting != NO_SCREEN
5405#ifdef FEAT_GUI
5406 && !gui.starting
5407#endif
5408 )
5409 {
5410 maketitle();
5411 if (icon)
5412 {
5413 if (!p_icon)
5414 mch_restore_title(2);
5415 }
5416 else
5417 {
5418 if (!p_title)
5419 mch_restore_title(1);
5420 }
5421 }
5422}
5423#endif
5424
5425/*
5426 * set_options_bin - called when 'bin' changes value.
5427 */
5428 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005429set_options_bin(
5430 int oldval,
5431 int newval,
5432 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433{
5434 /*
5435 * The option values that are changed when 'bin' changes are
5436 * copied when 'bin is set and restored when 'bin' is reset.
5437 */
5438 if (newval)
5439 {
5440 if (!oldval) /* switched on */
5441 {
5442 if (!(opt_flags & OPT_GLOBAL))
5443 {
5444 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5445 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5446 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5447 curbuf->b_p_et_nobin = curbuf->b_p_et;
5448 }
5449 if (!(opt_flags & OPT_LOCAL))
5450 {
5451 p_tw_nobin = p_tw;
5452 p_wm_nobin = p_wm;
5453 p_ml_nobin = p_ml;
5454 p_et_nobin = p_et;
5455 }
5456 }
5457
5458 if (!(opt_flags & OPT_GLOBAL))
5459 {
5460 curbuf->b_p_tw = 0; /* no automatic line wrap */
5461 curbuf->b_p_wm = 0; /* no automatic line wrap */
5462 curbuf->b_p_ml = 0; /* no modelines */
5463 curbuf->b_p_et = 0; /* no expandtab */
5464 }
5465 if (!(opt_flags & OPT_LOCAL))
5466 {
5467 p_tw = 0;
5468 p_wm = 0;
5469 p_ml = FALSE;
5470 p_et = FALSE;
5471 p_bin = TRUE; /* needed when called for the "-b" argument */
5472 }
5473 }
5474 else if (oldval) /* switched off */
5475 {
5476 if (!(opt_flags & OPT_GLOBAL))
5477 {
5478 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5479 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5480 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5481 curbuf->b_p_et = curbuf->b_p_et_nobin;
5482 }
5483 if (!(opt_flags & OPT_LOCAL))
5484 {
5485 p_tw = p_tw_nobin;
5486 p_wm = p_wm_nobin;
5487 p_ml = p_ml_nobin;
5488 p_et = p_et_nobin;
5489 }
5490 }
5491}
5492
5493#ifdef FEAT_VIMINFO
5494/*
5495 * Find the parameter represented by the given character (eg ', :, ", or /),
5496 * and return its associated value in the 'viminfo' string.
5497 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005498 * If the parameter is not specified in the string or there is no following
5499 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005500 */
5501 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005502get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005503{
5504 char_u *p;
5505
5506 p = find_viminfo_parameter(type);
5507 if (p != NULL && VIM_ISDIGIT(*p))
5508 return atoi((char *)p);
5509 return -1;
5510}
5511
5512/*
5513 * Find the parameter represented by the given character (eg ''', ':', '"', or
5514 * '/') in the 'viminfo' option and return a pointer to the string after it.
5515 * Return NULL if the parameter is not specified in the string.
5516 */
5517 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005518find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005519{
5520 char_u *p;
5521
5522 for (p = p_viminfo; *p; ++p)
5523 {
5524 if (*p == type)
5525 return p + 1;
5526 if (*p == 'n') /* 'n' is always the last one */
5527 break;
5528 p = vim_strchr(p, ','); /* skip until next ',' */
5529 if (p == NULL) /* hit the end without finding parameter */
5530 break;
5531 }
5532 return NULL;
5533}
5534#endif
5535
5536/*
5537 * Expand environment variables for some string options.
5538 * These string options cannot be indirect!
5539 * If "val" is NULL expand the current value of the option.
5540 * Return pointer to NameBuff, or NULL when not expanded.
5541 */
5542 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005543option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005544{
5545 /* if option doesn't need expansion nothing to do */
5546 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5547 return NULL;
5548
5549 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5550 * expand_env() would truncate the string. */
5551 if (val != NULL && STRLEN(val) > MAXPATHL)
5552 return NULL;
5553
5554 if (val == NULL)
5555 val = *(char_u **)options[opt_idx].var;
5556
5557 /*
5558 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5559 * Escape spaces when expanding 'tags', they are used to separate file
5560 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005561 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005562 */
5563 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005564 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005565#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005566 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5567#endif
5568 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005569 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5570 return NULL;
5571
5572 return NameBuff;
5573}
5574
5575/*
5576 * After setting various option values: recompute variables that depend on
5577 * option values.
5578 */
5579 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005580didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581{
5582 /* initialize the table for 'iskeyword' et.al. */
5583 (void)init_chartab();
5584
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005585#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005586 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005587#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005588 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005589 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590#ifdef FEAT_SESSION
5591 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5592 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5593#endif
5594#ifdef FEAT_FOLDING
5595 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5596#endif
5597 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005598 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005599#ifdef FEAT_VIRTUALEDIT
5600 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5601#endif
5602#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5603 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5604#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005605#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005606 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005607 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005608 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005609 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005610#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005611#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5612 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5613#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005614#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5616#endif
5617#ifdef FEAT_CMDWIN
5618 /* set cedit_key */
5619 (void)check_cedit();
5620#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005621#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005622 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005623#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005624#ifdef FEAT_LINEBREAK
5625 /* initialize the table for 'breakat'. */
5626 fill_breakat_flags();
5627#endif
5628
5629}
5630
5631/*
5632 * More side effects of setting options.
5633 */
5634 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005635didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005636{
5637 /* Initialize the highlight_attr[] table. */
5638 (void)highlight_changed();
5639
5640 /* Parse default for 'wildmode' */
5641 check_opt_wim();
5642
5643 (void)set_chars_option(&p_lcs);
5644#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5645 /* Parse default for 'fillchars'. */
5646 (void)set_chars_option(&p_fcs);
5647#endif
5648
5649#ifdef FEAT_CLIPBOARD
5650 /* Parse default for 'clipboard' */
5651 (void)check_clipboard_option();
5652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005653}
5654
5655/*
5656 * Check for string options that are NULL (normally only termcap options).
5657 */
5658 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005659check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005660{
5661 int opt_idx;
5662
5663 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5664 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5665 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5666}
5667
5668/*
5669 * Check string options in a buffer for NULL value.
5670 */
5671 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005672check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005674 check_string_option(&buf->b_p_bh);
5675 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005676#ifdef FEAT_MBYTE
5677 check_string_option(&buf->b_p_fenc);
5678#endif
5679 check_string_option(&buf->b_p_ff);
5680#ifdef FEAT_FIND_ID
5681 check_string_option(&buf->b_p_def);
5682 check_string_option(&buf->b_p_inc);
5683# ifdef FEAT_EVAL
5684 check_string_option(&buf->b_p_inex);
5685# endif
5686#endif
5687#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5688 check_string_option(&buf->b_p_inde);
5689 check_string_option(&buf->b_p_indk);
5690#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005691#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5692 check_string_option(&buf->b_p_bexpr);
5693#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005694#if defined(FEAT_CRYPT)
5695 check_string_option(&buf->b_p_cm);
5696#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005697 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005698#if defined(FEAT_EVAL)
5699 check_string_option(&buf->b_p_fex);
5700#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701#ifdef FEAT_CRYPT
5702 check_string_option(&buf->b_p_key);
5703#endif
5704 check_string_option(&buf->b_p_kp);
5705 check_string_option(&buf->b_p_mps);
5706 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005707 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708 check_string_option(&buf->b_p_isk);
5709#ifdef FEAT_COMMENTS
5710 check_string_option(&buf->b_p_com);
5711#endif
5712#ifdef FEAT_FOLDING
5713 check_string_option(&buf->b_p_cms);
5714#endif
5715 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005716#ifdef FEAT_TEXTOBJ
5717 check_string_option(&buf->b_p_qe);
5718#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719#ifdef FEAT_SYN_HL
5720 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005721 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005722#endif
5723#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005724 check_string_option(&buf->b_s.b_p_spc);
5725 check_string_option(&buf->b_s.b_p_spf);
5726 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727#endif
5728#ifdef FEAT_SEARCHPATH
5729 check_string_option(&buf->b_p_sua);
5730#endif
5731#ifdef FEAT_CINDENT
5732 check_string_option(&buf->b_p_cink);
5733 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005734 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735#endif
5736#ifdef FEAT_AUTOCMD
5737 check_string_option(&buf->b_p_ft);
5738#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5740 check_string_option(&buf->b_p_cinw);
5741#endif
5742#ifdef FEAT_INS_EXPAND
5743 check_string_option(&buf->b_p_cpt);
5744#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005745#ifdef FEAT_COMPL_FUNC
5746 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005747 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005748#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005749#ifdef FEAT_KEYMAP
5750 check_string_option(&buf->b_p_keymap);
5751#endif
5752#ifdef FEAT_QUICKFIX
5753 check_string_option(&buf->b_p_gp);
5754 check_string_option(&buf->b_p_mp);
5755 check_string_option(&buf->b_p_efm);
5756#endif
5757 check_string_option(&buf->b_p_ep);
5758 check_string_option(&buf->b_p_path);
5759 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005760 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005761#ifdef FEAT_INS_EXPAND
5762 check_string_option(&buf->b_p_dict);
5763 check_string_option(&buf->b_p_tsr);
5764#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005765#ifdef FEAT_LISP
5766 check_string_option(&buf->b_p_lw);
5767#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005768 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005769#ifdef FEAT_MBYTE
5770 check_string_option(&buf->b_p_menc);
5771#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772}
5773
5774/*
5775 * Free the string allocated for an option.
5776 * Checks for the string being empty_option. This may happen if we're out of
5777 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5778 * check_options().
5779 * Does NOT check for P_ALLOCED flag!
5780 */
5781 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005782free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783{
5784 if (p != empty_option)
5785 vim_free(p);
5786}
5787
5788 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005789clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005790{
5791 if (*pp != empty_option)
5792 vim_free(*pp);
5793 *pp = empty_option;
5794}
5795
5796 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005797check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005798{
5799 if (*pp == NULL)
5800 *pp = empty_option;
5801}
5802
5803/*
5804 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5805 */
5806 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005807set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005808{
5809 int opt_idx;
5810
5811 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5812 if (options[opt_idx].var == (char_u *)p)
5813 {
5814 options[opt_idx].flags |= P_ALLOCED;
5815 return;
5816 }
5817 return; /* cannot happen: didn't find it! */
5818}
5819
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005820#if defined(FEAT_EVAL) || defined(PROTO)
5821/*
5822 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5823 * Return FALSE when it wasn't.
5824 * Return -1 for an unknown option.
5825 */
5826 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005827was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005828{
5829 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005830 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005831
5832 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005833 {
5834 flagp = insecure_flag(idx, opt_flags);
5835 return (*flagp & P_INSECURE) != 0;
5836 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005837 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005838 return -1;
5839}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005840
5841/*
5842 * Get a pointer to the flags used for the P_INSECURE flag of option
5843 * "opt_idx". For some local options a local flags field is used.
5844 */
5845 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005846insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005847{
5848 if (opt_flags & OPT_LOCAL)
5849 switch ((int)options[opt_idx].indir)
5850 {
5851#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005852 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005853#endif
5854#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005855# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005856 case PV_FDE: return &curwin->w_p_fde_flags;
5857 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005858# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005859# ifdef FEAT_BEVAL
5860 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5861# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005862# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005863 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005864# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005865 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005866# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005867 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005868# endif
5869#endif
5870 }
5871
5872 /* Nothing special, return global flags field. */
5873 return &options[opt_idx].flags;
5874}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005875#endif
5876
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005877#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005878static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005879
5880/*
5881 * Redraw the window title and/or tab page text later.
5882 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005883static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005884{
5885 need_maketitle = TRUE;
5886# ifdef FEAT_WINDOWS
5887 redraw_tabline = TRUE;
5888# endif
5889}
5890#endif
5891
Bram Moolenaar071d4272004-06-13 20:20:40 +00005892/*
5893 * Set a string option to a new value (without checking the effect).
5894 * The string is copied into allocated memory.
5895 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005896 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005897 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 */
5899 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005900set_string_option_direct(
5901 char_u *name,
5902 int opt_idx,
5903 char_u *val,
5904 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5905 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906{
5907 char_u *s;
5908 char_u **varp;
5909 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005910 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005911
Bram Moolenaar89d40322006-08-29 15:30:07 +00005912 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005914 idx = findoption(name);
5915 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005916 {
5917 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005918 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005919 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005920 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005921 }
5922
Bram Moolenaar89d40322006-08-29 15:30:07 +00005923 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924 return;
5925
5926 s = vim_strsave(val);
5927 if (s != NULL)
5928 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005929 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005931 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932 free_string_option(*varp);
5933 *varp = s;
5934
5935 /* For buffer/window local option may also set the global value. */
5936 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005937 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938
Bram Moolenaar89d40322006-08-29 15:30:07 +00005939 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940
5941 /* When setting both values of a global option with a local value,
5942 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005943 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944 {
5945 free_string_option(*varp);
5946 *varp = empty_option;
5947 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005948# ifdef FEAT_EVAL
5949 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005950 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005951 set_sid == 0 ? current_SID : set_sid);
5952# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005953 }
5954}
5955
5956/*
5957 * Set global value for string option when it's a local option.
5958 */
5959 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005960set_string_option_global(
5961 int opt_idx, /* option index */
5962 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963{
5964 char_u **p, *s;
5965
5966 /* the global value is always allocated */
5967 if (options[opt_idx].var == VAR_WIN)
5968 p = (char_u **)GLOBAL_WO(varp);
5969 else
5970 p = (char_u **)options[opt_idx].var;
5971 if (options[opt_idx].indir != PV_NONE
5972 && p != varp
5973 && (s = vim_strsave(*varp)) != NULL)
5974 {
5975 free_string_option(*p);
5976 *p = s;
5977 }
5978}
5979
5980/*
5981 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005982 *
5983 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005985 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005986set_string_option(
5987 int opt_idx,
5988 char_u *value,
5989 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990{
5991 char_u *s;
5992 char_u **varp;
5993 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005994#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5995 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005996 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005997#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005998 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999
6000 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006001 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006002
6003 s = vim_strsave(value);
6004 if (s != NULL)
6005 {
6006 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6007 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006008 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006009 ? OPT_GLOBAL : OPT_LOCAL)
6010 : opt_flags);
6011 oldval = *varp;
6012 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006013
6014#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006015 if (!starting
6016# ifdef FEAT_CRYPT
6017 && options[opt_idx].indir != PV_KEY
6018# endif
6019 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006020 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006021 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006022 saved_newval = vim_strsave(s);
6023 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006024#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006025 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
6026 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00006027 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02006028
Bram Moolenaar53744302015-07-17 17:38:22 +02006029#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006030 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006031 if (r == NULL)
6032 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006033 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006034 vim_free(saved_oldval);
6035 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006036#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006038 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006039}
6040
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006041#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006042/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006043 * Return TRUE if "val" is a valid 'filetype' name.
6044 * Also used for 'syntax' and 'keymap'.
6045 */
6046 static int
6047valid_filetype(char_u *val)
6048{
6049 char_u *s;
6050
6051 for (s = val; *s != NUL; ++s)
6052 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6053 return FALSE;
6054 return TRUE;
6055}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006056#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006057
6058/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006059 * Handle string options that need some action to perform when changed.
6060 * Returns NULL for success, or an error message for an error.
6061 */
6062 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006063did_set_string_option(
6064 int opt_idx, /* index in options[] table */
6065 char_u **varp, /* pointer to the option variable */
6066 int new_value_alloced, /* new value was allocated */
6067 char_u *oldval, /* previous value of the option */
6068 char_u *errbuf, /* buffer for errors, or NULL */
6069 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006070{
6071 char_u *errmsg = NULL;
6072 char_u *s, *p;
6073 int did_chartab = FALSE;
6074 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006075 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006076#ifdef FEAT_GUI
6077 /* set when changing an option that only requires a redraw in the GUI */
6078 int redraw_gui_only = FALSE;
6079#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006080#ifdef FEAT_AUTOCMD
6081 int ft_changed = FALSE;
6082#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006083
6084 /* Get the global option to compare with, otherwise we would have to check
6085 * two values for all local options. */
6086 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6087
6088 /* Disallow changing some options from secure mode */
6089 if ((secure
6090#ifdef HAVE_SANDBOX
6091 || sandbox != 0
6092#endif
6093 ) && (options[opt_idx].flags & P_SECURE))
6094 {
6095 errmsg = e_secure;
6096 }
6097
Bram Moolenaar7554da42016-11-25 22:04:13 +01006098 /* Check for a "normal" directory or file name in some options. Disallow a
6099 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006100 * are often illegal in a file name. Be more permissive if "secure" is off.
6101 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006102 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006103 && vim_strpbrk(*varp, (char_u *)(secure
6104 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006105 || ((options[opt_idx].flags & P_NDNAME)
6106 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006107 {
6108 errmsg = e_invarg;
6109 }
6110
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 /* 'term' */
6112 else if (varp == &T_NAME)
6113 {
6114 if (T_NAME[0] == NUL)
6115 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6116#ifdef FEAT_GUI
6117 if (gui.in_use)
6118 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6119 else if (term_is_gui(T_NAME))
6120 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6121#endif
6122 else if (set_termname(T_NAME) == FAIL)
6123 errmsg = (char_u *)N_("E522: Not found in termcap");
6124 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006125 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006126 /* Screen colors may have changed. */
6127 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006128
6129 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6130 * P_ALLOCED flag on 'term'. */
6131 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006132 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006133 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134 }
6135
6136 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006137 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006139 char_u *bkc = p_bkc;
6140 unsigned int *flags = &bkc_flags;
6141
6142 if (opt_flags & OPT_LOCAL)
6143 {
6144 bkc = curbuf->b_p_bkc;
6145 flags = &curbuf->b_bkc_flags;
6146 }
6147
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006148 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6149 /* make the local value empty: use the global value */
6150 *flags = 0;
6151 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006152 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006153 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6154 errmsg = e_invarg;
6155 if ((((int)*flags & BKC_AUTO) != 0)
6156 + (((int)*flags & BKC_YES) != 0)
6157 + (((int)*flags & BKC_NO) != 0) != 1)
6158 {
6159 /* Must have exactly one of "auto", "yes" and "no". */
6160 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6161 errmsg = e_invarg;
6162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006163 }
6164 }
6165
6166 /* 'backupext' and 'patchmode' */
6167 else if (varp == &p_bex || varp == &p_pm)
6168 {
6169 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6170 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6171 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6172 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006173#ifdef FEAT_LINEBREAK
6174 /* 'breakindentopt' */
6175 else if (varp == &curwin->w_p_briopt)
6176 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006177 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006178 errmsg = e_invarg;
6179 }
6180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006181
6182 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006183 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006184 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006185 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006186 */
6187 else if ( varp == &p_isi
6188 || varp == &(curbuf->b_p_isk)
6189 || varp == &p_isp
6190 || varp == &p_isf)
6191 {
6192 if (init_chartab() == FAIL)
6193 {
6194 did_chartab = TRUE; /* need to restore it below */
6195 errmsg = e_invarg; /* error in value */
6196 }
6197 }
6198
6199 /* 'helpfile' */
6200 else if (varp == &p_hf)
6201 {
6202 /* May compute new values for $VIM and $VIMRUNTIME */
6203 if (didset_vim)
6204 {
6205 vim_setenv((char_u *)"VIM", (char_u *)"");
6206 didset_vim = FALSE;
6207 }
6208 if (didset_vimruntime)
6209 {
6210 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6211 didset_vimruntime = FALSE;
6212 }
6213 }
6214
Bram Moolenaar1a384422010-07-14 19:53:30 +02006215#ifdef FEAT_SYN_HL
6216 /* 'colorcolumn' */
6217 else if (varp == &curwin->w_p_cc)
6218 errmsg = check_colorcolumn(curwin);
6219#endif
6220
Bram Moolenaar071d4272004-06-13 20:20:40 +00006221#ifdef FEAT_MULTI_LANG
6222 /* 'helplang' */
6223 else if (varp == &p_hlg)
6224 {
6225 /* Check for "", "ab", "ab,cd", etc. */
6226 for (s = p_hlg; *s != NUL; s += 3)
6227 {
6228 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6229 {
6230 errmsg = e_invarg;
6231 break;
6232 }
6233 if (s[2] == NUL)
6234 break;
6235 }
6236 }
6237#endif
6238
6239 /* 'highlight' */
6240 else if (varp == &p_hl)
6241 {
6242 if (highlight_changed() == FAIL)
6243 errmsg = e_invarg; /* invalid flags */
6244 }
6245
6246 /* 'nrformats' */
6247 else if (gvarp == &p_nf)
6248 {
6249 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6250 errmsg = e_invarg;
6251 }
6252
6253#ifdef FEAT_SESSION
6254 /* 'sessionoptions' */
6255 else if (varp == &p_ssop)
6256 {
6257 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6258 errmsg = e_invarg;
6259 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6260 {
6261 /* Don't allow both "sesdir" and "curdir". */
6262 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6263 errmsg = e_invarg;
6264 }
6265 }
6266 /* 'viewoptions' */
6267 else if (varp == &p_vop)
6268 {
6269 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6270 errmsg = e_invarg;
6271 }
6272#endif
6273
6274 /* 'scrollopt' */
6275#ifdef FEAT_SCROLLBIND
6276 else if (varp == &p_sbo)
6277 {
6278 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6279 errmsg = e_invarg;
6280 }
6281#endif
6282
6283 /* 'ambiwidth' */
6284#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006285 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006286 {
6287 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6288 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006289 else if (set_chars_option(&p_lcs) != NULL)
6290 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6291# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6292 else if (set_chars_option(&p_fcs) != NULL)
6293 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6294# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006295 }
6296#endif
6297
6298 /* 'background' */
6299 else if (varp == &p_bg)
6300 {
6301 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6302 {
6303#ifdef FEAT_EVAL
6304 int dark = (*p_bg == 'd');
6305#endif
6306
6307 init_highlight(FALSE, FALSE);
6308
6309#ifdef FEAT_EVAL
6310 if (dark != (*p_bg == 'd')
6311 && get_var_value((char_u *)"g:colors_name") != NULL)
6312 {
6313 /* The color scheme must have set 'background' back to another
6314 * value, that's not what we want here. Disable the color
6315 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006316 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006317 free_string_option(p_bg);
6318 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6319 check_string_option(&p_bg);
6320 init_highlight(FALSE, FALSE);
6321 }
6322#endif
6323 }
6324 else
6325 errmsg = e_invarg;
6326 }
6327
6328 /* 'wildmode' */
6329 else if (varp == &p_wim)
6330 {
6331 if (check_opt_wim() == FAIL)
6332 errmsg = e_invarg;
6333 }
6334
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006335#ifdef FEAT_CMDL_COMPL
6336 /* 'wildoptions' */
6337 else if (varp == &p_wop)
6338 {
6339 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6340 errmsg = e_invarg;
6341 }
6342#endif
6343
Bram Moolenaar071d4272004-06-13 20:20:40 +00006344#ifdef FEAT_WAK
6345 /* 'winaltkeys' */
6346 else if (varp == &p_wak)
6347 {
6348 if (*p_wak == NUL
6349 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6350 errmsg = e_invarg;
6351# ifdef FEAT_MENU
6352# ifdef FEAT_GUI_MOTIF
6353 else if (gui.in_use)
6354 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6355# else
6356# ifdef FEAT_GUI_GTK
6357 else if (gui.in_use)
6358 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6359# endif
6360# endif
6361# endif
6362 }
6363#endif
6364
6365#ifdef FEAT_AUTOCMD
6366 /* 'eventignore' */
6367 else if (varp == &p_ei)
6368 {
6369 if (check_ei() == FAIL)
6370 errmsg = e_invarg;
6371 }
6372#endif
6373
6374#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006375 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6376 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6377 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006378 {
6379 if (gvarp == &p_fenc)
6380 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006381 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006382 errmsg = e_modifiable;
6383 else if (vim_strchr(*varp, ',') != NULL)
6384 /* No comma allowed in 'fileencoding'; catches confusing it
6385 * with 'fileencodings'. */
6386 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006387 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006388 {
6389# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006390 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006391 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006393 /* Add 'fileencoding' to the swap file. */
6394 ml_setflags(curbuf);
6395 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396 }
6397 if (errmsg == NULL)
6398 {
6399 /* canonize the value, so that STRCMP() can be used on it */
6400 p = enc_canonize(*varp);
6401 if (p != NULL)
6402 {
6403 vim_free(*varp);
6404 *varp = p;
6405 }
6406 if (varp == &p_enc)
6407 {
6408 errmsg = mb_init();
6409# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006410 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006411# endif
6412 }
6413 }
6414
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006415# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006416 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6417 {
6418 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6419 if (STRCMP(p_tenc, "utf-8") != 0)
6420 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6421 }
6422# endif
6423
6424 if (errmsg == NULL)
6425 {
6426# ifdef FEAT_KEYMAP
6427 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6428 * (with another encoding). */
6429 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6430 (void)keymap_init();
6431# endif
6432
6433 /* When 'termencoding' is not empty and 'encoding' changes or when
6434 * 'termencoding' changes, need to setup for keyboard input and
6435 * display output conversion. */
6436 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6437 {
6438 convert_setup(&input_conv, p_tenc, p_enc);
6439 convert_setup(&output_conv, p_enc, p_tenc);
6440 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006441
6442# if defined(WIN3264) && defined(FEAT_MBYTE)
6443 /* $HOME may have characters in active code page. */
6444 if (varp == &p_enc)
6445 init_homedir();
6446# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006447 }
6448 }
6449#endif
6450
6451#if defined(FEAT_POSTSCRIPT)
6452 else if (varp == &p_penc)
6453 {
6454 /* Canonize printencoding if VIM standard one */
6455 p = enc_canonize(p_penc);
6456 if (p != NULL)
6457 {
6458 vim_free(p_penc);
6459 p_penc = p;
6460 }
6461 else
6462 {
6463 /* Ensure lower case and '-' for '_' */
6464 for (s = p_penc; *s != NUL; s++)
6465 {
6466 if (*s == '_')
6467 *s = '-';
6468 else
6469 *s = TOLOWER_ASC(*s);
6470 }
6471 }
6472 }
6473#endif
6474
Bram Moolenaar9372a112005-12-06 19:59:18 +00006475#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006476 else if (varp == &p_imak)
6477 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006478 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006479 errmsg = e_invarg;
6480 }
6481#endif
6482
6483#ifdef FEAT_KEYMAP
6484 else if (varp == &curbuf->b_p_keymap)
6485 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006486 if (!valid_filetype(*varp))
6487 errmsg = e_invarg;
6488 else
6489 /* load or unload key mapping tables */
6490 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006491
Bram Moolenaarfab06232009-03-04 03:13:35 +00006492 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006493 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006494 if (*curbuf->b_p_keymap != NUL)
6495 {
6496 /* Installed a new keymap, switch on using it. */
6497 curbuf->b_p_iminsert = B_IMODE_LMAP;
6498 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6499 curbuf->b_p_imsearch = B_IMODE_LMAP;
6500 }
6501 else
6502 {
6503 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6504 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6505 curbuf->b_p_iminsert = B_IMODE_NONE;
6506 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6507 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6508 }
6509 if ((opt_flags & OPT_LOCAL) == 0)
6510 {
6511 set_iminsert_global();
6512 set_imsearch_global();
6513 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006514# ifdef FEAT_WINDOWS
6515 status_redraw_curbuf();
6516# endif
6517 }
6518 }
6519#endif
6520
6521 /* 'fileformat' */
6522 else if (gvarp == &p_ff)
6523 {
6524 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6525 errmsg = e_modifiable;
6526 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6527 errmsg = e_invarg;
6528 else
6529 {
6530 /* may also change 'textmode' */
6531 if (get_fileformat(curbuf) == EOL_DOS)
6532 curbuf->b_p_tx = TRUE;
6533 else
6534 curbuf->b_p_tx = FALSE;
6535#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006536 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006537#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006538 /* update flag in swap file */
6539 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006540 /* Redraw needed when switching to/from "mac": a CR in the text
6541 * will be displayed differently. */
6542 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6543 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006544 }
6545 }
6546
6547 /* 'fileformats' */
6548 else if (varp == &p_ffs)
6549 {
6550 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6551 errmsg = e_invarg;
6552 else
6553 {
6554 /* also change 'textauto' */
6555 if (*p_ffs == NUL)
6556 p_ta = FALSE;
6557 else
6558 p_ta = TRUE;
6559 }
6560 }
6561
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006562#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563 /* 'cryptkey' */
6564 else if (gvarp == &p_key)
6565 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006566# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006567 /* Make sure the ":set" command doesn't show the new value in the
6568 * history. */
6569 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006570# endif
6571 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6572 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006573 ml_set_crypt_key(curbuf, oldval,
6574 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006575 }
6576
6577 else if (gvarp == &p_cm)
6578 {
6579 if (opt_flags & OPT_LOCAL)
6580 p = curbuf->b_p_cm;
6581 else
6582 p = p_cm;
6583 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6584 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006585 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006586 errmsg = e_invarg;
6587 else
6588 {
6589 /* When setting the global value to empty, make it "zip". */
6590 if (*p_cm == NUL)
6591 {
6592 if (new_value_alloced)
6593 free_string_option(p_cm);
6594 p_cm = vim_strsave((char_u *)"zip");
6595 new_value_alloced = TRUE;
6596 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006597 /* When using ":set cm=name" the local value is going to be empty.
6598 * Do that here, otherwise the crypt functions will still use the
6599 * local value. */
6600 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6601 {
6602 free_string_option(curbuf->b_p_cm);
6603 curbuf->b_p_cm = empty_option;
6604 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006605
6606 /* Need to update the swapfile when the effective method changed.
6607 * Set "s" to the effective old value, "p" to the effective new
6608 * method and compare. */
6609 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6610 s = p_cm; /* was previously using the global value */
6611 else
6612 s = oldval;
6613 if (*curbuf->b_p_cm == NUL)
6614 p = p_cm; /* is now using the global value */
6615 else
6616 p = curbuf->b_p_cm;
6617 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006618 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006619
6620 /* If the global value changes need to update the swapfile for all
6621 * buffers using that value. */
6622 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6623 {
6624 buf_T *buf;
6625
Bram Moolenaar29323592016-07-24 22:04:11 +02006626 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006627 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006628 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006629 }
6630 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631 }
6632#endif
6633
6634 /* 'matchpairs' */
6635 else if (gvarp == &p_mps)
6636 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006637#ifdef FEAT_MBYTE
6638 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006639 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006640 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006641 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006642 int x2 = -1;
6643 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006644
6645 if (*p != NUL)
6646 p += mb_ptr2len(p);
6647 if (*p != NUL)
6648 x2 = *p++;
6649 if (*p != NUL)
6650 {
6651 x3 = mb_ptr2char(p);
6652 p += mb_ptr2len(p);
6653 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006654 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006655 {
6656 errmsg = e_invarg;
6657 break;
6658 }
6659 if (*p == NUL)
6660 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006661 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006662 }
6663 else
6664#endif
6665 {
6666 /* Check for "x:y,x:y" */
6667 for (p = *varp; *p != NUL; p += 4)
6668 {
6669 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6670 {
6671 errmsg = e_invarg;
6672 break;
6673 }
6674 if (p[3] == NUL)
6675 break;
6676 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006677 }
6678 }
6679
6680#ifdef FEAT_COMMENTS
6681 /* 'comments' */
6682 else if (gvarp == &p_com)
6683 {
6684 for (s = *varp; *s; )
6685 {
6686 while (*s && *s != ':')
6687 {
6688 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6689 && !VIM_ISDIGIT(*s) && *s != '-')
6690 {
6691 errmsg = illegal_char(errbuf, *s);
6692 break;
6693 }
6694 ++s;
6695 }
6696 if (*s++ == NUL)
6697 errmsg = (char_u *)N_("E524: Missing colon");
6698 else if (*s == ',' || *s == NUL)
6699 errmsg = (char_u *)N_("E525: Zero length string");
6700 if (errmsg != NULL)
6701 break;
6702 while (*s && *s != ',')
6703 {
6704 if (*s == '\\' && s[1] != NUL)
6705 ++s;
6706 ++s;
6707 }
6708 s = skip_to_option_part(s);
6709 }
6710 }
6711#endif
6712
6713 /* 'listchars' */
6714 else if (varp == &p_lcs)
6715 {
6716 errmsg = set_chars_option(varp);
6717 }
6718
6719#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6720 /* 'fillchars' */
6721 else if (varp == &p_fcs)
6722 {
6723 errmsg = set_chars_option(varp);
6724 }
6725#endif
6726
6727#ifdef FEAT_CMDWIN
6728 /* 'cedit' */
6729 else if (varp == &p_cedit)
6730 {
6731 errmsg = check_cedit();
6732 }
6733#endif
6734
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006735 /* 'verbosefile' */
6736 else if (varp == &p_vfile)
6737 {
6738 verbose_stop();
6739 if (*p_vfile != NUL && verbose_open() == FAIL)
6740 errmsg = e_invarg;
6741 }
6742
Bram Moolenaar071d4272004-06-13 20:20:40 +00006743#ifdef FEAT_VIMINFO
6744 /* 'viminfo' */
6745 else if (varp == &p_viminfo)
6746 {
6747 for (s = p_viminfo; *s;)
6748 {
6749 /* Check it's a valid character */
6750 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6751 {
6752 errmsg = illegal_char(errbuf, *s);
6753 break;
6754 }
6755 if (*s == 'n') /* name is always last one */
6756 {
6757 break;
6758 }
6759 else if (*s == 'r') /* skip until next ',' */
6760 {
6761 while (*++s && *s != ',')
6762 ;
6763 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006764 else if (*s == '%')
6765 {
6766 /* optional number */
6767 while (vim_isdigit(*++s))
6768 ;
6769 }
6770 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006771 ++s; /* no extra chars */
6772 else /* must have a number */
6773 {
6774 while (vim_isdigit(*++s))
6775 ;
6776
6777 if (!VIM_ISDIGIT(*(s - 1)))
6778 {
6779 if (errbuf != NULL)
6780 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006781 sprintf((char *)errbuf,
6782 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 transchar_byte(*(s - 1)));
6784 errmsg = errbuf;
6785 }
6786 else
6787 errmsg = (char_u *)"";
6788 break;
6789 }
6790 }
6791 if (*s == ',')
6792 ++s;
6793 else if (*s)
6794 {
6795 if (errbuf != NULL)
6796 errmsg = (char_u *)N_("E527: Missing comma");
6797 else
6798 errmsg = (char_u *)"";
6799 break;
6800 }
6801 }
6802 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6803 errmsg = (char_u *)N_("E528: Must specify a ' value");
6804 }
6805#endif /* FEAT_VIMINFO */
6806
6807 /* terminal options */
6808 else if (istermoption(&options[opt_idx]) && full_screen)
6809 {
6810 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6811 if (varp == &T_CCO)
6812 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006813 int colors = atoi((char *)T_CCO);
6814
6815 /* Only reinitialize colors if t_Co value has really changed to
6816 * avoid expensive reload of colorscheme if t_Co is set to the
6817 * same value multiple times. */
6818 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006819 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006820 t_colors = colors;
6821 if (t_colors <= 1)
6822 {
6823 if (new_value_alloced)
6824 vim_free(T_CCO);
6825 T_CCO = empty_option;
6826 }
6827 /* We now have a different color setup, initialize it again. */
6828 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006830 }
6831 ttest(FALSE);
6832 if (varp == &T_ME)
6833 {
6834 out_str(T_ME);
6835 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006836#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006837 /* Since t_me has been set, this probably means that the user
6838 * wants to use this as default colors. Need to reset default
6839 * background/foreground colors. */
6840 mch_set_normal_colors();
6841#endif
6842 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006843 if (varp == &T_BE && termcap_active)
6844 {
6845 if (*T_BE == NUL)
6846 /* When clearing t_BE we assume the user no longer wants
6847 * bracketed paste, thus disable it by writing t_BD. */
6848 out_str(T_BD);
6849 else
6850 out_str(T_BE);
6851 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006852 }
6853
6854#ifdef FEAT_LINEBREAK
6855 /* 'showbreak' */
6856 else if (varp == &p_sbr)
6857 {
6858 for (s = p_sbr; *s; )
6859 {
6860 if (ptr2cells(s) != 1)
6861 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006862 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006863 }
6864 }
6865#endif
6866
6867#ifdef FEAT_GUI
6868 /* 'guifont' */
6869 else if (varp == &p_guifont)
6870 {
6871 if (gui.in_use)
6872 {
6873 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006874# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006875 /*
6876 * Put up a font dialog and let the user select a new value.
6877 * If this is cancelled go back to the old value but don't
6878 * give an error message.
6879 */
6880 if (STRCMP(p, "*") == 0)
6881 {
6882 p = gui_mch_font_dialog(oldval);
6883
6884 if (new_value_alloced)
6885 free_string_option(p_guifont);
6886
6887 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6888 new_value_alloced = TRUE;
6889 }
6890# endif
6891 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6892 {
6893# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6894 if (STRCMP(p_guifont, "*") == 0)
6895 {
6896 /* Dialog was cancelled: Keep the old value without giving
6897 * an error message. */
6898 if (new_value_alloced)
6899 free_string_option(p_guifont);
6900 p_guifont = vim_strsave(oldval);
6901 new_value_alloced = TRUE;
6902 }
6903 else
6904# endif
6905 errmsg = (char_u *)N_("E596: Invalid font(s)");
6906 }
6907 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006908 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006909 }
6910# ifdef FEAT_XFONTSET
6911 else if (varp == &p_guifontset)
6912 {
6913 if (STRCMP(p_guifontset, "*") == 0)
6914 errmsg = (char_u *)N_("E597: can't select fontset");
6915 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6916 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006917 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006918 }
6919# endif
6920# ifdef FEAT_MBYTE
6921 else if (varp == &p_guifontwide)
6922 {
6923 if (STRCMP(p_guifontwide, "*") == 0)
6924 errmsg = (char_u *)N_("E533: can't select wide font");
6925 else if (gui_get_wide_font() == FAIL)
6926 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006927 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006928 }
6929# endif
6930#endif
6931
6932#ifdef CURSOR_SHAPE
6933 /* 'guicursor' */
6934 else if (varp == &p_guicursor)
6935 errmsg = parse_shape_opt(SHAPE_CURSOR);
6936#endif
6937
6938#ifdef FEAT_MOUSESHAPE
6939 /* 'mouseshape' */
6940 else if (varp == &p_mouseshape)
6941 {
6942 errmsg = parse_shape_opt(SHAPE_MOUSE);
6943 update_mouseshape(-1);
6944 }
6945#endif
6946
6947#ifdef FEAT_PRINTER
6948 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006949 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006950# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006951 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006952 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006953# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006954#endif
6955
6956#ifdef FEAT_LANGMAP
6957 /* 'langmap' */
6958 else if (varp == &p_langmap)
6959 langmap_set();
6960#endif
6961
6962#ifdef FEAT_LINEBREAK
6963 /* 'breakat' */
6964 else if (varp == &p_breakat)
6965 fill_breakat_flags();
6966#endif
6967
6968#ifdef FEAT_TITLE
6969 /* 'titlestring' and 'iconstring' */
6970 else if (varp == &p_titlestring || varp == &p_iconstring)
6971 {
6972# ifdef FEAT_STL_OPT
6973 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6974
6975 /* NULL => statusline syntax */
6976 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6977 stl_syntax |= flagval;
6978 else
6979 stl_syntax &= ~flagval;
6980# endif
6981 did_set_title(varp == &p_iconstring);
6982
6983 }
6984#endif
6985
6986#ifdef FEAT_GUI
6987 /* 'guioptions' */
6988 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006989 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006990 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006991 redraw_gui_only = TRUE;
6992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993#endif
6994
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006995#if defined(FEAT_GUI_TABLINE)
6996 /* 'guitablabel' */
6997 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006998 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006999 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007000 redraw_gui_only = TRUE;
7001 }
7002 /* 'guitabtooltip' */
7003 else if (varp == &p_gtt)
7004 {
7005 redraw_gui_only = TRUE;
7006 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007007#endif
7008
Bram Moolenaar071d4272004-06-13 20:20:40 +00007009#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7010 /* 'ttymouse' */
7011 else if (varp == &p_ttym)
7012 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007013 /* Switch the mouse off before changing the escape sequences used for
7014 * that. */
7015 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007016 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7017 errmsg = e_invarg;
7018 else
7019 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007020 if (termcap_active)
7021 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007022 }
7023#endif
7024
Bram Moolenaar071d4272004-06-13 20:20:40 +00007025 /* 'selection' */
7026 else if (varp == &p_sel)
7027 {
7028 if (*p_sel == NUL
7029 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7030 errmsg = e_invarg;
7031 }
7032
7033 /* 'selectmode' */
7034 else if (varp == &p_slm)
7035 {
7036 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7037 errmsg = e_invarg;
7038 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007039
7040#ifdef FEAT_BROWSE
7041 /* 'browsedir' */
7042 else if (varp == &p_bsdir)
7043 {
7044 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7045 && !mch_isdir(p_bsdir))
7046 errmsg = e_invarg;
7047 }
7048#endif
7049
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050 /* 'keymodel' */
7051 else if (varp == &p_km)
7052 {
7053 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7054 errmsg = e_invarg;
7055 else
7056 {
7057 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7058 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7059 }
7060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007061
7062 /* 'mousemodel' */
7063 else if (varp == &p_mousem)
7064 {
7065 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7066 errmsg = e_invarg;
7067#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7068 else if (*p_mousem != *oldval)
7069 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7070 * to create or delete the popup menus. */
7071 gui_motif_update_mousemodel(root_menu);
7072#endif
7073 }
7074
7075 /* 'switchbuf' */
7076 else if (varp == &p_swb)
7077 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007078 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007079 errmsg = e_invarg;
7080 }
7081
7082 /* 'debug' */
7083 else if (varp == &p_debug)
7084 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007085 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007086 errmsg = e_invarg;
7087 }
7088
7089 /* 'display' */
7090 else if (varp == &p_dy)
7091 {
7092 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7093 errmsg = e_invarg;
7094 else
7095 (void)init_chartab();
7096
7097 }
7098
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007099#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007100 /* 'eadirection' */
7101 else if (varp == &p_ead)
7102 {
7103 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7104 errmsg = e_invarg;
7105 }
7106#endif
7107
7108#ifdef FEAT_CLIPBOARD
7109 /* 'clipboard' */
7110 else if (varp == &p_cb)
7111 errmsg = check_clipboard_option();
7112#endif
7113
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007114#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007115 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7116 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007117 else if (varp == &(curwin->w_s->b_p_spl)
7118 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007119 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007120 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007121 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007122 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007123 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007124 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007125 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007126 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007127 /* 'spellsuggest' */
7128 else if (varp == &p_sps)
7129 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007130 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007131 errmsg = e_invarg;
7132 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007133 /* 'mkspellmem' */
7134 else if (varp == &p_msm)
7135 {
7136 if (spell_check_msm() != OK)
7137 errmsg = e_invarg;
7138 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007139#endif
7140
Bram Moolenaar071d4272004-06-13 20:20:40 +00007141 /* When 'bufhidden' is set, check for valid value. */
7142 else if (gvarp == &p_bh)
7143 {
7144 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7145 errmsg = e_invarg;
7146 }
7147
7148 /* When 'buftype' is set, check for valid value. */
7149 else if (gvarp == &p_bt)
7150 {
7151 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7152 errmsg = e_invarg;
7153 else
7154 {
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007155#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007156 if (curwin->w_status_height)
7157 {
7158 curwin->w_redr_status = TRUE;
7159 redraw_later(VALID);
7160 }
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007161#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007162 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007163#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007164 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007165#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007166 }
7167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007168
7169#ifdef FEAT_STL_OPT
7170 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007171 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007172 {
7173 int wid;
7174
7175 if (varp == &p_ruf) /* reset ru_wid first */
7176 ru_wid = 0;
7177 s = *varp;
7178 if (varp == &p_ruf && *s == '%')
7179 {
7180 /* set ru_wid if 'ruf' starts with "%99(" */
7181 if (*++s == '-') /* ignore a '-' */
7182 s++;
7183 wid = getdigits(&s);
7184 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7185 ru_wid = wid;
7186 else
7187 errmsg = check_stl_option(p_ruf);
7188 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007189 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007190 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007191 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007192 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007193 comp_col();
7194 }
7195#endif
7196
7197#ifdef FEAT_INS_EXPAND
7198 /* check if it is a valid value for 'complete' -- Acevedo */
7199 else if (gvarp == &p_cpt)
7200 {
7201 for (s = *varp; *s;)
7202 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007203 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007204 s++;
7205 if (!*s)
7206 break;
7207 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7208 {
7209 errmsg = illegal_char(errbuf, *s);
7210 break;
7211 }
7212 if (*++s != NUL && *s != ',' && *s != ' ')
7213 {
7214 if (s[-1] == 'k' || s[-1] == 's')
7215 {
7216 /* skip optional filename after 'k' and 's' */
7217 while (*s && *s != ',' && *s != ' ')
7218 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007219 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007220 ++s;
7221 ++s;
7222 }
7223 }
7224 else
7225 {
7226 if (errbuf != NULL)
7227 {
7228 sprintf((char *)errbuf,
7229 _("E535: Illegal character after <%c>"),
7230 *--s);
7231 errmsg = errbuf;
7232 }
7233 else
7234 errmsg = (char_u *)"";
7235 break;
7236 }
7237 }
7238 }
7239 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007240
7241 /* 'completeopt' */
7242 else if (varp == &p_cot)
7243 {
7244 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7245 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007246 else
7247 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007248 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007249#endif /* FEAT_INS_EXPAND */
7250
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007251#ifdef FEAT_SIGNS
7252 /* 'signcolumn' */
7253 else if (varp == &curwin->w_p_scl)
7254 {
7255 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7256 errmsg = e_invarg;
7257 }
7258#endif
7259
Bram Moolenaar071d4272004-06-13 20:20:40 +00007260
7261#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007262 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007263 else if (varp == &p_toolbar)
7264 {
7265 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7266 &toolbar_flags, TRUE) != OK)
7267 errmsg = e_invarg;
7268 else
7269 {
7270 out_flush();
7271 gui_mch_show_toolbar((toolbar_flags &
7272 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7273 }
7274 }
7275#endif
7276
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007277#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007278 /* 'toolbariconsize': GTK+ 2 only */
7279 else if (varp == &p_tbis)
7280 {
7281 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7282 errmsg = e_invarg;
7283 else
7284 {
7285 out_flush();
7286 gui_mch_show_toolbar((toolbar_flags &
7287 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7288 }
7289 }
7290#endif
7291
7292 /* 'pastetoggle': translate key codes like in a mapping */
7293 else if (varp == &p_pt)
7294 {
7295 if (*p_pt)
7296 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007297 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007298 if (p != NULL)
7299 {
7300 if (new_value_alloced)
7301 free_string_option(p_pt);
7302 p_pt = p;
7303 new_value_alloced = TRUE;
7304 }
7305 }
7306 }
7307
7308 /* 'backspace' */
7309 else if (varp == &p_bs)
7310 {
7311 if (VIM_ISDIGIT(*p_bs))
7312 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007313 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007314 errmsg = e_invarg;
7315 }
7316 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7317 errmsg = e_invarg;
7318 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007319 else if (varp == &p_bo)
7320 {
7321 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7322 errmsg = e_invarg;
7323 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007324
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007325 /* 'tagcase' */
7326 else if (gvarp == &p_tc)
7327 {
7328 unsigned int *flags;
7329
7330 if (opt_flags & OPT_LOCAL)
7331 {
7332 p = curbuf->b_p_tc;
7333 flags = &curbuf->b_tc_flags;
7334 }
7335 else
7336 {
7337 p = p_tc;
7338 flags = &tc_flags;
7339 }
7340
7341 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7342 /* make the local value empty: use the global value */
7343 *flags = 0;
7344 else if (*p == NUL
7345 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7346 errmsg = e_invarg;
7347 }
7348
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007349#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350 /* 'casemap' */
7351 else if (varp == &p_cmp)
7352 {
7353 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7354 errmsg = e_invarg;
7355 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007356#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007357
7358#ifdef FEAT_DIFF
7359 /* 'diffopt' */
7360 else if (varp == &p_dip)
7361 {
7362 if (diffopt_changed() == FAIL)
7363 errmsg = e_invarg;
7364 }
7365#endif
7366
7367#ifdef FEAT_FOLDING
7368 /* 'foldmethod' */
7369 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7370 {
7371 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7372 || *curwin->w_p_fdm == NUL)
7373 errmsg = e_invarg;
7374 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007375 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007376 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007377 if (foldmethodIsDiff(curwin))
7378 newFoldLevel();
7379 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007380 }
7381# ifdef FEAT_EVAL
7382 /* 'foldexpr' */
7383 else if (varp == &curwin->w_p_fde)
7384 {
7385 if (foldmethodIsExpr(curwin))
7386 foldUpdateAll(curwin);
7387 }
7388# endif
7389 /* 'foldmarker' */
7390 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7391 {
7392 p = vim_strchr(*varp, ',');
7393 if (p == NULL)
7394 errmsg = (char_u *)N_("E536: comma required");
7395 else if (p == *varp || p[1] == NUL)
7396 errmsg = e_invarg;
7397 else if (foldmethodIsMarker(curwin))
7398 foldUpdateAll(curwin);
7399 }
7400 /* 'commentstring' */
7401 else if (gvarp == &p_cms)
7402 {
7403 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7404 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7405 }
7406 /* 'foldopen' */
7407 else if (varp == &p_fdo)
7408 {
7409 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7410 errmsg = e_invarg;
7411 }
7412 /* 'foldclose' */
7413 else if (varp == &p_fcl)
7414 {
7415 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7416 errmsg = e_invarg;
7417 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007418 /* 'foldignore' */
7419 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7420 {
7421 if (foldmethodIsIndent(curwin))
7422 foldUpdateAll(curwin);
7423 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007424#endif
7425
7426#ifdef FEAT_VIRTUALEDIT
7427 /* 'virtualedit' */
7428 else if (varp == &p_ve)
7429 {
7430 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7431 errmsg = e_invarg;
7432 else if (STRCMP(p_ve, oldval) != 0)
7433 {
7434 /* Recompute cursor position in case the new 've' setting
7435 * changes something. */
7436 validate_virtcol();
7437 coladvance(curwin->w_virtcol);
7438 }
7439 }
7440#endif
7441
7442#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7443 else if (varp == &p_csqf)
7444 {
7445 if (p_csqf != NULL)
7446 {
7447 p = p_csqf;
7448 while (*p != NUL)
7449 {
7450 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7451 || p[1] == NUL
7452 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7453 || (p[2] != NUL && p[2] != ','))
7454 {
7455 errmsg = e_invarg;
7456 break;
7457 }
7458 else if (p[2] == NUL)
7459 break;
7460 else
7461 p += 3;
7462 }
7463 }
7464 }
7465#endif
7466
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007467#ifdef FEAT_CINDENT
7468 /* 'cinoptions' */
7469 else if (gvarp == &p_cino)
7470 {
7471 /* TODO: recognize errors */
7472 parse_cino(curbuf);
7473 }
7474#endif
7475
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007476#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007477 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007478 else if (varp == &p_rop && gui.in_use)
7479 {
7480 if (!gui_mch_set_rendering_options(p_rop))
7481 errmsg = e_invarg;
7482 }
7483#endif
7484
Bram Moolenaard0b51382016-11-04 15:23:45 +01007485#ifdef FEAT_AUTOCMD
7486 else if (gvarp == &p_ft)
7487 {
7488 if (!valid_filetype(*varp))
7489 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007490 else
7491 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007492 }
7493#endif
7494
7495#ifdef FEAT_SYN_HL
7496 else if (gvarp == &p_syn)
7497 {
7498 if (!valid_filetype(*varp))
7499 errmsg = e_invarg;
7500 }
7501#endif
7502
Bram Moolenaar825680f2017-07-22 17:04:02 +02007503#ifdef FEAT_TERMINAL
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007504 /* 'termkey' */
Bram Moolenaarc4f43bc2017-07-24 20:03:01 +02007505 else if (varp == &curwin->w_p_tk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007506 {
7507 if (*curwin->w_p_tk != NUL && string_to_key(curwin->w_p_tk, TRUE) == 0)
7508 errmsg = e_invarg;
7509 }
Bram Moolenaar825680f2017-07-22 17:04:02 +02007510 /* 'termsize' */
7511 else if (varp == &curwin->w_p_tms)
7512 {
7513 if (*curwin->w_p_tms != NUL)
7514 {
7515 p = skipdigits(curwin->w_p_tms);
7516 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7517 errmsg = e_invarg;
7518 }
7519 }
7520#endif
7521
Bram Moolenaar071d4272004-06-13 20:20:40 +00007522 /* Options that are a list of flags. */
7523 else
7524 {
7525 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007526 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007528 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007529 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007530 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007531 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007532 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007533 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007534#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007535 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007536 p = (char_u *)COCU_ALL;
7537#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007538 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007539 {
7540#ifdef FEAT_MOUSE
7541 p = (char_u *)MOUSE_ALL;
7542#else
7543 if (*p_mouse != NUL)
7544 errmsg = (char_u *)N_("E538: No mouse support");
7545#endif
7546 }
7547#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007548 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007549 p = (char_u *)GO_ALL;
7550#endif
7551 if (p != NULL)
7552 {
7553 for (s = *varp; *s; ++s)
7554 if (vim_strchr(p, *s) == NULL)
7555 {
7556 errmsg = illegal_char(errbuf, *s);
7557 break;
7558 }
7559 }
7560 }
7561
7562 /*
7563 * If error detected, restore the previous value.
7564 */
7565 if (errmsg != NULL)
7566 {
7567 if (new_value_alloced)
7568 free_string_option(*varp);
7569 *varp = oldval;
7570 /*
7571 * When resetting some values, need to act on it.
7572 */
7573 if (did_chartab)
7574 (void)init_chartab();
7575 if (varp == &p_hl)
7576 (void)highlight_changed();
7577 }
7578 else
7579 {
7580#ifdef FEAT_EVAL
7581 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007582 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007583#endif
7584 /*
7585 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007586 * Use "free_oldval", because recursiveness may change the flags under
7587 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007588 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007589 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007590 free_string_option(oldval);
7591 if (new_value_alloced)
7592 options[opt_idx].flags |= P_ALLOCED;
7593 else
7594 options[opt_idx].flags &= ~P_ALLOCED;
7595
7596 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007597 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007598 {
7599 /* global option with local value set to use global value; free
7600 * the local value and make it empty */
7601 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7602 free_string_option(*(char_u **)p);
7603 *(char_u **)p = empty_option;
7604 }
7605
7606 /* May set global value for local option. */
7607 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7608 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007609
7610#ifdef FEAT_AUTOCMD
7611 /*
7612 * Trigger the autocommand only after setting the flags.
7613 */
7614# ifdef FEAT_SYN_HL
7615 /* When 'syntax' is set, load the syntax of that name */
7616 if (varp == &(curbuf->b_p_syn))
7617 {
7618 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7619 curbuf->b_fname, TRUE, curbuf);
7620 }
7621# endif
7622 else if (varp == &(curbuf->b_p_ft))
7623 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007624 /* 'filetype' is set, trigger the FileType autocommand.
7625 * Skip this when called from a modeline and the filetype was
7626 * already set to this value. */
7627 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7628 {
7629 did_filetype = TRUE;
7630 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007631 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007632 /* Just in case the old "curbuf" is now invalid. */
7633 if (varp != &(curbuf->b_p_ft))
7634 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007635 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007636 }
7637#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007638#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007639 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007640 {
7641 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007642 char_u *q = curwin->w_s->b_p_spl;
7643
7644 /* Skip the first name if it is "cjk". */
7645 if (STRNCMP(q, "cjk,", 4) == 0)
7646 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007647
7648 /*
7649 * Source the spell/LANG.vim in 'runtimepath'.
7650 * They could set 'spellcapcheck' depending on the language.
7651 * Use the first name in 'spelllang' up to '_region' or
7652 * '.encoding'.
7653 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007654 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007655 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7656 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007657 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007658 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007659 }
7660#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 }
7662
7663#ifdef FEAT_MOUSE
7664 if (varp == &p_mouse)
7665 {
7666# ifdef FEAT_MOUSE_TTY
7667 if (*p_mouse == NUL)
7668 mch_setmouse(FALSE); /* switch mouse off */
7669 else
7670# endif
7671 setmouse(); /* in case 'mouse' changed */
7672 }
7673#endif
7674
Bram Moolenaar913077c2012-03-28 19:59:04 +02007675 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007676 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007677 curwin->w_set_curswant = TRUE;
7678
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007679#ifdef FEAT_GUI
7680 /* check redraw when it's not a GUI option or the GUI is active. */
7681 if (!redraw_gui_only || gui.in_use)
7682#endif
7683 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007684
7685 return errmsg;
7686}
7687
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007688#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007689/*
7690 * Simple int comparison function for use with qsort()
7691 */
7692 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007693int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007694{
7695 return *(const int *)a - *(const int *)b;
7696}
7697
7698/*
7699 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7700 * Returns error message, NULL if it's OK.
7701 */
7702 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007703check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007704{
7705 char_u *s;
7706 int col;
7707 int count = 0;
7708 int color_cols[256];
7709 int i;
7710 int j = 0;
7711
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007712 if (wp->w_buffer == NULL)
7713 return NULL; /* buffer was closed */
7714
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007715 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007716 {
7717 if (*s == '-' || *s == '+')
7718 {
7719 /* -N and +N: add to 'textwidth' */
7720 col = (*s == '-') ? -1 : 1;
7721 ++s;
7722 if (!VIM_ISDIGIT(*s))
7723 return e_invarg;
7724 col = col * getdigits(&s);
7725 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007726 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007727 col += wp->w_buffer->b_p_tw;
7728 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007729 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007730 }
7731 else if (VIM_ISDIGIT(*s))
7732 col = getdigits(&s);
7733 else
7734 return e_invarg;
7735 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007736skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007737 if (*s == NUL)
7738 break;
7739 if (*s != ',')
7740 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007741 if (*++s == NUL)
7742 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007743 }
7744
7745 vim_free(wp->w_p_cc_cols);
7746 if (count == 0)
7747 wp->w_p_cc_cols = NULL;
7748 else
7749 {
7750 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7751 if (wp->w_p_cc_cols != NULL)
7752 {
7753 /* sort the columns for faster usage on screen redraw inside
7754 * win_line() */
7755 qsort(color_cols, count, sizeof(int), int_cmp);
7756
7757 for (i = 0; i < count; ++i)
7758 /* skip duplicates */
7759 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7760 wp->w_p_cc_cols[j++] = color_cols[i];
7761 wp->w_p_cc_cols[j] = -1; /* end marker */
7762 }
7763 }
7764
7765 return NULL; /* no error */
7766}
7767#endif
7768
Bram Moolenaar071d4272004-06-13 20:20:40 +00007769/*
7770 * Handle setting 'listchars' or 'fillchars'.
7771 * Returns error message, NULL if it's OK.
7772 */
7773 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007774set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007775{
7776 int round, i, len, entries;
7777 char_u *p, *s;
7778 int c1, c2 = 0;
7779 struct charstab
7780 {
7781 int *cp;
7782 char *name;
7783 };
7784#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7785 static struct charstab filltab[] =
7786 {
7787 {&fill_stl, "stl"},
7788 {&fill_stlnc, "stlnc"},
7789 {&fill_vert, "vert"},
7790 {&fill_fold, "fold"},
7791 {&fill_diff, "diff"},
7792 };
7793#endif
7794 static struct charstab lcstab[] =
7795 {
7796 {&lcs_eol, "eol"},
7797 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007798 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007800 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801 {&lcs_tab2, "tab"},
7802 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007803#ifdef FEAT_CONCEAL
7804 {&lcs_conceal, "conceal"},
7805#else
7806 {NULL, "conceal"},
7807#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007808 };
7809 struct charstab *tab;
7810
7811#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7812 if (varp == &p_lcs)
7813#endif
7814 {
7815 tab = lcstab;
7816 entries = sizeof(lcstab) / sizeof(struct charstab);
7817 }
7818#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7819 else
7820 {
7821 tab = filltab;
7822 entries = sizeof(filltab) / sizeof(struct charstab);
7823 }
7824#endif
7825
7826 /* first round: check for valid value, second round: assign values */
7827 for (round = 0; round <= 1; ++round)
7828 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007829 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007830 {
7831 /* After checking that the value is valid: set defaults: space for
7832 * 'fillchars', NUL for 'listchars' */
7833 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007834 if (tab[i].cp != NULL)
7835 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007836 if (varp == &p_lcs)
7837 lcs_tab1 = NUL;
7838#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7839 else
7840 fill_diff = '-';
7841#endif
7842 }
7843 p = *varp;
7844 while (*p)
7845 {
7846 for (i = 0; i < entries; ++i)
7847 {
7848 len = (int)STRLEN(tab[i].name);
7849 if (STRNCMP(p, tab[i].name, len) == 0
7850 && p[len] == ':'
7851 && p[len + 1] != NUL)
7852 {
7853 s = p + len + 1;
7854#ifdef FEAT_MBYTE
7855 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007856 if (mb_char2cells(c1) > 1)
7857 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007858#else
7859 c1 = *s++;
7860#endif
7861 if (tab[i].cp == &lcs_tab2)
7862 {
7863 if (*s == NUL)
7864 continue;
7865#ifdef FEAT_MBYTE
7866 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007867 if (mb_char2cells(c2) > 1)
7868 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869#else
7870 c2 = *s++;
7871#endif
7872 }
7873 if (*s == ',' || *s == NUL)
7874 {
7875 if (round)
7876 {
7877 if (tab[i].cp == &lcs_tab2)
7878 {
7879 lcs_tab1 = c1;
7880 lcs_tab2 = c2;
7881 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007882 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007883 *(tab[i].cp) = c1;
7884
7885 }
7886 p = s;
7887 break;
7888 }
7889 }
7890 }
7891
7892 if (i == entries)
7893 return e_invarg;
7894 if (*p == ',')
7895 ++p;
7896 }
7897 }
7898
7899 return NULL; /* no error */
7900}
7901
7902#ifdef FEAT_STL_OPT
7903/*
7904 * Check validity of options with the 'statusline' format.
7905 * Return error message or NULL.
7906 */
7907 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007908check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909{
7910 int itemcnt = 0;
7911 int groupdepth = 0;
7912 static char_u errbuf[80];
7913
7914 while (*s && itemcnt < STL_MAX_ITEM)
7915 {
7916 /* Check for valid keys after % sequences */
7917 while (*s && *s != '%')
7918 s++;
7919 if (!*s)
7920 break;
7921 s++;
7922 if (*s != '%' && *s != ')')
7923 ++itemcnt;
7924 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7925 {
7926 s++;
7927 continue;
7928 }
7929 if (*s == ')')
7930 {
7931 s++;
7932 if (--groupdepth < 0)
7933 break;
7934 continue;
7935 }
7936 if (*s == '-')
7937 s++;
7938 while (VIM_ISDIGIT(*s))
7939 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007940 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007941 continue;
7942 if (*s == '.')
7943 {
7944 s++;
7945 while (*s && VIM_ISDIGIT(*s))
7946 s++;
7947 }
7948 if (*s == '(')
7949 {
7950 groupdepth++;
7951 continue;
7952 }
7953 if (vim_strchr(STL_ALL, *s) == NULL)
7954 {
7955 return illegal_char(errbuf, *s);
7956 }
7957 if (*s == '{')
7958 {
7959 s++;
7960 while (*s != '}' && *s)
7961 s++;
7962 if (*s != '}')
7963 return (char_u *)N_("E540: Unclosed expression sequence");
7964 }
7965 }
7966 if (itemcnt >= STL_MAX_ITEM)
7967 return (char_u *)N_("E541: too many items");
7968 if (groupdepth != 0)
7969 return (char_u *)N_("E542: unbalanced groups");
7970 return NULL;
7971}
7972#endif
7973
7974#ifdef FEAT_CLIPBOARD
7975/*
7976 * Extract the items in the 'clipboard' option and set global values.
7977 */
7978 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007979check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007981 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007982 int new_autoselect_star = FALSE;
7983 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007984 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007985 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007986 regprog_T *new_exclude_prog = NULL;
7987 char_u *errmsg = NULL;
7988 char_u *p;
7989
7990 for (p = p_cb; *p != NUL; )
7991 {
7992 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7993 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007994 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007995 p += 7;
7996 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007997 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007998 && (p[11] == ',' || p[11] == NUL))
7999 {
8000 new_unnamed |= CLIP_UNNAMED_PLUS;
8001 p += 11;
8002 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008004 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008005 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008006 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 p += 10;
8008 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008009 else if (STRNCMP(p, "autoselectplus", 14) == 0
8010 && (p[14] == ',' || p[14] == NUL))
8011 {
8012 new_autoselect_plus = TRUE;
8013 p += 14;
8014 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008015 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008016 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 {
8018 new_autoselectml = TRUE;
8019 p += 12;
8020 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008021 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8022 {
8023 new_html = TRUE;
8024 p += 4;
8025 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008026 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8027 {
8028 p += 8;
8029 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8030 if (new_exclude_prog == NULL)
8031 errmsg = e_invarg;
8032 break;
8033 }
8034 else
8035 {
8036 errmsg = e_invarg;
8037 break;
8038 }
8039 if (*p == ',')
8040 ++p;
8041 }
8042 if (errmsg == NULL)
8043 {
8044 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008045 clip_autoselect_star = new_autoselect_star;
8046 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008047 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008048 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008049 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008050 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008051#ifdef FEAT_GUI_GTK
8052 if (gui.in_use)
8053 {
8054 gui_gtk_set_selection_targets();
8055 gui_gtk_set_dnd_targets();
8056 }
8057#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008058 }
8059 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008060 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008061
8062 return errmsg;
8063}
8064#endif
8065
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008066#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008067 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008068did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008069{
8070 char_u *errmsg = NULL;
8071 win_T *wp;
8072 int l;
8073
8074 if (is_spellfile)
8075 {
8076 l = (int)STRLEN(curwin->w_s->b_p_spf);
8077 if (l > 0 && (l < 4
8078 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8079 errmsg = e_invarg;
8080 }
8081
8082 if (errmsg == NULL)
8083 {
8084 FOR_ALL_WINDOWS(wp)
8085 if (wp->w_buffer == curbuf && wp->w_p_spell)
8086 {
8087 errmsg = did_set_spelllang(wp);
8088# ifdef FEAT_WINDOWS
8089 break;
8090# endif
8091 }
8092 }
8093 return errmsg;
8094}
8095
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008096/*
8097 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8098 * Return error message when failed, NULL when OK.
8099 */
8100 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008101compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008102{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008103 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008104 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008105
Bram Moolenaar860cae12010-06-05 23:22:07 +02008106 if (*synblock->b_p_spc == NUL)
8107 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008108 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008109 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008110 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008111 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008112 if (re != NULL)
8113 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008114 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008115 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008116 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008117 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008118 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008119 return e_invarg;
8120 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008121 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008122 }
8123
Bram Moolenaar473de612013-06-08 18:19:48 +02008124 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008125 return NULL;
8126}
8127#endif
8128
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008129#if defined(FEAT_EVAL) || defined(PROTO)
8130/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008131 * Set the scriptID for an option, taking care of setting the buffer- or
8132 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008133 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008134 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008135set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008136{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008137 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8138 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008139
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008140 /* Remember where the option was set. For local options need to do that
8141 * in the buffer or window structure. */
8142 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008143 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008144 if (both || (opt_flags & OPT_LOCAL))
8145 {
8146 if (indir & PV_BUF)
8147 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8148 else if (indir & PV_WIN)
8149 curwin->w_p_scriptID[indir & PV_MASK] = id;
8150 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008151}
8152#endif
8153
Bram Moolenaar071d4272004-06-13 20:20:40 +00008154/*
8155 * Set the value of a boolean option, and take care of side effects.
8156 * Returns NULL for success, or an error message for an error.
8157 */
8158 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008159set_bool_option(
8160 int opt_idx, /* index in options[] table */
8161 char_u *varp, /* pointer to the option variable */
8162 int value, /* new value */
8163 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164{
8165 int old_value = *(int *)varp;
8166
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 /* Disallow changing some options from secure mode */
8168 if ((secure
8169#ifdef HAVE_SANDBOX
8170 || sandbox != 0
8171#endif
8172 ) && (options[opt_idx].flags & P_SECURE))
8173 return e_secure;
8174
8175 *(int *)varp = value; /* set the new value */
8176#ifdef FEAT_EVAL
8177 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008178 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008179#endif
8180
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008181#ifdef FEAT_GUI
8182 need_mouse_correct = TRUE;
8183#endif
8184
Bram Moolenaar071d4272004-06-13 20:20:40 +00008185 /* May set global value for local option. */
8186 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8187 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8188
8189 /*
8190 * Handle side effects of changing a bool option.
8191 */
8192
8193 /* 'compatible' */
8194 if ((int *)varp == &p_cp)
8195 {
8196 compatible_set();
8197 }
8198
Bram Moolenaar920694c2016-08-21 17:45:02 +02008199#ifdef FEAT_LANGMAP
8200 if ((int *)varp == &p_lrm)
8201 /* 'langremap' -> !'langnoremap' */
8202 p_lnr = !p_lrm;
8203 else if ((int *)varp == &p_lnr)
8204 /* 'langnoremap' -> !'langremap' */
8205 p_lrm = !p_lnr;
8206#endif
8207
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008208#ifdef FEAT_PERSISTENT_UNDO
8209 /* 'undofile' */
8210 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8211 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008212 /* Only take action when the option was set. When reset we do not
8213 * delete the undo file, the option may be set again without making
8214 * any changes in between. */
8215 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008216 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008217 char_u hash[UNDO_HASH_SIZE];
8218 buf_T *save_curbuf = curbuf;
8219
Bram Moolenaar29323592016-07-24 22:04:11 +02008220 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008221 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008222 /* When 'undofile' is set globally: for every buffer, otherwise
8223 * only for the current buffer: Try to read in the undofile,
8224 * if one exists, the buffer wasn't changed and the buffer was
8225 * loaded */
8226 if ((curbuf == save_curbuf
8227 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8228 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8229 {
8230 u_compute_hash(hash);
8231 u_read_undo(NULL, hash, curbuf->b_fname);
8232 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008233 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008234 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008235 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008236 }
8237#endif
8238
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239 else if ((int *)varp == &curbuf->b_p_ro)
8240 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008241 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008242 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8243 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008244
8245 /* when 'readonly' is set may give W10 again */
8246 if (curbuf->b_p_ro)
8247 curbuf->b_did_warn = FALSE;
8248
Bram Moolenaar071d4272004-06-13 20:20:40 +00008249#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008250 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251#endif
8252 }
8253
Bram Moolenaar9c449722010-07-20 18:44:27 +02008254#ifdef FEAT_GUI
8255 else if ((int *)varp == &p_mh)
8256 {
8257 if (!p_mh)
8258 gui_mch_mousehide(FALSE);
8259 }
8260#endif
8261
Bram Moolenaara539df02010-08-01 14:35:05 +02008262 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008263 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008264 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008265# ifdef FEAT_TERMINAL
8266 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaar6d819742017-08-06 14:57:49 +02008267 if (term_in_normal_mode()
Bram Moolenaar20e6cd02017-08-01 20:25:22 +02008268 || (bt_terminal(curbuf) && !term_is_finished(curbuf)))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008269 {
8270 curbuf->b_p_ma = FALSE;
8271 return (char_u *)N_("E946: Cannot make a terminal with running job modifiable");
8272 }
8273# endif
8274# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008275 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008276# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008277 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008278#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008279 /* when 'endofline' is changed, redraw the window title */
8280 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008281 {
8282 redraw_titles();
8283 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008284 /* when 'fixeol' is changed, redraw the window title */
8285 else if ((int *)varp == &curbuf->b_p_fixeol)
8286 {
8287 redraw_titles();
8288 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008289# ifdef FEAT_MBYTE
8290 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008291 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008292 {
8293 redraw_titles();
8294 }
8295# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008296#endif
8297
8298 /* when 'bin' is set also set some other options */
8299 else if ((int *)varp == &curbuf->b_p_bin)
8300 {
8301 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8302#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008303 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008304#endif
8305 }
8306
8307#ifdef FEAT_AUTOCMD
8308 /* when 'buflisted' changes, trigger autocommands */
8309 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8310 {
8311 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8312 NULL, NULL, TRUE, curbuf);
8313 }
8314#endif
8315
8316 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8317 else if ((int *)varp == &curbuf->b_p_swf)
8318 {
8319 if (curbuf->b_p_swf && p_uc)
8320 ml_open_file(curbuf); /* create the swap file */
8321 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008322 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8323 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324 mf_close_file(curbuf, TRUE); /* remove the swap file */
8325 }
8326
8327 /* when 'terse' is set change 'shortmess' */
8328 else if ((int *)varp == &p_terse)
8329 {
8330 char_u *p;
8331
8332 p = vim_strchr(p_shm, SHM_SEARCH);
8333
8334 /* insert 's' in p_shm */
8335 if (p_terse && p == NULL)
8336 {
8337 STRCPY(IObuff, p_shm);
8338 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008339 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008340 }
8341 /* remove 's' from p_shm */
8342 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008343 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008344 }
8345
8346 /* when 'paste' is set or reset also change other options */
8347 else if ((int *)varp == &p_paste)
8348 {
8349 paste_option_changed();
8350 }
8351
8352 /* when 'insertmode' is set from an autocommand need to do work here */
8353 else if ((int *)varp == &p_im)
8354 {
8355 if (p_im)
8356 {
8357 if ((State & INSERT) == 0)
8358 need_start_insertmode = TRUE;
8359 stop_insert_mode = FALSE;
8360 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008361 /* only reset if it was set previously */
8362 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363 {
8364 need_start_insertmode = FALSE;
8365 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008366 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008367 clear_cmdline = TRUE; /* remove "(insert)" */
8368 restart_edit = 0;
8369 }
8370 }
8371
8372 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8373 else if ((int *)varp == &p_ic && p_hls)
8374 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008375 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008376 }
8377
8378#ifdef FEAT_SEARCH_EXTRA
8379 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8380 else if ((int *)varp == &p_hls)
8381 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008382 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383 }
8384#endif
8385
8386#ifdef FEAT_SCROLLBIND
8387 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8388 * at the end of normal_cmd() */
8389 else if ((int *)varp == &curwin->w_p_scb)
8390 {
8391 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008392 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008393 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008394 curwin->w_scbind_pos = curwin->w_topline;
8395 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008396 }
8397#endif
8398
8399#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8400 /* There can be only one window with 'previewwindow' set. */
8401 else if ((int *)varp == &curwin->w_p_pvw)
8402 {
8403 if (curwin->w_p_pvw)
8404 {
8405 win_T *win;
8406
Bram Moolenaar29323592016-07-24 22:04:11 +02008407 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408 if (win->w_p_pvw && win != curwin)
8409 {
8410 curwin->w_p_pvw = FALSE;
8411 return (char_u *)N_("E590: A preview window already exists");
8412 }
8413 }
8414 }
8415#endif
8416
8417 /* when 'textmode' is set or reset also change 'fileformat' */
8418 else if ((int *)varp == &curbuf->b_p_tx)
8419 {
8420 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8421 }
8422
8423 /* when 'textauto' is set or reset also change 'fileformats' */
8424 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008425 set_string_option_direct((char_u *)"ffs", -1,
8426 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008427 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428
8429 /*
8430 * When 'lisp' option changes include/exclude '-' in
8431 * keyword characters.
8432 */
8433#ifdef FEAT_LISP
8434 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8435 {
8436 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8437 }
8438#endif
8439
8440#ifdef FEAT_TITLE
8441 /* when 'title' changed, may need to change the title; same for 'icon' */
8442 else if ((int *)varp == &p_title)
8443 {
8444 did_set_title(FALSE);
8445 }
8446
8447 else if ((int *)varp == &p_icon)
8448 {
8449 did_set_title(TRUE);
8450 }
8451#endif
8452
8453 else if ((int *)varp == &curbuf->b_changed)
8454 {
8455 if (!value)
8456 save_file_ff(curbuf); /* Buffer is unchanged */
8457#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008458 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008459#endif
8460#ifdef FEAT_AUTOCMD
8461 modified_was_set = value;
8462#endif
8463 }
8464
8465#ifdef BACKSLASH_IN_FILENAME
8466 else if ((int *)varp == &p_ssl)
8467 {
8468 if (p_ssl)
8469 {
8470 psepc = '/';
8471 psepcN = '\\';
8472 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 }
8474 else
8475 {
8476 psepc = '\\';
8477 psepcN = '/';
8478 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008479 }
8480
8481 /* need to adjust the file name arguments and buffer names. */
8482 buflist_slash_adjust();
8483 alist_slash_adjust();
8484# ifdef FEAT_EVAL
8485 scriptnames_slash_adjust();
8486# endif
8487 }
8488#endif
8489
8490 /* If 'wrap' is set, set w_leftcol to zero. */
8491 else if ((int *)varp == &curwin->w_p_wrap)
8492 {
8493 if (curwin->w_p_wrap)
8494 curwin->w_leftcol = 0;
8495 }
8496
8497#ifdef FEAT_WINDOWS
8498 else if ((int *)varp == &p_ea)
8499 {
8500 if (p_ea && !old_value)
8501 win_equal(curwin, FALSE, 0);
8502 }
8503#endif
8504
8505 else if ((int *)varp == &p_wiv)
8506 {
8507 /*
8508 * When 'weirdinvert' changed, set/reset 't_xs'.
8509 * Then set 'weirdinvert' according to value of 't_xs'.
8510 */
8511 if (p_wiv && !old_value)
8512 T_XS = (char_u *)"y";
8513 else if (!p_wiv && old_value)
8514 T_XS = empty_option;
8515 p_wiv = (*T_XS != NUL);
8516 }
8517
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008518#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008519 else if ((int *)varp == &p_beval)
8520 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008521 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008522 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008523 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008524 gui_mch_disable_beval_area(balloonEval);
8525 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008526#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008527
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008528#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008529 else if ((int *)varp == &p_acd)
8530 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008531 /* Change directories when the 'acd' option is set now. */
8532 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533 }
8534#endif
8535
8536#ifdef FEAT_DIFF
8537 /* 'diff' */
8538 else if ((int *)varp == &curwin->w_p_diff)
8539 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008540 /* May add or remove the buffer from the list of diff buffers. */
8541 diff_buf_adjust(curwin);
8542# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008543 if (foldmethodIsDiff(curwin))
8544 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008545# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008546 }
8547#endif
8548
8549#ifdef USE_IM_CONTROL
8550 /* 'imdisable' */
8551 else if ((int *)varp == &p_imdisable)
8552 {
8553 /* Only de-activate it here, it will be enabled when changing mode. */
8554 if (p_imdisable)
8555 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008556 else if (State & INSERT)
8557 /* When the option is set from an autocommand, it may need to take
8558 * effect right away. */
8559 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560 }
8561#endif
8562
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008563#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008564 /* 'spell' */
8565 else if ((int *)varp == &curwin->w_p_spell)
8566 {
8567 if (curwin->w_p_spell)
8568 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008569 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008570 if (errmsg != NULL)
8571 EMSG(_(errmsg));
8572 }
8573 }
8574#endif
8575
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576#ifdef FEAT_FKMAP
8577 else if ((int *)varp == &p_altkeymap)
8578 {
8579 if (old_value != p_altkeymap)
8580 {
8581 if (!p_altkeymap)
8582 {
8583 p_hkmap = p_fkmap;
8584 p_fkmap = 0;
8585 }
8586 else
8587 {
8588 p_fkmap = p_hkmap;
8589 p_hkmap = 0;
8590 }
8591 (void)init_chartab();
8592 }
8593 }
8594
8595 /*
8596 * In case some second language keymapping options have changed, check
8597 * and correct the setting in a consistent way.
8598 */
8599
8600 /*
8601 * If hkmap or fkmap are set, reset Arabic keymapping.
8602 */
8603 if ((p_hkmap || p_fkmap) && p_altkeymap)
8604 {
8605 p_altkeymap = p_fkmap;
8606# ifdef FEAT_ARABIC
8607 curwin->w_p_arab = FALSE;
8608# endif
8609 (void)init_chartab();
8610 }
8611
8612 /*
8613 * If hkmap set, reset Farsi keymapping.
8614 */
8615 if (p_hkmap && p_altkeymap)
8616 {
8617 p_altkeymap = 0;
8618 p_fkmap = 0;
8619# ifdef FEAT_ARABIC
8620 curwin->w_p_arab = FALSE;
8621# endif
8622 (void)init_chartab();
8623 }
8624
8625 /*
8626 * If fkmap set, reset Hebrew keymapping.
8627 */
8628 if (p_fkmap && !p_altkeymap)
8629 {
8630 p_altkeymap = 1;
8631 p_hkmap = 0;
8632# ifdef FEAT_ARABIC
8633 curwin->w_p_arab = FALSE;
8634# endif
8635 (void)init_chartab();
8636 }
8637#endif
8638
8639#ifdef FEAT_ARABIC
8640 if ((int *)varp == &curwin->w_p_arab)
8641 {
8642 if (curwin->w_p_arab)
8643 {
8644 /*
8645 * 'arabic' is set, handle various sub-settings.
8646 */
8647 if (!p_tbidi)
8648 {
8649 /* set rightleft mode */
8650 if (!curwin->w_p_rl)
8651 {
8652 curwin->w_p_rl = TRUE;
8653 changed_window_setting();
8654 }
8655
8656 /* Enable Arabic shaping (major part of what Arabic requires) */
8657 if (!p_arshape)
8658 {
8659 p_arshape = TRUE;
8660 redraw_later_clear();
8661 }
8662 }
8663
8664 /* Arabic requires a utf-8 encoding, inform the user if its not
8665 * set. */
8666 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008667 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008668 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8669
Bram Moolenaar8820b482017-03-16 17:23:31 +01008670 msg_source(HL_ATTR(HLF_W));
8671 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008672#ifdef FEAT_EVAL
8673 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8674#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676
8677# ifdef FEAT_MBYTE
8678 /* set 'delcombine' */
8679 p_deco = TRUE;
8680# endif
8681
8682# ifdef FEAT_KEYMAP
8683 /* Force-set the necessary keymap for arabic */
8684 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8685 OPT_LOCAL);
8686# endif
8687# ifdef FEAT_FKMAP
8688 p_altkeymap = 0;
8689 p_hkmap = 0;
8690 p_fkmap = 0;
8691 (void)init_chartab();
8692# endif
8693 }
8694 else
8695 {
8696 /*
8697 * 'arabic' is reset, handle various sub-settings.
8698 */
8699 if (!p_tbidi)
8700 {
8701 /* reset rightleft mode */
8702 if (curwin->w_p_rl)
8703 {
8704 curwin->w_p_rl = FALSE;
8705 changed_window_setting();
8706 }
8707
8708 /* 'arabicshape' isn't reset, it is a global option and
8709 * another window may still need it "on". */
8710 }
8711
8712 /* 'delcombine' isn't reset, it is a global option and another
8713 * window may still want it "on". */
8714
8715# ifdef FEAT_KEYMAP
8716 /* Revert to the default keymap */
8717 curbuf->b_p_iminsert = B_IMODE_NONE;
8718 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8719# endif
8720 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008721 }
8722
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008723#endif
8724
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008725#ifdef FEAT_TERMGUICOLORS
8726 /* 'termguicolors' */
8727 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008728 {
8729# ifdef FEAT_GUI
8730 if (!gui.in_use && !gui.starting)
8731# endif
8732 highlight_gui_started();
8733 }
8734#endif
8735
Bram Moolenaar071d4272004-06-13 20:20:40 +00008736 /*
8737 * End of handling side effects for bool options.
8738 */
8739
Bram Moolenaar53744302015-07-17 17:38:22 +02008740 /* after handling side effects, call autocommand */
8741
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742 options[opt_idx].flags |= P_WAS_SET;
8743
Bram Moolenaar53744302015-07-17 17:38:22 +02008744#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8745 if (!starting)
8746 {
8747 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008748 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8749 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8750 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008751 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8752 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8753 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8754 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8755 reset_v_option_vars();
8756 }
8757#endif
8758
Bram Moolenaar071d4272004-06-13 20:20:40 +00008759 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008760 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008761 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008762 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763 check_redraw(options[opt_idx].flags);
8764
8765 return NULL;
8766}
8767
8768/*
8769 * Set the value of a number option, and take care of side effects.
8770 * Returns NULL for success, or an error message for an error.
8771 */
8772 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008773set_num_option(
8774 int opt_idx, /* index in options[] table */
8775 char_u *varp, /* pointer to the option variable */
8776 long value, /* new value */
8777 char_u *errbuf, /* buffer for error messages */
8778 size_t errbuflen, /* length of "errbuf" */
8779 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780 OPT_MODELINE */
8781{
8782 char_u *errmsg = NULL;
8783 long old_value = *(long *)varp;
8784 long old_Rows = Rows; /* remember old Rows */
8785 long old_Columns = Columns; /* remember old Columns */
8786 long *pp = (long *)varp;
8787
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008788 /* Disallow changing some options from secure mode. */
8789 if ((secure
8790#ifdef HAVE_SANDBOX
8791 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008792#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008793 ) && (options[opt_idx].flags & P_SECURE))
8794 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795
8796 *pp = value;
8797#ifdef FEAT_EVAL
8798 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008799 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008801#ifdef FEAT_GUI
8802 need_mouse_correct = TRUE;
8803#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008804
Bram Moolenaar14f24742012-08-08 18:01:05 +02008805 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806 {
8807 errmsg = e_positive;
8808 curbuf->b_p_sw = curbuf->b_p_ts;
8809 }
8810
8811 /*
8812 * Number options that need some action when changed
8813 */
8814#ifdef FEAT_WINDOWS
8815 if (pp == &p_wh || pp == &p_hh)
8816 {
8817 if (p_wh < 1)
8818 {
8819 errmsg = e_positive;
8820 p_wh = 1;
8821 }
8822 if (p_wmh > p_wh)
8823 {
8824 errmsg = e_winheight;
8825 p_wh = p_wmh;
8826 }
8827 if (p_hh < 0)
8828 {
8829 errmsg = e_positive;
8830 p_hh = 0;
8831 }
8832
8833 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008834 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008835 {
8836 if (pp == &p_wh && curwin->w_height < p_wh)
8837 win_setheight((int)p_wh);
8838 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8839 win_setheight((int)p_hh);
8840 }
8841 }
8842
8843 /* 'winminheight' */
8844 else if (pp == &p_wmh)
8845 {
8846 if (p_wmh < 0)
8847 {
8848 errmsg = e_positive;
8849 p_wmh = 0;
8850 }
8851 if (p_wmh > p_wh)
8852 {
8853 errmsg = e_winheight;
8854 p_wmh = p_wh;
8855 }
8856 win_setminheight();
8857 }
8858
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008859# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008860 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 {
8862 if (p_wiw < 1)
8863 {
8864 errmsg = e_positive;
8865 p_wiw = 1;
8866 }
8867 if (p_wmw > p_wiw)
8868 {
8869 errmsg = e_winwidth;
8870 p_wiw = p_wmw;
8871 }
8872
8873 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008874 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008875 win_setwidth((int)p_wiw);
8876 }
8877
8878 /* 'winminwidth' */
8879 else if (pp == &p_wmw)
8880 {
8881 if (p_wmw < 0)
8882 {
8883 errmsg = e_positive;
8884 p_wmw = 0;
8885 }
8886 if (p_wmw > p_wiw)
8887 {
8888 errmsg = e_winwidth;
8889 p_wmw = p_wiw;
8890 }
8891 win_setminheight();
8892 }
8893# endif
8894
8895#endif
8896
8897#ifdef FEAT_WINDOWS
8898 /* (re)set last window status line */
8899 else if (pp == &p_ls)
8900 {
8901 last_status(FALSE);
8902 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008903
8904 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008905 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008906 {
8907 shell_new_rows(); /* recompute window positions and heights */
8908 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008909#endif
8910
8911#ifdef FEAT_GUI
8912 else if (pp == &p_linespace)
8913 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008914 /* Recompute gui.char_height and resize the Vim window to keep the
8915 * same number of lines. */
8916 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008917 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918 }
8919#endif
8920
8921#ifdef FEAT_FOLDING
8922 /* 'foldlevel' */
8923 else if (pp == &curwin->w_p_fdl)
8924 {
8925 if (curwin->w_p_fdl < 0)
8926 curwin->w_p_fdl = 0;
8927 newFoldLevel();
8928 }
8929
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008930 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008931 else if (pp == &curwin->w_p_fml)
8932 {
8933 foldUpdateAll(curwin);
8934 }
8935
8936 /* 'foldnestmax' */
8937 else if (pp == &curwin->w_p_fdn)
8938 {
8939 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8940 foldUpdateAll(curwin);
8941 }
8942
8943 /* 'foldcolumn' */
8944 else if (pp == &curwin->w_p_fdc)
8945 {
8946 if (curwin->w_p_fdc < 0)
8947 {
8948 errmsg = e_positive;
8949 curwin->w_p_fdc = 0;
8950 }
8951 else if (curwin->w_p_fdc > 12)
8952 {
8953 errmsg = e_invarg;
8954 curwin->w_p_fdc = 12;
8955 }
8956 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008957#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008958
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008959#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008960 /* 'shiftwidth' or 'tabstop' */
8961 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8962 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008963# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008964 if (foldmethodIsIndent(curwin))
8965 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008966# endif
8967# ifdef FEAT_CINDENT
8968 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8969 * parse 'cinoptions'. */
8970 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8971 parse_cino(curbuf);
8972# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008974#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008975
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008976#ifdef FEAT_MBYTE
8977 /* 'maxcombine' */
8978 else if (pp == &p_mco)
8979 {
8980 if (p_mco > MAX_MCO)
8981 p_mco = MAX_MCO;
8982 else if (p_mco < 0)
8983 p_mco = 0;
8984 screenclear(); /* will re-allocate the screen */
8985 }
8986#endif
8987
Bram Moolenaar071d4272004-06-13 20:20:40 +00008988 else if (pp == &curbuf->b_p_iminsert)
8989 {
8990 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8991 {
8992 errmsg = e_invarg;
8993 curbuf->b_p_iminsert = B_IMODE_NONE;
8994 }
8995 p_iminsert = curbuf->b_p_iminsert;
8996 if (termcap_active) /* don't do this in the alternate screen */
8997 showmode();
8998#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8999 /* Show/unshow value of 'keymap' in status lines. */
9000 status_redraw_curbuf();
9001#endif
9002 }
9003
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009004#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9005 /* 'imstyle' */
9006 else if (pp == &p_imst)
9007 {
9008 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9009 errmsg = e_invarg;
9010 }
9011#endif
9012
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009013 else if (pp == &p_window)
9014 {
9015 if (p_window < 1)
9016 p_window = 1;
9017 else if (p_window >= Rows)
9018 p_window = Rows - 1;
9019 }
9020
Bram Moolenaar071d4272004-06-13 20:20:40 +00009021 else if (pp == &curbuf->b_p_imsearch)
9022 {
9023 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9024 {
9025 errmsg = e_invarg;
9026 curbuf->b_p_imsearch = B_IMODE_NONE;
9027 }
9028 p_imsearch = curbuf->b_p_imsearch;
9029 }
9030
9031#ifdef FEAT_TITLE
9032 /* if 'titlelen' has changed, redraw the title */
9033 else if (pp == &p_titlelen)
9034 {
9035 if (p_titlelen < 0)
9036 {
9037 errmsg = e_positive;
9038 p_titlelen = 85;
9039 }
9040 if (starting != NO_SCREEN && old_value != p_titlelen)
9041 need_maketitle = TRUE;
9042 }
9043#endif
9044
9045 /* if p_ch changed value, change the command line height */
9046 else if (pp == &p_ch)
9047 {
9048 if (p_ch < 1)
9049 {
9050 errmsg = e_positive;
9051 p_ch = 1;
9052 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009053 if (p_ch > Rows - min_rows() + 1)
9054 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009055
9056 /* Only compute the new window layout when startup has been
9057 * completed. Otherwise the frame sizes may be wrong. */
9058 if (p_ch != old_value && full_screen
9059#ifdef FEAT_GUI
9060 && !gui.starting
9061#endif
9062 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009063 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009064 }
9065
9066 /* when 'updatecount' changes from zero to non-zero, open swap files */
9067 else if (pp == &p_uc)
9068 {
9069 if (p_uc < 0)
9070 {
9071 errmsg = e_positive;
9072 p_uc = 100;
9073 }
9074 if (p_uc && !old_value)
9075 ml_open_files();
9076 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009077#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009078 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009079 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009080 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009081 {
9082 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009083 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009084 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009085 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009086 {
9087 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009088 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009089 }
9090 }
9091#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009092#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009093 else if (pp == &p_mzq)
9094 mzvim_reset_timer();
9095#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009097#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9098 /* 'pyxversion' */
9099 else if (pp == &p_pyx)
9100 {
9101 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9102 errmsg = e_invarg;
9103 }
9104#endif
9105
Bram Moolenaar071d4272004-06-13 20:20:40 +00009106 /* sync undo before 'undolevels' changes */
9107 else if (pp == &p_ul)
9108 {
9109 /* use the old value, otherwise u_sync() may not work properly */
9110 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009111 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009112 p_ul = value;
9113 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009114 else if (pp == &curbuf->b_p_ul)
9115 {
9116 /* use the old value, otherwise u_sync() may not work properly */
9117 curbuf->b_p_ul = old_value;
9118 u_sync(TRUE);
9119 curbuf->b_p_ul = value;
9120 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009122#ifdef FEAT_LINEBREAK
9123 /* 'numberwidth' must be positive */
9124 else if (pp == &curwin->w_p_nuw)
9125 {
9126 if (curwin->w_p_nuw < 1)
9127 {
9128 errmsg = e_positive;
9129 curwin->w_p_nuw = 1;
9130 }
9131 if (curwin->w_p_nuw > 10)
9132 {
9133 errmsg = e_invarg;
9134 curwin->w_p_nuw = 10;
9135 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009136 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009137 }
9138#endif
9139
Bram Moolenaar1a384422010-07-14 19:53:30 +02009140 else if (pp == &curbuf->b_p_tw)
9141 {
9142 if (curbuf->b_p_tw < 0)
9143 {
9144 errmsg = e_positive;
9145 curbuf->b_p_tw = 0;
9146 }
9147#ifdef FEAT_SYN_HL
9148# ifdef FEAT_WINDOWS
9149 {
9150 win_T *wp;
9151 tabpage_T *tp;
9152
9153 FOR_ALL_TAB_WINDOWS(tp, wp)
9154 check_colorcolumn(wp);
9155 }
9156# else
9157 check_colorcolumn(curwin);
9158# endif
9159#endif
9160 }
9161
Bram Moolenaar071d4272004-06-13 20:20:40 +00009162 /*
9163 * Check the bounds for numeric options here
9164 */
9165 if (Rows < min_rows() && full_screen)
9166 {
9167 if (errbuf != NULL)
9168 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009169 vim_snprintf((char *)errbuf, errbuflen,
9170 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009171 errmsg = errbuf;
9172 }
9173 Rows = min_rows();
9174 }
9175 if (Columns < MIN_COLUMNS && full_screen)
9176 {
9177 if (errbuf != NULL)
9178 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009179 vim_snprintf((char *)errbuf, errbuflen,
9180 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009181 errmsg = errbuf;
9182 }
9183 Columns = MIN_COLUMNS;
9184 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009185 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009186
Bram Moolenaar071d4272004-06-13 20:20:40 +00009187 /*
9188 * If the screen (shell) height has been changed, assume it is the
9189 * physical screenheight.
9190 */
9191 if (old_Rows != Rows || old_Columns != Columns)
9192 {
9193 /* Changing the screen size is not allowed while updating the screen. */
9194 if (updating_screen)
9195 *pp = old_value;
9196 else if (full_screen
9197#ifdef FEAT_GUI
9198 && !gui.starting
9199#endif
9200 )
9201 set_shellsize((int)Columns, (int)Rows, TRUE);
9202 else
9203 {
9204 /* Postpone the resizing; check the size and cmdline position for
9205 * messages. */
9206 check_shellsize();
9207 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9208 cmdline_row = Rows - p_ch;
9209 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009210 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009211 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009212 }
9213
Bram Moolenaar071d4272004-06-13 20:20:40 +00009214 if (curbuf->b_p_ts <= 0)
9215 {
9216 errmsg = e_positive;
9217 curbuf->b_p_ts = 8;
9218 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009219 if (p_tm < 0)
9220 {
9221 errmsg = e_positive;
9222 p_tm = 0;
9223 }
9224 if ((curwin->w_p_scr <= 0
9225 || (curwin->w_p_scr > curwin->w_height
9226 && curwin->w_height > 0))
9227 && full_screen)
9228 {
9229 if (pp == &(curwin->w_p_scr))
9230 {
9231 if (curwin->w_p_scr != 0)
9232 errmsg = e_scroll;
9233 win_comp_scroll(curwin);
9234 }
9235 /* If 'scroll' became invalid because of a side effect silently adjust
9236 * it. */
9237 else if (curwin->w_p_scr <= 0)
9238 curwin->w_p_scr = 1;
9239 else /* curwin->w_p_scr > curwin->w_height */
9240 curwin->w_p_scr = curwin->w_height;
9241 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009242 if (p_hi < 0)
9243 {
9244 errmsg = e_positive;
9245 p_hi = 0;
9246 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009247 else if (p_hi > 10000)
9248 {
9249 errmsg = e_invarg;
9250 p_hi = 10000;
9251 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009252 if (p_re < 0 || p_re > 2)
9253 {
9254 errmsg = e_invarg;
9255 p_re = 0;
9256 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009257 if (p_report < 0)
9258 {
9259 errmsg = e_positive;
9260 p_report = 1;
9261 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009262 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009263 {
9264 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9265 p_sj = Rows / 2;
9266 else
9267 {
9268 errmsg = e_scroll;
9269 p_sj = 1;
9270 }
9271 }
9272 if (p_so < 0 && full_screen)
9273 {
9274 errmsg = e_scroll;
9275 p_so = 0;
9276 }
9277 if (p_siso < 0 && full_screen)
9278 {
9279 errmsg = e_positive;
9280 p_siso = 0;
9281 }
9282#ifdef FEAT_CMDWIN
9283 if (p_cwh < 1)
9284 {
9285 errmsg = e_positive;
9286 p_cwh = 1;
9287 }
9288#endif
9289 if (p_ut < 0)
9290 {
9291 errmsg = e_positive;
9292 p_ut = 2000;
9293 }
9294 if (p_ss < 0)
9295 {
9296 errmsg = e_positive;
9297 p_ss = 0;
9298 }
9299
9300 /* May set global value for local option. */
9301 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9302 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9303
9304 options[opt_idx].flags |= P_WAS_SET;
9305
Bram Moolenaar53744302015-07-17 17:38:22 +02009306#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9307 if (!starting && errmsg == NULL)
9308 {
9309 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009310 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9311 vim_snprintf((char *)buf_new, 10, "%ld", value);
9312 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009313 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9314 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9315 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9316 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9317 reset_v_option_vars();
9318 }
9319#endif
9320
Bram Moolenaar071d4272004-06-13 20:20:40 +00009321 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009322 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009323 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009324 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009325 check_redraw(options[opt_idx].flags);
9326
9327 return errmsg;
9328}
9329
9330/*
9331 * Called after an option changed: check if something needs to be redrawn.
9332 */
9333 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009334check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009335{
9336 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009337 int doclear = (flags & P_RCLR) == P_RCLR;
9338 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009339
9340#ifdef FEAT_WINDOWS
9341 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9342 status_redraw_all();
9343#endif
9344
9345 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9346 changed_window_setting();
9347 if (flags & P_RBUF)
9348 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009349 if (flags & P_RWINONLY)
9350 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009351 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009352 redraw_all_later(CLEAR);
9353 else if (all)
9354 redraw_all_later(NOT_VALID);
9355}
9356
9357/*
9358 * Find index for option 'arg'.
9359 * Return -1 if not found.
9360 */
9361 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009362findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009363{
9364 int opt_idx;
9365 char *s, *p;
9366 static short quick_tab[27] = {0, 0}; /* quick access table */
9367 int is_term_opt;
9368
9369 /*
9370 * For first call: Initialize the quick-access table.
9371 * It contains the index for the first option that starts with a certain
9372 * letter. There are 26 letters, plus the first "t_" option.
9373 */
9374 if (quick_tab[1] == 0)
9375 {
9376 p = options[0].fullname;
9377 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9378 {
9379 if (s[0] != p[0])
9380 {
9381 if (s[0] == 't' && s[1] == '_')
9382 quick_tab[26] = opt_idx;
9383 else
9384 quick_tab[CharOrdLow(s[0])] = opt_idx;
9385 }
9386 p = s;
9387 }
9388 }
9389
9390 /*
9391 * Check for name starting with an illegal character.
9392 */
9393#ifdef EBCDIC
9394 if (!islower(arg[0]))
9395#else
9396 if (arg[0] < 'a' || arg[0] > 'z')
9397#endif
9398 return -1;
9399
9400 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9401 if (is_term_opt)
9402 opt_idx = quick_tab[26];
9403 else
9404 opt_idx = quick_tab[CharOrdLow(arg[0])];
9405 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9406 {
9407 if (STRCMP(arg, s) == 0) /* match full name */
9408 break;
9409 }
9410 if (s == NULL && !is_term_opt)
9411 {
9412 opt_idx = quick_tab[CharOrdLow(arg[0])];
9413 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9414 {
9415 s = options[opt_idx].shortname;
9416 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9417 break;
9418 s = NULL;
9419 }
9420 }
9421 if (s == NULL)
9422 opt_idx = -1;
9423 return opt_idx;
9424}
9425
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009426#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009427/*
9428 * Get the value for an option.
9429 *
9430 * Returns:
9431 * Number or Toggle option: 1, *numval gets value.
9432 * String option: 0, *stringval gets allocated string.
9433 * Hidden Number or Toggle option: -1.
9434 * hidden String option: -2.
9435 * unknown option: -3.
9436 */
9437 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009438get_option_value(
9439 char_u *name,
9440 long *numval,
9441 char_u **stringval, /* NULL when only checking existence */
9442 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443{
9444 int opt_idx;
9445 char_u *varp;
9446
9447 opt_idx = findoption(name);
9448 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009449 {
9450 int key;
9451
9452 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9453 && (key = find_key_option(name)) != 0)
9454 {
9455 char_u key_name[2];
9456 char_u *p;
9457
9458 if (key < 0)
9459 {
9460 key_name[0] = KEY2TERMCAP0(key);
9461 key_name[1] = KEY2TERMCAP1(key);
9462 }
9463 else
9464 {
9465 key_name[0] = KS_KEY;
9466 key_name[1] = (key & 0xff);
9467 }
9468 p = find_termcode(key_name);
9469 if (p != NULL)
9470 {
9471 if (stringval != NULL)
9472 *stringval = vim_strsave(p);
9473 return 0;
9474 }
9475 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009476 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009477 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009478
9479 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9480
9481 if (options[opt_idx].flags & P_STRING)
9482 {
9483 if (varp == NULL) /* hidden option */
9484 return -2;
9485 if (stringval != NULL)
9486 {
9487#ifdef FEAT_CRYPT
9488 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009489 if ((char_u **)varp == &curbuf->b_p_key
9490 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009491 *stringval = vim_strsave((char_u *)"*****");
9492 else
9493#endif
9494 *stringval = vim_strsave(*(char_u **)(varp));
9495 }
9496 return 0;
9497 }
9498
9499 if (varp == NULL) /* hidden option */
9500 return -1;
9501 if (options[opt_idx].flags & P_NUM)
9502 *numval = *(long *)varp;
9503 else
9504 {
9505 /* Special case: 'modified' is b_changed, but we also want to consider
9506 * it set when 'ff' or 'fenc' changed. */
9507 if ((int *)varp == &curbuf->b_changed)
9508 *numval = curbufIsChanged();
9509 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009510 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009511 }
9512 return 1;
9513}
9514#endif
9515
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009516#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009517/*
9518 * Returns the option attributes and its value. Unlike the above function it
9519 * will return either global value or local value of the option depending on
9520 * what was requested, but it will never return global value if it was
9521 * requested to return local one and vice versa. Neither it will return
9522 * buffer-local value if it was requested to return window-local one.
9523 *
9524 * Pretends that option is absent if it is not present in the requested scope
9525 * (i.e. has no global, window-local or buffer-local value depending on
9526 * opt_type). Uses
9527 *
9528 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009529 * 0 hidden or unknown option, also option that does not have requested
9530 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009531 * see SOPT_* in vim.h for other flags
9532 *
9533 * Possible opt_type values: see SREQ_* in vim.h
9534 */
9535 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009536get_option_value_strict(
9537 char_u *name,
9538 long *numval,
9539 char_u **stringval, /* NULL when only obtaining attributes */
9540 int opt_type,
9541 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009542{
9543 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009544 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009545 struct vimoption *p;
9546 int r = 0;
9547
9548 opt_idx = findoption(name);
9549 if (opt_idx < 0)
9550 return 0;
9551
9552 p = &(options[opt_idx]);
9553
9554 /* Hidden option */
9555 if (p->var == NULL)
9556 return 0;
9557
9558 if (p->flags & P_BOOL)
9559 r |= SOPT_BOOL;
9560 else if (p->flags & P_NUM)
9561 r |= SOPT_NUM;
9562 else if (p->flags & P_STRING)
9563 r |= SOPT_STRING;
9564
9565 if (p->indir == PV_NONE)
9566 {
9567 if (opt_type == SREQ_GLOBAL)
9568 r |= SOPT_GLOBAL;
9569 else
9570 return 0; /* Did not request global-only option */
9571 }
9572 else
9573 {
9574 if (p->indir & PV_BOTH)
9575 r |= SOPT_GLOBAL;
9576 else if (opt_type == SREQ_GLOBAL)
9577 return 0; /* Requested global option */
9578
9579 if (p->indir & PV_WIN)
9580 {
9581 if (opt_type == SREQ_BUF)
9582 return 0; /* Did not request window-local option */
9583 else
9584 r |= SOPT_WIN;
9585 }
9586 else if (p->indir & PV_BUF)
9587 {
9588 if (opt_type == SREQ_WIN)
9589 return 0; /* Did not request buffer-local option */
9590 else
9591 r |= SOPT_BUF;
9592 }
9593 }
9594
9595 if (stringval == NULL)
9596 return r;
9597
9598 if (opt_type == SREQ_GLOBAL)
9599 varp = p->var;
9600 else
9601 {
9602 if (opt_type == SREQ_BUF)
9603 {
9604 /* Special case: 'modified' is b_changed, but we also want to
9605 * consider it set when 'ff' or 'fenc' changed. */
9606 if (p->indir == PV_MOD)
9607 {
9608 *numval = bufIsChanged((buf_T *) from);
9609 varp = NULL;
9610 }
9611#ifdef FEAT_CRYPT
9612 else if (p->indir == PV_KEY)
9613 {
9614 /* never return the value of the crypt key */
9615 *stringval = NULL;
9616 varp = NULL;
9617 }
9618#endif
9619 else
9620 {
9621 aco_save_T aco;
9622 aucmd_prepbuf(&aco, (buf_T *) from);
9623 varp = get_varp(p);
9624 aucmd_restbuf(&aco);
9625 }
9626 }
9627 else if (opt_type == SREQ_WIN)
9628 {
9629 win_T *save_curwin;
9630 save_curwin = curwin;
9631 curwin = (win_T *) from;
9632 curbuf = curwin->w_buffer;
9633 varp = get_varp(p);
9634 curwin = save_curwin;
9635 curbuf = curwin->w_buffer;
9636 }
9637 if (varp == p->var)
9638 return (r | SOPT_UNSET);
9639 }
9640
9641 if (varp != NULL)
9642 {
9643 if (p->flags & P_STRING)
9644 *stringval = vim_strsave(*(char_u **)(varp));
9645 else if (p->flags & P_NUM)
9646 *numval = *(long *) varp;
9647 else
9648 *numval = *(int *)varp;
9649 }
9650
9651 return r;
9652}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009653
9654/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009655 * Iterate over options. First argument is a pointer to a pointer to a
9656 * structure inside options[] array, second is option type like in the above
9657 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009658 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009659 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009660 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009661 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009662 * first argument to NULL.
9663 *
9664 * Returns full option name for current option on each call.
9665 */
9666 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009667option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009668{
9669 struct vimoption *ret = NULL;
9670 do
9671 {
9672 if (*option == NULL)
9673 *option = (void *) options;
9674 else if (((struct vimoption *) (*option))->fullname == NULL)
9675 {
9676 *option = NULL;
9677 return NULL;
9678 }
9679 else
9680 *option = (void *) (((struct vimoption *) (*option)) + 1);
9681
9682 ret = ((struct vimoption *) (*option));
9683
9684 /* Hidden option */
9685 if (ret->var == NULL)
9686 {
9687 ret = NULL;
9688 continue;
9689 }
9690
9691 switch (opt_type)
9692 {
9693 case SREQ_GLOBAL:
9694 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9695 ret = NULL;
9696 break;
9697 case SREQ_BUF:
9698 if (!(ret->indir & PV_BUF))
9699 ret = NULL;
9700 break;
9701 case SREQ_WIN:
9702 if (!(ret->indir & PV_WIN))
9703 ret = NULL;
9704 break;
9705 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009706 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009707 return NULL;
9708 }
9709 }
9710 while (ret == NULL);
9711
9712 return (char_u *)ret->fullname;
9713}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009714#endif
9715
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716/*
9717 * Set the value of option "name".
9718 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009719 *
9720 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009721 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009722 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009723set_option_value(
9724 char_u *name,
9725 long number,
9726 char_u *string,
9727 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009728{
9729 int opt_idx;
9730 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009731 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009732
9733 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009734 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009735 {
9736 int key;
9737
9738 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9739 && (key = find_key_option(name)) != 0)
9740 {
9741 char_u key_name[2];
9742
9743 if (key < 0)
9744 {
9745 key_name[0] = KEY2TERMCAP0(key);
9746 key_name[1] = KEY2TERMCAP1(key);
9747 }
9748 else
9749 {
9750 key_name[0] = KS_KEY;
9751 key_name[1] = (key & 0xff);
9752 }
9753 add_termcode(key_name, string, FALSE);
9754 if (full_screen)
9755 ttest(FALSE);
9756 redraw_all_later(CLEAR);
9757 return NULL;
9758 }
9759
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009761 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762 else
9763 {
9764 flags = options[opt_idx].flags;
9765#ifdef HAVE_SANDBOX
9766 /* Disallow changing some options in the sandbox */
9767 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009768 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009769 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009770 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009771 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009772#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009773 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009774 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009775 else
9776 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009777 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009778 if (varp != NULL) /* hidden option is not changed */
9779 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009780 if (number == 0 && string != NULL)
9781 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009782 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009783
9784 /* Either we are given a string or we are setting option
9785 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009786 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009787 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009788 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009789 {
9790 /* There's another character after zeros or the string
9791 * is empty. In both cases, we are trying to set a
9792 * num option using a string. */
9793 EMSG3(_("E521: Number required: &%s = '%s'"),
9794 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009795 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009796
9797 }
9798 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009799 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009800 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009801 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009802 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009803 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009804 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009805 }
9806 }
9807 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009808 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009809}
9810
9811/*
9812 * Get the terminal code for a terminal option.
9813 * Returns NULL when not found.
9814 */
9815 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009816get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009817{
9818 int opt_idx;
9819 char_u *varp;
9820
9821 if (tname[0] != 't' || tname[1] != '_' ||
9822 tname[2] == NUL || tname[3] == NUL)
9823 return NULL;
9824 if ((opt_idx = findoption(tname)) >= 0)
9825 {
9826 varp = get_varp(&(options[opt_idx]));
9827 if (varp != NULL)
9828 varp = *(char_u **)(varp);
9829 return varp;
9830 }
9831 return find_termcode(tname + 2);
9832}
9833
9834 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009835get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009836{
9837 int i;
9838
9839 i = findoption((char_u *)"hl");
9840 if (i >= 0)
9841 return options[i].def_val[VI_DEFAULT];
9842 return (char_u *)NULL;
9843}
9844
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009845#if defined(FEAT_MBYTE) || defined(PROTO)
9846 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009847get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009848{
9849 int i;
9850
9851 i = findoption((char_u *)"enc");
9852 if (i >= 0)
9853 return options[i].def_val[VI_DEFAULT];
9854 return (char_u *)NULL;
9855}
9856#endif
9857
Bram Moolenaar071d4272004-06-13 20:20:40 +00009858/*
9859 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9860 */
9861 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009862find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009863{
9864 int key;
9865 int modifiers;
9866
9867 /*
9868 * Don't use get_special_key_code() for t_xx, we don't want it to call
9869 * add_termcap_entry().
9870 */
9871 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9872 key = TERMCAP2KEY(arg[2], arg[3]);
9873 else
9874 {
9875 --arg; /* put arg at the '<' */
9876 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009877 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009878 if (modifiers) /* can't handle modifiers here */
9879 key = 0;
9880 }
9881 return key;
9882}
9883
9884/*
9885 * if 'all' == 0: show changed options
9886 * if 'all' == 1: show all normal options
9887 * if 'all' == 2: show all terminal options
9888 */
9889 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009890showoptions(
9891 int all,
9892 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009893{
9894 struct vimoption *p;
9895 int col;
9896 int isterm;
9897 char_u *varp;
9898 struct vimoption **items;
9899 int item_count;
9900 int run;
9901 int row, rows;
9902 int cols;
9903 int i;
9904 int len;
9905
9906#define INC 20
9907#define GAP 3
9908
9909 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9910 PARAM_COUNT));
9911 if (items == NULL)
9912 return;
9913
9914 /* Highlight title */
9915 if (all == 2)
9916 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9917 else if (opt_flags & OPT_GLOBAL)
9918 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9919 else if (opt_flags & OPT_LOCAL)
9920 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9921 else
9922 MSG_PUTS_TITLE(_("\n--- Options ---"));
9923
9924 /*
9925 * do the loop two times:
9926 * 1. display the short items
9927 * 2. display the long items (only strings and numbers)
9928 */
9929 for (run = 1; run <= 2 && !got_int; ++run)
9930 {
9931 /*
9932 * collect the items in items[]
9933 */
9934 item_count = 0;
9935 for (p = &options[0]; p->fullname != NULL; p++)
9936 {
9937 varp = NULL;
9938 isterm = istermoption(p);
9939 if (opt_flags != 0)
9940 {
9941 if (p->indir != PV_NONE && !isterm)
9942 varp = get_varp_scope(p, opt_flags);
9943 }
9944 else
9945 varp = get_varp(p);
9946 if (varp != NULL
9947 && ((all == 2 && isterm)
9948 || (all == 1 && !isterm)
9949 || (all == 0 && !optval_default(p, varp))))
9950 {
9951 if (p->flags & P_BOOL)
9952 len = 1; /* a toggle option fits always */
9953 else
9954 {
9955 option_value2string(p, opt_flags);
9956 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9957 }
9958 if ((len <= INC - GAP && run == 1) ||
9959 (len > INC - GAP && run == 2))
9960 items[item_count++] = p;
9961 }
9962 }
9963
9964 /*
9965 * display the items
9966 */
9967 if (run == 1)
9968 {
9969 cols = (Columns + GAP - 3) / INC;
9970 if (cols == 0)
9971 cols = 1;
9972 rows = (item_count + cols - 1) / cols;
9973 }
9974 else /* run == 2 */
9975 rows = item_count;
9976 for (row = 0; row < rows && !got_int; ++row)
9977 {
9978 msg_putchar('\n'); /* go to next line */
9979 if (got_int) /* 'q' typed in more */
9980 break;
9981 col = 0;
9982 for (i = row; i < item_count; i += rows)
9983 {
9984 msg_col = col; /* make columns */
9985 showoneopt(items[i], opt_flags);
9986 col += INC;
9987 }
9988 out_flush();
9989 ui_breakcheck();
9990 }
9991 }
9992 vim_free(items);
9993}
9994
9995/*
9996 * Return TRUE if option "p" has its default value.
9997 */
9998 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009999optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010000{
10001 int dvi;
10002
10003 if (varp == NULL)
10004 return TRUE; /* hidden option is always at default */
10005 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10006 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010007 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010009 /* the cast to long is required for Manx C, long_i is
10010 * needed for MSVC */
10011 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010012 /* P_STRING */
10013 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10014}
10015
10016/*
10017 * showoneopt: show the value of one option
10018 * must not be called with a hidden option!
10019 */
10020 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010021showoneopt(
10022 struct vimoption *p,
10023 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010024{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010025 char_u *varp;
10026 int save_silent = silent_mode;
10027
10028 silent_mode = FALSE;
10029 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010030
10031 varp = get_varp_scope(p, opt_flags);
10032
10033 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10034 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10035 ? !curbufIsChanged() : !*(int *)varp))
10036 MSG_PUTS("no");
10037 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
10038 MSG_PUTS("--");
10039 else
10040 MSG_PUTS(" ");
10041 MSG_PUTS(p->fullname);
10042 if (!(p->flags & P_BOOL))
10043 {
10044 msg_putchar('=');
10045 /* put value string in NameBuff */
10046 option_value2string(p, opt_flags);
10047 msg_outtrans(NameBuff);
10048 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010049
10050 silent_mode = save_silent;
10051 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052}
10053
10054/*
10055 * Write modified options as ":set" commands to a file.
10056 *
10057 * There are three values for "opt_flags":
10058 * OPT_GLOBAL: Write global option values and fresh values of
10059 * buffer-local options (used for start of a session
10060 * file).
10061 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10062 * curwin (used for a vimrc file).
10063 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10064 * and local values for window-local options of
10065 * curwin. Local values are also written when at the
10066 * default value, because a modeline or autocommand
10067 * may have set them when doing ":edit file" and the
10068 * user has set them back at the default or fresh
10069 * value.
10070 * When "local_only" is TRUE, don't write fresh
10071 * values, only local values (for ":mkview").
10072 * (fresh value = value used for a new buffer or window for a local option).
10073 *
10074 * Return FAIL on error, OK otherwise.
10075 */
10076 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010077makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010078{
10079 struct vimoption *p;
10080 char_u *varp; /* currently used value */
10081 char_u *varp_fresh; /* local value */
10082 char_u *varp_local = NULL; /* fresh value */
10083 char *cmd;
10084 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010085 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010086
10087 /*
10088 * The options that don't have a default (terminal name, columns, lines)
10089 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010090 * Do the loop over "options[]" twice: once for options with the
10091 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010092 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010093 for (pri = 1; pri >= 0; --pri)
10094 {
10095 for (p = &options[0]; !istermoption(p); p++)
10096 if (!(p->flags & P_NO_MKRC)
10097 && !istermoption(p)
10098 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010099 {
10100 /* skip global option when only doing locals */
10101 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10102 continue;
10103
10104 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10105 * file, they are always buffer-specific. */
10106 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10107 continue;
10108
10109 /* Global values are only written when not at the default value. */
10110 varp = get_varp_scope(p, opt_flags);
10111 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10112 continue;
10113
10114 round = 2;
10115 if (p->indir != PV_NONE)
10116 {
10117 if (p->var == VAR_WIN)
10118 {
10119 /* skip window-local option when only doing globals */
10120 if (!(opt_flags & OPT_LOCAL))
10121 continue;
10122 /* When fresh value of window-local option is not at the
10123 * default, need to write it too. */
10124 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10125 {
10126 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10127 if (!optval_default(p, varp_fresh))
10128 {
10129 round = 1;
10130 varp_local = varp;
10131 varp = varp_fresh;
10132 }
10133 }
10134 }
10135 }
10136
10137 /* Round 1: fresh value for window-local options.
10138 * Round 2: other values */
10139 for ( ; round <= 2; varp = varp_local, ++round)
10140 {
10141 if (round == 1 || (opt_flags & OPT_GLOBAL))
10142 cmd = "set";
10143 else
10144 cmd = "setlocal";
10145
10146 if (p->flags & P_BOOL)
10147 {
10148 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10149 return FAIL;
10150 }
10151 else if (p->flags & P_NUM)
10152 {
10153 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10154 return FAIL;
10155 }
10156 else /* P_STRING */
10157 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010158#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10159 int do_endif = FALSE;
10160
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161 /* Don't set 'syntax' and 'filetype' again if the value is
10162 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010163 if (
10164# if defined(FEAT_SYN_HL)
10165 p->indir == PV_SYN
10166# if defined(FEAT_AUTOCMD)
10167 ||
10168# endif
10169# endif
10170# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010171 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010172# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010173 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174 {
10175 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10176 *(char_u **)(varp)) < 0
10177 || put_eol(fd) < 0)
10178 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010179 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010180 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010181#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10183 (p->flags & P_EXPAND) != 0) == FAIL)
10184 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010185#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10186 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010187 {
10188 if (put_line(fd, "endif") == FAIL)
10189 return FAIL;
10190 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010191#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192 }
10193 }
10194 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010195 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 return OK;
10197}
10198
10199#if defined(FEAT_FOLDING) || defined(PROTO)
10200/*
10201 * Generate set commands for the local fold options only. Used when
10202 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10203 */
10204 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010205makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010206{
10207 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10208# ifdef FEAT_EVAL
10209 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10210 == FAIL
10211# endif
10212 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10213 == FAIL
10214 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10215 == FAIL
10216 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10217 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10218 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10219 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10220 )
10221 return FAIL;
10222
10223 return OK;
10224}
10225#endif
10226
10227 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010228put_setstring(
10229 FILE *fd,
10230 char *cmd,
10231 char *name,
10232 char_u **valuep,
10233 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234{
10235 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010236 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010237
10238 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10239 return FAIL;
10240 if (*valuep != NULL)
10241 {
10242 /* Output 'pastetoggle' as key names. For other
10243 * options some characters have to be escaped with
10244 * CTRL-V or backslash */
10245 if (valuep == &p_pt)
10246 {
10247 s = *valuep;
10248 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010249 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010250 return FAIL;
10251 }
10252 else if (expand)
10253 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010254 buf = alloc(MAXPATHL);
10255 if (buf == NULL)
10256 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10258 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010259 {
10260 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010261 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010262 }
10263 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264 }
10265 else if (put_escstr(fd, *valuep, 2) == FAIL)
10266 return FAIL;
10267 }
10268 if (put_eol(fd) < 0)
10269 return FAIL;
10270 return OK;
10271}
10272
10273 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010274put_setnum(
10275 FILE *fd,
10276 char *cmd,
10277 char *name,
10278 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279{
10280 long wc;
10281
10282 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10283 return FAIL;
10284 if (wc_use_keyname((char_u *)valuep, &wc))
10285 {
10286 /* print 'wildchar' and 'wildcharm' as a key name */
10287 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10288 return FAIL;
10289 }
10290 else if (fprintf(fd, "%ld", *valuep) < 0)
10291 return FAIL;
10292 if (put_eol(fd) < 0)
10293 return FAIL;
10294 return OK;
10295}
10296
10297 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010298put_setbool(
10299 FILE *fd,
10300 char *cmd,
10301 char *name,
10302 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303{
Bram Moolenaar893de922007-10-02 18:40:57 +000010304 if (value < 0) /* global/local option using global value */
10305 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10307 || put_eol(fd) < 0)
10308 return FAIL;
10309 return OK;
10310}
10311
10312/*
10313 * Clear all the terminal options.
10314 * If the option has been allocated, free the memory.
10315 * Terminal options are never hidden or indirect.
10316 */
10317 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010318clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320 /*
10321 * Reset a few things before clearing the old options. This may cause
10322 * outputting a few things that the terminal doesn't understand, but the
10323 * screen will be cleared later, so this is OK.
10324 */
10325#ifdef FEAT_MOUSE_TTY
10326 mch_setmouse(FALSE); /* switch mouse off */
10327#endif
10328#ifdef FEAT_TITLE
10329 mch_restore_title(3); /* restore window titles */
10330#endif
10331#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10332 /* When starting the GUI close the display opened for the clipboard.
10333 * After restoring the title, because that will need the display. */
10334 if (gui.starting)
10335 clear_xterm_clip();
10336#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010337 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010338
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010339 free_termoptions();
10340}
10341
10342 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010343free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010344{
10345 struct vimoption *p;
10346
Bram Moolenaar071d4272004-06-13 20:20:40 +000010347 for (p = &options[0]; p->fullname != NULL; p++)
10348 if (istermoption(p))
10349 {
10350 if (p->flags & P_ALLOCED)
10351 free_string_option(*(char_u **)(p->var));
10352 if (p->flags & P_DEF_ALLOCED)
10353 free_string_option(p->def_val[VI_DEFAULT]);
10354 *(char_u **)(p->var) = empty_option;
10355 p->def_val[VI_DEFAULT] = empty_option;
10356 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10357 }
10358 clear_termcodes();
10359}
10360
10361/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010362 * Free the string for one term option, if it was allocated.
10363 * Set the string to empty_option and clear allocated flag.
10364 * "var" points to the option value.
10365 */
10366 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010367free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010368{
10369 struct vimoption *p;
10370
10371 for (p = &options[0]; p->fullname != NULL; p++)
10372 if (p->var == var)
10373 {
10374 if (p->flags & P_ALLOCED)
10375 free_string_option(*(char_u **)(p->var));
10376 *(char_u **)(p->var) = empty_option;
10377 p->flags &= ~P_ALLOCED;
10378 break;
10379 }
10380}
10381
10382/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383 * Set the terminal option defaults to the current value.
10384 * Used after setting the terminal name.
10385 */
10386 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010387set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388{
10389 struct vimoption *p;
10390
10391 for (p = &options[0]; p->fullname != NULL; p++)
10392 {
10393 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10394 {
10395 if (p->flags & P_DEF_ALLOCED)
10396 {
10397 free_string_option(p->def_val[VI_DEFAULT]);
10398 p->flags &= ~P_DEF_ALLOCED;
10399 }
10400 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10401 if (p->flags & P_ALLOCED)
10402 {
10403 p->flags |= P_DEF_ALLOCED;
10404 p->flags &= ~P_ALLOCED; /* don't free the value now */
10405 }
10406 }
10407 }
10408}
10409
10410/*
10411 * return TRUE if 'p' starts with 't_'
10412 */
10413 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010414istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415{
10416 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10417}
10418
10419/*
10420 * Compute columns for ruler and shown command. 'sc_col' is also used to
10421 * decide what the maximum length of a message on the status line can be.
10422 * If there is a status line for the last window, 'sc_col' is independent
10423 * of 'ru_col'.
10424 */
10425
10426#define COL_RULER 17 /* columns needed by standard ruler */
10427
10428 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010429comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010430{
10431#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010432 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010433
10434 sc_col = 0;
10435 ru_col = 0;
10436 if (p_ru)
10437 {
10438#ifdef FEAT_STL_OPT
10439 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10440#else
10441 ru_col = COL_RULER + 1;
10442#endif
10443 /* no last status line, adjust sc_col */
10444 if (!last_has_status)
10445 sc_col = ru_col;
10446 }
10447 if (p_sc)
10448 {
10449 sc_col += SHOWCMD_COLS;
10450 if (!p_ru || last_has_status) /* no need for separating space */
10451 ++sc_col;
10452 }
10453 sc_col = Columns - sc_col;
10454 ru_col = Columns - ru_col;
10455 if (sc_col <= 0) /* screen too narrow, will become a mess */
10456 sc_col = 1;
10457 if (ru_col <= 0)
10458 ru_col = 1;
10459#else
10460 sc_col = Columns;
10461 ru_col = Columns;
10462#endif
10463}
10464
10465/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010466 * Unset local option value, similar to ":set opt<".
10467 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010468 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010469unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010470{
10471 struct vimoption *p;
10472 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010473 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010474
10475 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010476 if (opt_idx < 0)
10477 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010478 p = &(options[opt_idx]);
10479
10480 switch ((int)p->indir)
10481 {
10482 /* global option with local value: use local value if it's been set */
10483 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010484 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010485 break;
10486 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010487 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010488 break;
10489 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010490 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010491 break;
10492 case PV_AR:
10493 buf->b_p_ar = -1;
10494 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010495 case PV_BKC:
10496 clear_string_option(&buf->b_p_bkc);
10497 buf->b_bkc_flags = 0;
10498 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010499 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010500 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010501 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010502 case PV_TC:
10503 clear_string_option(&buf->b_p_tc);
10504 buf->b_tc_flags = 0;
10505 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010506#ifdef FEAT_FIND_ID
10507 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010508 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010509 break;
10510 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010511 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010512 break;
10513#endif
10514#ifdef FEAT_INS_EXPAND
10515 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010516 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010517 break;
10518 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010519 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010520 break;
10521#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010522 case PV_FP:
10523 clear_string_option(&buf->b_p_fp);
10524 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010525#ifdef FEAT_QUICKFIX
10526 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010527 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010528 break;
10529 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010530 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010531 break;
10532 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010533 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010534 break;
10535#endif
10536#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10537 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010538 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010539 break;
10540#endif
10541#if defined(FEAT_CRYPT)
10542 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010543 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010544 break;
10545#endif
10546#ifdef FEAT_STL_OPT
10547 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010548 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010549 break;
10550#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010551 case PV_UL:
10552 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10553 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010554#ifdef FEAT_LISP
10555 case PV_LW:
10556 clear_string_option(&buf->b_p_lw);
10557 break;
10558#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010559#ifdef FEAT_MBYTE
10560 case PV_MENC:
10561 clear_string_option(&buf->b_p_menc);
10562 break;
10563#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010564 }
10565}
10566
10567/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 * Get pointer to option variable, depending on local or global scope.
10569 */
10570 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010571get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010572{
10573 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10574 {
10575 if (p->var == VAR_WIN)
10576 return (char_u *)GLOBAL_WO(get_varp(p));
10577 return p->var;
10578 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010579 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580 {
10581 switch ((int)p->indir)
10582 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010583 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010585 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10586 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10587 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010589 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10590 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10591 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010592 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010593 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010594 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010596 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10597 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010598#endif
10599#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010600 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10601 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010603#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10604 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10605#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010606#if defined(FEAT_CRYPT)
10607 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10608#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010609#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010610 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010611#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010612 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010613#ifdef FEAT_LISP
10614 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10615#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010616 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010617#ifdef FEAT_MBYTE
10618 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10619#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620 }
10621 return NULL; /* "cannot happen" */
10622 }
10623 return get_varp(p);
10624}
10625
10626/*
10627 * Get pointer to option variable.
10628 */
10629 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010630get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010631{
10632 /* hidden option, always return NULL */
10633 if (p->var == NULL)
10634 return NULL;
10635
10636 switch ((int)p->indir)
10637 {
10638 case PV_NONE: return p->var;
10639
10640 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010641 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010643 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010644 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010645 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010646 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010647 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010648 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010649 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010650 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010651 case PV_TC: return *curbuf->b_p_tc != NUL
10652 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010653 case PV_BKC: return *curbuf->b_p_bkc != NUL
10654 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010656 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010658 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010659 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10660#endif
10661#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010662 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010663 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010664 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010665 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10666#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010667 case PV_FP: return *curbuf->b_p_fp != NUL
10668 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010669#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010670 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010671 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010672 case PV_GP: return *curbuf->b_p_gp != NUL
10673 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10674 case PV_MP: return *curbuf->b_p_mp != NUL
10675 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010676#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010677#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10678 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10679 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10680#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010681#if defined(FEAT_CRYPT)
10682 case PV_CM: return *curbuf->b_p_cm != NUL
10683 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10684#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010685#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010686 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010687 ? (char_u *)&(curwin->w_p_stl) : p->var;
10688#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010689 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10690 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010691#ifdef FEAT_LISP
10692 case PV_LW: return *curbuf->b_p_lw != NUL
10693 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10694#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010695#ifdef FEAT_MBYTE
10696 case PV_MENC: return *curbuf->b_p_menc != NUL
10697 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699
10700#ifdef FEAT_ARABIC
10701 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10702#endif
10703 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010704#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010705 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10706#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010707#ifdef FEAT_SYN_HL
10708 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10709 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010710 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010712#ifdef FEAT_DIFF
10713 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10714#endif
10715#ifdef FEAT_FOLDING
10716 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10717 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10718 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10719 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10720 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10721 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10722 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10723# ifdef FEAT_EVAL
10724 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10725 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10726# endif
10727 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10728#endif
10729 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010730 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010731#ifdef FEAT_LINEBREAK
10732 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10733#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010734#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010736 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10737#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10739 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10740#endif
10741#ifdef FEAT_RIGHTLEFT
10742 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10743 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10744#endif
10745 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10746 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10747#ifdef FEAT_LINEBREAK
10748 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010749 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10750 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751#endif
10752#ifdef FEAT_SCROLLBIND
10753 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10754#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010755#ifdef FEAT_CURSORBIND
10756 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10757#endif
10758#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010759 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10760 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10761#endif
10762#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010763 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010764 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766
10767 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10768 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10769#ifdef FEAT_MBYTE
10770 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10771#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10773 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10775 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10776#ifdef FEAT_CINDENT
10777 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10778 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10779 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10780#endif
10781#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10782 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10783#endif
10784#ifdef FEAT_COMMENTS
10785 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10786#endif
10787#ifdef FEAT_FOLDING
10788 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10789#endif
10790#ifdef FEAT_INS_EXPAND
10791 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10792#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010793#ifdef FEAT_COMPL_FUNC
10794 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010795 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010798 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10800#ifdef FEAT_MBYTE
10801 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10802#endif
10803 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10804#ifdef FEAT_AUTOCMD
10805 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10806#endif
10807 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010808 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010809 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10810 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10811 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10812 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10813#ifdef FEAT_FIND_ID
10814# ifdef FEAT_EVAL
10815 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10816# endif
10817#endif
10818#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10819 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10820 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10821#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010822#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010823 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825#ifdef FEAT_CRYPT
10826 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10827#endif
10828#ifdef FEAT_LISP
10829 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10830#endif
10831 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10832 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10833 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10834 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10835 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010836 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010837#ifdef FEAT_TEXTOBJ
10838 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10839#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10841#ifdef FEAT_SMARTINDENT
10842 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10843#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010844 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10846#ifdef FEAT_SEARCHPATH
10847 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10848#endif
10849 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10850#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010851 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010852 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10853#endif
10854#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010855 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10856 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10857 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858#endif
10859 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10860 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10861 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10862 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010863#ifdef FEAT_PERSISTENT_UNDO
10864 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10865#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10867#ifdef FEAT_KEYMAP
10868 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10869#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010870#ifdef FEAT_SIGNS
10871 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10872#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010873 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874 }
10875 /* always return a valid pointer to avoid a crash! */
10876 return (char_u *)&(curbuf->b_p_wm);
10877}
10878
10879/*
10880 * Get the value of 'equalprg', either the buffer-local one or the global one.
10881 */
10882 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010883get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884{
10885 if (*curbuf->b_p_ep == NUL)
10886 return p_ep;
10887 return curbuf->b_p_ep;
10888}
10889
10890#if defined(FEAT_WINDOWS) || defined(PROTO)
10891/*
10892 * Copy options from one window to another.
10893 * Used when splitting a window.
10894 */
10895 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010896win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010897{
10898 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10899 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10900# ifdef FEAT_RIGHTLEFT
10901# ifdef FEAT_FKMAP
10902 /* Is this right? */
10903 wp_to->w_farsi = wp_from->w_farsi;
10904# endif
10905# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010906#if defined(FEAT_LINEBREAK)
10907 briopt_check(wp_to);
10908#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909}
10910#endif
10911
10912/*
10913 * Copy the options from one winopt_T to another.
10914 * Doesn't free the old option values in "to", use clear_winopt() for that.
10915 * The 'scroll' option is not copied, because it depends on the window height.
10916 * The 'previewwindow' option is reset, there can be only one preview window.
10917 */
10918 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010919copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010920{
10921#ifdef FEAT_ARABIC
10922 to->wo_arab = from->wo_arab;
10923#endif
10924 to->wo_list = from->wo_list;
10925 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010926 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010927#ifdef FEAT_LINEBREAK
10928 to->wo_nuw = from->wo_nuw;
10929#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010930#ifdef FEAT_RIGHTLEFT
10931 to->wo_rl = from->wo_rl;
10932 to->wo_rlc = vim_strsave(from->wo_rlc);
10933#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010934#ifdef FEAT_STL_OPT
10935 to->wo_stl = vim_strsave(from->wo_stl);
10936#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010937 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010938#ifdef FEAT_DIFF
10939 to->wo_wrap_save = from->wo_wrap_save;
10940#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941#ifdef FEAT_LINEBREAK
10942 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010943 to->wo_bri = from->wo_bri;
10944 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945#endif
10946#ifdef FEAT_SCROLLBIND
10947 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010948 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010950#ifdef FEAT_CURSORBIND
10951 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010952 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010953#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010954#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010955 to->wo_spell = from->wo_spell;
10956#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010957#ifdef FEAT_SYN_HL
10958 to->wo_cuc = from->wo_cuc;
10959 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010960 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010961#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010962#ifdef FEAT_DIFF
10963 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010964 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010965#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010966#ifdef FEAT_CONCEAL
10967 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010968 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010969#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010970#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010971 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010972 to->wo_tms = vim_strsave(from->wo_tms);
10973#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010974#ifdef FEAT_FOLDING
10975 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010976 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010977 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010978 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010979 to->wo_fdi = vim_strsave(from->wo_fdi);
10980 to->wo_fml = from->wo_fml;
10981 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010982 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010983 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010984 to->wo_fdm_save = from->wo_diff_saved
10985 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010986 to->wo_fdn = from->wo_fdn;
10987# ifdef FEAT_EVAL
10988 to->wo_fde = vim_strsave(from->wo_fde);
10989 to->wo_fdt = vim_strsave(from->wo_fdt);
10990# endif
10991 to->wo_fmr = vim_strsave(from->wo_fmr);
10992#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010993#ifdef FEAT_SIGNS
10994 to->wo_scl = vim_strsave(from->wo_scl);
10995#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010996 check_winopt(to); /* don't want NULL pointers */
10997}
10998
10999/*
11000 * Check string options in a window for a NULL value.
11001 */
11002 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011003check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011004{
11005 check_winopt(&win->w_onebuf_opt);
11006 check_winopt(&win->w_allbuf_opt);
11007}
11008
11009/*
11010 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11011 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011012 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011013check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011014{
11015#ifdef FEAT_FOLDING
11016 check_string_option(&wop->wo_fdi);
11017 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011018 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011019# ifdef FEAT_EVAL
11020 check_string_option(&wop->wo_fde);
11021 check_string_option(&wop->wo_fdt);
11022# endif
11023 check_string_option(&wop->wo_fmr);
11024#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011025#ifdef FEAT_SIGNS
11026 check_string_option(&wop->wo_scl);
11027#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011028#ifdef FEAT_RIGHTLEFT
11029 check_string_option(&wop->wo_rlc);
11030#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011031#ifdef FEAT_STL_OPT
11032 check_string_option(&wop->wo_stl);
11033#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011034#ifdef FEAT_SYN_HL
11035 check_string_option(&wop->wo_cc);
11036#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011037#ifdef FEAT_CONCEAL
11038 check_string_option(&wop->wo_cocu);
11039#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011040#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011041 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011042 check_string_option(&wop->wo_tms);
11043#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011044#ifdef FEAT_LINEBREAK
11045 check_string_option(&wop->wo_briopt);
11046#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011047}
11048
11049/*
11050 * Free the allocated memory inside a winopt_T.
11051 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011052 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011053clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054{
11055#ifdef FEAT_FOLDING
11056 clear_string_option(&wop->wo_fdi);
11057 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011058 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011059# ifdef FEAT_EVAL
11060 clear_string_option(&wop->wo_fde);
11061 clear_string_option(&wop->wo_fdt);
11062# endif
11063 clear_string_option(&wop->wo_fmr);
11064#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011065#ifdef FEAT_SIGNS
11066 clear_string_option(&wop->wo_scl);
11067#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011068#ifdef FEAT_LINEBREAK
11069 clear_string_option(&wop->wo_briopt);
11070#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011071#ifdef FEAT_RIGHTLEFT
11072 clear_string_option(&wop->wo_rlc);
11073#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011074#ifdef FEAT_STL_OPT
11075 clear_string_option(&wop->wo_stl);
11076#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011077#ifdef FEAT_SYN_HL
11078 clear_string_option(&wop->wo_cc);
11079#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011080#ifdef FEAT_CONCEAL
11081 clear_string_option(&wop->wo_cocu);
11082#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011083#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011084 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011085 clear_string_option(&wop->wo_tms);
11086#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011087}
11088
11089/*
11090 * Copy global option values to local options for one buffer.
11091 * Used when creating a new buffer and sometimes when entering a buffer.
11092 * flags:
11093 * BCO_ENTER We will enter the buf buffer.
11094 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11095 * appropriate.
11096 * BCO_NOHELP Don't copy the values to a help buffer.
11097 */
11098 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011099buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011100{
11101 int should_copy = TRUE;
11102 char_u *save_p_isk = NULL; /* init for GCC */
11103 int dont_do_help;
11104 int did_isk = FALSE;
11105
11106 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011107 * Skip this when the option defaults have not been set yet. Happens when
11108 * main() allocates the first buffer.
11109 */
11110 if (p_cpo != NULL)
11111 {
11112 /*
11113 * Always copy when entering and 'cpo' contains 'S'.
11114 * Don't copy when already initialized.
11115 * Don't copy when 'cpo' contains 's' and not entering.
11116 * 'S' BCO_ENTER initialized 's' should_copy
11117 * yes yes X X TRUE
11118 * yes no yes X FALSE
11119 * no X yes X FALSE
11120 * X no no yes FALSE
11121 * X no no no TRUE
11122 * no yes no X TRUE
11123 */
11124 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11125 && (buf->b_p_initialized
11126 || (!(flags & BCO_ENTER)
11127 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11128 should_copy = FALSE;
11129
11130 if (should_copy || (flags & BCO_ALWAYS))
11131 {
11132 /* Don't copy the options specific to a help buffer when
11133 * BCO_NOHELP is given or the options were initialized already
11134 * (jumping back to a help file with CTRL-T or CTRL-O) */
11135 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11136 || buf->b_p_initialized;
11137 if (dont_do_help) /* don't free b_p_isk */
11138 {
11139 save_p_isk = buf->b_p_isk;
11140 buf->b_p_isk = NULL;
11141 }
11142 /*
11143 * Always free the allocated strings.
11144 * If not already initialized, set 'readonly' and copy 'fileformat'.
11145 */
11146 if (!buf->b_p_initialized)
11147 {
11148 free_buf_options(buf, TRUE);
11149 buf->b_p_ro = FALSE; /* don't copy readonly */
11150 buf->b_p_tx = p_tx;
11151#ifdef FEAT_MBYTE
11152 buf->b_p_fenc = vim_strsave(p_fenc);
11153#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011154 switch (*p_ffs)
11155 {
11156 case 'm':
11157 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11158 case 'd':
11159 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11160 case 'u':
11161 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11162 default:
11163 buf->b_p_ff = vim_strsave(p_ff);
11164 }
11165 if (buf->b_p_ff != NULL)
11166 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011167 buf->b_p_bh = empty_option;
11168 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011169 }
11170 else
11171 free_buf_options(buf, FALSE);
11172
11173 buf->b_p_ai = p_ai;
11174 buf->b_p_ai_nopaste = p_ai_nopaste;
11175 buf->b_p_sw = p_sw;
11176 buf->b_p_tw = p_tw;
11177 buf->b_p_tw_nopaste = p_tw_nopaste;
11178 buf->b_p_tw_nobin = p_tw_nobin;
11179 buf->b_p_wm = p_wm;
11180 buf->b_p_wm_nopaste = p_wm_nopaste;
11181 buf->b_p_wm_nobin = p_wm_nobin;
11182 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011183#ifdef FEAT_MBYTE
11184 buf->b_p_bomb = p_bomb;
11185#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011186 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011187 buf->b_p_et = p_et;
11188 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011189 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011190 buf->b_p_ml = p_ml;
11191 buf->b_p_ml_nobin = p_ml_nobin;
11192 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011193 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011194#ifdef FEAT_INS_EXPAND
11195 buf->b_p_cpt = vim_strsave(p_cpt);
11196#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011197#ifdef FEAT_COMPL_FUNC
11198 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011199 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011201 buf->b_p_sts = p_sts;
11202 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011203 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011204#ifdef FEAT_COMMENTS
11205 buf->b_p_com = vim_strsave(p_com);
11206#endif
11207#ifdef FEAT_FOLDING
11208 buf->b_p_cms = vim_strsave(p_cms);
11209#endif
11210 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011211 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011212 buf->b_p_nf = vim_strsave(p_nf);
11213 buf->b_p_mps = vim_strsave(p_mps);
11214#ifdef FEAT_SMARTINDENT
11215 buf->b_p_si = p_si;
11216#endif
11217 buf->b_p_ci = p_ci;
11218#ifdef FEAT_CINDENT
11219 buf->b_p_cin = p_cin;
11220 buf->b_p_cink = vim_strsave(p_cink);
11221 buf->b_p_cino = vim_strsave(p_cino);
11222#endif
11223#ifdef FEAT_AUTOCMD
11224 /* Don't copy 'filetype', it must be detected */
11225 buf->b_p_ft = empty_option;
11226#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011227 buf->b_p_pi = p_pi;
11228#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11229 buf->b_p_cinw = vim_strsave(p_cinw);
11230#endif
11231#ifdef FEAT_LISP
11232 buf->b_p_lisp = p_lisp;
11233#endif
11234#ifdef FEAT_SYN_HL
11235 /* Don't copy 'syntax', it must be set */
11236 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011237 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011238 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011239#endif
11240#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011241 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011242 (void)compile_cap_prog(&buf->b_s);
11243 buf->b_s.b_p_spf = vim_strsave(p_spf);
11244 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011245#endif
11246#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11247 buf->b_p_inde = vim_strsave(p_inde);
11248 buf->b_p_indk = vim_strsave(p_indk);
11249#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011250 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011251#if defined(FEAT_EVAL)
11252 buf->b_p_fex = vim_strsave(p_fex);
11253#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011254#ifdef FEAT_CRYPT
11255 buf->b_p_key = vim_strsave(p_key);
11256#endif
11257#ifdef FEAT_SEARCHPATH
11258 buf->b_p_sua = vim_strsave(p_sua);
11259#endif
11260#ifdef FEAT_KEYMAP
11261 buf->b_p_keymap = vim_strsave(p_keymap);
11262 buf->b_kmap_state |= KEYMAP_INIT;
11263#endif
11264 /* This isn't really an option, but copying the langmap and IME
11265 * state from the current buffer is better than resetting it. */
11266 buf->b_p_iminsert = p_iminsert;
11267 buf->b_p_imsearch = p_imsearch;
11268
11269 /* options that are normally global but also have a local value
11270 * are not copied, start using the global value */
11271 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011272 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011273 buf->b_p_bkc = empty_option;
11274 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011275#ifdef FEAT_QUICKFIX
11276 buf->b_p_gp = empty_option;
11277 buf->b_p_mp = empty_option;
11278 buf->b_p_efm = empty_option;
11279#endif
11280 buf->b_p_ep = empty_option;
11281 buf->b_p_kp = empty_option;
11282 buf->b_p_path = empty_option;
11283 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011284 buf->b_p_tc = empty_option;
11285 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286#ifdef FEAT_FIND_ID
11287 buf->b_p_def = empty_option;
11288 buf->b_p_inc = empty_option;
11289# ifdef FEAT_EVAL
11290 buf->b_p_inex = vim_strsave(p_inex);
11291# endif
11292#endif
11293#ifdef FEAT_INS_EXPAND
11294 buf->b_p_dict = empty_option;
11295 buf->b_p_tsr = empty_option;
11296#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011297#ifdef FEAT_TEXTOBJ
11298 buf->b_p_qe = vim_strsave(p_qe);
11299#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011300#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11301 buf->b_p_bexpr = empty_option;
11302#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011303#if defined(FEAT_CRYPT)
11304 buf->b_p_cm = empty_option;
11305#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011306#ifdef FEAT_PERSISTENT_UNDO
11307 buf->b_p_udf = p_udf;
11308#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011309#ifdef FEAT_LISP
11310 buf->b_p_lw = empty_option;
11311#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011312#ifdef FEAT_MBYTE
11313 buf->b_p_menc = empty_option;
11314#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315
11316 /*
11317 * Don't copy the options set by ex_help(), use the saved values,
11318 * when going from a help buffer to a non-help buffer.
11319 * Don't touch these at all when BCO_NOHELP is used and going from
11320 * or to a help buffer.
11321 */
11322 if (dont_do_help)
11323 buf->b_p_isk = save_p_isk;
11324 else
11325 {
11326 buf->b_p_isk = vim_strsave(p_isk);
11327 did_isk = TRUE;
11328 buf->b_p_ts = p_ts;
11329 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330 if (buf->b_p_bt[0] == 'h')
11331 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332 buf->b_p_ma = p_ma;
11333 }
11334 }
11335
11336 /*
11337 * When the options should be copied (ignoring BCO_ALWAYS), set the
11338 * flag that indicates that the options have been initialized.
11339 */
11340 if (should_copy)
11341 buf->b_p_initialized = TRUE;
11342 }
11343
11344 check_buf_options(buf); /* make sure we don't have NULLs */
11345 if (did_isk)
11346 (void)buf_init_chartab(buf, FALSE);
11347}
11348
11349/*
11350 * Reset the 'modifiable' option and its default value.
11351 */
11352 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011353reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011354{
11355 int opt_idx;
11356
11357 curbuf->b_p_ma = FALSE;
11358 p_ma = FALSE;
11359 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011360 if (opt_idx >= 0)
11361 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011362}
11363
11364/*
11365 * Set the global value for 'iminsert' to the local value.
11366 */
11367 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011368set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011369{
11370 p_iminsert = curbuf->b_p_iminsert;
11371}
11372
11373/*
11374 * Set the global value for 'imsearch' to the local value.
11375 */
11376 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011377set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011378{
11379 p_imsearch = curbuf->b_p_imsearch;
11380}
11381
11382#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11383static int expand_option_idx = -1;
11384static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11385static int expand_option_flags = 0;
11386
11387 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011388set_context_in_set_cmd(
11389 expand_T *xp,
11390 char_u *arg,
11391 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011392{
11393 int nextchar;
11394 long_u flags = 0; /* init for GCC */
11395 int opt_idx = 0; /* init for GCC */
11396 char_u *p;
11397 char_u *s;
11398 int is_term_option = FALSE;
11399 int key;
11400
11401 expand_option_flags = opt_flags;
11402
11403 xp->xp_context = EXPAND_SETTINGS;
11404 if (*arg == NUL)
11405 {
11406 xp->xp_pattern = arg;
11407 return;
11408 }
11409 p = arg + STRLEN(arg) - 1;
11410 if (*p == ' ' && *(p - 1) != '\\')
11411 {
11412 xp->xp_pattern = p + 1;
11413 return;
11414 }
11415 while (p > arg)
11416 {
11417 s = p;
11418 /* count number of backslashes before ' ' or ',' */
11419 if (*p == ' ' || *p == ',')
11420 {
11421 while (s > arg && *(s - 1) == '\\')
11422 --s;
11423 }
11424 /* break at a space with an even number of backslashes */
11425 if (*p == ' ' && ((p - s) & 1) == 0)
11426 {
11427 ++p;
11428 break;
11429 }
11430 --p;
11431 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011432 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011433 {
11434 xp->xp_context = EXPAND_BOOL_SETTINGS;
11435 p += 2;
11436 }
11437 if (STRNCMP(p, "inv", 3) == 0)
11438 {
11439 xp->xp_context = EXPAND_BOOL_SETTINGS;
11440 p += 3;
11441 }
11442 xp->xp_pattern = arg = p;
11443 if (*arg == '<')
11444 {
11445 while (*p != '>')
11446 if (*p++ == NUL) /* expand terminal option name */
11447 return;
11448 key = get_special_key_code(arg + 1);
11449 if (key == 0) /* unknown name */
11450 {
11451 xp->xp_context = EXPAND_NOTHING;
11452 return;
11453 }
11454 nextchar = *++p;
11455 is_term_option = TRUE;
11456 expand_option_name[2] = KEY2TERMCAP0(key);
11457 expand_option_name[3] = KEY2TERMCAP1(key);
11458 }
11459 else
11460 {
11461 if (p[0] == 't' && p[1] == '_')
11462 {
11463 p += 2;
11464 if (*p != NUL)
11465 ++p;
11466 if (*p == NUL)
11467 return; /* expand option name */
11468 nextchar = *++p;
11469 is_term_option = TRUE;
11470 expand_option_name[2] = p[-2];
11471 expand_option_name[3] = p[-1];
11472 }
11473 else
11474 {
11475 /* Allow * wildcard */
11476 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11477 p++;
11478 if (*p == NUL)
11479 return;
11480 nextchar = *p;
11481 *p = NUL;
11482 opt_idx = findoption(arg);
11483 *p = nextchar;
11484 if (opt_idx == -1 || options[opt_idx].var == NULL)
11485 {
11486 xp->xp_context = EXPAND_NOTHING;
11487 return;
11488 }
11489 flags = options[opt_idx].flags;
11490 if (flags & P_BOOL)
11491 {
11492 xp->xp_context = EXPAND_NOTHING;
11493 return;
11494 }
11495 }
11496 }
11497 /* handle "-=" and "+=" */
11498 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11499 {
11500 ++p;
11501 nextchar = '=';
11502 }
11503 if ((nextchar != '=' && nextchar != ':')
11504 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11505 {
11506 xp->xp_context = EXPAND_UNSUCCESSFUL;
11507 return;
11508 }
11509 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11510 {
11511 xp->xp_context = EXPAND_OLD_SETTING;
11512 if (is_term_option)
11513 expand_option_idx = -1;
11514 else
11515 expand_option_idx = opt_idx;
11516 xp->xp_pattern = p + 1;
11517 return;
11518 }
11519 xp->xp_context = EXPAND_NOTHING;
11520 if (is_term_option || (flags & P_NUM))
11521 return;
11522
11523 xp->xp_pattern = p + 1;
11524
11525 if (flags & P_EXPAND)
11526 {
11527 p = options[opt_idx].var;
11528 if (p == (char_u *)&p_bdir
11529 || p == (char_u *)&p_dir
11530 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011531 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011532 || p == (char_u *)&p_rtp
11533#ifdef FEAT_SEARCHPATH
11534 || p == (char_u *)&p_cdpath
11535#endif
11536#ifdef FEAT_SESSION
11537 || p == (char_u *)&p_vdir
11538#endif
11539 )
11540 {
11541 xp->xp_context = EXPAND_DIRECTORIES;
11542 if (p == (char_u *)&p_path
11543#ifdef FEAT_SEARCHPATH
11544 || p == (char_u *)&p_cdpath
11545#endif
11546 )
11547 xp->xp_backslash = XP_BS_THREE;
11548 else
11549 xp->xp_backslash = XP_BS_ONE;
11550 }
11551 else
11552 {
11553 xp->xp_context = EXPAND_FILES;
11554 /* for 'tags' need three backslashes for a space */
11555 if (p == (char_u *)&p_tags)
11556 xp->xp_backslash = XP_BS_THREE;
11557 else
11558 xp->xp_backslash = XP_BS_ONE;
11559 }
11560 }
11561
11562 /* For an option that is a list of file names, find the start of the
11563 * last file name. */
11564 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11565 {
11566 /* count number of backslashes before ' ' or ',' */
11567 if (*p == ' ' || *p == ',')
11568 {
11569 s = p;
11570 while (s > xp->xp_pattern && *(s - 1) == '\\')
11571 --s;
11572 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11573 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11574 {
11575 xp->xp_pattern = p + 1;
11576 break;
11577 }
11578 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011579
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011580#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011581 /* for 'spellsuggest' start at "file:" */
11582 if (options[opt_idx].var == (char_u *)&p_sps
11583 && STRNCMP(p, "file:", 5) == 0)
11584 {
11585 xp->xp_pattern = p + 5;
11586 break;
11587 }
11588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011589 }
11590
11591 return;
11592}
11593
11594 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011595ExpandSettings(
11596 expand_T *xp,
11597 regmatch_T *regmatch,
11598 int *num_file,
11599 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011600{
11601 int num_normal = 0; /* Nr of matching non-term-code settings */
11602 int num_term = 0; /* Nr of matching terminal code settings */
11603 int opt_idx;
11604 int match;
11605 int count = 0;
11606 char_u *str;
11607 int loop;
11608 int is_term_opt;
11609 char_u name_buf[MAX_KEY_NAME_LEN];
11610 static char *(names[]) = {"all", "termcap"};
11611 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11612
11613 /* do this loop twice:
11614 * loop == 0: count the number of matching options
11615 * loop == 1: copy the matching options into allocated memory
11616 */
11617 for (loop = 0; loop <= 1; ++loop)
11618 {
11619 regmatch->rm_ic = ic;
11620 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11621 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011622 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11623 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011624 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11625 {
11626 if (loop == 0)
11627 num_normal++;
11628 else
11629 (*file)[count++] = vim_strsave((char_u *)names[match]);
11630 }
11631 }
11632 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11633 opt_idx++)
11634 {
11635 if (options[opt_idx].var == NULL)
11636 continue;
11637 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11638 && !(options[opt_idx].flags & P_BOOL))
11639 continue;
11640 is_term_opt = istermoption(&options[opt_idx]);
11641 if (is_term_opt && num_normal > 0)
11642 continue;
11643 match = FALSE;
11644 if (vim_regexec(regmatch, str, (colnr_T)0)
11645 || (options[opt_idx].shortname != NULL
11646 && vim_regexec(regmatch,
11647 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11648 match = TRUE;
11649 else if (is_term_opt)
11650 {
11651 name_buf[0] = '<';
11652 name_buf[1] = 't';
11653 name_buf[2] = '_';
11654 name_buf[3] = str[2];
11655 name_buf[4] = str[3];
11656 name_buf[5] = '>';
11657 name_buf[6] = NUL;
11658 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11659 {
11660 match = TRUE;
11661 str = name_buf;
11662 }
11663 }
11664 if (match)
11665 {
11666 if (loop == 0)
11667 {
11668 if (is_term_opt)
11669 num_term++;
11670 else
11671 num_normal++;
11672 }
11673 else
11674 (*file)[count++] = vim_strsave(str);
11675 }
11676 }
11677 /*
11678 * Check terminal key codes, these are not in the option table
11679 */
11680 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11681 {
11682 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11683 {
11684 if (!isprint(str[0]) || !isprint(str[1]))
11685 continue;
11686
11687 name_buf[0] = 't';
11688 name_buf[1] = '_';
11689 name_buf[2] = str[0];
11690 name_buf[3] = str[1];
11691 name_buf[4] = NUL;
11692
11693 match = FALSE;
11694 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11695 match = TRUE;
11696 else
11697 {
11698 name_buf[0] = '<';
11699 name_buf[1] = 't';
11700 name_buf[2] = '_';
11701 name_buf[3] = str[0];
11702 name_buf[4] = str[1];
11703 name_buf[5] = '>';
11704 name_buf[6] = NUL;
11705
11706 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11707 match = TRUE;
11708 }
11709 if (match)
11710 {
11711 if (loop == 0)
11712 num_term++;
11713 else
11714 (*file)[count++] = vim_strsave(name_buf);
11715 }
11716 }
11717
11718 /*
11719 * Check special key names.
11720 */
11721 regmatch->rm_ic = TRUE; /* ignore case here */
11722 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11723 {
11724 name_buf[0] = '<';
11725 STRCPY(name_buf + 1, str);
11726 STRCAT(name_buf, ">");
11727
11728 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11729 {
11730 if (loop == 0)
11731 num_term++;
11732 else
11733 (*file)[count++] = vim_strsave(name_buf);
11734 }
11735 }
11736 }
11737 if (loop == 0)
11738 {
11739 if (num_normal > 0)
11740 *num_file = num_normal;
11741 else if (num_term > 0)
11742 *num_file = num_term;
11743 else
11744 return OK;
11745 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11746 if (*file == NULL)
11747 {
11748 *file = (char_u **)"";
11749 return FAIL;
11750 }
11751 }
11752 }
11753 return OK;
11754}
11755
11756 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011757ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011758{
11759 char_u *var = NULL; /* init for GCC */
11760 char_u *buf;
11761
11762 *num_file = 0;
11763 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11764 if (*file == NULL)
11765 return FAIL;
11766
11767 /*
11768 * For a terminal key code expand_option_idx is < 0.
11769 */
11770 if (expand_option_idx < 0)
11771 {
11772 var = find_termcode(expand_option_name + 2);
11773 if (var == NULL)
11774 expand_option_idx = findoption(expand_option_name);
11775 }
11776
11777 if (expand_option_idx >= 0)
11778 {
11779 /* put string of option value in NameBuff */
11780 option_value2string(&options[expand_option_idx], expand_option_flags);
11781 var = NameBuff;
11782 }
11783 else if (var == NULL)
11784 var = (char_u *)"";
11785
11786 /* A backslash is required before some characters. This is the reverse of
11787 * what happens in do_set(). */
11788 buf = vim_strsave_escaped(var, escape_chars);
11789
11790 if (buf == NULL)
11791 {
11792 vim_free(*file);
11793 *file = NULL;
11794 return FAIL;
11795 }
11796
11797#ifdef BACKSLASH_IN_FILENAME
11798 /* For MS-Windows et al. we don't double backslashes at the start and
11799 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011800 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011801 if (var[0] == '\\' && var[1] == '\\'
11802 && expand_option_idx >= 0
11803 && (options[expand_option_idx].flags & P_EXPAND)
11804 && vim_isfilec(var[2])
11805 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011806 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011807#endif
11808
11809 *file[0] = buf;
11810 *num_file = 1;
11811 return OK;
11812}
11813#endif
11814
11815/*
11816 * Get the value for the numeric or string option *opp in a nice format into
11817 * NameBuff[]. Must not be called with a hidden option!
11818 */
11819 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011820option_value2string(
11821 struct vimoption *opp,
11822 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011823{
11824 char_u *varp;
11825
11826 varp = get_varp_scope(opp, opt_flags);
11827
11828 if (opp->flags & P_NUM)
11829 {
11830 long wc = 0;
11831
11832 if (wc_use_keyname(varp, &wc))
11833 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11834 else if (wc != 0)
11835 STRCPY(NameBuff, transchar((int)wc));
11836 else
11837 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11838 }
11839 else /* P_STRING */
11840 {
11841 varp = *(char_u **)(varp);
11842 if (varp == NULL) /* just in case */
11843 NameBuff[0] = NUL;
11844#ifdef FEAT_CRYPT
11845 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011846 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011847 STRCPY(NameBuff, "*****");
11848#endif
11849 else if (opp->flags & P_EXPAND)
11850 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11851 /* Translate 'pastetoggle' into special key names */
11852 else if ((char_u **)opp->var == &p_pt)
11853 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11854 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011855 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856 }
11857}
11858
11859/*
11860 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11861 * printed as a keyname.
11862 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11863 */
11864 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011865wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011866{
11867 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11868 {
11869 *wcp = *(long *)varp;
11870 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11871 return TRUE;
11872 }
11873 return FALSE;
11874}
11875
Bram Moolenaar01615492015-02-03 13:00:38 +010011876#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011877/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011878 * Any character has an equivalent 'langmap' character. This is used for
11879 * keyboards that have a special language mode that sends characters above
11880 * 128 (although other characters can be translated too). The "to" field is a
11881 * Vim command character. This avoids having to switch the keyboard back to
11882 * ASCII mode when leaving Insert mode.
11883 *
11884 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11885 * commands.
11886 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11887 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11888 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011890# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011891/*
11892 * With multi-byte support use growarray for 'langmap' chars >= 256
11893 */
11894typedef struct
11895{
11896 int from;
11897 int to;
11898} langmap_entry_T;
11899
11900static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011901static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902
11903/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011904 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11905 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011907 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011908langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011909{
11910 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011911 int a = 0;
11912 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011913
11914 /* Do a binary search for an existing entry. */
11915 while (a != b)
11916 {
11917 int i = (a + b) / 2;
11918 int d = entries[i].from - from;
11919
11920 if (d == 0)
11921 {
11922 entries[i].to = to;
11923 return;
11924 }
11925 if (d < 0)
11926 a = i + 1;
11927 else
11928 b = i;
11929 }
11930
11931 if (ga_grow(&langmap_mapga, 1) != OK)
11932 return; /* out of memory */
11933
11934 /* insert new entry at position "a" */
11935 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11936 mch_memmove(entries + 1, entries,
11937 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11938 ++langmap_mapga.ga_len;
11939 entries[0].from = from;
11940 entries[0].to = to;
11941}
11942
11943/*
11944 * Apply 'langmap' to multi-byte character "c" and return the result.
11945 */
11946 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011947langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011948{
11949 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11950 int a = 0;
11951 int b = langmap_mapga.ga_len;
11952
11953 while (a != b)
11954 {
11955 int i = (a + b) / 2;
11956 int d = entries[i].from - c;
11957
11958 if (d == 0)
11959 return entries[i].to; /* found matching entry */
11960 if (d < 0)
11961 a = i + 1;
11962 else
11963 b = i;
11964 }
11965 return c; /* no entry found, return "c" unmodified */
11966}
11967# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011968
11969 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011970langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011971{
11972 int i;
11973
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011974 for (i = 0; i < 256; i++)
11975 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11976# ifdef FEAT_MBYTE
11977 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11978# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011979}
11980
11981/*
11982 * Called when langmap option is set; the language map can be
11983 * changed at any time!
11984 */
11985 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011986langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011987{
11988 char_u *p;
11989 char_u *p2;
11990 int from, to;
11991
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011992#ifdef FEAT_MBYTE
11993 ga_clear(&langmap_mapga); /* clear the previous map first */
11994#endif
11995 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011996
11997 for (p = p_langmap; p[0] != NUL; )
11998 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011999 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012000 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001 {
12002 if (p2[0] == '\\' && p2[1] != NUL)
12003 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012004 }
12005 if (p2[0] == ';')
12006 ++p2; /* abcd;ABCD form, p2 points to A */
12007 else
12008 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12009 while (p[0])
12010 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012011 if (p[0] == ',')
12012 {
12013 ++p;
12014 break;
12015 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012016 if (p[0] == '\\' && p[1] != NUL)
12017 ++p;
12018#ifdef FEAT_MBYTE
12019 from = (*mb_ptr2char)(p);
12020#else
12021 from = p[0];
12022#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012023 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012024 if (p2 == NULL)
12025 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012026 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012027 if (p[0] != ',')
12028 {
12029 if (p[0] == '\\')
12030 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012031#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012032 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012033#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012034 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012035#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012037 }
12038 else
12039 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012040 if (p2[0] != ',')
12041 {
12042 if (p2[0] == '\\')
12043 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012044#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020012045 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012046#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020012047 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000012048#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020012049 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050 }
12051 if (to == NUL)
12052 {
12053 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
12054 transchar(from));
12055 return;
12056 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012057
12058#ifdef FEAT_MBYTE
12059 if (from >= 256)
12060 langmap_set_entry(from, to);
12061 else
12062#endif
12063 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012064
12065 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012066 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012067 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012068 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012069 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070 if (*p == ';')
12071 {
12072 p = p2;
12073 if (p[0] != NUL)
12074 {
12075 if (p[0] != ',')
12076 {
12077 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12078 return;
12079 }
12080 ++p;
12081 }
12082 break;
12083 }
12084 }
12085 }
12086 }
12087}
12088#endif
12089
12090/*
12091 * Return TRUE if format option 'x' is in effect.
12092 * Take care of no formatting when 'paste' is set.
12093 */
12094 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012095has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012096{
12097 if (p_paste)
12098 return FALSE;
12099 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12100}
12101
12102/*
12103 * Return TRUE if "x" is present in 'shortmess' option, or
12104 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12105 */
12106 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012107shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012108{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012109 return p_shm != NULL &&
12110 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012111 || (vim_strchr(p_shm, 'a') != NULL
12112 && vim_strchr((char_u *)SHM_A, x) != NULL));
12113}
12114
12115/*
12116 * paste_option_changed() - Called after p_paste was set or reset.
12117 */
12118 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012119paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120{
12121 static int old_p_paste = FALSE;
12122 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012123 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012124#ifdef FEAT_CMDL_INFO
12125 static int save_ru = 0;
12126#endif
12127#ifdef FEAT_RIGHTLEFT
12128 static int save_ri = 0;
12129 static int save_hkmap = 0;
12130#endif
12131 buf_T *buf;
12132
12133 if (p_paste)
12134 {
12135 /*
12136 * Paste switched from off to on.
12137 * Save the current values, so they can be restored later.
12138 */
12139 if (!old_p_paste)
12140 {
12141 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012142 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012143 {
12144 buf->b_p_tw_nopaste = buf->b_p_tw;
12145 buf->b_p_wm_nopaste = buf->b_p_wm;
12146 buf->b_p_sts_nopaste = buf->b_p_sts;
12147 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012148 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 }
12150
12151 /* save global options */
12152 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012153 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012154#ifdef FEAT_CMDL_INFO
12155 save_ru = p_ru;
12156#endif
12157#ifdef FEAT_RIGHTLEFT
12158 save_ri = p_ri;
12159 save_hkmap = p_hkmap;
12160#endif
12161 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012162 p_ai_nopaste = p_ai;
12163 p_et_nopaste = p_et;
12164 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 p_tw_nopaste = p_tw;
12166 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167 }
12168
12169 /*
12170 * Always set the option values, also when 'paste' is set when it is
12171 * already on.
12172 */
12173 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012174 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012175 {
12176 buf->b_p_tw = 0; /* textwidth is 0 */
12177 buf->b_p_wm = 0; /* wrapmargin is 0 */
12178 buf->b_p_sts = 0; /* softtabstop is 0 */
12179 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012180 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012181 }
12182
12183 /* set global options */
12184 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012185 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012186#ifdef FEAT_CMDL_INFO
12187# ifdef FEAT_WINDOWS
12188 if (p_ru)
12189 status_redraw_all(); /* redraw to remove the ruler */
12190# endif
12191 p_ru = 0; /* no ruler */
12192#endif
12193#ifdef FEAT_RIGHTLEFT
12194 p_ri = 0; /* no reverse insert */
12195 p_hkmap = 0; /* no Hebrew keyboard */
12196#endif
12197 /* set global values for local buffer options */
12198 p_tw = 0;
12199 p_wm = 0;
12200 p_sts = 0;
12201 p_ai = 0;
12202 }
12203
12204 /*
12205 * Paste switched from on to off: Restore saved values.
12206 */
12207 else if (old_p_paste)
12208 {
12209 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012210 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012211 {
12212 buf->b_p_tw = buf->b_p_tw_nopaste;
12213 buf->b_p_wm = buf->b_p_wm_nopaste;
12214 buf->b_p_sts = buf->b_p_sts_nopaste;
12215 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012216 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012217 }
12218
12219 /* restore global options */
12220 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012221 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012222#ifdef FEAT_CMDL_INFO
12223# ifdef FEAT_WINDOWS
12224 if (p_ru != save_ru)
12225 status_redraw_all(); /* redraw to draw the ruler */
12226# endif
12227 p_ru = save_ru;
12228#endif
12229#ifdef FEAT_RIGHTLEFT
12230 p_ri = save_ri;
12231 p_hkmap = save_hkmap;
12232#endif
12233 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012234 p_ai = p_ai_nopaste;
12235 p_et = p_et_nopaste;
12236 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012237 p_tw = p_tw_nopaste;
12238 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012239 }
12240
12241 old_p_paste = p_paste;
12242}
12243
12244/*
12245 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12246 *
12247 * Reset 'compatible' and set the values for options that didn't get set yet
12248 * to the Vim defaults.
12249 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012250 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012251 */
12252 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012253vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012254{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012255 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012256 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012257 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012258
12259 if (!option_was_set((char_u *)"cp"))
12260 {
12261 p_cp = FALSE;
12262 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12263 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12264 set_option_default(opt_idx, OPT_FREE, FALSE);
12265 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012266 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012267 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012268
12269 if (fname != NULL)
12270 {
12271 p = vim_getenv(envname, &dofree);
12272 if (p == NULL)
12273 {
12274 /* Set $MYVIMRC to the first vimrc file found. */
12275 p = FullName_save(fname, FALSE);
12276 if (p != NULL)
12277 {
12278 vim_setenv(envname, p);
12279 vim_free(p);
12280 }
12281 }
12282 else if (dofree)
12283 vim_free(p);
12284 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012285}
12286
12287/*
12288 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12289 */
12290 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012291change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012292{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012293 int opt_idx;
12294
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295 if (p_cp != on)
12296 {
12297 p_cp = on;
12298 compatible_set();
12299 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012300 opt_idx = findoption((char_u *)"cp");
12301 if (opt_idx >= 0)
12302 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012303}
12304
12305/*
12306 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012307 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012308 */
12309 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012310option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012311{
12312 int idx;
12313
12314 idx = findoption(name);
12315 if (idx < 0) /* unknown option */
12316 return FALSE;
12317 if (options[idx].flags & P_WAS_SET)
12318 return TRUE;
12319 return FALSE;
12320}
12321
12322/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012323 * Reset the flag indicating option "name" was set.
12324 */
12325 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012326reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012327{
12328 int idx = findoption(name);
12329
12330 if (idx >= 0)
12331 options[idx].flags &= ~P_WAS_SET;
12332}
12333
12334/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012335 * compatible_set() - Called when 'compatible' has been set or unset.
12336 *
12337 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12338 * flag) to a Vi compatible value.
12339 * When 'compatible' is unset: Set all options that have a different default
12340 * for Vim (without the P_VI_DEF flag) to that default.
12341 */
12342 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012343compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012344{
12345 int opt_idx;
12346
12347 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12348 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12349 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12350 set_option_default(opt_idx, OPT_FREE, p_cp);
12351 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012352 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012353}
12354
12355#ifdef FEAT_LINEBREAK
12356
12357# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12358 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012359 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012360# endif
12361
12362/*
12363 * fill_breakat_flags() -- called when 'breakat' changes value.
12364 */
12365 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012366fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012367{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012368 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012369 int i;
12370
12371 for (i = 0; i < 256; i++)
12372 breakat_flags[i] = FALSE;
12373
12374 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012375 for (p = p_breakat; *p; p++)
12376 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012377}
12378
12379# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012380 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012381# endif
12382
12383#endif
12384
12385/*
12386 * Check an option that can be a range of string values.
12387 *
12388 * Return OK for correct value, FAIL otherwise.
12389 * Empty is always OK.
12390 */
12391 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012392check_opt_strings(
12393 char_u *val,
12394 char **values,
12395 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012396{
12397 return opt_strings_flags(val, values, NULL, list);
12398}
12399
12400/*
12401 * Handle an option that can be a range of string values.
12402 * Set a flag in "*flagp" for each string present.
12403 *
12404 * Return OK for correct value, FAIL otherwise.
12405 * Empty is always OK.
12406 */
12407 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012408opt_strings_flags(
12409 char_u *val, /* new value */
12410 char **values, /* array of valid string values */
12411 unsigned *flagp,
12412 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012413{
12414 int i;
12415 int len;
12416 unsigned new_flags = 0;
12417
12418 while (*val)
12419 {
12420 for (i = 0; ; ++i)
12421 {
12422 if (values[i] == NULL) /* val not found in values[] */
12423 return FAIL;
12424
12425 len = (int)STRLEN(values[i]);
12426 if (STRNCMP(values[i], val, len) == 0
12427 && ((list && val[len] == ',') || val[len] == NUL))
12428 {
12429 val += len + (val[len] == ',');
12430 new_flags |= (1 << i);
12431 break; /* check next item in val list */
12432 }
12433 }
12434 }
12435 if (flagp != NULL)
12436 *flagp = new_flags;
12437
12438 return OK;
12439}
12440
12441/*
12442 * Read the 'wildmode' option, fill wim_flags[].
12443 */
12444 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012445check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012446{
12447 char_u new_wim_flags[4];
12448 char_u *p;
12449 int i;
12450 int idx = 0;
12451
12452 for (i = 0; i < 4; ++i)
12453 new_wim_flags[i] = 0;
12454
12455 for (p = p_wim; *p; ++p)
12456 {
12457 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12458 ;
12459 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12460 return FAIL;
12461 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12462 new_wim_flags[idx] |= WIM_LONGEST;
12463 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12464 new_wim_flags[idx] |= WIM_FULL;
12465 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12466 new_wim_flags[idx] |= WIM_LIST;
12467 else
12468 return FAIL;
12469 p += i;
12470 if (*p == NUL)
12471 break;
12472 if (*p == ',')
12473 {
12474 if (idx == 3)
12475 return FAIL;
12476 ++idx;
12477 }
12478 }
12479
12480 /* fill remaining entries with last flag */
12481 while (idx < 3)
12482 {
12483 new_wim_flags[idx + 1] = new_wim_flags[idx];
12484 ++idx;
12485 }
12486
12487 /* only when there are no errors, wim_flags[] is changed */
12488 for (i = 0; i < 4; ++i)
12489 wim_flags[i] = new_wim_flags[i];
12490 return OK;
12491}
12492
12493/*
12494 * Check if backspacing over something is allowed.
12495 */
12496 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012497can_bs(
12498 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012499{
12500 switch (*p_bs)
12501 {
12502 case '2': return TRUE;
12503 case '1': return (what != BS_START);
12504 case '0': return FALSE;
12505 }
12506 return vim_strchr(p_bs, what) != NULL;
12507}
12508
12509/*
12510 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12511 * the file must be considered changed when the value is different.
12512 */
12513 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012514save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012515{
12516 buf->b_start_ffc = *buf->b_p_ff;
12517 buf->b_start_eol = buf->b_p_eol;
12518#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012519 buf->b_start_bomb = buf->b_p_bomb;
12520
Bram Moolenaar071d4272004-06-13 20:20:40 +000012521 /* Only use free/alloc when necessary, they take time. */
12522 if (buf->b_start_fenc == NULL
12523 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12524 {
12525 vim_free(buf->b_start_fenc);
12526 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12527 }
12528#endif
12529}
12530
12531/*
12532 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12533 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012534 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12535 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012536 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012537 * When "ignore_empty" is true don't consider a new, empty buffer to be
12538 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012539 */
12540 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012541file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012542{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012543 /* In a buffer that was never loaded the options are not valid. */
12544 if (buf->b_flags & BF_NEVERLOADED)
12545 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012546 if (ignore_empty
12547 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012548 && buf->b_ml.ml_line_count == 1
12549 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12550 return FALSE;
12551 if (buf->b_start_ffc != *buf->b_p_ff)
12552 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012553 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012554 return TRUE;
12555#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012556 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12557 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012558 if (buf->b_start_fenc == NULL)
12559 return (*buf->b_p_fenc != NUL);
12560 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12561#else
12562 return FALSE;
12563#endif
12564}
12565
12566/*
12567 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12568 */
12569 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012570check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012571{
12572 return check_opt_strings(p, p_ff_values, FALSE);
12573}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012574
12575/*
12576 * Return the effective shiftwidth value for current buffer, using the
12577 * 'tabstop' value when 'shiftwidth' is zero.
12578 */
12579 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012580get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012581{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012582 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012583}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012584
12585/*
12586 * Return the effective softtabstop value for the current buffer, using the
12587 * 'tabstop' value when 'softtabstop' is negative.
12588 */
12589 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012590get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012591{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012592 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012593}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012594
12595/*
12596 * Check matchpairs option for "*initc".
12597 * If there is a match set "*initc" to the matching character and "*findc" to
12598 * the opposite character. Set "*backwards" to the direction.
12599 * When "switchit" is TRUE swap the direction.
12600 */
12601 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012602find_mps_values(
12603 int *initc,
12604 int *findc,
12605 int *backwards,
12606 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012607{
12608 char_u *ptr;
12609
12610 ptr = curbuf->b_p_mps;
12611 while (*ptr != NUL)
12612 {
12613#ifdef FEAT_MBYTE
12614 if (has_mbyte)
12615 {
12616 char_u *prev;
12617
12618 if (mb_ptr2char(ptr) == *initc)
12619 {
12620 if (switchit)
12621 {
12622 *findc = *initc;
12623 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12624 *backwards = TRUE;
12625 }
12626 else
12627 {
12628 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12629 *backwards = FALSE;
12630 }
12631 return;
12632 }
12633 prev = ptr;
12634 ptr += mb_ptr2len(ptr) + 1;
12635 if (mb_ptr2char(ptr) == *initc)
12636 {
12637 if (switchit)
12638 {
12639 *findc = *initc;
12640 *initc = mb_ptr2char(prev);
12641 *backwards = FALSE;
12642 }
12643 else
12644 {
12645 *findc = mb_ptr2char(prev);
12646 *backwards = TRUE;
12647 }
12648 return;
12649 }
12650 ptr += mb_ptr2len(ptr);
12651 }
12652 else
12653#endif
12654 {
12655 if (*ptr == *initc)
12656 {
12657 if (switchit)
12658 {
12659 *backwards = TRUE;
12660 *findc = *initc;
12661 *initc = ptr[2];
12662 }
12663 else
12664 {
12665 *backwards = FALSE;
12666 *findc = ptr[2];
12667 }
12668 return;
12669 }
12670 ptr += 2;
12671 if (*ptr == *initc)
12672 {
12673 if (switchit)
12674 {
12675 *backwards = FALSE;
12676 *findc = *initc;
12677 *initc = ptr[-2];
12678 }
12679 else
12680 {
12681 *backwards = TRUE;
12682 *findc = ptr[-2];
12683 }
12684 return;
12685 }
12686 ++ptr;
12687 }
12688 if (*ptr == ',')
12689 ++ptr;
12690 }
12691}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012692
12693#if defined(FEAT_LINEBREAK) || defined(PROTO)
12694/*
12695 * This is called when 'breakindentopt' is changed and when a window is
12696 * initialized.
12697 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012698 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012699briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012700{
12701 char_u *p;
12702 int bri_shift = 0;
12703 long bri_min = 20;
12704 int bri_sbr = FALSE;
12705
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012706 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012707 while (*p != NUL)
12708 {
12709 if (STRNCMP(p, "shift:", 6) == 0
12710 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12711 {
12712 p += 6;
12713 bri_shift = getdigits(&p);
12714 }
12715 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12716 {
12717 p += 4;
12718 bri_min = getdigits(&p);
12719 }
12720 else if (STRNCMP(p, "sbr", 3) == 0)
12721 {
12722 p += 3;
12723 bri_sbr = TRUE;
12724 }
12725 if (*p != ',' && *p != NUL)
12726 return FAIL;
12727 if (*p == ',')
12728 ++p;
12729 }
12730
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012731 wp->w_p_brishift = bri_shift;
12732 wp->w_p_brimin = bri_min;
12733 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012734
12735 return OK;
12736}
12737#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012738
12739/*
12740 * Get the local or global value of 'backupcopy'.
12741 */
12742 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012743get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012744{
12745 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12746}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012747
12748#if defined(FEAT_SIGNS) || defined(PROTO)
12749/*
12750 * Return TRUE when window "wp" has a column to draw signs in.
12751 */
12752 int
12753signcolumn_on(win_T *wp)
12754{
12755 if (*wp->w_p_scl == 'n')
12756 return FALSE;
12757 if (*wp->w_p_scl == 'y')
12758 return TRUE;
12759 return (wp->w_buffer->b_signlist != NULL
12760# ifdef FEAT_NETBEANS_INTG
12761 || wp->w_buffer->b_has_sign_column
12762# endif
12763 );
12764}
12765#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012766
12767#if defined(FEAT_EVAL) || defined(PROTO)
12768/*
12769 * Get window or buffer local options.
12770 */
12771 dict_T *
12772get_winbuf_options(int bufopt)
12773{
12774 dict_T *d;
12775 int opt_idx;
12776
12777 d = dict_alloc();
12778 if (d == NULL)
12779 return NULL;
12780
12781 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12782 {
12783 struct vimoption *opt = &options[opt_idx];
12784
12785 if ((bufopt && (opt->indir & PV_BUF))
12786 || (!bufopt && (opt->indir & PV_WIN)))
12787 {
12788 char_u *varp = get_varp(opt);
12789
12790 if (varp != NULL)
12791 {
12792 if (opt->flags & P_STRING)
12793 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012794 else if (opt->flags & P_NUM)
12795 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012796 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012797 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012798 }
12799 }
12800 }
12801
12802 return d;
12803}
12804#endif