blob: fa7eac4e1ad8dde9250da137b18aa849de1aa417 [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 Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram 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) \
482 || defined(FEAT_CONCEAL) || defined(FEAT_QUICKFIX)
483# 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"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000484#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100485# 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 +0000486#endif
487
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100488/* Default python version for pyx* commands */
489#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
490# define DEFAULT_PYTHON_VER 0
491#elif defined(FEAT_PYTHON3)
492# define DEFAULT_PYTHON_VER 3
493#elif defined(FEAT_PYTHON)
494# define DEFAULT_PYTHON_VER 2
495#else
496# define DEFAULT_PYTHON_VER 0
497#endif
498
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499/*
500 * options[] is initialized here.
501 * The order of the options MUST be alphabetic for ":set all" and findoption().
502 * All option names MUST start with a lowercase letter (for findoption()).
503 * Exception: "t_" options are at the end.
504 * The options with a NULL variable are 'hidden': a set command for them is
505 * ignored and they are not printed.
506 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100507static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200509 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510#ifdef FEAT_RIGHTLEFT
511 (char_u *)&p_aleph, PV_NONE,
512#else
513 (char_u *)NULL, PV_NONE,
514#endif
515 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100516#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000517 (char_u *)128L,
518#else
519 (char_u *)224L,
520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000521 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
523#if defined(FEAT_GUI) && defined(MACOS_X)
524 (char_u *)&p_antialias, PV_NONE,
525 {(char_u *)FALSE, (char_u *)FALSE}
526#else
527 (char_u *)NULL, PV_NONE,
528 {(char_u *)FALSE, (char_u *)FALSE}
529#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000530 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200531 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532#ifdef FEAT_ARABIC
533 (char_u *)VAR_WIN, PV_ARAB,
534#else
535 (char_u *)NULL, PV_NONE,
536#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
539#ifdef FEAT_ARABIC
540 (char_u *)&p_arshape, PV_NONE,
541#else
542 (char_u *)NULL, PV_NONE,
543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000544 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
546#ifdef FEAT_RIGHTLEFT
547 (char_u *)&p_ari, PV_NONE,
548#else
549 (char_u *)NULL, PV_NONE,
550#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000551 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
553#ifdef FEAT_FKMAP
554 (char_u *)&p_altkeymap, PV_NONE,
555#else
556 (char_u *)NULL, PV_NONE,
557#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
560#if defined(FEAT_MBYTE)
561 (char_u *)&p_ambw, PV_NONE,
562 {(char_u *)"single", (char_u *)0L}
563#else
564 (char_u *)NULL, PV_NONE,
565 {(char_u *)0L, (char_u *)0L}
566#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000567 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100569#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100571 {(char_u *)FALSE, (char_u *)0L}
572#else
573 (char_u *)NULL, PV_NONE,
574 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100576 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autoindent", "ai", P_BOOL|P_VI_DEF,
578 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"autoprint", "ap", P_BOOL|P_VI_DEF,
581 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000584 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"autowrite", "aw", P_BOOL|P_VI_DEF,
587 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589 {"autowriteall","awa", P_BOOL|P_VI_DEF,
590 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000591 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
593 (char_u *)&p_bg, PV_NONE,
594 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100595#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 (char_u *)"dark",
597#else
598 (char_u *)"light",
599#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200601 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
605 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000606 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200607 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200608 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609#ifdef UNIX
610 {(char_u *)"yes", (char_u *)"auto"}
611#else
612 {(char_u *)"auto", (char_u *)"auto"}
613#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000614 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200615 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
616 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000618 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000619 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000620 (char_u *)&p_bex, PV_NONE,
621 {
622#ifdef VMS
623 (char_u *)"_",
624#else
625 (char_u *)"~",
626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000627 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200628 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629#ifdef FEAT_WILDIGN
630 (char_u *)&p_bsk, PV_NONE,
631 {(char_u *)"", (char_u *)0L}
632#else
633 (char_u *)NULL, PV_NONE,
634 {(char_u *)0L, (char_u *)0L}
635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000636 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100638#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100640 {(char_u *)600L, (char_u *)0L}
641#else
642 (char_u *)NULL, PV_NONE,
643 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000644#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100645 SCRIPTID_INIT},
646 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
647#ifdef FEAT_BEVAL
648 (char_u *)&p_beval, PV_NONE,
649 {(char_u *)FALSE, (char_u *)0L}
650#else
651 (char_u *)NULL, PV_NONE,
652 {(char_u *)0L, (char_u *)0L}
653#endif
654 SCRIPTID_INIT},
655 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
656#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
657 (char_u *)&p_bexpr, PV_BEXPR,
658 {(char_u *)"", (char_u *)0L}
659#else
660 (char_u *)NULL, PV_NONE,
661 {(char_u *)0L, (char_u *)0L}
662#endif
663 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 {"beautify", "bf", P_BOOL|P_VI_DEF,
665 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000666 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200667 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
668 (char_u *)&p_bo, PV_NONE,
669 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
671 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000675 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
677#ifdef FEAT_MBYTE
678 (char_u *)&p_bomb, PV_BOMB,
679#else
680 (char_u *)NULL, PV_NONE,
681#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000682 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
684#ifdef FEAT_LINEBREAK
685 (char_u *)&p_breakat, PV_NONE,
686 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
687#else
688 (char_u *)NULL, PV_NONE,
689 {(char_u *)0L, (char_u *)0L}
690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000691 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200692 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
693#ifdef FEAT_LINEBREAK
694 (char_u *)VAR_WIN, PV_BRI,
695 {(char_u *)FALSE, (char_u *)0L}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)0L, (char_u *)0L}
699#endif
700 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200701 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
702 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200703#ifdef FEAT_LINEBREAK
704 (char_u *)VAR_WIN, PV_BRIOPT,
705 {(char_u *)"", (char_u *)NULL}
706#else
707 (char_u *)NULL, PV_NONE,
708 {(char_u *)"", (char_u *)NULL}
709#endif
710 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
712#ifdef FEAT_BROWSE
713 (char_u *)&p_bsdir, PV_NONE,
714 {(char_u *)"last", (char_u *)0L}
715#else
716 (char_u *)NULL, PV_NONE,
717 {(char_u *)0L, (char_u *)0L}
718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000719 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 (char_u *)&p_bh, PV_BH,
722 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000723 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
725 (char_u *)&p_bl, PV_BL,
726 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000727 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 (char_u *)&p_bt, PV_BT,
730 {(char_u *)"", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000731 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200732 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000733#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734 (char_u *)&p_cmp, PV_NONE,
735 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000736#else
737 (char_u *)NULL, PV_NONE,
738 {(char_u *)0L, (char_u *)0L}
739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000740 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
742#ifdef FEAT_SEARCHPATH
743 (char_u *)&p_cdpath, PV_NONE,
744 {(char_u *)",,", (char_u *)0L}
745#else
746 (char_u *)NULL, PV_NONE,
747 {(char_u *)0L, (char_u *)0L}
748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000749 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750 {"cedit", NULL, P_STRING,
751#ifdef FEAT_CMDWIN
752 (char_u *)&p_cedit, PV_NONE,
753 {(char_u *)"", (char_u *)CTRL_F_STR}
754#else
755 (char_u *)NULL, PV_NONE,
756 {(char_u *)0L, (char_u *)0L}
757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000758 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000759 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
760#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
761 (char_u *)&p_ccv, PV_NONE,
762 {(char_u *)"", (char_u *)0L}
763#else
764 (char_u *)NULL, PV_NONE,
765 {(char_u *)0L, (char_u *)0L}
766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000767 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
769#ifdef FEAT_CINDENT
770 (char_u *)&p_cin, PV_CIN,
771#else
772 (char_u *)NULL, PV_NONE,
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200775 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776#ifdef FEAT_CINDENT
777 (char_u *)&p_cink, PV_CINK,
778 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
779#else
780 (char_u *)NULL, PV_NONE,
781 {(char_u *)0L, (char_u *)0L}
782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000783 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200784 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000785#ifdef FEAT_CINDENT
786 (char_u *)&p_cino, PV_CINO,
787#else
788 (char_u *)NULL, PV_NONE,
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200791 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
793 (char_u *)&p_cinw, PV_CINW,
794 {(char_u *)"if,else,while,do,for,switch",
795 (char_u *)0L}
796#else
797 (char_u *)NULL, PV_NONE,
798 {(char_u *)0L, (char_u *)0L}
799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000800 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200801 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000802#ifdef FEAT_CLIPBOARD
803 (char_u *)&p_cb, PV_NONE,
804# ifdef FEAT_XCLIPBOARD
805 {(char_u *)"autoselect,exclude:cons\\|linux",
806 (char_u *)0L}
807# else
808 {(char_u *)"", (char_u *)0L}
809# endif
810#else
811 (char_u *)NULL, PV_NONE,
812 {(char_u *)"", (char_u *)0L}
813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000815 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
816 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000817 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
819#ifdef FEAT_CMDWIN
820 (char_u *)&p_cwh, PV_NONE,
821#else
822 (char_u *)NULL, PV_NONE,
823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200825 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200826#ifdef FEAT_SYN_HL
827 (char_u *)VAR_WIN, PV_CC,
828#else
829 (char_u *)NULL, PV_NONE,
830#endif
831 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000832 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
833 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000834 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200835 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
836 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837#ifdef FEAT_COMMENTS
838 (char_u *)&p_com, PV_COM,
839 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
840 (char_u *)0L}
841#else
842 (char_u *)NULL, PV_NONE,
843 {(char_u *)0L, (char_u *)0L}
844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000845 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200846 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847#ifdef FEAT_FOLDING
848 (char_u *)&p_cms, PV_CMS,
849 {(char_u *)"/*%s*/", (char_u *)0L}
850#else
851 (char_u *)NULL, PV_NONE,
852 {(char_u *)0L, (char_u *)0L}
853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000854 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000855 /* P_PRI_MKRC isn't needed here, optval_default()
856 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000857 {"compatible", "cp", P_BOOL|P_RALL,
858 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000859 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200860 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000861#ifdef FEAT_INS_EXPAND
862 (char_u *)&p_cpt, PV_CPT,
863 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
864#else
865 (char_u *)NULL, PV_NONE,
866 {(char_u *)0L, (char_u *)0L}
867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000868 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200869 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200870#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200871 (char_u *)VAR_WIN, PV_COCU,
872 {(char_u *)"", (char_u *)NULL}
873#else
874 (char_u *)NULL, PV_NONE,
875 {(char_u *)NULL, (char_u *)0L}
876#endif
877 SCRIPTID_INIT},
878 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
879#ifdef FEAT_CONCEAL
880 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200881#else
882 (char_u *)NULL, PV_NONE,
883#endif
884 {(char_u *)0L, (char_u *)0L}
885 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000886 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
887#ifdef FEAT_COMPL_FUNC
888 (char_u *)&p_cfu, PV_CFU,
889 {(char_u *)"", (char_u *)0L}
890#else
891 (char_u *)NULL, PV_NONE,
892 {(char_u *)0L, (char_u *)0L}
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200895 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000896#ifdef FEAT_INS_EXPAND
897 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000898 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000899#else
900 (char_u *)NULL, PV_NONE,
901 {(char_u *)0L, (char_u *)0L}
902#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 {"confirm", "cf", P_BOOL|P_VI_DEF,
905#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
906 (char_u *)&p_confirm, PV_NONE,
907#else
908 (char_u *)NULL, PV_NONE,
909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000913 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
915 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000916 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
918 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000919 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
920 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200921 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200922#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200923 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200924 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200925#else
926 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200927 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200928#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200929 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000930 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
931#ifdef FEAT_CSCOPE
932 (char_u *)&p_cspc, PV_NONE,
933#else
934 (char_u *)NULL, PV_NONE,
935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000936 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
938#ifdef FEAT_CSCOPE
939 (char_u *)&p_csprg, PV_NONE,
940 {(char_u *)"cscope", (char_u *)0L}
941#else
942 (char_u *)NULL, PV_NONE,
943 {(char_u *)0L, (char_u *)0L}
944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000945 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200946 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000947#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
948 (char_u *)&p_csqf, PV_NONE,
949 {(char_u *)"", (char_u *)0L}
950#else
951 (char_u *)NULL, PV_NONE,
952 {(char_u *)0L, (char_u *)0L}
953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200955 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
956#ifdef FEAT_CSCOPE
957 (char_u *)&p_csre, PV_NONE,
958#else
959 (char_u *)NULL, PV_NONE,
960#endif
961 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000962 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
963#ifdef FEAT_CSCOPE
964 (char_u *)&p_cst, PV_NONE,
965#else
966 (char_u *)NULL, PV_NONE,
967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000968 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
970#ifdef FEAT_CSCOPE
971 (char_u *)&p_csto, PV_NONE,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
977#ifdef FEAT_CSCOPE
978 (char_u *)&p_csverbose, PV_NONE,
979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200983 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
984#ifdef FEAT_CURSORBIND
985 (char_u *)VAR_WIN, PV_CRBIND,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000990 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
991#ifdef FEAT_SYN_HL
992 (char_u *)VAR_WIN, PV_CUC,
993#else
994 (char_u *)NULL, PV_NONE,
995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000996 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100997 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000998#ifdef FEAT_SYN_HL
999 (char_u *)VAR_WIN, PV_CUL,
1000#else
1001 (char_u *)NULL, PV_NONE,
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 {"debug", NULL, P_STRING|P_VI_DEF,
1005 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001006 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001007 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001009 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001010 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011#else
1012 (char_u *)NULL, PV_NONE,
1013 {(char_u *)NULL, (char_u *)0L}
1014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001015 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1017#ifdef FEAT_MBYTE
1018 (char_u *)&p_deco, PV_NONE,
1019#else
1020 (char_u *)NULL, PV_NONE,
1021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001022 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001023 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001025 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026#else
1027 (char_u *)NULL, PV_NONE,
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1031#ifdef FEAT_DIFF
1032 (char_u *)VAR_WIN, PV_DIFF,
1033#else
1034 (char_u *)NULL, PV_NONE,
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001037 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1039 (char_u *)&p_dex, PV_NONE,
1040 {(char_u *)"", (char_u *)0L}
1041#else
1042 (char_u *)NULL, PV_NONE,
1043 {(char_u *)0L, (char_u *)0L}
1044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001045 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001046 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1047 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048#ifdef FEAT_DIFF
1049 (char_u *)&p_dip, PV_NONE,
1050 {(char_u *)"filler", (char_u *)NULL}
1051#else
1052 (char_u *)NULL, PV_NONE,
1053 {(char_u *)"", (char_u *)NULL}
1054#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001055 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1057#ifdef FEAT_DIGRAPHS
1058 (char_u *)&p_dg, PV_NONE,
1059#else
1060 (char_u *)NULL, PV_NONE,
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001063 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1064 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001067 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001071#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 (char_u *)&p_ead, PV_NONE,
1073 {(char_u *)"both", (char_u *)0L}
1074#else
1075 (char_u *)NULL, PV_NONE,
1076 {(char_u *)NULL, (char_u *)0L}
1077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001078 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001079 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1080 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001082 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1083#if defined(FEAT_MBYTE)
1084 (char_u *)&p_emoji, PV_NONE,
1085 {(char_u *)TRUE, (char_u *)0L}
1086#else
1087 (char_u *)NULL, PV_NONE,
1088 {(char_u *)0L, (char_u *)0L}
1089#endif
1090 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001091 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092#ifdef FEAT_MBYTE
1093 (char_u *)&p_enc, PV_NONE,
1094 {(char_u *)ENC_DFLT, (char_u *)0L}
1095#else
1096 (char_u *)NULL, PV_NONE,
1097 {(char_u *)0L, (char_u *)0L}
1098#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1101 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1104 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001107 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1110 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1113#ifdef FEAT_QUICKFIX
1114 (char_u *)&p_ef, PV_NONE,
1115 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1116#else
1117 (char_u *)NULL, PV_NONE,
1118 {(char_u *)NULL, (char_u *)0L}
1119#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001120 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001121 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001123 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125#else
1126 (char_u *)NULL, PV_NONE,
1127 {(char_u *)NULL, (char_u *)0L}
1128#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001129 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130 {"esckeys", "ek", P_BOOL|P_VIM,
1131 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001132 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001133 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134#ifdef FEAT_AUTOCMD
1135 (char_u *)&p_ei, PV_NONE,
1136#else
1137 (char_u *)NULL, PV_NONE,
1138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1141 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001142 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1144 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001145 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001146 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1147 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148#ifdef FEAT_MBYTE
1149 (char_u *)&p_fenc, PV_FENC,
1150 {(char_u *)"", (char_u *)0L}
1151#else
1152 (char_u *)NULL, PV_NONE,
1153 {(char_u *)0L, (char_u *)0L}
1154#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001155 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001156 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157#ifdef FEAT_MBYTE
1158 (char_u *)&p_fencs, PV_NONE,
1159 {(char_u *)"ucs-bom", (char_u *)0L}
1160#else
1161 (char_u *)NULL, PV_NONE,
1162 {(char_u *)0L, (char_u *)0L}
1163#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001164 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001165 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1166 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001169 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001170 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1172 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001173 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1174 (char_u *)&p_fic, PV_NONE,
1175 {
1176#ifdef CASE_INSENSITIVE_FILENAME
1177 (char_u *)TRUE,
1178#else
1179 (char_u *)FALSE,
1180#endif
1181 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001182 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183#ifdef FEAT_AUTOCMD
1184 (char_u *)&p_ft, PV_FT,
1185 {(char_u *)"", (char_u *)0L}
1186#else
1187 (char_u *)NULL, PV_NONE,
1188 {(char_u *)0L, (char_u *)0L}
1189#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001190 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001191 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1193 (char_u *)&p_fcs, PV_NONE,
1194 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1195#else
1196 (char_u *)NULL, PV_NONE,
1197 {(char_u *)"", (char_u *)0L}
1198#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001199 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001200 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1201 (char_u *)&p_fixeol, PV_FIXEOL,
1202 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001203 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1204#ifdef FEAT_FKMAP
1205 (char_u *)&p_fkmap, PV_NONE,
1206#else
1207 (char_u *)NULL, PV_NONE,
1208#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"flash", "fl", P_BOOL|P_VI_DEF,
1211 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001213 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001214#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001216 {(char_u *)"", (char_u *)0L}
1217#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 (char_u *)NULL, PV_NONE,
1219 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001220#endif
1221 SCRIPTID_INIT},
1222 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1223#ifdef FEAT_FOLDING
1224 (char_u *)VAR_WIN, PV_FDC,
1225 {(char_u *)FALSE, (char_u *)0L}
1226#else
1227 (char_u *)NULL, PV_NONE,
1228 {(char_u *)NULL, (char_u *)0L}
1229#endif
1230 SCRIPTID_INIT},
1231 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1232#ifdef FEAT_FOLDING
1233 (char_u *)VAR_WIN, PV_FEN,
1234 {(char_u *)TRUE, (char_u *)0L}
1235#else
1236 (char_u *)NULL, PV_NONE,
1237 {(char_u *)NULL, (char_u *)0L}
1238#endif
1239 SCRIPTID_INIT},
1240 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1241#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1242 (char_u *)VAR_WIN, PV_FDE,
1243 {(char_u *)"0", (char_u *)NULL}
1244#else
1245 (char_u *)NULL, PV_NONE,
1246 {(char_u *)NULL, (char_u *)0L}
1247#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001248 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001250#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001251 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001252 {(char_u *)"#", (char_u *)NULL}
1253#else
1254 (char_u *)NULL, PV_NONE,
1255 {(char_u *)NULL, (char_u *)0L}
1256#endif
1257 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001259#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001260 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001261 {(char_u *)0L, (char_u *)0L}
1262#else
1263 (char_u *)NULL, PV_NONE,
1264 {(char_u *)NULL, (char_u *)0L}
1265#endif
1266 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001267 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001268#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001269 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001270 {(char_u *)-1L, (char_u *)0L}
1271#else
1272 (char_u *)NULL, PV_NONE,
1273 {(char_u *)NULL, (char_u *)0L}
1274#endif
1275 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001277 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001278#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001279 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001280 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001281#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282 (char_u *)NULL, PV_NONE,
1283 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001284#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001285 SCRIPTID_INIT},
1286 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1287#ifdef FEAT_FOLDING
1288 (char_u *)VAR_WIN, PV_FDM,
1289 {(char_u *)"manual", (char_u *)NULL}
1290#else
1291 (char_u *)NULL, PV_NONE,
1292 {(char_u *)NULL, (char_u *)0L}
1293#endif
1294 SCRIPTID_INIT},
1295 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1296#ifdef FEAT_FOLDING
1297 (char_u *)VAR_WIN, PV_FML,
1298 {(char_u *)1L, (char_u *)0L}
1299#else
1300 (char_u *)NULL, PV_NONE,
1301 {(char_u *)NULL, (char_u *)0L}
1302#endif
1303 SCRIPTID_INIT},
1304 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1305#ifdef FEAT_FOLDING
1306 (char_u *)VAR_WIN, PV_FDN,
1307 {(char_u *)20L, (char_u *)0L}
1308#else
1309 (char_u *)NULL, PV_NONE,
1310 {(char_u *)NULL, (char_u *)0L}
1311#endif
1312 SCRIPTID_INIT},
1313 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1314#ifdef FEAT_FOLDING
1315 (char_u *)&p_fdo, PV_NONE,
1316 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1317 (char_u *)0L}
1318#else
1319 (char_u *)NULL, PV_NONE,
1320 {(char_u *)NULL, (char_u *)0L}
1321#endif
1322 SCRIPTID_INIT},
1323 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1324#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1325 (char_u *)VAR_WIN, PV_FDT,
1326 {(char_u *)"foldtext()", (char_u *)NULL}
1327#else
1328 (char_u *)NULL, PV_NONE,
1329 {(char_u *)NULL, (char_u *)0L}
1330#endif
1331 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001332 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001333#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001334 (char_u *)&p_fex, PV_FEX,
1335 {(char_u *)"", (char_u *)0L}
1336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)0L, (char_u *)0L}
1339#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001340 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1342 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001343 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1344 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001345 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1346 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001347 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1348 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001350 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001351 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001352 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1353#ifdef HAVE_FSYNC
1354 (char_u *)&p_fs, PV_NONE,
1355 {(char_u *)TRUE, (char_u *)0L}
1356#else
1357 (char_u *)NULL, PV_NONE,
1358 {(char_u *)FALSE, (char_u *)0L}
1359#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001360 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1362 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001363 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364 {"graphic", "gr", P_BOOL|P_VI_DEF,
1365 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001366 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001367 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368#ifdef FEAT_QUICKFIX
1369 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001370 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001375 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1377#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001378 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379 {
1380# ifdef WIN3264
1381 /* may be changed to "grep -n" in os_win32.c */
1382 (char_u *)"findstr /n",
1383# else
1384# ifdef UNIX
1385 /* Add an extra file name so that grep will always
1386 * insert a file name in the match line. */
1387 (char_u *)"grep -n $* /dev/null",
1388# else
1389# ifdef VMS
1390 (char_u *)"SEARCH/NUMBERS ",
1391# else
1392 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001393# endif
1394# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001396 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001397#else
1398 (char_u *)NULL, PV_NONE,
1399 {(char_u *)NULL, (char_u *)0L}
1400#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001401 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001402 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403#ifdef CURSOR_SHAPE
1404 (char_u *)&p_guicursor, PV_NONE,
1405 {
1406# ifdef FEAT_GUI
1407 (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 +01001408# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001409 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1410# endif
1411 (char_u *)0L}
1412#else
1413 (char_u *)NULL, PV_NONE,
1414 {(char_u *)NULL, (char_u *)0L}
1415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001416 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001417 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001418#ifdef FEAT_GUI
1419 (char_u *)&p_guifont, PV_NONE,
1420 {(char_u *)"", (char_u *)0L}
1421#else
1422 (char_u *)NULL, PV_NONE,
1423 {(char_u *)NULL, (char_u *)0L}
1424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001425 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001426 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1428 (char_u *)&p_guifontset, PV_NONE,
1429 {(char_u *)"", (char_u *)0L}
1430#else
1431 (char_u *)NULL, PV_NONE,
1432 {(char_u *)NULL, (char_u *)0L}
1433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001435 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1437 (char_u *)&p_guifontwide, PV_NONE,
1438 {(char_u *)"", (char_u *)0L}
1439#else
1440 (char_u *)NULL, PV_NONE,
1441 {(char_u *)NULL, (char_u *)0L}
1442#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001443 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001444 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001445#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001446 (char_u *)&p_ghr, PV_NONE,
1447#else
1448 (char_u *)NULL, PV_NONE,
1449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001452#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 (char_u *)&p_go, PV_NONE,
1454# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001455 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001457 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458# endif
1459#else
1460 (char_u *)NULL, PV_NONE,
1461 {(char_u *)NULL, (char_u *)0L}
1462#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001463 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 {"guipty", NULL, P_BOOL|P_VI_DEF,
1465#if defined(FEAT_GUI)
1466 (char_u *)&p_guipty, PV_NONE,
1467#else
1468 (char_u *)NULL, PV_NONE,
1469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001470 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001471 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001472#if defined(FEAT_GUI_TABLINE)
1473 (char_u *)&p_gtl, PV_NONE,
1474 {(char_u *)"", (char_u *)0L}
1475#else
1476 (char_u *)NULL, PV_NONE,
1477 {(char_u *)NULL, (char_u *)0L}
1478#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001479 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001480 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001481#if defined(FEAT_GUI_TABLINE)
1482 (char_u *)&p_gtt, PV_NONE,
1483 {(char_u *)"", (char_u *)0L}
1484#else
1485 (char_u *)NULL, PV_NONE,
1486 {(char_u *)NULL, (char_u *)0L}
1487#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001488 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1490 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001491 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001492 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1493 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001494 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1495 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496 {"helpheight", "hh", P_NUM|P_VI_DEF,
1497#ifdef FEAT_WINDOWS
1498 (char_u *)&p_hh, PV_NONE,
1499#else
1500 (char_u *)NULL, PV_NONE,
1501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001503 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504#ifdef FEAT_MULTI_LANG
1505 (char_u *)&p_hlg, PV_NONE,
1506 {(char_u *)"", (char_u *)0L}
1507#else
1508 (char_u *)NULL, PV_NONE,
1509 {(char_u *)0L, (char_u *)0L}
1510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001511 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"hidden", "hid", P_BOOL|P_VI_DEF,
1513 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001515 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001517 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1518 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 {"history", "hi", P_NUM|P_VIM,
1520 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001521 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1523#ifdef FEAT_RIGHTLEFT
1524 (char_u *)&p_hkmap, PV_NONE,
1525#else
1526 (char_u *)NULL, PV_NONE,
1527#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001528 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1530#ifdef FEAT_RIGHTLEFT
1531 (char_u *)&p_hkmapp, PV_NONE,
1532#else
1533 (char_u *)NULL, PV_NONE,
1534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001536 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1537 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001538 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001539 {"icon", NULL, P_BOOL|P_VI_DEF,
1540#ifdef FEAT_TITLE
1541 (char_u *)&p_icon, PV_NONE,
1542#else
1543 (char_u *)NULL, PV_NONE,
1544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"iconstring", NULL, P_STRING|P_VI_DEF,
1547#ifdef FEAT_TITLE
1548 (char_u *)&p_iconstring, PV_NONE,
1549#else
1550 (char_u *)NULL, PV_NONE,
1551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001552 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1554 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001556 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1557# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1558 (char_u *)&p_imaf, PV_NONE,
1559 {(char_u *)"", (char_u *)NULL}
1560# else
1561 (char_u *)NULL, PV_NONE,
1562 {(char_u *)NULL, (char_u *)0L}
1563# endif
1564 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001565 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001566#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 (char_u *)&p_imak, PV_NONE,
1568#else
1569 (char_u *)NULL, PV_NONE,
1570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001571 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1573#ifdef USE_IM_CONTROL
1574 (char_u *)&p_imcmdline, PV_NONE,
1575#else
1576 (char_u *)NULL, PV_NONE,
1577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1580#ifdef USE_IM_CONTROL
1581 (char_u *)&p_imdisable, PV_NONE,
1582#else
1583 (char_u *)NULL, PV_NONE,
1584#endif
1585#ifdef __sgi
1586 {(char_u *)TRUE, (char_u *)0L}
1587#else
1588 {(char_u *)FALSE, (char_u *)0L}
1589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001590 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001591 {"iminsert", "imi", P_NUM|P_VI_DEF,
1592 (char_u *)&p_iminsert, PV_IMI,
1593#ifdef B_IMODE_IM
1594 {(char_u *)B_IMODE_IM, (char_u *)0L}
1595#else
1596 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001598 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 {"imsearch", "ims", P_NUM|P_VI_DEF,
1600 (char_u *)&p_imsearch, PV_IMS,
1601#ifdef B_IMODE_IM
1602 {(char_u *)B_IMODE_IM, (char_u *)0L}
1603#else
1604 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001606 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001607 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001608# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1609 (char_u *)&p_imsf, PV_NONE,
1610 {(char_u *)"", (char_u *)NULL}
1611# else
1612 (char_u *)NULL, PV_NONE,
1613 {(char_u *)NULL, (char_u *)0L}
1614# endif
1615 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001616 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1617#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001618 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001619 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1620#else
1621 (char_u *)NULL, PV_NONE,
1622 {(char_u *)0L, (char_u *)0L}
1623#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001624 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001625 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1626#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1627 (char_u *)&p_inex, PV_INEX,
1628 {(char_u *)"", (char_u *)0L}
1629#else
1630 (char_u *)NULL, PV_NONE,
1631 {(char_u *)0L, (char_u *)0L}
1632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001633 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001634 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1635 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001636 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001637 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1638#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1639 (char_u *)&p_inde, PV_INDE,
1640 {(char_u *)"", (char_u *)0L}
1641#else
1642 (char_u *)NULL, PV_NONE,
1643 {(char_u *)0L, (char_u *)0L}
1644#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001645 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001646 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1648 (char_u *)&p_indk, PV_INDK,
1649 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1650#else
1651 (char_u *)NULL, PV_NONE,
1652 {(char_u *)0L, (char_u *)0L}
1653#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001654 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655 {"infercase", "inf", P_BOOL|P_VI_DEF,
1656 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001657 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1659 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001660 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1662 (char_u *)&p_isf, PV_NONE,
1663 {
1664#ifdef BACKSLASH_IN_FILENAME
1665 /* Excluded are: & and ^ are special in cmd.exe
1666 * ( and ) are used in text separating fnames */
1667 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1668#else
1669# ifdef AMIGA
1670 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1671# else
1672# ifdef VMS
1673 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1674# else /* UNIX et al. */
1675# ifdef EBCDIC
1676 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1677# else
1678 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1679# endif
1680# endif
1681# endif
1682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001683 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001684 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1685 (char_u *)&p_isi, PV_NONE,
1686 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001687#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 (char_u *)"@,48-57,_,128-167,224-235",
1689#else
1690# ifdef EBCDIC
1691 /* TODO: EBCDIC Check this! @ == isalpha()*/
1692 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1693 "112-120,128,140-142,156,158,172,"
1694 "174,186,191,203-207,219-225,235-239,"
1695 "251-254",
1696# else
1697 (char_u *)"@,48-57,_,192-255",
1698# endif
1699#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001700 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1702 (char_u *)&p_isk, PV_ISK,
1703 {
1704#ifdef EBCDIC
1705 (char_u *)"@,240-249,_",
1706 /* TODO: EBCDIC Check this! @ == isalpha()*/
1707 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1708 "112-120,128,140-142,156,158,172,"
1709 "174,186,191,203-207,219-225,235-239,"
1710 "251-254",
1711#else
1712 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001713# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714 (char_u *)"@,48-57,_,128-167,224-235"
1715# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001716 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717# endif
1718#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001719 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1721 (char_u *)&p_isp, PV_NONE,
1722 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001723#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724 || defined(VMS)
1725 (char_u *)"@,~-255",
1726#else
1727# ifdef EBCDIC
1728 /* all chars above 63 are printable */
1729 (char_u *)"63-255",
1730# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001731 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732# endif
1733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001734 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1736 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001737 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1739#ifdef FEAT_CRYPT
1740 (char_u *)&p_key, PV_KEY,
1741 {(char_u *)"", (char_u *)0L}
1742#else
1743 (char_u *)NULL, PV_NONE,
1744 {(char_u *)0L, (char_u *)0L}
1745#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001746 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001747 {"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 +00001748#ifdef FEAT_KEYMAP
1749 (char_u *)&p_keymap, PV_KMAP,
1750 {(char_u *)"", (char_u *)0L}
1751#else
1752 (char_u *)NULL, PV_NONE,
1753 {(char_u *)"", (char_u *)0L}
1754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001755 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001756 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001758 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001760 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001762#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 (char_u *)":help",
1764#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001765# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001767# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001768# ifdef USEMAN_S
1769 (char_u *)"man -s",
1770# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001772# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773# endif
1774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001775 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001776 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777#ifdef FEAT_LANGMAP
1778 (char_u *)&p_langmap, PV_NONE,
1779 {(char_u *)"", /* unmatched } */
1780#else
1781 (char_u *)NULL, PV_NONE,
1782 {(char_u *)NULL,
1783#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001784 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001785 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1787 (char_u *)&p_lm, PV_NONE,
1788#else
1789 (char_u *)NULL, PV_NONE,
1790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001792 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1793#ifdef FEAT_LANGMAP
1794 (char_u *)&p_lnr, PV_NONE,
1795#else
1796 (char_u *)NULL, PV_NONE,
1797#endif
1798 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001799 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1800#ifdef FEAT_LANGMAP
1801 (char_u *)&p_lrm, PV_NONE,
1802#else
1803 (char_u *)NULL, PV_NONE,
1804#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001805 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001806 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1807#ifdef FEAT_WINDOWS
1808 (char_u *)&p_ls, PV_NONE,
1809#else
1810 (char_u *)NULL, PV_NONE,
1811#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001812 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1814 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001815 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1817#ifdef FEAT_LINEBREAK
1818 (char_u *)VAR_WIN, PV_LBR,
1819#else
1820 (char_u *)NULL, PV_NONE,
1821#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1824 (char_u *)&Rows, PV_NONE,
1825 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001826#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 (char_u *)25L,
1828#else
1829 (char_u *)24L,
1830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001831 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1833#ifdef FEAT_GUI
1834 (char_u *)&p_linespace, PV_NONE,
1835#else
1836 (char_u *)NULL, PV_NONE,
1837#endif
1838#ifdef FEAT_GUI_W32
1839 {(char_u *)1L, (char_u *)0L}
1840#else
1841 {(char_u *)0L, (char_u *)0L}
1842#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001844 {"lisp", NULL, P_BOOL|P_VI_DEF,
1845#ifdef FEAT_LISP
1846 (char_u *)&p_lisp, PV_LISP,
1847#else
1848 (char_u *)NULL, PV_NONE,
1849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001851 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001853 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001854 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1855#else
1856 (char_u *)NULL, PV_NONE,
1857 {(char_u *)"", (char_u *)0L}
1858#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001859 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1861 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001863 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001865 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1867 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001868 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001869 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001870#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001871 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001872 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001873#else
1874 (char_u *)NULL, PV_NONE,
1875 {(char_u *)"", (char_u *)0L}
1876#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001877 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001878 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001879#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001880 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001881 {(char_u *)TRUE, (char_u *)0L}
1882#else
1883 (char_u *)NULL, PV_NONE,
1884 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001885#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001886 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001887 {"magic", NULL, P_BOOL|P_VI_DEF,
1888 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001889 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001890 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891#ifdef FEAT_QUICKFIX
1892 (char_u *)&p_mef, PV_NONE,
1893 {(char_u *)"", (char_u *)0L}
1894#else
1895 (char_u *)NULL, PV_NONE,
1896 {(char_u *)NULL, (char_u *)0L}
1897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001899 {"makeencoding","menc", P_STRING|P_VI_DEF,
1900#ifdef FEAT_MBYTE
1901 (char_u *)&p_menc, PV_MENC,
1902 {(char_u *)"", (char_u *)0L}
1903#else
1904 (char_u *)NULL, PV_NONE,
1905 {(char_u *)0L, (char_u *)0L}
1906#endif
1907 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001908 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1909#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001910 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001911# ifdef VMS
1912 {(char_u *)"MMS", (char_u *)0L}
1913# else
1914 {(char_u *)"make", (char_u *)0L}
1915# endif
1916#else
1917 (char_u *)NULL, PV_NONE,
1918 {(char_u *)NULL, (char_u *)0L}
1919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001920 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001921 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001922 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001923 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1924 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"matchtime", "mat", P_NUM|P_VI_DEF,
1926 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001928 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001929#ifdef FEAT_MBYTE
1930 (char_u *)&p_mco, PV_NONE,
1931#else
1932 (char_u *)NULL, PV_NONE,
1933#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1936#ifdef FEAT_EVAL
1937 (char_u *)&p_mfd, PV_NONE,
1938#else
1939 (char_u *)NULL, PV_NONE,
1940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1943 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 {"maxmem", "mm", P_NUM|P_VI_DEF,
1946 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1948 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001949 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1950 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1953 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1955 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"menuitems", "mis", P_NUM|P_VI_DEF,
1957#ifdef FEAT_MENU
1958 (char_u *)&p_mis, PV_NONE,
1959#else
1960 (char_u *)NULL, PV_NONE,
1961#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001962 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"mesg", NULL, P_BOOL|P_VI_DEF,
1964 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001965 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001966 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001967#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001968 (char_u *)&p_msm, PV_NONE,
1969 {(char_u *)"460000,2000,500", (char_u *)0L}
1970#else
1971 (char_u *)NULL, PV_NONE,
1972 {(char_u *)0L, (char_u *)0L}
1973#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001974 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001975 {"modeline", "ml", P_BOOL|P_VIM,
1976 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"modelines", "mls", P_NUM|P_VI_DEF,
1979 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001980 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1982 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001983 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1985 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001986 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 {"more", NULL, P_BOOL|P_VIM,
1988 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001989 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001990 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1991 (char_u *)&p_mouse, PV_NONE,
1992 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001993#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 (char_u *)"a",
1995#else
1996 (char_u *)"",
1997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
2000#ifdef FEAT_GUI
2001 (char_u *)&p_mousef, PV_NONE,
2002#else
2003 (char_u *)NULL, PV_NONE,
2004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2007#ifdef FEAT_GUI
2008 (char_u *)&p_mh, PV_NONE,
2009#else
2010 (char_u *)NULL, PV_NONE,
2011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2014 (char_u *)&p_mousem, PV_NONE,
2015 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002016#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 (char_u *)"popup",
2018#else
2019# if defined(MACOS)
2020 (char_u *)"popup_setpos",
2021# else
2022 (char_u *)"extend",
2023# endif
2024#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002025 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002026 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027#ifdef FEAT_MOUSESHAPE
2028 (char_u *)&p_mouseshape, PV_NONE,
2029 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2030#else
2031 (char_u *)NULL, PV_NONE,
2032 {(char_u *)NULL, (char_u *)0L}
2033#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002034 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2036 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002037 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002038 {"mzquantum", "mzq", P_NUM,
2039#ifdef FEAT_MZSCHEME
2040 (char_u *)&p_mzq, PV_NONE,
2041#else
2042 (char_u *)NULL, PV_NONE,
2043#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045 {"novice", NULL, P_BOOL|P_VI_DEF,
2046 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002047 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002048 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002050 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2053 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002055 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2056#ifdef FEAT_LINEBREAK
2057 (char_u *)VAR_WIN, PV_NUW,
2058#else
2059 (char_u *)NULL, PV_NONE,
2060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002062 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002063#ifdef FEAT_COMPL_FUNC
2064 (char_u *)&p_ofu, PV_OFU,
2065 {(char_u *)"", (char_u *)0L}
2066#else
2067 (char_u *)NULL, PV_NONE,
2068 {(char_u *)0L, (char_u *)0L}
2069#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002070 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 {"open", NULL, P_BOOL|P_VI_DEF,
2072 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002073 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002074 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002075#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002076 (char_u *)&p_odev, PV_NONE,
2077#else
2078 (char_u *)NULL, PV_NONE,
2079#endif
2080 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002081 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002082 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2083 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002084 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085 {"optimize", "opt", P_BOOL|P_VI_DEF,
2086 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002087 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002089 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002090 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002091 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2092 |P_SECURE,
2093 (char_u *)&p_pp, PV_NONE,
2094 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2095 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 {"paragraphs", "para", P_STRING|P_VI_DEF,
2097 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002098 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002099 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002100 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002101 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002102 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2104 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002105 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002106 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2107#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2108 (char_u *)&p_pex, PV_NONE,
2109 {(char_u *)"", (char_u *)0L}
2110#else
2111 (char_u *)NULL, PV_NONE,
2112 {(char_u *)0L, (char_u *)0L}
2113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002115 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002117 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002119 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002120 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002121#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 (char_u *)".,,",
2123#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002126 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002127 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002128#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002129 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002130 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002131#else
2132 (char_u *)NULL, PV_NONE,
2133 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002134#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002135 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2137 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002138 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002139 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2141 (char_u *)&p_pvh, PV_NONE,
2142#else
2143 (char_u *)NULL, PV_NONE,
2144#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2147#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2148 (char_u *)VAR_WIN, PV_PVW,
2149#else
2150 (char_u *)NULL, PV_NONE,
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002153 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154#ifdef FEAT_PRINTER
2155 (char_u *)&p_pdev, PV_NONE,
2156 {(char_u *)"", (char_u *)0L}
2157#else
2158 (char_u *)NULL, PV_NONE,
2159 {(char_u *)NULL, (char_u *)0L}
2160#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002161 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002162 {"printencoding", "penc", P_STRING|P_VI_DEF,
2163#ifdef FEAT_POSTSCRIPT
2164 (char_u *)&p_penc, PV_NONE,
2165 {(char_u *)"", (char_u *)0L}
2166#else
2167 (char_u *)NULL, PV_NONE,
2168 {(char_u *)NULL, (char_u *)0L}
2169#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002170 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002171 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172#ifdef FEAT_POSTSCRIPT
2173 (char_u *)&p_pexpr, PV_NONE,
2174 {(char_u *)"", (char_u *)0L}
2175#else
2176 (char_u *)NULL, PV_NONE,
2177 {(char_u *)NULL, (char_u *)0L}
2178#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002179 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002180 {"printfont", "pfn", P_STRING|P_VI_DEF,
2181#ifdef FEAT_PRINTER
2182 (char_u *)&p_pfn, PV_NONE,
2183 {
2184# ifdef MSWIN
2185 (char_u *)"Courier_New:h10",
2186# else
2187 (char_u *)"courier",
2188# endif
2189 (char_u *)0L}
2190#else
2191 (char_u *)NULL, PV_NONE,
2192 {(char_u *)NULL, (char_u *)0L}
2193#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002194 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002195 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2196#ifdef FEAT_PRINTER
2197 (char_u *)&p_header, PV_NONE,
2198 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2199#else
2200 (char_u *)NULL, PV_NONE,
2201 {(char_u *)NULL, (char_u *)0L}
2202#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002203 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002204 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2205#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2206 (char_u *)&p_pmcs, PV_NONE,
2207 {(char_u *)"", (char_u *)0L}
2208#else
2209 (char_u *)NULL, PV_NONE,
2210 {(char_u *)NULL, (char_u *)0L}
2211#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002212 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002213 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2214#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2215 (char_u *)&p_pmfn, PV_NONE,
2216 {(char_u *)"", (char_u *)0L}
2217#else
2218 (char_u *)NULL, PV_NONE,
2219 {(char_u *)NULL, (char_u *)0L}
2220#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002222 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002223#ifdef FEAT_PRINTER
2224 (char_u *)&p_popt, PV_NONE,
2225 {(char_u *)"", (char_u *)0L}
2226#else
2227 (char_u *)NULL, PV_NONE,
2228 {(char_u *)NULL, (char_u *)0L}
2229#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002230 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002232 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002233 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002234 {"pumheight", "ph", P_NUM|P_VI_DEF,
2235#ifdef FEAT_INS_EXPAND
2236 (char_u *)&p_ph, PV_NONE,
2237#else
2238 (char_u *)NULL, PV_NONE,
2239#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002240 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002241 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002242#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002243 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002244 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002245#else
2246 (char_u *)NULL, PV_NONE,
2247 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002248#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002249 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002250 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002251#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002252 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002253 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002254#else
2255 (char_u *)NULL, PV_NONE,
2256 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002257#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002258 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002259 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2260#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2261 (char_u *)&p_pyx, PV_NONE,
2262#else
2263 (char_u *)NULL, PV_NONE,
2264#endif
2265 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2266 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002267 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2268#ifdef FEAT_TEXTOBJ
2269 (char_u *)&p_qe, PV_QE,
2270 {(char_u *)"\\", (char_u *)0L}
2271#else
2272 (char_u *)NULL, PV_NONE,
2273 {(char_u *)NULL, (char_u *)0L}
2274#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002275 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002276 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2277 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002278 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 {"redraw", NULL, P_BOOL|P_VI_DEF,
2280 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002281 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002282 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2283#ifdef FEAT_RELTIME
2284 (char_u *)&p_rdt, PV_NONE,
2285#else
2286 (char_u *)NULL, PV_NONE,
2287#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002288 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002289 {"regexpengine", "re", P_NUM|P_VI_DEF,
2290 (char_u *)&p_re, PV_NONE,
2291 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002292 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2293 (char_u *)VAR_WIN, PV_RNU,
2294 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 {"remap", NULL, P_BOOL|P_VI_DEF,
2296 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002298 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002299#ifdef FEAT_RENDER_OPTIONS
2300 (char_u *)&p_rop, PV_NONE,
2301 {(char_u *)"", (char_u *)0L}
2302#else
2303 (char_u *)NULL, PV_NONE,
2304 {(char_u *)NULL, (char_u *)0L}
2305#endif
2306 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 {"report", NULL, P_NUM|P_VI_DEF,
2308 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002309 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2311#ifdef WIN3264
2312 (char_u *)&p_rs, PV_NONE,
2313#else
2314 (char_u *)NULL, PV_NONE,
2315#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2318#ifdef FEAT_RIGHTLEFT
2319 (char_u *)&p_ri, PV_NONE,
2320#else
2321 (char_u *)NULL, PV_NONE,
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2325#ifdef FEAT_RIGHTLEFT
2326 (char_u *)VAR_WIN, PV_RL,
2327#else
2328 (char_u *)NULL, PV_NONE,
2329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2332#ifdef FEAT_RIGHTLEFT
2333 (char_u *)VAR_WIN, PV_RLC,
2334 {(char_u *)"search", (char_u *)NULL}
2335#else
2336 (char_u *)NULL, PV_NONE,
2337 {(char_u *)NULL, (char_u *)0L}
2338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002340 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002341#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002342 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002343 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002344#else
2345 (char_u *)NULL, PV_NONE,
2346 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002347#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002348 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2350#ifdef FEAT_CMDL_INFO
2351 (char_u *)&p_ru, PV_NONE,
2352#else
2353 (char_u *)NULL, PV_NONE,
2354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002355 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2357#ifdef FEAT_STL_OPT
2358 (char_u *)&p_ruf, PV_NONE,
2359#else
2360 (char_u *)NULL, PV_NONE,
2361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002363 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2364 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2367 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2369 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002370 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2372#ifdef FEAT_SCROLLBIND
2373 (char_u *)VAR_WIN, PV_SCBIND,
2374#else
2375 (char_u *)NULL, PV_NONE,
2376#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2379 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2382 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002383 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002384 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385#ifdef FEAT_SCROLLBIND
2386 (char_u *)&p_sbo, PV_NONE,
2387 {(char_u *)"ver,jump", (char_u *)0L}
2388#else
2389 (char_u *)NULL, PV_NONE,
2390 {(char_u *)0L, (char_u *)0L}
2391#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"sections", "sect", P_STRING|P_VI_DEF,
2394 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2396 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2398 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)"inclusive", (char_u *)0L}
2403 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002404 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002405 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002407 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408#ifdef FEAT_SESSION
2409 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002410 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002411 (char_u *)0L}
2412#else
2413 (char_u *)NULL, PV_NONE,
2414 {(char_u *)0L, (char_u *)0L}
2415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2418 (char_u *)&p_sh, PV_NONE,
2419 {
2420#ifdef VMS
2421 (char_u *)"-",
2422#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002423# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002425# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427# endif
2428#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002429 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2431 (char_u *)&p_shcf, PV_NONE,
2432 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002433#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 (char_u *)"/c",
2435#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002436 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2440#ifdef FEAT_QUICKFIX
2441 (char_u *)&p_sp, PV_NONE,
2442 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002443#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445#else
2446 (char_u *)">",
2447#endif
2448 (char_u *)0L}
2449#else
2450 (char_u *)NULL, PV_NONE,
2451 {(char_u *)0L, (char_u *)0L}
2452#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2455 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002456 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2458 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2461#ifdef BACKSLASH_IN_FILENAME
2462 (char_u *)&p_ssl, PV_NONE,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002467 {"shelltemp", "stmp", P_BOOL,
2468 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"shelltype", "st", P_NUM|P_VI_DEF,
2471#ifdef AMIGA
2472 (char_u *)&p_st, PV_NONE,
2473#else
2474 (char_u *)NULL, PV_NONE,
2475#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2478 (char_u *)&p_sxq, PV_NONE,
2479 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002480#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 (char_u *)"\"",
2482#else
2483 (char_u *)"",
2484#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002485 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002486 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2487 (char_u *)&p_sxe, PV_NONE,
2488 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002489#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002490 (char_u *)"\"&|<>()@^",
2491#else
2492 (char_u *)"",
2493#endif
2494 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2496 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002497 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2499 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002500 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2502 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002503 {(char_u *)"", (char_u *)"filnxtToO"}
2504 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2509#ifdef FEAT_LINEBREAK
2510 (char_u *)&p_sbr, PV_NONE,
2511#else
2512 (char_u *)NULL, PV_NONE,
2513#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"showcmd", "sc", P_BOOL|P_VIM,
2516#ifdef FEAT_CMDL_INFO
2517 (char_u *)&p_sc, PV_NONE,
2518#else
2519 (char_u *)NULL, PV_NONE,
2520#endif
2521 {(char_u *)FALSE,
2522#ifdef UNIX
2523 (char_u *)FALSE
2524#else
2525 (char_u *)TRUE
2526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2529 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002530 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2532 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002533 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"showmode", "smd", P_BOOL|P_VIM,
2535 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002536 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002537 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2538#ifdef FEAT_WINDOWS
2539 (char_u *)&p_stal, PV_NONE,
2540#else
2541 (char_u *)NULL, PV_NONE,
2542#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2545 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002546 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002547 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2548 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002549 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002550 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2551#ifdef FEAT_SIGNS
2552 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002553 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002554#else
2555 (char_u *)NULL, PV_NONE,
2556 {(char_u *)NULL, (char_u *)0L}
2557#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002558 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002559 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2560 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002562 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2563 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2566#ifdef FEAT_SMARTINDENT
2567 (char_u *)&p_si, PV_SI,
2568#else
2569 (char_u *)NULL, PV_NONE,
2570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2573 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2576 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2579 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002580 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002581 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002582#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002583 (char_u *)VAR_WIN, PV_SPELL,
2584#else
2585 (char_u *)NULL, PV_NONE,
2586#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002588 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002589#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002590 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002591 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002592#else
2593 (char_u *)NULL, PV_NONE,
2594 {(char_u *)0L, (char_u *)0L}
2595#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002597 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2598 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002599#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002600 (char_u *)&p_spf, PV_SPF,
2601 {(char_u *)"", (char_u *)0L}
2602#else
2603 (char_u *)NULL, PV_NONE,
2604 {(char_u *)0L, (char_u *)0L}
2605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002606 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002607 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2608 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002609#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002610 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002611 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002612#else
2613 (char_u *)NULL, PV_NONE,
2614 {(char_u *)0L, (char_u *)0L}
2615#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002616 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002617 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002618#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002619 (char_u *)&p_sps, PV_NONE,
2620 {(char_u *)"best", (char_u *)0L}
2621#else
2622 (char_u *)NULL, PV_NONE,
2623 {(char_u *)0L, (char_u *)0L}
2624#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002625 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2627#ifdef FEAT_WINDOWS
2628 (char_u *)&p_sb, PV_NONE,
2629#else
2630 (char_u *)NULL, PV_NONE,
2631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002634#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 (char_u *)&p_spr, PV_NONE,
2636#else
2637 (char_u *)NULL, PV_NONE,
2638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2641 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002642 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002643 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2644#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002645 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646#else
2647 (char_u *)NULL, PV_NONE,
2648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002650 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 (char_u *)&p_su, PV_NONE,
2652 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002654 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002655#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 (char_u *)&p_sua, PV_SUA,
2657 {(char_u *)"", (char_u *)0L}
2658#else
2659 (char_u *)NULL, PV_NONE,
2660 {(char_u *)0L, (char_u *)0L}
2661#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002662 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2664 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002665 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666 {"swapsync", "sws", P_STRING|P_VI_DEF,
2667 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002668 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002669 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002672 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2673#ifdef FEAT_SYN_HL
2674 (char_u *)&p_smc, PV_SMC,
2675 {(char_u *)3000L, (char_u *)0L}
2676#else
2677 (char_u *)NULL, PV_NONE,
2678 {(char_u *)0L, (char_u *)0L}
2679#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002681 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682#ifdef FEAT_SYN_HL
2683 (char_u *)&p_syn, PV_SYN,
2684 {(char_u *)"", (char_u *)0L}
2685#else
2686 (char_u *)NULL, PV_NONE,
2687 {(char_u *)0L, (char_u *)0L}
2688#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002689 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002690 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2691#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002692 (char_u *)&p_tal, PV_NONE,
2693#else
2694 (char_u *)NULL, PV_NONE,
2695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002697 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2698#ifdef FEAT_WINDOWS
2699 (char_u *)&p_tpm, PV_NONE,
2700#else
2701 (char_u *)NULL, PV_NONE,
2702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2705 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002706 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2708 (char_u *)&p_tbs, PV_NONE,
2709#ifdef VMS /* binary searching doesn't appear to work on VMS */
2710 {(char_u *)0L, (char_u *)0L}
2711#else
2712 {(char_u *)TRUE, (char_u *)0L}
2713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002714 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002715 {"tagcase", "tc", P_STRING|P_VIM,
2716 (char_u *)&p_tc, PV_TC,
2717 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002718 {"taglength", "tl", P_NUM|P_VI_DEF,
2719 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"tagrelative", "tr", P_BOOL|P_VIM,
2722 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002724 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002725 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726 {
2727#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2728 (char_u *)"./tags,./TAGS,tags,TAGS",
2729#else
2730 (char_u *)"./tags,tags",
2731#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002732 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2734 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002735 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002736 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002737#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002738 (char_u *)&p_tcldll, PV_NONE,
2739 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002740#else
2741 (char_u *)NULL, PV_NONE,
2742 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002743#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002744 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2746 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2749#ifdef FEAT_ARABIC
2750 (char_u *)&p_tbidi, PV_NONE,
2751#else
2752 (char_u *)NULL, PV_NONE,
2753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002754 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2756#ifdef FEAT_MBYTE
2757 (char_u *)&p_tenc, PV_NONE,
2758 {(char_u *)"", (char_u *)0L}
2759#else
2760 (char_u *)NULL, PV_NONE,
2761 {(char_u *)0L, (char_u *)0L}
2762#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002763 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002764 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2765#ifdef FEAT_TERMGUICOLORS
2766 (char_u *)&p_tgc, PV_NONE,
2767 {(char_u *)FALSE, (char_u *)FALSE}
2768#else
2769 (char_u*)NULL, PV_NONE,
2770 {(char_u *)FALSE, (char_u *)FALSE}
2771#endif
2772 SCRIPTID_INIT},
Bram Moolenaar1b0675c2017-07-15 14:04:01 +02002773 {"termkey", "tk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2774#ifdef FEAT_TERMINAL
2775 (char_u *)VAR_WIN, PV_TK,
2776 {(char_u *)"\x17", (char_u *)NULL}
2777#else
2778 (char_u *)NULL, PV_NONE,
2779 {(char_u *)NULL, (char_u *)0L}
2780#endif
2781 SCRIPTID_INIT},
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002782 {"termsize", "tms", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2783#ifdef FEAT_TERMINAL
2784 (char_u *)VAR_WIN, PV_TMS,
2785 {(char_u *)"", (char_u *)NULL}
2786#else
2787 (char_u *)NULL, PV_NONE,
2788 {(char_u *)NULL, (char_u *)0L}
2789#endif
2790 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 {"terse", NULL, P_BOOL|P_VI_DEF,
2792 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002793 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794 {"textauto", "ta", P_BOOL|P_VIM,
2795 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2797 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2799 (char_u *)&p_tx, PV_TX,
2800 {
2801#ifdef USE_CRNL
2802 (char_u *)TRUE,
2803#else
2804 (char_u *)FALSE,
2805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002807 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002810 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002811#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002812 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813#else
2814 (char_u *)NULL, PV_NONE,
2815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2818 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820 {"timeout", "to", P_BOOL|P_VI_DEF,
2821 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002822 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2824 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 {"title", NULL, P_BOOL|P_VI_DEF,
2827#ifdef FEAT_TITLE
2828 (char_u *)&p_title, PV_NONE,
2829#else
2830 (char_u *)NULL, PV_NONE,
2831#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002832 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"titlelen", NULL, P_NUM|P_VI_DEF,
2834#ifdef FEAT_TITLE
2835 (char_u *)&p_titlelen, PV_NONE,
2836#else
2837 (char_u *)NULL, PV_NONE,
2838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002840 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841#ifdef FEAT_TITLE
2842 (char_u *)&p_titleold, PV_NONE,
2843 {(char_u *)N_("Thanks for flying Vim"),
2844 (char_u *)0L}
2845#else
2846 (char_u *)NULL, PV_NONE,
2847 {(char_u *)0L, (char_u *)0L}
2848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850 {"titlestring", NULL, P_STRING|P_VI_DEF,
2851#ifdef FEAT_TITLE
2852 (char_u *)&p_titlestring, PV_NONE,
2853#else
2854 (char_u *)NULL, PV_NONE,
2855#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002856 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002857 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002858#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002859 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002861#else
2862 (char_u *)NULL, PV_NONE,
2863 {(char_u *)0L, (char_u *)0L}
2864#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002865 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002867#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002869 {(char_u *)"small", (char_u *)0L}
2870#else
2871 (char_u *)NULL, PV_NONE,
2872 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002874 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002875 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2876 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002877 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2879 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002880 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2882 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002883 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2885 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002886 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2888#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2889 (char_u *)&p_ttym, PV_NONE,
2890#else
2891 (char_u *)NULL, PV_NONE,
2892#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002893 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2895 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002896 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2898 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002899 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002900 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2901 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002902#ifdef FEAT_PERSISTENT_UNDO
2903 (char_u *)&p_udir, PV_NONE,
2904 {(char_u *)".", (char_u *)0L}
2905#else
2906 (char_u *)NULL, PV_NONE,
2907 {(char_u *)0L, (char_u *)0L}
2908#endif
2909 SCRIPTID_INIT},
2910 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2911#ifdef FEAT_PERSISTENT_UNDO
2912 (char_u *)&p_udf, PV_UDF,
2913#else
2914 (char_u *)NULL, PV_NONE,
2915#endif
2916 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002918 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002920#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 (char_u *)1000L,
2922#else
2923 (char_u *)100L,
2924#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002925 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002926 {"undoreload", "ur", P_NUM|P_VI_DEF,
2927 (char_u *)&p_ur, PV_NONE,
2928 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002929 {"updatecount", "uc", P_NUM|P_VI_DEF,
2930 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002931 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 {"updatetime", "ut", P_NUM|P_VI_DEF,
2933 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002934 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935 {"verbose", "vbs", P_NUM|P_VI_DEF,
2936 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002937 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002938 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2939 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002940 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2942#ifdef FEAT_SESSION
2943 (char_u *)&p_vdir, PV_NONE,
2944 {(char_u *)DFLT_VDIR, (char_u *)0L}
2945#else
2946 (char_u *)NULL, PV_NONE,
2947 {(char_u *)0L, (char_u *)0L}
2948#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002949 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002950 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951#ifdef FEAT_SESSION
2952 (char_u *)&p_vop, PV_NONE,
2953 {(char_u *)"folds,options,cursor", (char_u *)0L}
2954#else
2955 (char_u *)NULL, PV_NONE,
2956 {(char_u *)0L, (char_u *)0L}
2957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002958 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002959 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960#ifdef FEAT_VIMINFO
2961 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002962#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002963 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964#else
2965# ifdef AMIGA
2966 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002967 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002969 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970# endif
2971#endif
2972#else
2973 (char_u *)NULL, PV_NONE,
2974 {(char_u *)0L, (char_u *)0L}
2975#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002976 SCRIPTID_INIT},
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002977 {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF,
2978#ifdef FEAT_VIMINFO
2979 (char_u *)&p_viminfofile, PV_NONE,
2980 {(char_u *)"", (char_u *)0L}
2981#else
2982 (char_u *)NULL, PV_NONE,
2983 {(char_u *)0L, (char_u *)0L}
2984#endif
2985 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002986 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2987 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988#ifdef FEAT_VIRTUALEDIT
2989 (char_u *)&p_ve, PV_NONE,
2990 {(char_u *)"", (char_u *)""}
2991#else
2992 (char_u *)NULL, PV_NONE,
2993 {(char_u *)0L, (char_u *)0L}
2994#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002995 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2997 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002998 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 {"w300", NULL, P_NUM|P_VI_DEF,
3000 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003001 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 {"w1200", NULL, P_NUM|P_VI_DEF,
3003 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003004 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005 {"w9600", NULL, P_NUM|P_VI_DEF,
3006 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003007 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 {"warn", NULL, P_BOOL|P_VI_DEF,
3009 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003010 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
3012 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003013 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003014 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003016 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 {"wildchar", "wc", P_NUM|P_VIM,
3018 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003019 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3020 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003021 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003023 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003024 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025#ifdef FEAT_WILDIGN
3026 (char_u *)&p_wig, PV_NONE,
3027#else
3028 (char_u *)NULL, PV_NONE,
3029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003030 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003031 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3032 (char_u *)&p_wic, PV_NONE,
3033 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3035#ifdef FEAT_WILDMENU
3036 (char_u *)&p_wmnu, PV_NONE,
3037#else
3038 (char_u *)NULL, PV_NONE,
3039#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003040 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003041 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003043 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003044 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3045#ifdef FEAT_CMDL_COMPL
3046 (char_u *)&p_wop, PV_NONE,
3047 {(char_u *)"", (char_u *)0L}
3048#else
3049 (char_u *)NULL, PV_NONE,
3050 {(char_u *)NULL, (char_u *)0L}
3051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003052 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3054#ifdef FEAT_WAK
3055 (char_u *)&p_wak, PV_NONE,
3056 {(char_u *)"menu", (char_u *)0L}
3057#else
3058 (char_u *)NULL, PV_NONE,
3059 {(char_u *)NULL, (char_u *)0L}
3060#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003061 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003063 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003064 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065 {"winheight", "wh", P_NUM|P_VI_DEF,
3066#ifdef FEAT_WINDOWS
3067 (char_u *)&p_wh, PV_NONE,
3068#else
3069 (char_u *)NULL, PV_NONE,
3070#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003071 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003073#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 (char_u *)VAR_WIN, PV_WFH,
3075#else
3076 (char_u *)NULL, PV_NONE,
3077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003078 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003079 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003080#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003081 (char_u *)VAR_WIN, PV_WFW,
3082#else
3083 (char_u *)NULL, PV_NONE,
3084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003085 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 {"winminheight", "wmh", P_NUM|P_VI_DEF,
3087#ifdef FEAT_WINDOWS
3088 (char_u *)&p_wmh, PV_NONE,
3089#else
3090 (char_u *)NULL, PV_NONE,
3091#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003092 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003094#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 (char_u *)&p_wmw, PV_NONE,
3096#else
3097 (char_u *)NULL, PV_NONE,
3098#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003099 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003101#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 (char_u *)&p_wiw, PV_NONE,
3103#else
3104 (char_u *)NULL, PV_NONE,
3105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003106 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3108 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003109 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3111 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003112 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3114 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003115 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116 {"write", NULL, P_BOOL|P_VI_DEF,
3117 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003118 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 {"writeany", "wa", P_BOOL|P_VI_DEF,
3120 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003121 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3123 (char_u *)&p_wb, PV_NONE,
3124 {
3125#ifdef FEAT_WRITEBACKUP
3126 (char_u *)TRUE,
3127#else
3128 (char_u *)FALSE,
3129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003130 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 {"writedelay", "wd", P_NUM|P_VI_DEF,
3132 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003133 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134
3135/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003136#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003138 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139
3140 p_term("t_AB", T_CAB)
3141 p_term("t_AF", T_CAF)
3142 p_term("t_AL", T_CAL)
3143 p_term("t_al", T_AL)
3144 p_term("t_bc", T_BC)
3145 p_term("t_cd", T_CD)
3146 p_term("t_ce", T_CE)
3147 p_term("t_cl", T_CL)
3148 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003149 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 p_term("t_Co", T_CCO)
3151 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003152 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003154#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003155 p_term("t_CV", T_CSV)
3156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_da", T_DA)
3158 p_term("t_db", T_DB)
3159 p_term("t_DL", T_CDL)
3160 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003161 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_fs", T_FS)
3163 p_term("t_IE", T_CIE)
3164 p_term("t_IS", T_CIS)
3165 p_term("t_ke", T_KE)
3166 p_term("t_ks", T_KS)
3167 p_term("t_le", T_LE)
3168 p_term("t_mb", T_MB)
3169 p_term("t_md", T_MD)
3170 p_term("t_me", T_ME)
3171 p_term("t_mr", T_MR)
3172 p_term("t_ms", T_MS)
3173 p_term("t_nd", T_ND)
3174 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003175 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176 p_term("t_RI", T_CRI)
3177 p_term("t_RV", T_CRV)
3178 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003180 p_term("t_Sf", T_CSF)
3181 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003183 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185 p_term("t_te", T_TE)
3186 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003187 p_term("t_ts", T_TS)
3188 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189 p_term("t_ue", T_UE)
3190 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003191 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192 p_term("t_vb", T_VB)
3193 p_term("t_ve", T_VE)
3194 p_term("t_vi", T_VI)
3195 p_term("t_vs", T_VS)
3196 p_term("t_WP", T_CWP)
Bram Moolenaar9f928862017-04-11 22:44:05 +02003197 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003199 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 p_term("t_xs", T_XS)
3201 p_term("t_ZH", T_CZH)
3202 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003203 p_term("t_8f", T_8F)
3204 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003205 p_term("t_BE", T_BE)
3206 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207
3208/* terminal key codes are not in here */
3209
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003210 /* end marker */
3211 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212};
3213
3214#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3215
3216#ifdef FEAT_MBYTE
3217static char *(p_ambw_values[]) = {"single", "double", NULL};
3218#endif
3219static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003220static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003222#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003223static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003224#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003225#ifdef FEAT_CMDL_COMPL
3226static char *(p_wop_values[]) = {"tagfile", NULL};
3227#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228#ifdef FEAT_WAK
3229static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3230#endif
3231static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3233static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235#ifdef FEAT_BROWSE
3236static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3237#endif
3238#ifdef FEAT_SCROLLBIND
3239static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3240#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003241static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003242#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3244#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003245#ifdef FEAT_AUTOCMD
3246static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", NULL};
3247#else
3248static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249#endif
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003250static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3252#ifdef FEAT_FOLDING
3253static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003254# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003256# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257 NULL};
3258static char *(p_fcl_values[]) = {"all", NULL};
3259#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003260#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003261static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003262#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003263#ifdef FEAT_SIGNS
3264static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3265#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003267static void set_option_default(int, int opt_flags, int compatible);
3268static void set_options_default(int opt_flags);
3269static char_u *term_bg_default(void);
3270static void did_set_option(int opt_idx, int opt_flags, int new_value);
3271static char_u *illegal_char(char_u *, int);
3272static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003274static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275#endif
3276#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003279static char_u *option_expand(int opt_idx, char_u *val);
3280static void didset_options(void);
3281static void didset_options2(void);
3282static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003283#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003284static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003285#else
3286# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3287#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003288static void set_string_option_global(int opt_idx, char_u **varp);
3289static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3290static 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);
3291static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003292#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003294#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003296static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003298#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static char_u *did_set_spell_option(int is_spellfile);
3300static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003301#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003302#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003303static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003304#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3306static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3307static void check_redraw(long_u flags);
3308static int findoption(char_u *);
3309static int find_key_option(char_u *);
3310static void showoptions(int all, int opt_flags);
3311static int optval_default(struct vimoption *, char_u *varp);
3312static void showoneopt(struct vimoption *, int opt_flags);
3313static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3314static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3315static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3316static int istermoption(struct vimoption *);
3317static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3318static char_u *get_varp(struct vimoption *);
3319static void option_value2string(struct vimoption *, int opt_flags);
3320static void check_winopt(winopt_T *wop);
3321static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003323static void langmap_init(void);
3324static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003326static void paste_option_changed(void);
3327static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003329static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003331static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3332static int check_opt_strings(char_u *val, char **values, int);
3333static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003334#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003335static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337
3338/*
3339 * Initialize the options, first part.
3340 *
3341 * Called only once from main(), just after creating the first buffer.
3342 */
3343 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003344set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345{
3346 char_u *p;
3347 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003348 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349
3350#ifdef FEAT_LANGMAP
3351 langmap_init();
3352#endif
3353
3354 /* Be Vi compatible by default */
3355 p_cp = TRUE;
3356
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003357 /* Use POSIX compatibility when $VIM_POSIX is set. */
3358 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003359 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003360 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003361 set_string_default("shm", (char_u *)"A");
3362 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003363
Bram Moolenaar071d4272004-06-13 20:20:40 +00003364 /*
3365 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003366 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003368 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003369#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003370 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003372 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373# endif
3374#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003375 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376 set_string_default("sh", p);
3377
3378#ifdef FEAT_WILDIGN
3379 /*
3380 * Set the default for 'backupskip' to include environment variables for
3381 * temp files.
3382 */
3383 {
3384# ifdef UNIX
3385 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3386# else
3387 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3388# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003389 int len;
3390 garray_T ga;
3391 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392
3393 ga_init2(&ga, 1, 100);
3394 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3395 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003396 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397# ifdef UNIX
3398 if (*names[n] == NUL)
3399 p = (char_u *)"/tmp";
3400 else
3401# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003402 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403 if (p != NULL && *p != NUL)
3404 {
3405 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003406 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407 if (ga_grow(&ga, len) == OK)
3408 {
3409 if (ga.ga_len > 0)
3410 STRCAT(ga.ga_data, ",");
3411 STRCAT(ga.ga_data, p);
3412 add_pathsep(ga.ga_data);
3413 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414 ga.ga_len += len;
3415 }
3416 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003417 if (mustfree)
3418 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419 }
3420 if (ga.ga_data != NULL)
3421 {
3422 set_string_default("bsk", ga.ga_data);
3423 vim_free(ga.ga_data);
3424 }
3425 }
3426#endif
3427
3428 /*
3429 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3430 */
3431 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003432 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003434#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3435 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3436#endif
3437 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003439 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003440 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441#else
3442# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003443 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003444 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003446 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447# endif
3448#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003450 opt_idx = findoption((char_u *)"maxmem");
3451 if (opt_idx >= 0)
3452 {
3453#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003454 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3455 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003456#endif
3457 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3458 }
3459 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003460 }
3461
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462#ifdef FEAT_SEARCHPATH
3463 {
3464 char_u *cdpath;
3465 char_u *buf;
3466 int i;
3467 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003468 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469
3470 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003471 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472 if (cdpath != NULL)
3473 {
3474 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3475 if (buf != NULL)
3476 {
3477 buf[0] = ','; /* start with ",", current dir first */
3478 j = 1;
3479 for (i = 0; cdpath[i] != NUL; ++i)
3480 {
3481 if (vim_ispathlistsep(cdpath[i]))
3482 buf[j++] = ',';
3483 else
3484 {
3485 if (cdpath[i] == ' ' || cdpath[i] == ',')
3486 buf[j++] = '\\';
3487 buf[j++] = cdpath[i];
3488 }
3489 }
3490 buf[j] = NUL;
3491 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003492 if (opt_idx >= 0)
3493 {
3494 options[opt_idx].def_val[VI_DEFAULT] = buf;
3495 options[opt_idx].flags |= P_DEF_ALLOCED;
3496 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003497 else
3498 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003499 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003500 if (mustfree)
3501 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502 }
3503 }
3504#endif
3505
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003506#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507 /* Set print encoding on platforms that don't default to latin1 */
3508 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003509# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510 (char_u *)"cp1252"
3511# else
3512# ifdef VMS
3513 (char_u *)"dec-mcs"
3514# else
3515# ifdef EBCDIC
3516 (char_u *)"ebcdic-uk"
3517# else
3518# ifdef MAC
3519 (char_u *)"mac-roman"
3520# else /* HPUX */
3521 (char_u *)"hp-roman8"
3522# endif
3523# endif
3524# endif
3525# endif
3526 );
3527#endif
3528
3529#ifdef FEAT_POSTSCRIPT
3530 /* 'printexpr' must be allocated to be able to evaluate it. */
3531 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003532# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003533 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003534# else
3535# ifdef VMS
3536 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3537
3538# else
3539 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3540# endif
3541# endif
3542 );
3543#endif
3544
3545 /*
3546 * Set all the options (except the terminal options) to their default
3547 * value. Also set the global value for local options.
3548 */
3549 set_options_default(0);
3550
3551#ifdef FEAT_GUI
3552 if (found_reverse_arg)
3553 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3554#endif
3555
3556 curbuf->b_p_initialized = TRUE;
3557 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003558 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003559 check_buf_options(curbuf);
3560 check_win_options(curwin);
3561 check_options();
3562
3563 /* Must be before option_expand(), because that one needs vim_isIDc() */
3564 didset_options();
3565
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003566#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003567 /* Use the current chartab for the generic chartab. This is not in
3568 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003569 init_spell_chartab();
3570#endif
3571
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572 /*
3573 * Expand environment variables and things like "~" for the defaults.
3574 * If option_expand() returns non-NULL the variable is expanded. This can
3575 * only happen for non-indirect options.
3576 * Also set the default to the expanded value, so ":set" does not list
3577 * them.
3578 * Don't set the P_ALLOCED flag, because we don't want to free the
3579 * default.
3580 */
3581 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3582 {
3583 if ((options[opt_idx].flags & P_GETTEXT)
3584 && options[opt_idx].var != NULL)
3585 p = (char_u *)_(*(char **)options[opt_idx].var);
3586 else
3587 p = option_expand(opt_idx, NULL);
3588 if (p != NULL && (p = vim_strsave(p)) != NULL)
3589 {
3590 *(char_u **)options[opt_idx].var = p;
3591 /* VIMEXP
3592 * Defaults for all expanded options are currently the same for Vi
3593 * and Vim. When this changes, add some code here! Also need to
3594 * split P_DEF_ALLOCED in two.
3595 */
3596 if (options[opt_idx].flags & P_DEF_ALLOCED)
3597 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3598 options[opt_idx].def_val[VI_DEFAULT] = p;
3599 options[opt_idx].flags |= P_DEF_ALLOCED;
3600 }
3601 }
3602
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603 save_file_ff(curbuf); /* Buffer is unchanged */
3604
Bram Moolenaar071d4272004-06-13 20:20:40 +00003605#if defined(FEAT_ARABIC)
3606 /* Detect use of mlterm.
3607 * Mlterm is a terminal emulator akin to xterm that has some special
3608 * abilities (bidi namely).
3609 * NOTE: mlterm's author is being asked to 'set' a variable
3610 * instead of an environment variable due to inheritance.
3611 */
3612 if (mch_getenv((char_u *)"MLTERM") != NULL)
3613 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3614#endif
3615
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003616 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003617
3618#ifdef FEAT_MBYTE
3619# if defined(WIN3264) && defined(FEAT_GETTEXT)
3620 /*
3621 * If $LANG isn't set, try to get a good value for it. This makes the
3622 * right language be used automatically. Don't do this for English.
3623 */
3624 if (mch_getenv((char_u *)"LANG") == NULL)
3625 {
3626 char buf[20];
3627
3628 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3629 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3630 * only the first two. */
3631 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3632 (LPTSTR)buf, 20);
3633 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3634 {
3635 /* There are a few exceptions (probably more) */
3636 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3637 STRCPY(buf, "zh_TW");
3638 else if (STRNICMP(buf, "chs", 3) == 0
3639 || STRNICMP(buf, "zhc", 3) == 0)
3640 STRCPY(buf, "zh_CN");
3641 else if (STRNICMP(buf, "jp", 2) == 0)
3642 STRCPY(buf, "ja");
3643 else
3644 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003645 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 }
3647 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003648# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003649# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003650 /* Moved to os_mac_conv.c to avoid dependency problems. */
3651 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003652# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653# endif
3654
3655 /* enc_locale() will try to find the encoding of the current locale. */
3656 p = enc_locale();
3657 if (p != NULL)
3658 {
3659 char_u *save_enc;
3660
3661 /* Try setting 'encoding' and check if the value is valid.
3662 * If not, go back to the default "latin1". */
3663 save_enc = p_enc;
3664 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003665 if (STRCMP(p_enc, "gb18030") == 0)
3666 {
3667 /* We don't support "gb18030", but "cp936" is a good substitute
3668 * for practical purposes, thus use that. It's not an alias to
3669 * still support conversion between gb18030 and utf-8. */
3670 p_enc = vim_strsave((char_u *)"cp936");
3671 vim_free(p);
3672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003673 if (mb_init() == NULL)
3674 {
3675 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003676 if (opt_idx >= 0)
3677 {
3678 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3679 options[opt_idx].flags |= P_DEF_ALLOCED;
3680 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003682#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003683 if (STRCMP(p_enc, "latin1") == 0
3684# ifdef FEAT_MBYTE
3685 || enc_utf8
3686# endif
3687 )
3688 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003689 /* Adjust the default for 'isprint' and 'iskeyword' to match
3690 * latin1. Also set the defaults for when 'nocompatible' is
3691 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003692 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003693 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003694 set_string_option_direct((char_u *)"isk", -1,
3695 ISK_LATIN1, OPT_FREE, SID_NONE);
3696 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003697 if (opt_idx >= 0)
3698 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003699 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003700 if (opt_idx >= 0)
3701 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003702 (void)init_chartab();
3703 }
3704#endif
3705
Bram Moolenaar071d4272004-06-13 20:20:40 +00003706# if defined(WIN3264) && !defined(FEAT_GUI)
3707 /* Win32 console: When GetACP() returns a different value from
3708 * GetConsoleCP() set 'termencoding'. */
3709 if (GetACP() != GetConsoleCP())
3710 {
3711 char buf[50];
3712
3713 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3714 p_tenc = vim_strsave((char_u *)buf);
3715 if (p_tenc != NULL)
3716 {
3717 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003718 if (opt_idx >= 0)
3719 {
3720 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3721 options[opt_idx].flags |= P_DEF_ALLOCED;
3722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723 convert_setup(&input_conv, p_tenc, p_enc);
3724 convert_setup(&output_conv, p_enc, p_tenc);
3725 }
3726 else
3727 p_tenc = empty_option;
3728 }
3729# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003730# if defined(WIN3264) && defined(FEAT_MBYTE)
3731 /* $HOME may have characters in active code page. */
3732 init_homedir();
3733# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734 }
3735 else
3736 {
3737 vim_free(p_enc);
3738 p_enc = save_enc;
3739 }
3740 }
3741#endif
3742
3743#ifdef FEAT_MULTI_LANG
3744 /* Set the default for 'helplang'. */
3745 set_helplang_default(get_mess_lang());
3746#endif
3747}
3748
3749/*
3750 * Set an option to its default value.
3751 * This does not take care of side effects!
3752 */
3753 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003754set_option_default(
3755 int opt_idx,
3756 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3757 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758{
3759 char_u *varp; /* pointer to variable for current option */
3760 int dvi; /* index in def_val[] */
3761 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003762 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3764
3765 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3766 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003767 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768 {
3769 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3770 if (flags & P_STRING)
3771 {
3772 /* Use set_string_option_direct() for local options to handle
3773 * freeing and allocating the value. */
3774 if (options[opt_idx].indir != PV_NONE)
3775 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003776 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 else
3778 {
3779 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3780 free_string_option(*(char_u **)(varp));
3781 *(char_u **)varp = options[opt_idx].def_val[dvi];
3782 options[opt_idx].flags &= ~P_ALLOCED;
3783 }
3784 }
3785 else if (flags & P_NUM)
3786 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003787 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 win_comp_scroll(curwin);
3789 else
3790 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003791 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792 /* May also set global value for local option. */
3793 if (both)
3794 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3795 *(long *)varp;
3796 }
3797 }
3798 else /* P_BOOL */
3799 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003800 /* the cast to long is required for Manx C, long_i is needed for
3801 * MSVC */
3802 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003803#ifdef UNIX
3804 /* 'modeline' defaults to off for root */
3805 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3806 *(int *)varp = FALSE;
3807#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 /* May also set global value for local option. */
3809 if (both)
3810 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3811 *(int *)varp;
3812 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003813
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003814 /* The default value is not insecure. */
3815 flagsp = insecure_flag(opt_idx, opt_flags);
3816 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817 }
3818
3819#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003820 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821#endif
3822}
3823
3824/*
3825 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003826 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003827 */
3828 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003829set_options_default(
3830 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831{
3832 int i;
3833#ifdef FEAT_WINDOWS
3834 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003835 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003836#endif
3837
3838 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003839 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003840#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003841 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003842 || (TRUE
3843# if defined(FEAT_MBYTE)
3844 && options[i].var != (char_u *)&p_enc
3845# endif
3846# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003847 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003848 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003849# endif
3850 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003851#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003852 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853 set_option_default(i, opt_flags, p_cp);
3854
3855#ifdef FEAT_WINDOWS
3856 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003857 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 win_comp_scroll(wp);
3859#else
3860 win_comp_scroll(curwin);
3861#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003862#ifdef FEAT_CINDENT
3863 parse_cino(curbuf);
3864#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003865}
3866
3867/*
3868 * Set the Vi-default value of a string option.
3869 * Used for 'sh', 'backupskip' and 'term'.
3870 */
3871 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003872set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873{
3874 char_u *p;
3875 int opt_idx;
3876
3877 p = vim_strsave(val);
3878 if (p != NULL) /* we don't want a NULL */
3879 {
3880 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003881 if (opt_idx >= 0)
3882 {
3883 if (options[opt_idx].flags & P_DEF_ALLOCED)
3884 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3885 options[opt_idx].def_val[VI_DEFAULT] = p;
3886 options[opt_idx].flags |= P_DEF_ALLOCED;
3887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 }
3889}
3890
3891/*
3892 * Set the Vi-default value of a number option.
3893 * Used for 'lines' and 'columns'.
3894 */
3895 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003896set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003898 int opt_idx;
3899
3900 opt_idx = findoption((char_u *)name);
3901 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003902 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903}
3904
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003905#if defined(EXITFREE) || defined(PROTO)
3906/*
3907 * Free all options.
3908 */
3909 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003910free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003911{
3912 int i;
3913
3914 for (i = 0; !istermoption(&options[i]); i++)
3915 {
3916 if (options[i].indir == PV_NONE)
3917 {
3918 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003919 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003920 free_string_option(*(char_u **)options[i].var);
3921 if (options[i].flags & P_DEF_ALLOCED)
3922 free_string_option(options[i].def_val[VI_DEFAULT]);
3923 }
3924 else if (options[i].var != VAR_WIN
3925 && (options[i].flags & P_STRING))
3926 /* buffer-local option: free global value */
3927 free_string_option(*(char_u **)options[i].var);
3928 }
3929}
3930#endif
3931
3932
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933/*
3934 * Initialize the options, part two: After getting Rows and Columns and
3935 * setting 'term'.
3936 */
3937 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003938set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003940 int idx;
3941
Bram Moolenaar071d4272004-06-13 20:20:40 +00003942 /*
3943 * 'scroll' defaults to half the window height. Note that this default is
3944 * wrong when the window height changes.
3945 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003946 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003947 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003948 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003949 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950 comp_col();
3951
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003952 /*
3953 * 'window' is only for backwards compatibility with Vi.
3954 * Default is Rows - 1.
3955 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003956 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003957 p_window = Rows - 1;
3958 set_number_default("window", Rows - 1);
3959
Bram Moolenaarf740b292006-02-16 22:11:02 +00003960 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003961#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003962 /*
3963 * If 'background' wasn't set by the user, try guessing the value,
3964 * depending on the terminal name. Only need to check for terminals
3965 * with a dark background, that can handle color.
3966 */
3967 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003968 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3969 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003971 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003972 /* don't mark it as set, when starting the GUI it may be
3973 * changed again */
3974 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 }
3976#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003977
3978#ifdef CURSOR_SHAPE
3979 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3980#endif
3981#ifdef FEAT_MOUSESHAPE
3982 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3983#endif
3984#ifdef FEAT_PRINTER
3985 (void)parse_printoptions(); /* parse 'printoptions' default value */
3986#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987}
3988
3989/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003990 * Return "dark" or "light" depending on the kind of terminal.
3991 * This is just guessing! Recognized are:
3992 * "linux" Linux console
3993 * "screen.linux" Linux console with screen
3994 * "cygwin" Cygwin shell
3995 * "putty" Putty program
3996 * We also check the COLORFGBG environment variable, which is set by
3997 * rxvt and derivatives. This variable contains either two or three
3998 * values separated by semicolons; we want the last value in either
3999 * case. If this value is 0-6 or 8, our background is dark.
4000 */
4001 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004002term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004003{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004004#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004005 /* DOS console nearly always black */
4006 return (char_u *)"dark";
4007#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004008 char_u *p;
4009
Bram Moolenaarf740b292006-02-16 22:11:02 +00004010 if (STRCMP(T_NAME, "linux") == 0
4011 || STRCMP(T_NAME, "screen.linux") == 0
4012 || STRCMP(T_NAME, "cygwin") == 0
4013 || STRCMP(T_NAME, "putty") == 0
4014 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4015 && (p = vim_strrchr(p, ';')) != NULL
4016 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4017 && p[2] == NUL))
4018 return (char_u *)"dark";
4019 return (char_u *)"light";
4020#endif
4021}
4022
4023/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004024 * Initialize the options, part three: After reading the .vimrc
4025 */
4026 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004027set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004029#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030/*
4031 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4032 * This is done after other initializations, where 'shell' might have been
4033 * set, but only if they have not been set before.
4034 */
4035 char_u *p;
4036 int idx_srr;
4037 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004038# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039 int idx_sp;
4040 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004041# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004042
4043 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004044 if (idx_srr < 0)
4045 do_srr = FALSE;
4046 else
4047 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004048# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004049 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004050 if (idx_sp < 0)
4051 do_sp = FALSE;
4052 else
4053 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004054# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004055 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 if (p != NULL)
4057 {
4058 /*
4059 * Default for p_sp is "| tee", for p_srr is ">".
4060 * For known shells it is changed here to include stderr.
4061 */
4062 if ( fnamecmp(p, "csh") == 0
4063 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004064# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065 || fnamecmp(p, "csh.exe") == 0
4066 || fnamecmp(p, "tcsh.exe") == 0
4067# endif
4068 )
4069 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004070# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071 if (do_sp)
4072 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004073# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004075# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004077# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4079 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004080# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 if (do_srr)
4082 {
4083 p_srr = (char_u *)">&";
4084 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4085 }
4086 }
4087 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004088 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 if ( fnamecmp(p, "sh") == 0
4090 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004091 || fnamecmp(p, "mksh") == 0
4092 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004094 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004096 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004097# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 || fnamecmp(p, "cmd") == 0
4099 || fnamecmp(p, "sh.exe") == 0
4100 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004101 || fnamecmp(p, "mksh.exe") == 0
4102 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004104 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 || fnamecmp(p, "bash.exe") == 0
4106 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004108 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004110# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 if (do_sp)
4112 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004113# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004115# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004117# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4119 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004120# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 if (do_srr)
4122 {
4123 p_srr = (char_u *)">%s 2>&1";
4124 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4125 }
4126 }
4127 vim_free(p);
4128 }
4129#endif
4130
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004131#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004133 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4134 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 * This is done after other initializations, where 'shell' might have been
4136 * set, but only if they have not been set before. Default for p_shcf is
4137 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004138 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004140 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 {
4142 int idx3;
4143
4144 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004145 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 {
4147 p_shcf = (char_u *)"-c";
4148 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4149 }
4150
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 /* Somehow Win32 requires the quotes around the redirection too */
4152 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004153 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004154 {
4155 p_sxq = (char_u *)"\"";
4156 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4157 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004158 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004159 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4160 {
4161 int idx3;
4162
4163 /*
4164 * cmd.exe on Windows will strip the first and last double quote given
4165 * on the command line, e.g. most of the time things like:
4166 * cmd /c "my path/to/echo" "my args to echo"
4167 * become:
4168 * my path/to/echo" "my args to echo
4169 * when executed.
4170 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004171 * To avoid this, set shellxquote to surround the command in
4172 * parenthesis. This appears to make most commands work, without
4173 * breaking commands that worked previously, such as
4174 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004175 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004176 idx3 = findoption((char_u *)"sxq");
4177 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4178 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004179 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004180 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4181 }
4182
Bram Moolenaara64ba222012-02-12 23:23:31 +01004183 idx3 = findoption((char_u *)"shcf");
4184 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4185 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004186 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004187 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4188 }
4189 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190#endif
4191
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004192 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004193 {
4194 int idx_ffs = findoption((char_u *)"ffs");
4195
4196 /* Apply the first entry of 'fileformats' to the initial buffer. */
4197 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4198 set_fileformat(default_fileformat(), OPT_LOCAL);
4199 }
4200
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201#ifdef FEAT_TITLE
4202 set_title_defaults();
4203#endif
4204}
4205
4206#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4207/*
4208 * When 'helplang' is still at its default value, set it to "lang".
4209 * Only the first two characters of "lang" are used.
4210 */
4211 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004212set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004213{
4214 int idx;
4215
4216 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4217 return;
4218 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004219 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004220 {
4221 if (options[idx].flags & P_ALLOCED)
4222 free_string_option(p_hlg);
4223 p_hlg = vim_strsave(lang);
4224 if (p_hlg == NULL)
4225 p_hlg = empty_option;
4226 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004227 {
4228 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4229 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4230 {
4231 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4232 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4233 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236 options[idx].flags |= P_ALLOCED;
4237 }
4238}
4239#endif
4240
4241#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004242static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004243
4244 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004245gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246{
4247 if (gui_get_lightness(gui.back_pixel) < 127)
4248 return (char_u *)"dark";
4249 return (char_u *)"light";
4250}
4251
4252/*
4253 * Option initializations that can only be done after opening the GUI window.
4254 */
4255 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004256init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004257{
4258 /* Set the 'background' option according to the lightness of the
4259 * background color, unless the user has set it already. */
4260 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4261 {
4262 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4263 highlight_changed();
4264 }
4265}
4266#endif
4267
4268#ifdef FEAT_TITLE
4269/*
4270 * 'title' and 'icon' only default to true if they have not been set or reset
4271 * in .vimrc and we can read the old value.
4272 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4273 * they can be reset. This reduces startup time when using X on a remote
4274 * machine.
4275 */
4276 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004277set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004278{
4279 int idx1;
4280 long val;
4281
4282 /*
4283 * If GUI is (going to be) used, we can always set the window title and
4284 * icon name. Saves a bit of time, because the X11 display server does
4285 * not need to be contacted.
4286 */
4287 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004288 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004289 {
4290#ifdef FEAT_GUI
4291 if (gui.starting || gui.in_use)
4292 val = TRUE;
4293 else
4294#endif
4295 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004296 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004297 p_title = val;
4298 }
4299 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004300 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004301 {
4302#ifdef FEAT_GUI
4303 if (gui.starting || gui.in_use)
4304 val = TRUE;
4305 else
4306#endif
4307 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004308 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004309 p_icon = val;
4310 }
4311}
4312#endif
4313
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004314#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4315 static void
4316trigger_optionsset_string(
4317 int opt_idx,
4318 int opt_flags,
4319 char_u *oldval,
4320 char_u *newval)
4321{
4322 if (oldval != NULL && newval != NULL)
4323 {
4324 char_u buf_type[7];
4325
4326 sprintf((char *)buf_type, "%s",
4327 (opt_flags & OPT_LOCAL) ? "local" : "global");
4328 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4329 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4330 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4331 apply_autocmds(EVENT_OPTIONSET,
4332 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4333 reset_v_option_vars();
4334 }
4335 vim_free(oldval);
4336 vim_free(newval);
4337}
4338#endif
4339
Bram Moolenaar071d4272004-06-13 20:20:40 +00004340/*
4341 * Parse 'arg' for option settings.
4342 *
4343 * 'arg' may be IObuff, but only when no errors can be present and option
4344 * does not need to be expanded with option_expand().
4345 * "opt_flags":
4346 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004347 * OPT_GLOBAL for ":setglobal"
4348 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004350 * OPT_WINONLY to only set window-local options
4351 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004352 *
4353 * returns FAIL if an error is detected, OK otherwise
4354 */
4355 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004356do_set(
4357 char_u *arg, /* option string (may be written to!) */
4358 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004359{
4360 int opt_idx;
4361 char_u *errmsg;
4362 char_u errbuf[80];
4363 char_u *startarg;
4364 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4365 int nextchar; /* next non-white char after option name */
4366 int afterchar; /* character just after option name */
4367 int len;
4368 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004369 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004370 int key;
4371 long_u flags; /* flags for current option */
4372 char_u *varp = NULL; /* pointer to variable for current option */
4373 int did_show = FALSE; /* already showed one value */
4374 int adding; /* "opt+=arg" */
4375 int prepending; /* "opt^=arg" */
4376 int removing; /* "opt-=arg" */
4377 int cp_val = 0;
4378 char_u key_name[2];
4379
4380 if (*arg == NUL)
4381 {
4382 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004383 did_show = TRUE;
4384 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 }
4386
4387 while (*arg != NUL) /* loop to process all options */
4388 {
4389 errmsg = NULL;
4390 startarg = arg; /* remember for error message */
4391
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004392 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4393 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004394 {
4395 /*
4396 * ":set all" show all options.
4397 * ":set all&" set all options to their default value.
4398 */
4399 arg += 3;
4400 if (*arg == '&')
4401 {
4402 ++arg;
4403 /* Only for :set command set global value of local options. */
4404 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004405 didset_options();
4406 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004407 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 }
4409 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004410 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004411 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004412 did_show = TRUE;
4413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004414 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004415 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004416 {
4417 showoptions(2, opt_flags);
4418 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004419 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 arg += 7;
4421 }
4422 else
4423 {
4424 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004425 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004426 {
4427 prefix = 0;
4428 arg += 2;
4429 }
4430 else if (STRNCMP(arg, "inv", 3) == 0)
4431 {
4432 prefix = 2;
4433 arg += 3;
4434 }
4435
4436 /* find end of name */
4437 key = 0;
4438 if (*arg == '<')
4439 {
4440 nextchar = 0;
4441 opt_idx = -1;
4442 /* look out for <t_>;> */
4443 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4444 len = 5;
4445 else
4446 {
4447 len = 1;
4448 while (arg[len] != NUL && arg[len] != '>')
4449 ++len;
4450 }
4451 if (arg[len] != '>')
4452 {
4453 errmsg = e_invarg;
4454 goto skip;
4455 }
4456 arg[len] = NUL; /* put NUL after name */
4457 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4458 opt_idx = findoption(arg + 1);
4459 arg[len++] = '>'; /* restore '>' */
4460 if (opt_idx == -1)
4461 key = find_key_option(arg + 1);
4462 }
4463 else
4464 {
4465 len = 0;
4466 /*
4467 * The two characters after "t_" may not be alphanumeric.
4468 */
4469 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4470 len = 4;
4471 else
4472 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4473 ++len;
4474 nextchar = arg[len];
4475 arg[len] = NUL; /* put NUL after name */
4476 opt_idx = findoption(arg);
4477 arg[len] = nextchar; /* restore nextchar */
4478 if (opt_idx == -1)
4479 key = find_key_option(arg);
4480 }
4481
4482 /* remember character after option name */
4483 afterchar = arg[len];
4484
4485 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004486 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004487 ++len;
4488
4489 adding = FALSE;
4490 prepending = FALSE;
4491 removing = FALSE;
4492 if (arg[len] != NUL && arg[len + 1] == '=')
4493 {
4494 if (arg[len] == '+')
4495 {
4496 adding = TRUE; /* "+=" */
4497 ++len;
4498 }
4499 else if (arg[len] == '^')
4500 {
4501 prepending = TRUE; /* "^=" */
4502 ++len;
4503 }
4504 else if (arg[len] == '-')
4505 {
4506 removing = TRUE; /* "-=" */
4507 ++len;
4508 }
4509 }
4510 nextchar = arg[len];
4511
4512 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4513 {
4514 errmsg = (char_u *)N_("E518: Unknown option");
4515 goto skip;
4516 }
4517
4518 if (opt_idx >= 0)
4519 {
4520 if (options[opt_idx].var == NULL) /* hidden option: skip */
4521 {
4522 /* Only give an error message when requesting the value of
4523 * a hidden option, ignore setting it. */
4524 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4525 && (!(options[opt_idx].flags & P_BOOL)
4526 || nextchar == '?'))
4527 errmsg = (char_u *)N_("E519: Option not supported");
4528 goto skip;
4529 }
4530
4531 flags = options[opt_idx].flags;
4532 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4533 }
4534 else
4535 {
4536 flags = P_STRING;
4537 if (key < 0)
4538 {
4539 key_name[0] = KEY2TERMCAP0(key);
4540 key_name[1] = KEY2TERMCAP1(key);
4541 }
4542 else
4543 {
4544 key_name[0] = KS_KEY;
4545 key_name[1] = (key & 0xff);
4546 }
4547 }
4548
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004549 /* Skip all options that are not window-local (used when showing
4550 * an already loaded buffer in a window). */
4551 if ((opt_flags & OPT_WINONLY)
4552 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4553 goto skip;
4554
Bram Moolenaara3227e22006-03-08 21:32:40 +00004555 /* Skip all options that are window-local (used for :vimgrep). */
4556 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4557 && options[opt_idx].var == VAR_WIN)
4558 goto skip;
4559
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004560 /* Disallow changing some options from modelines. */
4561 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004563 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004564 {
4565 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4566 goto skip;
4567 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004568#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004569 /* In diff mode some options are overruled. This avoids that
4570 * 'foldmethod' becomes "marker" instead of "diff" and that
4571 * "wrap" gets set. */
4572 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004573 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004574 && (
4575#ifdef FEAT_FOLDING
4576 options[opt_idx].indir == PV_FDM ||
4577#endif
4578 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004579 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004580#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 }
4582
4583#ifdef HAVE_SANDBOX
4584 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004585 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004586 {
4587 errmsg = (char_u *)_(e_sandbox);
4588 goto skip;
4589 }
4590#endif
4591
4592 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4593 {
4594 arg += len;
4595 cp_val = p_cp;
4596 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4597 {
4598 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4599 {
4600 cp_val = FALSE;
4601 arg += 3;
4602 }
4603 else /* "opt&vi": set to Vi default */
4604 {
4605 cp_val = TRUE;
4606 arg += 2;
4607 }
4608 }
4609 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004610 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004611 {
4612 errmsg = e_trailing;
4613 goto skip;
4614 }
4615 }
4616
4617 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004618 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4619 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004620 */
4621 if (nextchar == '?'
4622 || (prefix == 1
4623 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4624 && !(flags & P_BOOL)))
4625 {
4626 /*
4627 * print value
4628 */
4629 if (did_show)
4630 msg_putchar('\n'); /* cursor below last one */
4631 else
4632 {
4633 gotocmdline(TRUE); /* cursor at status line */
4634 did_show = TRUE; /* remember that we did a line */
4635 }
4636 if (opt_idx >= 0)
4637 {
4638 showoneopt(&options[opt_idx], opt_flags);
4639#ifdef FEAT_EVAL
4640 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004641 {
4642 /* Mention where the option was last set. */
4643 if (varp == options[opt_idx].var)
4644 last_set_msg(options[opt_idx].scriptID);
4645 else if ((int)options[opt_idx].indir & PV_WIN)
4646 last_set_msg(curwin->w_p_scriptID[
4647 (int)options[opt_idx].indir & PV_MASK]);
4648 else if ((int)options[opt_idx].indir & PV_BUF)
4649 last_set_msg(curbuf->b_p_scriptID[
4650 (int)options[opt_idx].indir & PV_MASK]);
4651 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652#endif
4653 }
4654 else
4655 {
4656 char_u *p;
4657
4658 p = find_termcode(key_name);
4659 if (p == NULL)
4660 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004661 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004662 goto skip;
4663 }
4664 else
4665 (void)show_one_termcode(key_name, p, TRUE);
4666 }
4667 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004668 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004669 errmsg = e_trailing;
4670 }
4671 else
4672 {
4673 if (flags & P_BOOL) /* boolean */
4674 {
4675 if (nextchar == '=' || nextchar == ':')
4676 {
4677 errmsg = e_invarg;
4678 goto skip;
4679 }
4680
4681 /*
4682 * ":set opt!": invert
4683 * ":set opt&": reset to default value
4684 * ":set opt<": reset to global value
4685 */
4686 if (nextchar == '!')
4687 value = *(int *)(varp) ^ 1;
4688 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004689 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004690 ((flags & P_VI_DEF) || cp_val)
4691 ? VI_DEFAULT : VIM_DEFAULT];
4692 else if (nextchar == '<')
4693 {
4694 /* For 'autoread' -1 means to use global value. */
4695 if ((int *)varp == &curbuf->b_p_ar
4696 && opt_flags == OPT_LOCAL)
4697 value = -1;
4698 else
4699 value = *(int *)get_varp_scope(&(options[opt_idx]),
4700 OPT_GLOBAL);
4701 }
4702 else
4703 {
4704 /*
4705 * ":set invopt": invert
4706 * ":set opt" or ":set noopt": set or reset
4707 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004708 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004709 {
4710 errmsg = e_trailing;
4711 goto skip;
4712 }
4713 if (prefix == 2) /* inv */
4714 value = *(int *)(varp) ^ 1;
4715 else
4716 value = prefix;
4717 }
4718
4719 errmsg = set_bool_option(opt_idx, varp, (int)value,
4720 opt_flags);
4721 }
4722 else /* numeric or string */
4723 {
4724 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4725 || prefix != 1)
4726 {
4727 errmsg = e_invarg;
4728 goto skip;
4729 }
4730
4731 if (flags & P_NUM) /* numeric */
4732 {
4733 /*
4734 * Different ways to set a number option:
4735 * & set to default value
4736 * < set to global value
4737 * <xx> accept special key codes for 'wildchar'
4738 * c accept any non-digit for 'wildchar'
4739 * [-]0-9 set number
4740 * other error
4741 */
4742 ++arg;
4743 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004744 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004745 ((flags & P_VI_DEF) || cp_val)
4746 ? VI_DEFAULT : VIM_DEFAULT];
4747 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004748 {
4749 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4750 * use the global value. */
4751 if ((long *)varp == &curbuf->b_p_ul
4752 && opt_flags == OPT_LOCAL)
4753 value = NO_LOCAL_UNDOLEVEL;
4754 else
4755 value = *(long *)get_varp_scope(
4756 &(options[opt_idx]), OPT_GLOBAL);
4757 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004758 else if (((long *)varp == &p_wc
4759 || (long *)varp == &p_wcm)
4760 && (*arg == '<'
4761 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004762 || (*arg != NUL
4763 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004764 && !VIM_ISDIGIT(*arg))))
4765 {
4766 value = string_to_key(arg);
4767 if (value == 0 && (long *)varp != &p_wcm)
4768 {
4769 errmsg = e_invarg;
4770 goto skip;
4771 }
4772 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004773 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4774 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004775 /* Allow negative (for 'undolevels'), octal and
4776 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004777 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4778 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004779 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004780 {
4781 errmsg = e_invarg;
4782 goto skip;
4783 }
4784 }
4785 else
4786 {
4787 errmsg = (char_u *)N_("E521: Number required after =");
4788 goto skip;
4789 }
4790
4791 if (adding)
4792 value = *(long *)varp + value;
4793 if (prepending)
4794 value = *(long *)varp * value;
4795 if (removing)
4796 value = *(long *)varp - value;
4797 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004798 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004799 }
4800 else if (opt_idx >= 0) /* string */
4801 {
4802 char_u *save_arg = NULL;
4803 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004804 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004805 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004806 char_u *origval = NULL;
4807#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4808 char_u *saved_origval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004809 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004810#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004811 unsigned newlen;
4812 int comma;
4813 int bs;
4814 int new_value_alloced; /* new string option
4815 was allocated */
4816
4817 /* When using ":set opt=val" for a global option
4818 * with a local value the local value will be
4819 * reset, use the global value here. */
4820 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004821 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004822 varp = options[opt_idx].var;
4823
4824 /* The old value is kept until we are sure that the
4825 * new value is valid. */
4826 oldval = *(char_u **)varp;
4827 if (nextchar == '&') /* set to default val */
4828 {
4829 newval = options[opt_idx].def_val[
4830 ((flags & P_VI_DEF) || cp_val)
4831 ? VI_DEFAULT : VIM_DEFAULT];
4832 if ((char_u **)varp == &p_bg)
4833 {
4834 /* guess the value of 'background' */
4835#ifdef FEAT_GUI
4836 if (gui.in_use)
4837 newval = gui_bg_default();
4838 else
4839#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004840 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004841 }
4842
4843 /* expand environment variables and ~ (since the
4844 * default value was already expanded, only
4845 * required when an environment variable was set
4846 * later */
4847 if (newval == NULL)
4848 newval = empty_option;
4849 else
4850 {
4851 s = option_expand(opt_idx, newval);
4852 if (s == NULL)
4853 s = newval;
4854 newval = vim_strsave(s);
4855 }
4856 new_value_alloced = TRUE;
4857 }
4858 else if (nextchar == '<') /* set to global val */
4859 {
4860 newval = vim_strsave(*(char_u **)get_varp_scope(
4861 &(options[opt_idx]), OPT_GLOBAL));
4862 new_value_alloced = TRUE;
4863 }
4864 else
4865 {
4866 ++arg; /* jump to after the '=' or ':' */
4867
4868 /*
4869 * Set 'keywordprg' to ":help" if an empty
4870 * value was passed to :set by the user.
4871 * Misuse errbuf[] for the resulting string.
4872 */
4873 if (varp == (char_u *)&p_kp
4874 && (*arg == NUL || *arg == ' '))
4875 {
4876 STRCPY(errbuf, ":help");
4877 save_arg = arg;
4878 arg = errbuf;
4879 }
4880 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004881 * Convert 'backspace' number to string, for
4882 * adding, prepending and removing string.
4883 */
4884 else if (varp == (char_u *)&p_bs
4885 && VIM_ISDIGIT(**(char_u **)varp))
4886 {
4887 i = getdigits((char_u **)varp);
4888 switch (i)
4889 {
4890 case 0:
4891 *(char_u **)varp = empty_option;
4892 break;
4893 case 1:
4894 *(char_u **)varp = vim_strsave(
4895 (char_u *)"indent,eol");
4896 break;
4897 case 2:
4898 *(char_u **)varp = vim_strsave(
4899 (char_u *)"indent,eol,start");
4900 break;
4901 }
4902 vim_free(oldval);
4903 oldval = *(char_u **)varp;
4904 }
4905 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004906 * Convert 'whichwrap' number to string, for
4907 * backwards compatibility with Vim 3.0.
4908 * Misuse errbuf[] for the resulting string.
4909 */
4910 else if (varp == (char_u *)&p_ww
4911 && VIM_ISDIGIT(*arg))
4912 {
4913 *errbuf = NUL;
4914 i = getdigits(&arg);
4915 if (i & 1)
4916 STRCAT(errbuf, "b,");
4917 if (i & 2)
4918 STRCAT(errbuf, "s,");
4919 if (i & 4)
4920 STRCAT(errbuf, "h,l,");
4921 if (i & 8)
4922 STRCAT(errbuf, "<,>,");
4923 if (i & 16)
4924 STRCAT(errbuf, "[,],");
4925 if (*errbuf != NUL) /* remove trailing , */
4926 errbuf[STRLEN(errbuf) - 1] = NUL;
4927 save_arg = arg;
4928 arg = errbuf;
4929 }
4930 /*
4931 * Remove '>' before 'dir' and 'bdir', for
4932 * backwards compatibility with version 3.0
4933 */
4934 else if ( *arg == '>'
4935 && (varp == (char_u *)&p_dir
4936 || varp == (char_u *)&p_bdir))
4937 {
4938 ++arg;
4939 }
4940
4941 /* When setting the local value of a global
4942 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004943 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004944 && (opt_flags & OPT_LOCAL))
4945 origval = *(char_u **)get_varp(
4946 &options[opt_idx]);
4947 else
4948 origval = oldval;
4949
4950 /*
4951 * Copy the new string into allocated memory.
4952 * Can't use set_string_option_direct(), because
4953 * we need to remove the backslashes.
4954 */
4955 /* get a bit too much */
4956 newlen = (unsigned)STRLEN(arg) + 1;
4957 if (adding || prepending || removing)
4958 newlen += (unsigned)STRLEN(origval) + 1;
4959 newval = alloc(newlen);
4960 if (newval == NULL) /* out of mem, don't change */
4961 break;
4962 s = newval;
4963
4964 /*
4965 * Copy the string, skip over escaped chars.
4966 * For MS-DOS and WIN32 backslashes before normal
4967 * file name characters are not removed, and keep
4968 * backslash at start, for "\\machine\path", but
4969 * do remove it for "\\\\machine\\path".
4970 * The reverse is found in ExpandOldSetting().
4971 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004972 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004973 {
4974 if (*arg == '\\' && arg[1] != NUL
4975#ifdef BACKSLASH_IN_FILENAME
4976 && !((flags & P_EXPAND)
4977 && vim_isfilec(arg[1])
4978 && (arg[1] != '\\'
4979 || (s == newval
4980 && arg[2] != '\\')))
4981#endif
4982 )
4983 ++arg; /* remove backslash */
4984#ifdef FEAT_MBYTE
4985 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004986 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004987 {
4988 /* copy multibyte char */
4989 mch_memmove(s, arg, (size_t)i);
4990 arg += i;
4991 s += i;
4992 }
4993 else
4994#endif
4995 *s++ = *arg++;
4996 }
4997 *s = NUL;
4998
4999 /*
5000 * Expand environment variables and ~.
5001 * Don't do it when adding without inserting a
5002 * comma.
5003 */
5004 if (!(adding || prepending || removing)
5005 || (flags & P_COMMA))
5006 {
5007 s = option_expand(opt_idx, newval);
5008 if (s != NULL)
5009 {
5010 vim_free(newval);
5011 newlen = (unsigned)STRLEN(s) + 1;
5012 if (adding || prepending || removing)
5013 newlen += (unsigned)STRLEN(origval) + 1;
5014 newval = alloc(newlen);
5015 if (newval == NULL)
5016 break;
5017 STRCPY(newval, s);
5018 }
5019 }
5020
5021 /* locate newval[] in origval[] when removing it
5022 * and when adding to avoid duplicates */
5023 i = 0; /* init for GCC */
5024 if (removing || (flags & P_NODUP))
5025 {
5026 i = (int)STRLEN(newval);
5027 bs = 0;
5028 for (s = origval; *s; ++s)
5029 {
5030 if ((!(flags & P_COMMA)
5031 || s == origval
5032 || (s[-1] == ',' && !(bs & 1)))
5033 && STRNCMP(s, newval, i) == 0
5034 && (!(flags & P_COMMA)
5035 || s[i] == ','
5036 || s[i] == NUL))
5037 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005038 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005039 * even number of backslashes or a single
5040 * backslash preceded by a comma before it
5041 * is recognized as a separator */
5042 if ((s > origval + 1
5043 && s[-1] == '\\'
5044 && s[-2] != ',')
5045 || (s == origval + 1
5046 && s[-1] == '\\'))
5047
Bram Moolenaar071d4272004-06-13 20:20:40 +00005048 ++bs;
5049 else
5050 bs = 0;
5051 }
5052
5053 /* do not add if already there */
5054 if ((adding || prepending) && *s)
5055 {
5056 prepending = FALSE;
5057 adding = FALSE;
5058 STRCPY(newval, origval);
5059 }
5060 }
5061
5062 /* concatenate the two strings; add a ',' if
5063 * needed */
5064 if (adding || prepending)
5065 {
5066 comma = ((flags & P_COMMA) && *origval != NUL
5067 && *newval != NUL);
5068 if (adding)
5069 {
5070 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005071 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005072 if (comma && i > 1
5073 && (flags & P_ONECOMMA) == P_ONECOMMA
5074 && origval[i - 1] == ','
5075 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005076 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005077 mch_memmove(newval + i + comma, newval,
5078 STRLEN(newval) + 1);
5079 mch_memmove(newval, origval, (size_t)i);
5080 }
5081 else
5082 {
5083 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005084 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005085 }
5086 if (comma)
5087 newval[i] = ',';
5088 }
5089
5090 /* Remove newval[] from origval[]. (Note: "i" has
5091 * been set above and is used here). */
5092 if (removing)
5093 {
5094 STRCPY(newval, origval);
5095 if (*s)
5096 {
5097 /* may need to remove a comma */
5098 if (flags & P_COMMA)
5099 {
5100 if (s == origval)
5101 {
5102 /* include comma after string */
5103 if (s[i] == ',')
5104 ++i;
5105 }
5106 else
5107 {
5108 /* include comma before string */
5109 --s;
5110 ++i;
5111 }
5112 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005113 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005114 }
5115 }
5116
5117 if (flags & P_FLAGLIST)
5118 {
5119 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005120 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005121 {
5122 /* if options have P_FLAGLIST and
5123 * P_ONECOMMA such as 'whichwrap' */
5124 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005125 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005126 if (*s != ',' && *(s + 1) == ','
5127 && vim_strchr(s + 2, *s) != NULL)
5128 {
5129 /* Remove the duplicated value and
5130 * the next comma. */
5131 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005132 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005133 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005134 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005135 else
5136 {
5137 if ((!(flags & P_COMMA) || *s != ',')
5138 && vim_strchr(s + 1, *s) != NULL)
5139 {
5140 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005141 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005142 }
5143 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005144 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005145 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005146 }
5147
5148 if (save_arg != NULL) /* number for 'whichwrap' */
5149 arg = save_arg;
5150 new_value_alloced = TRUE;
5151 }
5152
5153 /* Set the new value. */
5154 *(char_u **)(varp) = newval;
5155
Bram Moolenaar53744302015-07-17 17:38:22 +02005156#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005157 if (!starting
5158# ifdef FEAT_CRYPT
5159 && options[opt_idx].indir != PV_KEY
5160# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005161 && origval != NULL && newval != NULL)
5162 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005163 /* origval may be freed by
5164 * did_set_string_option(), make a copy. */
5165 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005166 /* newval (and varp) may become invalid if the
5167 * buffer is closed by autocommands. */
5168 saved_newval = vim_strsave(newval);
5169 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005170#endif
5171
Bram Moolenaar071d4272004-06-13 20:20:40 +00005172 /* Handle side effects, and set the global value for
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005173 * ":set" on local options. Note: when setting 'syntax'
5174 * or 'filetype' autocommands may be triggered that can
5175 * cause havoc. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005176 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5177 new_value_alloced, oldval, errbuf, opt_flags);
5178
5179 /* If error detected, print the error message. */
5180 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005181 {
5182#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5183 vim_free(saved_origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005184 vim_free(saved_newval);
Bram Moolenaara9884962015-12-13 15:08:56 +01005185#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005186 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005187 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005188#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005189 trigger_optionsset_string(opt_idx, opt_flags,
5190 saved_origval, saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005191#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005192 }
5193 else /* key code option */
5194 {
5195 char_u *p;
5196
5197 if (nextchar == '&')
5198 {
5199 if (add_termcap_entry(key_name, TRUE) == FAIL)
5200 errmsg = (char_u *)N_("E522: Not found in termcap");
5201 }
5202 else
5203 {
5204 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005205 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005206 if (*p == '\\' && p[1] != NUL)
5207 ++p;
5208 nextchar = *p;
5209 *p = NUL;
5210 add_termcode(key_name, arg, FALSE);
5211 *p = nextchar;
5212 }
5213 if (full_screen)
5214 ttest(FALSE);
5215 redraw_all_later(CLEAR);
5216 }
5217 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005218
Bram Moolenaar071d4272004-06-13 20:20:40 +00005219 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005220 did_set_option(opt_idx, opt_flags,
5221 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005222 }
5223
5224skip:
5225 /*
5226 * Advance to next argument.
5227 * - skip until a blank found, taking care of backslashes
5228 * - skip blanks
5229 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5230 */
5231 for (i = 0; i < 2 ; ++i)
5232 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005233 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005234 if (*arg++ == '\\' && *arg != NUL)
5235 ++arg;
5236 arg = skipwhite(arg);
5237 if (*arg != '=')
5238 break;
5239 }
5240 }
5241
5242 if (errmsg != NULL)
5243 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005244 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005245 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005246 if (i + (arg - startarg) < IOSIZE)
5247 {
5248 /* append the argument with the error */
5249 STRCAT(IObuff, ": ");
5250 mch_memmove(IObuff + i, startarg, (arg - startarg));
5251 IObuff[i + (arg - startarg)] = NUL;
5252 }
5253 /* make sure all characters are printable */
5254 trans_characters(IObuff, IOSIZE);
5255
5256 ++no_wait_return; /* wait_return done later */
5257 emsg(IObuff); /* show error highlighted */
5258 --no_wait_return;
5259
5260 return FAIL;
5261 }
5262
5263 arg = skipwhite(arg);
5264 }
5265
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005266theend:
5267 if (silent_mode && did_show)
5268 {
5269 /* After displaying option values in silent mode. */
5270 silent_mode = FALSE;
5271 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5272 msg_putchar('\n');
5273 cursor_on(); /* msg_start() switches it off */
5274 out_flush();
5275 silent_mode = TRUE;
5276 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5277 }
5278
Bram Moolenaar071d4272004-06-13 20:20:40 +00005279 return OK;
5280}
5281
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005282/*
5283 * Call this when an option has been given a new value through a user command.
5284 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5285 */
5286 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005287did_set_option(
5288 int opt_idx,
5289 int opt_flags, /* possibly with OPT_MODELINE */
5290 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005291{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005292 long_u *p;
5293
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005294 options[opt_idx].flags |= P_WAS_SET;
5295
5296 /* When an option is set in the sandbox, from a modeline or in secure mode
5297 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005298 * flag. */
5299 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005300 if (secure
5301#ifdef HAVE_SANDBOX
5302 || sandbox != 0
5303#endif
5304 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005305 *p = *p | P_INSECURE;
5306 else if (new_value)
5307 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005308}
5309
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005311illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005312{
5313 if (errbuf == NULL)
5314 return (char_u *)"";
5315 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005316 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317 return errbuf;
5318}
5319
5320/*
5321 * Convert a key name or string into a key value.
5322 * Used for 'wildchar' and 'cedit' options.
5323 */
5324 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005325string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326{
5327 if (*arg == '<')
5328 return find_key_option(arg + 1);
5329 if (*arg == '^')
5330 return Ctrl_chr(arg[1]);
5331 return *arg;
5332}
5333
5334#ifdef FEAT_CMDWIN
5335/*
5336 * Check value of 'cedit' and set cedit_key.
5337 * Returns NULL if value is OK, error message otherwise.
5338 */
5339 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005340check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005341{
5342 int n;
5343
5344 if (*p_cedit == NUL)
5345 cedit_key = -1;
5346 else
5347 {
5348 n = string_to_key(p_cedit);
5349 if (vim_isprintc(n))
5350 return e_invarg;
5351 cedit_key = n;
5352 }
5353 return NULL;
5354}
5355#endif
5356
5357#ifdef FEAT_TITLE
5358/*
5359 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5360 * maketitle() to create and display it.
5361 * When switching the title or icon off, call mch_restore_title() to get
5362 * the old value back.
5363 */
5364 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005365did_set_title(
5366 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005367{
5368 if (starting != NO_SCREEN
5369#ifdef FEAT_GUI
5370 && !gui.starting
5371#endif
5372 )
5373 {
5374 maketitle();
5375 if (icon)
5376 {
5377 if (!p_icon)
5378 mch_restore_title(2);
5379 }
5380 else
5381 {
5382 if (!p_title)
5383 mch_restore_title(1);
5384 }
5385 }
5386}
5387#endif
5388
5389/*
5390 * set_options_bin - called when 'bin' changes value.
5391 */
5392 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005393set_options_bin(
5394 int oldval,
5395 int newval,
5396 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005397{
5398 /*
5399 * The option values that are changed when 'bin' changes are
5400 * copied when 'bin is set and restored when 'bin' is reset.
5401 */
5402 if (newval)
5403 {
5404 if (!oldval) /* switched on */
5405 {
5406 if (!(opt_flags & OPT_GLOBAL))
5407 {
5408 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5409 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5410 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5411 curbuf->b_p_et_nobin = curbuf->b_p_et;
5412 }
5413 if (!(opt_flags & OPT_LOCAL))
5414 {
5415 p_tw_nobin = p_tw;
5416 p_wm_nobin = p_wm;
5417 p_ml_nobin = p_ml;
5418 p_et_nobin = p_et;
5419 }
5420 }
5421
5422 if (!(opt_flags & OPT_GLOBAL))
5423 {
5424 curbuf->b_p_tw = 0; /* no automatic line wrap */
5425 curbuf->b_p_wm = 0; /* no automatic line wrap */
5426 curbuf->b_p_ml = 0; /* no modelines */
5427 curbuf->b_p_et = 0; /* no expandtab */
5428 }
5429 if (!(opt_flags & OPT_LOCAL))
5430 {
5431 p_tw = 0;
5432 p_wm = 0;
5433 p_ml = FALSE;
5434 p_et = FALSE;
5435 p_bin = TRUE; /* needed when called for the "-b" argument */
5436 }
5437 }
5438 else if (oldval) /* switched off */
5439 {
5440 if (!(opt_flags & OPT_GLOBAL))
5441 {
5442 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5443 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5444 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5445 curbuf->b_p_et = curbuf->b_p_et_nobin;
5446 }
5447 if (!(opt_flags & OPT_LOCAL))
5448 {
5449 p_tw = p_tw_nobin;
5450 p_wm = p_wm_nobin;
5451 p_ml = p_ml_nobin;
5452 p_et = p_et_nobin;
5453 }
5454 }
5455}
5456
5457#ifdef FEAT_VIMINFO
5458/*
5459 * Find the parameter represented by the given character (eg ', :, ", or /),
5460 * and return its associated value in the 'viminfo' string.
5461 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005462 * If the parameter is not specified in the string or there is no following
5463 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005464 */
5465 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005466get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005467{
5468 char_u *p;
5469
5470 p = find_viminfo_parameter(type);
5471 if (p != NULL && VIM_ISDIGIT(*p))
5472 return atoi((char *)p);
5473 return -1;
5474}
5475
5476/*
5477 * Find the parameter represented by the given character (eg ''', ':', '"', or
5478 * '/') in the 'viminfo' option and return a pointer to the string after it.
5479 * Return NULL if the parameter is not specified in the string.
5480 */
5481 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005482find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005483{
5484 char_u *p;
5485
5486 for (p = p_viminfo; *p; ++p)
5487 {
5488 if (*p == type)
5489 return p + 1;
5490 if (*p == 'n') /* 'n' is always the last one */
5491 break;
5492 p = vim_strchr(p, ','); /* skip until next ',' */
5493 if (p == NULL) /* hit the end without finding parameter */
5494 break;
5495 }
5496 return NULL;
5497}
5498#endif
5499
5500/*
5501 * Expand environment variables for some string options.
5502 * These string options cannot be indirect!
5503 * If "val" is NULL expand the current value of the option.
5504 * Return pointer to NameBuff, or NULL when not expanded.
5505 */
5506 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005507option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508{
5509 /* if option doesn't need expansion nothing to do */
5510 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5511 return NULL;
5512
5513 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5514 * expand_env() would truncate the string. */
5515 if (val != NULL && STRLEN(val) > MAXPATHL)
5516 return NULL;
5517
5518 if (val == NULL)
5519 val = *(char_u **)options[opt_idx].var;
5520
5521 /*
5522 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5523 * Escape spaces when expanding 'tags', they are used to separate file
5524 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005525 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005526 */
5527 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005528 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005529#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005530 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5531#endif
5532 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5534 return NULL;
5535
5536 return NameBuff;
5537}
5538
5539/*
5540 * After setting various option values: recompute variables that depend on
5541 * option values.
5542 */
5543 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005544didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545{
5546 /* initialize the table for 'iskeyword' et.al. */
5547 (void)init_chartab();
5548
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005549#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005551#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005552 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005553 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005554#ifdef FEAT_SESSION
5555 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5556 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5557#endif
5558#ifdef FEAT_FOLDING
5559 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5560#endif
5561 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005562 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005563#ifdef FEAT_VIRTUALEDIT
5564 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5565#endif
5566#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5567 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5568#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005569#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005570 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005571 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005572 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005573 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005574#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5576 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5577#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005578#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005579 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5580#endif
5581#ifdef FEAT_CMDWIN
5582 /* set cedit_key */
5583 (void)check_cedit();
5584#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005585#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005586 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005587#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005588#ifdef FEAT_LINEBREAK
5589 /* initialize the table for 'breakat'. */
5590 fill_breakat_flags();
5591#endif
5592
5593}
5594
5595/*
5596 * More side effects of setting options.
5597 */
5598 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005599didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005600{
5601 /* Initialize the highlight_attr[] table. */
5602 (void)highlight_changed();
5603
5604 /* Parse default for 'wildmode' */
5605 check_opt_wim();
5606
5607 (void)set_chars_option(&p_lcs);
5608#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5609 /* Parse default for 'fillchars'. */
5610 (void)set_chars_option(&p_fcs);
5611#endif
5612
5613#ifdef FEAT_CLIPBOARD
5614 /* Parse default for 'clipboard' */
5615 (void)check_clipboard_option();
5616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005617}
5618
5619/*
5620 * Check for string options that are NULL (normally only termcap options).
5621 */
5622 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005623check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005624{
5625 int opt_idx;
5626
5627 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5628 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5629 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5630}
5631
5632/*
5633 * Check string options in a buffer for NULL value.
5634 */
5635 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005636check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005637{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638 check_string_option(&buf->b_p_bh);
5639 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640#ifdef FEAT_MBYTE
5641 check_string_option(&buf->b_p_fenc);
5642#endif
5643 check_string_option(&buf->b_p_ff);
5644#ifdef FEAT_FIND_ID
5645 check_string_option(&buf->b_p_def);
5646 check_string_option(&buf->b_p_inc);
5647# ifdef FEAT_EVAL
5648 check_string_option(&buf->b_p_inex);
5649# endif
5650#endif
5651#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5652 check_string_option(&buf->b_p_inde);
5653 check_string_option(&buf->b_p_indk);
5654#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005655#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5656 check_string_option(&buf->b_p_bexpr);
5657#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005658#if defined(FEAT_CRYPT)
5659 check_string_option(&buf->b_p_cm);
5660#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005661 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005662#if defined(FEAT_EVAL)
5663 check_string_option(&buf->b_p_fex);
5664#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665#ifdef FEAT_CRYPT
5666 check_string_option(&buf->b_p_key);
5667#endif
5668 check_string_option(&buf->b_p_kp);
5669 check_string_option(&buf->b_p_mps);
5670 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005671 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672 check_string_option(&buf->b_p_isk);
5673#ifdef FEAT_COMMENTS
5674 check_string_option(&buf->b_p_com);
5675#endif
5676#ifdef FEAT_FOLDING
5677 check_string_option(&buf->b_p_cms);
5678#endif
5679 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005680#ifdef FEAT_TEXTOBJ
5681 check_string_option(&buf->b_p_qe);
5682#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683#ifdef FEAT_SYN_HL
5684 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005685 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005686#endif
5687#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005688 check_string_option(&buf->b_s.b_p_spc);
5689 check_string_option(&buf->b_s.b_p_spf);
5690 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691#endif
5692#ifdef FEAT_SEARCHPATH
5693 check_string_option(&buf->b_p_sua);
5694#endif
5695#ifdef FEAT_CINDENT
5696 check_string_option(&buf->b_p_cink);
5697 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005698 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699#endif
5700#ifdef FEAT_AUTOCMD
5701 check_string_option(&buf->b_p_ft);
5702#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005703#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5704 check_string_option(&buf->b_p_cinw);
5705#endif
5706#ifdef FEAT_INS_EXPAND
5707 check_string_option(&buf->b_p_cpt);
5708#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005709#ifdef FEAT_COMPL_FUNC
5710 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005711 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005712#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713#ifdef FEAT_KEYMAP
5714 check_string_option(&buf->b_p_keymap);
5715#endif
5716#ifdef FEAT_QUICKFIX
5717 check_string_option(&buf->b_p_gp);
5718 check_string_option(&buf->b_p_mp);
5719 check_string_option(&buf->b_p_efm);
5720#endif
5721 check_string_option(&buf->b_p_ep);
5722 check_string_option(&buf->b_p_path);
5723 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005724 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725#ifdef FEAT_INS_EXPAND
5726 check_string_option(&buf->b_p_dict);
5727 check_string_option(&buf->b_p_tsr);
5728#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005729#ifdef FEAT_LISP
5730 check_string_option(&buf->b_p_lw);
5731#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005732 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005733#ifdef FEAT_MBYTE
5734 check_string_option(&buf->b_p_menc);
5735#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736}
5737
5738/*
5739 * Free the string allocated for an option.
5740 * Checks for the string being empty_option. This may happen if we're out of
5741 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5742 * check_options().
5743 * Does NOT check for P_ALLOCED flag!
5744 */
5745 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005746free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005747{
5748 if (p != empty_option)
5749 vim_free(p);
5750}
5751
5752 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005753clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754{
5755 if (*pp != empty_option)
5756 vim_free(*pp);
5757 *pp = empty_option;
5758}
5759
5760 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005761check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005762{
5763 if (*pp == NULL)
5764 *pp = empty_option;
5765}
5766
5767/*
5768 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5769 */
5770 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005771set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772{
5773 int opt_idx;
5774
5775 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5776 if (options[opt_idx].var == (char_u *)p)
5777 {
5778 options[opt_idx].flags |= P_ALLOCED;
5779 return;
5780 }
5781 return; /* cannot happen: didn't find it! */
5782}
5783
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005784#if defined(FEAT_EVAL) || defined(PROTO)
5785/*
5786 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5787 * Return FALSE when it wasn't.
5788 * Return -1 for an unknown option.
5789 */
5790 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005791was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005792{
5793 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005794 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005795
5796 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005797 {
5798 flagp = insecure_flag(idx, opt_flags);
5799 return (*flagp & P_INSECURE) != 0;
5800 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005801 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005802 return -1;
5803}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005804
5805/*
5806 * Get a pointer to the flags used for the P_INSECURE flag of option
5807 * "opt_idx". For some local options a local flags field is used.
5808 */
5809 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005810insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005811{
5812 if (opt_flags & OPT_LOCAL)
5813 switch ((int)options[opt_idx].indir)
5814 {
5815#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005816 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005817#endif
5818#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005819# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005820 case PV_FDE: return &curwin->w_p_fde_flags;
5821 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005822# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005823# ifdef FEAT_BEVAL
5824 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5825# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005826# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005827 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005828# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005829 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005830# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005831 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005832# endif
5833#endif
5834 }
5835
5836 /* Nothing special, return global flags field. */
5837 return &options[opt_idx].flags;
5838}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005839#endif
5840
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005841#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005842static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005843
5844/*
5845 * Redraw the window title and/or tab page text later.
5846 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005847static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005848{
5849 need_maketitle = TRUE;
5850# ifdef FEAT_WINDOWS
5851 redraw_tabline = TRUE;
5852# endif
5853}
5854#endif
5855
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856/*
5857 * Set a string option to a new value (without checking the effect).
5858 * The string is copied into allocated memory.
5859 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005860 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005861 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005862 */
5863 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005864set_string_option_direct(
5865 char_u *name,
5866 int opt_idx,
5867 char_u *val,
5868 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5869 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870{
5871 char_u *s;
5872 char_u **varp;
5873 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005874 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005875
Bram Moolenaar89d40322006-08-29 15:30:07 +00005876 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005877 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005878 idx = findoption(name);
5879 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005880 {
5881 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005882 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005884 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885 }
5886
Bram Moolenaar89d40322006-08-29 15:30:07 +00005887 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005888 return;
5889
5890 s = vim_strsave(val);
5891 if (s != NULL)
5892 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005893 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005895 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 free_string_option(*varp);
5897 *varp = s;
5898
5899 /* For buffer/window local option may also set the global value. */
5900 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005901 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005902
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904
5905 /* When setting both values of a global option with a local value,
5906 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005907 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005908 {
5909 free_string_option(*varp);
5910 *varp = empty_option;
5911 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005912# ifdef FEAT_EVAL
5913 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005914 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005915 set_sid == 0 ? current_SID : set_sid);
5916# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917 }
5918}
5919
5920/*
5921 * Set global value for string option when it's a local option.
5922 */
5923 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005924set_string_option_global(
5925 int opt_idx, /* option index */
5926 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927{
5928 char_u **p, *s;
5929
5930 /* the global value is always allocated */
5931 if (options[opt_idx].var == VAR_WIN)
5932 p = (char_u **)GLOBAL_WO(varp);
5933 else
5934 p = (char_u **)options[opt_idx].var;
5935 if (options[opt_idx].indir != PV_NONE
5936 && p != varp
5937 && (s = vim_strsave(*varp)) != NULL)
5938 {
5939 free_string_option(*p);
5940 *p = s;
5941 }
5942}
5943
5944/*
5945 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005946 *
5947 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005948 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005949 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005950set_string_option(
5951 int opt_idx,
5952 char_u *value,
5953 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005954{
5955 char_u *s;
5956 char_u **varp;
5957 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005958#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5959 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005960 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005961#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005962 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963
5964 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005965 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966
5967 s = vim_strsave(value);
5968 if (s != NULL)
5969 {
5970 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5971 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005972 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005973 ? OPT_GLOBAL : OPT_LOCAL)
5974 : opt_flags);
5975 oldval = *varp;
5976 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005977
5978#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005979 if (!starting
5980# ifdef FEAT_CRYPT
5981 && options[opt_idx].indir != PV_KEY
5982# endif
5983 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005984 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005985 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005986 saved_newval = vim_strsave(s);
5987 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005988#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005989 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5990 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005991 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005992
Bram Moolenaar53744302015-07-17 17:38:22 +02005993#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005994 /* call autocommand after handling side effects */
5995 trigger_optionsset_string(opt_idx, opt_flags,
5996 saved_oldval, saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005997#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005998 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005999 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006000}
6001
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006002#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006003/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006004 * Return TRUE if "val" is a valid 'filetype' name.
6005 * Also used for 'syntax' and 'keymap'.
6006 */
6007 static int
6008valid_filetype(char_u *val)
6009{
6010 char_u *s;
6011
6012 for (s = val; *s != NUL; ++s)
6013 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6014 return FALSE;
6015 return TRUE;
6016}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01006017#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01006018
6019/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006020 * Handle string options that need some action to perform when changed.
6021 * Returns NULL for success, or an error message for an error.
6022 */
6023 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006024did_set_string_option(
6025 int opt_idx, /* index in options[] table */
6026 char_u **varp, /* pointer to the option variable */
6027 int new_value_alloced, /* new value was allocated */
6028 char_u *oldval, /* previous value of the option */
6029 char_u *errbuf, /* buffer for errors, or NULL */
6030 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006031{
6032 char_u *errmsg = NULL;
6033 char_u *s, *p;
6034 int did_chartab = FALSE;
6035 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006036 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006037#ifdef FEAT_GUI
6038 /* set when changing an option that only requires a redraw in the GUI */
6039 int redraw_gui_only = FALSE;
6040#endif
Bram Moolenaar90492982017-06-22 14:16:31 +02006041#ifdef FEAT_AUTOCMD
6042 int ft_changed = FALSE;
6043#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006044
6045 /* Get the global option to compare with, otherwise we would have to check
6046 * two values for all local options. */
6047 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6048
6049 /* Disallow changing some options from secure mode */
6050 if ((secure
6051#ifdef HAVE_SANDBOX
6052 || sandbox != 0
6053#endif
6054 ) && (options[opt_idx].flags & P_SECURE))
6055 {
6056 errmsg = e_secure;
6057 }
6058
Bram Moolenaar7554da42016-11-25 22:04:13 +01006059 /* Check for a "normal" directory or file name in some options. Disallow a
6060 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006061 * are often illegal in a file name. Be more permissive if "secure" is off.
6062 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006063 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006064 && vim_strpbrk(*varp, (char_u *)(secure
6065 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006066 || ((options[opt_idx].flags & P_NDNAME)
6067 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006068 {
6069 errmsg = e_invarg;
6070 }
6071
Bram Moolenaar071d4272004-06-13 20:20:40 +00006072 /* 'term' */
6073 else if (varp == &T_NAME)
6074 {
6075 if (T_NAME[0] == NUL)
6076 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6077#ifdef FEAT_GUI
6078 if (gui.in_use)
6079 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6080 else if (term_is_gui(T_NAME))
6081 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6082#endif
6083 else if (set_termname(T_NAME) == FAIL)
6084 errmsg = (char_u *)N_("E522: Not found in termcap");
6085 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006086 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006087 /* Screen colors may have changed. */
6088 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006089
6090 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6091 * P_ALLOCED flag on 'term'. */
6092 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006093 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006094 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095 }
6096
6097 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006098 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006100 char_u *bkc = p_bkc;
6101 unsigned int *flags = &bkc_flags;
6102
6103 if (opt_flags & OPT_LOCAL)
6104 {
6105 bkc = curbuf->b_p_bkc;
6106 flags = &curbuf->b_bkc_flags;
6107 }
6108
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006109 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6110 /* make the local value empty: use the global value */
6111 *flags = 0;
6112 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006113 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006114 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6115 errmsg = e_invarg;
6116 if ((((int)*flags & BKC_AUTO) != 0)
6117 + (((int)*flags & BKC_YES) != 0)
6118 + (((int)*flags & BKC_NO) != 0) != 1)
6119 {
6120 /* Must have exactly one of "auto", "yes" and "no". */
6121 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6122 errmsg = e_invarg;
6123 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 }
6125 }
6126
6127 /* 'backupext' and 'patchmode' */
6128 else if (varp == &p_bex || varp == &p_pm)
6129 {
6130 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6131 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6132 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6133 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006134#ifdef FEAT_LINEBREAK
6135 /* 'breakindentopt' */
6136 else if (varp == &curwin->w_p_briopt)
6137 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006138 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006139 errmsg = e_invarg;
6140 }
6141#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006142
6143 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006144 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006145 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006146 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006147 */
6148 else if ( varp == &p_isi
6149 || varp == &(curbuf->b_p_isk)
6150 || varp == &p_isp
6151 || varp == &p_isf)
6152 {
6153 if (init_chartab() == FAIL)
6154 {
6155 did_chartab = TRUE; /* need to restore it below */
6156 errmsg = e_invarg; /* error in value */
6157 }
6158 }
6159
6160 /* 'helpfile' */
6161 else if (varp == &p_hf)
6162 {
6163 /* May compute new values for $VIM and $VIMRUNTIME */
6164 if (didset_vim)
6165 {
6166 vim_setenv((char_u *)"VIM", (char_u *)"");
6167 didset_vim = FALSE;
6168 }
6169 if (didset_vimruntime)
6170 {
6171 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6172 didset_vimruntime = FALSE;
6173 }
6174 }
6175
Bram Moolenaar1a384422010-07-14 19:53:30 +02006176#ifdef FEAT_SYN_HL
6177 /* 'colorcolumn' */
6178 else if (varp == &curwin->w_p_cc)
6179 errmsg = check_colorcolumn(curwin);
6180#endif
6181
Bram Moolenaar071d4272004-06-13 20:20:40 +00006182#ifdef FEAT_MULTI_LANG
6183 /* 'helplang' */
6184 else if (varp == &p_hlg)
6185 {
6186 /* Check for "", "ab", "ab,cd", etc. */
6187 for (s = p_hlg; *s != NUL; s += 3)
6188 {
6189 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6190 {
6191 errmsg = e_invarg;
6192 break;
6193 }
6194 if (s[2] == NUL)
6195 break;
6196 }
6197 }
6198#endif
6199
6200 /* 'highlight' */
6201 else if (varp == &p_hl)
6202 {
6203 if (highlight_changed() == FAIL)
6204 errmsg = e_invarg; /* invalid flags */
6205 }
6206
6207 /* 'nrformats' */
6208 else if (gvarp == &p_nf)
6209 {
6210 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6211 errmsg = e_invarg;
6212 }
6213
6214#ifdef FEAT_SESSION
6215 /* 'sessionoptions' */
6216 else if (varp == &p_ssop)
6217 {
6218 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6219 errmsg = e_invarg;
6220 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6221 {
6222 /* Don't allow both "sesdir" and "curdir". */
6223 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6224 errmsg = e_invarg;
6225 }
6226 }
6227 /* 'viewoptions' */
6228 else if (varp == &p_vop)
6229 {
6230 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6231 errmsg = e_invarg;
6232 }
6233#endif
6234
6235 /* 'scrollopt' */
6236#ifdef FEAT_SCROLLBIND
6237 else if (varp == &p_sbo)
6238 {
6239 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6240 errmsg = e_invarg;
6241 }
6242#endif
6243
6244 /* 'ambiwidth' */
6245#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006246 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006247 {
6248 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6249 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006250 else if (set_chars_option(&p_lcs) != NULL)
6251 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6252# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6253 else if (set_chars_option(&p_fcs) != NULL)
6254 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6255# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006256 }
6257#endif
6258
6259 /* 'background' */
6260 else if (varp == &p_bg)
6261 {
6262 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6263 {
6264#ifdef FEAT_EVAL
6265 int dark = (*p_bg == 'd');
6266#endif
6267
6268 init_highlight(FALSE, FALSE);
6269
6270#ifdef FEAT_EVAL
6271 if (dark != (*p_bg == 'd')
6272 && get_var_value((char_u *)"g:colors_name") != NULL)
6273 {
6274 /* The color scheme must have set 'background' back to another
6275 * value, that's not what we want here. Disable the color
6276 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006277 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006278 free_string_option(p_bg);
6279 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6280 check_string_option(&p_bg);
6281 init_highlight(FALSE, FALSE);
6282 }
6283#endif
6284 }
6285 else
6286 errmsg = e_invarg;
6287 }
6288
6289 /* 'wildmode' */
6290 else if (varp == &p_wim)
6291 {
6292 if (check_opt_wim() == FAIL)
6293 errmsg = e_invarg;
6294 }
6295
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006296#ifdef FEAT_CMDL_COMPL
6297 /* 'wildoptions' */
6298 else if (varp == &p_wop)
6299 {
6300 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6301 errmsg = e_invarg;
6302 }
6303#endif
6304
Bram Moolenaar071d4272004-06-13 20:20:40 +00006305#ifdef FEAT_WAK
6306 /* 'winaltkeys' */
6307 else if (varp == &p_wak)
6308 {
6309 if (*p_wak == NUL
6310 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6311 errmsg = e_invarg;
6312# ifdef FEAT_MENU
6313# ifdef FEAT_GUI_MOTIF
6314 else if (gui.in_use)
6315 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6316# else
6317# ifdef FEAT_GUI_GTK
6318 else if (gui.in_use)
6319 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6320# endif
6321# endif
6322# endif
6323 }
6324#endif
6325
6326#ifdef FEAT_AUTOCMD
6327 /* 'eventignore' */
6328 else if (varp == &p_ei)
6329 {
6330 if (check_ei() == FAIL)
6331 errmsg = e_invarg;
6332 }
6333#endif
6334
6335#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006336 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6337 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6338 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006339 {
6340 if (gvarp == &p_fenc)
6341 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006342 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343 errmsg = e_modifiable;
6344 else if (vim_strchr(*varp, ',') != NULL)
6345 /* No comma allowed in 'fileencoding'; catches confusing it
6346 * with 'fileencodings'. */
6347 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006348 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006349 {
6350# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006352 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006353# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006354 /* Add 'fileencoding' to the swap file. */
6355 ml_setflags(curbuf);
6356 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006357 }
6358 if (errmsg == NULL)
6359 {
6360 /* canonize the value, so that STRCMP() can be used on it */
6361 p = enc_canonize(*varp);
6362 if (p != NULL)
6363 {
6364 vim_free(*varp);
6365 *varp = p;
6366 }
6367 if (varp == &p_enc)
6368 {
6369 errmsg = mb_init();
6370# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006371 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006372# endif
6373 }
6374 }
6375
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006376# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6378 {
6379 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6380 if (STRCMP(p_tenc, "utf-8") != 0)
6381 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6382 }
6383# endif
6384
6385 if (errmsg == NULL)
6386 {
6387# ifdef FEAT_KEYMAP
6388 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6389 * (with another encoding). */
6390 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6391 (void)keymap_init();
6392# endif
6393
6394 /* When 'termencoding' is not empty and 'encoding' changes or when
6395 * 'termencoding' changes, need to setup for keyboard input and
6396 * display output conversion. */
6397 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6398 {
6399 convert_setup(&input_conv, p_tenc, p_enc);
6400 convert_setup(&output_conv, p_enc, p_tenc);
6401 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006402
6403# if defined(WIN3264) && defined(FEAT_MBYTE)
6404 /* $HOME may have characters in active code page. */
6405 if (varp == &p_enc)
6406 init_homedir();
6407# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 }
6409 }
6410#endif
6411
6412#if defined(FEAT_POSTSCRIPT)
6413 else if (varp == &p_penc)
6414 {
6415 /* Canonize printencoding if VIM standard one */
6416 p = enc_canonize(p_penc);
6417 if (p != NULL)
6418 {
6419 vim_free(p_penc);
6420 p_penc = p;
6421 }
6422 else
6423 {
6424 /* Ensure lower case and '-' for '_' */
6425 for (s = p_penc; *s != NUL; s++)
6426 {
6427 if (*s == '_')
6428 *s = '-';
6429 else
6430 *s = TOLOWER_ASC(*s);
6431 }
6432 }
6433 }
6434#endif
6435
Bram Moolenaar9372a112005-12-06 19:59:18 +00006436#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006437 else if (varp == &p_imak)
6438 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006439 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006440 errmsg = e_invarg;
6441 }
6442#endif
6443
6444#ifdef FEAT_KEYMAP
6445 else if (varp == &curbuf->b_p_keymap)
6446 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006447 if (!valid_filetype(*varp))
6448 errmsg = e_invarg;
6449 else
6450 /* load or unload key mapping tables */
6451 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006452
Bram Moolenaarfab06232009-03-04 03:13:35 +00006453 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006455 if (*curbuf->b_p_keymap != NUL)
6456 {
6457 /* Installed a new keymap, switch on using it. */
6458 curbuf->b_p_iminsert = B_IMODE_LMAP;
6459 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6460 curbuf->b_p_imsearch = B_IMODE_LMAP;
6461 }
6462 else
6463 {
6464 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6465 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6466 curbuf->b_p_iminsert = B_IMODE_NONE;
6467 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6468 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6469 }
6470 if ((opt_flags & OPT_LOCAL) == 0)
6471 {
6472 set_iminsert_global();
6473 set_imsearch_global();
6474 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006475# ifdef FEAT_WINDOWS
6476 status_redraw_curbuf();
6477# endif
6478 }
6479 }
6480#endif
6481
6482 /* 'fileformat' */
6483 else if (gvarp == &p_ff)
6484 {
6485 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6486 errmsg = e_modifiable;
6487 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6488 errmsg = e_invarg;
6489 else
6490 {
6491 /* may also change 'textmode' */
6492 if (get_fileformat(curbuf) == EOL_DOS)
6493 curbuf->b_p_tx = TRUE;
6494 else
6495 curbuf->b_p_tx = FALSE;
6496#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006497 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006499 /* update flag in swap file */
6500 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006501 /* Redraw needed when switching to/from "mac": a CR in the text
6502 * will be displayed differently. */
6503 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6504 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006505 }
6506 }
6507
6508 /* 'fileformats' */
6509 else if (varp == &p_ffs)
6510 {
6511 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6512 errmsg = e_invarg;
6513 else
6514 {
6515 /* also change 'textauto' */
6516 if (*p_ffs == NUL)
6517 p_ta = FALSE;
6518 else
6519 p_ta = TRUE;
6520 }
6521 }
6522
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006523#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006524 /* 'cryptkey' */
6525 else if (gvarp == &p_key)
6526 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006527# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006528 /* Make sure the ":set" command doesn't show the new value in the
6529 * history. */
6530 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006531# endif
6532 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6533 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006534 ml_set_crypt_key(curbuf, oldval,
6535 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006536 }
6537
6538 else if (gvarp == &p_cm)
6539 {
6540 if (opt_flags & OPT_LOCAL)
6541 p = curbuf->b_p_cm;
6542 else
6543 p = p_cm;
6544 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6545 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006546 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006547 errmsg = e_invarg;
6548 else
6549 {
6550 /* When setting the global value to empty, make it "zip". */
6551 if (*p_cm == NUL)
6552 {
6553 if (new_value_alloced)
6554 free_string_option(p_cm);
6555 p_cm = vim_strsave((char_u *)"zip");
6556 new_value_alloced = TRUE;
6557 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006558 /* When using ":set cm=name" the local value is going to be empty.
6559 * Do that here, otherwise the crypt functions will still use the
6560 * local value. */
6561 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6562 {
6563 free_string_option(curbuf->b_p_cm);
6564 curbuf->b_p_cm = empty_option;
6565 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006566
6567 /* Need to update the swapfile when the effective method changed.
6568 * Set "s" to the effective old value, "p" to the effective new
6569 * method and compare. */
6570 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6571 s = p_cm; /* was previously using the global value */
6572 else
6573 s = oldval;
6574 if (*curbuf->b_p_cm == NUL)
6575 p = p_cm; /* is now using the global value */
6576 else
6577 p = curbuf->b_p_cm;
6578 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006579 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006580
6581 /* If the global value changes need to update the swapfile for all
6582 * buffers using that value. */
6583 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6584 {
6585 buf_T *buf;
6586
Bram Moolenaar29323592016-07-24 22:04:11 +02006587 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006588 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006589 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006590 }
6591 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006592 }
6593#endif
6594
6595 /* 'matchpairs' */
6596 else if (gvarp == &p_mps)
6597 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006598#ifdef FEAT_MBYTE
6599 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006600 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006601 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006602 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006603 int x2 = -1;
6604 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006605
6606 if (*p != NUL)
6607 p += mb_ptr2len(p);
6608 if (*p != NUL)
6609 x2 = *p++;
6610 if (*p != NUL)
6611 {
6612 x3 = mb_ptr2char(p);
6613 p += mb_ptr2len(p);
6614 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006615 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006616 {
6617 errmsg = e_invarg;
6618 break;
6619 }
6620 if (*p == NUL)
6621 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006622 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006623 }
6624 else
6625#endif
6626 {
6627 /* Check for "x:y,x:y" */
6628 for (p = *varp; *p != NUL; p += 4)
6629 {
6630 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6631 {
6632 errmsg = e_invarg;
6633 break;
6634 }
6635 if (p[3] == NUL)
6636 break;
6637 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006638 }
6639 }
6640
6641#ifdef FEAT_COMMENTS
6642 /* 'comments' */
6643 else if (gvarp == &p_com)
6644 {
6645 for (s = *varp; *s; )
6646 {
6647 while (*s && *s != ':')
6648 {
6649 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6650 && !VIM_ISDIGIT(*s) && *s != '-')
6651 {
6652 errmsg = illegal_char(errbuf, *s);
6653 break;
6654 }
6655 ++s;
6656 }
6657 if (*s++ == NUL)
6658 errmsg = (char_u *)N_("E524: Missing colon");
6659 else if (*s == ',' || *s == NUL)
6660 errmsg = (char_u *)N_("E525: Zero length string");
6661 if (errmsg != NULL)
6662 break;
6663 while (*s && *s != ',')
6664 {
6665 if (*s == '\\' && s[1] != NUL)
6666 ++s;
6667 ++s;
6668 }
6669 s = skip_to_option_part(s);
6670 }
6671 }
6672#endif
6673
6674 /* 'listchars' */
6675 else if (varp == &p_lcs)
6676 {
6677 errmsg = set_chars_option(varp);
6678 }
6679
6680#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6681 /* 'fillchars' */
6682 else if (varp == &p_fcs)
6683 {
6684 errmsg = set_chars_option(varp);
6685 }
6686#endif
6687
6688#ifdef FEAT_CMDWIN
6689 /* 'cedit' */
6690 else if (varp == &p_cedit)
6691 {
6692 errmsg = check_cedit();
6693 }
6694#endif
6695
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006696 /* 'verbosefile' */
6697 else if (varp == &p_vfile)
6698 {
6699 verbose_stop();
6700 if (*p_vfile != NUL && verbose_open() == FAIL)
6701 errmsg = e_invarg;
6702 }
6703
Bram Moolenaar071d4272004-06-13 20:20:40 +00006704#ifdef FEAT_VIMINFO
6705 /* 'viminfo' */
6706 else if (varp == &p_viminfo)
6707 {
6708 for (s = p_viminfo; *s;)
6709 {
6710 /* Check it's a valid character */
6711 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6712 {
6713 errmsg = illegal_char(errbuf, *s);
6714 break;
6715 }
6716 if (*s == 'n') /* name is always last one */
6717 {
6718 break;
6719 }
6720 else if (*s == 'r') /* skip until next ',' */
6721 {
6722 while (*++s && *s != ',')
6723 ;
6724 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006725 else if (*s == '%')
6726 {
6727 /* optional number */
6728 while (vim_isdigit(*++s))
6729 ;
6730 }
6731 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006732 ++s; /* no extra chars */
6733 else /* must have a number */
6734 {
6735 while (vim_isdigit(*++s))
6736 ;
6737
6738 if (!VIM_ISDIGIT(*(s - 1)))
6739 {
6740 if (errbuf != NULL)
6741 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006742 sprintf((char *)errbuf,
6743 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006744 transchar_byte(*(s - 1)));
6745 errmsg = errbuf;
6746 }
6747 else
6748 errmsg = (char_u *)"";
6749 break;
6750 }
6751 }
6752 if (*s == ',')
6753 ++s;
6754 else if (*s)
6755 {
6756 if (errbuf != NULL)
6757 errmsg = (char_u *)N_("E527: Missing comma");
6758 else
6759 errmsg = (char_u *)"";
6760 break;
6761 }
6762 }
6763 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6764 errmsg = (char_u *)N_("E528: Must specify a ' value");
6765 }
6766#endif /* FEAT_VIMINFO */
6767
6768 /* terminal options */
6769 else if (istermoption(&options[opt_idx]) && full_screen)
6770 {
6771 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6772 if (varp == &T_CCO)
6773 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006774 int colors = atoi((char *)T_CCO);
6775
6776 /* Only reinitialize colors if t_Co value has really changed to
6777 * avoid expensive reload of colorscheme if t_Co is set to the
6778 * same value multiple times. */
6779 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006781 t_colors = colors;
6782 if (t_colors <= 1)
6783 {
6784 if (new_value_alloced)
6785 vim_free(T_CCO);
6786 T_CCO = empty_option;
6787 }
6788 /* We now have a different color setup, initialize it again. */
6789 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006791 }
6792 ttest(FALSE);
6793 if (varp == &T_ME)
6794 {
6795 out_str(T_ME);
6796 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006797#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006798 /* Since t_me has been set, this probably means that the user
6799 * wants to use this as default colors. Need to reset default
6800 * background/foreground colors. */
6801 mch_set_normal_colors();
6802#endif
6803 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006804 if (varp == &T_BE && termcap_active)
6805 {
6806 if (*T_BE == NUL)
6807 /* When clearing t_BE we assume the user no longer wants
6808 * bracketed paste, thus disable it by writing t_BD. */
6809 out_str(T_BD);
6810 else
6811 out_str(T_BE);
6812 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006813 }
6814
6815#ifdef FEAT_LINEBREAK
6816 /* 'showbreak' */
6817 else if (varp == &p_sbr)
6818 {
6819 for (s = p_sbr; *s; )
6820 {
6821 if (ptr2cells(s) != 1)
6822 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006823 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006824 }
6825 }
6826#endif
6827
6828#ifdef FEAT_GUI
6829 /* 'guifont' */
6830 else if (varp == &p_guifont)
6831 {
6832 if (gui.in_use)
6833 {
6834 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006835# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006836 /*
6837 * Put up a font dialog and let the user select a new value.
6838 * If this is cancelled go back to the old value but don't
6839 * give an error message.
6840 */
6841 if (STRCMP(p, "*") == 0)
6842 {
6843 p = gui_mch_font_dialog(oldval);
6844
6845 if (new_value_alloced)
6846 free_string_option(p_guifont);
6847
6848 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6849 new_value_alloced = TRUE;
6850 }
6851# endif
6852 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6853 {
6854# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6855 if (STRCMP(p_guifont, "*") == 0)
6856 {
6857 /* Dialog was cancelled: Keep the old value without giving
6858 * an error message. */
6859 if (new_value_alloced)
6860 free_string_option(p_guifont);
6861 p_guifont = vim_strsave(oldval);
6862 new_value_alloced = TRUE;
6863 }
6864 else
6865# endif
6866 errmsg = (char_u *)N_("E596: Invalid font(s)");
6867 }
6868 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006869 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006870 }
6871# ifdef FEAT_XFONTSET
6872 else if (varp == &p_guifontset)
6873 {
6874 if (STRCMP(p_guifontset, "*") == 0)
6875 errmsg = (char_u *)N_("E597: can't select fontset");
6876 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6877 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006878 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006879 }
6880# endif
6881# ifdef FEAT_MBYTE
6882 else if (varp == &p_guifontwide)
6883 {
6884 if (STRCMP(p_guifontwide, "*") == 0)
6885 errmsg = (char_u *)N_("E533: can't select wide font");
6886 else if (gui_get_wide_font() == FAIL)
6887 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006888 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006889 }
6890# endif
6891#endif
6892
6893#ifdef CURSOR_SHAPE
6894 /* 'guicursor' */
6895 else if (varp == &p_guicursor)
6896 errmsg = parse_shape_opt(SHAPE_CURSOR);
6897#endif
6898
6899#ifdef FEAT_MOUSESHAPE
6900 /* 'mouseshape' */
6901 else if (varp == &p_mouseshape)
6902 {
6903 errmsg = parse_shape_opt(SHAPE_MOUSE);
6904 update_mouseshape(-1);
6905 }
6906#endif
6907
6908#ifdef FEAT_PRINTER
6909 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006910 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006911# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006912 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006913 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006914# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006915#endif
6916
6917#ifdef FEAT_LANGMAP
6918 /* 'langmap' */
6919 else if (varp == &p_langmap)
6920 langmap_set();
6921#endif
6922
6923#ifdef FEAT_LINEBREAK
6924 /* 'breakat' */
6925 else if (varp == &p_breakat)
6926 fill_breakat_flags();
6927#endif
6928
6929#ifdef FEAT_TITLE
6930 /* 'titlestring' and 'iconstring' */
6931 else if (varp == &p_titlestring || varp == &p_iconstring)
6932 {
6933# ifdef FEAT_STL_OPT
6934 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6935
6936 /* NULL => statusline syntax */
6937 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6938 stl_syntax |= flagval;
6939 else
6940 stl_syntax &= ~flagval;
6941# endif
6942 did_set_title(varp == &p_iconstring);
6943
6944 }
6945#endif
6946
6947#ifdef FEAT_GUI
6948 /* 'guioptions' */
6949 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006950 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006951 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006952 redraw_gui_only = TRUE;
6953 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006954#endif
6955
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006956#if defined(FEAT_GUI_TABLINE)
6957 /* 'guitablabel' */
6958 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006959 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006960 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006961 redraw_gui_only = TRUE;
6962 }
6963 /* 'guitabtooltip' */
6964 else if (varp == &p_gtt)
6965 {
6966 redraw_gui_only = TRUE;
6967 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006968#endif
6969
Bram Moolenaar071d4272004-06-13 20:20:40 +00006970#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6971 /* 'ttymouse' */
6972 else if (varp == &p_ttym)
6973 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006974 /* Switch the mouse off before changing the escape sequences used for
6975 * that. */
6976 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006977 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6978 errmsg = e_invarg;
6979 else
6980 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006981 if (termcap_active)
6982 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006983 }
6984#endif
6985
Bram Moolenaar071d4272004-06-13 20:20:40 +00006986 /* 'selection' */
6987 else if (varp == &p_sel)
6988 {
6989 if (*p_sel == NUL
6990 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6991 errmsg = e_invarg;
6992 }
6993
6994 /* 'selectmode' */
6995 else if (varp == &p_slm)
6996 {
6997 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6998 errmsg = e_invarg;
6999 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007000
7001#ifdef FEAT_BROWSE
7002 /* 'browsedir' */
7003 else if (varp == &p_bsdir)
7004 {
7005 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7006 && !mch_isdir(p_bsdir))
7007 errmsg = e_invarg;
7008 }
7009#endif
7010
Bram Moolenaar071d4272004-06-13 20:20:40 +00007011 /* 'keymodel' */
7012 else if (varp == &p_km)
7013 {
7014 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7015 errmsg = e_invarg;
7016 else
7017 {
7018 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7019 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7020 }
7021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007022
7023 /* 'mousemodel' */
7024 else if (varp == &p_mousem)
7025 {
7026 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7027 errmsg = e_invarg;
7028#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7029 else if (*p_mousem != *oldval)
7030 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7031 * to create or delete the popup menus. */
7032 gui_motif_update_mousemodel(root_menu);
7033#endif
7034 }
7035
7036 /* 'switchbuf' */
7037 else if (varp == &p_swb)
7038 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007039 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007040 errmsg = e_invarg;
7041 }
7042
7043 /* 'debug' */
7044 else if (varp == &p_debug)
7045 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007046 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007047 errmsg = e_invarg;
7048 }
7049
7050 /* 'display' */
7051 else if (varp == &p_dy)
7052 {
7053 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7054 errmsg = e_invarg;
7055 else
7056 (void)init_chartab();
7057
7058 }
7059
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007060#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007061 /* 'eadirection' */
7062 else if (varp == &p_ead)
7063 {
7064 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7065 errmsg = e_invarg;
7066 }
7067#endif
7068
7069#ifdef FEAT_CLIPBOARD
7070 /* 'clipboard' */
7071 else if (varp == &p_cb)
7072 errmsg = check_clipboard_option();
7073#endif
7074
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007075#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007076 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7077 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007078 else if (varp == &(curwin->w_s->b_p_spl)
7079 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007080 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007081 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007082 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007083 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007084 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007085 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007086 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007087 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007088 /* 'spellsuggest' */
7089 else if (varp == &p_sps)
7090 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007091 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007092 errmsg = e_invarg;
7093 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007094 /* 'mkspellmem' */
7095 else if (varp == &p_msm)
7096 {
7097 if (spell_check_msm() != OK)
7098 errmsg = e_invarg;
7099 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007100#endif
7101
Bram Moolenaar071d4272004-06-13 20:20:40 +00007102 /* When 'bufhidden' is set, check for valid value. */
7103 else if (gvarp == &p_bh)
7104 {
7105 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7106 errmsg = e_invarg;
7107 }
7108
7109 /* When 'buftype' is set, check for valid value. */
7110 else if (gvarp == &p_bt)
7111 {
7112 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7113 errmsg = e_invarg;
7114 else
7115 {
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007116#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007117 if (curwin->w_status_height)
7118 {
7119 curwin->w_redr_status = TRUE;
7120 redraw_later(VALID);
7121 }
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007122#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007123 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007124#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007125 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007127 }
7128 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129
7130#ifdef FEAT_STL_OPT
7131 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007132 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 {
7134 int wid;
7135
7136 if (varp == &p_ruf) /* reset ru_wid first */
7137 ru_wid = 0;
7138 s = *varp;
7139 if (varp == &p_ruf && *s == '%')
7140 {
7141 /* set ru_wid if 'ruf' starts with "%99(" */
7142 if (*++s == '-') /* ignore a '-' */
7143 s++;
7144 wid = getdigits(&s);
7145 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7146 ru_wid = wid;
7147 else
7148 errmsg = check_stl_option(p_ruf);
7149 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007150 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007151 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007152 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007153 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007154 comp_col();
7155 }
7156#endif
7157
7158#ifdef FEAT_INS_EXPAND
7159 /* check if it is a valid value for 'complete' -- Acevedo */
7160 else if (gvarp == &p_cpt)
7161 {
7162 for (s = *varp; *s;)
7163 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007164 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165 s++;
7166 if (!*s)
7167 break;
7168 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7169 {
7170 errmsg = illegal_char(errbuf, *s);
7171 break;
7172 }
7173 if (*++s != NUL && *s != ',' && *s != ' ')
7174 {
7175 if (s[-1] == 'k' || s[-1] == 's')
7176 {
7177 /* skip optional filename after 'k' and 's' */
7178 while (*s && *s != ',' && *s != ' ')
7179 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007180 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 ++s;
7182 ++s;
7183 }
7184 }
7185 else
7186 {
7187 if (errbuf != NULL)
7188 {
7189 sprintf((char *)errbuf,
7190 _("E535: Illegal character after <%c>"),
7191 *--s);
7192 errmsg = errbuf;
7193 }
7194 else
7195 errmsg = (char_u *)"";
7196 break;
7197 }
7198 }
7199 }
7200 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007201
7202 /* 'completeopt' */
7203 else if (varp == &p_cot)
7204 {
7205 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7206 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007207 else
7208 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007210#endif /* FEAT_INS_EXPAND */
7211
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007212#ifdef FEAT_SIGNS
7213 /* 'signcolumn' */
7214 else if (varp == &curwin->w_p_scl)
7215 {
7216 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7217 errmsg = e_invarg;
7218 }
7219#endif
7220
Bram Moolenaar071d4272004-06-13 20:20:40 +00007221
7222#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007223 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007224 else if (varp == &p_toolbar)
7225 {
7226 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7227 &toolbar_flags, TRUE) != OK)
7228 errmsg = e_invarg;
7229 else
7230 {
7231 out_flush();
7232 gui_mch_show_toolbar((toolbar_flags &
7233 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7234 }
7235 }
7236#endif
7237
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007238#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007239 /* 'toolbariconsize': GTK+ 2 only */
7240 else if (varp == &p_tbis)
7241 {
7242 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7243 errmsg = e_invarg;
7244 else
7245 {
7246 out_flush();
7247 gui_mch_show_toolbar((toolbar_flags &
7248 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7249 }
7250 }
7251#endif
7252
7253 /* 'pastetoggle': translate key codes like in a mapping */
7254 else if (varp == &p_pt)
7255 {
7256 if (*p_pt)
7257 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007258 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007259 if (p != NULL)
7260 {
7261 if (new_value_alloced)
7262 free_string_option(p_pt);
7263 p_pt = p;
7264 new_value_alloced = TRUE;
7265 }
7266 }
7267 }
7268
7269 /* 'backspace' */
7270 else if (varp == &p_bs)
7271 {
7272 if (VIM_ISDIGIT(*p_bs))
7273 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007274 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275 errmsg = e_invarg;
7276 }
7277 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7278 errmsg = e_invarg;
7279 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007280 else if (varp == &p_bo)
7281 {
7282 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7283 errmsg = e_invarg;
7284 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007286 /* 'tagcase' */
7287 else if (gvarp == &p_tc)
7288 {
7289 unsigned int *flags;
7290
7291 if (opt_flags & OPT_LOCAL)
7292 {
7293 p = curbuf->b_p_tc;
7294 flags = &curbuf->b_tc_flags;
7295 }
7296 else
7297 {
7298 p = p_tc;
7299 flags = &tc_flags;
7300 }
7301
7302 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7303 /* make the local value empty: use the global value */
7304 *flags = 0;
7305 else if (*p == NUL
7306 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7307 errmsg = e_invarg;
7308 }
7309
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007310#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 /* 'casemap' */
7312 else if (varp == &p_cmp)
7313 {
7314 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7315 errmsg = e_invarg;
7316 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007317#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007318
7319#ifdef FEAT_DIFF
7320 /* 'diffopt' */
7321 else if (varp == &p_dip)
7322 {
7323 if (diffopt_changed() == FAIL)
7324 errmsg = e_invarg;
7325 }
7326#endif
7327
7328#ifdef FEAT_FOLDING
7329 /* 'foldmethod' */
7330 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7331 {
7332 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7333 || *curwin->w_p_fdm == NUL)
7334 errmsg = e_invarg;
7335 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007336 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007337 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007338 if (foldmethodIsDiff(curwin))
7339 newFoldLevel();
7340 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007341 }
7342# ifdef FEAT_EVAL
7343 /* 'foldexpr' */
7344 else if (varp == &curwin->w_p_fde)
7345 {
7346 if (foldmethodIsExpr(curwin))
7347 foldUpdateAll(curwin);
7348 }
7349# endif
7350 /* 'foldmarker' */
7351 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7352 {
7353 p = vim_strchr(*varp, ',');
7354 if (p == NULL)
7355 errmsg = (char_u *)N_("E536: comma required");
7356 else if (p == *varp || p[1] == NUL)
7357 errmsg = e_invarg;
7358 else if (foldmethodIsMarker(curwin))
7359 foldUpdateAll(curwin);
7360 }
7361 /* 'commentstring' */
7362 else if (gvarp == &p_cms)
7363 {
7364 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7365 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7366 }
7367 /* 'foldopen' */
7368 else if (varp == &p_fdo)
7369 {
7370 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7371 errmsg = e_invarg;
7372 }
7373 /* 'foldclose' */
7374 else if (varp == &p_fcl)
7375 {
7376 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7377 errmsg = e_invarg;
7378 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007379 /* 'foldignore' */
7380 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7381 {
7382 if (foldmethodIsIndent(curwin))
7383 foldUpdateAll(curwin);
7384 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007385#endif
7386
7387#ifdef FEAT_VIRTUALEDIT
7388 /* 'virtualedit' */
7389 else if (varp == &p_ve)
7390 {
7391 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7392 errmsg = e_invarg;
7393 else if (STRCMP(p_ve, oldval) != 0)
7394 {
7395 /* Recompute cursor position in case the new 've' setting
7396 * changes something. */
7397 validate_virtcol();
7398 coladvance(curwin->w_virtcol);
7399 }
7400 }
7401#endif
7402
7403#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7404 else if (varp == &p_csqf)
7405 {
7406 if (p_csqf != NULL)
7407 {
7408 p = p_csqf;
7409 while (*p != NUL)
7410 {
7411 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7412 || p[1] == NUL
7413 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7414 || (p[2] != NUL && p[2] != ','))
7415 {
7416 errmsg = e_invarg;
7417 break;
7418 }
7419 else if (p[2] == NUL)
7420 break;
7421 else
7422 p += 3;
7423 }
7424 }
7425 }
7426#endif
7427
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007428#ifdef FEAT_CINDENT
7429 /* 'cinoptions' */
7430 else if (gvarp == &p_cino)
7431 {
7432 /* TODO: recognize errors */
7433 parse_cino(curbuf);
7434 }
7435#endif
7436
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007437#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007438 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007439 else if (varp == &p_rop && gui.in_use)
7440 {
7441 if (!gui_mch_set_rendering_options(p_rop))
7442 errmsg = e_invarg;
7443 }
7444#endif
7445
Bram Moolenaard0b51382016-11-04 15:23:45 +01007446#ifdef FEAT_AUTOCMD
7447 else if (gvarp == &p_ft)
7448 {
7449 if (!valid_filetype(*varp))
7450 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007451 else
7452 ft_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaard0b51382016-11-04 15:23:45 +01007453 }
7454#endif
7455
7456#ifdef FEAT_SYN_HL
7457 else if (gvarp == &p_syn)
7458 {
7459 if (!valid_filetype(*varp))
7460 errmsg = e_invarg;
7461 }
7462#endif
7463
Bram Moolenaar825680f2017-07-22 17:04:02 +02007464#ifdef FEAT_TERMINAL
7465 /* 'termsize' */
7466 else if (varp == &curwin->w_p_tms)
7467 {
7468 if (*curwin->w_p_tms != NUL)
7469 {
7470 p = skipdigits(curwin->w_p_tms);
7471 if (p == curwin->w_p_tms || *p != 'x' || *skipdigits(p + 1) != NUL)
7472 errmsg = e_invarg;
7473 }
7474 }
7475#endif
7476
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477 /* Options that are a list of flags. */
7478 else
7479 {
7480 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007481 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007483 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007484 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007485 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007486 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007487 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007488 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007489#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007490 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007491 p = (char_u *)COCU_ALL;
7492#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007493 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007494 {
7495#ifdef FEAT_MOUSE
7496 p = (char_u *)MOUSE_ALL;
7497#else
7498 if (*p_mouse != NUL)
7499 errmsg = (char_u *)N_("E538: No mouse support");
7500#endif
7501 }
7502#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007503 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007504 p = (char_u *)GO_ALL;
7505#endif
7506 if (p != NULL)
7507 {
7508 for (s = *varp; *s; ++s)
7509 if (vim_strchr(p, *s) == NULL)
7510 {
7511 errmsg = illegal_char(errbuf, *s);
7512 break;
7513 }
7514 }
7515 }
7516
7517 /*
7518 * If error detected, restore the previous value.
7519 */
7520 if (errmsg != NULL)
7521 {
7522 if (new_value_alloced)
7523 free_string_option(*varp);
7524 *varp = oldval;
7525 /*
7526 * When resetting some values, need to act on it.
7527 */
7528 if (did_chartab)
7529 (void)init_chartab();
7530 if (varp == &p_hl)
7531 (void)highlight_changed();
7532 }
7533 else
7534 {
7535#ifdef FEAT_EVAL
7536 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007537 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007538#endif
7539 /*
7540 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007541 * Use "free_oldval", because recursiveness may change the flags under
7542 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007544 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007545 free_string_option(oldval);
7546 if (new_value_alloced)
7547 options[opt_idx].flags |= P_ALLOCED;
7548 else
7549 options[opt_idx].flags &= ~P_ALLOCED;
7550
7551 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007552 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007553 {
7554 /* global option with local value set to use global value; free
7555 * the local value and make it empty */
7556 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7557 free_string_option(*(char_u **)p);
7558 *(char_u **)p = empty_option;
7559 }
7560
7561 /* May set global value for local option. */
7562 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7563 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007564
7565#ifdef FEAT_AUTOCMD
7566 /*
7567 * Trigger the autocommand only after setting the flags.
7568 */
7569# ifdef FEAT_SYN_HL
7570 /* When 'syntax' is set, load the syntax of that name */
7571 if (varp == &(curbuf->b_p_syn))
7572 {
7573 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7574 curbuf->b_fname, TRUE, curbuf);
7575 }
7576# endif
7577 else if (varp == &(curbuf->b_p_ft))
7578 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007579 /* 'filetype' is set, trigger the FileType autocommand.
7580 * Skip this when called from a modeline and the filetype was
7581 * already set to this value. */
7582 if (!(opt_flags & OPT_MODELINE) || ft_changed)
7583 {
7584 did_filetype = TRUE;
7585 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007586 curbuf->b_fname, TRUE, curbuf);
Bram Moolenaar163095f2017-07-09 15:41:53 +02007587 /* Just in case the old "curbuf" is now invalid. */
7588 if (varp != &(curbuf->b_p_ft))
7589 varp = NULL;
Bram Moolenaar90492982017-06-22 14:16:31 +02007590 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007591 }
7592#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007593#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007594 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007595 {
7596 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007597 char_u *q = curwin->w_s->b_p_spl;
7598
7599 /* Skip the first name if it is "cjk". */
7600 if (STRNCMP(q, "cjk,", 4) == 0)
7601 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007602
7603 /*
7604 * Source the spell/LANG.vim in 'runtimepath'.
7605 * They could set 'spellcapcheck' depending on the language.
7606 * Use the first name in 'spelllang' up to '_region' or
7607 * '.encoding'.
7608 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007609 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007610 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7611 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007612 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007613 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007614 }
7615#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007616 }
7617
7618#ifdef FEAT_MOUSE
7619 if (varp == &p_mouse)
7620 {
7621# ifdef FEAT_MOUSE_TTY
7622 if (*p_mouse == NUL)
7623 mch_setmouse(FALSE); /* switch mouse off */
7624 else
7625# endif
7626 setmouse(); /* in case 'mouse' changed */
7627 }
7628#endif
7629
Bram Moolenaar913077c2012-03-28 19:59:04 +02007630 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007631 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007632 curwin->w_set_curswant = TRUE;
7633
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007634#ifdef FEAT_GUI
7635 /* check redraw when it's not a GUI option or the GUI is active. */
7636 if (!redraw_gui_only || gui.in_use)
7637#endif
7638 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007639
7640 return errmsg;
7641}
7642
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007643#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007644/*
7645 * Simple int comparison function for use with qsort()
7646 */
7647 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007648int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007649{
7650 return *(const int *)a - *(const int *)b;
7651}
7652
7653/*
7654 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7655 * Returns error message, NULL if it's OK.
7656 */
7657 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007658check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007659{
7660 char_u *s;
7661 int col;
7662 int count = 0;
7663 int color_cols[256];
7664 int i;
7665 int j = 0;
7666
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007667 if (wp->w_buffer == NULL)
7668 return NULL; /* buffer was closed */
7669
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007670 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007671 {
7672 if (*s == '-' || *s == '+')
7673 {
7674 /* -N and +N: add to 'textwidth' */
7675 col = (*s == '-') ? -1 : 1;
7676 ++s;
7677 if (!VIM_ISDIGIT(*s))
7678 return e_invarg;
7679 col = col * getdigits(&s);
7680 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007681 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007682 col += wp->w_buffer->b_p_tw;
7683 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007684 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007685 }
7686 else if (VIM_ISDIGIT(*s))
7687 col = getdigits(&s);
7688 else
7689 return e_invarg;
7690 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007691skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007692 if (*s == NUL)
7693 break;
7694 if (*s != ',')
7695 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007696 if (*++s == NUL)
7697 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007698 }
7699
7700 vim_free(wp->w_p_cc_cols);
7701 if (count == 0)
7702 wp->w_p_cc_cols = NULL;
7703 else
7704 {
7705 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7706 if (wp->w_p_cc_cols != NULL)
7707 {
7708 /* sort the columns for faster usage on screen redraw inside
7709 * win_line() */
7710 qsort(color_cols, count, sizeof(int), int_cmp);
7711
7712 for (i = 0; i < count; ++i)
7713 /* skip duplicates */
7714 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7715 wp->w_p_cc_cols[j++] = color_cols[i];
7716 wp->w_p_cc_cols[j] = -1; /* end marker */
7717 }
7718 }
7719
7720 return NULL; /* no error */
7721}
7722#endif
7723
Bram Moolenaar071d4272004-06-13 20:20:40 +00007724/*
7725 * Handle setting 'listchars' or 'fillchars'.
7726 * Returns error message, NULL if it's OK.
7727 */
7728 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007729set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007730{
7731 int round, i, len, entries;
7732 char_u *p, *s;
7733 int c1, c2 = 0;
7734 struct charstab
7735 {
7736 int *cp;
7737 char *name;
7738 };
7739#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7740 static struct charstab filltab[] =
7741 {
7742 {&fill_stl, "stl"},
7743 {&fill_stlnc, "stlnc"},
7744 {&fill_vert, "vert"},
7745 {&fill_fold, "fold"},
7746 {&fill_diff, "diff"},
7747 };
7748#endif
7749 static struct charstab lcstab[] =
7750 {
7751 {&lcs_eol, "eol"},
7752 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007753 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007754 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007755 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007756 {&lcs_tab2, "tab"},
7757 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007758#ifdef FEAT_CONCEAL
7759 {&lcs_conceal, "conceal"},
7760#else
7761 {NULL, "conceal"},
7762#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763 };
7764 struct charstab *tab;
7765
7766#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7767 if (varp == &p_lcs)
7768#endif
7769 {
7770 tab = lcstab;
7771 entries = sizeof(lcstab) / sizeof(struct charstab);
7772 }
7773#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7774 else
7775 {
7776 tab = filltab;
7777 entries = sizeof(filltab) / sizeof(struct charstab);
7778 }
7779#endif
7780
7781 /* first round: check for valid value, second round: assign values */
7782 for (round = 0; round <= 1; ++round)
7783 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007784 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785 {
7786 /* After checking that the value is valid: set defaults: space for
7787 * 'fillchars', NUL for 'listchars' */
7788 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007789 if (tab[i].cp != NULL)
7790 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 if (varp == &p_lcs)
7792 lcs_tab1 = NUL;
7793#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7794 else
7795 fill_diff = '-';
7796#endif
7797 }
7798 p = *varp;
7799 while (*p)
7800 {
7801 for (i = 0; i < entries; ++i)
7802 {
7803 len = (int)STRLEN(tab[i].name);
7804 if (STRNCMP(p, tab[i].name, len) == 0
7805 && p[len] == ':'
7806 && p[len + 1] != NUL)
7807 {
7808 s = p + len + 1;
7809#ifdef FEAT_MBYTE
7810 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007811 if (mb_char2cells(c1) > 1)
7812 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007813#else
7814 c1 = *s++;
7815#endif
7816 if (tab[i].cp == &lcs_tab2)
7817 {
7818 if (*s == NUL)
7819 continue;
7820#ifdef FEAT_MBYTE
7821 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007822 if (mb_char2cells(c2) > 1)
7823 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007824#else
7825 c2 = *s++;
7826#endif
7827 }
7828 if (*s == ',' || *s == NUL)
7829 {
7830 if (round)
7831 {
7832 if (tab[i].cp == &lcs_tab2)
7833 {
7834 lcs_tab1 = c1;
7835 lcs_tab2 = c2;
7836 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007837 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007838 *(tab[i].cp) = c1;
7839
7840 }
7841 p = s;
7842 break;
7843 }
7844 }
7845 }
7846
7847 if (i == entries)
7848 return e_invarg;
7849 if (*p == ',')
7850 ++p;
7851 }
7852 }
7853
7854 return NULL; /* no error */
7855}
7856
7857#ifdef FEAT_STL_OPT
7858/*
7859 * Check validity of options with the 'statusline' format.
7860 * Return error message or NULL.
7861 */
7862 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007863check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864{
7865 int itemcnt = 0;
7866 int groupdepth = 0;
7867 static char_u errbuf[80];
7868
7869 while (*s && itemcnt < STL_MAX_ITEM)
7870 {
7871 /* Check for valid keys after % sequences */
7872 while (*s && *s != '%')
7873 s++;
7874 if (!*s)
7875 break;
7876 s++;
7877 if (*s != '%' && *s != ')')
7878 ++itemcnt;
7879 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7880 {
7881 s++;
7882 continue;
7883 }
7884 if (*s == ')')
7885 {
7886 s++;
7887 if (--groupdepth < 0)
7888 break;
7889 continue;
7890 }
7891 if (*s == '-')
7892 s++;
7893 while (VIM_ISDIGIT(*s))
7894 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007895 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007896 continue;
7897 if (*s == '.')
7898 {
7899 s++;
7900 while (*s && VIM_ISDIGIT(*s))
7901 s++;
7902 }
7903 if (*s == '(')
7904 {
7905 groupdepth++;
7906 continue;
7907 }
7908 if (vim_strchr(STL_ALL, *s) == NULL)
7909 {
7910 return illegal_char(errbuf, *s);
7911 }
7912 if (*s == '{')
7913 {
7914 s++;
7915 while (*s != '}' && *s)
7916 s++;
7917 if (*s != '}')
7918 return (char_u *)N_("E540: Unclosed expression sequence");
7919 }
7920 }
7921 if (itemcnt >= STL_MAX_ITEM)
7922 return (char_u *)N_("E541: too many items");
7923 if (groupdepth != 0)
7924 return (char_u *)N_("E542: unbalanced groups");
7925 return NULL;
7926}
7927#endif
7928
7929#ifdef FEAT_CLIPBOARD
7930/*
7931 * Extract the items in the 'clipboard' option and set global values.
7932 */
7933 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007934check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007936 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007937 int new_autoselect_star = FALSE;
7938 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007940 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007941 regprog_T *new_exclude_prog = NULL;
7942 char_u *errmsg = NULL;
7943 char_u *p;
7944
7945 for (p = p_cb; *p != NUL; )
7946 {
7947 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7948 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007949 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007950 p += 7;
7951 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007952 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007953 && (p[11] == ',' || p[11] == NUL))
7954 {
7955 new_unnamed |= CLIP_UNNAMED_PLUS;
7956 p += 11;
7957 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007959 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007960 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007961 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007962 p += 10;
7963 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007964 else if (STRNCMP(p, "autoselectplus", 14) == 0
7965 && (p[14] == ',' || p[14] == NUL))
7966 {
7967 new_autoselect_plus = TRUE;
7968 p += 14;
7969 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007970 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007971 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 {
7973 new_autoselectml = TRUE;
7974 p += 12;
7975 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007976 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7977 {
7978 new_html = TRUE;
7979 p += 4;
7980 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7982 {
7983 p += 8;
7984 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7985 if (new_exclude_prog == NULL)
7986 errmsg = e_invarg;
7987 break;
7988 }
7989 else
7990 {
7991 errmsg = e_invarg;
7992 break;
7993 }
7994 if (*p == ',')
7995 ++p;
7996 }
7997 if (errmsg == NULL)
7998 {
7999 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008000 clip_autoselect_star = new_autoselect_star;
8001 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008003 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008004 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008005 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008006#ifdef FEAT_GUI_GTK
8007 if (gui.in_use)
8008 {
8009 gui_gtk_set_selection_targets();
8010 gui_gtk_set_dnd_targets();
8011 }
8012#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013 }
8014 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008015 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016
8017 return errmsg;
8018}
8019#endif
8020
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008021#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008022 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008023did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008024{
8025 char_u *errmsg = NULL;
8026 win_T *wp;
8027 int l;
8028
8029 if (is_spellfile)
8030 {
8031 l = (int)STRLEN(curwin->w_s->b_p_spf);
8032 if (l > 0 && (l < 4
8033 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8034 errmsg = e_invarg;
8035 }
8036
8037 if (errmsg == NULL)
8038 {
8039 FOR_ALL_WINDOWS(wp)
8040 if (wp->w_buffer == curbuf && wp->w_p_spell)
8041 {
8042 errmsg = did_set_spelllang(wp);
8043# ifdef FEAT_WINDOWS
8044 break;
8045# endif
8046 }
8047 }
8048 return errmsg;
8049}
8050
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008051/*
8052 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8053 * Return error message when failed, NULL when OK.
8054 */
8055 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008056compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008057{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008058 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008059 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008060
Bram Moolenaar860cae12010-06-05 23:22:07 +02008061 if (*synblock->b_p_spc == NUL)
8062 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008063 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008064 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008065 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008066 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008067 if (re != NULL)
8068 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008069 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008070 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008071 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008072 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008073 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008074 return e_invarg;
8075 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008076 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008077 }
8078
Bram Moolenaar473de612013-06-08 18:19:48 +02008079 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008080 return NULL;
8081}
8082#endif
8083
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008084#if defined(FEAT_EVAL) || defined(PROTO)
8085/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008086 * Set the scriptID for an option, taking care of setting the buffer- or
8087 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008088 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008089 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008090set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008091{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008092 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8093 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008094
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008095 /* Remember where the option was set. For local options need to do that
8096 * in the buffer or window structure. */
8097 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008098 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008099 if (both || (opt_flags & OPT_LOCAL))
8100 {
8101 if (indir & PV_BUF)
8102 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8103 else if (indir & PV_WIN)
8104 curwin->w_p_scriptID[indir & PV_MASK] = id;
8105 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008106}
8107#endif
8108
Bram Moolenaar071d4272004-06-13 20:20:40 +00008109/*
8110 * Set the value of a boolean option, and take care of side effects.
8111 * Returns NULL for success, or an error message for an error.
8112 */
8113 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008114set_bool_option(
8115 int opt_idx, /* index in options[] table */
8116 char_u *varp, /* pointer to the option variable */
8117 int value, /* new value */
8118 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008119{
8120 int old_value = *(int *)varp;
8121
Bram Moolenaar071d4272004-06-13 20:20:40 +00008122 /* Disallow changing some options from secure mode */
8123 if ((secure
8124#ifdef HAVE_SANDBOX
8125 || sandbox != 0
8126#endif
8127 ) && (options[opt_idx].flags & P_SECURE))
8128 return e_secure;
8129
8130 *(int *)varp = value; /* set the new value */
8131#ifdef FEAT_EVAL
8132 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008133 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008134#endif
8135
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008136#ifdef FEAT_GUI
8137 need_mouse_correct = TRUE;
8138#endif
8139
Bram Moolenaar071d4272004-06-13 20:20:40 +00008140 /* May set global value for local option. */
8141 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8142 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8143
8144 /*
8145 * Handle side effects of changing a bool option.
8146 */
8147
8148 /* 'compatible' */
8149 if ((int *)varp == &p_cp)
8150 {
8151 compatible_set();
8152 }
8153
Bram Moolenaar920694c2016-08-21 17:45:02 +02008154#ifdef FEAT_LANGMAP
8155 if ((int *)varp == &p_lrm)
8156 /* 'langremap' -> !'langnoremap' */
8157 p_lnr = !p_lrm;
8158 else if ((int *)varp == &p_lnr)
8159 /* 'langnoremap' -> !'langremap' */
8160 p_lrm = !p_lnr;
8161#endif
8162
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008163#ifdef FEAT_PERSISTENT_UNDO
8164 /* 'undofile' */
8165 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8166 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008167 /* Only take action when the option was set. When reset we do not
8168 * delete the undo file, the option may be set again without making
8169 * any changes in between. */
8170 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008171 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008172 char_u hash[UNDO_HASH_SIZE];
8173 buf_T *save_curbuf = curbuf;
8174
Bram Moolenaar29323592016-07-24 22:04:11 +02008175 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008176 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008177 /* When 'undofile' is set globally: for every buffer, otherwise
8178 * only for the current buffer: Try to read in the undofile,
8179 * if one exists, the buffer wasn't changed and the buffer was
8180 * loaded */
8181 if ((curbuf == save_curbuf
8182 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8183 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8184 {
8185 u_compute_hash(hash);
8186 u_read_undo(NULL, hash, curbuf->b_fname);
8187 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008188 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008189 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008190 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008191 }
8192#endif
8193
Bram Moolenaar071d4272004-06-13 20:20:40 +00008194 else if ((int *)varp == &curbuf->b_p_ro)
8195 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008196 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8198 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008199
8200 /* when 'readonly' is set may give W10 again */
8201 if (curbuf->b_p_ro)
8202 curbuf->b_did_warn = FALSE;
8203
Bram Moolenaar071d4272004-06-13 20:20:40 +00008204#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008205 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008206#endif
8207 }
8208
Bram Moolenaar9c449722010-07-20 18:44:27 +02008209#ifdef FEAT_GUI
8210 else if ((int *)varp == &p_mh)
8211 {
8212 if (!p_mh)
8213 gui_mch_mousehide(FALSE);
8214 }
8215#endif
8216
Bram Moolenaara539df02010-08-01 14:35:05 +02008217#ifdef FEAT_TITLE
8218 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008219 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008220 {
8221 redraw_titles();
8222 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008223 /* when 'endofline' is changed, redraw the window title */
8224 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008225 {
8226 redraw_titles();
8227 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008228 /* when 'fixeol' is changed, redraw the window title */
8229 else if ((int *)varp == &curbuf->b_p_fixeol)
8230 {
8231 redraw_titles();
8232 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008233# ifdef FEAT_MBYTE
8234 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008235 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008236 {
8237 redraw_titles();
8238 }
8239# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008240#endif
8241
8242 /* when 'bin' is set also set some other options */
8243 else if ((int *)varp == &curbuf->b_p_bin)
8244 {
8245 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8246#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008247 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008248#endif
8249 }
8250
8251#ifdef FEAT_AUTOCMD
8252 /* when 'buflisted' changes, trigger autocommands */
8253 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8254 {
8255 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8256 NULL, NULL, TRUE, curbuf);
8257 }
8258#endif
8259
8260 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8261 else if ((int *)varp == &curbuf->b_p_swf)
8262 {
8263 if (curbuf->b_p_swf && p_uc)
8264 ml_open_file(curbuf); /* create the swap file */
8265 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008266 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8267 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268 mf_close_file(curbuf, TRUE); /* remove the swap file */
8269 }
8270
8271 /* when 'terse' is set change 'shortmess' */
8272 else if ((int *)varp == &p_terse)
8273 {
8274 char_u *p;
8275
8276 p = vim_strchr(p_shm, SHM_SEARCH);
8277
8278 /* insert 's' in p_shm */
8279 if (p_terse && p == NULL)
8280 {
8281 STRCPY(IObuff, p_shm);
8282 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008283 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284 }
8285 /* remove 's' from p_shm */
8286 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008287 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008288 }
8289
8290 /* when 'paste' is set or reset also change other options */
8291 else if ((int *)varp == &p_paste)
8292 {
8293 paste_option_changed();
8294 }
8295
8296 /* when 'insertmode' is set from an autocommand need to do work here */
8297 else if ((int *)varp == &p_im)
8298 {
8299 if (p_im)
8300 {
8301 if ((State & INSERT) == 0)
8302 need_start_insertmode = TRUE;
8303 stop_insert_mode = FALSE;
8304 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008305 /* only reset if it was set previously */
8306 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008307 {
8308 need_start_insertmode = FALSE;
8309 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008310 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008311 clear_cmdline = TRUE; /* remove "(insert)" */
8312 restart_edit = 0;
8313 }
8314 }
8315
8316 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8317 else if ((int *)varp == &p_ic && p_hls)
8318 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008319 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 }
8321
8322#ifdef FEAT_SEARCH_EXTRA
8323 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8324 else if ((int *)varp == &p_hls)
8325 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008326 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008327 }
8328#endif
8329
8330#ifdef FEAT_SCROLLBIND
8331 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8332 * at the end of normal_cmd() */
8333 else if ((int *)varp == &curwin->w_p_scb)
8334 {
8335 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008336 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008337 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008338 curwin->w_scbind_pos = curwin->w_topline;
8339 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008340 }
8341#endif
8342
8343#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8344 /* There can be only one window with 'previewwindow' set. */
8345 else if ((int *)varp == &curwin->w_p_pvw)
8346 {
8347 if (curwin->w_p_pvw)
8348 {
8349 win_T *win;
8350
Bram Moolenaar29323592016-07-24 22:04:11 +02008351 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352 if (win->w_p_pvw && win != curwin)
8353 {
8354 curwin->w_p_pvw = FALSE;
8355 return (char_u *)N_("E590: A preview window already exists");
8356 }
8357 }
8358 }
8359#endif
8360
8361 /* when 'textmode' is set or reset also change 'fileformat' */
8362 else if ((int *)varp == &curbuf->b_p_tx)
8363 {
8364 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8365 }
8366
8367 /* when 'textauto' is set or reset also change 'fileformats' */
8368 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008369 set_string_option_direct((char_u *)"ffs", -1,
8370 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008371 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372
8373 /*
8374 * When 'lisp' option changes include/exclude '-' in
8375 * keyword characters.
8376 */
8377#ifdef FEAT_LISP
8378 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8379 {
8380 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8381 }
8382#endif
8383
8384#ifdef FEAT_TITLE
8385 /* when 'title' changed, may need to change the title; same for 'icon' */
8386 else if ((int *)varp == &p_title)
8387 {
8388 did_set_title(FALSE);
8389 }
8390
8391 else if ((int *)varp == &p_icon)
8392 {
8393 did_set_title(TRUE);
8394 }
8395#endif
8396
8397 else if ((int *)varp == &curbuf->b_changed)
8398 {
8399 if (!value)
8400 save_file_ff(curbuf); /* Buffer is unchanged */
8401#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008402 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403#endif
8404#ifdef FEAT_AUTOCMD
8405 modified_was_set = value;
8406#endif
8407 }
8408
8409#ifdef BACKSLASH_IN_FILENAME
8410 else if ((int *)varp == &p_ssl)
8411 {
8412 if (p_ssl)
8413 {
8414 psepc = '/';
8415 psepcN = '\\';
8416 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008417 }
8418 else
8419 {
8420 psepc = '\\';
8421 psepcN = '/';
8422 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423 }
8424
8425 /* need to adjust the file name arguments and buffer names. */
8426 buflist_slash_adjust();
8427 alist_slash_adjust();
8428# ifdef FEAT_EVAL
8429 scriptnames_slash_adjust();
8430# endif
8431 }
8432#endif
8433
8434 /* If 'wrap' is set, set w_leftcol to zero. */
8435 else if ((int *)varp == &curwin->w_p_wrap)
8436 {
8437 if (curwin->w_p_wrap)
8438 curwin->w_leftcol = 0;
8439 }
8440
8441#ifdef FEAT_WINDOWS
8442 else if ((int *)varp == &p_ea)
8443 {
8444 if (p_ea && !old_value)
8445 win_equal(curwin, FALSE, 0);
8446 }
8447#endif
8448
8449 else if ((int *)varp == &p_wiv)
8450 {
8451 /*
8452 * When 'weirdinvert' changed, set/reset 't_xs'.
8453 * Then set 'weirdinvert' according to value of 't_xs'.
8454 */
8455 if (p_wiv && !old_value)
8456 T_XS = (char_u *)"y";
8457 else if (!p_wiv && old_value)
8458 T_XS = empty_option;
8459 p_wiv = (*T_XS != NUL);
8460 }
8461
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008462#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008463 else if ((int *)varp == &p_beval)
8464 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008465 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008467 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008468 gui_mch_disable_beval_area(balloonEval);
8469 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008470#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008472#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 else if ((int *)varp == &p_acd)
8474 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008475 /* Change directories when the 'acd' option is set now. */
8476 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477 }
8478#endif
8479
8480#ifdef FEAT_DIFF
8481 /* 'diff' */
8482 else if ((int *)varp == &curwin->w_p_diff)
8483 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008484 /* May add or remove the buffer from the list of diff buffers. */
8485 diff_buf_adjust(curwin);
8486# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008487 if (foldmethodIsDiff(curwin))
8488 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008489# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008490 }
8491#endif
8492
8493#ifdef USE_IM_CONTROL
8494 /* 'imdisable' */
8495 else if ((int *)varp == &p_imdisable)
8496 {
8497 /* Only de-activate it here, it will be enabled when changing mode. */
8498 if (p_imdisable)
8499 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008500 else if (State & INSERT)
8501 /* When the option is set from an autocommand, it may need to take
8502 * effect right away. */
8503 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008504 }
8505#endif
8506
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008507#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008508 /* 'spell' */
8509 else if ((int *)varp == &curwin->w_p_spell)
8510 {
8511 if (curwin->w_p_spell)
8512 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008513 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008514 if (errmsg != NULL)
8515 EMSG(_(errmsg));
8516 }
8517 }
8518#endif
8519
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520#ifdef FEAT_FKMAP
8521 else if ((int *)varp == &p_altkeymap)
8522 {
8523 if (old_value != p_altkeymap)
8524 {
8525 if (!p_altkeymap)
8526 {
8527 p_hkmap = p_fkmap;
8528 p_fkmap = 0;
8529 }
8530 else
8531 {
8532 p_fkmap = p_hkmap;
8533 p_hkmap = 0;
8534 }
8535 (void)init_chartab();
8536 }
8537 }
8538
8539 /*
8540 * In case some second language keymapping options have changed, check
8541 * and correct the setting in a consistent way.
8542 */
8543
8544 /*
8545 * If hkmap or fkmap are set, reset Arabic keymapping.
8546 */
8547 if ((p_hkmap || p_fkmap) && p_altkeymap)
8548 {
8549 p_altkeymap = p_fkmap;
8550# ifdef FEAT_ARABIC
8551 curwin->w_p_arab = FALSE;
8552# endif
8553 (void)init_chartab();
8554 }
8555
8556 /*
8557 * If hkmap set, reset Farsi keymapping.
8558 */
8559 if (p_hkmap && p_altkeymap)
8560 {
8561 p_altkeymap = 0;
8562 p_fkmap = 0;
8563# ifdef FEAT_ARABIC
8564 curwin->w_p_arab = FALSE;
8565# endif
8566 (void)init_chartab();
8567 }
8568
8569 /*
8570 * If fkmap set, reset Hebrew keymapping.
8571 */
8572 if (p_fkmap && !p_altkeymap)
8573 {
8574 p_altkeymap = 1;
8575 p_hkmap = 0;
8576# ifdef FEAT_ARABIC
8577 curwin->w_p_arab = FALSE;
8578# endif
8579 (void)init_chartab();
8580 }
8581#endif
8582
8583#ifdef FEAT_ARABIC
8584 if ((int *)varp == &curwin->w_p_arab)
8585 {
8586 if (curwin->w_p_arab)
8587 {
8588 /*
8589 * 'arabic' is set, handle various sub-settings.
8590 */
8591 if (!p_tbidi)
8592 {
8593 /* set rightleft mode */
8594 if (!curwin->w_p_rl)
8595 {
8596 curwin->w_p_rl = TRUE;
8597 changed_window_setting();
8598 }
8599
8600 /* Enable Arabic shaping (major part of what Arabic requires) */
8601 if (!p_arshape)
8602 {
8603 p_arshape = TRUE;
8604 redraw_later_clear();
8605 }
8606 }
8607
8608 /* Arabic requires a utf-8 encoding, inform the user if its not
8609 * set. */
8610 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008611 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008612 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8613
Bram Moolenaar8820b482017-03-16 17:23:31 +01008614 msg_source(HL_ATTR(HLF_W));
8615 MSG_ATTR(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008616#ifdef FEAT_EVAL
8617 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8618#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008619 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008620
8621# ifdef FEAT_MBYTE
8622 /* set 'delcombine' */
8623 p_deco = TRUE;
8624# endif
8625
8626# ifdef FEAT_KEYMAP
8627 /* Force-set the necessary keymap for arabic */
8628 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8629 OPT_LOCAL);
8630# endif
8631# ifdef FEAT_FKMAP
8632 p_altkeymap = 0;
8633 p_hkmap = 0;
8634 p_fkmap = 0;
8635 (void)init_chartab();
8636# endif
8637 }
8638 else
8639 {
8640 /*
8641 * 'arabic' is reset, handle various sub-settings.
8642 */
8643 if (!p_tbidi)
8644 {
8645 /* reset rightleft mode */
8646 if (curwin->w_p_rl)
8647 {
8648 curwin->w_p_rl = FALSE;
8649 changed_window_setting();
8650 }
8651
8652 /* 'arabicshape' isn't reset, it is a global option and
8653 * another window may still need it "on". */
8654 }
8655
8656 /* 'delcombine' isn't reset, it is a global option and another
8657 * window may still want it "on". */
8658
8659# ifdef FEAT_KEYMAP
8660 /* Revert to the default keymap */
8661 curbuf->b_p_iminsert = B_IMODE_NONE;
8662 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8663# endif
8664 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008665 }
8666
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008667#endif
8668
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008669#ifdef FEAT_TERMGUICOLORS
8670 /* 'termguicolors' */
8671 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008672 {
8673# ifdef FEAT_GUI
8674 if (!gui.in_use && !gui.starting)
8675# endif
8676 highlight_gui_started();
8677 }
8678#endif
8679
Bram Moolenaar071d4272004-06-13 20:20:40 +00008680 /*
8681 * End of handling side effects for bool options.
8682 */
8683
Bram Moolenaar53744302015-07-17 17:38:22 +02008684 /* after handling side effects, call autocommand */
8685
Bram Moolenaar071d4272004-06-13 20:20:40 +00008686 options[opt_idx].flags |= P_WAS_SET;
8687
Bram Moolenaar53744302015-07-17 17:38:22 +02008688#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8689 if (!starting)
8690 {
8691 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008692 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8693 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8694 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008695 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8696 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8697 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8698 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8699 reset_v_option_vars();
8700 }
8701#endif
8702
Bram Moolenaar071d4272004-06-13 20:20:40 +00008703 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008704 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008705 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008706 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008707 check_redraw(options[opt_idx].flags);
8708
8709 return NULL;
8710}
8711
8712/*
8713 * Set the value of a number option, and take care of side effects.
8714 * Returns NULL for success, or an error message for an error.
8715 */
8716 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008717set_num_option(
8718 int opt_idx, /* index in options[] table */
8719 char_u *varp, /* pointer to the option variable */
8720 long value, /* new value */
8721 char_u *errbuf, /* buffer for error messages */
8722 size_t errbuflen, /* length of "errbuf" */
8723 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008724 OPT_MODELINE */
8725{
8726 char_u *errmsg = NULL;
8727 long old_value = *(long *)varp;
8728 long old_Rows = Rows; /* remember old Rows */
8729 long old_Columns = Columns; /* remember old Columns */
8730 long *pp = (long *)varp;
8731
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008732 /* Disallow changing some options from secure mode. */
8733 if ((secure
8734#ifdef HAVE_SANDBOX
8735 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008736#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008737 ) && (options[opt_idx].flags & P_SECURE))
8738 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008739
8740 *pp = value;
8741#ifdef FEAT_EVAL
8742 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008743 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008744#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008745#ifdef FEAT_GUI
8746 need_mouse_correct = TRUE;
8747#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008748
Bram Moolenaar14f24742012-08-08 18:01:05 +02008749 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750 {
8751 errmsg = e_positive;
8752 curbuf->b_p_sw = curbuf->b_p_ts;
8753 }
8754
8755 /*
8756 * Number options that need some action when changed
8757 */
8758#ifdef FEAT_WINDOWS
8759 if (pp == &p_wh || pp == &p_hh)
8760 {
8761 if (p_wh < 1)
8762 {
8763 errmsg = e_positive;
8764 p_wh = 1;
8765 }
8766 if (p_wmh > p_wh)
8767 {
8768 errmsg = e_winheight;
8769 p_wh = p_wmh;
8770 }
8771 if (p_hh < 0)
8772 {
8773 errmsg = e_positive;
8774 p_hh = 0;
8775 }
8776
8777 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008778 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008779 {
8780 if (pp == &p_wh && curwin->w_height < p_wh)
8781 win_setheight((int)p_wh);
8782 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8783 win_setheight((int)p_hh);
8784 }
8785 }
8786
8787 /* 'winminheight' */
8788 else if (pp == &p_wmh)
8789 {
8790 if (p_wmh < 0)
8791 {
8792 errmsg = e_positive;
8793 p_wmh = 0;
8794 }
8795 if (p_wmh > p_wh)
8796 {
8797 errmsg = e_winheight;
8798 p_wmh = p_wh;
8799 }
8800 win_setminheight();
8801 }
8802
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008803# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008804 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008805 {
8806 if (p_wiw < 1)
8807 {
8808 errmsg = e_positive;
8809 p_wiw = 1;
8810 }
8811 if (p_wmw > p_wiw)
8812 {
8813 errmsg = e_winwidth;
8814 p_wiw = p_wmw;
8815 }
8816
8817 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008818 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008819 win_setwidth((int)p_wiw);
8820 }
8821
8822 /* 'winminwidth' */
8823 else if (pp == &p_wmw)
8824 {
8825 if (p_wmw < 0)
8826 {
8827 errmsg = e_positive;
8828 p_wmw = 0;
8829 }
8830 if (p_wmw > p_wiw)
8831 {
8832 errmsg = e_winwidth;
8833 p_wmw = p_wiw;
8834 }
8835 win_setminheight();
8836 }
8837# endif
8838
8839#endif
8840
8841#ifdef FEAT_WINDOWS
8842 /* (re)set last window status line */
8843 else if (pp == &p_ls)
8844 {
8845 last_status(FALSE);
8846 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008847
8848 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008849 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008850 {
8851 shell_new_rows(); /* recompute window positions and heights */
8852 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853#endif
8854
8855#ifdef FEAT_GUI
8856 else if (pp == &p_linespace)
8857 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008858 /* Recompute gui.char_height and resize the Vim window to keep the
8859 * same number of lines. */
8860 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008861 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862 }
8863#endif
8864
8865#ifdef FEAT_FOLDING
8866 /* 'foldlevel' */
8867 else if (pp == &curwin->w_p_fdl)
8868 {
8869 if (curwin->w_p_fdl < 0)
8870 curwin->w_p_fdl = 0;
8871 newFoldLevel();
8872 }
8873
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008874 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008875 else if (pp == &curwin->w_p_fml)
8876 {
8877 foldUpdateAll(curwin);
8878 }
8879
8880 /* 'foldnestmax' */
8881 else if (pp == &curwin->w_p_fdn)
8882 {
8883 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8884 foldUpdateAll(curwin);
8885 }
8886
8887 /* 'foldcolumn' */
8888 else if (pp == &curwin->w_p_fdc)
8889 {
8890 if (curwin->w_p_fdc < 0)
8891 {
8892 errmsg = e_positive;
8893 curwin->w_p_fdc = 0;
8894 }
8895 else if (curwin->w_p_fdc > 12)
8896 {
8897 errmsg = e_invarg;
8898 curwin->w_p_fdc = 12;
8899 }
8900 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008901#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008902
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008903#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008904 /* 'shiftwidth' or 'tabstop' */
8905 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8906 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008907# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008908 if (foldmethodIsIndent(curwin))
8909 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008910# endif
8911# ifdef FEAT_CINDENT
8912 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8913 * parse 'cinoptions'. */
8914 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8915 parse_cino(curbuf);
8916# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008917 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008918#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008920#ifdef FEAT_MBYTE
8921 /* 'maxcombine' */
8922 else if (pp == &p_mco)
8923 {
8924 if (p_mco > MAX_MCO)
8925 p_mco = MAX_MCO;
8926 else if (p_mco < 0)
8927 p_mco = 0;
8928 screenclear(); /* will re-allocate the screen */
8929 }
8930#endif
8931
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932 else if (pp == &curbuf->b_p_iminsert)
8933 {
8934 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8935 {
8936 errmsg = e_invarg;
8937 curbuf->b_p_iminsert = B_IMODE_NONE;
8938 }
8939 p_iminsert = curbuf->b_p_iminsert;
8940 if (termcap_active) /* don't do this in the alternate screen */
8941 showmode();
8942#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8943 /* Show/unshow value of 'keymap' in status lines. */
8944 status_redraw_curbuf();
8945#endif
8946 }
8947
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008948 else if (pp == &p_window)
8949 {
8950 if (p_window < 1)
8951 p_window = 1;
8952 else if (p_window >= Rows)
8953 p_window = Rows - 1;
8954 }
8955
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956 else if (pp == &curbuf->b_p_imsearch)
8957 {
8958 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8959 {
8960 errmsg = e_invarg;
8961 curbuf->b_p_imsearch = B_IMODE_NONE;
8962 }
8963 p_imsearch = curbuf->b_p_imsearch;
8964 }
8965
8966#ifdef FEAT_TITLE
8967 /* if 'titlelen' has changed, redraw the title */
8968 else if (pp == &p_titlelen)
8969 {
8970 if (p_titlelen < 0)
8971 {
8972 errmsg = e_positive;
8973 p_titlelen = 85;
8974 }
8975 if (starting != NO_SCREEN && old_value != p_titlelen)
8976 need_maketitle = TRUE;
8977 }
8978#endif
8979
8980 /* if p_ch changed value, change the command line height */
8981 else if (pp == &p_ch)
8982 {
8983 if (p_ch < 1)
8984 {
8985 errmsg = e_positive;
8986 p_ch = 1;
8987 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008988 if (p_ch > Rows - min_rows() + 1)
8989 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008990
8991 /* Only compute the new window layout when startup has been
8992 * completed. Otherwise the frame sizes may be wrong. */
8993 if (p_ch != old_value && full_screen
8994#ifdef FEAT_GUI
8995 && !gui.starting
8996#endif
8997 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008998 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008999 }
9000
9001 /* when 'updatecount' changes from zero to non-zero, open swap files */
9002 else if (pp == &p_uc)
9003 {
9004 if (p_uc < 0)
9005 {
9006 errmsg = e_positive;
9007 p_uc = 100;
9008 }
9009 if (p_uc && !old_value)
9010 ml_open_files();
9011 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009012#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009013 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009014 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009015 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009016 {
9017 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009018 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009019 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009020 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009021 {
9022 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009023 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009024 }
9025 }
9026#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009027#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009028 else if (pp == &p_mzq)
9029 mzvim_reset_timer();
9030#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009031
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009032#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9033 /* 'pyxversion' */
9034 else if (pp == &p_pyx)
9035 {
9036 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9037 errmsg = e_invarg;
9038 }
9039#endif
9040
Bram Moolenaar071d4272004-06-13 20:20:40 +00009041 /* sync undo before 'undolevels' changes */
9042 else if (pp == &p_ul)
9043 {
9044 /* use the old value, otherwise u_sync() may not work properly */
9045 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009046 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009047 p_ul = value;
9048 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009049 else if (pp == &curbuf->b_p_ul)
9050 {
9051 /* use the old value, otherwise u_sync() may not work properly */
9052 curbuf->b_p_ul = old_value;
9053 u_sync(TRUE);
9054 curbuf->b_p_ul = value;
9055 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009056
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009057#ifdef FEAT_LINEBREAK
9058 /* 'numberwidth' must be positive */
9059 else if (pp == &curwin->w_p_nuw)
9060 {
9061 if (curwin->w_p_nuw < 1)
9062 {
9063 errmsg = e_positive;
9064 curwin->w_p_nuw = 1;
9065 }
9066 if (curwin->w_p_nuw > 10)
9067 {
9068 errmsg = e_invarg;
9069 curwin->w_p_nuw = 10;
9070 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009071 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009072 }
9073#endif
9074
Bram Moolenaar1a384422010-07-14 19:53:30 +02009075 else if (pp == &curbuf->b_p_tw)
9076 {
9077 if (curbuf->b_p_tw < 0)
9078 {
9079 errmsg = e_positive;
9080 curbuf->b_p_tw = 0;
9081 }
9082#ifdef FEAT_SYN_HL
9083# ifdef FEAT_WINDOWS
9084 {
9085 win_T *wp;
9086 tabpage_T *tp;
9087
9088 FOR_ALL_TAB_WINDOWS(tp, wp)
9089 check_colorcolumn(wp);
9090 }
9091# else
9092 check_colorcolumn(curwin);
9093# endif
9094#endif
9095 }
9096
Bram Moolenaar071d4272004-06-13 20:20:40 +00009097 /*
9098 * Check the bounds for numeric options here
9099 */
9100 if (Rows < min_rows() && full_screen)
9101 {
9102 if (errbuf != NULL)
9103 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009104 vim_snprintf((char *)errbuf, errbuflen,
9105 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009106 errmsg = errbuf;
9107 }
9108 Rows = min_rows();
9109 }
9110 if (Columns < MIN_COLUMNS && full_screen)
9111 {
9112 if (errbuf != NULL)
9113 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009114 vim_snprintf((char *)errbuf, errbuflen,
9115 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116 errmsg = errbuf;
9117 }
9118 Columns = MIN_COLUMNS;
9119 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009120 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121
Bram Moolenaar071d4272004-06-13 20:20:40 +00009122 /*
9123 * If the screen (shell) height has been changed, assume it is the
9124 * physical screenheight.
9125 */
9126 if (old_Rows != Rows || old_Columns != Columns)
9127 {
9128 /* Changing the screen size is not allowed while updating the screen. */
9129 if (updating_screen)
9130 *pp = old_value;
9131 else if (full_screen
9132#ifdef FEAT_GUI
9133 && !gui.starting
9134#endif
9135 )
9136 set_shellsize((int)Columns, (int)Rows, TRUE);
9137 else
9138 {
9139 /* Postpone the resizing; check the size and cmdline position for
9140 * messages. */
9141 check_shellsize();
9142 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9143 cmdline_row = Rows - p_ch;
9144 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009145 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009146 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009147 }
9148
Bram Moolenaar071d4272004-06-13 20:20:40 +00009149 if (curbuf->b_p_ts <= 0)
9150 {
9151 errmsg = e_positive;
9152 curbuf->b_p_ts = 8;
9153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009154 if (p_tm < 0)
9155 {
9156 errmsg = e_positive;
9157 p_tm = 0;
9158 }
9159 if ((curwin->w_p_scr <= 0
9160 || (curwin->w_p_scr > curwin->w_height
9161 && curwin->w_height > 0))
9162 && full_screen)
9163 {
9164 if (pp == &(curwin->w_p_scr))
9165 {
9166 if (curwin->w_p_scr != 0)
9167 errmsg = e_scroll;
9168 win_comp_scroll(curwin);
9169 }
9170 /* If 'scroll' became invalid because of a side effect silently adjust
9171 * it. */
9172 else if (curwin->w_p_scr <= 0)
9173 curwin->w_p_scr = 1;
9174 else /* curwin->w_p_scr > curwin->w_height */
9175 curwin->w_p_scr = curwin->w_height;
9176 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009177 if (p_hi < 0)
9178 {
9179 errmsg = e_positive;
9180 p_hi = 0;
9181 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009182 else if (p_hi > 10000)
9183 {
9184 errmsg = e_invarg;
9185 p_hi = 10000;
9186 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009187 if (p_re < 0 || p_re > 2)
9188 {
9189 errmsg = e_invarg;
9190 p_re = 0;
9191 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009192 if (p_report < 0)
9193 {
9194 errmsg = e_positive;
9195 p_report = 1;
9196 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009197 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009198 {
9199 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9200 p_sj = Rows / 2;
9201 else
9202 {
9203 errmsg = e_scroll;
9204 p_sj = 1;
9205 }
9206 }
9207 if (p_so < 0 && full_screen)
9208 {
9209 errmsg = e_scroll;
9210 p_so = 0;
9211 }
9212 if (p_siso < 0 && full_screen)
9213 {
9214 errmsg = e_positive;
9215 p_siso = 0;
9216 }
9217#ifdef FEAT_CMDWIN
9218 if (p_cwh < 1)
9219 {
9220 errmsg = e_positive;
9221 p_cwh = 1;
9222 }
9223#endif
9224 if (p_ut < 0)
9225 {
9226 errmsg = e_positive;
9227 p_ut = 2000;
9228 }
9229 if (p_ss < 0)
9230 {
9231 errmsg = e_positive;
9232 p_ss = 0;
9233 }
9234
9235 /* May set global value for local option. */
9236 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9237 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9238
9239 options[opt_idx].flags |= P_WAS_SET;
9240
Bram Moolenaar53744302015-07-17 17:38:22 +02009241#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9242 if (!starting && errmsg == NULL)
9243 {
9244 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009245 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9246 vim_snprintf((char *)buf_new, 10, "%ld", value);
9247 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009248 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9249 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9250 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9251 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9252 reset_v_option_vars();
9253 }
9254#endif
9255
Bram Moolenaar071d4272004-06-13 20:20:40 +00009256 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009257 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009258 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009259 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009260 check_redraw(options[opt_idx].flags);
9261
9262 return errmsg;
9263}
9264
9265/*
9266 * Called after an option changed: check if something needs to be redrawn.
9267 */
9268 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009269check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009270{
9271 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009272 int doclear = (flags & P_RCLR) == P_RCLR;
9273 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009274
9275#ifdef FEAT_WINDOWS
9276 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9277 status_redraw_all();
9278#endif
9279
9280 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9281 changed_window_setting();
9282 if (flags & P_RBUF)
9283 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009284 if (flags & P_RWINONLY)
9285 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009286 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009287 redraw_all_later(CLEAR);
9288 else if (all)
9289 redraw_all_later(NOT_VALID);
9290}
9291
9292/*
9293 * Find index for option 'arg'.
9294 * Return -1 if not found.
9295 */
9296 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009297findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009298{
9299 int opt_idx;
9300 char *s, *p;
9301 static short quick_tab[27] = {0, 0}; /* quick access table */
9302 int is_term_opt;
9303
9304 /*
9305 * For first call: Initialize the quick-access table.
9306 * It contains the index for the first option that starts with a certain
9307 * letter. There are 26 letters, plus the first "t_" option.
9308 */
9309 if (quick_tab[1] == 0)
9310 {
9311 p = options[0].fullname;
9312 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9313 {
9314 if (s[0] != p[0])
9315 {
9316 if (s[0] == 't' && s[1] == '_')
9317 quick_tab[26] = opt_idx;
9318 else
9319 quick_tab[CharOrdLow(s[0])] = opt_idx;
9320 }
9321 p = s;
9322 }
9323 }
9324
9325 /*
9326 * Check for name starting with an illegal character.
9327 */
9328#ifdef EBCDIC
9329 if (!islower(arg[0]))
9330#else
9331 if (arg[0] < 'a' || arg[0] > 'z')
9332#endif
9333 return -1;
9334
9335 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9336 if (is_term_opt)
9337 opt_idx = quick_tab[26];
9338 else
9339 opt_idx = quick_tab[CharOrdLow(arg[0])];
9340 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9341 {
9342 if (STRCMP(arg, s) == 0) /* match full name */
9343 break;
9344 }
9345 if (s == NULL && !is_term_opt)
9346 {
9347 opt_idx = quick_tab[CharOrdLow(arg[0])];
9348 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9349 {
9350 s = options[opt_idx].shortname;
9351 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9352 break;
9353 s = NULL;
9354 }
9355 }
9356 if (s == NULL)
9357 opt_idx = -1;
9358 return opt_idx;
9359}
9360
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009361#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362/*
9363 * Get the value for an option.
9364 *
9365 * Returns:
9366 * Number or Toggle option: 1, *numval gets value.
9367 * String option: 0, *stringval gets allocated string.
9368 * Hidden Number or Toggle option: -1.
9369 * hidden String option: -2.
9370 * unknown option: -3.
9371 */
9372 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009373get_option_value(
9374 char_u *name,
9375 long *numval,
9376 char_u **stringval, /* NULL when only checking existence */
9377 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009378{
9379 int opt_idx;
9380 char_u *varp;
9381
9382 opt_idx = findoption(name);
9383 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009384 {
9385 int key;
9386
9387 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9388 && (key = find_key_option(name)) != 0)
9389 {
9390 char_u key_name[2];
9391 char_u *p;
9392
9393 if (key < 0)
9394 {
9395 key_name[0] = KEY2TERMCAP0(key);
9396 key_name[1] = KEY2TERMCAP1(key);
9397 }
9398 else
9399 {
9400 key_name[0] = KS_KEY;
9401 key_name[1] = (key & 0xff);
9402 }
9403 p = find_termcode(key_name);
9404 if (p != NULL)
9405 {
9406 if (stringval != NULL)
9407 *stringval = vim_strsave(p);
9408 return 0;
9409 }
9410 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009411 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009412 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413
9414 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9415
9416 if (options[opt_idx].flags & P_STRING)
9417 {
9418 if (varp == NULL) /* hidden option */
9419 return -2;
9420 if (stringval != NULL)
9421 {
9422#ifdef FEAT_CRYPT
9423 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009424 if ((char_u **)varp == &curbuf->b_p_key
9425 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009426 *stringval = vim_strsave((char_u *)"*****");
9427 else
9428#endif
9429 *stringval = vim_strsave(*(char_u **)(varp));
9430 }
9431 return 0;
9432 }
9433
9434 if (varp == NULL) /* hidden option */
9435 return -1;
9436 if (options[opt_idx].flags & P_NUM)
9437 *numval = *(long *)varp;
9438 else
9439 {
9440 /* Special case: 'modified' is b_changed, but we also want to consider
9441 * it set when 'ff' or 'fenc' changed. */
9442 if ((int *)varp == &curbuf->b_changed)
9443 *numval = curbufIsChanged();
9444 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009445 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009446 }
9447 return 1;
9448}
9449#endif
9450
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009451#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009452/*
9453 * Returns the option attributes and its value. Unlike the above function it
9454 * will return either global value or local value of the option depending on
9455 * what was requested, but it will never return global value if it was
9456 * requested to return local one and vice versa. Neither it will return
9457 * buffer-local value if it was requested to return window-local one.
9458 *
9459 * Pretends that option is absent if it is not present in the requested scope
9460 * (i.e. has no global, window-local or buffer-local value depending on
9461 * opt_type). Uses
9462 *
9463 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009464 * 0 hidden or unknown option, also option that does not have requested
9465 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009466 * see SOPT_* in vim.h for other flags
9467 *
9468 * Possible opt_type values: see SREQ_* in vim.h
9469 */
9470 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009471get_option_value_strict(
9472 char_u *name,
9473 long *numval,
9474 char_u **stringval, /* NULL when only obtaining attributes */
9475 int opt_type,
9476 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009477{
9478 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009479 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009480 struct vimoption *p;
9481 int r = 0;
9482
9483 opt_idx = findoption(name);
9484 if (opt_idx < 0)
9485 return 0;
9486
9487 p = &(options[opt_idx]);
9488
9489 /* Hidden option */
9490 if (p->var == NULL)
9491 return 0;
9492
9493 if (p->flags & P_BOOL)
9494 r |= SOPT_BOOL;
9495 else if (p->flags & P_NUM)
9496 r |= SOPT_NUM;
9497 else if (p->flags & P_STRING)
9498 r |= SOPT_STRING;
9499
9500 if (p->indir == PV_NONE)
9501 {
9502 if (opt_type == SREQ_GLOBAL)
9503 r |= SOPT_GLOBAL;
9504 else
9505 return 0; /* Did not request global-only option */
9506 }
9507 else
9508 {
9509 if (p->indir & PV_BOTH)
9510 r |= SOPT_GLOBAL;
9511 else if (opt_type == SREQ_GLOBAL)
9512 return 0; /* Requested global option */
9513
9514 if (p->indir & PV_WIN)
9515 {
9516 if (opt_type == SREQ_BUF)
9517 return 0; /* Did not request window-local option */
9518 else
9519 r |= SOPT_WIN;
9520 }
9521 else if (p->indir & PV_BUF)
9522 {
9523 if (opt_type == SREQ_WIN)
9524 return 0; /* Did not request buffer-local option */
9525 else
9526 r |= SOPT_BUF;
9527 }
9528 }
9529
9530 if (stringval == NULL)
9531 return r;
9532
9533 if (opt_type == SREQ_GLOBAL)
9534 varp = p->var;
9535 else
9536 {
9537 if (opt_type == SREQ_BUF)
9538 {
9539 /* Special case: 'modified' is b_changed, but we also want to
9540 * consider it set when 'ff' or 'fenc' changed. */
9541 if (p->indir == PV_MOD)
9542 {
9543 *numval = bufIsChanged((buf_T *) from);
9544 varp = NULL;
9545 }
9546#ifdef FEAT_CRYPT
9547 else if (p->indir == PV_KEY)
9548 {
9549 /* never return the value of the crypt key */
9550 *stringval = NULL;
9551 varp = NULL;
9552 }
9553#endif
9554 else
9555 {
9556 aco_save_T aco;
9557 aucmd_prepbuf(&aco, (buf_T *) from);
9558 varp = get_varp(p);
9559 aucmd_restbuf(&aco);
9560 }
9561 }
9562 else if (opt_type == SREQ_WIN)
9563 {
9564 win_T *save_curwin;
9565 save_curwin = curwin;
9566 curwin = (win_T *) from;
9567 curbuf = curwin->w_buffer;
9568 varp = get_varp(p);
9569 curwin = save_curwin;
9570 curbuf = curwin->w_buffer;
9571 }
9572 if (varp == p->var)
9573 return (r | SOPT_UNSET);
9574 }
9575
9576 if (varp != NULL)
9577 {
9578 if (p->flags & P_STRING)
9579 *stringval = vim_strsave(*(char_u **)(varp));
9580 else if (p->flags & P_NUM)
9581 *numval = *(long *) varp;
9582 else
9583 *numval = *(int *)varp;
9584 }
9585
9586 return r;
9587}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009588
9589/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009590 * Iterate over options. First argument is a pointer to a pointer to a
9591 * structure inside options[] array, second is option type like in the above
9592 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009593 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009594 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009595 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009596 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009597 * first argument to NULL.
9598 *
9599 * Returns full option name for current option on each call.
9600 */
9601 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009602option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009603{
9604 struct vimoption *ret = NULL;
9605 do
9606 {
9607 if (*option == NULL)
9608 *option = (void *) options;
9609 else if (((struct vimoption *) (*option))->fullname == NULL)
9610 {
9611 *option = NULL;
9612 return NULL;
9613 }
9614 else
9615 *option = (void *) (((struct vimoption *) (*option)) + 1);
9616
9617 ret = ((struct vimoption *) (*option));
9618
9619 /* Hidden option */
9620 if (ret->var == NULL)
9621 {
9622 ret = NULL;
9623 continue;
9624 }
9625
9626 switch (opt_type)
9627 {
9628 case SREQ_GLOBAL:
9629 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9630 ret = NULL;
9631 break;
9632 case SREQ_BUF:
9633 if (!(ret->indir & PV_BUF))
9634 ret = NULL;
9635 break;
9636 case SREQ_WIN:
9637 if (!(ret->indir & PV_WIN))
9638 ret = NULL;
9639 break;
9640 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009641 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009642 return NULL;
9643 }
9644 }
9645 while (ret == NULL);
9646
9647 return (char_u *)ret->fullname;
9648}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009649#endif
9650
Bram Moolenaar071d4272004-06-13 20:20:40 +00009651/*
9652 * Set the value of option "name".
9653 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009654 *
9655 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009656 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009657 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009658set_option_value(
9659 char_u *name,
9660 long number,
9661 char_u *string,
9662 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009663{
9664 int opt_idx;
9665 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009666 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009667
9668 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009669 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009670 {
9671 int key;
9672
9673 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9674 && (key = find_key_option(name)) != 0)
9675 {
9676 char_u key_name[2];
9677
9678 if (key < 0)
9679 {
9680 key_name[0] = KEY2TERMCAP0(key);
9681 key_name[1] = KEY2TERMCAP1(key);
9682 }
9683 else
9684 {
9685 key_name[0] = KS_KEY;
9686 key_name[1] = (key & 0xff);
9687 }
9688 add_termcode(key_name, string, FALSE);
9689 if (full_screen)
9690 ttest(FALSE);
9691 redraw_all_later(CLEAR);
9692 return NULL;
9693 }
9694
Bram Moolenaar071d4272004-06-13 20:20:40 +00009695 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009696 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009697 else
9698 {
9699 flags = options[opt_idx].flags;
9700#ifdef HAVE_SANDBOX
9701 /* Disallow changing some options in the sandbox */
9702 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009703 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009704 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009705 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009706 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009707#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009708 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009709 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009710 else
9711 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009712 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009713 if (varp != NULL) /* hidden option is not changed */
9714 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009715 if (number == 0 && string != NULL)
9716 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009717 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009718
9719 /* Either we are given a string or we are setting option
9720 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009721 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009722 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009723 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009724 {
9725 /* There's another character after zeros or the string
9726 * is empty. In both cases, we are trying to set a
9727 * num option using a string. */
9728 EMSG3(_("E521: Number required: &%s = '%s'"),
9729 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009730 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009731
9732 }
9733 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009735 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009736 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009737 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009738 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009739 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009740 }
9741 }
9742 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009743 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009744}
9745
9746/*
9747 * Get the terminal code for a terminal option.
9748 * Returns NULL when not found.
9749 */
9750 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009751get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752{
9753 int opt_idx;
9754 char_u *varp;
9755
9756 if (tname[0] != 't' || tname[1] != '_' ||
9757 tname[2] == NUL || tname[3] == NUL)
9758 return NULL;
9759 if ((opt_idx = findoption(tname)) >= 0)
9760 {
9761 varp = get_varp(&(options[opt_idx]));
9762 if (varp != NULL)
9763 varp = *(char_u **)(varp);
9764 return varp;
9765 }
9766 return find_termcode(tname + 2);
9767}
9768
9769 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009770get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009771{
9772 int i;
9773
9774 i = findoption((char_u *)"hl");
9775 if (i >= 0)
9776 return options[i].def_val[VI_DEFAULT];
9777 return (char_u *)NULL;
9778}
9779
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009780#if defined(FEAT_MBYTE) || defined(PROTO)
9781 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009782get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009783{
9784 int i;
9785
9786 i = findoption((char_u *)"enc");
9787 if (i >= 0)
9788 return options[i].def_val[VI_DEFAULT];
9789 return (char_u *)NULL;
9790}
9791#endif
9792
Bram Moolenaar071d4272004-06-13 20:20:40 +00009793/*
9794 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9795 */
9796 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009797find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009798{
9799 int key;
9800 int modifiers;
9801
9802 /*
9803 * Don't use get_special_key_code() for t_xx, we don't want it to call
9804 * add_termcap_entry().
9805 */
9806 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9807 key = TERMCAP2KEY(arg[2], arg[3]);
9808 else
9809 {
9810 --arg; /* put arg at the '<' */
9811 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009812 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009813 if (modifiers) /* can't handle modifiers here */
9814 key = 0;
9815 }
9816 return key;
9817}
9818
9819/*
9820 * if 'all' == 0: show changed options
9821 * if 'all' == 1: show all normal options
9822 * if 'all' == 2: show all terminal options
9823 */
9824 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009825showoptions(
9826 int all,
9827 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009828{
9829 struct vimoption *p;
9830 int col;
9831 int isterm;
9832 char_u *varp;
9833 struct vimoption **items;
9834 int item_count;
9835 int run;
9836 int row, rows;
9837 int cols;
9838 int i;
9839 int len;
9840
9841#define INC 20
9842#define GAP 3
9843
9844 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9845 PARAM_COUNT));
9846 if (items == NULL)
9847 return;
9848
9849 /* Highlight title */
9850 if (all == 2)
9851 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9852 else if (opt_flags & OPT_GLOBAL)
9853 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9854 else if (opt_flags & OPT_LOCAL)
9855 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9856 else
9857 MSG_PUTS_TITLE(_("\n--- Options ---"));
9858
9859 /*
9860 * do the loop two times:
9861 * 1. display the short items
9862 * 2. display the long items (only strings and numbers)
9863 */
9864 for (run = 1; run <= 2 && !got_int; ++run)
9865 {
9866 /*
9867 * collect the items in items[]
9868 */
9869 item_count = 0;
9870 for (p = &options[0]; p->fullname != NULL; p++)
9871 {
9872 varp = NULL;
9873 isterm = istermoption(p);
9874 if (opt_flags != 0)
9875 {
9876 if (p->indir != PV_NONE && !isterm)
9877 varp = get_varp_scope(p, opt_flags);
9878 }
9879 else
9880 varp = get_varp(p);
9881 if (varp != NULL
9882 && ((all == 2 && isterm)
9883 || (all == 1 && !isterm)
9884 || (all == 0 && !optval_default(p, varp))))
9885 {
9886 if (p->flags & P_BOOL)
9887 len = 1; /* a toggle option fits always */
9888 else
9889 {
9890 option_value2string(p, opt_flags);
9891 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9892 }
9893 if ((len <= INC - GAP && run == 1) ||
9894 (len > INC - GAP && run == 2))
9895 items[item_count++] = p;
9896 }
9897 }
9898
9899 /*
9900 * display the items
9901 */
9902 if (run == 1)
9903 {
9904 cols = (Columns + GAP - 3) / INC;
9905 if (cols == 0)
9906 cols = 1;
9907 rows = (item_count + cols - 1) / cols;
9908 }
9909 else /* run == 2 */
9910 rows = item_count;
9911 for (row = 0; row < rows && !got_int; ++row)
9912 {
9913 msg_putchar('\n'); /* go to next line */
9914 if (got_int) /* 'q' typed in more */
9915 break;
9916 col = 0;
9917 for (i = row; i < item_count; i += rows)
9918 {
9919 msg_col = col; /* make columns */
9920 showoneopt(items[i], opt_flags);
9921 col += INC;
9922 }
9923 out_flush();
9924 ui_breakcheck();
9925 }
9926 }
9927 vim_free(items);
9928}
9929
9930/*
9931 * Return TRUE if option "p" has its default value.
9932 */
9933 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009934optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009935{
9936 int dvi;
9937
9938 if (varp == NULL)
9939 return TRUE; /* hidden option is always at default */
9940 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9941 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009942 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009943 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009944 /* the cast to long is required for Manx C, long_i is
9945 * needed for MSVC */
9946 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009947 /* P_STRING */
9948 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9949}
9950
9951/*
9952 * showoneopt: show the value of one option
9953 * must not be called with a hidden option!
9954 */
9955 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009956showoneopt(
9957 struct vimoption *p,
9958 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009959{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009960 char_u *varp;
9961 int save_silent = silent_mode;
9962
9963 silent_mode = FALSE;
9964 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965
9966 varp = get_varp_scope(p, opt_flags);
9967
9968 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9969 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9970 ? !curbufIsChanged() : !*(int *)varp))
9971 MSG_PUTS("no");
9972 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9973 MSG_PUTS("--");
9974 else
9975 MSG_PUTS(" ");
9976 MSG_PUTS(p->fullname);
9977 if (!(p->flags & P_BOOL))
9978 {
9979 msg_putchar('=');
9980 /* put value string in NameBuff */
9981 option_value2string(p, opt_flags);
9982 msg_outtrans(NameBuff);
9983 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009984
9985 silent_mode = save_silent;
9986 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009987}
9988
9989/*
9990 * Write modified options as ":set" commands to a file.
9991 *
9992 * There are three values for "opt_flags":
9993 * OPT_GLOBAL: Write global option values and fresh values of
9994 * buffer-local options (used for start of a session
9995 * file).
9996 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9997 * curwin (used for a vimrc file).
9998 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9999 * and local values for window-local options of
10000 * curwin. Local values are also written when at the
10001 * default value, because a modeline or autocommand
10002 * may have set them when doing ":edit file" and the
10003 * user has set them back at the default or fresh
10004 * value.
10005 * When "local_only" is TRUE, don't write fresh
10006 * values, only local values (for ":mkview").
10007 * (fresh value = value used for a new buffer or window for a local option).
10008 *
10009 * Return FAIL on error, OK otherwise.
10010 */
10011 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010012makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010013{
10014 struct vimoption *p;
10015 char_u *varp; /* currently used value */
10016 char_u *varp_fresh; /* local value */
10017 char_u *varp_local = NULL; /* fresh value */
10018 char *cmd;
10019 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010020 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010021
10022 /*
10023 * The options that don't have a default (terminal name, columns, lines)
10024 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010025 * Do the loop over "options[]" twice: once for options with the
10026 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010027 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010028 for (pri = 1; pri >= 0; --pri)
10029 {
10030 for (p = &options[0]; !istermoption(p); p++)
10031 if (!(p->flags & P_NO_MKRC)
10032 && !istermoption(p)
10033 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034 {
10035 /* skip global option when only doing locals */
10036 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10037 continue;
10038
10039 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10040 * file, they are always buffer-specific. */
10041 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10042 continue;
10043
10044 /* Global values are only written when not at the default value. */
10045 varp = get_varp_scope(p, opt_flags);
10046 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10047 continue;
10048
10049 round = 2;
10050 if (p->indir != PV_NONE)
10051 {
10052 if (p->var == VAR_WIN)
10053 {
10054 /* skip window-local option when only doing globals */
10055 if (!(opt_flags & OPT_LOCAL))
10056 continue;
10057 /* When fresh value of window-local option is not at the
10058 * default, need to write it too. */
10059 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10060 {
10061 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10062 if (!optval_default(p, varp_fresh))
10063 {
10064 round = 1;
10065 varp_local = varp;
10066 varp = varp_fresh;
10067 }
10068 }
10069 }
10070 }
10071
10072 /* Round 1: fresh value for window-local options.
10073 * Round 2: other values */
10074 for ( ; round <= 2; varp = varp_local, ++round)
10075 {
10076 if (round == 1 || (opt_flags & OPT_GLOBAL))
10077 cmd = "set";
10078 else
10079 cmd = "setlocal";
10080
10081 if (p->flags & P_BOOL)
10082 {
10083 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10084 return FAIL;
10085 }
10086 else if (p->flags & P_NUM)
10087 {
10088 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10089 return FAIL;
10090 }
10091 else /* P_STRING */
10092 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010093#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10094 int do_endif = FALSE;
10095
Bram Moolenaar071d4272004-06-13 20:20:40 +000010096 /* Don't set 'syntax' and 'filetype' again if the value is
10097 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010098 if (
10099# if defined(FEAT_SYN_HL)
10100 p->indir == PV_SYN
10101# if defined(FEAT_AUTOCMD)
10102 ||
10103# endif
10104# endif
10105# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010106 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010107# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010108 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010109 {
10110 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10111 *(char_u **)(varp)) < 0
10112 || put_eol(fd) < 0)
10113 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010114 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010115 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010116#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010117 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10118 (p->flags & P_EXPAND) != 0) == FAIL)
10119 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010120#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10121 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010122 {
10123 if (put_line(fd, "endif") == FAIL)
10124 return FAIL;
10125 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127 }
10128 }
10129 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010131 return OK;
10132}
10133
10134#if defined(FEAT_FOLDING) || defined(PROTO)
10135/*
10136 * Generate set commands for the local fold options only. Used when
10137 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10138 */
10139 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010140makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141{
10142 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10143# ifdef FEAT_EVAL
10144 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10145 == FAIL
10146# endif
10147 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10148 == FAIL
10149 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10150 == FAIL
10151 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10152 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10153 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10154 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10155 )
10156 return FAIL;
10157
10158 return OK;
10159}
10160#endif
10161
10162 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010163put_setstring(
10164 FILE *fd,
10165 char *cmd,
10166 char *name,
10167 char_u **valuep,
10168 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010169{
10170 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010171 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172
10173 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10174 return FAIL;
10175 if (*valuep != NULL)
10176 {
10177 /* Output 'pastetoggle' as key names. For other
10178 * options some characters have to be escaped with
10179 * CTRL-V or backslash */
10180 if (valuep == &p_pt)
10181 {
10182 s = *valuep;
10183 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010184 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185 return FAIL;
10186 }
10187 else if (expand)
10188 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010189 buf = alloc(MAXPATHL);
10190 if (buf == NULL)
10191 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10193 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010194 {
10195 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010196 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010197 }
10198 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199 }
10200 else if (put_escstr(fd, *valuep, 2) == FAIL)
10201 return FAIL;
10202 }
10203 if (put_eol(fd) < 0)
10204 return FAIL;
10205 return OK;
10206}
10207
10208 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010209put_setnum(
10210 FILE *fd,
10211 char *cmd,
10212 char *name,
10213 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010214{
10215 long wc;
10216
10217 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10218 return FAIL;
10219 if (wc_use_keyname((char_u *)valuep, &wc))
10220 {
10221 /* print 'wildchar' and 'wildcharm' as a key name */
10222 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10223 return FAIL;
10224 }
10225 else if (fprintf(fd, "%ld", *valuep) < 0)
10226 return FAIL;
10227 if (put_eol(fd) < 0)
10228 return FAIL;
10229 return OK;
10230}
10231
10232 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010233put_setbool(
10234 FILE *fd,
10235 char *cmd,
10236 char *name,
10237 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010238{
Bram Moolenaar893de922007-10-02 18:40:57 +000010239 if (value < 0) /* global/local option using global value */
10240 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10242 || put_eol(fd) < 0)
10243 return FAIL;
10244 return OK;
10245}
10246
10247/*
10248 * Clear all the terminal options.
10249 * If the option has been allocated, free the memory.
10250 * Terminal options are never hidden or indirect.
10251 */
10252 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010253clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010254{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255 /*
10256 * Reset a few things before clearing the old options. This may cause
10257 * outputting a few things that the terminal doesn't understand, but the
10258 * screen will be cleared later, so this is OK.
10259 */
10260#ifdef FEAT_MOUSE_TTY
10261 mch_setmouse(FALSE); /* switch mouse off */
10262#endif
10263#ifdef FEAT_TITLE
10264 mch_restore_title(3); /* restore window titles */
10265#endif
10266#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10267 /* When starting the GUI close the display opened for the clipboard.
10268 * After restoring the title, because that will need the display. */
10269 if (gui.starting)
10270 clear_xterm_clip();
10271#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010272 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010273
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010274 free_termoptions();
10275}
10276
10277 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010278free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010279{
10280 struct vimoption *p;
10281
Bram Moolenaar071d4272004-06-13 20:20:40 +000010282 for (p = &options[0]; p->fullname != NULL; p++)
10283 if (istermoption(p))
10284 {
10285 if (p->flags & P_ALLOCED)
10286 free_string_option(*(char_u **)(p->var));
10287 if (p->flags & P_DEF_ALLOCED)
10288 free_string_option(p->def_val[VI_DEFAULT]);
10289 *(char_u **)(p->var) = empty_option;
10290 p->def_val[VI_DEFAULT] = empty_option;
10291 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10292 }
10293 clear_termcodes();
10294}
10295
10296/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010297 * Free the string for one term option, if it was allocated.
10298 * Set the string to empty_option and clear allocated flag.
10299 * "var" points to the option value.
10300 */
10301 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010302free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010303{
10304 struct vimoption *p;
10305
10306 for (p = &options[0]; p->fullname != NULL; p++)
10307 if (p->var == var)
10308 {
10309 if (p->flags & P_ALLOCED)
10310 free_string_option(*(char_u **)(p->var));
10311 *(char_u **)(p->var) = empty_option;
10312 p->flags &= ~P_ALLOCED;
10313 break;
10314 }
10315}
10316
10317/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318 * Set the terminal option defaults to the current value.
10319 * Used after setting the terminal name.
10320 */
10321 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010322set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323{
10324 struct vimoption *p;
10325
10326 for (p = &options[0]; p->fullname != NULL; p++)
10327 {
10328 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10329 {
10330 if (p->flags & P_DEF_ALLOCED)
10331 {
10332 free_string_option(p->def_val[VI_DEFAULT]);
10333 p->flags &= ~P_DEF_ALLOCED;
10334 }
10335 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10336 if (p->flags & P_ALLOCED)
10337 {
10338 p->flags |= P_DEF_ALLOCED;
10339 p->flags &= ~P_ALLOCED; /* don't free the value now */
10340 }
10341 }
10342 }
10343}
10344
10345/*
10346 * return TRUE if 'p' starts with 't_'
10347 */
10348 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010349istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010350{
10351 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10352}
10353
10354/*
10355 * Compute columns for ruler and shown command. 'sc_col' is also used to
10356 * decide what the maximum length of a message on the status line can be.
10357 * If there is a status line for the last window, 'sc_col' is independent
10358 * of 'ru_col'.
10359 */
10360
10361#define COL_RULER 17 /* columns needed by standard ruler */
10362
10363 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010364comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365{
10366#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010367 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010368
10369 sc_col = 0;
10370 ru_col = 0;
10371 if (p_ru)
10372 {
10373#ifdef FEAT_STL_OPT
10374 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10375#else
10376 ru_col = COL_RULER + 1;
10377#endif
10378 /* no last status line, adjust sc_col */
10379 if (!last_has_status)
10380 sc_col = ru_col;
10381 }
10382 if (p_sc)
10383 {
10384 sc_col += SHOWCMD_COLS;
10385 if (!p_ru || last_has_status) /* no need for separating space */
10386 ++sc_col;
10387 }
10388 sc_col = Columns - sc_col;
10389 ru_col = Columns - ru_col;
10390 if (sc_col <= 0) /* screen too narrow, will become a mess */
10391 sc_col = 1;
10392 if (ru_col <= 0)
10393 ru_col = 1;
10394#else
10395 sc_col = Columns;
10396 ru_col = Columns;
10397#endif
10398}
10399
10400/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010401 * Unset local option value, similar to ":set opt<".
10402 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010403 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010404unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010405{
10406 struct vimoption *p;
10407 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010408 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010409
10410 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010411 if (opt_idx < 0)
10412 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010413 p = &(options[opt_idx]);
10414
10415 switch ((int)p->indir)
10416 {
10417 /* global option with local value: use local value if it's been set */
10418 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010419 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010420 break;
10421 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010422 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010423 break;
10424 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010425 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010426 break;
10427 case PV_AR:
10428 buf->b_p_ar = -1;
10429 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010430 case PV_BKC:
10431 clear_string_option(&buf->b_p_bkc);
10432 buf->b_bkc_flags = 0;
10433 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010434 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010435 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010436 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010437 case PV_TC:
10438 clear_string_option(&buf->b_p_tc);
10439 buf->b_tc_flags = 0;
10440 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010441#ifdef FEAT_FIND_ID
10442 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010443 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010444 break;
10445 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010446 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010447 break;
10448#endif
10449#ifdef FEAT_INS_EXPAND
10450 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010451 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010452 break;
10453 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010454 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010455 break;
10456#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010457 case PV_FP:
10458 clear_string_option(&buf->b_p_fp);
10459 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010460#ifdef FEAT_QUICKFIX
10461 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010462 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010463 break;
10464 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010465 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010466 break;
10467 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010468 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010469 break;
10470#endif
10471#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10472 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010473 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010474 break;
10475#endif
10476#if defined(FEAT_CRYPT)
10477 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010478 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010479 break;
10480#endif
10481#ifdef FEAT_STL_OPT
10482 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010483 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010484 break;
10485#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010486 case PV_UL:
10487 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10488 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010489#ifdef FEAT_LISP
10490 case PV_LW:
10491 clear_string_option(&buf->b_p_lw);
10492 break;
10493#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010494#ifdef FEAT_MBYTE
10495 case PV_MENC:
10496 clear_string_option(&buf->b_p_menc);
10497 break;
10498#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010499 }
10500}
10501
10502/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010503 * Get pointer to option variable, depending on local or global scope.
10504 */
10505 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010506get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507{
10508 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10509 {
10510 if (p->var == VAR_WIN)
10511 return (char_u *)GLOBAL_WO(get_varp(p));
10512 return p->var;
10513 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010514 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515 {
10516 switch ((int)p->indir)
10517 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010518 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010519#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010520 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10521 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10522 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010524 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10525 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10526 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010527 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010528 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010529 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010531 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10532 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533#endif
10534#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010535 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10536 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010538#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10539 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10540#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010541#if defined(FEAT_CRYPT)
10542 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10543#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010544#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010545 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010546#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010547 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010548#ifdef FEAT_LISP
10549 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10550#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010551 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010552#ifdef FEAT_MBYTE
10553 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10554#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555 }
10556 return NULL; /* "cannot happen" */
10557 }
10558 return get_varp(p);
10559}
10560
10561/*
10562 * Get pointer to option variable.
10563 */
10564 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010565get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566{
10567 /* hidden option, always return NULL */
10568 if (p->var == NULL)
10569 return NULL;
10570
10571 switch ((int)p->indir)
10572 {
10573 case PV_NONE: return p->var;
10574
10575 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010576 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010578 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010579 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010580 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010582 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010584 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010586 case PV_TC: return *curbuf->b_p_tc != NUL
10587 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010588 case PV_BKC: return *curbuf->b_p_bkc != NUL
10589 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010591 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010593 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10595#endif
10596#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010597 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010598 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010599 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10601#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010602 case PV_FP: return *curbuf->b_p_fp != NUL
10603 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010605 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010607 case PV_GP: return *curbuf->b_p_gp != NUL
10608 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10609 case PV_MP: return *curbuf->b_p_mp != NUL
10610 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010612#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10613 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10614 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10615#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010616#if defined(FEAT_CRYPT)
10617 case PV_CM: return *curbuf->b_p_cm != NUL
10618 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10619#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010620#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010621 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010622 ? (char_u *)&(curwin->w_p_stl) : p->var;
10623#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010624 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10625 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010626#ifdef FEAT_LISP
10627 case PV_LW: return *curbuf->b_p_lw != NUL
10628 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10629#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010630#ifdef FEAT_MBYTE
10631 case PV_MENC: return *curbuf->b_p_menc != NUL
10632 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10633#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634
10635#ifdef FEAT_ARABIC
10636 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10637#endif
10638 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010639#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010640 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10641#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010642#ifdef FEAT_SYN_HL
10643 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10644 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010645 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010646#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647#ifdef FEAT_DIFF
10648 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10649#endif
10650#ifdef FEAT_FOLDING
10651 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10652 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10653 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10654 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10655 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10656 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10657 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10658# ifdef FEAT_EVAL
10659 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10660 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10661# endif
10662 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10663#endif
10664 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010665 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010666#ifdef FEAT_LINEBREAK
10667 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10668#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010669#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010670 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010671 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010673#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10674 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10675#endif
10676#ifdef FEAT_RIGHTLEFT
10677 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10678 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10679#endif
10680 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10681 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10682#ifdef FEAT_LINEBREAK
10683 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010684 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10685 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686#endif
10687#ifdef FEAT_SCROLLBIND
10688 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10689#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010690#ifdef FEAT_CURSORBIND
10691 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10692#endif
10693#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010694 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10695 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10696#endif
10697#ifdef FEAT_TERMINAL
Bram Moolenaar1b0675c2017-07-15 14:04:01 +020010698 case PV_TK: return (char_u *)&(curwin->w_p_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010699 case PV_TMS: return (char_u *)&(curwin->w_p_tms);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010700#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010701
10702 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10703 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10704#ifdef FEAT_MBYTE
10705 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10708 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10710 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10711#ifdef FEAT_CINDENT
10712 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10713 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10714 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10715#endif
10716#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10717 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10718#endif
10719#ifdef FEAT_COMMENTS
10720 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10721#endif
10722#ifdef FEAT_FOLDING
10723 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10724#endif
10725#ifdef FEAT_INS_EXPAND
10726 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10727#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010728#ifdef FEAT_COMPL_FUNC
10729 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010730 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010731#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010733 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10735#ifdef FEAT_MBYTE
10736 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10737#endif
10738 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10739#ifdef FEAT_AUTOCMD
10740 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10741#endif
10742 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010743 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010744 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10745 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10746 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10747 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10748#ifdef FEAT_FIND_ID
10749# ifdef FEAT_EVAL
10750 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10751# endif
10752#endif
10753#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10754 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10755 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10756#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010757#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010758 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10759#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010760#ifdef FEAT_CRYPT
10761 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10762#endif
10763#ifdef FEAT_LISP
10764 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10765#endif
10766 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10767 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10768 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10769 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10770 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010772#ifdef FEAT_TEXTOBJ
10773 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10774#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10776#ifdef FEAT_SMARTINDENT
10777 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10781#ifdef FEAT_SEARCHPATH
10782 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10783#endif
10784 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10785#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010786 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010787 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10788#endif
10789#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010790 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10791 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10792 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010793#endif
10794 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10795 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10796 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10797 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010798#ifdef FEAT_PERSISTENT_UNDO
10799 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10802#ifdef FEAT_KEYMAP
10803 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10804#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010805#ifdef FEAT_SIGNS
10806 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10807#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010808 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010809 }
10810 /* always return a valid pointer to avoid a crash! */
10811 return (char_u *)&(curbuf->b_p_wm);
10812}
10813
10814/*
10815 * Get the value of 'equalprg', either the buffer-local one or the global one.
10816 */
10817 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010818get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819{
10820 if (*curbuf->b_p_ep == NUL)
10821 return p_ep;
10822 return curbuf->b_p_ep;
10823}
10824
10825#if defined(FEAT_WINDOWS) || defined(PROTO)
10826/*
10827 * Copy options from one window to another.
10828 * Used when splitting a window.
10829 */
10830 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010831win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832{
10833 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10834 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10835# ifdef FEAT_RIGHTLEFT
10836# ifdef FEAT_FKMAP
10837 /* Is this right? */
10838 wp_to->w_farsi = wp_from->w_farsi;
10839# endif
10840# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010841#if defined(FEAT_LINEBREAK)
10842 briopt_check(wp_to);
10843#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010844}
10845#endif
10846
10847/*
10848 * Copy the options from one winopt_T to another.
10849 * Doesn't free the old option values in "to", use clear_winopt() for that.
10850 * The 'scroll' option is not copied, because it depends on the window height.
10851 * The 'previewwindow' option is reset, there can be only one preview window.
10852 */
10853 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010854copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855{
10856#ifdef FEAT_ARABIC
10857 to->wo_arab = from->wo_arab;
10858#endif
10859 to->wo_list = from->wo_list;
10860 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010861 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010862#ifdef FEAT_LINEBREAK
10863 to->wo_nuw = from->wo_nuw;
10864#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865#ifdef FEAT_RIGHTLEFT
10866 to->wo_rl = from->wo_rl;
10867 to->wo_rlc = vim_strsave(from->wo_rlc);
10868#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010869#ifdef FEAT_STL_OPT
10870 to->wo_stl = vim_strsave(from->wo_stl);
10871#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010873#ifdef FEAT_DIFF
10874 to->wo_wrap_save = from->wo_wrap_save;
10875#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876#ifdef FEAT_LINEBREAK
10877 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010878 to->wo_bri = from->wo_bri;
10879 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880#endif
10881#ifdef FEAT_SCROLLBIND
10882 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010883 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010885#ifdef FEAT_CURSORBIND
10886 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010887 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010888#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010889#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010890 to->wo_spell = from->wo_spell;
10891#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010892#ifdef FEAT_SYN_HL
10893 to->wo_cuc = from->wo_cuc;
10894 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010895 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010896#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010897#ifdef FEAT_DIFF
10898 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010899 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010901#ifdef FEAT_CONCEAL
10902 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010903 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010904#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010905#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010906 to->wo_tk = vim_strsave(from->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010907 to->wo_tms = vim_strsave(from->wo_tms);
10908#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909#ifdef FEAT_FOLDING
10910 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010911 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010912 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010913 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914 to->wo_fdi = vim_strsave(from->wo_fdi);
10915 to->wo_fml = from->wo_fml;
10916 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010917 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010919 to->wo_fdm_save = from->wo_diff_saved
10920 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921 to->wo_fdn = from->wo_fdn;
10922# ifdef FEAT_EVAL
10923 to->wo_fde = vim_strsave(from->wo_fde);
10924 to->wo_fdt = vim_strsave(from->wo_fdt);
10925# endif
10926 to->wo_fmr = vim_strsave(from->wo_fmr);
10927#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010928#ifdef FEAT_SIGNS
10929 to->wo_scl = vim_strsave(from->wo_scl);
10930#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010931 check_winopt(to); /* don't want NULL pointers */
10932}
10933
10934/*
10935 * Check string options in a window for a NULL value.
10936 */
10937 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010938check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939{
10940 check_winopt(&win->w_onebuf_opt);
10941 check_winopt(&win->w_allbuf_opt);
10942}
10943
10944/*
10945 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10946 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010947 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010948check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949{
10950#ifdef FEAT_FOLDING
10951 check_string_option(&wop->wo_fdi);
10952 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010953 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010954# ifdef FEAT_EVAL
10955 check_string_option(&wop->wo_fde);
10956 check_string_option(&wop->wo_fdt);
10957# endif
10958 check_string_option(&wop->wo_fmr);
10959#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010960#ifdef FEAT_SIGNS
10961 check_string_option(&wop->wo_scl);
10962#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010963#ifdef FEAT_RIGHTLEFT
10964 check_string_option(&wop->wo_rlc);
10965#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010966#ifdef FEAT_STL_OPT
10967 check_string_option(&wop->wo_stl);
10968#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010969#ifdef FEAT_SYN_HL
10970 check_string_option(&wop->wo_cc);
10971#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010972#ifdef FEAT_CONCEAL
10973 check_string_option(&wop->wo_cocu);
10974#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010975#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020010976 check_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010977 check_string_option(&wop->wo_tms);
10978#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010979#ifdef FEAT_LINEBREAK
10980 check_string_option(&wop->wo_briopt);
10981#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982}
10983
10984/*
10985 * Free the allocated memory inside a winopt_T.
10986 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010987 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010988clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989{
10990#ifdef FEAT_FOLDING
10991 clear_string_option(&wop->wo_fdi);
10992 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010993 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994# ifdef FEAT_EVAL
10995 clear_string_option(&wop->wo_fde);
10996 clear_string_option(&wop->wo_fdt);
10997# endif
10998 clear_string_option(&wop->wo_fmr);
10999#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011000#ifdef FEAT_SIGNS
11001 clear_string_option(&wop->wo_scl);
11002#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011003#ifdef FEAT_LINEBREAK
11004 clear_string_option(&wop->wo_briopt);
11005#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011006#ifdef FEAT_RIGHTLEFT
11007 clear_string_option(&wop->wo_rlc);
11008#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011009#ifdef FEAT_STL_OPT
11010 clear_string_option(&wop->wo_stl);
11011#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011012#ifdef FEAT_SYN_HL
11013 clear_string_option(&wop->wo_cc);
11014#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011015#ifdef FEAT_CONCEAL
11016 clear_string_option(&wop->wo_cocu);
11017#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011018#ifdef FEAT_TERMINAL
Bram Moolenaar0daf8432017-07-15 15:16:40 +020011019 clear_string_option(&wop->wo_tk);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011020 clear_string_option(&wop->wo_tms);
11021#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011022}
11023
11024/*
11025 * Copy global option values to local options for one buffer.
11026 * Used when creating a new buffer and sometimes when entering a buffer.
11027 * flags:
11028 * BCO_ENTER We will enter the buf buffer.
11029 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11030 * appropriate.
11031 * BCO_NOHELP Don't copy the values to a help buffer.
11032 */
11033 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011034buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035{
11036 int should_copy = TRUE;
11037 char_u *save_p_isk = NULL; /* init for GCC */
11038 int dont_do_help;
11039 int did_isk = FALSE;
11040
11041 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011042 * Skip this when the option defaults have not been set yet. Happens when
11043 * main() allocates the first buffer.
11044 */
11045 if (p_cpo != NULL)
11046 {
11047 /*
11048 * Always copy when entering and 'cpo' contains 'S'.
11049 * Don't copy when already initialized.
11050 * Don't copy when 'cpo' contains 's' and not entering.
11051 * 'S' BCO_ENTER initialized 's' should_copy
11052 * yes yes X X TRUE
11053 * yes no yes X FALSE
11054 * no X yes X FALSE
11055 * X no no yes FALSE
11056 * X no no no TRUE
11057 * no yes no X TRUE
11058 */
11059 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11060 && (buf->b_p_initialized
11061 || (!(flags & BCO_ENTER)
11062 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11063 should_copy = FALSE;
11064
11065 if (should_copy || (flags & BCO_ALWAYS))
11066 {
11067 /* Don't copy the options specific to a help buffer when
11068 * BCO_NOHELP is given or the options were initialized already
11069 * (jumping back to a help file with CTRL-T or CTRL-O) */
11070 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11071 || buf->b_p_initialized;
11072 if (dont_do_help) /* don't free b_p_isk */
11073 {
11074 save_p_isk = buf->b_p_isk;
11075 buf->b_p_isk = NULL;
11076 }
11077 /*
11078 * Always free the allocated strings.
11079 * If not already initialized, set 'readonly' and copy 'fileformat'.
11080 */
11081 if (!buf->b_p_initialized)
11082 {
11083 free_buf_options(buf, TRUE);
11084 buf->b_p_ro = FALSE; /* don't copy readonly */
11085 buf->b_p_tx = p_tx;
11086#ifdef FEAT_MBYTE
11087 buf->b_p_fenc = vim_strsave(p_fenc);
11088#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011089 switch (*p_ffs)
11090 {
11091 case 'm':
11092 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11093 case 'd':
11094 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11095 case 'u':
11096 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11097 default:
11098 buf->b_p_ff = vim_strsave(p_ff);
11099 }
11100 if (buf->b_p_ff != NULL)
11101 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102 buf->b_p_bh = empty_option;
11103 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104 }
11105 else
11106 free_buf_options(buf, FALSE);
11107
11108 buf->b_p_ai = p_ai;
11109 buf->b_p_ai_nopaste = p_ai_nopaste;
11110 buf->b_p_sw = p_sw;
11111 buf->b_p_tw = p_tw;
11112 buf->b_p_tw_nopaste = p_tw_nopaste;
11113 buf->b_p_tw_nobin = p_tw_nobin;
11114 buf->b_p_wm = p_wm;
11115 buf->b_p_wm_nopaste = p_wm_nopaste;
11116 buf->b_p_wm_nobin = p_wm_nobin;
11117 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011118#ifdef FEAT_MBYTE
11119 buf->b_p_bomb = p_bomb;
11120#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011121 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122 buf->b_p_et = p_et;
11123 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011124 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011125 buf->b_p_ml = p_ml;
11126 buf->b_p_ml_nobin = p_ml_nobin;
11127 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011128 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129#ifdef FEAT_INS_EXPAND
11130 buf->b_p_cpt = vim_strsave(p_cpt);
11131#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011132#ifdef FEAT_COMPL_FUNC
11133 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011134 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011135#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011136 buf->b_p_sts = p_sts;
11137 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011138 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011139#ifdef FEAT_COMMENTS
11140 buf->b_p_com = vim_strsave(p_com);
11141#endif
11142#ifdef FEAT_FOLDING
11143 buf->b_p_cms = vim_strsave(p_cms);
11144#endif
11145 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011146 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147 buf->b_p_nf = vim_strsave(p_nf);
11148 buf->b_p_mps = vim_strsave(p_mps);
11149#ifdef FEAT_SMARTINDENT
11150 buf->b_p_si = p_si;
11151#endif
11152 buf->b_p_ci = p_ci;
11153#ifdef FEAT_CINDENT
11154 buf->b_p_cin = p_cin;
11155 buf->b_p_cink = vim_strsave(p_cink);
11156 buf->b_p_cino = vim_strsave(p_cino);
11157#endif
11158#ifdef FEAT_AUTOCMD
11159 /* Don't copy 'filetype', it must be detected */
11160 buf->b_p_ft = empty_option;
11161#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011162 buf->b_p_pi = p_pi;
11163#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11164 buf->b_p_cinw = vim_strsave(p_cinw);
11165#endif
11166#ifdef FEAT_LISP
11167 buf->b_p_lisp = p_lisp;
11168#endif
11169#ifdef FEAT_SYN_HL
11170 /* Don't copy 'syntax', it must be set */
11171 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011172 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011173 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011174#endif
11175#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011176 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011177 (void)compile_cap_prog(&buf->b_s);
11178 buf->b_s.b_p_spf = vim_strsave(p_spf);
11179 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011180#endif
11181#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11182 buf->b_p_inde = vim_strsave(p_inde);
11183 buf->b_p_indk = vim_strsave(p_indk);
11184#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011185 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011186#if defined(FEAT_EVAL)
11187 buf->b_p_fex = vim_strsave(p_fex);
11188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011189#ifdef FEAT_CRYPT
11190 buf->b_p_key = vim_strsave(p_key);
11191#endif
11192#ifdef FEAT_SEARCHPATH
11193 buf->b_p_sua = vim_strsave(p_sua);
11194#endif
11195#ifdef FEAT_KEYMAP
11196 buf->b_p_keymap = vim_strsave(p_keymap);
11197 buf->b_kmap_state |= KEYMAP_INIT;
11198#endif
11199 /* This isn't really an option, but copying the langmap and IME
11200 * state from the current buffer is better than resetting it. */
11201 buf->b_p_iminsert = p_iminsert;
11202 buf->b_p_imsearch = p_imsearch;
11203
11204 /* options that are normally global but also have a local value
11205 * are not copied, start using the global value */
11206 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011207 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011208 buf->b_p_bkc = empty_option;
11209 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011210#ifdef FEAT_QUICKFIX
11211 buf->b_p_gp = empty_option;
11212 buf->b_p_mp = empty_option;
11213 buf->b_p_efm = empty_option;
11214#endif
11215 buf->b_p_ep = empty_option;
11216 buf->b_p_kp = empty_option;
11217 buf->b_p_path = empty_option;
11218 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011219 buf->b_p_tc = empty_option;
11220 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011221#ifdef FEAT_FIND_ID
11222 buf->b_p_def = empty_option;
11223 buf->b_p_inc = empty_option;
11224# ifdef FEAT_EVAL
11225 buf->b_p_inex = vim_strsave(p_inex);
11226# endif
11227#endif
11228#ifdef FEAT_INS_EXPAND
11229 buf->b_p_dict = empty_option;
11230 buf->b_p_tsr = empty_option;
11231#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011232#ifdef FEAT_TEXTOBJ
11233 buf->b_p_qe = vim_strsave(p_qe);
11234#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011235#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11236 buf->b_p_bexpr = empty_option;
11237#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011238#if defined(FEAT_CRYPT)
11239 buf->b_p_cm = empty_option;
11240#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011241#ifdef FEAT_PERSISTENT_UNDO
11242 buf->b_p_udf = p_udf;
11243#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011244#ifdef FEAT_LISP
11245 buf->b_p_lw = empty_option;
11246#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011247#ifdef FEAT_MBYTE
11248 buf->b_p_menc = empty_option;
11249#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011250
11251 /*
11252 * Don't copy the options set by ex_help(), use the saved values,
11253 * when going from a help buffer to a non-help buffer.
11254 * Don't touch these at all when BCO_NOHELP is used and going from
11255 * or to a help buffer.
11256 */
11257 if (dont_do_help)
11258 buf->b_p_isk = save_p_isk;
11259 else
11260 {
11261 buf->b_p_isk = vim_strsave(p_isk);
11262 did_isk = TRUE;
11263 buf->b_p_ts = p_ts;
11264 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011265 if (buf->b_p_bt[0] == 'h')
11266 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267 buf->b_p_ma = p_ma;
11268 }
11269 }
11270
11271 /*
11272 * When the options should be copied (ignoring BCO_ALWAYS), set the
11273 * flag that indicates that the options have been initialized.
11274 */
11275 if (should_copy)
11276 buf->b_p_initialized = TRUE;
11277 }
11278
11279 check_buf_options(buf); /* make sure we don't have NULLs */
11280 if (did_isk)
11281 (void)buf_init_chartab(buf, FALSE);
11282}
11283
11284/*
11285 * Reset the 'modifiable' option and its default value.
11286 */
11287 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011288reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011289{
11290 int opt_idx;
11291
11292 curbuf->b_p_ma = FALSE;
11293 p_ma = FALSE;
11294 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011295 if (opt_idx >= 0)
11296 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011297}
11298
11299/*
11300 * Set the global value for 'iminsert' to the local value.
11301 */
11302 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011303set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011304{
11305 p_iminsert = curbuf->b_p_iminsert;
11306}
11307
11308/*
11309 * Set the global value for 'imsearch' to the local value.
11310 */
11311 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011312set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011313{
11314 p_imsearch = curbuf->b_p_imsearch;
11315}
11316
11317#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11318static int expand_option_idx = -1;
11319static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11320static int expand_option_flags = 0;
11321
11322 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011323set_context_in_set_cmd(
11324 expand_T *xp,
11325 char_u *arg,
11326 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011327{
11328 int nextchar;
11329 long_u flags = 0; /* init for GCC */
11330 int opt_idx = 0; /* init for GCC */
11331 char_u *p;
11332 char_u *s;
11333 int is_term_option = FALSE;
11334 int key;
11335
11336 expand_option_flags = opt_flags;
11337
11338 xp->xp_context = EXPAND_SETTINGS;
11339 if (*arg == NUL)
11340 {
11341 xp->xp_pattern = arg;
11342 return;
11343 }
11344 p = arg + STRLEN(arg) - 1;
11345 if (*p == ' ' && *(p - 1) != '\\')
11346 {
11347 xp->xp_pattern = p + 1;
11348 return;
11349 }
11350 while (p > arg)
11351 {
11352 s = p;
11353 /* count number of backslashes before ' ' or ',' */
11354 if (*p == ' ' || *p == ',')
11355 {
11356 while (s > arg && *(s - 1) == '\\')
11357 --s;
11358 }
11359 /* break at a space with an even number of backslashes */
11360 if (*p == ' ' && ((p - s) & 1) == 0)
11361 {
11362 ++p;
11363 break;
11364 }
11365 --p;
11366 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011367 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368 {
11369 xp->xp_context = EXPAND_BOOL_SETTINGS;
11370 p += 2;
11371 }
11372 if (STRNCMP(p, "inv", 3) == 0)
11373 {
11374 xp->xp_context = EXPAND_BOOL_SETTINGS;
11375 p += 3;
11376 }
11377 xp->xp_pattern = arg = p;
11378 if (*arg == '<')
11379 {
11380 while (*p != '>')
11381 if (*p++ == NUL) /* expand terminal option name */
11382 return;
11383 key = get_special_key_code(arg + 1);
11384 if (key == 0) /* unknown name */
11385 {
11386 xp->xp_context = EXPAND_NOTHING;
11387 return;
11388 }
11389 nextchar = *++p;
11390 is_term_option = TRUE;
11391 expand_option_name[2] = KEY2TERMCAP0(key);
11392 expand_option_name[3] = KEY2TERMCAP1(key);
11393 }
11394 else
11395 {
11396 if (p[0] == 't' && p[1] == '_')
11397 {
11398 p += 2;
11399 if (*p != NUL)
11400 ++p;
11401 if (*p == NUL)
11402 return; /* expand option name */
11403 nextchar = *++p;
11404 is_term_option = TRUE;
11405 expand_option_name[2] = p[-2];
11406 expand_option_name[3] = p[-1];
11407 }
11408 else
11409 {
11410 /* Allow * wildcard */
11411 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11412 p++;
11413 if (*p == NUL)
11414 return;
11415 nextchar = *p;
11416 *p = NUL;
11417 opt_idx = findoption(arg);
11418 *p = nextchar;
11419 if (opt_idx == -1 || options[opt_idx].var == NULL)
11420 {
11421 xp->xp_context = EXPAND_NOTHING;
11422 return;
11423 }
11424 flags = options[opt_idx].flags;
11425 if (flags & P_BOOL)
11426 {
11427 xp->xp_context = EXPAND_NOTHING;
11428 return;
11429 }
11430 }
11431 }
11432 /* handle "-=" and "+=" */
11433 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11434 {
11435 ++p;
11436 nextchar = '=';
11437 }
11438 if ((nextchar != '=' && nextchar != ':')
11439 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11440 {
11441 xp->xp_context = EXPAND_UNSUCCESSFUL;
11442 return;
11443 }
11444 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11445 {
11446 xp->xp_context = EXPAND_OLD_SETTING;
11447 if (is_term_option)
11448 expand_option_idx = -1;
11449 else
11450 expand_option_idx = opt_idx;
11451 xp->xp_pattern = p + 1;
11452 return;
11453 }
11454 xp->xp_context = EXPAND_NOTHING;
11455 if (is_term_option || (flags & P_NUM))
11456 return;
11457
11458 xp->xp_pattern = p + 1;
11459
11460 if (flags & P_EXPAND)
11461 {
11462 p = options[opt_idx].var;
11463 if (p == (char_u *)&p_bdir
11464 || p == (char_u *)&p_dir
11465 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011466 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011467 || p == (char_u *)&p_rtp
11468#ifdef FEAT_SEARCHPATH
11469 || p == (char_u *)&p_cdpath
11470#endif
11471#ifdef FEAT_SESSION
11472 || p == (char_u *)&p_vdir
11473#endif
11474 )
11475 {
11476 xp->xp_context = EXPAND_DIRECTORIES;
11477 if (p == (char_u *)&p_path
11478#ifdef FEAT_SEARCHPATH
11479 || p == (char_u *)&p_cdpath
11480#endif
11481 )
11482 xp->xp_backslash = XP_BS_THREE;
11483 else
11484 xp->xp_backslash = XP_BS_ONE;
11485 }
11486 else
11487 {
11488 xp->xp_context = EXPAND_FILES;
11489 /* for 'tags' need three backslashes for a space */
11490 if (p == (char_u *)&p_tags)
11491 xp->xp_backslash = XP_BS_THREE;
11492 else
11493 xp->xp_backslash = XP_BS_ONE;
11494 }
11495 }
11496
11497 /* For an option that is a list of file names, find the start of the
11498 * last file name. */
11499 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11500 {
11501 /* count number of backslashes before ' ' or ',' */
11502 if (*p == ' ' || *p == ',')
11503 {
11504 s = p;
11505 while (s > xp->xp_pattern && *(s - 1) == '\\')
11506 --s;
11507 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11508 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11509 {
11510 xp->xp_pattern = p + 1;
11511 break;
11512 }
11513 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011514
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011515#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011516 /* for 'spellsuggest' start at "file:" */
11517 if (options[opt_idx].var == (char_u *)&p_sps
11518 && STRNCMP(p, "file:", 5) == 0)
11519 {
11520 xp->xp_pattern = p + 5;
11521 break;
11522 }
11523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524 }
11525
11526 return;
11527}
11528
11529 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011530ExpandSettings(
11531 expand_T *xp,
11532 regmatch_T *regmatch,
11533 int *num_file,
11534 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535{
11536 int num_normal = 0; /* Nr of matching non-term-code settings */
11537 int num_term = 0; /* Nr of matching terminal code settings */
11538 int opt_idx;
11539 int match;
11540 int count = 0;
11541 char_u *str;
11542 int loop;
11543 int is_term_opt;
11544 char_u name_buf[MAX_KEY_NAME_LEN];
11545 static char *(names[]) = {"all", "termcap"};
11546 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11547
11548 /* do this loop twice:
11549 * loop == 0: count the number of matching options
11550 * loop == 1: copy the matching options into allocated memory
11551 */
11552 for (loop = 0; loop <= 1; ++loop)
11553 {
11554 regmatch->rm_ic = ic;
11555 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11556 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011557 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11558 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011559 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11560 {
11561 if (loop == 0)
11562 num_normal++;
11563 else
11564 (*file)[count++] = vim_strsave((char_u *)names[match]);
11565 }
11566 }
11567 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11568 opt_idx++)
11569 {
11570 if (options[opt_idx].var == NULL)
11571 continue;
11572 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11573 && !(options[opt_idx].flags & P_BOOL))
11574 continue;
11575 is_term_opt = istermoption(&options[opt_idx]);
11576 if (is_term_opt && num_normal > 0)
11577 continue;
11578 match = FALSE;
11579 if (vim_regexec(regmatch, str, (colnr_T)0)
11580 || (options[opt_idx].shortname != NULL
11581 && vim_regexec(regmatch,
11582 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11583 match = TRUE;
11584 else if (is_term_opt)
11585 {
11586 name_buf[0] = '<';
11587 name_buf[1] = 't';
11588 name_buf[2] = '_';
11589 name_buf[3] = str[2];
11590 name_buf[4] = str[3];
11591 name_buf[5] = '>';
11592 name_buf[6] = NUL;
11593 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11594 {
11595 match = TRUE;
11596 str = name_buf;
11597 }
11598 }
11599 if (match)
11600 {
11601 if (loop == 0)
11602 {
11603 if (is_term_opt)
11604 num_term++;
11605 else
11606 num_normal++;
11607 }
11608 else
11609 (*file)[count++] = vim_strsave(str);
11610 }
11611 }
11612 /*
11613 * Check terminal key codes, these are not in the option table
11614 */
11615 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11616 {
11617 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11618 {
11619 if (!isprint(str[0]) || !isprint(str[1]))
11620 continue;
11621
11622 name_buf[0] = 't';
11623 name_buf[1] = '_';
11624 name_buf[2] = str[0];
11625 name_buf[3] = str[1];
11626 name_buf[4] = NUL;
11627
11628 match = FALSE;
11629 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11630 match = TRUE;
11631 else
11632 {
11633 name_buf[0] = '<';
11634 name_buf[1] = 't';
11635 name_buf[2] = '_';
11636 name_buf[3] = str[0];
11637 name_buf[4] = str[1];
11638 name_buf[5] = '>';
11639 name_buf[6] = NUL;
11640
11641 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11642 match = TRUE;
11643 }
11644 if (match)
11645 {
11646 if (loop == 0)
11647 num_term++;
11648 else
11649 (*file)[count++] = vim_strsave(name_buf);
11650 }
11651 }
11652
11653 /*
11654 * Check special key names.
11655 */
11656 regmatch->rm_ic = TRUE; /* ignore case here */
11657 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11658 {
11659 name_buf[0] = '<';
11660 STRCPY(name_buf + 1, str);
11661 STRCAT(name_buf, ">");
11662
11663 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11664 {
11665 if (loop == 0)
11666 num_term++;
11667 else
11668 (*file)[count++] = vim_strsave(name_buf);
11669 }
11670 }
11671 }
11672 if (loop == 0)
11673 {
11674 if (num_normal > 0)
11675 *num_file = num_normal;
11676 else if (num_term > 0)
11677 *num_file = num_term;
11678 else
11679 return OK;
11680 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11681 if (*file == NULL)
11682 {
11683 *file = (char_u **)"";
11684 return FAIL;
11685 }
11686 }
11687 }
11688 return OK;
11689}
11690
11691 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011692ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011693{
11694 char_u *var = NULL; /* init for GCC */
11695 char_u *buf;
11696
11697 *num_file = 0;
11698 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11699 if (*file == NULL)
11700 return FAIL;
11701
11702 /*
11703 * For a terminal key code expand_option_idx is < 0.
11704 */
11705 if (expand_option_idx < 0)
11706 {
11707 var = find_termcode(expand_option_name + 2);
11708 if (var == NULL)
11709 expand_option_idx = findoption(expand_option_name);
11710 }
11711
11712 if (expand_option_idx >= 0)
11713 {
11714 /* put string of option value in NameBuff */
11715 option_value2string(&options[expand_option_idx], expand_option_flags);
11716 var = NameBuff;
11717 }
11718 else if (var == NULL)
11719 var = (char_u *)"";
11720
11721 /* A backslash is required before some characters. This is the reverse of
11722 * what happens in do_set(). */
11723 buf = vim_strsave_escaped(var, escape_chars);
11724
11725 if (buf == NULL)
11726 {
11727 vim_free(*file);
11728 *file = NULL;
11729 return FAIL;
11730 }
11731
11732#ifdef BACKSLASH_IN_FILENAME
11733 /* For MS-Windows et al. we don't double backslashes at the start and
11734 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011735 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011736 if (var[0] == '\\' && var[1] == '\\'
11737 && expand_option_idx >= 0
11738 && (options[expand_option_idx].flags & P_EXPAND)
11739 && vim_isfilec(var[2])
11740 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011741 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011742#endif
11743
11744 *file[0] = buf;
11745 *num_file = 1;
11746 return OK;
11747}
11748#endif
11749
11750/*
11751 * Get the value for the numeric or string option *opp in a nice format into
11752 * NameBuff[]. Must not be called with a hidden option!
11753 */
11754 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011755option_value2string(
11756 struct vimoption *opp,
11757 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011758{
11759 char_u *varp;
11760
11761 varp = get_varp_scope(opp, opt_flags);
11762
11763 if (opp->flags & P_NUM)
11764 {
11765 long wc = 0;
11766
11767 if (wc_use_keyname(varp, &wc))
11768 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11769 else if (wc != 0)
11770 STRCPY(NameBuff, transchar((int)wc));
11771 else
11772 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11773 }
11774 else /* P_STRING */
11775 {
11776 varp = *(char_u **)(varp);
11777 if (varp == NULL) /* just in case */
11778 NameBuff[0] = NUL;
11779#ifdef FEAT_CRYPT
11780 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011781 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782 STRCPY(NameBuff, "*****");
11783#endif
11784 else if (opp->flags & P_EXPAND)
11785 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11786 /* Translate 'pastetoggle' into special key names */
11787 else if ((char_u **)opp->var == &p_pt)
11788 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11789 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011790 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011791 }
11792}
11793
11794/*
11795 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11796 * printed as a keyname.
11797 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11798 */
11799 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011800wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011801{
11802 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11803 {
11804 *wcp = *(long *)varp;
11805 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11806 return TRUE;
11807 }
11808 return FALSE;
11809}
11810
Bram Moolenaar01615492015-02-03 13:00:38 +010011811#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011812/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011813 * Any character has an equivalent 'langmap' character. This is used for
11814 * keyboards that have a special language mode that sends characters above
11815 * 128 (although other characters can be translated too). The "to" field is a
11816 * Vim command character. This avoids having to switch the keyboard back to
11817 * ASCII mode when leaving Insert mode.
11818 *
11819 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11820 * commands.
11821 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11822 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11823 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011824 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011825# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011826/*
11827 * With multi-byte support use growarray for 'langmap' chars >= 256
11828 */
11829typedef struct
11830{
11831 int from;
11832 int to;
11833} langmap_entry_T;
11834
11835static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011836static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011837
11838/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011839 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11840 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011841 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011842 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011843langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011844{
11845 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011846 int a = 0;
11847 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011848
11849 /* Do a binary search for an existing entry. */
11850 while (a != b)
11851 {
11852 int i = (a + b) / 2;
11853 int d = entries[i].from - from;
11854
11855 if (d == 0)
11856 {
11857 entries[i].to = to;
11858 return;
11859 }
11860 if (d < 0)
11861 a = i + 1;
11862 else
11863 b = i;
11864 }
11865
11866 if (ga_grow(&langmap_mapga, 1) != OK)
11867 return; /* out of memory */
11868
11869 /* insert new entry at position "a" */
11870 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11871 mch_memmove(entries + 1, entries,
11872 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11873 ++langmap_mapga.ga_len;
11874 entries[0].from = from;
11875 entries[0].to = to;
11876}
11877
11878/*
11879 * Apply 'langmap' to multi-byte character "c" and return the result.
11880 */
11881 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011882langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011883{
11884 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11885 int a = 0;
11886 int b = langmap_mapga.ga_len;
11887
11888 while (a != b)
11889 {
11890 int i = (a + b) / 2;
11891 int d = entries[i].from - c;
11892
11893 if (d == 0)
11894 return entries[i].to; /* found matching entry */
11895 if (d < 0)
11896 a = i + 1;
11897 else
11898 b = i;
11899 }
11900 return c; /* no entry found, return "c" unmodified */
11901}
11902# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011903
11904 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011905langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906{
11907 int i;
11908
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011909 for (i = 0; i < 256; i++)
11910 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11911# ifdef FEAT_MBYTE
11912 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11913# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011914}
11915
11916/*
11917 * Called when langmap option is set; the language map can be
11918 * changed at any time!
11919 */
11920 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011921langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011922{
11923 char_u *p;
11924 char_u *p2;
11925 int from, to;
11926
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011927#ifdef FEAT_MBYTE
11928 ga_clear(&langmap_mapga); /* clear the previous map first */
11929#endif
11930 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011931
11932 for (p = p_langmap; p[0] != NUL; )
11933 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011934 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011935 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936 {
11937 if (p2[0] == '\\' && p2[1] != NUL)
11938 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011939 }
11940 if (p2[0] == ';')
11941 ++p2; /* abcd;ABCD form, p2 points to A */
11942 else
11943 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11944 while (p[0])
11945 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011946 if (p[0] == ',')
11947 {
11948 ++p;
11949 break;
11950 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011951 if (p[0] == '\\' && p[1] != NUL)
11952 ++p;
11953#ifdef FEAT_MBYTE
11954 from = (*mb_ptr2char)(p);
11955#else
11956 from = p[0];
11957#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011958 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011959 if (p2 == NULL)
11960 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011961 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011962 if (p[0] != ',')
11963 {
11964 if (p[0] == '\\')
11965 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011966#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011967 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011968#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011969 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011970#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011971 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011972 }
11973 else
11974 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011975 if (p2[0] != ',')
11976 {
11977 if (p2[0] == '\\')
11978 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011979#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011980 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011981#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011982 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011983#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011984 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985 }
11986 if (to == NUL)
11987 {
11988 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11989 transchar(from));
11990 return;
11991 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011992
11993#ifdef FEAT_MBYTE
11994 if (from >= 256)
11995 langmap_set_entry(from, to);
11996 else
11997#endif
11998 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011999
12000 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012001 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012002 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012003 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012004 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012005 if (*p == ';')
12006 {
12007 p = p2;
12008 if (p[0] != NUL)
12009 {
12010 if (p[0] != ',')
12011 {
12012 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
12013 return;
12014 }
12015 ++p;
12016 }
12017 break;
12018 }
12019 }
12020 }
12021 }
12022}
12023#endif
12024
12025/*
12026 * Return TRUE if format option 'x' is in effect.
12027 * Take care of no formatting when 'paste' is set.
12028 */
12029 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012030has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012031{
12032 if (p_paste)
12033 return FALSE;
12034 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12035}
12036
12037/*
12038 * Return TRUE if "x" is present in 'shortmess' option, or
12039 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12040 */
12041 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012042shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012043{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012044 return p_shm != NULL &&
12045 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012046 || (vim_strchr(p_shm, 'a') != NULL
12047 && vim_strchr((char_u *)SHM_A, x) != NULL));
12048}
12049
12050/*
12051 * paste_option_changed() - Called after p_paste was set or reset.
12052 */
12053 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012054paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012055{
12056 static int old_p_paste = FALSE;
12057 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012058 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012059#ifdef FEAT_CMDL_INFO
12060 static int save_ru = 0;
12061#endif
12062#ifdef FEAT_RIGHTLEFT
12063 static int save_ri = 0;
12064 static int save_hkmap = 0;
12065#endif
12066 buf_T *buf;
12067
12068 if (p_paste)
12069 {
12070 /*
12071 * Paste switched from off to on.
12072 * Save the current values, so they can be restored later.
12073 */
12074 if (!old_p_paste)
12075 {
12076 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012077 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078 {
12079 buf->b_p_tw_nopaste = buf->b_p_tw;
12080 buf->b_p_wm_nopaste = buf->b_p_wm;
12081 buf->b_p_sts_nopaste = buf->b_p_sts;
12082 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012083 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012084 }
12085
12086 /* save global options */
12087 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012088 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012089#ifdef FEAT_CMDL_INFO
12090 save_ru = p_ru;
12091#endif
12092#ifdef FEAT_RIGHTLEFT
12093 save_ri = p_ri;
12094 save_hkmap = p_hkmap;
12095#endif
12096 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012097 p_ai_nopaste = p_ai;
12098 p_et_nopaste = p_et;
12099 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012100 p_tw_nopaste = p_tw;
12101 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012102 }
12103
12104 /*
12105 * Always set the option values, also when 'paste' is set when it is
12106 * already on.
12107 */
12108 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012109 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012110 {
12111 buf->b_p_tw = 0; /* textwidth is 0 */
12112 buf->b_p_wm = 0; /* wrapmargin is 0 */
12113 buf->b_p_sts = 0; /* softtabstop is 0 */
12114 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012115 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012116 }
12117
12118 /* set global options */
12119 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012120 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012121#ifdef FEAT_CMDL_INFO
12122# ifdef FEAT_WINDOWS
12123 if (p_ru)
12124 status_redraw_all(); /* redraw to remove the ruler */
12125# endif
12126 p_ru = 0; /* no ruler */
12127#endif
12128#ifdef FEAT_RIGHTLEFT
12129 p_ri = 0; /* no reverse insert */
12130 p_hkmap = 0; /* no Hebrew keyboard */
12131#endif
12132 /* set global values for local buffer options */
12133 p_tw = 0;
12134 p_wm = 0;
12135 p_sts = 0;
12136 p_ai = 0;
12137 }
12138
12139 /*
12140 * Paste switched from on to off: Restore saved values.
12141 */
12142 else if (old_p_paste)
12143 {
12144 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012145 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146 {
12147 buf->b_p_tw = buf->b_p_tw_nopaste;
12148 buf->b_p_wm = buf->b_p_wm_nopaste;
12149 buf->b_p_sts = buf->b_p_sts_nopaste;
12150 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012151 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012152 }
12153
12154 /* restore global options */
12155 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012156 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012157#ifdef FEAT_CMDL_INFO
12158# ifdef FEAT_WINDOWS
12159 if (p_ru != save_ru)
12160 status_redraw_all(); /* redraw to draw the ruler */
12161# endif
12162 p_ru = save_ru;
12163#endif
12164#ifdef FEAT_RIGHTLEFT
12165 p_ri = save_ri;
12166 p_hkmap = save_hkmap;
12167#endif
12168 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012169 p_ai = p_ai_nopaste;
12170 p_et = p_et_nopaste;
12171 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012172 p_tw = p_tw_nopaste;
12173 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012174 }
12175
12176 old_p_paste = p_paste;
12177}
12178
12179/*
12180 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12181 *
12182 * Reset 'compatible' and set the values for options that didn't get set yet
12183 * to the Vim defaults.
12184 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012185 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012186 */
12187 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012188vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012189{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012190 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012191 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012192 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193
12194 if (!option_was_set((char_u *)"cp"))
12195 {
12196 p_cp = FALSE;
12197 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12198 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12199 set_option_default(opt_idx, OPT_FREE, FALSE);
12200 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012201 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012202 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012203
12204 if (fname != NULL)
12205 {
12206 p = vim_getenv(envname, &dofree);
12207 if (p == NULL)
12208 {
12209 /* Set $MYVIMRC to the first vimrc file found. */
12210 p = FullName_save(fname, FALSE);
12211 if (p != NULL)
12212 {
12213 vim_setenv(envname, p);
12214 vim_free(p);
12215 }
12216 }
12217 else if (dofree)
12218 vim_free(p);
12219 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012220}
12221
12222/*
12223 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12224 */
12225 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012226change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012227{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012228 int opt_idx;
12229
Bram Moolenaar071d4272004-06-13 20:20:40 +000012230 if (p_cp != on)
12231 {
12232 p_cp = on;
12233 compatible_set();
12234 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012235 opt_idx = findoption((char_u *)"cp");
12236 if (opt_idx >= 0)
12237 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012238}
12239
12240/*
12241 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012242 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012243 */
12244 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012245option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246{
12247 int idx;
12248
12249 idx = findoption(name);
12250 if (idx < 0) /* unknown option */
12251 return FALSE;
12252 if (options[idx].flags & P_WAS_SET)
12253 return TRUE;
12254 return FALSE;
12255}
12256
12257/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012258 * Reset the flag indicating option "name" was set.
12259 */
12260 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012261reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012262{
12263 int idx = findoption(name);
12264
12265 if (idx >= 0)
12266 options[idx].flags &= ~P_WAS_SET;
12267}
12268
12269/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012270 * compatible_set() - Called when 'compatible' has been set or unset.
12271 *
12272 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12273 * flag) to a Vi compatible value.
12274 * When 'compatible' is unset: Set all options that have a different default
12275 * for Vim (without the P_VI_DEF flag) to that default.
12276 */
12277 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012278compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012279{
12280 int opt_idx;
12281
12282 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12283 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12284 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12285 set_option_default(opt_idx, OPT_FREE, p_cp);
12286 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012287 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012288}
12289
12290#ifdef FEAT_LINEBREAK
12291
12292# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12293 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012294 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295# endif
12296
12297/*
12298 * fill_breakat_flags() -- called when 'breakat' changes value.
12299 */
12300 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012301fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012302{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012303 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012304 int i;
12305
12306 for (i = 0; i < 256; i++)
12307 breakat_flags[i] = FALSE;
12308
12309 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012310 for (p = p_breakat; *p; p++)
12311 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012312}
12313
12314# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012315 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012316# endif
12317
12318#endif
12319
12320/*
12321 * Check an option that can be a range of string values.
12322 *
12323 * Return OK for correct value, FAIL otherwise.
12324 * Empty is always OK.
12325 */
12326 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012327check_opt_strings(
12328 char_u *val,
12329 char **values,
12330 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012331{
12332 return opt_strings_flags(val, values, NULL, list);
12333}
12334
12335/*
12336 * Handle an option that can be a range of string values.
12337 * Set a flag in "*flagp" for each string present.
12338 *
12339 * Return OK for correct value, FAIL otherwise.
12340 * Empty is always OK.
12341 */
12342 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012343opt_strings_flags(
12344 char_u *val, /* new value */
12345 char **values, /* array of valid string values */
12346 unsigned *flagp,
12347 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012348{
12349 int i;
12350 int len;
12351 unsigned new_flags = 0;
12352
12353 while (*val)
12354 {
12355 for (i = 0; ; ++i)
12356 {
12357 if (values[i] == NULL) /* val not found in values[] */
12358 return FAIL;
12359
12360 len = (int)STRLEN(values[i]);
12361 if (STRNCMP(values[i], val, len) == 0
12362 && ((list && val[len] == ',') || val[len] == NUL))
12363 {
12364 val += len + (val[len] == ',');
12365 new_flags |= (1 << i);
12366 break; /* check next item in val list */
12367 }
12368 }
12369 }
12370 if (flagp != NULL)
12371 *flagp = new_flags;
12372
12373 return OK;
12374}
12375
12376/*
12377 * Read the 'wildmode' option, fill wim_flags[].
12378 */
12379 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012380check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012381{
12382 char_u new_wim_flags[4];
12383 char_u *p;
12384 int i;
12385 int idx = 0;
12386
12387 for (i = 0; i < 4; ++i)
12388 new_wim_flags[i] = 0;
12389
12390 for (p = p_wim; *p; ++p)
12391 {
12392 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12393 ;
12394 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12395 return FAIL;
12396 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12397 new_wim_flags[idx] |= WIM_LONGEST;
12398 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12399 new_wim_flags[idx] |= WIM_FULL;
12400 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12401 new_wim_flags[idx] |= WIM_LIST;
12402 else
12403 return FAIL;
12404 p += i;
12405 if (*p == NUL)
12406 break;
12407 if (*p == ',')
12408 {
12409 if (idx == 3)
12410 return FAIL;
12411 ++idx;
12412 }
12413 }
12414
12415 /* fill remaining entries with last flag */
12416 while (idx < 3)
12417 {
12418 new_wim_flags[idx + 1] = new_wim_flags[idx];
12419 ++idx;
12420 }
12421
12422 /* only when there are no errors, wim_flags[] is changed */
12423 for (i = 0; i < 4; ++i)
12424 wim_flags[i] = new_wim_flags[i];
12425 return OK;
12426}
12427
12428/*
12429 * Check if backspacing over something is allowed.
12430 */
12431 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012432can_bs(
12433 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012434{
12435 switch (*p_bs)
12436 {
12437 case '2': return TRUE;
12438 case '1': return (what != BS_START);
12439 case '0': return FALSE;
12440 }
12441 return vim_strchr(p_bs, what) != NULL;
12442}
12443
12444/*
12445 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12446 * the file must be considered changed when the value is different.
12447 */
12448 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012449save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012450{
12451 buf->b_start_ffc = *buf->b_p_ff;
12452 buf->b_start_eol = buf->b_p_eol;
12453#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012454 buf->b_start_bomb = buf->b_p_bomb;
12455
Bram Moolenaar071d4272004-06-13 20:20:40 +000012456 /* Only use free/alloc when necessary, they take time. */
12457 if (buf->b_start_fenc == NULL
12458 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12459 {
12460 vim_free(buf->b_start_fenc);
12461 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12462 }
12463#endif
12464}
12465
12466/*
12467 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12468 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012469 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12470 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012471 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012472 * When "ignore_empty" is true don't consider a new, empty buffer to be
12473 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012474 */
12475 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012476file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012477{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012478 /* In a buffer that was never loaded the options are not valid. */
12479 if (buf->b_flags & BF_NEVERLOADED)
12480 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012481 if (ignore_empty
12482 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012483 && buf->b_ml.ml_line_count == 1
12484 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12485 return FALSE;
12486 if (buf->b_start_ffc != *buf->b_p_ff)
12487 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012488 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012489 return TRUE;
12490#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012491 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12492 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012493 if (buf->b_start_fenc == NULL)
12494 return (*buf->b_p_fenc != NUL);
12495 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12496#else
12497 return FALSE;
12498#endif
12499}
12500
12501/*
12502 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12503 */
12504 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012505check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012506{
12507 return check_opt_strings(p, p_ff_values, FALSE);
12508}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012509
12510/*
12511 * Return the effective shiftwidth value for current buffer, using the
12512 * 'tabstop' value when 'shiftwidth' is zero.
12513 */
12514 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012515get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012516{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012517 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012518}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012519
12520/*
12521 * Return the effective softtabstop value for the current buffer, using the
12522 * 'tabstop' value when 'softtabstop' is negative.
12523 */
12524 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012525get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012526{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012527 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012528}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012529
12530/*
12531 * Check matchpairs option for "*initc".
12532 * If there is a match set "*initc" to the matching character and "*findc" to
12533 * the opposite character. Set "*backwards" to the direction.
12534 * When "switchit" is TRUE swap the direction.
12535 */
12536 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012537find_mps_values(
12538 int *initc,
12539 int *findc,
12540 int *backwards,
12541 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012542{
12543 char_u *ptr;
12544
12545 ptr = curbuf->b_p_mps;
12546 while (*ptr != NUL)
12547 {
12548#ifdef FEAT_MBYTE
12549 if (has_mbyte)
12550 {
12551 char_u *prev;
12552
12553 if (mb_ptr2char(ptr) == *initc)
12554 {
12555 if (switchit)
12556 {
12557 *findc = *initc;
12558 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12559 *backwards = TRUE;
12560 }
12561 else
12562 {
12563 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12564 *backwards = FALSE;
12565 }
12566 return;
12567 }
12568 prev = ptr;
12569 ptr += mb_ptr2len(ptr) + 1;
12570 if (mb_ptr2char(ptr) == *initc)
12571 {
12572 if (switchit)
12573 {
12574 *findc = *initc;
12575 *initc = mb_ptr2char(prev);
12576 *backwards = FALSE;
12577 }
12578 else
12579 {
12580 *findc = mb_ptr2char(prev);
12581 *backwards = TRUE;
12582 }
12583 return;
12584 }
12585 ptr += mb_ptr2len(ptr);
12586 }
12587 else
12588#endif
12589 {
12590 if (*ptr == *initc)
12591 {
12592 if (switchit)
12593 {
12594 *backwards = TRUE;
12595 *findc = *initc;
12596 *initc = ptr[2];
12597 }
12598 else
12599 {
12600 *backwards = FALSE;
12601 *findc = ptr[2];
12602 }
12603 return;
12604 }
12605 ptr += 2;
12606 if (*ptr == *initc)
12607 {
12608 if (switchit)
12609 {
12610 *backwards = FALSE;
12611 *findc = *initc;
12612 *initc = ptr[-2];
12613 }
12614 else
12615 {
12616 *backwards = TRUE;
12617 *findc = ptr[-2];
12618 }
12619 return;
12620 }
12621 ++ptr;
12622 }
12623 if (*ptr == ',')
12624 ++ptr;
12625 }
12626}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012627
12628#if defined(FEAT_LINEBREAK) || defined(PROTO)
12629/*
12630 * This is called when 'breakindentopt' is changed and when a window is
12631 * initialized.
12632 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012633 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012634briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012635{
12636 char_u *p;
12637 int bri_shift = 0;
12638 long bri_min = 20;
12639 int bri_sbr = FALSE;
12640
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012641 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012642 while (*p != NUL)
12643 {
12644 if (STRNCMP(p, "shift:", 6) == 0
12645 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12646 {
12647 p += 6;
12648 bri_shift = getdigits(&p);
12649 }
12650 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12651 {
12652 p += 4;
12653 bri_min = getdigits(&p);
12654 }
12655 else if (STRNCMP(p, "sbr", 3) == 0)
12656 {
12657 p += 3;
12658 bri_sbr = TRUE;
12659 }
12660 if (*p != ',' && *p != NUL)
12661 return FAIL;
12662 if (*p == ',')
12663 ++p;
12664 }
12665
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012666 wp->w_p_brishift = bri_shift;
12667 wp->w_p_brimin = bri_min;
12668 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012669
12670 return OK;
12671}
12672#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012673
12674/*
12675 * Get the local or global value of 'backupcopy'.
12676 */
12677 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012678get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012679{
12680 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12681}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012682
12683#if defined(FEAT_SIGNS) || defined(PROTO)
12684/*
12685 * Return TRUE when window "wp" has a column to draw signs in.
12686 */
12687 int
12688signcolumn_on(win_T *wp)
12689{
12690 if (*wp->w_p_scl == 'n')
12691 return FALSE;
12692 if (*wp->w_p_scl == 'y')
12693 return TRUE;
12694 return (wp->w_buffer->b_signlist != NULL
12695# ifdef FEAT_NETBEANS_INTG
12696 || wp->w_buffer->b_has_sign_column
12697# endif
12698 );
12699}
12700#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012701
12702#if defined(FEAT_EVAL) || defined(PROTO)
12703/*
12704 * Get window or buffer local options.
12705 */
12706 dict_T *
12707get_winbuf_options(int bufopt)
12708{
12709 dict_T *d;
12710 int opt_idx;
12711
12712 d = dict_alloc();
12713 if (d == NULL)
12714 return NULL;
12715
12716 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12717 {
12718 struct vimoption *opt = &options[opt_idx];
12719
12720 if ((bufopt && (opt->indir & PV_BUF))
12721 || (!bufopt && (opt->indir & PV_WIN)))
12722 {
12723 char_u *varp = get_varp(opt);
12724
12725 if (varp != NULL)
12726 {
12727 if (opt->flags & P_STRING)
12728 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012729 else if (opt->flags & P_NUM)
12730 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012731 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012732 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012733 }
12734 }
12735 }
12736
12737 return d;
12738}
12739#endif